1 // x86_64.cc -- x86_64 target support for gold.
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 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"
50 // A class to handle the PLT data.
52 class Output_data_plt_x86_64
: public Output_section_data
55 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, 64, false> Reloc_section
;
57 Output_data_plt_x86_64(Layout
* layout
, Output_data_got
<64, false>* got
,
58 Output_data_space
* got_plt
,
59 Output_data_space
* got_irelative
)
60 : Output_section_data(16), layout_(layout
), tlsdesc_rel_(NULL
),
61 irelative_rel_(NULL
), got_(got
), got_plt_(got_plt
),
62 got_irelative_(got_irelative
), count_(0), irelative_count_(0),
63 tlsdesc_got_offset_(-1U), free_list_()
64 { this->init(layout
); }
66 Output_data_plt_x86_64(Layout
* layout
, Output_data_got
<64, false>* got
,
67 Output_data_space
* got_plt
,
68 Output_data_space
* got_irelative
,
69 unsigned int plt_count
)
70 : Output_section_data((plt_count
+ 1) * plt_entry_size
, 16, false),
71 layout_(layout
), tlsdesc_rel_(NULL
), irelative_rel_(NULL
), got_(got
),
72 got_plt_(got_plt
), got_irelative_(got_irelative
), count_(plt_count
),
73 irelative_count_(0), tlsdesc_got_offset_(-1U), free_list_()
77 // Initialize the free list and reserve the first entry.
78 this->free_list_
.init((plt_count
+ 1) * plt_entry_size
, false);
79 this->free_list_
.remove(0, plt_entry_size
);
82 // Initialize the PLT section.
86 // Add an entry to the PLT.
88 add_entry(Symbol_table
*, Layout
*, Symbol
* gsym
);
90 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
92 add_local_ifunc_entry(Symbol_table
* symtab
, Layout
*,
93 Sized_relobj_file
<64, false>* relobj
,
94 unsigned int local_sym_index
);
96 // Add the relocation for a PLT entry.
98 add_relocation(Symbol_table
*, Layout
*, Symbol
* gsym
,
99 unsigned int got_offset
);
101 // Add the reserved TLSDESC_PLT entry to the PLT.
103 reserve_tlsdesc_entry(unsigned int got_offset
)
104 { this->tlsdesc_got_offset_
= got_offset
; }
106 // Return true if a TLSDESC_PLT entry has been reserved.
108 has_tlsdesc_entry() const
109 { return this->tlsdesc_got_offset_
!= -1U; }
111 // Return the GOT offset for the reserved TLSDESC_PLT entry.
113 get_tlsdesc_got_offset() const
114 { return this->tlsdesc_got_offset_
; }
116 // Return the offset of the reserved TLSDESC_PLT entry.
118 get_tlsdesc_plt_offset() const
119 { return (this->count_
+ this->irelative_count_
+ 1) * plt_entry_size
; }
121 // Return the .rela.plt section data.
124 { return this->rel_
; }
126 // Return where the TLSDESC relocations should go.
128 rela_tlsdesc(Layout
*);
130 // Return where the IRELATIVE relocations should go in the PLT
133 rela_irelative(Symbol_table
*, Layout
*);
135 // Return whether we created a section for IRELATIVE relocations.
137 has_irelative_section() const
138 { return this->irelative_rel_
!= NULL
; }
140 // Return the number of PLT entries.
143 { return this->count_
+ this->irelative_count_
; }
145 // Return the offset of the first non-reserved PLT entry.
147 first_plt_entry_offset()
148 { return plt_entry_size
; }
150 // Return the size of a PLT entry.
153 { return plt_entry_size
; }
155 // Reserve a slot in the PLT for an existing symbol in an incremental update.
157 reserve_slot(unsigned int plt_index
)
159 this->free_list_
.remove((plt_index
+ 1) * plt_entry_size
,
160 (plt_index
+ 2) * plt_entry_size
);
163 // Return the PLT address to use for a global symbol.
165 address_for_global(const Symbol
*);
167 // Return the PLT address to use for a local symbol.
169 address_for_local(const Relobj
*, unsigned int symndx
);
173 do_adjust_output_section(Output_section
* os
);
175 // Write to a map file.
177 do_print_to_mapfile(Mapfile
* mapfile
) const
178 { mapfile
->print_output_data(this, _("** PLT")); }
181 // The size of an entry in the PLT.
182 static const int plt_entry_size
= 16;
184 // The first entry in the PLT.
185 // From the AMD64 ABI: "Unlike Intel386 ABI, this ABI uses the same
186 // procedure linkage table for both programs and shared objects."
187 static const unsigned char first_plt_entry
[plt_entry_size
];
189 // Other entries in the PLT for an executable.
190 static const unsigned char plt_entry
[plt_entry_size
];
192 // The reserved TLSDESC entry in the PLT for an executable.
193 static const unsigned char tlsdesc_plt_entry
[plt_entry_size
];
195 // The .eh_frame unwind information for the PLT.
196 static const int plt_eh_frame_cie_size
= 16;
197 static const int plt_eh_frame_fde_size
= 32;
198 static const unsigned char plt_eh_frame_cie
[plt_eh_frame_cie_size
];
199 static const unsigned char plt_eh_frame_fde
[plt_eh_frame_fde_size
];
201 // Set the final size.
203 set_final_data_size();
205 // Write out the PLT data.
207 do_write(Output_file
*);
209 // A pointer to the Layout class, so that we can find the .dynamic
210 // section when we write out the GOT PLT section.
212 // The reloc section.
214 // The TLSDESC relocs, if necessary. These must follow the regular
216 Reloc_section
* tlsdesc_rel_
;
217 // The IRELATIVE relocs, if necessary. These must follow the
218 // regular PLT relocations and the TLSDESC relocations.
219 Reloc_section
* irelative_rel_
;
221 Output_data_got
<64, false>* got_
;
222 // The .got.plt section.
223 Output_data_space
* got_plt_
;
224 // The part of the .got.plt section used for IRELATIVE relocs.
225 Output_data_space
* got_irelative_
;
226 // The number of PLT entries.
228 // Number of PLT entries with R_X86_64_IRELATIVE relocs. These
229 // follow the regular PLT entries.
230 unsigned int irelative_count_
;
231 // Offset of the reserved TLSDESC_GOT entry when needed.
232 unsigned int tlsdesc_got_offset_
;
233 // List of available regions within the section, for incremental
235 Free_list free_list_
;
238 // The x86_64 target class.
240 // http://www.x86-64.org/documentation/abi.pdf
241 // TLS info comes from
242 // http://people.redhat.com/drepper/tls.pdf
243 // http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt
245 class Target_x86_64
: public Sized_target
<64, false>
248 // In the x86_64 ABI (p 68), it says "The AMD64 ABI architectures
249 // uses only Elf64_Rela relocation entries with explicit addends."
250 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, 64, false> Reloc_section
;
253 : Sized_target
<64, false>(&x86_64_info
),
254 got_(NULL
), plt_(NULL
), got_plt_(NULL
), got_irelative_(NULL
),
255 got_tlsdesc_(NULL
), global_offset_table_(NULL
), rela_dyn_(NULL
),
256 rela_irelative_(NULL
), copy_relocs_(elfcpp::R_X86_64_COPY
),
257 dynbss_(NULL
), got_mod_index_offset_(-1U), tlsdesc_reloc_info_(),
258 tls_base_symbol_defined_(false)
261 // Hook for a new output section.
263 do_new_output_section(Output_section
*) const;
265 // Scan the relocations to look for symbol adjustments.
267 gc_process_relocs(Symbol_table
* symtab
,
269 Sized_relobj_file
<64, false>* object
,
270 unsigned int data_shndx
,
271 unsigned int sh_type
,
272 const unsigned char* prelocs
,
274 Output_section
* output_section
,
275 bool needs_special_offset_handling
,
276 size_t local_symbol_count
,
277 const unsigned char* plocal_symbols
);
279 // Scan the relocations to look for symbol adjustments.
281 scan_relocs(Symbol_table
* symtab
,
283 Sized_relobj_file
<64, false>* object
,
284 unsigned int data_shndx
,
285 unsigned int sh_type
,
286 const unsigned char* prelocs
,
288 Output_section
* output_section
,
289 bool needs_special_offset_handling
,
290 size_t local_symbol_count
,
291 const unsigned char* plocal_symbols
);
293 // Finalize the sections.
295 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
297 // Return the value to use for a dynamic which requires special
300 do_dynsym_value(const Symbol
*) const;
302 // Relocate a section.
304 relocate_section(const Relocate_info
<64, false>*,
305 unsigned int sh_type
,
306 const unsigned char* prelocs
,
308 Output_section
* output_section
,
309 bool needs_special_offset_handling
,
311 elfcpp::Elf_types
<64>::Elf_Addr view_address
,
312 section_size_type view_size
,
313 const Reloc_symbol_changes
*);
315 // Scan the relocs during a relocatable link.
317 scan_relocatable_relocs(Symbol_table
* symtab
,
319 Sized_relobj_file
<64, false>* object
,
320 unsigned int data_shndx
,
321 unsigned int sh_type
,
322 const unsigned char* prelocs
,
324 Output_section
* output_section
,
325 bool needs_special_offset_handling
,
326 size_t local_symbol_count
,
327 const unsigned char* plocal_symbols
,
328 Relocatable_relocs
*);
330 // Relocate a section during a relocatable link.
332 relocate_for_relocatable(const Relocate_info
<64, false>*,
333 unsigned int sh_type
,
334 const unsigned char* prelocs
,
336 Output_section
* output_section
,
337 off_t offset_in_output_section
,
338 const Relocatable_relocs
*,
340 elfcpp::Elf_types
<64>::Elf_Addr view_address
,
341 section_size_type view_size
,
342 unsigned char* reloc_view
,
343 section_size_type reloc_view_size
);
345 // Return a string used to fill a code section with nops.
347 do_code_fill(section_size_type length
) const;
349 // Return whether SYM is defined by the ABI.
351 do_is_defined_by_abi(const Symbol
* sym
) const
352 { return strcmp(sym
->name(), "__tls_get_addr") == 0; }
354 // Return the symbol index to use for a target specific relocation.
355 // The only target specific relocation is R_X86_64_TLSDESC for a
356 // local symbol, which is an absolute reloc.
358 do_reloc_symbol_index(void*, unsigned int r_type
) const
360 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC
);
364 // Return the addend to use for a target specific relocation.
366 do_reloc_addend(void* arg
, unsigned int r_type
, uint64_t addend
) const;
368 // Return the PLT section.
370 do_plt_address_for_global(const Symbol
* gsym
) const
371 { return this->plt_section()->address_for_global(gsym
); }
374 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
375 { return this->plt_section()->address_for_local(relobj
, symndx
); }
377 // This function should be defined in targets that can use relocation
378 // types to determine (implemented in local_reloc_may_be_function_pointer
379 // and global_reloc_may_be_function_pointer)
380 // if a function's pointer is taken. ICF uses this in safe mode to only
381 // fold those functions whose pointer is defintely not taken. For x86_64
382 // pie binaries, safe ICF cannot be done by looking at relocation types.
384 do_can_check_for_function_pointers() const
385 { return !parameters
->options().pie(); }
387 // Return the base for a DW_EH_PE_datarel encoding.
389 do_ehframe_datarel_base() const;
391 // Adjust -fsplit-stack code which calls non-split-stack code.
393 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
394 section_offset_type fnoffset
, section_size_type fnsize
,
395 unsigned char* view
, section_size_type view_size
,
396 std::string
* from
, std::string
* to
) const;
398 // Return the size of the GOT section.
402 gold_assert(this->got_
!= NULL
);
403 return this->got_
->data_size();
406 // Return the number of entries in the GOT.
408 got_entry_count() const
410 if (this->got_
== NULL
)
412 return this->got_size() / 8;
415 // Return the number of entries in the PLT.
417 plt_entry_count() const;
419 // Return the offset of the first non-reserved PLT entry.
421 first_plt_entry_offset() const;
423 // Return the size of each PLT entry.
425 plt_entry_size() const;
427 // Create the GOT section for an incremental update.
428 Output_data_got
<64, false>*
429 init_got_plt_for_update(Symbol_table
* symtab
,
431 unsigned int got_count
,
432 unsigned int plt_count
);
434 // Reserve a GOT entry for a local symbol, and regenerate any
435 // necessary dynamic relocations.
437 reserve_local_got_entry(unsigned int got_index
,
438 Sized_relobj
<64, false>* obj
,
440 unsigned int got_type
);
442 // Reserve a GOT entry for a global symbol, and regenerate any
443 // necessary dynamic relocations.
445 reserve_global_got_entry(unsigned int got_index
, Symbol
* gsym
,
446 unsigned int got_type
);
448 // Register an existing PLT entry for a global symbol.
450 register_global_plt_entry(Symbol_table
*, Layout
*, unsigned int plt_index
,
453 // Force a COPY relocation for a given symbol.
455 emit_copy_reloc(Symbol_table
*, Symbol
*, Output_section
*, off_t
);
457 // Apply an incremental relocation.
459 apply_relocation(const Relocate_info
<64, false>* relinfo
,
460 elfcpp::Elf_types
<64>::Elf_Addr r_offset
,
462 elfcpp::Elf_types
<64>::Elf_Swxword r_addend
,
465 elfcpp::Elf_types
<64>::Elf_Addr address
,
466 section_size_type view_size
);
468 // Add a new reloc argument, returning the index in the vector.
470 add_tlsdesc_info(Sized_relobj_file
<64, false>* object
, unsigned int r_sym
)
472 this->tlsdesc_reloc_info_
.push_back(Tlsdesc_info(object
, r_sym
));
473 return this->tlsdesc_reloc_info_
.size() - 1;
477 // The class which scans relocations.
482 : issued_non_pic_error_(false)
486 get_reference_flags(unsigned int r_type
);
489 local(Symbol_table
* symtab
, Layout
* layout
, Target_x86_64
* target
,
490 Sized_relobj_file
<64, false>* object
,
491 unsigned int data_shndx
,
492 Output_section
* output_section
,
493 const elfcpp::Rela
<64, false>& reloc
, unsigned int r_type
,
494 const elfcpp::Sym
<64, false>& lsym
);
497 global(Symbol_table
* symtab
, Layout
* layout
, Target_x86_64
* target
,
498 Sized_relobj_file
<64, false>* object
,
499 unsigned int data_shndx
,
500 Output_section
* output_section
,
501 const elfcpp::Rela
<64, false>& reloc
, unsigned int r_type
,
505 local_reloc_may_be_function_pointer(Symbol_table
* symtab
, Layout
* layout
,
506 Target_x86_64
* target
,
507 Sized_relobj_file
<64, false>* object
,
508 unsigned int data_shndx
,
509 Output_section
* output_section
,
510 const elfcpp::Rela
<64, false>& reloc
,
512 const elfcpp::Sym
<64, false>& lsym
);
515 global_reloc_may_be_function_pointer(Symbol_table
* symtab
, Layout
* layout
,
516 Target_x86_64
* target
,
517 Sized_relobj_file
<64, false>* object
,
518 unsigned int data_shndx
,
519 Output_section
* output_section
,
520 const elfcpp::Rela
<64, false>& reloc
,
526 unsupported_reloc_local(Sized_relobj_file
<64, false>*, unsigned int r_type
);
529 unsupported_reloc_global(Sized_relobj_file
<64, false>*, unsigned int r_type
,
533 check_non_pic(Relobj
*, unsigned int r_type
, Symbol
*);
536 possible_function_pointer_reloc(unsigned int r_type
);
539 reloc_needs_plt_for_ifunc(Sized_relobj_file
<64, false>*,
540 unsigned int r_type
);
542 // Whether we have issued an error about a non-PIC compilation.
543 bool issued_non_pic_error_
;
546 // The class which implements relocation.
551 : skip_call_tls_get_addr_(false)
556 if (this->skip_call_tls_get_addr_
)
558 // FIXME: This needs to specify the location somehow.
559 gold_error(_("missing expected TLS relocation"));
563 // Do a relocation. Return false if the caller should not issue
564 // any warnings about this relocation.
566 relocate(const Relocate_info
<64, false>*, Target_x86_64
*, Output_section
*,
567 size_t relnum
, const elfcpp::Rela
<64, false>&,
568 unsigned int r_type
, const Sized_symbol
<64>*,
569 const Symbol_value
<64>*,
570 unsigned char*, elfcpp::Elf_types
<64>::Elf_Addr
,
574 // Do a TLS relocation.
576 relocate_tls(const Relocate_info
<64, false>*, Target_x86_64
*,
577 size_t relnum
, const elfcpp::Rela
<64, false>&,
578 unsigned int r_type
, const Sized_symbol
<64>*,
579 const Symbol_value
<64>*,
580 unsigned char*, elfcpp::Elf_types
<64>::Elf_Addr
,
583 // Do a TLS General-Dynamic to Initial-Exec transition.
585 tls_gd_to_ie(const Relocate_info
<64, false>*, size_t relnum
,
586 Output_segment
* tls_segment
,
587 const elfcpp::Rela
<64, false>&, unsigned int r_type
,
588 elfcpp::Elf_types
<64>::Elf_Addr value
,
590 elfcpp::Elf_types
<64>::Elf_Addr
,
591 section_size_type view_size
);
593 // Do a TLS General-Dynamic to Local-Exec transition.
595 tls_gd_to_le(const Relocate_info
<64, false>*, size_t relnum
,
596 Output_segment
* tls_segment
,
597 const elfcpp::Rela
<64, false>&, unsigned int r_type
,
598 elfcpp::Elf_types
<64>::Elf_Addr value
,
600 section_size_type view_size
);
602 // Do a TLSDESC-style General-Dynamic to Initial-Exec transition.
604 tls_desc_gd_to_ie(const Relocate_info
<64, false>*, size_t relnum
,
605 Output_segment
* tls_segment
,
606 const elfcpp::Rela
<64, false>&, unsigned int r_type
,
607 elfcpp::Elf_types
<64>::Elf_Addr value
,
609 elfcpp::Elf_types
<64>::Elf_Addr
,
610 section_size_type view_size
);
612 // Do a TLSDESC-style General-Dynamic to Local-Exec transition.
614 tls_desc_gd_to_le(const Relocate_info
<64, false>*, size_t relnum
,
615 Output_segment
* tls_segment
,
616 const elfcpp::Rela
<64, false>&, unsigned int r_type
,
617 elfcpp::Elf_types
<64>::Elf_Addr value
,
619 section_size_type view_size
);
621 // Do a TLS Local-Dynamic to Local-Exec transition.
623 tls_ld_to_le(const Relocate_info
<64, false>*, size_t relnum
,
624 Output_segment
* tls_segment
,
625 const elfcpp::Rela
<64, false>&, unsigned int r_type
,
626 elfcpp::Elf_types
<64>::Elf_Addr value
,
628 section_size_type view_size
);
630 // Do a TLS Initial-Exec to Local-Exec transition.
632 tls_ie_to_le(const Relocate_info
<64, false>*, size_t relnum
,
633 Output_segment
* tls_segment
,
634 const elfcpp::Rela
<64, false>&, unsigned int r_type
,
635 elfcpp::Elf_types
<64>::Elf_Addr value
,
637 section_size_type view_size
);
639 // This is set if we should skip the next reloc, which should be a
640 // PLT32 reloc against ___tls_get_addr.
641 bool skip_call_tls_get_addr_
;
644 // A class which returns the size required for a relocation type,
645 // used while scanning relocs during a relocatable link.
646 class Relocatable_size_for_reloc
650 get_size_for_reloc(unsigned int, Relobj
*);
653 // Adjust TLS relocation type based on the options and whether this
654 // is a local symbol.
655 static tls::Tls_optimization
656 optimize_tls_reloc(bool is_final
, int r_type
);
658 // Get the GOT section, creating it if necessary.
659 Output_data_got
<64, false>*
660 got_section(Symbol_table
*, Layout
*);
662 // Get the GOT PLT section.
664 got_plt_section() const
666 gold_assert(this->got_plt_
!= NULL
);
667 return this->got_plt_
;
670 // Get the GOT section for TLSDESC entries.
671 Output_data_got
<64, false>*
672 got_tlsdesc_section() const
674 gold_assert(this->got_tlsdesc_
!= NULL
);
675 return this->got_tlsdesc_
;
678 // Create the PLT section.
680 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
682 // Create a PLT entry for a global symbol.
684 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
686 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
688 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
689 Sized_relobj_file
<64, false>* relobj
,
690 unsigned int local_sym_index
);
692 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
694 define_tls_base_symbol(Symbol_table
*, Layout
*);
696 // Create the reserved PLT and GOT entries for the TLS descriptor resolver.
698 reserve_tlsdesc_entries(Symbol_table
* symtab
, Layout
* layout
);
700 // Create a GOT entry for the TLS module index.
702 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
703 Sized_relobj_file
<64, false>* object
);
705 // Get the PLT section.
706 Output_data_plt_x86_64
*
709 gold_assert(this->plt_
!= NULL
);
713 // Get the dynamic reloc section, creating it if necessary.
715 rela_dyn_section(Layout
*);
717 // Get the section to use for TLSDESC relocations.
719 rela_tlsdesc_section(Layout
*) const;
721 // Get the section to use for IRELATIVE relocations.
723 rela_irelative_section(Layout
*);
725 // Add a potential copy relocation.
727 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
728 Sized_relobj_file
<64, false>* object
,
729 unsigned int shndx
, Output_section
* output_section
,
730 Symbol
* sym
, const elfcpp::Rela
<64, false>& reloc
)
732 this->copy_relocs_
.copy_reloc(symtab
, layout
,
733 symtab
->get_sized_symbol
<64>(sym
),
734 object
, shndx
, output_section
,
735 reloc
, this->rela_dyn_section(layout
));
738 // Information about this specific target which we pass to the
739 // general Target structure.
740 static const Target::Target_info x86_64_info
;
742 // The types of GOT entries needed for this platform.
743 // These values are exposed to the ABI in an incremental link.
744 // Do not renumber existing values without changing the version
745 // number of the .gnu_incremental_inputs section.
748 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
749 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
750 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
751 GOT_TYPE_TLS_DESC
= 3 // GOT entry for TLS_DESC pair
754 // This type is used as the argument to the target specific
755 // relocation routines. The only target specific reloc is
756 // R_X86_64_TLSDESC against a local symbol.
759 Tlsdesc_info(Sized_relobj_file
<64, false>* a_object
, unsigned int a_r_sym
)
760 : object(a_object
), r_sym(a_r_sym
)
763 // The object in which the local symbol is defined.
764 Sized_relobj_file
<64, false>* object
;
765 // The local symbol index in the object.
770 Output_data_got
<64, false>* got_
;
772 Output_data_plt_x86_64
* plt_
;
773 // The GOT PLT section.
774 Output_data_space
* got_plt_
;
775 // The GOT section for IRELATIVE relocations.
776 Output_data_space
* got_irelative_
;
777 // The GOT section for TLSDESC relocations.
778 Output_data_got
<64, false>* got_tlsdesc_
;
779 // The _GLOBAL_OFFSET_TABLE_ symbol.
780 Symbol
* global_offset_table_
;
781 // The dynamic reloc section.
782 Reloc_section
* rela_dyn_
;
783 // The section to use for IRELATIVE relocs.
784 Reloc_section
* rela_irelative_
;
785 // Relocs saved to avoid a COPY reloc.
786 Copy_relocs
<elfcpp::SHT_RELA
, 64, false> copy_relocs_
;
787 // Space for variables copied with a COPY reloc.
788 Output_data_space
* dynbss_
;
789 // Offset of the GOT entry for the TLS module index.
790 unsigned int got_mod_index_offset_
;
791 // We handle R_X86_64_TLSDESC against a local symbol as a target
792 // specific relocation. Here we store the object and local symbol
793 // index for the relocation.
794 std::vector
<Tlsdesc_info
> tlsdesc_reloc_info_
;
795 // True if the _TLS_MODULE_BASE_ symbol has been defined.
796 bool tls_base_symbol_defined_
;
799 const Target::Target_info
Target_x86_64::x86_64_info
=
802 false, // is_big_endian
803 elfcpp::EM_X86_64
, // machine_code
804 false, // has_make_symbol
805 false, // has_resolve
806 true, // has_code_fill
807 true, // is_default_stack_executable
808 true, // can_icf_inline_merge_sections
810 "/lib/ld64.so.1", // program interpreter
811 0x400000, // default_text_segment_address
812 0x1000, // abi_pagesize (overridable by -z max-page-size)
813 0x1000, // common_pagesize (overridable by -z common-page-size)
814 elfcpp::SHN_UNDEF
, // small_common_shndx
815 elfcpp::SHN_X86_64_LCOMMON
, // large_common_shndx
816 0, // small_common_section_flags
817 elfcpp::SHF_X86_64_LARGE
, // large_common_section_flags
818 NULL
, // attributes_section
819 NULL
// attributes_vendor
822 // This is called when a new output section is created. This is where
823 // we handle the SHF_X86_64_LARGE.
826 Target_x86_64::do_new_output_section(Output_section
* os
) const
828 if ((os
->flags() & elfcpp::SHF_X86_64_LARGE
) != 0)
829 os
->set_is_large_section();
832 // Get the GOT section, creating it if necessary.
834 Output_data_got
<64, false>*
835 Target_x86_64::got_section(Symbol_table
* symtab
, Layout
* layout
)
837 if (this->got_
== NULL
)
839 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
841 // When using -z now, we can treat .got.plt as a relro section.
842 // Without -z now, it is modified after program startup by lazy
844 bool is_got_plt_relro
= parameters
->options().now();
845 Output_section_order got_order
= (is_got_plt_relro
848 Output_section_order got_plt_order
= (is_got_plt_relro
850 : ORDER_NON_RELRO_FIRST
);
852 this->got_
= new Output_data_got
<64, false>();
854 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
856 | elfcpp::SHF_WRITE
),
857 this->got_
, got_order
, true);
859 this->got_plt_
= new Output_data_space(8, "** GOT PLT");
860 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
862 | elfcpp::SHF_WRITE
),
863 this->got_plt_
, got_plt_order
,
866 // The first three entries are reserved.
867 this->got_plt_
->set_current_data_size(3 * 8);
869 if (!is_got_plt_relro
)
871 // Those bytes can go into the relro segment.
872 layout
->increase_relro(3 * 8);
875 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
876 this->global_offset_table_
=
877 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
878 Symbol_table::PREDEFINED
,
880 0, 0, elfcpp::STT_OBJECT
,
882 elfcpp::STV_HIDDEN
, 0,
885 // If there are any IRELATIVE relocations, they get GOT entries
886 // in .got.plt after the jump slot entries.
887 this->got_irelative_
= new Output_data_space(8, "** GOT IRELATIVE PLT");
888 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
890 | elfcpp::SHF_WRITE
),
891 this->got_irelative_
,
892 got_plt_order
, is_got_plt_relro
);
894 // If there are any TLSDESC relocations, they get GOT entries in
895 // .got.plt after the jump slot and IRELATIVE entries.
896 this->got_tlsdesc_
= new Output_data_got
<64, false>();
897 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
899 | elfcpp::SHF_WRITE
),
901 got_plt_order
, is_got_plt_relro
);
907 // Get the dynamic reloc section, creating it if necessary.
909 Target_x86_64::Reloc_section
*
910 Target_x86_64::rela_dyn_section(Layout
* layout
)
912 if (this->rela_dyn_
== NULL
)
914 gold_assert(layout
!= NULL
);
915 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
916 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
917 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
918 ORDER_DYNAMIC_RELOCS
, false);
920 return this->rela_dyn_
;
923 // Get the section to use for IRELATIVE relocs, creating it if
924 // necessary. These go in .rela.dyn, but only after all other dynamic
925 // relocations. They need to follow the other dynamic relocations so
926 // that they can refer to global variables initialized by those
929 Target_x86_64::Reloc_section
*
930 Target_x86_64::rela_irelative_section(Layout
* layout
)
932 if (this->rela_irelative_
== NULL
)
934 // Make sure we have already created the dynamic reloc section.
935 this->rela_dyn_section(layout
);
936 this->rela_irelative_
= new Reloc_section(false);
937 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
938 elfcpp::SHF_ALLOC
, this->rela_irelative_
,
939 ORDER_DYNAMIC_RELOCS
, false);
940 gold_assert(this->rela_dyn_
->output_section()
941 == this->rela_irelative_
->output_section());
943 return this->rela_irelative_
;
946 // Initialize the PLT section.
949 Output_data_plt_x86_64::init(Layout
* layout
)
951 this->rel_
= new Reloc_section(false);
952 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
953 elfcpp::SHF_ALLOC
, this->rel_
,
954 ORDER_DYNAMIC_PLT_RELOCS
, false);
956 // Add unwind information if requested.
957 if (parameters
->options().ld_generated_unwind_info())
958 layout
->add_eh_frame_for_plt(this, plt_eh_frame_cie
, plt_eh_frame_cie_size
,
959 plt_eh_frame_fde
, plt_eh_frame_fde_size
);
963 Output_data_plt_x86_64::do_adjust_output_section(Output_section
* os
)
965 os
->set_entsize(plt_entry_size
);
968 // Add an entry to the PLT.
971 Output_data_plt_x86_64::add_entry(Symbol_table
* symtab
, Layout
* layout
,
974 gold_assert(!gsym
->has_plt_offset());
976 unsigned int plt_index
;
978 section_offset_type got_offset
;
980 unsigned int* pcount
;
982 unsigned int reserved
;
983 Output_data_space
* got
;
984 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
985 && gsym
->can_use_relative_reloc(false))
987 pcount
= &this->irelative_count_
;
990 got
= this->got_irelative_
;
994 pcount
= &this->count_
;
997 got
= this->got_plt_
;
1000 if (!this->is_data_size_valid())
1002 // Note that when setting the PLT offset for a non-IRELATIVE
1003 // entry we skip the initial reserved PLT entry.
1004 plt_index
= *pcount
+ offset
;
1005 plt_offset
= plt_index
* plt_entry_size
;
1009 got_offset
= (plt_index
- offset
+ reserved
) * 8;
1010 gold_assert(got_offset
== got
->current_data_size());
1012 // Every PLT entry needs a GOT entry which points back to the PLT
1013 // entry (this will be changed by the dynamic linker, normally
1014 // lazily when the function is called).
1015 got
->set_current_data_size(got_offset
+ 8);
1019 // FIXME: This is probably not correct for IRELATIVE relocs.
1021 // For incremental updates, find an available slot.
1022 plt_offset
= this->free_list_
.allocate(plt_entry_size
, plt_entry_size
, 0);
1023 if (plt_offset
== -1)
1024 gold_fallback(_("out of patch space (PLT);"
1025 " relink with --incremental-full"));
1027 // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
1028 // can be calculated from the PLT index, adjusting for the three
1029 // reserved entries at the beginning of the GOT.
1030 plt_index
= plt_offset
/ plt_entry_size
- 1;
1031 got_offset
= (plt_index
- offset
+ reserved
) * 8;
1034 gsym
->set_plt_offset(plt_offset
);
1036 // Every PLT entry needs a reloc.
1037 this->add_relocation(symtab
, layout
, gsym
, got_offset
);
1039 // Note that we don't need to save the symbol. The contents of the
1040 // PLT are independent of which symbols are used. The symbols only
1041 // appear in the relocations.
1044 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol. Return
1048 Output_data_plt_x86_64::add_local_ifunc_entry(
1049 Symbol_table
* symtab
,
1051 Sized_relobj_file
<64, false>* relobj
,
1052 unsigned int local_sym_index
)
1054 unsigned int plt_offset
= this->irelative_count_
* plt_entry_size
;
1055 ++this->irelative_count_
;
1057 section_offset_type got_offset
= this->got_irelative_
->current_data_size();
1059 // Every PLT entry needs a GOT entry which points back to the PLT
1061 this->got_irelative_
->set_current_data_size(got_offset
+ 8);
1063 // Every PLT entry needs a reloc.
1064 Reloc_section
* rela
= this->rela_irelative(symtab
, layout
);
1065 rela
->add_symbolless_local_addend(relobj
, local_sym_index
,
1066 elfcpp::R_X86_64_IRELATIVE
,
1067 this->got_irelative_
, got_offset
, 0);
1072 // Add the relocation for a PLT entry.
1075 Output_data_plt_x86_64::add_relocation(Symbol_table
* symtab
, Layout
* layout
,
1076 Symbol
* gsym
, unsigned int got_offset
)
1078 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1079 && gsym
->can_use_relative_reloc(false))
1081 Reloc_section
* rela
= this->rela_irelative(symtab
, layout
);
1082 rela
->add_symbolless_global_addend(gsym
, elfcpp::R_X86_64_IRELATIVE
,
1083 this->got_irelative_
, got_offset
, 0);
1087 gsym
->set_needs_dynsym_entry();
1088 this->rel_
->add_global(gsym
, elfcpp::R_X86_64_JUMP_SLOT
, this->got_plt_
,
1093 // Return where the TLSDESC relocations should go, creating it if
1094 // necessary. These follow the JUMP_SLOT relocations.
1096 Output_data_plt_x86_64::Reloc_section
*
1097 Output_data_plt_x86_64::rela_tlsdesc(Layout
* layout
)
1099 if (this->tlsdesc_rel_
== NULL
)
1101 this->tlsdesc_rel_
= new Reloc_section(false);
1102 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1103 elfcpp::SHF_ALLOC
, this->tlsdesc_rel_
,
1104 ORDER_DYNAMIC_PLT_RELOCS
, false);
1105 gold_assert(this->tlsdesc_rel_
->output_section()
1106 == this->rel_
->output_section());
1108 return this->tlsdesc_rel_
;
1111 // Return where the IRELATIVE relocations should go in the PLT. These
1112 // follow the JUMP_SLOT and the TLSDESC relocations.
1114 Output_data_plt_x86_64::Reloc_section
*
1115 Output_data_plt_x86_64::rela_irelative(Symbol_table
* symtab
, Layout
* layout
)
1117 if (this->irelative_rel_
== NULL
)
1119 // Make sure we have a place for the TLSDESC relocations, in
1120 // case we see any later on.
1121 this->rela_tlsdesc(layout
);
1122 this->irelative_rel_
= new Reloc_section(false);
1123 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1124 elfcpp::SHF_ALLOC
, this->irelative_rel_
,
1125 ORDER_DYNAMIC_PLT_RELOCS
, false);
1126 gold_assert(this->irelative_rel_
->output_section()
1127 == this->rel_
->output_section());
1129 if (parameters
->doing_static_link())
1131 // A statically linked executable will only have a .rela.plt
1132 // section to hold R_X86_64_IRELATIVE relocs for
1133 // STT_GNU_IFUNC symbols. The library will use these
1134 // symbols to locate the IRELATIVE relocs at program startup
1136 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1137 Symbol_table::PREDEFINED
,
1138 this->irelative_rel_
, 0, 0,
1139 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1140 elfcpp::STV_HIDDEN
, 0, false, true);
1141 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1142 Symbol_table::PREDEFINED
,
1143 this->irelative_rel_
, 0, 0,
1144 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1145 elfcpp::STV_HIDDEN
, 0, true, true);
1148 return this->irelative_rel_
;
1151 // Return the PLT address to use for a global symbol.
1154 Output_data_plt_x86_64::address_for_global(const Symbol
* gsym
)
1156 uint64_t offset
= 0;
1157 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1158 && gsym
->can_use_relative_reloc(false))
1159 offset
= (this->count_
+ 1) * plt_entry_size
;
1160 return this->address() + offset
;
1163 // Return the PLT address to use for a local symbol. These are always
1164 // IRELATIVE relocs.
1167 Output_data_plt_x86_64::address_for_local(const Relobj
*, unsigned int)
1169 return this->address() + (this->count_
+ 1) * plt_entry_size
;
1172 // Set the final size.
1174 Output_data_plt_x86_64::set_final_data_size()
1176 unsigned int count
= this->count_
+ this->irelative_count_
;
1177 if (this->has_tlsdesc_entry())
1179 this->set_data_size((count
+ 1) * plt_entry_size
);
1182 // The first entry in the PLT for an executable.
1184 const unsigned char Output_data_plt_x86_64::first_plt_entry
[plt_entry_size
] =
1186 // From AMD64 ABI Draft 0.98, page 76
1187 0xff, 0x35, // pushq contents of memory address
1188 0, 0, 0, 0, // replaced with address of .got + 8
1189 0xff, 0x25, // jmp indirect
1190 0, 0, 0, 0, // replaced with address of .got + 16
1191 0x90, 0x90, 0x90, 0x90 // noop (x4)
1194 // Subsequent entries in the PLT for an executable.
1196 const unsigned char Output_data_plt_x86_64::plt_entry
[plt_entry_size
] =
1198 // From AMD64 ABI Draft 0.98, page 76
1199 0xff, 0x25, // jmpq indirect
1200 0, 0, 0, 0, // replaced with address of symbol in .got
1201 0x68, // pushq immediate
1202 0, 0, 0, 0, // replaced with offset into relocation table
1203 0xe9, // jmpq relative
1204 0, 0, 0, 0 // replaced with offset to start of .plt
1207 // The reserved TLSDESC entry in the PLT for an executable.
1209 const unsigned char Output_data_plt_x86_64::tlsdesc_plt_entry
[plt_entry_size
] =
1211 // From Alexandre Oliva, "Thread-Local Storage Descriptors for IA32
1212 // and AMD64/EM64T", Version 0.9.4 (2005-10-10).
1213 0xff, 0x35, // pushq x(%rip)
1214 0, 0, 0, 0, // replaced with address of linkmap GOT entry (at PLTGOT + 8)
1215 0xff, 0x25, // jmpq *y(%rip)
1216 0, 0, 0, 0, // replaced with offset of reserved TLSDESC_GOT entry
1221 // The .eh_frame unwind information for the PLT.
1224 Output_data_plt_x86_64::plt_eh_frame_cie
[plt_eh_frame_cie_size
] =
1227 'z', // Augmentation: augmentation size included.
1228 'R', // Augmentation: FDE encoding included.
1229 '\0', // End of augmentation string.
1230 1, // Code alignment factor.
1231 0x78, // Data alignment factor.
1232 16, // Return address column.
1233 1, // Augmentation size.
1234 (elfcpp::DW_EH_PE_pcrel
// FDE encoding.
1235 | elfcpp::DW_EH_PE_sdata4
),
1236 elfcpp::DW_CFA_def_cfa
, 7, 8, // DW_CFA_def_cfa: r7 (rsp) ofs 8.
1237 elfcpp::DW_CFA_offset
+ 16, 1,// DW_CFA_offset: r16 (rip) at cfa-8.
1238 elfcpp::DW_CFA_nop
, // Align to 16 bytes.
1243 Output_data_plt_x86_64::plt_eh_frame_fde
[plt_eh_frame_fde_size
] =
1245 0, 0, 0, 0, // Replaced with offset to .plt.
1246 0, 0, 0, 0, // Replaced with size of .plt.
1247 0, // Augmentation size.
1248 elfcpp::DW_CFA_def_cfa_offset
, 16, // DW_CFA_def_cfa_offset: 16.
1249 elfcpp::DW_CFA_advance_loc
+ 6, // Advance 6 to __PLT__ + 6.
1250 elfcpp::DW_CFA_def_cfa_offset
, 24, // DW_CFA_def_cfa_offset: 24.
1251 elfcpp::DW_CFA_advance_loc
+ 10, // Advance 10 to __PLT__ + 16.
1252 elfcpp::DW_CFA_def_cfa_expression
, // DW_CFA_def_cfa_expression.
1253 11, // Block length.
1254 elfcpp::DW_OP_breg7
, 8, // Push %rsp + 8.
1255 elfcpp::DW_OP_breg16
, 0, // Push %rip.
1256 elfcpp::DW_OP_lit15
, // Push 0xf.
1257 elfcpp::DW_OP_and
, // & (%rip & 0xf).
1258 elfcpp::DW_OP_lit11
, // Push 0xb.
1259 elfcpp::DW_OP_ge
, // >= ((%rip & 0xf) >= 0xb)
1260 elfcpp::DW_OP_lit3
, // Push 3.
1261 elfcpp::DW_OP_shl
, // << (((%rip & 0xf) >= 0xb) << 3)
1262 elfcpp::DW_OP_plus
, // + ((((%rip&0xf)>=0xb)<<3)+%rsp+8
1263 elfcpp::DW_CFA_nop
, // Align to 32 bytes.
1269 // Write out the PLT. This uses the hand-coded instructions above,
1270 // and adjusts them as needed. This is specified by the AMD64 ABI.
1273 Output_data_plt_x86_64::do_write(Output_file
* of
)
1275 const off_t offset
= this->offset();
1276 const section_size_type oview_size
=
1277 convert_to_section_size_type(this->data_size());
1278 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1280 const off_t got_file_offset
= this->got_plt_
->offset();
1281 gold_assert(parameters
->incremental_update()
1282 || (got_file_offset
+ this->got_plt_
->data_size()
1283 == this->got_irelative_
->offset()));
1284 const section_size_type got_size
=
1285 convert_to_section_size_type(this->got_plt_
->data_size()
1286 + this->got_irelative_
->data_size());
1287 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
1290 unsigned char* pov
= oview
;
1292 // The base address of the .plt section.
1293 elfcpp::Elf_types
<64>::Elf_Addr plt_address
= this->address();
1294 // The base address of the .got section.
1295 elfcpp::Elf_types
<64>::Elf_Addr got_base
= this->got_
->address();
1296 // The base address of the PLT portion of the .got section,
1297 // which is where the GOT pointer will point, and where the
1298 // three reserved GOT entries are located.
1299 elfcpp::Elf_types
<64>::Elf_Addr got_address
= this->got_plt_
->address();
1301 memcpy(pov
, first_plt_entry
, plt_entry_size
);
1302 // We do a jmp relative to the PC at the end of this instruction.
1303 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
1305 - (plt_address
+ 6)));
1306 elfcpp::Swap
<32, false>::writeval(pov
+ 8,
1308 - (plt_address
+ 12)));
1309 pov
+= plt_entry_size
;
1311 unsigned char* got_pov
= got_view
;
1313 // The first entry in the GOT is the address of the .dynamic section
1314 // aka the PT_DYNAMIC segment. The next two entries are reserved.
1315 // We saved space for them when we created the section in
1316 // Target_x86_64::got_section.
1317 Output_section
* dynamic
= this->layout_
->dynamic_section();
1318 uint32_t dynamic_addr
= dynamic
== NULL
? 0 : dynamic
->address();
1319 elfcpp::Swap
<64, false>::writeval(got_pov
, dynamic_addr
);
1321 memset(got_pov
, 0, 16);
1324 unsigned int plt_offset
= plt_entry_size
;
1325 unsigned int got_offset
= 24;
1326 const unsigned int count
= this->count_
+ this->irelative_count_
;
1327 for (unsigned int plt_index
= 0;
1330 pov
+= plt_entry_size
,
1332 plt_offset
+= plt_entry_size
,
1335 // Set and adjust the PLT entry itself.
1336 memcpy(pov
, plt_entry
, plt_entry_size
);
1337 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
1338 (got_address
+ got_offset
1339 - (plt_address
+ plt_offset
1342 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 7, plt_index
);
1343 elfcpp::Swap
<32, false>::writeval(pov
+ 12,
1344 - (plt_offset
+ plt_entry_size
));
1346 // Set the entry in the GOT.
1347 elfcpp::Swap
<64, false>::writeval(got_pov
, plt_address
+ plt_offset
+ 6);
1350 if (this->has_tlsdesc_entry())
1352 // Set and adjust the reserved TLSDESC PLT entry.
1353 unsigned int tlsdesc_got_offset
= this->get_tlsdesc_got_offset();
1354 memcpy(pov
, tlsdesc_plt_entry
, plt_entry_size
);
1355 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
1357 - (plt_address
+ plt_offset
1359 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 8,
1361 + tlsdesc_got_offset
1362 - (plt_address
+ plt_offset
1364 pov
+= plt_entry_size
;
1367 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1368 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
1370 of
->write_output_view(offset
, oview_size
, oview
);
1371 of
->write_output_view(got_file_offset
, got_size
, got_view
);
1374 // Create the PLT section.
1377 Target_x86_64::make_plt_section(Symbol_table
* symtab
, Layout
* layout
)
1379 if (this->plt_
== NULL
)
1381 // Create the GOT sections first.
1382 this->got_section(symtab
, layout
);
1384 this->plt_
= new Output_data_plt_x86_64(layout
, this->got_
,
1386 this->got_irelative_
);
1387 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1389 | elfcpp::SHF_EXECINSTR
),
1390 this->plt_
, ORDER_PLT
, false);
1392 // Make the sh_info field of .rela.plt point to .plt.
1393 Output_section
* rela_plt_os
= this->plt_
->rela_plt()->output_section();
1394 rela_plt_os
->set_info_section(this->plt_
->output_section());
1398 // Return the section for TLSDESC relocations.
1400 Target_x86_64::Reloc_section
*
1401 Target_x86_64::rela_tlsdesc_section(Layout
* layout
) const
1403 return this->plt_section()->rela_tlsdesc(layout
);
1406 // Create a PLT entry for a global symbol.
1409 Target_x86_64::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
1412 if (gsym
->has_plt_offset())
1415 if (this->plt_
== NULL
)
1416 this->make_plt_section(symtab
, layout
);
1418 this->plt_
->add_entry(symtab
, layout
, gsym
);
1421 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1424 Target_x86_64::make_local_ifunc_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
1425 Sized_relobj_file
<64, false>* relobj
,
1426 unsigned int local_sym_index
)
1428 if (relobj
->local_has_plt_offset(local_sym_index
))
1430 if (this->plt_
== NULL
)
1431 this->make_plt_section(symtab
, layout
);
1432 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1435 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1438 // Return the number of entries in the PLT.
1441 Target_x86_64::plt_entry_count() const
1443 if (this->plt_
== NULL
)
1445 return this->plt_
->entry_count();
1448 // Return the offset of the first non-reserved PLT entry.
1451 Target_x86_64::first_plt_entry_offset() const
1453 return Output_data_plt_x86_64::first_plt_entry_offset();
1456 // Return the size of each PLT entry.
1459 Target_x86_64::plt_entry_size() const
1461 return Output_data_plt_x86_64::get_plt_entry_size();
1464 // Create the GOT and PLT sections for an incremental update.
1466 Output_data_got
<64, false>*
1467 Target_x86_64::init_got_plt_for_update(Symbol_table
* symtab
,
1469 unsigned int got_count
,
1470 unsigned int plt_count
)
1472 gold_assert(this->got_
== NULL
);
1474 this->got_
= new Output_data_got
<64, false>(got_count
* 8);
1475 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1477 | elfcpp::SHF_WRITE
),
1478 this->got_
, ORDER_RELRO_LAST
,
1481 // Add the three reserved entries.
1482 this->got_plt_
= new Output_data_space((plt_count
+ 3) * 8, 8, "** GOT PLT");
1483 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
1485 | elfcpp::SHF_WRITE
),
1486 this->got_plt_
, ORDER_NON_RELRO_FIRST
,
1489 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
1490 this->global_offset_table_
=
1491 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1492 Symbol_table::PREDEFINED
,
1494 0, 0, elfcpp::STT_OBJECT
,
1496 elfcpp::STV_HIDDEN
, 0,
1499 // If there are any TLSDESC relocations, they get GOT entries in
1500 // .got.plt after the jump slot entries.
1501 // FIXME: Get the count for TLSDESC entries.
1502 this->got_tlsdesc_
= new Output_data_got
<64, false>(0);
1503 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
1504 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1506 ORDER_NON_RELRO_FIRST
, false);
1508 // If there are any IRELATIVE relocations, they get GOT entries in
1509 // .got.plt after the jump slot and TLSDESC entries.
1510 this->got_irelative_
= new Output_data_space(0, 8, "** GOT IRELATIVE PLT");
1511 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
1512 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1513 this->got_irelative_
,
1514 ORDER_NON_RELRO_FIRST
, false);
1516 // Create the PLT section.
1517 this->plt_
= new Output_data_plt_x86_64(layout
, this->got_
, this->got_plt_
,
1518 this->got_irelative_
, plt_count
);
1519 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1520 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
1521 this->plt_
, ORDER_PLT
, false);
1523 // Make the sh_info field of .rela.plt point to .plt.
1524 Output_section
* rela_plt_os
= this->plt_
->rela_plt()->output_section();
1525 rela_plt_os
->set_info_section(this->plt_
->output_section());
1527 // Create the rela_dyn section.
1528 this->rela_dyn_section(layout
);
1533 // Reserve a GOT entry for a local symbol, and regenerate any
1534 // necessary dynamic relocations.
1537 Target_x86_64::reserve_local_got_entry(
1538 unsigned int got_index
,
1539 Sized_relobj
<64, false>* obj
,
1541 unsigned int got_type
)
1543 unsigned int got_offset
= got_index
* 8;
1544 Reloc_section
* rela_dyn
= this->rela_dyn_section(NULL
);
1546 this->got_
->reserve_local(got_index
, obj
, r_sym
, got_type
);
1549 case GOT_TYPE_STANDARD
:
1550 if (parameters
->options().output_is_position_independent())
1551 rela_dyn
->add_local_relative(obj
, r_sym
, elfcpp::R_X86_64_RELATIVE
,
1552 this->got_
, got_offset
, 0, false);
1554 case GOT_TYPE_TLS_OFFSET
:
1555 rela_dyn
->add_local(obj
, r_sym
, elfcpp::R_X86_64_TPOFF64
,
1556 this->got_
, got_offset
, 0);
1558 case GOT_TYPE_TLS_PAIR
:
1559 this->got_
->reserve_slot(got_index
+ 1);
1560 rela_dyn
->add_local(obj
, r_sym
, elfcpp::R_X86_64_DTPMOD64
,
1561 this->got_
, got_offset
, 0);
1563 case GOT_TYPE_TLS_DESC
:
1564 gold_fatal(_("TLS_DESC not yet supported for incremental linking"));
1565 // this->got_->reserve_slot(got_index + 1);
1566 // rela_dyn->add_target_specific(elfcpp::R_X86_64_TLSDESC, arg,
1567 // this->got_, got_offset, 0);
1574 // Reserve a GOT entry for a global symbol, and regenerate any
1575 // necessary dynamic relocations.
1578 Target_x86_64::reserve_global_got_entry(unsigned int got_index
, Symbol
* gsym
,
1579 unsigned int got_type
)
1581 unsigned int got_offset
= got_index
* 8;
1582 Reloc_section
* rela_dyn
= this->rela_dyn_section(NULL
);
1584 this->got_
->reserve_global(got_index
, gsym
, got_type
);
1587 case GOT_TYPE_STANDARD
:
1588 if (!gsym
->final_value_is_known())
1590 if (gsym
->is_from_dynobj()
1591 || gsym
->is_undefined()
1592 || gsym
->is_preemptible()
1593 || gsym
->type() == elfcpp::STT_GNU_IFUNC
)
1594 rela_dyn
->add_global(gsym
, elfcpp::R_X86_64_GLOB_DAT
,
1595 this->got_
, got_offset
, 0);
1597 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_RELATIVE
,
1598 this->got_
, got_offset
, 0);
1601 case GOT_TYPE_TLS_OFFSET
:
1602 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_TPOFF64
,
1603 this->got_
, got_offset
, 0);
1605 case GOT_TYPE_TLS_PAIR
:
1606 this->got_
->reserve_slot(got_index
+ 1);
1607 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_DTPMOD64
,
1608 this->got_
, got_offset
, 0);
1609 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_DTPOFF64
,
1610 this->got_
, got_offset
+ 8, 0);
1612 case GOT_TYPE_TLS_DESC
:
1613 this->got_
->reserve_slot(got_index
+ 1);
1614 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_TLSDESC
,
1615 this->got_
, got_offset
, 0);
1622 // Register an existing PLT entry for a global symbol.
1625 Target_x86_64::register_global_plt_entry(Symbol_table
* symtab
,
1627 unsigned int plt_index
,
1630 gold_assert(this->plt_
!= NULL
);
1631 gold_assert(!gsym
->has_plt_offset());
1633 this->plt_
->reserve_slot(plt_index
);
1635 gsym
->set_plt_offset((plt_index
+ 1) * this->plt_entry_size());
1637 unsigned int got_offset
= (plt_index
+ 3) * 8;
1638 this->plt_
->add_relocation(symtab
, layout
, gsym
, got_offset
);
1641 // Force a COPY relocation for a given symbol.
1644 Target_x86_64::emit_copy_reloc(
1645 Symbol_table
* symtab
, Symbol
* sym
, Output_section
* os
, off_t offset
)
1647 this->copy_relocs_
.emit_copy_reloc(symtab
,
1648 symtab
->get_sized_symbol
<64>(sym
),
1651 this->rela_dyn_section(NULL
));
1654 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
1657 Target_x86_64::define_tls_base_symbol(Symbol_table
* symtab
, Layout
* layout
)
1659 if (this->tls_base_symbol_defined_
)
1662 Output_segment
* tls_segment
= layout
->tls_segment();
1663 if (tls_segment
!= NULL
)
1665 bool is_exec
= parameters
->options().output_is_executable();
1666 symtab
->define_in_output_segment("_TLS_MODULE_BASE_", NULL
,
1667 Symbol_table::PREDEFINED
,
1671 elfcpp::STV_HIDDEN
, 0,
1673 ? Symbol::SEGMENT_END
1674 : Symbol::SEGMENT_START
),
1677 this->tls_base_symbol_defined_
= true;
1680 // Create the reserved PLT and GOT entries for the TLS descriptor resolver.
1683 Target_x86_64::reserve_tlsdesc_entries(Symbol_table
* symtab
,
1686 if (this->plt_
== NULL
)
1687 this->make_plt_section(symtab
, layout
);
1689 if (!this->plt_
->has_tlsdesc_entry())
1691 // Allocate the TLSDESC_GOT entry.
1692 Output_data_got
<64, false>* got
= this->got_section(symtab
, layout
);
1693 unsigned int got_offset
= got
->add_constant(0);
1695 // Allocate the TLSDESC_PLT entry.
1696 this->plt_
->reserve_tlsdesc_entry(got_offset
);
1700 // Create a GOT entry for the TLS module index.
1703 Target_x86_64::got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
1704 Sized_relobj_file
<64, false>* object
)
1706 if (this->got_mod_index_offset_
== -1U)
1708 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1709 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1710 Output_data_got
<64, false>* got
= this->got_section(symtab
, layout
);
1711 unsigned int got_offset
= got
->add_constant(0);
1712 rela_dyn
->add_local(object
, 0, elfcpp::R_X86_64_DTPMOD64
, got
,
1714 got
->add_constant(0);
1715 this->got_mod_index_offset_
= got_offset
;
1717 return this->got_mod_index_offset_
;
1720 // Optimize the TLS relocation type based on what we know about the
1721 // symbol. IS_FINAL is true if the final address of this symbol is
1722 // known at link time.
1724 tls::Tls_optimization
1725 Target_x86_64::optimize_tls_reloc(bool is_final
, int r_type
)
1727 // If we are generating a shared library, then we can't do anything
1729 if (parameters
->options().shared())
1730 return tls::TLSOPT_NONE
;
1734 case elfcpp::R_X86_64_TLSGD
:
1735 case elfcpp::R_X86_64_GOTPC32_TLSDESC
:
1736 case elfcpp::R_X86_64_TLSDESC_CALL
:
1737 // These are General-Dynamic which permits fully general TLS
1738 // access. Since we know that we are generating an executable,
1739 // we can convert this to Initial-Exec. If we also know that
1740 // this is a local symbol, we can further switch to Local-Exec.
1742 return tls::TLSOPT_TO_LE
;
1743 return tls::TLSOPT_TO_IE
;
1745 case elfcpp::R_X86_64_TLSLD
:
1746 // This is Local-Dynamic, which refers to a local symbol in the
1747 // dynamic TLS block. Since we know that we generating an
1748 // executable, we can switch to Local-Exec.
1749 return tls::TLSOPT_TO_LE
;
1751 case elfcpp::R_X86_64_DTPOFF32
:
1752 case elfcpp::R_X86_64_DTPOFF64
:
1753 // Another Local-Dynamic reloc.
1754 return tls::TLSOPT_TO_LE
;
1756 case elfcpp::R_X86_64_GOTTPOFF
:
1757 // These are Initial-Exec relocs which get the thread offset
1758 // from the GOT. If we know that we are linking against the
1759 // local symbol, we can switch to Local-Exec, which links the
1760 // thread offset into the instruction.
1762 return tls::TLSOPT_TO_LE
;
1763 return tls::TLSOPT_NONE
;
1765 case elfcpp::R_X86_64_TPOFF32
:
1766 // When we already have Local-Exec, there is nothing further we
1768 return tls::TLSOPT_NONE
;
1775 // Get the Reference_flags for a particular relocation.
1778 Target_x86_64::Scan::get_reference_flags(unsigned int r_type
)
1782 case elfcpp::R_X86_64_NONE
:
1783 case elfcpp::R_X86_64_GNU_VTINHERIT
:
1784 case elfcpp::R_X86_64_GNU_VTENTRY
:
1785 case elfcpp::R_X86_64_GOTPC32
:
1786 case elfcpp::R_X86_64_GOTPC64
:
1787 // No symbol reference.
1790 case elfcpp::R_X86_64_64
:
1791 case elfcpp::R_X86_64_32
:
1792 case elfcpp::R_X86_64_32S
:
1793 case elfcpp::R_X86_64_16
:
1794 case elfcpp::R_X86_64_8
:
1795 return Symbol::ABSOLUTE_REF
;
1797 case elfcpp::R_X86_64_PC64
:
1798 case elfcpp::R_X86_64_PC32
:
1799 case elfcpp::R_X86_64_PC16
:
1800 case elfcpp::R_X86_64_PC8
:
1801 case elfcpp::R_X86_64_GOTOFF64
:
1802 return Symbol::RELATIVE_REF
;
1804 case elfcpp::R_X86_64_PLT32
:
1805 case elfcpp::R_X86_64_PLTOFF64
:
1806 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
1808 case elfcpp::R_X86_64_GOT64
:
1809 case elfcpp::R_X86_64_GOT32
:
1810 case elfcpp::R_X86_64_GOTPCREL64
:
1811 case elfcpp::R_X86_64_GOTPCREL
:
1812 case elfcpp::R_X86_64_GOTPLT64
:
1814 return Symbol::ABSOLUTE_REF
;
1816 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
1817 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
1818 case elfcpp::R_X86_64_TLSDESC_CALL
:
1819 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
1820 case elfcpp::R_X86_64_DTPOFF32
:
1821 case elfcpp::R_X86_64_DTPOFF64
:
1822 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
1823 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
1824 return Symbol::TLS_REF
;
1826 case elfcpp::R_X86_64_COPY
:
1827 case elfcpp::R_X86_64_GLOB_DAT
:
1828 case elfcpp::R_X86_64_JUMP_SLOT
:
1829 case elfcpp::R_X86_64_RELATIVE
:
1830 case elfcpp::R_X86_64_IRELATIVE
:
1831 case elfcpp::R_X86_64_TPOFF64
:
1832 case elfcpp::R_X86_64_DTPMOD64
:
1833 case elfcpp::R_X86_64_TLSDESC
:
1834 case elfcpp::R_X86_64_SIZE32
:
1835 case elfcpp::R_X86_64_SIZE64
:
1837 // Not expected. We will give an error later.
1842 // Report an unsupported relocation against a local symbol.
1845 Target_x86_64::Scan::unsupported_reloc_local(
1846 Sized_relobj_file
<64, false>* object
,
1847 unsigned int r_type
)
1849 gold_error(_("%s: unsupported reloc %u against local symbol"),
1850 object
->name().c_str(), r_type
);
1853 // We are about to emit a dynamic relocation of type R_TYPE. If the
1854 // dynamic linker does not support it, issue an error. The GNU linker
1855 // only issues a non-PIC error for an allocated read-only section.
1856 // Here we know the section is allocated, but we don't know that it is
1857 // read-only. But we check for all the relocation types which the
1858 // glibc dynamic linker supports, so it seems appropriate to issue an
1859 // error even if the section is not read-only. If GSYM is not NULL,
1860 // it is the symbol the relocation is against; if it is NULL, the
1861 // relocation is against a local symbol.
1864 Target_x86_64::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
,
1869 // These are the relocation types supported by glibc for x86_64
1870 // which should always work.
1871 case elfcpp::R_X86_64_RELATIVE
:
1872 case elfcpp::R_X86_64_IRELATIVE
:
1873 case elfcpp::R_X86_64_GLOB_DAT
:
1874 case elfcpp::R_X86_64_JUMP_SLOT
:
1875 case elfcpp::R_X86_64_DTPMOD64
:
1876 case elfcpp::R_X86_64_DTPOFF64
:
1877 case elfcpp::R_X86_64_TPOFF64
:
1878 case elfcpp::R_X86_64_64
:
1879 case elfcpp::R_X86_64_COPY
:
1882 // glibc supports these reloc types, but they can overflow.
1883 case elfcpp::R_X86_64_PC32
:
1884 // A PC relative reference is OK against a local symbol or if
1885 // the symbol is defined locally.
1887 || (!gsym
->is_from_dynobj()
1888 && !gsym
->is_undefined()
1889 && !gsym
->is_preemptible()))
1892 case elfcpp::R_X86_64_32
:
1893 if (this->issued_non_pic_error_
)
1895 gold_assert(parameters
->options().output_is_position_independent());
1897 object
->error(_("requires dynamic R_X86_64_32 reloc which may "
1898 "overflow at runtime; recompile with -fPIC"));
1900 object
->error(_("requires dynamic %s reloc against '%s' which may "
1901 "overflow at runtime; recompile with -fPIC"),
1902 (r_type
== elfcpp::R_X86_64_32
1906 this->issued_non_pic_error_
= true;
1910 // This prevents us from issuing more than one error per reloc
1911 // section. But we can still wind up issuing more than one
1912 // error per object file.
1913 if (this->issued_non_pic_error_
)
1915 gold_assert(parameters
->options().output_is_position_independent());
1916 object
->error(_("requires unsupported dynamic reloc %u; "
1917 "recompile with -fPIC"),
1919 this->issued_non_pic_error_
= true;
1922 case elfcpp::R_X86_64_NONE
:
1927 // Return whether we need to make a PLT entry for a relocation of the
1928 // given type against a STT_GNU_IFUNC symbol.
1931 Target_x86_64::Scan::reloc_needs_plt_for_ifunc(
1932 Sized_relobj_file
<64, false>* object
,
1933 unsigned int r_type
)
1935 int flags
= Scan::get_reference_flags(r_type
);
1936 if (flags
& Symbol::TLS_REF
)
1937 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
1938 object
->name().c_str(), r_type
);
1942 // Scan a relocation for a local symbol.
1945 Target_x86_64::Scan::local(Symbol_table
* symtab
,
1947 Target_x86_64
* target
,
1948 Sized_relobj_file
<64, false>* object
,
1949 unsigned int data_shndx
,
1950 Output_section
* output_section
,
1951 const elfcpp::Rela
<64, false>& reloc
,
1952 unsigned int r_type
,
1953 const elfcpp::Sym
<64, false>& lsym
)
1955 // A local STT_GNU_IFUNC symbol may require a PLT entry.
1956 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
1957 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
1959 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(reloc
.get_r_info());
1960 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
1965 case elfcpp::R_X86_64_NONE
:
1966 case elfcpp::R_X86_64_GNU_VTINHERIT
:
1967 case elfcpp::R_X86_64_GNU_VTENTRY
:
1970 case elfcpp::R_X86_64_64
:
1971 // If building a shared library (or a position-independent
1972 // executable), we need to create a dynamic relocation for this
1973 // location. The relocation applied at link time will apply the
1974 // link-time value, so we flag the location with an
1975 // R_X86_64_RELATIVE relocation so the dynamic loader can
1976 // relocate it easily.
1977 if (parameters
->options().output_is_position_independent())
1979 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(reloc
.get_r_info());
1980 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1981 rela_dyn
->add_local_relative(object
, r_sym
,
1982 elfcpp::R_X86_64_RELATIVE
,
1983 output_section
, data_shndx
,
1984 reloc
.get_r_offset(),
1985 reloc
.get_r_addend(), is_ifunc
);
1989 case elfcpp::R_X86_64_32
:
1990 case elfcpp::R_X86_64_32S
:
1991 case elfcpp::R_X86_64_16
:
1992 case elfcpp::R_X86_64_8
:
1993 // If building a shared library (or a position-independent
1994 // executable), we need to create a dynamic relocation for this
1995 // location. We can't use an R_X86_64_RELATIVE relocation
1996 // because that is always a 64-bit relocation.
1997 if (parameters
->options().output_is_position_independent())
1999 this->check_non_pic(object
, r_type
, NULL
);
2001 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2002 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(reloc
.get_r_info());
2003 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2004 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
2005 data_shndx
, reloc
.get_r_offset(),
2006 reloc
.get_r_addend());
2009 gold_assert(lsym
.get_st_value() == 0);
2010 unsigned int shndx
= lsym
.get_st_shndx();
2012 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
2015 object
->error(_("section symbol %u has bad shndx %u"),
2018 rela_dyn
->add_local_section(object
, shndx
,
2019 r_type
, output_section
,
2020 data_shndx
, reloc
.get_r_offset(),
2021 reloc
.get_r_addend());
2026 case elfcpp::R_X86_64_PC64
:
2027 case elfcpp::R_X86_64_PC32
:
2028 case elfcpp::R_X86_64_PC16
:
2029 case elfcpp::R_X86_64_PC8
:
2032 case elfcpp::R_X86_64_PLT32
:
2033 // Since we know this is a local symbol, we can handle this as a
2037 case elfcpp::R_X86_64_GOTPC32
:
2038 case elfcpp::R_X86_64_GOTOFF64
:
2039 case elfcpp::R_X86_64_GOTPC64
:
2040 case elfcpp::R_X86_64_PLTOFF64
:
2041 // We need a GOT section.
2042 target
->got_section(symtab
, layout
);
2043 // For PLTOFF64, we'd normally want a PLT section, but since we
2044 // know this is a local symbol, no PLT is needed.
2047 case elfcpp::R_X86_64_GOT64
:
2048 case elfcpp::R_X86_64_GOT32
:
2049 case elfcpp::R_X86_64_GOTPCREL64
:
2050 case elfcpp::R_X86_64_GOTPCREL
:
2051 case elfcpp::R_X86_64_GOTPLT64
:
2053 // The symbol requires a GOT entry.
2054 Output_data_got
<64, false>* got
= target
->got_section(symtab
, layout
);
2055 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(reloc
.get_r_info());
2057 // For a STT_GNU_IFUNC symbol we want the PLT offset. That
2058 // lets function pointers compare correctly with shared
2059 // libraries. Otherwise we would need an IRELATIVE reloc.
2062 is_new
= got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
2064 is_new
= got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2067 // If we are generating a shared object, we need to add a
2068 // dynamic relocation for this symbol's GOT entry.
2069 if (parameters
->options().output_is_position_independent())
2071 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2072 // R_X86_64_RELATIVE assumes a 64-bit relocation.
2073 if (r_type
!= elfcpp::R_X86_64_GOT32
)
2075 unsigned int got_offset
=
2076 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2077 rela_dyn
->add_local_relative(object
, r_sym
,
2078 elfcpp::R_X86_64_RELATIVE
,
2079 got
, got_offset
, 0, is_ifunc
);
2083 this->check_non_pic(object
, r_type
, NULL
);
2085 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2086 rela_dyn
->add_local(
2087 object
, r_sym
, r_type
, got
,
2088 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
), 0);
2092 // For GOTPLT64, we'd normally want a PLT section, but since
2093 // we know this is a local symbol, no PLT is needed.
2097 case elfcpp::R_X86_64_COPY
:
2098 case elfcpp::R_X86_64_GLOB_DAT
:
2099 case elfcpp::R_X86_64_JUMP_SLOT
:
2100 case elfcpp::R_X86_64_RELATIVE
:
2101 case elfcpp::R_X86_64_IRELATIVE
:
2102 // These are outstanding tls relocs, which are unexpected when linking
2103 case elfcpp::R_X86_64_TPOFF64
:
2104 case elfcpp::R_X86_64_DTPMOD64
:
2105 case elfcpp::R_X86_64_TLSDESC
:
2106 gold_error(_("%s: unexpected reloc %u in object file"),
2107 object
->name().c_str(), r_type
);
2110 // These are initial tls relocs, which are expected when linking
2111 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
2112 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
2113 case elfcpp::R_X86_64_TLSDESC_CALL
:
2114 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
2115 case elfcpp::R_X86_64_DTPOFF32
:
2116 case elfcpp::R_X86_64_DTPOFF64
:
2117 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
2118 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
2120 bool output_is_shared
= parameters
->options().shared();
2121 const tls::Tls_optimization optimized_type
2122 = Target_x86_64::optimize_tls_reloc(!output_is_shared
, r_type
);
2125 case elfcpp::R_X86_64_TLSGD
: // General-dynamic
2126 if (optimized_type
== tls::TLSOPT_NONE
)
2128 // Create a pair of GOT entries for the module index and
2129 // dtv-relative offset.
2130 Output_data_got
<64, false>* got
2131 = target
->got_section(symtab
, layout
);
2132 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(reloc
.get_r_info());
2133 unsigned int shndx
= lsym
.get_st_shndx();
2135 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2137 object
->error(_("local symbol %u has bad shndx %u"),
2140 got
->add_local_pair_with_rela(object
, r_sym
,
2143 target
->rela_dyn_section(layout
),
2144 elfcpp::R_X86_64_DTPMOD64
, 0);
2146 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2147 unsupported_reloc_local(object
, r_type
);
2150 case elfcpp::R_X86_64_GOTPC32_TLSDESC
:
2151 target
->define_tls_base_symbol(symtab
, layout
);
2152 if (optimized_type
== tls::TLSOPT_NONE
)
2154 // Create reserved PLT and GOT entries for the resolver.
2155 target
->reserve_tlsdesc_entries(symtab
, layout
);
2157 // Generate a double GOT entry with an
2158 // R_X86_64_TLSDESC reloc. The R_X86_64_TLSDESC reloc
2159 // is resolved lazily, so the GOT entry needs to be in
2160 // an area in .got.plt, not .got. Call got_section to
2161 // make sure the section has been created.
2162 target
->got_section(symtab
, layout
);
2163 Output_data_got
<64, false>* got
= target
->got_tlsdesc_section();
2164 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(reloc
.get_r_info());
2165 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_DESC
))
2167 unsigned int got_offset
= got
->add_constant(0);
2168 got
->add_constant(0);
2169 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_DESC
,
2171 Reloc_section
* rt
= target
->rela_tlsdesc_section(layout
);
2172 // We store the arguments we need in a vector, and
2173 // use the index into the vector as the parameter
2174 // to pass to the target specific routines.
2175 uintptr_t intarg
= target
->add_tlsdesc_info(object
, r_sym
);
2176 void* arg
= reinterpret_cast<void*>(intarg
);
2177 rt
->add_target_specific(elfcpp::R_X86_64_TLSDESC
, arg
,
2178 got
, got_offset
, 0);
2181 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2182 unsupported_reloc_local(object
, r_type
);
2185 case elfcpp::R_X86_64_TLSDESC_CALL
:
2188 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
2189 if (optimized_type
== tls::TLSOPT_NONE
)
2191 // Create a GOT entry for the module index.
2192 target
->got_mod_index_entry(symtab
, layout
, object
);
2194 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2195 unsupported_reloc_local(object
, r_type
);
2198 case elfcpp::R_X86_64_DTPOFF32
:
2199 case elfcpp::R_X86_64_DTPOFF64
:
2202 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
2203 layout
->set_has_static_tls();
2204 if (optimized_type
== tls::TLSOPT_NONE
)
2206 // Create a GOT entry for the tp-relative offset.
2207 Output_data_got
<64, false>* got
2208 = target
->got_section(symtab
, layout
);
2209 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(reloc
.get_r_info());
2210 got
->add_local_with_rela(object
, r_sym
, GOT_TYPE_TLS_OFFSET
,
2211 target
->rela_dyn_section(layout
),
2212 elfcpp::R_X86_64_TPOFF64
);
2214 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2215 unsupported_reloc_local(object
, r_type
);
2218 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
2219 layout
->set_has_static_tls();
2220 if (output_is_shared
)
2221 unsupported_reloc_local(object
, r_type
);
2230 case elfcpp::R_X86_64_SIZE32
:
2231 case elfcpp::R_X86_64_SIZE64
:
2233 gold_error(_("%s: unsupported reloc %u against local symbol"),
2234 object
->name().c_str(), r_type
);
2240 // Report an unsupported relocation against a global symbol.
2243 Target_x86_64::Scan::unsupported_reloc_global(
2244 Sized_relobj_file
<64, false>* object
,
2245 unsigned int r_type
,
2248 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2249 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2252 // Returns true if this relocation type could be that of a function pointer.
2254 Target_x86_64::Scan::possible_function_pointer_reloc(unsigned int r_type
)
2258 case elfcpp::R_X86_64_64
:
2259 case elfcpp::R_X86_64_32
:
2260 case elfcpp::R_X86_64_32S
:
2261 case elfcpp::R_X86_64_16
:
2262 case elfcpp::R_X86_64_8
:
2263 case elfcpp::R_X86_64_GOT64
:
2264 case elfcpp::R_X86_64_GOT32
:
2265 case elfcpp::R_X86_64_GOTPCREL64
:
2266 case elfcpp::R_X86_64_GOTPCREL
:
2267 case elfcpp::R_X86_64_GOTPLT64
:
2275 // For safe ICF, scan a relocation for a local symbol to check if it
2276 // corresponds to a function pointer being taken. In that case mark
2277 // the function whose pointer was taken as not foldable.
2280 Target_x86_64::Scan::local_reloc_may_be_function_pointer(
2284 Sized_relobj_file
<64, false>* ,
2287 const elfcpp::Rela
<64, false>& ,
2288 unsigned int r_type
,
2289 const elfcpp::Sym
<64, false>&)
2291 // When building a shared library, do not fold any local symbols as it is
2292 // not possible to distinguish pointer taken versus a call by looking at
2293 // the relocation types.
2294 return (parameters
->options().shared()
2295 || possible_function_pointer_reloc(r_type
));
2298 // For safe ICF, scan a relocation for a global symbol to check if it
2299 // corresponds to a function pointer being taken. In that case mark
2300 // the function whose pointer was taken as not foldable.
2303 Target_x86_64::Scan::global_reloc_may_be_function_pointer(
2307 Sized_relobj_file
<64, false>* ,
2310 const elfcpp::Rela
<64, false>& ,
2311 unsigned int r_type
,
2314 // When building a shared library, do not fold symbols whose visibility
2315 // is hidden, internal or protected.
2316 return ((parameters
->options().shared()
2317 && (gsym
->visibility() == elfcpp::STV_INTERNAL
2318 || gsym
->visibility() == elfcpp::STV_PROTECTED
2319 || gsym
->visibility() == elfcpp::STV_HIDDEN
))
2320 || possible_function_pointer_reloc(r_type
));
2323 // Scan a relocation for a global symbol.
2326 Target_x86_64::Scan::global(Symbol_table
* symtab
,
2328 Target_x86_64
* target
,
2329 Sized_relobj_file
<64, false>* object
,
2330 unsigned int data_shndx
,
2331 Output_section
* output_section
,
2332 const elfcpp::Rela
<64, false>& reloc
,
2333 unsigned int r_type
,
2336 // A STT_GNU_IFUNC symbol may require a PLT entry.
2337 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
2338 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2339 target
->make_plt_entry(symtab
, layout
, gsym
);
2343 case elfcpp::R_X86_64_NONE
:
2344 case elfcpp::R_X86_64_GNU_VTINHERIT
:
2345 case elfcpp::R_X86_64_GNU_VTENTRY
:
2348 case elfcpp::R_X86_64_64
:
2349 case elfcpp::R_X86_64_32
:
2350 case elfcpp::R_X86_64_32S
:
2351 case elfcpp::R_X86_64_16
:
2352 case elfcpp::R_X86_64_8
:
2354 // Make a PLT entry if necessary.
2355 if (gsym
->needs_plt_entry())
2357 target
->make_plt_entry(symtab
, layout
, gsym
);
2358 // Since this is not a PC-relative relocation, we may be
2359 // taking the address of a function. In that case we need to
2360 // set the entry in the dynamic symbol table to the address of
2362 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2363 gsym
->set_needs_dynsym_value();
2365 // Make a dynamic relocation if necessary.
2366 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2368 if (gsym
->may_need_copy_reloc())
2370 target
->copy_reloc(symtab
, layout
, object
,
2371 data_shndx
, output_section
, gsym
, reloc
);
2373 else if (r_type
== elfcpp::R_X86_64_64
2374 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2375 && gsym
->can_use_relative_reloc(false)
2376 && !gsym
->is_from_dynobj()
2377 && !gsym
->is_undefined()
2378 && !gsym
->is_preemptible())
2380 // Use an IRELATIVE reloc for a locally defined
2381 // STT_GNU_IFUNC symbol. This makes a function
2382 // address in a PIE executable match the address in a
2383 // shared library that it links against.
2384 Reloc_section
* rela_dyn
=
2385 target
->rela_irelative_section(layout
);
2386 unsigned int r_type
= elfcpp::R_X86_64_IRELATIVE
;
2387 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2388 output_section
, object
,
2390 reloc
.get_r_offset(),
2391 reloc
.get_r_addend());
2393 else if (r_type
== elfcpp::R_X86_64_64
2394 && gsym
->can_use_relative_reloc(false))
2396 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2397 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_RELATIVE
,
2398 output_section
, object
,
2400 reloc
.get_r_offset(),
2401 reloc
.get_r_addend());
2405 this->check_non_pic(object
, r_type
, gsym
);
2406 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2407 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2408 data_shndx
, reloc
.get_r_offset(),
2409 reloc
.get_r_addend());
2415 case elfcpp::R_X86_64_PC64
:
2416 case elfcpp::R_X86_64_PC32
:
2417 case elfcpp::R_X86_64_PC16
:
2418 case elfcpp::R_X86_64_PC8
:
2420 // Make a PLT entry if necessary.
2421 if (gsym
->needs_plt_entry())
2422 target
->make_plt_entry(symtab
, layout
, gsym
);
2423 // Make a dynamic relocation if necessary.
2424 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2426 if (gsym
->may_need_copy_reloc())
2428 target
->copy_reloc(symtab
, layout
, object
,
2429 data_shndx
, output_section
, gsym
, reloc
);
2433 this->check_non_pic(object
, r_type
, gsym
);
2434 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2435 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2436 data_shndx
, reloc
.get_r_offset(),
2437 reloc
.get_r_addend());
2443 case elfcpp::R_X86_64_GOT64
:
2444 case elfcpp::R_X86_64_GOT32
:
2445 case elfcpp::R_X86_64_GOTPCREL64
:
2446 case elfcpp::R_X86_64_GOTPCREL
:
2447 case elfcpp::R_X86_64_GOTPLT64
:
2449 // The symbol requires a GOT entry.
2450 Output_data_got
<64, false>* got
= target
->got_section(symtab
, layout
);
2451 if (gsym
->final_value_is_known())
2453 // For a STT_GNU_IFUNC symbol we want the PLT address.
2454 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2455 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2457 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2461 // If this symbol is not fully resolved, we need to add a
2462 // dynamic relocation for it.
2463 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2465 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2467 // 1) The symbol may be defined in some other module.
2469 // 2) We are building a shared library and this is a
2470 // protected symbol; using GLOB_DAT means that the dynamic
2471 // linker can use the address of the PLT in the main
2472 // executable when appropriate so that function address
2473 // comparisons work.
2475 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2476 // code, again so that function address comparisons work.
2477 if (gsym
->is_from_dynobj()
2478 || gsym
->is_undefined()
2479 || gsym
->is_preemptible()
2480 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2481 && parameters
->options().shared())
2482 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2483 && parameters
->options().output_is_position_independent()))
2484 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2485 elfcpp::R_X86_64_GLOB_DAT
);
2488 // For a STT_GNU_IFUNC symbol we want to write the PLT
2489 // offset into the GOT, so that function pointer
2490 // comparisons work correctly.
2492 if (gsym
->type() != elfcpp::STT_GNU_IFUNC
)
2493 is_new
= got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2496 is_new
= got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2497 // Tell the dynamic linker to use the PLT address
2498 // when resolving relocations.
2499 if (gsym
->is_from_dynobj()
2500 && !parameters
->options().shared())
2501 gsym
->set_needs_dynsym_value();
2505 unsigned int got_off
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2506 rela_dyn
->add_global_relative(gsym
,
2507 elfcpp::R_X86_64_RELATIVE
,
2512 // For GOTPLT64, we also need a PLT entry (but only if the
2513 // symbol is not fully resolved).
2514 if (r_type
== elfcpp::R_X86_64_GOTPLT64
2515 && !gsym
->final_value_is_known())
2516 target
->make_plt_entry(symtab
, layout
, gsym
);
2520 case elfcpp::R_X86_64_PLT32
:
2521 // If the symbol is fully resolved, this is just a PC32 reloc.
2522 // Otherwise we need a PLT entry.
2523 if (gsym
->final_value_is_known())
2525 // If building a shared library, we can also skip the PLT entry
2526 // if the symbol is defined in the output file and is protected
2528 if (gsym
->is_defined()
2529 && !gsym
->is_from_dynobj()
2530 && !gsym
->is_preemptible())
2532 target
->make_plt_entry(symtab
, layout
, gsym
);
2535 case elfcpp::R_X86_64_GOTPC32
:
2536 case elfcpp::R_X86_64_GOTOFF64
:
2537 case elfcpp::R_X86_64_GOTPC64
:
2538 case elfcpp::R_X86_64_PLTOFF64
:
2539 // We need a GOT section.
2540 target
->got_section(symtab
, layout
);
2541 // For PLTOFF64, we also need a PLT entry (but only if the
2542 // symbol is not fully resolved).
2543 if (r_type
== elfcpp::R_X86_64_PLTOFF64
2544 && !gsym
->final_value_is_known())
2545 target
->make_plt_entry(symtab
, layout
, gsym
);
2548 case elfcpp::R_X86_64_COPY
:
2549 case elfcpp::R_X86_64_GLOB_DAT
:
2550 case elfcpp::R_X86_64_JUMP_SLOT
:
2551 case elfcpp::R_X86_64_RELATIVE
:
2552 case elfcpp::R_X86_64_IRELATIVE
:
2553 // These are outstanding tls relocs, which are unexpected when linking
2554 case elfcpp::R_X86_64_TPOFF64
:
2555 case elfcpp::R_X86_64_DTPMOD64
:
2556 case elfcpp::R_X86_64_TLSDESC
:
2557 gold_error(_("%s: unexpected reloc %u in object file"),
2558 object
->name().c_str(), r_type
);
2561 // These are initial tls relocs, which are expected for global()
2562 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
2563 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
2564 case elfcpp::R_X86_64_TLSDESC_CALL
:
2565 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
2566 case elfcpp::R_X86_64_DTPOFF32
:
2567 case elfcpp::R_X86_64_DTPOFF64
:
2568 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
2569 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
2571 const bool is_final
= gsym
->final_value_is_known();
2572 const tls::Tls_optimization optimized_type
2573 = Target_x86_64::optimize_tls_reloc(is_final
, r_type
);
2576 case elfcpp::R_X86_64_TLSGD
: // General-dynamic
2577 if (optimized_type
== tls::TLSOPT_NONE
)
2579 // Create a pair of GOT entries for the module index and
2580 // dtv-relative offset.
2581 Output_data_got
<64, false>* got
2582 = target
->got_section(symtab
, layout
);
2583 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2584 target
->rela_dyn_section(layout
),
2585 elfcpp::R_X86_64_DTPMOD64
,
2586 elfcpp::R_X86_64_DTPOFF64
);
2588 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2590 // Create a GOT entry for the tp-relative offset.
2591 Output_data_got
<64, false>* got
2592 = target
->got_section(symtab
, layout
);
2593 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2594 target
->rela_dyn_section(layout
),
2595 elfcpp::R_X86_64_TPOFF64
);
2597 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2598 unsupported_reloc_global(object
, r_type
, gsym
);
2601 case elfcpp::R_X86_64_GOTPC32_TLSDESC
:
2602 target
->define_tls_base_symbol(symtab
, layout
);
2603 if (optimized_type
== tls::TLSOPT_NONE
)
2605 // Create reserved PLT and GOT entries for the resolver.
2606 target
->reserve_tlsdesc_entries(symtab
, layout
);
2608 // Create a double GOT entry with an R_X86_64_TLSDESC
2609 // reloc. The R_X86_64_TLSDESC reloc is resolved
2610 // lazily, so the GOT entry needs to be in an area in
2611 // .got.plt, not .got. Call got_section to make sure
2612 // the section has been created.
2613 target
->got_section(symtab
, layout
);
2614 Output_data_got
<64, false>* got
= target
->got_tlsdesc_section();
2615 Reloc_section
* rt
= target
->rela_tlsdesc_section(layout
);
2616 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_DESC
, rt
,
2617 elfcpp::R_X86_64_TLSDESC
, 0);
2619 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2621 // Create a GOT entry for the tp-relative offset.
2622 Output_data_got
<64, false>* got
2623 = target
->got_section(symtab
, layout
);
2624 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2625 target
->rela_dyn_section(layout
),
2626 elfcpp::R_X86_64_TPOFF64
);
2628 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2629 unsupported_reloc_global(object
, r_type
, gsym
);
2632 case elfcpp::R_X86_64_TLSDESC_CALL
:
2635 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
2636 if (optimized_type
== tls::TLSOPT_NONE
)
2638 // Create a GOT entry for the module index.
2639 target
->got_mod_index_entry(symtab
, layout
, object
);
2641 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2642 unsupported_reloc_global(object
, r_type
, gsym
);
2645 case elfcpp::R_X86_64_DTPOFF32
:
2646 case elfcpp::R_X86_64_DTPOFF64
:
2649 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
2650 layout
->set_has_static_tls();
2651 if (optimized_type
== tls::TLSOPT_NONE
)
2653 // Create a GOT entry for the tp-relative offset.
2654 Output_data_got
<64, false>* got
2655 = target
->got_section(symtab
, layout
);
2656 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2657 target
->rela_dyn_section(layout
),
2658 elfcpp::R_X86_64_TPOFF64
);
2660 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2661 unsupported_reloc_global(object
, r_type
, gsym
);
2664 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
2665 layout
->set_has_static_tls();
2666 if (parameters
->options().shared())
2667 unsupported_reloc_local(object
, r_type
);
2676 case elfcpp::R_X86_64_SIZE32
:
2677 case elfcpp::R_X86_64_SIZE64
:
2679 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2680 object
->name().c_str(), r_type
,
2681 gsym
->demangled_name().c_str());
2687 Target_x86_64::gc_process_relocs(Symbol_table
* symtab
,
2689 Sized_relobj_file
<64, false>* object
,
2690 unsigned int data_shndx
,
2691 unsigned int sh_type
,
2692 const unsigned char* prelocs
,
2694 Output_section
* output_section
,
2695 bool needs_special_offset_handling
,
2696 size_t local_symbol_count
,
2697 const unsigned char* plocal_symbols
)
2700 if (sh_type
== elfcpp::SHT_REL
)
2705 gold::gc_process_relocs
<64, false, Target_x86_64
, elfcpp::SHT_RELA
,
2706 Target_x86_64::Scan
,
2707 Target_x86_64::Relocatable_size_for_reloc
>(
2716 needs_special_offset_handling
,
2721 // Scan relocations for a section.
2724 Target_x86_64::scan_relocs(Symbol_table
* symtab
,
2726 Sized_relobj_file
<64, false>* object
,
2727 unsigned int data_shndx
,
2728 unsigned int sh_type
,
2729 const unsigned char* prelocs
,
2731 Output_section
* output_section
,
2732 bool needs_special_offset_handling
,
2733 size_t local_symbol_count
,
2734 const unsigned char* plocal_symbols
)
2736 if (sh_type
== elfcpp::SHT_REL
)
2738 gold_error(_("%s: unsupported REL reloc section"),
2739 object
->name().c_str());
2743 gold::scan_relocs
<64, false, Target_x86_64
, elfcpp::SHT_RELA
,
2744 Target_x86_64::Scan
>(
2753 needs_special_offset_handling
,
2758 // Finalize the sections.
2761 Target_x86_64::do_finalize_sections(
2763 const Input_objects
*,
2764 Symbol_table
* symtab
)
2766 const Reloc_section
* rel_plt
= (this->plt_
== NULL
2768 : this->plt_
->rela_plt());
2769 layout
->add_target_dynamic_tags(false, this->got_plt_
, rel_plt
,
2770 this->rela_dyn_
, true, false);
2772 // Fill in some more dynamic tags.
2773 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
2776 if (this->plt_
!= NULL
2777 && this->plt_
->output_section() != NULL
2778 && this->plt_
->has_tlsdesc_entry())
2780 unsigned int plt_offset
= this->plt_
->get_tlsdesc_plt_offset();
2781 unsigned int got_offset
= this->plt_
->get_tlsdesc_got_offset();
2782 this->got_
->finalize_data_size();
2783 odyn
->add_section_plus_offset(elfcpp::DT_TLSDESC_PLT
,
2784 this->plt_
, plt_offset
);
2785 odyn
->add_section_plus_offset(elfcpp::DT_TLSDESC_GOT
,
2786 this->got_
, got_offset
);
2790 // Emit any relocs we saved in an attempt to avoid generating COPY
2792 if (this->copy_relocs_
.any_saved_relocs())
2793 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2795 // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
2796 // the .got.plt section.
2797 Symbol
* sym
= this->global_offset_table_
;
2800 uint64_t data_size
= this->got_plt_
->current_data_size();
2801 symtab
->get_sized_symbol
<64>(sym
)->set_symsize(data_size
);
2804 if (parameters
->doing_static_link()
2805 && (this->plt_
== NULL
|| !this->plt_
->has_irelative_section()))
2807 // If linking statically, make sure that the __rela_iplt symbols
2808 // were defined if necessary, even if we didn't create a PLT.
2809 static const Define_symbol_in_segment syms
[] =
2812 "__rela_iplt_start", // name
2813 elfcpp::PT_LOAD
, // segment_type
2814 elfcpp::PF_W
, // segment_flags_set
2815 elfcpp::PF(0), // segment_flags_clear
2818 elfcpp::STT_NOTYPE
, // type
2819 elfcpp::STB_GLOBAL
, // binding
2820 elfcpp::STV_HIDDEN
, // visibility
2822 Symbol::SEGMENT_START
, // offset_from_base
2826 "__rela_iplt_end", // name
2827 elfcpp::PT_LOAD
, // segment_type
2828 elfcpp::PF_W
, // segment_flags_set
2829 elfcpp::PF(0), // segment_flags_clear
2832 elfcpp::STT_NOTYPE
, // type
2833 elfcpp::STB_GLOBAL
, // binding
2834 elfcpp::STV_HIDDEN
, // visibility
2836 Symbol::SEGMENT_START
, // offset_from_base
2841 symtab
->define_symbols(layout
, 2, syms
,
2842 layout
->script_options()->saw_sections_clause());
2846 // Perform a relocation.
2849 Target_x86_64::Relocate::relocate(const Relocate_info
<64, false>* relinfo
,
2850 Target_x86_64
* target
,
2853 const elfcpp::Rela
<64, false>& rela
,
2854 unsigned int r_type
,
2855 const Sized_symbol
<64>* gsym
,
2856 const Symbol_value
<64>* psymval
,
2857 unsigned char* view
,
2858 elfcpp::Elf_types
<64>::Elf_Addr address
,
2859 section_size_type view_size
)
2861 if (this->skip_call_tls_get_addr_
)
2863 if ((r_type
!= elfcpp::R_X86_64_PLT32
2864 && r_type
!= elfcpp::R_X86_64_PC32
)
2866 || strcmp(gsym
->name(), "__tls_get_addr") != 0)
2868 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2869 _("missing expected TLS relocation"));
2873 this->skip_call_tls_get_addr_
= false;
2878 const Sized_relobj_file
<64, false>* object
= relinfo
->object
;
2880 // Pick the value to use for symbols defined in the PLT.
2881 Symbol_value
<64> symval
;
2883 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
2885 symval
.set_output_value(target
->plt_address_for_global(gsym
)
2886 + gsym
->plt_offset());
2889 else if (gsym
== NULL
&& psymval
->is_ifunc_symbol())
2891 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(rela
.get_r_info());
2892 if (object
->local_has_plt_offset(r_sym
))
2894 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
)
2895 + object
->local_plt_offset(r_sym
));
2900 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2902 // Get the GOT offset if needed.
2903 // The GOT pointer points to the end of the GOT section.
2904 // We need to subtract the size of the GOT section to get
2905 // the actual offset to use in the relocation.
2906 bool have_got_offset
= false;
2907 unsigned int got_offset
= 0;
2910 case elfcpp::R_X86_64_GOT32
:
2911 case elfcpp::R_X86_64_GOT64
:
2912 case elfcpp::R_X86_64_GOTPLT64
:
2913 case elfcpp::R_X86_64_GOTPCREL
:
2914 case elfcpp::R_X86_64_GOTPCREL64
:
2917 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2918 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
) - target
->got_size();
2922 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(rela
.get_r_info());
2923 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2924 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
2925 - target
->got_size());
2927 have_got_offset
= true;
2936 case elfcpp::R_X86_64_NONE
:
2937 case elfcpp::R_X86_64_GNU_VTINHERIT
:
2938 case elfcpp::R_X86_64_GNU_VTENTRY
:
2941 case elfcpp::R_X86_64_64
:
2942 Relocate_functions
<64, false>::rela64(view
, object
, psymval
, addend
);
2945 case elfcpp::R_X86_64_PC64
:
2946 Relocate_functions
<64, false>::pcrela64(view
, object
, psymval
, addend
,
2950 case elfcpp::R_X86_64_32
:
2951 // FIXME: we need to verify that value + addend fits into 32 bits:
2952 // uint64_t x = value + addend;
2953 // x == static_cast<uint64_t>(static_cast<uint32_t>(x))
2954 // Likewise for other <=32-bit relocations (but see R_X86_64_32S).
2955 Relocate_functions
<64, false>::rela32(view
, object
, psymval
, addend
);
2958 case elfcpp::R_X86_64_32S
:
2959 // FIXME: we need to verify that value + addend fits into 32 bits:
2960 // int64_t x = value + addend; // note this quantity is signed!
2961 // x == static_cast<int64_t>(static_cast<int32_t>(x))
2962 Relocate_functions
<64, false>::rela32(view
, object
, psymval
, addend
);
2965 case elfcpp::R_X86_64_PC32
:
2966 Relocate_functions
<64, false>::pcrela32(view
, object
, psymval
, addend
,
2970 case elfcpp::R_X86_64_16
:
2971 Relocate_functions
<64, false>::rela16(view
, object
, psymval
, addend
);
2974 case elfcpp::R_X86_64_PC16
:
2975 Relocate_functions
<64, false>::pcrela16(view
, object
, psymval
, addend
,
2979 case elfcpp::R_X86_64_8
:
2980 Relocate_functions
<64, false>::rela8(view
, object
, psymval
, addend
);
2983 case elfcpp::R_X86_64_PC8
:
2984 Relocate_functions
<64, false>::pcrela8(view
, object
, psymval
, addend
,
2988 case elfcpp::R_X86_64_PLT32
:
2989 gold_assert(gsym
== NULL
2990 || gsym
->has_plt_offset()
2991 || gsym
->final_value_is_known()
2992 || (gsym
->is_defined()
2993 && !gsym
->is_from_dynobj()
2994 && !gsym
->is_preemptible()));
2995 // Note: while this code looks the same as for R_X86_64_PC32, it
2996 // behaves differently because psymval was set to point to
2997 // the PLT entry, rather than the symbol, in Scan::global().
2998 Relocate_functions
<64, false>::pcrela32(view
, object
, psymval
, addend
,
3002 case elfcpp::R_X86_64_PLTOFF64
:
3005 gold_assert(gsym
->has_plt_offset()
3006 || gsym
->final_value_is_known());
3007 elfcpp::Elf_types
<64>::Elf_Addr got_address
;
3008 got_address
= target
->got_section(NULL
, NULL
)->address();
3009 Relocate_functions
<64, false>::rela64(view
, object
, psymval
,
3010 addend
- got_address
);
3013 case elfcpp::R_X86_64_GOT32
:
3014 gold_assert(have_got_offset
);
3015 Relocate_functions
<64, false>::rela32(view
, got_offset
, addend
);
3018 case elfcpp::R_X86_64_GOTPC32
:
3021 elfcpp::Elf_types
<64>::Elf_Addr value
;
3022 value
= target
->got_plt_section()->address();
3023 Relocate_functions
<64, false>::pcrela32(view
, value
, addend
, address
);
3027 case elfcpp::R_X86_64_GOT64
:
3028 // The ABI doc says "Like GOT64, but indicates a PLT entry is needed."
3029 // Since we always add a PLT entry, this is equivalent.
3030 case elfcpp::R_X86_64_GOTPLT64
:
3031 gold_assert(have_got_offset
);
3032 Relocate_functions
<64, false>::rela64(view
, got_offset
, addend
);
3035 case elfcpp::R_X86_64_GOTPC64
:
3038 elfcpp::Elf_types
<64>::Elf_Addr value
;
3039 value
= target
->got_plt_section()->address();
3040 Relocate_functions
<64, false>::pcrela64(view
, value
, addend
, address
);
3044 case elfcpp::R_X86_64_GOTOFF64
:
3046 elfcpp::Elf_types
<64>::Elf_Addr value
;
3047 value
= (psymval
->value(object
, 0)
3048 - target
->got_plt_section()->address());
3049 Relocate_functions
<64, false>::rela64(view
, value
, addend
);
3053 case elfcpp::R_X86_64_GOTPCREL
:
3055 gold_assert(have_got_offset
);
3056 elfcpp::Elf_types
<64>::Elf_Addr value
;
3057 value
= target
->got_plt_section()->address() + got_offset
;
3058 Relocate_functions
<64, false>::pcrela32(view
, value
, addend
, address
);
3062 case elfcpp::R_X86_64_GOTPCREL64
:
3064 gold_assert(have_got_offset
);
3065 elfcpp::Elf_types
<64>::Elf_Addr value
;
3066 value
= target
->got_plt_section()->address() + got_offset
;
3067 Relocate_functions
<64, false>::pcrela64(view
, value
, addend
, address
);
3071 case elfcpp::R_X86_64_COPY
:
3072 case elfcpp::R_X86_64_GLOB_DAT
:
3073 case elfcpp::R_X86_64_JUMP_SLOT
:
3074 case elfcpp::R_X86_64_RELATIVE
:
3075 case elfcpp::R_X86_64_IRELATIVE
:
3076 // These are outstanding tls relocs, which are unexpected when linking
3077 case elfcpp::R_X86_64_TPOFF64
:
3078 case elfcpp::R_X86_64_DTPMOD64
:
3079 case elfcpp::R_X86_64_TLSDESC
:
3080 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3081 _("unexpected reloc %u in object file"),
3085 // These are initial tls relocs, which are expected when linking
3086 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
3087 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
3088 case elfcpp::R_X86_64_TLSDESC_CALL
:
3089 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
3090 case elfcpp::R_X86_64_DTPOFF32
:
3091 case elfcpp::R_X86_64_DTPOFF64
:
3092 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
3093 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
3094 this->relocate_tls(relinfo
, target
, relnum
, rela
, r_type
, gsym
, psymval
,
3095 view
, address
, view_size
);
3098 case elfcpp::R_X86_64_SIZE32
:
3099 case elfcpp::R_X86_64_SIZE64
:
3101 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3102 _("unsupported reloc %u"),
3110 // Perform a TLS relocation.
3113 Target_x86_64::Relocate::relocate_tls(const Relocate_info
<64, false>* relinfo
,
3114 Target_x86_64
* target
,
3116 const elfcpp::Rela
<64, false>& rela
,
3117 unsigned int r_type
,
3118 const Sized_symbol
<64>* gsym
,
3119 const Symbol_value
<64>* psymval
,
3120 unsigned char* view
,
3121 elfcpp::Elf_types
<64>::Elf_Addr address
,
3122 section_size_type view_size
)
3124 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3126 const Sized_relobj_file
<64, false>* object
= relinfo
->object
;
3127 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3128 elfcpp::Shdr
<64, false> data_shdr(relinfo
->data_shdr
);
3129 bool is_executable
= (data_shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0;
3131 elfcpp::Elf_types
<64>::Elf_Addr value
= psymval
->value(relinfo
->object
, 0);
3133 const bool is_final
= (gsym
== NULL
3134 ? !parameters
->options().shared()
3135 : gsym
->final_value_is_known());
3136 tls::Tls_optimization optimized_type
3137 = Target_x86_64::optimize_tls_reloc(is_final
, r_type
);
3140 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
3141 if (!is_executable
&& optimized_type
== tls::TLSOPT_TO_LE
)
3143 // If this code sequence is used in a non-executable section,
3144 // we will not optimize the R_X86_64_DTPOFF32/64 relocation,
3145 // on the assumption that it's being used by itself in a debug
3146 // section. Therefore, in the unlikely event that the code
3147 // sequence appears in a non-executable section, we simply
3148 // leave it unoptimized.
3149 optimized_type
= tls::TLSOPT_NONE
;
3151 if (optimized_type
== tls::TLSOPT_TO_LE
)
3153 if (tls_segment
== NULL
)
3155 gold_assert(parameters
->errors()->error_count() > 0
3156 || issue_undefined_symbol_error(gsym
));
3159 this->tls_gd_to_le(relinfo
, relnum
, tls_segment
,
3160 rela
, r_type
, value
, view
,
3166 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3167 ? GOT_TYPE_TLS_OFFSET
3168 : GOT_TYPE_TLS_PAIR
);
3169 unsigned int got_offset
;
3172 gold_assert(gsym
->has_got_offset(got_type
));
3173 got_offset
= gsym
->got_offset(got_type
) - target
->got_size();
3177 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(rela
.get_r_info());
3178 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3179 got_offset
= (object
->local_got_offset(r_sym
, got_type
)
3180 - target
->got_size());
3182 if (optimized_type
== tls::TLSOPT_TO_IE
)
3184 value
= target
->got_plt_section()->address() + got_offset
;
3185 this->tls_gd_to_ie(relinfo
, relnum
, tls_segment
, rela
, r_type
,
3186 value
, view
, address
, view_size
);
3189 else if (optimized_type
== tls::TLSOPT_NONE
)
3191 // Relocate the field with the offset of the pair of GOT
3193 value
= target
->got_plt_section()->address() + got_offset
;
3194 Relocate_functions
<64, false>::pcrela32(view
, value
, addend
,
3199 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3200 _("unsupported reloc %u"), r_type
);
3203 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
3204 case elfcpp::R_X86_64_TLSDESC_CALL
:
3205 if (!is_executable
&& optimized_type
== tls::TLSOPT_TO_LE
)
3207 // See above comment for R_X86_64_TLSGD.
3208 optimized_type
= tls::TLSOPT_NONE
;
3210 if (optimized_type
== tls::TLSOPT_TO_LE
)
3212 if (tls_segment
== NULL
)
3214 gold_assert(parameters
->errors()->error_count() > 0
3215 || issue_undefined_symbol_error(gsym
));
3218 this->tls_desc_gd_to_le(relinfo
, relnum
, tls_segment
,
3219 rela
, r_type
, value
, view
,
3225 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3226 ? GOT_TYPE_TLS_OFFSET
3227 : GOT_TYPE_TLS_DESC
);
3228 unsigned int got_offset
= 0;
3229 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
3230 && optimized_type
== tls::TLSOPT_NONE
)
3232 // We created GOT entries in the .got.tlsdesc portion of
3233 // the .got.plt section, but the offset stored in the
3234 // symbol is the offset within .got.tlsdesc.
3235 got_offset
= (target
->got_size()
3236 + target
->got_plt_section()->data_size());
3240 gold_assert(gsym
->has_got_offset(got_type
));
3241 got_offset
+= gsym
->got_offset(got_type
) - target
->got_size();
3245 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(rela
.get_r_info());
3246 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3247 got_offset
+= (object
->local_got_offset(r_sym
, got_type
)
3248 - target
->got_size());
3250 if (optimized_type
== tls::TLSOPT_TO_IE
)
3252 if (tls_segment
== NULL
)
3254 gold_assert(parameters
->errors()->error_count() > 0
3255 || issue_undefined_symbol_error(gsym
));
3258 value
= target
->got_plt_section()->address() + got_offset
;
3259 this->tls_desc_gd_to_ie(relinfo
, relnum
, tls_segment
,
3260 rela
, r_type
, value
, view
, address
,
3264 else if (optimized_type
== tls::TLSOPT_NONE
)
3266 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
)
3268 // Relocate the field with the offset of the pair of GOT
3270 value
= target
->got_plt_section()->address() + got_offset
;
3271 Relocate_functions
<64, false>::pcrela32(view
, value
, addend
,
3277 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3278 _("unsupported reloc %u"), r_type
);
3281 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
3282 if (!is_executable
&& optimized_type
== tls::TLSOPT_TO_LE
)
3284 // See above comment for R_X86_64_TLSGD.
3285 optimized_type
= tls::TLSOPT_NONE
;
3287 if (optimized_type
== tls::TLSOPT_TO_LE
)
3289 if (tls_segment
== NULL
)
3291 gold_assert(parameters
->errors()->error_count() > 0
3292 || issue_undefined_symbol_error(gsym
));
3295 this->tls_ld_to_le(relinfo
, relnum
, tls_segment
, rela
, r_type
,
3296 value
, view
, view_size
);
3299 else if (optimized_type
== tls::TLSOPT_NONE
)
3301 // Relocate the field with the offset of the GOT entry for
3302 // the module index.
3303 unsigned int got_offset
;
3304 got_offset
= (target
->got_mod_index_entry(NULL
, NULL
, NULL
)
3305 - target
->got_size());
3306 value
= target
->got_plt_section()->address() + got_offset
;
3307 Relocate_functions
<64, false>::pcrela32(view
, value
, addend
,
3311 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3312 _("unsupported reloc %u"), r_type
);
3315 case elfcpp::R_X86_64_DTPOFF32
:
3316 // This relocation type is used in debugging information.
3317 // In that case we need to not optimize the value. If the
3318 // section is not executable, then we assume we should not
3319 // optimize this reloc. See comments above for R_X86_64_TLSGD,
3320 // R_X86_64_GOTPC32_TLSDESC, R_X86_64_TLSDESC_CALL, and
3322 if (optimized_type
== tls::TLSOPT_TO_LE
&& is_executable
)
3324 if (tls_segment
== NULL
)
3326 gold_assert(parameters
->errors()->error_count() > 0
3327 || issue_undefined_symbol_error(gsym
));
3330 value
-= tls_segment
->memsz();
3332 Relocate_functions
<64, false>::rela32(view
, value
, addend
);
3335 case elfcpp::R_X86_64_DTPOFF64
:
3336 // See R_X86_64_DTPOFF32, just above, for why we check for is_executable.
3337 if (optimized_type
== tls::TLSOPT_TO_LE
&& is_executable
)
3339 if (tls_segment
== NULL
)
3341 gold_assert(parameters
->errors()->error_count() > 0
3342 || issue_undefined_symbol_error(gsym
));
3345 value
-= tls_segment
->memsz();
3347 Relocate_functions
<64, false>::rela64(view
, value
, addend
);
3350 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
3351 if (optimized_type
== tls::TLSOPT_TO_LE
)
3353 if (tls_segment
== NULL
)
3355 gold_assert(parameters
->errors()->error_count() > 0
3356 || issue_undefined_symbol_error(gsym
));
3359 Target_x86_64::Relocate::tls_ie_to_le(relinfo
, relnum
, tls_segment
,
3360 rela
, r_type
, value
, view
,
3364 else if (optimized_type
== tls::TLSOPT_NONE
)
3366 // Relocate the field with the offset of the GOT entry for
3367 // the tp-relative offset of the symbol.
3368 unsigned int got_offset
;
3371 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3372 got_offset
= (gsym
->got_offset(GOT_TYPE_TLS_OFFSET
)
3373 - target
->got_size());
3377 unsigned int r_sym
= elfcpp::elf_r_sym
<64>(rela
.get_r_info());
3378 gold_assert(object
->local_has_got_offset(r_sym
,
3379 GOT_TYPE_TLS_OFFSET
));
3380 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
)
3381 - target
->got_size());
3383 value
= target
->got_plt_section()->address() + got_offset
;
3384 Relocate_functions
<64, false>::pcrela32(view
, value
, addend
, address
);
3387 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3388 _("unsupported reloc type %u"),
3392 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
3393 if (tls_segment
== NULL
)
3395 gold_assert(parameters
->errors()->error_count() > 0
3396 || issue_undefined_symbol_error(gsym
));
3399 value
-= tls_segment
->memsz();
3400 Relocate_functions
<64, false>::rela32(view
, value
, addend
);
3405 // Do a relocation in which we convert a TLS General-Dynamic to an
3409 Target_x86_64::Relocate::tls_gd_to_ie(const Relocate_info
<64, false>* relinfo
,
3412 const elfcpp::Rela
<64, false>& rela
,
3414 elfcpp::Elf_types
<64>::Elf_Addr value
,
3415 unsigned char* view
,
3416 elfcpp::Elf_types
<64>::Elf_Addr address
,
3417 section_size_type view_size
)
3419 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
3420 // .word 0x6666; rex64; call __tls_get_addr
3421 // ==> movq %fs:0,%rax; addq x@gottpoff(%rip),%rax
3423 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -4);
3424 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 12);
3426 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3427 (memcmp(view
- 4, "\x66\x48\x8d\x3d", 4) == 0));
3428 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3429 (memcmp(view
+ 4, "\x66\x66\x48\xe8", 4) == 0));
3431 memcpy(view
- 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0\0", 16);
3433 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3434 Relocate_functions
<64, false>::pcrela32(view
+ 8, value
, addend
- 8, address
);
3436 // The next reloc should be a PLT32 reloc against __tls_get_addr.
3438 this->skip_call_tls_get_addr_
= true;
3441 // Do a relocation in which we convert a TLS General-Dynamic to a
3445 Target_x86_64::Relocate::tls_gd_to_le(const Relocate_info
<64, false>* relinfo
,
3447 Output_segment
* tls_segment
,
3448 const elfcpp::Rela
<64, false>& rela
,
3450 elfcpp::Elf_types
<64>::Elf_Addr value
,
3451 unsigned char* view
,
3452 section_size_type view_size
)
3454 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
3455 // .word 0x6666; rex64; call __tls_get_addr
3456 // ==> movq %fs:0,%rax; leaq x@tpoff(%rax),%rax
3458 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -4);
3459 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 12);
3461 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3462 (memcmp(view
- 4, "\x66\x48\x8d\x3d", 4) == 0));
3463 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3464 (memcmp(view
+ 4, "\x66\x66\x48\xe8", 4) == 0));
3466 memcpy(view
- 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0\0", 16);
3468 value
-= tls_segment
->memsz();
3469 Relocate_functions
<64, false>::rela32(view
+ 8, value
, 0);
3471 // The next reloc should be a PLT32 reloc against __tls_get_addr.
3473 this->skip_call_tls_get_addr_
= true;
3476 // Do a TLSDESC-style General-Dynamic to Initial-Exec transition.
3479 Target_x86_64::Relocate::tls_desc_gd_to_ie(
3480 const Relocate_info
<64, false>* relinfo
,
3483 const elfcpp::Rela
<64, false>& rela
,
3484 unsigned int r_type
,
3485 elfcpp::Elf_types
<64>::Elf_Addr value
,
3486 unsigned char* view
,
3487 elfcpp::Elf_types
<64>::Elf_Addr address
,
3488 section_size_type view_size
)
3490 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
)
3492 // leaq foo@tlsdesc(%rip), %rax
3493 // ==> movq foo@gottpoff(%rip), %rax
3494 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
3495 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
3496 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3497 view
[-3] == 0x48 && view
[-2] == 0x8d && view
[-1] == 0x05);
3499 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3500 Relocate_functions
<64, false>::pcrela32(view
, value
, addend
, address
);
3504 // call *foo@tlscall(%rax)
3506 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC_CALL
);
3507 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 2);
3508 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3509 view
[0] == 0xff && view
[1] == 0x10);
3515 // Do a TLSDESC-style General-Dynamic to Local-Exec transition.
3518 Target_x86_64::Relocate::tls_desc_gd_to_le(
3519 const Relocate_info
<64, false>* relinfo
,
3521 Output_segment
* tls_segment
,
3522 const elfcpp::Rela
<64, false>& rela
,
3523 unsigned int r_type
,
3524 elfcpp::Elf_types
<64>::Elf_Addr value
,
3525 unsigned char* view
,
3526 section_size_type view_size
)
3528 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
)
3530 // leaq foo@tlsdesc(%rip), %rax
3531 // ==> movq foo@tpoff, %rax
3532 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
3533 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
3534 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3535 view
[-3] == 0x48 && view
[-2] == 0x8d && view
[-1] == 0x05);
3538 value
-= tls_segment
->memsz();
3539 Relocate_functions
<64, false>::rela32(view
, value
, 0);
3543 // call *foo@tlscall(%rax)
3545 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC_CALL
);
3546 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 2);
3547 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3548 view
[0] == 0xff && view
[1] == 0x10);
3555 Target_x86_64::Relocate::tls_ld_to_le(const Relocate_info
<64, false>* relinfo
,
3558 const elfcpp::Rela
<64, false>& rela
,
3560 elfcpp::Elf_types
<64>::Elf_Addr
,
3561 unsigned char* view
,
3562 section_size_type view_size
)
3564 // leaq foo@tlsld(%rip),%rdi; call __tls_get_addr@plt;
3565 // ... leq foo@dtpoff(%rax),%reg
3566 // ==> .word 0x6666; .byte 0x66; movq %fs:0,%rax ... leaq x@tpoff(%rax),%rdx
3568 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
3569 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 9);
3571 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
3572 view
[-3] == 0x48 && view
[-2] == 0x8d && view
[-1] == 0x3d);
3574 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(), view
[4] == 0xe8);
3576 memcpy(view
- 3, "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0\0", 12);
3578 // The next reloc should be a PLT32 reloc against __tls_get_addr.
3580 this->skip_call_tls_get_addr_
= true;
3583 // Do a relocation in which we convert a TLS Initial-Exec to a
3587 Target_x86_64::Relocate::tls_ie_to_le(const Relocate_info
<64, false>* relinfo
,
3589 Output_segment
* tls_segment
,
3590 const elfcpp::Rela
<64, false>& rela
,
3592 elfcpp::Elf_types
<64>::Elf_Addr value
,
3593 unsigned char* view
,
3594 section_size_type view_size
)
3596 // We need to examine the opcodes to figure out which instruction we
3599 // movq foo@gottpoff(%rip),%reg ==> movq $YY,%reg
3600 // addq foo@gottpoff(%rip),%reg ==> addq $YY,%reg
3602 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
3603 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
3605 unsigned char op1
= view
[-3];
3606 unsigned char op2
= view
[-2];
3607 unsigned char op3
= view
[-1];
3608 unsigned char reg
= op3
>> 3;
3616 view
[-1] = 0xc0 | reg
;
3620 // Special handling for %rsp.
3624 view
[-1] = 0xc0 | reg
;
3632 view
[-1] = 0x80 | reg
| (reg
<< 3);
3635 value
-= tls_segment
->memsz();
3636 Relocate_functions
<64, false>::rela32(view
, value
, 0);
3639 // Relocate section data.
3642 Target_x86_64::relocate_section(
3643 const Relocate_info
<64, false>* relinfo
,
3644 unsigned int sh_type
,
3645 const unsigned char* prelocs
,
3647 Output_section
* output_section
,
3648 bool needs_special_offset_handling
,
3649 unsigned char* view
,
3650 elfcpp::Elf_types
<64>::Elf_Addr address
,
3651 section_size_type view_size
,
3652 const Reloc_symbol_changes
* reloc_symbol_changes
)
3654 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3656 gold::relocate_section
<64, false, Target_x86_64
, elfcpp::SHT_RELA
,
3657 Target_x86_64::Relocate
>(
3663 needs_special_offset_handling
,
3667 reloc_symbol_changes
);
3670 // Apply an incremental relocation. Incremental relocations always refer
3671 // to global symbols.
3674 Target_x86_64::apply_relocation(
3675 const Relocate_info
<64, false>* relinfo
,
3676 elfcpp::Elf_types
<64>::Elf_Addr r_offset
,
3677 unsigned int r_type
,
3678 elfcpp::Elf_types
<64>::Elf_Swxword r_addend
,
3680 unsigned char* view
,
3681 elfcpp::Elf_types
<64>::Elf_Addr address
,
3682 section_size_type view_size
)
3684 gold::apply_relocation
<64, false, Target_x86_64
, Target_x86_64::Relocate
>(
3696 // Return the size of a relocation while scanning during a relocatable
3700 Target_x86_64::Relocatable_size_for_reloc::get_size_for_reloc(
3701 unsigned int r_type
,
3706 case elfcpp::R_X86_64_NONE
:
3707 case elfcpp::R_X86_64_GNU_VTINHERIT
:
3708 case elfcpp::R_X86_64_GNU_VTENTRY
:
3709 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
3710 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
3711 case elfcpp::R_X86_64_TLSDESC_CALL
:
3712 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
3713 case elfcpp::R_X86_64_DTPOFF32
:
3714 case elfcpp::R_X86_64_DTPOFF64
:
3715 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
3716 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
3719 case elfcpp::R_X86_64_64
:
3720 case elfcpp::R_X86_64_PC64
:
3721 case elfcpp::R_X86_64_GOTOFF64
:
3722 case elfcpp::R_X86_64_GOTPC64
:
3723 case elfcpp::R_X86_64_PLTOFF64
:
3724 case elfcpp::R_X86_64_GOT64
:
3725 case elfcpp::R_X86_64_GOTPCREL64
:
3726 case elfcpp::R_X86_64_GOTPCREL
:
3727 case elfcpp::R_X86_64_GOTPLT64
:
3730 case elfcpp::R_X86_64_32
:
3731 case elfcpp::R_X86_64_32S
:
3732 case elfcpp::R_X86_64_PC32
:
3733 case elfcpp::R_X86_64_PLT32
:
3734 case elfcpp::R_X86_64_GOTPC32
:
3735 case elfcpp::R_X86_64_GOT32
:
3738 case elfcpp::R_X86_64_16
:
3739 case elfcpp::R_X86_64_PC16
:
3742 case elfcpp::R_X86_64_8
:
3743 case elfcpp::R_X86_64_PC8
:
3746 case elfcpp::R_X86_64_COPY
:
3747 case elfcpp::R_X86_64_GLOB_DAT
:
3748 case elfcpp::R_X86_64_JUMP_SLOT
:
3749 case elfcpp::R_X86_64_RELATIVE
:
3750 case elfcpp::R_X86_64_IRELATIVE
:
3751 // These are outstanding tls relocs, which are unexpected when linking
3752 case elfcpp::R_X86_64_TPOFF64
:
3753 case elfcpp::R_X86_64_DTPMOD64
:
3754 case elfcpp::R_X86_64_TLSDESC
:
3755 object
->error(_("unexpected reloc %u in object file"), r_type
);
3758 case elfcpp::R_X86_64_SIZE32
:
3759 case elfcpp::R_X86_64_SIZE64
:
3761 object
->error(_("unsupported reloc %u against local symbol"), r_type
);
3766 // Scan the relocs during a relocatable link.
3769 Target_x86_64::scan_relocatable_relocs(Symbol_table
* symtab
,
3771 Sized_relobj_file
<64, false>* object
,
3772 unsigned int data_shndx
,
3773 unsigned int sh_type
,
3774 const unsigned char* prelocs
,
3776 Output_section
* output_section
,
3777 bool needs_special_offset_handling
,
3778 size_t local_symbol_count
,
3779 const unsigned char* plocal_symbols
,
3780 Relocatable_relocs
* rr
)
3782 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3784 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3785 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3787 gold::scan_relocatable_relocs
<64, false, elfcpp::SHT_RELA
,
3788 Scan_relocatable_relocs
>(
3796 needs_special_offset_handling
,
3802 // Relocate a section during a relocatable link.
3805 Target_x86_64::relocate_for_relocatable(
3806 const Relocate_info
<64, false>* relinfo
,
3807 unsigned int sh_type
,
3808 const unsigned char* prelocs
,
3810 Output_section
* output_section
,
3811 off_t offset_in_output_section
,
3812 const Relocatable_relocs
* rr
,
3813 unsigned char* view
,
3814 elfcpp::Elf_types
<64>::Elf_Addr view_address
,
3815 section_size_type view_size
,
3816 unsigned char* reloc_view
,
3817 section_size_type reloc_view_size
)
3819 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3821 gold::relocate_for_relocatable
<64, false, elfcpp::SHT_RELA
>(
3826 offset_in_output_section
,
3835 // Return the value to use for a dynamic which requires special
3836 // treatment. This is how we support equality comparisons of function
3837 // pointers across shared library boundaries, as described in the
3838 // processor specific ABI supplement.
3841 Target_x86_64::do_dynsym_value(const Symbol
* gsym
) const
3843 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3844 return this->plt_address_for_global(gsym
) + gsym
->plt_offset();
3847 // Return a string used to fill a code section with nops to take up
3848 // the specified length.
3851 Target_x86_64::do_code_fill(section_size_type length
) const
3855 // Build a jmpq instruction to skip over the bytes.
3856 unsigned char jmp
[5];
3858 elfcpp::Swap_unaligned
<32, false>::writeval(jmp
+ 1, length
- 5);
3859 return (std::string(reinterpret_cast<char*>(&jmp
[0]), 5)
3860 + std::string(length
- 5, '\0'));
3863 // Nop sequences of various lengths.
3864 const char nop1
[1] = { '\x90' }; // nop
3865 const char nop2
[2] = { '\x66', '\x90' }; // xchg %ax %ax
3866 const char nop3
[3] = { '\x0f', '\x1f', '\x00' }; // nop (%rax)
3867 const char nop4
[4] = { '\x0f', '\x1f', '\x40', // nop 0(%rax)
3869 const char nop5
[5] = { '\x0f', '\x1f', '\x44', // nop 0(%rax,%rax,1)
3871 const char nop6
[6] = { '\x66', '\x0f', '\x1f', // nopw 0(%rax,%rax,1)
3872 '\x44', '\x00', '\x00' };
3873 const char nop7
[7] = { '\x0f', '\x1f', '\x80', // nopl 0L(%rax)
3874 '\x00', '\x00', '\x00',
3876 const char nop8
[8] = { '\x0f', '\x1f', '\x84', // nopl 0L(%rax,%rax,1)
3877 '\x00', '\x00', '\x00',
3879 const char nop9
[9] = { '\x66', '\x0f', '\x1f', // nopw 0L(%rax,%rax,1)
3880 '\x84', '\x00', '\x00',
3881 '\x00', '\x00', '\x00' };
3882 const char nop10
[10] = { '\x66', '\x2e', '\x0f', // nopw %cs:0L(%rax,%rax,1)
3883 '\x1f', '\x84', '\x00',
3884 '\x00', '\x00', '\x00',
3886 const char nop11
[11] = { '\x66', '\x66', '\x2e', // data16
3887 '\x0f', '\x1f', '\x84', // nopw %cs:0L(%rax,%rax,1)
3888 '\x00', '\x00', '\x00',
3890 const char nop12
[12] = { '\x66', '\x66', '\x66', // data16; data16
3891 '\x2e', '\x0f', '\x1f', // nopw %cs:0L(%rax,%rax,1)
3892 '\x84', '\x00', '\x00',
3893 '\x00', '\x00', '\x00' };
3894 const char nop13
[13] = { '\x66', '\x66', '\x66', // data16; data16; data16
3895 '\x66', '\x2e', '\x0f', // nopw %cs:0L(%rax,%rax,1)
3896 '\x1f', '\x84', '\x00',
3897 '\x00', '\x00', '\x00',
3899 const char nop14
[14] = { '\x66', '\x66', '\x66', // data16; data16; data16
3900 '\x66', '\x66', '\x2e', // data16
3901 '\x0f', '\x1f', '\x84', // nopw %cs:0L(%rax,%rax,1)
3902 '\x00', '\x00', '\x00',
3904 const char nop15
[15] = { '\x66', '\x66', '\x66', // data16; data16; data16
3905 '\x66', '\x66', '\x66', // data16; data16
3906 '\x2e', '\x0f', '\x1f', // nopw %cs:0L(%rax,%rax,1)
3907 '\x84', '\x00', '\x00',
3908 '\x00', '\x00', '\x00' };
3910 const char* nops
[16] = {
3912 nop1
, nop2
, nop3
, nop4
, nop5
, nop6
, nop7
,
3913 nop8
, nop9
, nop10
, nop11
, nop12
, nop13
, nop14
, nop15
3916 return std::string(nops
[length
], length
);
3919 // Return the addend to use for a target specific relocation. The
3920 // only target specific relocation is R_X86_64_TLSDESC for a local
3921 // symbol. We want to set the addend is the offset of the local
3922 // symbol in the TLS segment.
3925 Target_x86_64::do_reloc_addend(void* arg
, unsigned int r_type
,
3928 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC
);
3929 uintptr_t intarg
= reinterpret_cast<uintptr_t>(arg
);
3930 gold_assert(intarg
< this->tlsdesc_reloc_info_
.size());
3931 const Tlsdesc_info
& ti(this->tlsdesc_reloc_info_
[intarg
]);
3932 const Symbol_value
<64>* psymval
= ti
.object
->local_symbol(ti
.r_sym
);
3933 gold_assert(psymval
->is_tls_symbol());
3934 // The value of a TLS symbol is the offset in the TLS segment.
3935 return psymval
->value(ti
.object
, 0);
3938 // Return the value to use for the base of a DW_EH_PE_datarel offset
3939 // in an FDE. Solaris and SVR4 use DW_EH_PE_datarel because their
3940 // assembler can not write out the difference between two labels in
3941 // different sections, so instead of using a pc-relative value they
3942 // use an offset from the GOT.
3945 Target_x86_64::do_ehframe_datarel_base() const
3947 gold_assert(this->global_offset_table_
!= NULL
);
3948 Symbol
* sym
= this->global_offset_table_
;
3949 Sized_symbol
<64>* ssym
= static_cast<Sized_symbol
<64>*>(sym
);
3950 return ssym
->value();
3953 // FNOFFSET in section SHNDX in OBJECT is the start of a function
3954 // compiled with -fsplit-stack. The function calls non-split-stack
3955 // code. We have to change the function so that it always ensures
3956 // that it has enough stack space to run some random function.
3959 Target_x86_64::do_calls_non_split(Relobj
* object
, unsigned int shndx
,
3960 section_offset_type fnoffset
,
3961 section_size_type fnsize
,
3962 unsigned char* view
,
3963 section_size_type view_size
,
3965 std::string
* to
) const
3967 // The function starts with a comparison of the stack pointer and a
3968 // field in the TCB. This is followed by a jump.
3971 if (this->match_view(view
, view_size
, fnoffset
, "\x64\x48\x3b\x24\x25", 5)
3974 // We will call __morestack if the carry flag is set after this
3975 // comparison. We turn the comparison into an stc instruction
3977 view
[fnoffset
] = '\xf9';
3978 this->set_view_to_nop(view
, view_size
, fnoffset
+ 1, 8);
3980 // lea NN(%rsp),%r10
3981 // lea NN(%rsp),%r11
3982 else if ((this->match_view(view
, view_size
, fnoffset
,
3983 "\x4c\x8d\x94\x24", 4)
3984 || this->match_view(view
, view_size
, fnoffset
,
3985 "\x4c\x8d\x9c\x24", 4))
3988 // This is loading an offset from the stack pointer for a
3989 // comparison. The offset is negative, so we decrease the
3990 // offset by the amount of space we need for the stack. This
3991 // means we will avoid calling __morestack if there happens to
3992 // be plenty of space on the stack already.
3993 unsigned char* pval
= view
+ fnoffset
+ 4;
3994 uint32_t val
= elfcpp::Swap_unaligned
<32, false>::readval(pval
);
3995 val
-= parameters
->options().split_stack_adjust_size();
3996 elfcpp::Swap_unaligned
<32, false>::writeval(pval
, val
);
4000 if (!object
->has_no_split_stack())
4001 object
->error(_("failed to match split-stack sequence at "
4002 "section %u offset %0zx"),
4003 shndx
, static_cast<size_t>(fnoffset
));
4007 // We have to change the function so that it calls
4008 // __morestack_non_split instead of __morestack. The former will
4009 // allocate additional stack space.
4010 *from
= "__morestack";
4011 *to
= "__morestack_non_split";
4014 // The selector for x86_64 object files.
4016 class Target_selector_x86_64
: public Target_selector_freebsd
4019 Target_selector_x86_64()
4020 : Target_selector_freebsd(elfcpp::EM_X86_64
, 64, false, "elf64-x86-64",
4021 "elf64-x86-64-freebsd", "elf_x86_64")
4025 do_instantiate_target()
4026 { return new Target_x86_64(); }
4030 Target_selector_x86_64 target_selector_x86_64
;
4032 } // End anonymous namespace.