1 // i386.cc -- i386 target support for gold.
3 // Copyright 2006, 2007, 2008, 2009 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.
28 #include "parameters.h"
35 #include "copy-relocs.h"
37 #include "target-reloc.h"
38 #include "target-select.h"
48 class Output_data_plt_i386
;
50 // The i386 target class.
51 // TLS info comes from
52 // http://people.redhat.com/drepper/tls.pdf
53 // http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt
55 class Target_i386
: public Target_freebsd
<32, false>
58 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false> Reloc_section
;
61 : Target_freebsd
<32, false>(&i386_info
),
62 got_(NULL
), plt_(NULL
), got_plt_(NULL
), global_offset_table_(NULL
),
63 rel_dyn_(NULL
), copy_relocs_(elfcpp::R_386_COPY
), dynbss_(NULL
),
64 got_mod_index_offset_(-1U), tls_base_symbol_defined_(false)
67 // Process the relocations to determine unreferenced sections for
68 // garbage collection.
70 gc_process_relocs(Symbol_table
* symtab
,
72 Sized_relobj
<32, false>* object
,
73 unsigned int data_shndx
,
75 const unsigned char* prelocs
,
77 Output_section
* output_section
,
78 bool needs_special_offset_handling
,
79 size_t local_symbol_count
,
80 const unsigned char* plocal_symbols
);
82 // Scan the relocations to look for symbol adjustments.
84 scan_relocs(Symbol_table
* symtab
,
86 Sized_relobj
<32, false>* object
,
87 unsigned int data_shndx
,
89 const unsigned char* prelocs
,
91 Output_section
* output_section
,
92 bool needs_special_offset_handling
,
93 size_t local_symbol_count
,
94 const unsigned char* plocal_symbols
);
96 // Finalize the sections.
98 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
100 // Return the value to use for a dynamic which requires special
103 do_dynsym_value(const Symbol
*) const;
105 // Relocate a section.
107 relocate_section(const Relocate_info
<32, false>*,
108 unsigned int sh_type
,
109 const unsigned char* prelocs
,
111 Output_section
* output_section
,
112 bool needs_special_offset_handling
,
114 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
115 section_size_type view_size
,
116 const Reloc_symbol_changes
*);
118 // Scan the relocs during a relocatable link.
120 scan_relocatable_relocs(Symbol_table
* symtab
,
122 Sized_relobj
<32, false>* object
,
123 unsigned int data_shndx
,
124 unsigned int sh_type
,
125 const unsigned char* prelocs
,
127 Output_section
* output_section
,
128 bool needs_special_offset_handling
,
129 size_t local_symbol_count
,
130 const unsigned char* plocal_symbols
,
131 Relocatable_relocs
*);
133 // Relocate a section during a relocatable link.
135 relocate_for_relocatable(const Relocate_info
<32, false>*,
136 unsigned int sh_type
,
137 const unsigned char* prelocs
,
139 Output_section
* output_section
,
140 off_t offset_in_output_section
,
141 const Relocatable_relocs
*,
143 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
144 section_size_type view_size
,
145 unsigned char* reloc_view
,
146 section_size_type reloc_view_size
);
148 // Return a string used to fill a code section with nops.
150 do_code_fill(section_size_type length
) const;
152 // Return whether SYM is defined by the ABI.
154 do_is_defined_by_abi(const Symbol
* sym
) const
155 { return strcmp(sym
->name(), "___tls_get_addr") == 0; }
157 // Return whether a symbol name implies a local label. The UnixWare
158 // 2.1 cc generates temporary symbols that start with .X, so we
159 // recognize them here. FIXME: do other SVR4 compilers also use .X?.
160 // If so, we should move the .X recognition into
161 // Target::do_is_local_label_name.
163 do_is_local_label_name(const char* name
) const
165 if (name
[0] == '.' && name
[1] == 'X')
167 return Target::do_is_local_label_name(name
);
170 // Adjust -fstack-split code which calls non-stack-split code.
172 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
173 section_offset_type fnoffset
, section_size_type fnsize
,
174 unsigned char* view
, section_size_type view_size
,
175 std::string
* from
, std::string
* to
) const;
177 // Return the size of the GOT section.
181 gold_assert(this->got_
!= NULL
);
182 return this->got_
->data_size();
186 // The class which scans relocations.
190 local(Symbol_table
* symtab
, Layout
* layout
, Target_i386
* target
,
191 Sized_relobj
<32, false>* object
,
192 unsigned int data_shndx
,
193 Output_section
* output_section
,
194 const elfcpp::Rel
<32, false>& reloc
, unsigned int r_type
,
195 const elfcpp::Sym
<32, false>& lsym
);
198 global(Symbol_table
* symtab
, Layout
* layout
, Target_i386
* target
,
199 Sized_relobj
<32, false>* object
,
200 unsigned int data_shndx
,
201 Output_section
* output_section
,
202 const elfcpp::Rel
<32, false>& reloc
, unsigned int r_type
,
206 unsupported_reloc_local(Sized_relobj
<32, false>*, unsigned int r_type
);
209 unsupported_reloc_global(Sized_relobj
<32, false>*, unsigned int r_type
,
213 // The class which implements relocation.
218 : skip_call_tls_get_addr_(false),
219 local_dynamic_type_(LOCAL_DYNAMIC_NONE
)
224 if (this->skip_call_tls_get_addr_
)
226 // FIXME: This needs to specify the location somehow.
227 gold_error(_("missing expected TLS relocation"));
231 // Return whether the static relocation needs to be applied.
233 should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
236 Output_section
* output_section
);
238 // Do a relocation. Return false if the caller should not issue
239 // any warnings about this relocation.
241 relocate(const Relocate_info
<32, false>*, Target_i386
*, Output_section
*,
242 size_t relnum
, const elfcpp::Rel
<32, false>&,
243 unsigned int r_type
, const Sized_symbol
<32>*,
244 const Symbol_value
<32>*,
245 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
,
249 // Do a TLS relocation.
251 relocate_tls(const Relocate_info
<32, false>*, Target_i386
* target
,
252 size_t relnum
, const elfcpp::Rel
<32, false>&,
253 unsigned int r_type
, const Sized_symbol
<32>*,
254 const Symbol_value
<32>*,
255 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
,
258 // Do a TLS General-Dynamic to Initial-Exec transition.
260 tls_gd_to_ie(const Relocate_info
<32, false>*, size_t relnum
,
261 Output_segment
* tls_segment
,
262 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
263 elfcpp::Elf_types
<32>::Elf_Addr value
,
265 section_size_type view_size
);
267 // Do a TLS General-Dynamic to Local-Exec transition.
269 tls_gd_to_le(const Relocate_info
<32, false>*, size_t relnum
,
270 Output_segment
* tls_segment
,
271 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
272 elfcpp::Elf_types
<32>::Elf_Addr value
,
274 section_size_type view_size
);
276 // Do a TLS_GOTDESC or TLS_DESC_CALL General-Dynamic to Initial-Exec
279 tls_desc_gd_to_ie(const Relocate_info
<32, false>*, size_t relnum
,
280 Output_segment
* tls_segment
,
281 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
282 elfcpp::Elf_types
<32>::Elf_Addr value
,
284 section_size_type view_size
);
286 // Do a TLS_GOTDESC or TLS_DESC_CALL General-Dynamic to Local-Exec
289 tls_desc_gd_to_le(const Relocate_info
<32, false>*, size_t relnum
,
290 Output_segment
* tls_segment
,
291 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
292 elfcpp::Elf_types
<32>::Elf_Addr value
,
294 section_size_type view_size
);
296 // Do a TLS Local-Dynamic to Local-Exec transition.
298 tls_ld_to_le(const Relocate_info
<32, false>*, size_t relnum
,
299 Output_segment
* tls_segment
,
300 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
301 elfcpp::Elf_types
<32>::Elf_Addr value
,
303 section_size_type view_size
);
305 // Do a TLS Initial-Exec to Local-Exec transition.
307 tls_ie_to_le(const Relocate_info
<32, false>*, size_t relnum
,
308 Output_segment
* tls_segment
,
309 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
310 elfcpp::Elf_types
<32>::Elf_Addr value
,
312 section_size_type view_size
);
314 // We need to keep track of which type of local dynamic relocation
315 // we have seen, so that we can optimize R_386_TLS_LDO_32 correctly.
316 enum Local_dynamic_type
323 // This is set if we should skip the next reloc, which should be a
324 // PLT32 reloc against ___tls_get_addr.
325 bool skip_call_tls_get_addr_
;
326 // The type of local dynamic relocation we have seen in the section
327 // being relocated, if any.
328 Local_dynamic_type local_dynamic_type_
;
331 // A class which returns the size required for a relocation type,
332 // used while scanning relocs during a relocatable link.
333 class Relocatable_size_for_reloc
337 get_size_for_reloc(unsigned int, Relobj
*);
340 // Adjust TLS relocation type based on the options and whether this
341 // is a local symbol.
342 static tls::Tls_optimization
343 optimize_tls_reloc(bool is_final
, int r_type
);
345 // Get the GOT section, creating it if necessary.
346 Output_data_got
<32, false>*
347 got_section(Symbol_table
*, Layout
*);
349 // Get the GOT PLT section.
351 got_plt_section() const
353 gold_assert(this->got_plt_
!= NULL
);
354 return this->got_plt_
;
357 // Create a PLT entry for a global symbol.
359 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
361 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
363 define_tls_base_symbol(Symbol_table
*, Layout
*);
365 // Create a GOT entry for the TLS module index.
367 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
368 Sized_relobj
<32, false>* object
);
370 // Get the PLT section.
371 const Output_data_plt_i386
*
374 gold_assert(this->plt_
!= NULL
);
378 // Get the dynamic reloc section, creating it if necessary.
380 rel_dyn_section(Layout
*);
382 // Add a potential copy relocation.
384 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
385 Sized_relobj
<32, false>* object
,
386 unsigned int shndx
, Output_section
* output_section
,
387 Symbol
* sym
, const elfcpp::Rel
<32, false>& reloc
)
389 this->copy_relocs_
.copy_reloc(symtab
, layout
,
390 symtab
->get_sized_symbol
<32>(sym
),
391 object
, shndx
, output_section
, reloc
,
392 this->rel_dyn_section(layout
));
395 // Information about this specific target which we pass to the
396 // general Target structure.
397 static const Target::Target_info i386_info
;
399 // The types of GOT entries needed for this platform.
402 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
403 GOT_TYPE_TLS_NOFFSET
= 1, // GOT entry for negative TLS offset
404 GOT_TYPE_TLS_OFFSET
= 2, // GOT entry for positive TLS offset
405 GOT_TYPE_TLS_PAIR
= 3, // GOT entry for TLS module/offset pair
406 GOT_TYPE_TLS_DESC
= 4 // GOT entry for TLS_DESC pair
410 Output_data_got
<32, false>* got_
;
412 Output_data_plt_i386
* plt_
;
413 // The GOT PLT section.
414 Output_data_space
* got_plt_
;
415 // The _GLOBAL_OFFSET_TABLE_ symbol.
416 Symbol
* global_offset_table_
;
417 // The dynamic reloc section.
418 Reloc_section
* rel_dyn_
;
419 // Relocs saved to avoid a COPY reloc.
420 Copy_relocs
<elfcpp::SHT_REL
, 32, false> copy_relocs_
;
421 // Space for variables copied with a COPY reloc.
422 Output_data_space
* dynbss_
;
423 // Offset of the GOT entry for the TLS module index.
424 unsigned int got_mod_index_offset_
;
425 // True if the _TLS_MODULE_BASE_ symbol has been defined.
426 bool tls_base_symbol_defined_
;
429 const Target::Target_info
Target_i386::i386_info
=
432 false, // is_big_endian
433 elfcpp::EM_386
, // machine_code
434 false, // has_make_symbol
435 false, // has_resolve
436 true, // has_code_fill
437 true, // is_default_stack_executable
439 "/usr/lib/libc.so.1", // dynamic_linker
440 0x08048000, // default_text_segment_address
441 0x1000, // abi_pagesize (overridable by -z max-page-size)
442 0x1000, // common_pagesize (overridable by -z common-page-size)
443 elfcpp::SHN_UNDEF
, // small_common_shndx
444 elfcpp::SHN_UNDEF
, // large_common_shndx
445 0, // small_common_section_flags
446 0, // large_common_section_flags
447 NULL
, // attributes_section
448 NULL
// attributes_vendor
451 // Get the GOT section, creating it if necessary.
453 Output_data_got
<32, false>*
454 Target_i386::got_section(Symbol_table
* symtab
, Layout
* layout
)
456 if (this->got_
== NULL
)
458 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
460 this->got_
= new Output_data_got
<32, false>();
463 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
465 | elfcpp::SHF_WRITE
),
466 this->got_
, false, true, true,
469 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
470 os
= layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
472 | elfcpp::SHF_WRITE
),
473 this->got_plt_
, false, false, false,
476 // The first three entries are reserved.
477 this->got_plt_
->set_current_data_size(3 * 4);
479 // Those bytes can go into the relro segment.
480 layout
->increase_relro(3 * 4);
482 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
483 this->global_offset_table_
=
484 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
485 Symbol_table::PREDEFINED
,
487 0, 0, elfcpp::STT_OBJECT
,
489 elfcpp::STV_HIDDEN
, 0,
496 // Get the dynamic reloc section, creating it if necessary.
498 Target_i386::Reloc_section
*
499 Target_i386::rel_dyn_section(Layout
* layout
)
501 if (this->rel_dyn_
== NULL
)
503 gold_assert(layout
!= NULL
);
504 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
505 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
506 elfcpp::SHF_ALLOC
, this->rel_dyn_
, true,
507 false, false, false);
509 return this->rel_dyn_
;
512 // A class to handle the PLT data.
514 class Output_data_plt_i386
: public Output_section_data
517 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false> Reloc_section
;
519 Output_data_plt_i386(Layout
*, Output_data_space
*);
521 // Add an entry to the PLT.
523 add_entry(Symbol
* gsym
);
525 // Return the .rel.plt section data.
528 { return this->rel_
; }
532 do_adjust_output_section(Output_section
* os
);
534 // Write to a map file.
536 do_print_to_mapfile(Mapfile
* mapfile
) const
537 { mapfile
->print_output_data(this, _("** PLT")); }
540 // The size of an entry in the PLT.
541 static const int plt_entry_size
= 16;
543 // The first entry in the PLT for an executable.
544 static unsigned char exec_first_plt_entry
[plt_entry_size
];
546 // The first entry in the PLT for a shared object.
547 static unsigned char dyn_first_plt_entry
[plt_entry_size
];
549 // Other entries in the PLT for an executable.
550 static unsigned char exec_plt_entry
[plt_entry_size
];
552 // Other entries in the PLT for a shared object.
553 static unsigned char dyn_plt_entry
[plt_entry_size
];
555 // Set the final size.
557 set_final_data_size()
558 { this->set_data_size((this->count_
+ 1) * plt_entry_size
); }
560 // Write out the PLT data.
562 do_write(Output_file
*);
564 // The reloc section.
566 // The .got.plt section.
567 Output_data_space
* got_plt_
;
568 // The number of PLT entries.
572 // Create the PLT section. The ordinary .got section is an argument,
573 // since we need to refer to the start. We also create our own .got
574 // section just for PLT entries.
576 Output_data_plt_i386::Output_data_plt_i386(Layout
* layout
,
577 Output_data_space
* got_plt
)
578 : Output_section_data(4), got_plt_(got_plt
), count_(0)
580 this->rel_
= new Reloc_section(false);
581 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
582 elfcpp::SHF_ALLOC
, this->rel_
, true,
583 false, false, false);
587 Output_data_plt_i386::do_adjust_output_section(Output_section
* os
)
589 // UnixWare sets the entsize of .plt to 4, and so does the old GNU
590 // linker, and so do we.
594 // Add an entry to the PLT.
597 Output_data_plt_i386::add_entry(Symbol
* gsym
)
599 gold_assert(!gsym
->has_plt_offset());
601 // Note that when setting the PLT offset we skip the initial
602 // reserved PLT entry.
603 gsym
->set_plt_offset((this->count_
+ 1) * plt_entry_size
);
607 section_offset_type got_offset
= this->got_plt_
->current_data_size();
609 // Every PLT entry needs a GOT entry which points back to the PLT
610 // entry (this will be changed by the dynamic linker, normally
611 // lazily when the function is called).
612 this->got_plt_
->set_current_data_size(got_offset
+ 4);
614 // Every PLT entry needs a reloc.
615 gsym
->set_needs_dynsym_entry();
616 this->rel_
->add_global(gsym
, elfcpp::R_386_JUMP_SLOT
, this->got_plt_
,
619 // Note that we don't need to save the symbol. The contents of the
620 // PLT are independent of which symbols are used. The symbols only
621 // appear in the relocations.
624 // The first entry in the PLT for an executable.
626 unsigned char Output_data_plt_i386::exec_first_plt_entry
[plt_entry_size
] =
628 0xff, 0x35, // pushl contents of memory address
629 0, 0, 0, 0, // replaced with address of .got + 4
630 0xff, 0x25, // jmp indirect
631 0, 0, 0, 0, // replaced with address of .got + 8
635 // The first entry in the PLT for a shared object.
637 unsigned char Output_data_plt_i386::dyn_first_plt_entry
[plt_entry_size
] =
639 0xff, 0xb3, 4, 0, 0, 0, // pushl 4(%ebx)
640 0xff, 0xa3, 8, 0, 0, 0, // jmp *8(%ebx)
644 // Subsequent entries in the PLT for an executable.
646 unsigned char Output_data_plt_i386::exec_plt_entry
[plt_entry_size
] =
648 0xff, 0x25, // jmp indirect
649 0, 0, 0, 0, // replaced with address of symbol in .got
650 0x68, // pushl immediate
651 0, 0, 0, 0, // replaced with offset into relocation table
652 0xe9, // jmp relative
653 0, 0, 0, 0 // replaced with offset to start of .plt
656 // Subsequent entries in the PLT for a shared object.
658 unsigned char Output_data_plt_i386::dyn_plt_entry
[plt_entry_size
] =
660 0xff, 0xa3, // jmp *offset(%ebx)
661 0, 0, 0, 0, // replaced with offset of symbol in .got
662 0x68, // pushl immediate
663 0, 0, 0, 0, // replaced with offset into relocation table
664 0xe9, // jmp relative
665 0, 0, 0, 0 // replaced with offset to start of .plt
668 // Write out the PLT. This uses the hand-coded instructions above,
669 // and adjusts them as needed. This is all specified by the i386 ELF
670 // Processor Supplement.
673 Output_data_plt_i386::do_write(Output_file
* of
)
675 const off_t offset
= this->offset();
676 const section_size_type oview_size
=
677 convert_to_section_size_type(this->data_size());
678 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
680 const off_t got_file_offset
= this->got_plt_
->offset();
681 const section_size_type got_size
=
682 convert_to_section_size_type(this->got_plt_
->data_size());
683 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
686 unsigned char* pov
= oview
;
688 elfcpp::Elf_types
<32>::Elf_Addr plt_address
= this->address();
689 elfcpp::Elf_types
<32>::Elf_Addr got_address
= this->got_plt_
->address();
691 if (parameters
->options().output_is_position_independent())
692 memcpy(pov
, dyn_first_plt_entry
, plt_entry_size
);
695 memcpy(pov
, exec_first_plt_entry
, plt_entry_size
);
696 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_address
+ 4);
697 elfcpp::Swap
<32, false>::writeval(pov
+ 8, got_address
+ 8);
699 pov
+= plt_entry_size
;
701 unsigned char* got_pov
= got_view
;
703 memset(got_pov
, 0, 12);
706 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
708 unsigned int plt_offset
= plt_entry_size
;
709 unsigned int plt_rel_offset
= 0;
710 unsigned int got_offset
= 12;
711 const unsigned int count
= this->count_
;
712 for (unsigned int i
= 0;
715 pov
+= plt_entry_size
,
717 plt_offset
+= plt_entry_size
,
718 plt_rel_offset
+= rel_size
,
721 // Set and adjust the PLT entry itself.
723 if (parameters
->options().output_is_position_independent())
725 memcpy(pov
, dyn_plt_entry
, plt_entry_size
);
726 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_offset
);
730 memcpy(pov
, exec_plt_entry
, plt_entry_size
);
731 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
736 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 7, plt_rel_offset
);
737 elfcpp::Swap
<32, false>::writeval(pov
+ 12,
738 - (plt_offset
+ plt_entry_size
));
740 // Set the entry in the GOT.
741 elfcpp::Swap
<32, false>::writeval(got_pov
, plt_address
+ plt_offset
+ 6);
744 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
745 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
747 of
->write_output_view(offset
, oview_size
, oview
);
748 of
->write_output_view(got_file_offset
, got_size
, got_view
);
751 // Create a PLT entry for a global symbol.
754 Target_i386::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
)
756 if (gsym
->has_plt_offset())
759 if (this->plt_
== NULL
)
761 // Create the GOT sections first.
762 this->got_section(symtab
, layout
);
764 this->plt_
= new Output_data_plt_i386(layout
, this->got_plt_
);
765 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
767 | elfcpp::SHF_EXECINSTR
),
768 this->plt_
, false, false, false, false);
771 this->plt_
->add_entry(gsym
);
774 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
777 Target_i386::define_tls_base_symbol(Symbol_table
* symtab
, Layout
* layout
)
779 if (this->tls_base_symbol_defined_
)
782 Output_segment
* tls_segment
= layout
->tls_segment();
783 if (tls_segment
!= NULL
)
785 bool is_exec
= parameters
->options().output_is_executable();
786 symtab
->define_in_output_segment("_TLS_MODULE_BASE_", NULL
,
787 Symbol_table::PREDEFINED
,
791 elfcpp::STV_HIDDEN
, 0,
793 ? Symbol::SEGMENT_END
794 : Symbol::SEGMENT_START
),
797 this->tls_base_symbol_defined_
= true;
800 // Create a GOT entry for the TLS module index.
803 Target_i386::got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
804 Sized_relobj
<32, false>* object
)
806 if (this->got_mod_index_offset_
== -1U)
808 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
809 Reloc_section
* rel_dyn
= this->rel_dyn_section(layout
);
810 Output_data_got
<32, false>* got
= this->got_section(symtab
, layout
);
811 unsigned int got_offset
= got
->add_constant(0);
812 rel_dyn
->add_local(object
, 0, elfcpp::R_386_TLS_DTPMOD32
, got
,
814 got
->add_constant(0);
815 this->got_mod_index_offset_
= got_offset
;
817 return this->got_mod_index_offset_
;
820 // Optimize the TLS relocation type based on what we know about the
821 // symbol. IS_FINAL is true if the final address of this symbol is
822 // known at link time.
824 tls::Tls_optimization
825 Target_i386::optimize_tls_reloc(bool is_final
, int r_type
)
827 // If we are generating a shared library, then we can't do anything
829 if (parameters
->options().shared())
830 return tls::TLSOPT_NONE
;
834 case elfcpp::R_386_TLS_GD
:
835 case elfcpp::R_386_TLS_GOTDESC
:
836 case elfcpp::R_386_TLS_DESC_CALL
:
837 // These are General-Dynamic which permits fully general TLS
838 // access. Since we know that we are generating an executable,
839 // we can convert this to Initial-Exec. If we also know that
840 // this is a local symbol, we can further switch to Local-Exec.
842 return tls::TLSOPT_TO_LE
;
843 return tls::TLSOPT_TO_IE
;
845 case elfcpp::R_386_TLS_LDM
:
846 // This is Local-Dynamic, which refers to a local symbol in the
847 // dynamic TLS block. Since we know that we generating an
848 // executable, we can switch to Local-Exec.
849 return tls::TLSOPT_TO_LE
;
851 case elfcpp::R_386_TLS_LDO_32
:
852 // Another type of Local-Dynamic relocation.
853 return tls::TLSOPT_TO_LE
;
855 case elfcpp::R_386_TLS_IE
:
856 case elfcpp::R_386_TLS_GOTIE
:
857 case elfcpp::R_386_TLS_IE_32
:
858 // These are Initial-Exec relocs which get the thread offset
859 // from the GOT. If we know that we are linking against the
860 // local symbol, we can switch to Local-Exec, which links the
861 // thread offset into the instruction.
863 return tls::TLSOPT_TO_LE
;
864 return tls::TLSOPT_NONE
;
866 case elfcpp::R_386_TLS_LE
:
867 case elfcpp::R_386_TLS_LE_32
:
868 // When we already have Local-Exec, there is nothing further we
870 return tls::TLSOPT_NONE
;
877 // Report an unsupported relocation against a local symbol.
880 Target_i386::Scan::unsupported_reloc_local(Sized_relobj
<32, false>* object
,
883 gold_error(_("%s: unsupported reloc %u against local symbol"),
884 object
->name().c_str(), r_type
);
887 // Scan a relocation for a local symbol.
890 Target_i386::Scan::local(Symbol_table
* symtab
,
893 Sized_relobj
<32, false>* object
,
894 unsigned int data_shndx
,
895 Output_section
* output_section
,
896 const elfcpp::Rel
<32, false>& reloc
,
898 const elfcpp::Sym
<32, false>& lsym
)
902 case elfcpp::R_386_NONE
:
903 case elfcpp::R_386_GNU_VTINHERIT
:
904 case elfcpp::R_386_GNU_VTENTRY
:
907 case elfcpp::R_386_32
:
908 // If building a shared library (or a position-independent
909 // executable), we need to create a dynamic relocation for
910 // this location. The relocation applied at link time will
911 // apply the link-time value, so we flag the location with
912 // an R_386_RELATIVE relocation so the dynamic loader can
913 // relocate it easily.
914 if (parameters
->options().output_is_position_independent())
916 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
917 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
918 rel_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_386_RELATIVE
,
919 output_section
, data_shndx
,
920 reloc
.get_r_offset());
924 case elfcpp::R_386_16
:
925 case elfcpp::R_386_8
:
926 // If building a shared library (or a position-independent
927 // executable), we need to create a dynamic relocation for
928 // this location. Because the addend needs to remain in the
929 // data section, we need to be careful not to apply this
930 // relocation statically.
931 if (parameters
->options().output_is_position_independent())
933 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
934 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
935 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
936 rel_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
937 data_shndx
, reloc
.get_r_offset());
940 gold_assert(lsym
.get_st_value() == 0);
941 unsigned int shndx
= lsym
.get_st_shndx();
943 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
946 object
->error(_("section symbol %u has bad shndx %u"),
949 rel_dyn
->add_local_section(object
, shndx
,
950 r_type
, output_section
,
951 data_shndx
, reloc
.get_r_offset());
956 case elfcpp::R_386_PC32
:
957 case elfcpp::R_386_PC16
:
958 case elfcpp::R_386_PC8
:
961 case elfcpp::R_386_PLT32
:
962 // Since we know this is a local symbol, we can handle this as a
966 case elfcpp::R_386_GOTOFF
:
967 case elfcpp::R_386_GOTPC
:
968 // We need a GOT section.
969 target
->got_section(symtab
, layout
);
972 case elfcpp::R_386_GOT32
:
974 // The symbol requires a GOT entry.
975 Output_data_got
<32, false>* got
= target
->got_section(symtab
, layout
);
976 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
977 if (got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
))
979 // If we are generating a shared object, we need to add a
980 // dynamic RELATIVE relocation for this symbol's GOT entry.
981 if (parameters
->options().output_is_position_independent())
983 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
984 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
985 rel_dyn
->add_local_relative(
986 object
, r_sym
, elfcpp::R_386_RELATIVE
, got
,
987 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
));
993 // These are relocations which should only be seen by the
994 // dynamic linker, and should never be seen here.
995 case elfcpp::R_386_COPY
:
996 case elfcpp::R_386_GLOB_DAT
:
997 case elfcpp::R_386_JUMP_SLOT
:
998 case elfcpp::R_386_RELATIVE
:
999 case elfcpp::R_386_TLS_TPOFF
:
1000 case elfcpp::R_386_TLS_DTPMOD32
:
1001 case elfcpp::R_386_TLS_DTPOFF32
:
1002 case elfcpp::R_386_TLS_TPOFF32
:
1003 case elfcpp::R_386_TLS_DESC
:
1004 gold_error(_("%s: unexpected reloc %u in object file"),
1005 object
->name().c_str(), r_type
);
1008 // These are initial TLS relocs, which are expected when
1010 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1011 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1012 case elfcpp::R_386_TLS_DESC_CALL
:
1013 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1014 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1015 case elfcpp::R_386_TLS_IE
: // Initial-exec
1016 case elfcpp::R_386_TLS_IE_32
:
1017 case elfcpp::R_386_TLS_GOTIE
:
1018 case elfcpp::R_386_TLS_LE
: // Local-exec
1019 case elfcpp::R_386_TLS_LE_32
:
1021 bool output_is_shared
= parameters
->options().shared();
1022 const tls::Tls_optimization optimized_type
1023 = Target_i386::optimize_tls_reloc(!output_is_shared
, r_type
);
1026 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1027 if (optimized_type
== tls::TLSOPT_NONE
)
1029 // Create a pair of GOT entries for the module index and
1030 // dtv-relative offset.
1031 Output_data_got
<32, false>* got
1032 = target
->got_section(symtab
, layout
);
1033 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1034 unsigned int shndx
= lsym
.get_st_shndx();
1036 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1038 object
->error(_("local symbol %u has bad shndx %u"),
1041 got
->add_local_pair_with_rel(object
, r_sym
, shndx
,
1043 target
->rel_dyn_section(layout
),
1044 elfcpp::R_386_TLS_DTPMOD32
, 0);
1046 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1047 unsupported_reloc_local(object
, r_type
);
1050 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva)
1051 target
->define_tls_base_symbol(symtab
, layout
);
1052 if (optimized_type
== tls::TLSOPT_NONE
)
1054 // Create a double GOT entry with an R_386_TLS_DESC reloc.
1055 Output_data_got
<32, false>* got
1056 = target
->got_section(symtab
, layout
);
1057 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1058 unsigned int shndx
= lsym
.get_st_shndx();
1060 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1062 object
->error(_("local symbol %u has bad shndx %u"),
1065 got
->add_local_pair_with_rel(object
, r_sym
, shndx
,
1067 target
->rel_dyn_section(layout
),
1068 elfcpp::R_386_TLS_DESC
, 0);
1070 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1071 unsupported_reloc_local(object
, r_type
);
1074 case elfcpp::R_386_TLS_DESC_CALL
:
1077 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1078 if (optimized_type
== tls::TLSOPT_NONE
)
1080 // Create a GOT entry for the module index.
1081 target
->got_mod_index_entry(symtab
, layout
, object
);
1083 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1084 unsupported_reloc_local(object
, r_type
);
1087 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1090 case elfcpp::R_386_TLS_IE
: // Initial-exec
1091 case elfcpp::R_386_TLS_IE_32
:
1092 case elfcpp::R_386_TLS_GOTIE
:
1093 layout
->set_has_static_tls();
1094 if (optimized_type
== tls::TLSOPT_NONE
)
1096 // For the R_386_TLS_IE relocation, we need to create a
1097 // dynamic relocation when building a shared library.
1098 if (r_type
== elfcpp::R_386_TLS_IE
1099 && parameters
->options().shared())
1101 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1103 = elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1104 rel_dyn
->add_local_relative(object
, r_sym
,
1105 elfcpp::R_386_RELATIVE
,
1106 output_section
, data_shndx
,
1107 reloc
.get_r_offset());
1109 // Create a GOT entry for the tp-relative offset.
1110 Output_data_got
<32, false>* got
1111 = target
->got_section(symtab
, layout
);
1112 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1113 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1114 ? elfcpp::R_386_TLS_TPOFF32
1115 : elfcpp::R_386_TLS_TPOFF
);
1116 unsigned int got_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1117 ? GOT_TYPE_TLS_OFFSET
1118 : GOT_TYPE_TLS_NOFFSET
);
1119 got
->add_local_with_rel(object
, r_sym
, got_type
,
1120 target
->rel_dyn_section(layout
),
1123 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1124 unsupported_reloc_local(object
, r_type
);
1127 case elfcpp::R_386_TLS_LE
: // Local-exec
1128 case elfcpp::R_386_TLS_LE_32
:
1129 layout
->set_has_static_tls();
1130 if (output_is_shared
)
1132 // We need to create a dynamic relocation.
1133 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1134 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1135 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_LE_32
1136 ? elfcpp::R_386_TLS_TPOFF32
1137 : elfcpp::R_386_TLS_TPOFF
);
1138 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1139 rel_dyn
->add_local(object
, r_sym
, dyn_r_type
, output_section
,
1140 data_shndx
, reloc
.get_r_offset());
1150 case elfcpp::R_386_32PLT
:
1151 case elfcpp::R_386_TLS_GD_32
:
1152 case elfcpp::R_386_TLS_GD_PUSH
:
1153 case elfcpp::R_386_TLS_GD_CALL
:
1154 case elfcpp::R_386_TLS_GD_POP
:
1155 case elfcpp::R_386_TLS_LDM_32
:
1156 case elfcpp::R_386_TLS_LDM_PUSH
:
1157 case elfcpp::R_386_TLS_LDM_CALL
:
1158 case elfcpp::R_386_TLS_LDM_POP
:
1159 case elfcpp::R_386_USED_BY_INTEL_200
:
1161 unsupported_reloc_local(object
, r_type
);
1166 // Report an unsupported relocation against a global symbol.
1169 Target_i386::Scan::unsupported_reloc_global(Sized_relobj
<32, false>* object
,
1170 unsigned int r_type
,
1173 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1174 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1177 // Scan a relocation for a global symbol.
1180 Target_i386::Scan::global(Symbol_table
* symtab
,
1182 Target_i386
* target
,
1183 Sized_relobj
<32, false>* object
,
1184 unsigned int data_shndx
,
1185 Output_section
* output_section
,
1186 const elfcpp::Rel
<32, false>& reloc
,
1187 unsigned int r_type
,
1192 case elfcpp::R_386_NONE
:
1193 case elfcpp::R_386_GNU_VTINHERIT
:
1194 case elfcpp::R_386_GNU_VTENTRY
:
1197 case elfcpp::R_386_32
:
1198 case elfcpp::R_386_16
:
1199 case elfcpp::R_386_8
:
1201 // Make a PLT entry if necessary.
1202 if (gsym
->needs_plt_entry())
1204 target
->make_plt_entry(symtab
, layout
, gsym
);
1205 // Since this is not a PC-relative relocation, we may be
1206 // taking the address of a function. In that case we need to
1207 // set the entry in the dynamic symbol table to the address of
1209 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
1210 gsym
->set_needs_dynsym_value();
1212 // Make a dynamic relocation if necessary.
1213 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
1215 if (gsym
->may_need_copy_reloc())
1217 target
->copy_reloc(symtab
, layout
, object
,
1218 data_shndx
, output_section
, gsym
, reloc
);
1220 else if (r_type
== elfcpp::R_386_32
1221 && gsym
->can_use_relative_reloc(false))
1223 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1224 rel_dyn
->add_global_relative(gsym
, elfcpp::R_386_RELATIVE
,
1225 output_section
, object
,
1226 data_shndx
, reloc
.get_r_offset());
1230 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1231 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1232 data_shndx
, reloc
.get_r_offset());
1238 case elfcpp::R_386_PC32
:
1239 case elfcpp::R_386_PC16
:
1240 case elfcpp::R_386_PC8
:
1242 // Make a PLT entry if necessary.
1243 if (gsym
->needs_plt_entry())
1245 // These relocations are used for function calls only in
1246 // non-PIC code. For a 32-bit relocation in a shared library,
1247 // we'll need a text relocation anyway, so we can skip the
1248 // PLT entry and let the dynamic linker bind the call directly
1249 // to the target. For smaller relocations, we should use a
1250 // PLT entry to ensure that the call can reach.
1251 if (!parameters
->options().shared()
1252 || r_type
!= elfcpp::R_386_PC32
)
1253 target
->make_plt_entry(symtab
, layout
, gsym
);
1255 // Make a dynamic relocation if necessary.
1256 int flags
= Symbol::NON_PIC_REF
;
1257 if (gsym
->is_func())
1258 flags
|= Symbol::FUNCTION_CALL
;
1259 if (gsym
->needs_dynamic_reloc(flags
))
1261 if (gsym
->may_need_copy_reloc())
1263 target
->copy_reloc(symtab
, layout
, object
,
1264 data_shndx
, output_section
, gsym
, reloc
);
1268 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1269 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1270 data_shndx
, reloc
.get_r_offset());
1276 case elfcpp::R_386_GOT32
:
1278 // The symbol requires a GOT entry.
1279 Output_data_got
<32, false>* got
= target
->got_section(symtab
, layout
);
1280 if (gsym
->final_value_is_known())
1281 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
1284 // If this symbol is not fully resolved, we need to add a
1285 // GOT entry with a dynamic relocation.
1286 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1287 if (gsym
->is_from_dynobj()
1288 || gsym
->is_undefined()
1289 || gsym
->is_preemptible())
1290 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
,
1291 rel_dyn
, elfcpp::R_386_GLOB_DAT
);
1294 if (got
->add_global(gsym
, GOT_TYPE_STANDARD
))
1295 rel_dyn
->add_global_relative(
1296 gsym
, elfcpp::R_386_RELATIVE
, got
,
1297 gsym
->got_offset(GOT_TYPE_STANDARD
));
1303 case elfcpp::R_386_PLT32
:
1304 // If the symbol is fully resolved, this is just a PC32 reloc.
1305 // Otherwise we need a PLT entry.
1306 if (gsym
->final_value_is_known())
1308 // If building a shared library, we can also skip the PLT entry
1309 // if the symbol is defined in the output file and is protected
1311 if (gsym
->is_defined()
1312 && !gsym
->is_from_dynobj()
1313 && !gsym
->is_preemptible())
1315 target
->make_plt_entry(symtab
, layout
, gsym
);
1318 case elfcpp::R_386_GOTOFF
:
1319 case elfcpp::R_386_GOTPC
:
1320 // We need a GOT section.
1321 target
->got_section(symtab
, layout
);
1324 // These are relocations which should only be seen by the
1325 // dynamic linker, and should never be seen here.
1326 case elfcpp::R_386_COPY
:
1327 case elfcpp::R_386_GLOB_DAT
:
1328 case elfcpp::R_386_JUMP_SLOT
:
1329 case elfcpp::R_386_RELATIVE
:
1330 case elfcpp::R_386_TLS_TPOFF
:
1331 case elfcpp::R_386_TLS_DTPMOD32
:
1332 case elfcpp::R_386_TLS_DTPOFF32
:
1333 case elfcpp::R_386_TLS_TPOFF32
:
1334 case elfcpp::R_386_TLS_DESC
:
1335 gold_error(_("%s: unexpected reloc %u in object file"),
1336 object
->name().c_str(), r_type
);
1339 // These are initial tls relocs, which are expected when
1341 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1342 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1343 case elfcpp::R_386_TLS_DESC_CALL
:
1344 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1345 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1346 case elfcpp::R_386_TLS_IE
: // Initial-exec
1347 case elfcpp::R_386_TLS_IE_32
:
1348 case elfcpp::R_386_TLS_GOTIE
:
1349 case elfcpp::R_386_TLS_LE
: // Local-exec
1350 case elfcpp::R_386_TLS_LE_32
:
1352 const bool is_final
= gsym
->final_value_is_known();
1353 const tls::Tls_optimization optimized_type
1354 = Target_i386::optimize_tls_reloc(is_final
, r_type
);
1357 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1358 if (optimized_type
== tls::TLSOPT_NONE
)
1360 // Create a pair of GOT entries for the module index and
1361 // dtv-relative offset.
1362 Output_data_got
<32, false>* got
1363 = target
->got_section(symtab
, layout
);
1364 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
1365 target
->rel_dyn_section(layout
),
1366 elfcpp::R_386_TLS_DTPMOD32
,
1367 elfcpp::R_386_TLS_DTPOFF32
);
1369 else if (optimized_type
== tls::TLSOPT_TO_IE
)
1371 // Create a GOT entry for the tp-relative offset.
1372 Output_data_got
<32, false>* got
1373 = target
->got_section(symtab
, layout
);
1374 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_NOFFSET
,
1375 target
->rel_dyn_section(layout
),
1376 elfcpp::R_386_TLS_TPOFF
);
1378 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1379 unsupported_reloc_global(object
, r_type
, gsym
);
1382 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (~oliva url)
1383 target
->define_tls_base_symbol(symtab
, layout
);
1384 if (optimized_type
== tls::TLSOPT_NONE
)
1386 // Create a double GOT entry with an R_386_TLS_DESC reloc.
1387 Output_data_got
<32, false>* got
1388 = target
->got_section(symtab
, layout
);
1389 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_DESC
,
1390 target
->rel_dyn_section(layout
),
1391 elfcpp::R_386_TLS_DESC
, 0);
1393 else if (optimized_type
== tls::TLSOPT_TO_IE
)
1395 // Create a GOT entry for the tp-relative offset.
1396 Output_data_got
<32, false>* got
1397 = target
->got_section(symtab
, layout
);
1398 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_NOFFSET
,
1399 target
->rel_dyn_section(layout
),
1400 elfcpp::R_386_TLS_TPOFF
);
1402 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1403 unsupported_reloc_global(object
, r_type
, gsym
);
1406 case elfcpp::R_386_TLS_DESC_CALL
:
1409 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1410 if (optimized_type
== tls::TLSOPT_NONE
)
1412 // Create a GOT entry for the module index.
1413 target
->got_mod_index_entry(symtab
, layout
, object
);
1415 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1416 unsupported_reloc_global(object
, r_type
, gsym
);
1419 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1422 case elfcpp::R_386_TLS_IE
: // Initial-exec
1423 case elfcpp::R_386_TLS_IE_32
:
1424 case elfcpp::R_386_TLS_GOTIE
:
1425 layout
->set_has_static_tls();
1426 if (optimized_type
== tls::TLSOPT_NONE
)
1428 // For the R_386_TLS_IE relocation, we need to create a
1429 // dynamic relocation when building a shared library.
1430 if (r_type
== elfcpp::R_386_TLS_IE
1431 && parameters
->options().shared())
1433 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1434 rel_dyn
->add_global_relative(gsym
, elfcpp::R_386_RELATIVE
,
1435 output_section
, object
,
1437 reloc
.get_r_offset());
1439 // Create a GOT entry for the tp-relative offset.
1440 Output_data_got
<32, false>* got
1441 = target
->got_section(symtab
, layout
);
1442 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1443 ? elfcpp::R_386_TLS_TPOFF32
1444 : elfcpp::R_386_TLS_TPOFF
);
1445 unsigned int got_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1446 ? GOT_TYPE_TLS_OFFSET
1447 : GOT_TYPE_TLS_NOFFSET
);
1448 got
->add_global_with_rel(gsym
, got_type
,
1449 target
->rel_dyn_section(layout
),
1452 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1453 unsupported_reloc_global(object
, r_type
, gsym
);
1456 case elfcpp::R_386_TLS_LE
: // Local-exec
1457 case elfcpp::R_386_TLS_LE_32
:
1458 layout
->set_has_static_tls();
1459 if (parameters
->options().shared())
1461 // We need to create a dynamic relocation.
1462 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_LE_32
1463 ? elfcpp::R_386_TLS_TPOFF32
1464 : elfcpp::R_386_TLS_TPOFF
);
1465 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1466 rel_dyn
->add_global(gsym
, dyn_r_type
, output_section
, object
,
1467 data_shndx
, reloc
.get_r_offset());
1477 case elfcpp::R_386_32PLT
:
1478 case elfcpp::R_386_TLS_GD_32
:
1479 case elfcpp::R_386_TLS_GD_PUSH
:
1480 case elfcpp::R_386_TLS_GD_CALL
:
1481 case elfcpp::R_386_TLS_GD_POP
:
1482 case elfcpp::R_386_TLS_LDM_32
:
1483 case elfcpp::R_386_TLS_LDM_PUSH
:
1484 case elfcpp::R_386_TLS_LDM_CALL
:
1485 case elfcpp::R_386_TLS_LDM_POP
:
1486 case elfcpp::R_386_USED_BY_INTEL_200
:
1488 unsupported_reloc_global(object
, r_type
, gsym
);
1493 // Process relocations for gc.
1496 Target_i386::gc_process_relocs(Symbol_table
* symtab
,
1498 Sized_relobj
<32, false>* object
,
1499 unsigned int data_shndx
,
1501 const unsigned char* prelocs
,
1503 Output_section
* output_section
,
1504 bool needs_special_offset_handling
,
1505 size_t local_symbol_count
,
1506 const unsigned char* plocal_symbols
)
1508 gold::gc_process_relocs
<32, false, Target_i386
, elfcpp::SHT_REL
,
1518 needs_special_offset_handling
,
1523 // Scan relocations for a section.
1526 Target_i386::scan_relocs(Symbol_table
* symtab
,
1528 Sized_relobj
<32, false>* object
,
1529 unsigned int data_shndx
,
1530 unsigned int sh_type
,
1531 const unsigned char* prelocs
,
1533 Output_section
* output_section
,
1534 bool needs_special_offset_handling
,
1535 size_t local_symbol_count
,
1536 const unsigned char* plocal_symbols
)
1538 if (sh_type
== elfcpp::SHT_RELA
)
1540 gold_error(_("%s: unsupported RELA reloc section"),
1541 object
->name().c_str());
1545 gold::scan_relocs
<32, false, Target_i386
, elfcpp::SHT_REL
,
1555 needs_special_offset_handling
,
1560 // Finalize the sections.
1563 Target_i386::do_finalize_sections(
1565 const Input_objects
*,
1566 Symbol_table
* symtab
)
1568 // Fill in some more dynamic tags.
1569 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
1572 if (this->got_plt_
!= NULL
1573 && this->got_plt_
->output_section() != NULL
)
1574 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->got_plt_
);
1576 if (this->plt_
!= NULL
1577 && this->plt_
->output_section() != NULL
)
1579 const Output_data
* od
= this->plt_
->rel_plt();
1580 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
1581 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
1582 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_REL
);
1585 if (this->rel_dyn_
!= NULL
1586 && this->rel_dyn_
->output_section() != NULL
)
1588 const Output_data
* od
= this->rel_dyn_
;
1589 odyn
->add_section_address(elfcpp::DT_REL
, od
);
1590 odyn
->add_section_size(elfcpp::DT_RELSZ
, od
);
1591 odyn
->add_constant(elfcpp::DT_RELENT
,
1592 elfcpp::Elf_sizes
<32>::rel_size
);
1595 if (!parameters
->options().shared())
1597 // The value of the DT_DEBUG tag is filled in by the dynamic
1598 // linker at run time, and used by the debugger.
1599 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
1603 // Emit any relocs we saved in an attempt to avoid generating COPY
1605 if (this->copy_relocs_
.any_saved_relocs())
1606 this->copy_relocs_
.emit(this->rel_dyn_section(layout
));
1608 // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
1609 // the .got.plt section.
1610 Symbol
* sym
= this->global_offset_table_
;
1613 uint32_t data_size
= this->got_plt_
->current_data_size();
1614 symtab
->get_sized_symbol
<32>(sym
)->set_symsize(data_size
);
1618 // Return whether a direct absolute static relocation needs to be applied.
1619 // In cases where Scan::local() or Scan::global() has created
1620 // a dynamic relocation other than R_386_RELATIVE, the addend
1621 // of the relocation is carried in the data, and we must not
1622 // apply the static relocation.
1625 Target_i386::Relocate::should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
1628 Output_section
* output_section
)
1630 // If the output section is not allocated, then we didn't call
1631 // scan_relocs, we didn't create a dynamic reloc, and we must apply
1633 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
1636 // For local symbols, we will have created a non-RELATIVE dynamic
1637 // relocation only if (a) the output is position independent,
1638 // (b) the relocation is absolute (not pc- or segment-relative), and
1639 // (c) the relocation is not 32 bits wide.
1641 return !(parameters
->options().output_is_position_independent()
1642 && (ref_flags
& Symbol::ABSOLUTE_REF
)
1645 // For global symbols, we use the same helper routines used in the
1646 // scan pass. If we did not create a dynamic relocation, or if we
1647 // created a RELATIVE dynamic relocation, we should apply the static
1649 bool has_dyn
= gsym
->needs_dynamic_reloc(ref_flags
);
1650 bool is_rel
= (ref_flags
& Symbol::ABSOLUTE_REF
)
1651 && gsym
->can_use_relative_reloc(ref_flags
1652 & Symbol::FUNCTION_CALL
);
1653 return !has_dyn
|| is_rel
;
1656 // Perform a relocation.
1659 Target_i386::Relocate::relocate(const Relocate_info
<32, false>* relinfo
,
1660 Target_i386
* target
,
1661 Output_section
*output_section
,
1663 const elfcpp::Rel
<32, false>& rel
,
1664 unsigned int r_type
,
1665 const Sized_symbol
<32>* gsym
,
1666 const Symbol_value
<32>* psymval
,
1667 unsigned char* view
,
1668 elfcpp::Elf_types
<32>::Elf_Addr address
,
1669 section_size_type view_size
)
1671 if (this->skip_call_tls_get_addr_
)
1673 if ((r_type
!= elfcpp::R_386_PLT32
1674 && r_type
!= elfcpp::R_386_PC32
)
1676 || strcmp(gsym
->name(), "___tls_get_addr") != 0)
1677 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1678 _("missing expected TLS relocation"));
1681 this->skip_call_tls_get_addr_
= false;
1686 // Pick the value to use for symbols defined in shared objects.
1687 Symbol_value
<32> symval
;
1689 && gsym
->use_plt_offset(r_type
== elfcpp::R_386_PC8
1690 || r_type
== elfcpp::R_386_PC16
1691 || r_type
== elfcpp::R_386_PC32
))
1693 symval
.set_output_value(target
->plt_section()->address()
1694 + gsym
->plt_offset());
1698 const Sized_relobj
<32, false>* object
= relinfo
->object
;
1700 // Get the GOT offset if needed.
1701 // The GOT pointer points to the end of the GOT section.
1702 // We need to subtract the size of the GOT section to get
1703 // the actual offset to use in the relocation.
1704 bool have_got_offset
= false;
1705 unsigned int got_offset
= 0;
1708 case elfcpp::R_386_GOT32
:
1711 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
1712 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
1713 - target
->got_size());
1717 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1718 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
1719 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
1720 - target
->got_size());
1722 have_got_offset
= true;
1731 case elfcpp::R_386_NONE
:
1732 case elfcpp::R_386_GNU_VTINHERIT
:
1733 case elfcpp::R_386_GNU_VTENTRY
:
1736 case elfcpp::R_386_32
:
1737 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1739 Relocate_functions
<32, false>::rel32(view
, object
, psymval
);
1742 case elfcpp::R_386_PC32
:
1744 int ref_flags
= Symbol::NON_PIC_REF
;
1745 if (gsym
!= NULL
&& gsym
->is_func())
1746 ref_flags
|= Symbol::FUNCTION_CALL
;
1747 if (should_apply_static_reloc(gsym
, ref_flags
, true, output_section
))
1748 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1752 case elfcpp::R_386_16
:
1753 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
1755 Relocate_functions
<32, false>::rel16(view
, object
, psymval
);
1758 case elfcpp::R_386_PC16
:
1760 int ref_flags
= Symbol::NON_PIC_REF
;
1761 if (gsym
!= NULL
&& gsym
->is_func())
1762 ref_flags
|= Symbol::FUNCTION_CALL
;
1763 if (should_apply_static_reloc(gsym
, ref_flags
, false, output_section
))
1764 Relocate_functions
<32, false>::pcrel16(view
, object
, psymval
, address
);
1768 case elfcpp::R_386_8
:
1769 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
1771 Relocate_functions
<32, false>::rel8(view
, object
, psymval
);
1774 case elfcpp::R_386_PC8
:
1776 int ref_flags
= Symbol::NON_PIC_REF
;
1777 if (gsym
!= NULL
&& gsym
->is_func())
1778 ref_flags
|= Symbol::FUNCTION_CALL
;
1779 if (should_apply_static_reloc(gsym
, ref_flags
, false,
1781 Relocate_functions
<32, false>::pcrel8(view
, object
, psymval
, address
);
1785 case elfcpp::R_386_PLT32
:
1786 gold_assert(gsym
== NULL
1787 || gsym
->has_plt_offset()
1788 || gsym
->final_value_is_known()
1789 || (gsym
->is_defined()
1790 && !gsym
->is_from_dynobj()
1791 && !gsym
->is_preemptible()));
1792 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1795 case elfcpp::R_386_GOT32
:
1796 gold_assert(have_got_offset
);
1797 Relocate_functions
<32, false>::rel32(view
, got_offset
);
1800 case elfcpp::R_386_GOTOFF
:
1802 elfcpp::Elf_types
<32>::Elf_Addr value
;
1803 value
= (psymval
->value(object
, 0)
1804 - target
->got_plt_section()->address());
1805 Relocate_functions
<32, false>::rel32(view
, value
);
1809 case elfcpp::R_386_GOTPC
:
1811 elfcpp::Elf_types
<32>::Elf_Addr value
;
1812 value
= target
->got_plt_section()->address();
1813 Relocate_functions
<32, false>::pcrel32(view
, value
, address
);
1817 case elfcpp::R_386_COPY
:
1818 case elfcpp::R_386_GLOB_DAT
:
1819 case elfcpp::R_386_JUMP_SLOT
:
1820 case elfcpp::R_386_RELATIVE
:
1821 // These are outstanding tls relocs, which are unexpected when
1823 case elfcpp::R_386_TLS_TPOFF
:
1824 case elfcpp::R_386_TLS_DTPMOD32
:
1825 case elfcpp::R_386_TLS_DTPOFF32
:
1826 case elfcpp::R_386_TLS_TPOFF32
:
1827 case elfcpp::R_386_TLS_DESC
:
1828 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1829 _("unexpected reloc %u in object file"),
1833 // These are initial tls relocs, which are expected when
1835 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1836 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1837 case elfcpp::R_386_TLS_DESC_CALL
:
1838 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1839 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1840 case elfcpp::R_386_TLS_IE
: // Initial-exec
1841 case elfcpp::R_386_TLS_IE_32
:
1842 case elfcpp::R_386_TLS_GOTIE
:
1843 case elfcpp::R_386_TLS_LE
: // Local-exec
1844 case elfcpp::R_386_TLS_LE_32
:
1845 this->relocate_tls(relinfo
, target
, relnum
, rel
, r_type
, gsym
, psymval
,
1846 view
, address
, view_size
);
1849 case elfcpp::R_386_32PLT
:
1850 case elfcpp::R_386_TLS_GD_32
:
1851 case elfcpp::R_386_TLS_GD_PUSH
:
1852 case elfcpp::R_386_TLS_GD_CALL
:
1853 case elfcpp::R_386_TLS_GD_POP
:
1854 case elfcpp::R_386_TLS_LDM_32
:
1855 case elfcpp::R_386_TLS_LDM_PUSH
:
1856 case elfcpp::R_386_TLS_LDM_CALL
:
1857 case elfcpp::R_386_TLS_LDM_POP
:
1858 case elfcpp::R_386_USED_BY_INTEL_200
:
1860 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1861 _("unsupported reloc %u"),
1869 // Perform a TLS relocation.
1872 Target_i386::Relocate::relocate_tls(const Relocate_info
<32, false>* relinfo
,
1873 Target_i386
* target
,
1875 const elfcpp::Rel
<32, false>& rel
,
1876 unsigned int r_type
,
1877 const Sized_symbol
<32>* gsym
,
1878 const Symbol_value
<32>* psymval
,
1879 unsigned char* view
,
1880 elfcpp::Elf_types
<32>::Elf_Addr
,
1881 section_size_type view_size
)
1883 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
1885 const Sized_relobj
<32, false>* object
= relinfo
->object
;
1887 elfcpp::Elf_types
<32>::Elf_Addr value
= psymval
->value(object
, 0);
1889 const bool is_final
=
1891 ? !parameters
->options().output_is_position_independent()
1892 : gsym
->final_value_is_known());
1893 const tls::Tls_optimization optimized_type
1894 = Target_i386::optimize_tls_reloc(is_final
, r_type
);
1897 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1898 if (optimized_type
== tls::TLSOPT_TO_LE
)
1900 gold_assert(tls_segment
!= NULL
);
1901 this->tls_gd_to_le(relinfo
, relnum
, tls_segment
,
1902 rel
, r_type
, value
, view
,
1908 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
1909 ? GOT_TYPE_TLS_NOFFSET
1910 : GOT_TYPE_TLS_PAIR
);
1911 unsigned int got_offset
;
1914 gold_assert(gsym
->has_got_offset(got_type
));
1915 got_offset
= gsym
->got_offset(got_type
) - target
->got_size();
1919 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1920 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
1921 got_offset
= (object
->local_got_offset(r_sym
, got_type
)
1922 - target
->got_size());
1924 if (optimized_type
== tls::TLSOPT_TO_IE
)
1926 gold_assert(tls_segment
!= NULL
);
1927 this->tls_gd_to_ie(relinfo
, relnum
, tls_segment
, rel
, r_type
,
1928 got_offset
, view
, view_size
);
1931 else if (optimized_type
== tls::TLSOPT_NONE
)
1933 // Relocate the field with the offset of the pair of GOT
1935 Relocate_functions
<32, false>::rel32(view
, got_offset
);
1939 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1940 _("unsupported reloc %u"),
1944 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1945 case elfcpp::R_386_TLS_DESC_CALL
:
1946 this->local_dynamic_type_
= LOCAL_DYNAMIC_GNU
;
1947 if (optimized_type
== tls::TLSOPT_TO_LE
)
1949 gold_assert(tls_segment
!= NULL
);
1950 this->tls_desc_gd_to_le(relinfo
, relnum
, tls_segment
,
1951 rel
, r_type
, value
, view
,
1957 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
1958 ? GOT_TYPE_TLS_NOFFSET
1959 : GOT_TYPE_TLS_DESC
);
1960 unsigned int got_offset
;
1963 gold_assert(gsym
->has_got_offset(got_type
));
1964 got_offset
= gsym
->got_offset(got_type
) - target
->got_size();
1968 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1969 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
1970 got_offset
= (object
->local_got_offset(r_sym
, got_type
)
1971 - target
->got_size());
1973 if (optimized_type
== tls::TLSOPT_TO_IE
)
1975 gold_assert(tls_segment
!= NULL
);
1976 this->tls_desc_gd_to_ie(relinfo
, relnum
, tls_segment
, rel
, r_type
,
1977 got_offset
, view
, view_size
);
1980 else if (optimized_type
== tls::TLSOPT_NONE
)
1982 if (r_type
== elfcpp::R_386_TLS_GOTDESC
)
1984 // Relocate the field with the offset of the pair of GOT
1986 Relocate_functions
<32, false>::rel32(view
, got_offset
);
1991 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1992 _("unsupported reloc %u"),
1996 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1997 if (this->local_dynamic_type_
== LOCAL_DYNAMIC_SUN
)
1999 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2000 _("both SUN and GNU model "
2001 "TLS relocations"));
2004 this->local_dynamic_type_
= LOCAL_DYNAMIC_GNU
;
2005 if (optimized_type
== tls::TLSOPT_TO_LE
)
2007 gold_assert(tls_segment
!= NULL
);
2008 this->tls_ld_to_le(relinfo
, relnum
, tls_segment
, rel
, r_type
,
2009 value
, view
, view_size
);
2012 else if (optimized_type
== tls::TLSOPT_NONE
)
2014 // Relocate the field with the offset of the GOT entry for
2015 // the module index.
2016 unsigned int got_offset
;
2017 got_offset
= (target
->got_mod_index_entry(NULL
, NULL
, NULL
)
2018 - target
->got_size());
2019 Relocate_functions
<32, false>::rel32(view
, got_offset
);
2022 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2023 _("unsupported reloc %u"),
2027 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
2028 if (optimized_type
== tls::TLSOPT_TO_LE
)
2030 // This reloc can appear in debugging sections, in which
2031 // case we must not convert to local-exec. We decide what
2032 // to do based on whether the section is marked as
2033 // containing executable code. That is what the GNU linker
2035 elfcpp::Shdr
<32, false> shdr(relinfo
->data_shdr
);
2036 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
2038 gold_assert(tls_segment
!= NULL
);
2039 value
-= tls_segment
->memsz();
2042 Relocate_functions
<32, false>::rel32(view
, value
);
2045 case elfcpp::R_386_TLS_IE
: // Initial-exec
2046 case elfcpp::R_386_TLS_GOTIE
:
2047 case elfcpp::R_386_TLS_IE_32
:
2048 if (optimized_type
== tls::TLSOPT_TO_LE
)
2050 gold_assert(tls_segment
!= NULL
);
2051 Target_i386::Relocate::tls_ie_to_le(relinfo
, relnum
, tls_segment
,
2052 rel
, r_type
, value
, view
,
2056 else if (optimized_type
== tls::TLSOPT_NONE
)
2058 // Relocate the field with the offset of the GOT entry for
2059 // the tp-relative offset of the symbol.
2060 unsigned int got_type
= (r_type
== elfcpp::R_386_TLS_IE_32
2061 ? GOT_TYPE_TLS_OFFSET
2062 : GOT_TYPE_TLS_NOFFSET
);
2063 unsigned int got_offset
;
2066 gold_assert(gsym
->has_got_offset(got_type
));
2067 got_offset
= gsym
->got_offset(got_type
);
2071 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
2072 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2073 got_offset
= object
->local_got_offset(r_sym
, got_type
);
2075 // For the R_386_TLS_IE relocation, we need to apply the
2076 // absolute address of the GOT entry.
2077 if (r_type
== elfcpp::R_386_TLS_IE
)
2078 got_offset
+= target
->got_plt_section()->address();
2079 // All GOT offsets are relative to the end of the GOT.
2080 got_offset
-= target
->got_size();
2081 Relocate_functions
<32, false>::rel32(view
, got_offset
);
2084 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2085 _("unsupported reloc %u"),
2089 case elfcpp::R_386_TLS_LE
: // Local-exec
2090 // If we're creating a shared library, a dynamic relocation will
2091 // have been created for this location, so do not apply it now.
2092 if (!parameters
->options().shared())
2094 gold_assert(tls_segment
!= NULL
);
2095 value
-= tls_segment
->memsz();
2096 Relocate_functions
<32, false>::rel32(view
, value
);
2100 case elfcpp::R_386_TLS_LE_32
:
2101 // If we're creating a shared library, a dynamic relocation will
2102 // have been created for this location, so do not apply it now.
2103 if (!parameters
->options().shared())
2105 gold_assert(tls_segment
!= NULL
);
2106 value
= tls_segment
->memsz() - value
;
2107 Relocate_functions
<32, false>::rel32(view
, value
);
2113 // Do a relocation in which we convert a TLS General-Dynamic to a
2117 Target_i386::Relocate::tls_gd_to_le(const Relocate_info
<32, false>* relinfo
,
2119 Output_segment
* tls_segment
,
2120 const elfcpp::Rel
<32, false>& rel
,
2122 elfcpp::Elf_types
<32>::Elf_Addr value
,
2123 unsigned char* view
,
2124 section_size_type view_size
)
2126 // leal foo(,%reg,1),%eax; call ___tls_get_addr
2127 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
2128 // leal foo(%reg),%eax; call ___tls_get_addr
2129 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
2131 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2132 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 9);
2134 unsigned char op1
= view
[-1];
2135 unsigned char op2
= view
[-2];
2137 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2138 op2
== 0x8d || op2
== 0x04);
2139 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[4] == 0xe8);
2145 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -3);
2146 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[-3] == 0x8d);
2147 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2148 ((op1
& 0xc7) == 0x05 && op1
!= (4 << 3)));
2149 memcpy(view
- 3, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2153 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2154 (op1
& 0xf8) == 0x80 && (op1
& 7) != 4);
2155 if (rel
.get_r_offset() + 9 < view_size
2158 // There is a trailing nop. Use the size byte subl.
2159 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2164 // Use the five byte subl.
2165 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2169 value
= tls_segment
->memsz() - value
;
2170 Relocate_functions
<32, false>::rel32(view
+ roff
, value
);
2172 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2174 this->skip_call_tls_get_addr_
= true;
2177 // Do a relocation in which we convert a TLS General-Dynamic to an
2181 Target_i386::Relocate::tls_gd_to_ie(const Relocate_info
<32, false>* relinfo
,
2184 const elfcpp::Rel
<32, false>& rel
,
2186 elfcpp::Elf_types
<32>::Elf_Addr value
,
2187 unsigned char* view
,
2188 section_size_type view_size
)
2190 // leal foo(,%ebx,1),%eax; call ___tls_get_addr
2191 // ==> movl %gs:0,%eax; addl foo@gotntpoff(%ebx),%eax
2193 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2194 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 9);
2196 unsigned char op1
= view
[-1];
2197 unsigned char op2
= view
[-2];
2199 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2200 op2
== 0x8d || op2
== 0x04);
2201 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[4] == 0xe8);
2205 // FIXME: For now, support only the first (SIB) form.
2206 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), op2
== 0x04);
2210 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -3);
2211 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[-3] == 0x8d);
2212 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2213 ((op1
& 0xc7) == 0x05 && op1
!= (4 << 3)));
2214 memcpy(view
- 3, "\x65\xa1\0\0\0\0\x03\x83\0\0\0", 12);
2218 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2219 (op1
& 0xf8) == 0x80 && (op1
& 7) != 4);
2220 if (rel
.get_r_offset() + 9 < view_size
2223 // FIXME: This is not the right instruction sequence.
2224 // There is a trailing nop. Use the size byte subl.
2225 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2230 // FIXME: This is not the right instruction sequence.
2231 // Use the five byte subl.
2232 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2236 Relocate_functions
<32, false>::rel32(view
+ roff
, value
);
2238 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2240 this->skip_call_tls_get_addr_
= true;
2243 // Do a relocation in which we convert a TLS_GOTDESC or TLS_DESC_CALL
2244 // General-Dynamic to a Local-Exec.
2247 Target_i386::Relocate::tls_desc_gd_to_le(
2248 const Relocate_info
<32, false>* relinfo
,
2250 Output_segment
* tls_segment
,
2251 const elfcpp::Rel
<32, false>& rel
,
2252 unsigned int r_type
,
2253 elfcpp::Elf_types
<32>::Elf_Addr value
,
2254 unsigned char* view
,
2255 section_size_type view_size
)
2257 if (r_type
== elfcpp::R_386_TLS_GOTDESC
)
2259 // leal foo@TLSDESC(%ebx), %eax
2260 // ==> leal foo@NTPOFF, %eax
2261 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2262 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2263 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2264 view
[-2] == 0x8d && view
[-1] == 0x83);
2266 value
-= tls_segment
->memsz();
2267 Relocate_functions
<32, false>::rel32(view
, value
);
2271 // call *foo@TLSCALL(%eax)
2273 gold_assert(r_type
== elfcpp::R_386_TLS_DESC_CALL
);
2274 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 2);
2275 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2276 view
[0] == 0xff && view
[1] == 0x10);
2282 // Do a relocation in which we convert a TLS_GOTDESC or TLS_DESC_CALL
2283 // General-Dynamic to an Initial-Exec.
2286 Target_i386::Relocate::tls_desc_gd_to_ie(
2287 const Relocate_info
<32, false>* relinfo
,
2290 const elfcpp::Rel
<32, false>& rel
,
2291 unsigned int r_type
,
2292 elfcpp::Elf_types
<32>::Elf_Addr value
,
2293 unsigned char* view
,
2294 section_size_type view_size
)
2296 if (r_type
== elfcpp::R_386_TLS_GOTDESC
)
2298 // leal foo@TLSDESC(%ebx), %eax
2299 // ==> movl foo@GOTNTPOFF(%ebx), %eax
2300 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2301 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2302 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2303 view
[-2] == 0x8d && view
[-1] == 0x83);
2305 Relocate_functions
<32, false>::rel32(view
, value
);
2309 // call *foo@TLSCALL(%eax)
2311 gold_assert(r_type
== elfcpp::R_386_TLS_DESC_CALL
);
2312 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 2);
2313 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2314 view
[0] == 0xff && view
[1] == 0x10);
2320 // Do a relocation in which we convert a TLS Local-Dynamic to a
2324 Target_i386::Relocate::tls_ld_to_le(const Relocate_info
<32, false>* relinfo
,
2327 const elfcpp::Rel
<32, false>& rel
,
2329 elfcpp::Elf_types
<32>::Elf_Addr
,
2330 unsigned char* view
,
2331 section_size_type view_size
)
2333 // leal foo(%reg), %eax; call ___tls_get_addr
2334 // ==> movl %gs:0,%eax; nop; leal 0(%esi,1),%esi
2336 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2337 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 9);
2339 // FIXME: Does this test really always pass?
2340 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2341 view
[-2] == 0x8d && view
[-1] == 0x83);
2343 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[4] == 0xe8);
2345 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x90\x8d\x74\x26\0", 11);
2347 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2349 this->skip_call_tls_get_addr_
= true;
2352 // Do a relocation in which we convert a TLS Initial-Exec to a
2356 Target_i386::Relocate::tls_ie_to_le(const Relocate_info
<32, false>* relinfo
,
2358 Output_segment
* tls_segment
,
2359 const elfcpp::Rel
<32, false>& rel
,
2360 unsigned int r_type
,
2361 elfcpp::Elf_types
<32>::Elf_Addr value
,
2362 unsigned char* view
,
2363 section_size_type view_size
)
2365 // We have to actually change the instructions, which means that we
2366 // need to examine the opcodes to figure out which instruction we
2368 if (r_type
== elfcpp::R_386_TLS_IE
)
2370 // movl %gs:XX,%eax ==> movl $YY,%eax
2371 // movl %gs:XX,%reg ==> movl $YY,%reg
2372 // addl %gs:XX,%reg ==> addl $YY,%reg
2373 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -1);
2374 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2376 unsigned char op1
= view
[-1];
2379 // movl XX,%eax ==> movl $YY,%eax
2384 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2386 unsigned char op2
= view
[-2];
2389 // movl XX,%reg ==> movl $YY,%reg
2390 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2391 (op1
& 0xc7) == 0x05);
2393 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2395 else if (op2
== 0x03)
2397 // addl XX,%reg ==> addl $YY,%reg
2398 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2399 (op1
& 0xc7) == 0x05);
2401 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2404 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), 0);
2409 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
2410 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
2411 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
2412 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2413 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2415 unsigned char op1
= view
[-1];
2416 unsigned char op2
= view
[-2];
2417 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2418 (op1
& 0xc0) == 0x80 && (op1
& 7) != 4);
2421 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
2423 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2425 else if (op2
== 0x2b)
2427 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
2429 view
[-1] = 0xe8 | ((op1
>> 3) & 7);
2431 else if (op2
== 0x03)
2433 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
2435 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2438 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), 0);
2441 value
= tls_segment
->memsz() - value
;
2442 if (r_type
== elfcpp::R_386_TLS_IE
|| r_type
== elfcpp::R_386_TLS_GOTIE
)
2445 Relocate_functions
<32, false>::rel32(view
, value
);
2448 // Relocate section data.
2451 Target_i386::relocate_section(const Relocate_info
<32, false>* relinfo
,
2452 unsigned int sh_type
,
2453 const unsigned char* prelocs
,
2455 Output_section
* output_section
,
2456 bool needs_special_offset_handling
,
2457 unsigned char* view
,
2458 elfcpp::Elf_types
<32>::Elf_Addr address
,
2459 section_size_type view_size
,
2460 const Reloc_symbol_changes
* reloc_symbol_changes
)
2462 gold_assert(sh_type
== elfcpp::SHT_REL
);
2464 gold::relocate_section
<32, false, Target_i386
, elfcpp::SHT_REL
,
2465 Target_i386::Relocate
>(
2471 needs_special_offset_handling
,
2475 reloc_symbol_changes
);
2478 // Return the size of a relocation while scanning during a relocatable
2482 Target_i386::Relocatable_size_for_reloc::get_size_for_reloc(
2483 unsigned int r_type
,
2488 case elfcpp::R_386_NONE
:
2489 case elfcpp::R_386_GNU_VTINHERIT
:
2490 case elfcpp::R_386_GNU_VTENTRY
:
2491 case elfcpp::R_386_TLS_GD
: // Global-dynamic
2492 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
2493 case elfcpp::R_386_TLS_DESC_CALL
:
2494 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
2495 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
2496 case elfcpp::R_386_TLS_IE
: // Initial-exec
2497 case elfcpp::R_386_TLS_IE_32
:
2498 case elfcpp::R_386_TLS_GOTIE
:
2499 case elfcpp::R_386_TLS_LE
: // Local-exec
2500 case elfcpp::R_386_TLS_LE_32
:
2503 case elfcpp::R_386_32
:
2504 case elfcpp::R_386_PC32
:
2505 case elfcpp::R_386_GOT32
:
2506 case elfcpp::R_386_PLT32
:
2507 case elfcpp::R_386_GOTOFF
:
2508 case elfcpp::R_386_GOTPC
:
2511 case elfcpp::R_386_16
:
2512 case elfcpp::R_386_PC16
:
2515 case elfcpp::R_386_8
:
2516 case elfcpp::R_386_PC8
:
2519 // These are relocations which should only be seen by the
2520 // dynamic linker, and should never be seen here.
2521 case elfcpp::R_386_COPY
:
2522 case elfcpp::R_386_GLOB_DAT
:
2523 case elfcpp::R_386_JUMP_SLOT
:
2524 case elfcpp::R_386_RELATIVE
:
2525 case elfcpp::R_386_TLS_TPOFF
:
2526 case elfcpp::R_386_TLS_DTPMOD32
:
2527 case elfcpp::R_386_TLS_DTPOFF32
:
2528 case elfcpp::R_386_TLS_TPOFF32
:
2529 case elfcpp::R_386_TLS_DESC
:
2530 object
->error(_("unexpected reloc %u in object file"), r_type
);
2533 case elfcpp::R_386_32PLT
:
2534 case elfcpp::R_386_TLS_GD_32
:
2535 case elfcpp::R_386_TLS_GD_PUSH
:
2536 case elfcpp::R_386_TLS_GD_CALL
:
2537 case elfcpp::R_386_TLS_GD_POP
:
2538 case elfcpp::R_386_TLS_LDM_32
:
2539 case elfcpp::R_386_TLS_LDM_PUSH
:
2540 case elfcpp::R_386_TLS_LDM_CALL
:
2541 case elfcpp::R_386_TLS_LDM_POP
:
2542 case elfcpp::R_386_USED_BY_INTEL_200
:
2544 object
->error(_("unsupported reloc %u in object file"), r_type
);
2549 // Scan the relocs during a relocatable link.
2552 Target_i386::scan_relocatable_relocs(Symbol_table
* symtab
,
2554 Sized_relobj
<32, false>* object
,
2555 unsigned int data_shndx
,
2556 unsigned int sh_type
,
2557 const unsigned char* prelocs
,
2559 Output_section
* output_section
,
2560 bool needs_special_offset_handling
,
2561 size_t local_symbol_count
,
2562 const unsigned char* plocal_symbols
,
2563 Relocatable_relocs
* rr
)
2565 gold_assert(sh_type
== elfcpp::SHT_REL
);
2567 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_REL
,
2568 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
2570 gold::scan_relocatable_relocs
<32, false, elfcpp::SHT_REL
,
2571 Scan_relocatable_relocs
>(
2579 needs_special_offset_handling
,
2585 // Relocate a section during a relocatable link.
2588 Target_i386::relocate_for_relocatable(
2589 const Relocate_info
<32, false>* relinfo
,
2590 unsigned int sh_type
,
2591 const unsigned char* prelocs
,
2593 Output_section
* output_section
,
2594 off_t offset_in_output_section
,
2595 const Relocatable_relocs
* rr
,
2596 unsigned char* view
,
2597 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
2598 section_size_type view_size
,
2599 unsigned char* reloc_view
,
2600 section_size_type reloc_view_size
)
2602 gold_assert(sh_type
== elfcpp::SHT_REL
);
2604 gold::relocate_for_relocatable
<32, false, elfcpp::SHT_REL
>(
2609 offset_in_output_section
,
2618 // Return the value to use for a dynamic which requires special
2619 // treatment. This is how we support equality comparisons of function
2620 // pointers across shared library boundaries, as described in the
2621 // processor specific ABI supplement.
2624 Target_i386::do_dynsym_value(const Symbol
* gsym
) const
2626 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
2627 return this->plt_section()->address() + gsym
->plt_offset();
2630 // Return a string used to fill a code section with nops to take up
2631 // the specified length.
2634 Target_i386::do_code_fill(section_size_type length
) const
2638 // Build a jmp instruction to skip over the bytes.
2639 unsigned char jmp
[5];
2641 elfcpp::Swap_unaligned
<32, false>::writeval(jmp
+ 1, length
- 5);
2642 return (std::string(reinterpret_cast<char*>(&jmp
[0]), 5)
2643 + std::string(length
- 5, '\0'));
2646 // Nop sequences of various lengths.
2647 const char nop1
[1] = { 0x90 }; // nop
2648 const char nop2
[2] = { 0x66, 0x90 }; // xchg %ax %ax
2649 const char nop3
[3] = { 0x8d, 0x76, 0x00 }; // leal 0(%esi),%esi
2650 const char nop4
[4] = { 0x8d, 0x74, 0x26, 0x00}; // leal 0(%esi,1),%esi
2651 const char nop5
[5] = { 0x90, 0x8d, 0x74, 0x26, // nop
2652 0x00 }; // leal 0(%esi,1),%esi
2653 const char nop6
[6] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2655 const char nop7
[7] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2657 const char nop8
[8] = { 0x90, 0x8d, 0xb4, 0x26, // nop
2658 0x00, 0x00, 0x00, 0x00 }; // leal 0L(%esi,1),%esi
2659 const char nop9
[9] = { 0x89, 0xf6, 0x8d, 0xbc, // movl %esi,%esi
2660 0x27, 0x00, 0x00, 0x00, // leal 0L(%edi,1),%edi
2662 const char nop10
[10] = { 0x8d, 0x76, 0x00, 0x8d, // leal 0(%esi),%esi
2663 0xbc, 0x27, 0x00, 0x00, // leal 0L(%edi,1),%edi
2665 const char nop11
[11] = { 0x8d, 0x74, 0x26, 0x00, // leal 0(%esi,1),%esi
2666 0x8d, 0xbc, 0x27, 0x00, // leal 0L(%edi,1),%edi
2668 const char nop12
[12] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2669 0x00, 0x00, 0x8d, 0xbf, // leal 0L(%edi),%edi
2670 0x00, 0x00, 0x00, 0x00 };
2671 const char nop13
[13] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2672 0x00, 0x00, 0x8d, 0xbc, // leal 0L(%edi,1),%edi
2673 0x27, 0x00, 0x00, 0x00,
2675 const char nop14
[14] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2676 0x00, 0x00, 0x00, 0x8d, // leal 0L(%edi,1),%edi
2677 0xbc, 0x27, 0x00, 0x00,
2679 const char nop15
[15] = { 0xeb, 0x0d, 0x90, 0x90, // jmp .+15
2680 0x90, 0x90, 0x90, 0x90, // nop,nop,nop,...
2681 0x90, 0x90, 0x90, 0x90,
2684 const char* nops
[16] = {
2686 nop1
, nop2
, nop3
, nop4
, nop5
, nop6
, nop7
,
2687 nop8
, nop9
, nop10
, nop11
, nop12
, nop13
, nop14
, nop15
2690 return std::string(nops
[length
], length
);
2693 // FNOFFSET in section SHNDX in OBJECT is the start of a function
2694 // compiled with -fstack-split. The function calls non-stack-split
2695 // code. We have to change the function so that it always ensures
2696 // that it has enough stack space to run some random function.
2699 Target_i386::do_calls_non_split(Relobj
* object
, unsigned int shndx
,
2700 section_offset_type fnoffset
,
2701 section_size_type fnsize
,
2702 unsigned char* view
,
2703 section_size_type view_size
,
2705 std::string
* to
) const
2707 // The function starts with a comparison of the stack pointer and a
2708 // field in the TCB. This is followed by a jump.
2711 if (this->match_view(view
, view_size
, fnoffset
, "\x65\x3b\x25", 3)
2714 // We will call __morestack if the carry flag is set after this
2715 // comparison. We turn the comparison into an stc instruction
2717 view
[fnoffset
] = '\xf9';
2718 this->set_view_to_nop(view
, view_size
, fnoffset
+ 1, 6);
2720 // lea NN(%esp),%ecx
2721 // lea NN(%esp),%edx
2722 else if ((this->match_view(view
, view_size
, fnoffset
, "\x8d\x8c\x24", 3)
2723 || this->match_view(view
, view_size
, fnoffset
, "\x8d\x94\x24", 3))
2726 // This is loading an offset from the stack pointer for a
2727 // comparison. The offset is negative, so we decrease the
2728 // offset by the amount of space we need for the stack. This
2729 // means we will avoid calling __morestack if there happens to
2730 // be plenty of space on the stack already.
2731 unsigned char* pval
= view
+ fnoffset
+ 3;
2732 uint32_t val
= elfcpp::Swap_unaligned
<32, false>::readval(pval
);
2733 val
-= parameters
->options().split_stack_adjust_size();
2734 elfcpp::Swap_unaligned
<32, false>::writeval(pval
, val
);
2738 if (!object
->has_no_split_stack())
2739 object
->error(_("failed to match split-stack sequence at "
2740 "section %u offset %0zx"),
2741 shndx
, static_cast<size_t>(fnoffset
));
2745 // We have to change the function so that it calls
2746 // __morestack_non_split instead of __morestack. The former will
2747 // allocate additional stack space.
2748 *from
= "__morestack";
2749 *to
= "__morestack_non_split";
2752 // The selector for i386 object files.
2754 class Target_selector_i386
: public Target_selector_freebsd
2757 Target_selector_i386()
2758 : Target_selector_freebsd(elfcpp::EM_386
, 32, false,
2759 "elf32-i386", "elf32-i386-freebsd")
2763 do_instantiate_target()
2764 { return new Target_i386(); }
2767 Target_selector_i386 target_selector_i386
;
2769 } // End anonymous namespace.