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
), rel_dyn_(NULL
),
63 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 dynamic reloc section.
416 Reloc_section
* rel_dyn_
;
417 // Relocs saved to avoid a COPY reloc.
418 Copy_relocs
<elfcpp::SHT_REL
, 32, false> copy_relocs_
;
419 // Space for variables copied with a COPY reloc.
420 Output_data_space
* dynbss_
;
421 // Offset of the GOT entry for the TLS module index.
422 unsigned int got_mod_index_offset_
;
423 // True if the _TLS_MODULE_BASE_ symbol has been defined.
424 bool tls_base_symbol_defined_
;
427 const Target::Target_info
Target_i386::i386_info
=
430 false, // is_big_endian
431 elfcpp::EM_386
, // machine_code
432 false, // has_make_symbol
433 false, // has_resolve
434 true, // has_code_fill
435 true, // is_default_stack_executable
437 "/usr/lib/libc.so.1", // dynamic_linker
438 0x08048000, // default_text_segment_address
439 0x1000, // abi_pagesize (overridable by -z max-page-size)
440 0x1000, // common_pagesize (overridable by -z common-page-size)
441 elfcpp::SHN_UNDEF
, // small_common_shndx
442 elfcpp::SHN_UNDEF
, // large_common_shndx
443 0, // small_common_section_flags
444 0 // large_common_section_flags
447 // Get the GOT section, creating it if necessary.
449 Output_data_got
<32, false>*
450 Target_i386::got_section(Symbol_table
* symtab
, Layout
* layout
)
452 if (this->got_
== NULL
)
454 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
456 this->got_
= new Output_data_got
<32, false>();
459 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
461 | elfcpp::SHF_WRITE
),
465 // The old GNU linker creates a .got.plt section. We just
466 // create another set of data in the .got section. Note that we
467 // always create a PLT if we create a GOT, although the PLT
469 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
470 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
472 | elfcpp::SHF_WRITE
),
473 this->got_plt_
, false);
476 // The first three entries are reserved.
477 this->got_plt_
->set_current_data_size(3 * 4);
479 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
480 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
482 0, 0, elfcpp::STT_OBJECT
,
484 elfcpp::STV_HIDDEN
, 0,
491 // Get the dynamic reloc section, creating it if necessary.
493 Target_i386::Reloc_section
*
494 Target_i386::rel_dyn_section(Layout
* layout
)
496 if (this->rel_dyn_
== NULL
)
498 gold_assert(layout
!= NULL
);
499 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
500 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
501 elfcpp::SHF_ALLOC
, this->rel_dyn_
, true);
503 return this->rel_dyn_
;
506 // A class to handle the PLT data.
508 class Output_data_plt_i386
: public Output_section_data
511 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false> Reloc_section
;
513 Output_data_plt_i386(Layout
*, Output_data_space
*);
515 // Add an entry to the PLT.
517 add_entry(Symbol
* gsym
);
519 // Return the .rel.plt section data.
522 { return this->rel_
; }
526 do_adjust_output_section(Output_section
* os
);
528 // Write to a map file.
530 do_print_to_mapfile(Mapfile
* mapfile
) const
531 { mapfile
->print_output_data(this, _("** PLT")); }
534 // The size of an entry in the PLT.
535 static const int plt_entry_size
= 16;
537 // The first entry in the PLT for an executable.
538 static unsigned char exec_first_plt_entry
[plt_entry_size
];
540 // The first entry in the PLT for a shared object.
541 static unsigned char dyn_first_plt_entry
[plt_entry_size
];
543 // Other entries in the PLT for an executable.
544 static unsigned char exec_plt_entry
[plt_entry_size
];
546 // Other entries in the PLT for a shared object.
547 static unsigned char dyn_plt_entry
[plt_entry_size
];
549 // Set the final size.
551 set_final_data_size()
552 { this->set_data_size((this->count_
+ 1) * plt_entry_size
); }
554 // Write out the PLT data.
556 do_write(Output_file
*);
558 // The reloc section.
560 // The .got.plt section.
561 Output_data_space
* got_plt_
;
562 // The number of PLT entries.
566 // Create the PLT section. The ordinary .got section is an argument,
567 // since we need to refer to the start. We also create our own .got
568 // section just for PLT entries.
570 Output_data_plt_i386::Output_data_plt_i386(Layout
* layout
,
571 Output_data_space
* got_plt
)
572 : Output_section_data(4), got_plt_(got_plt
), count_(0)
574 this->rel_
= new Reloc_section(false);
575 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
576 elfcpp::SHF_ALLOC
, this->rel_
, true);
580 Output_data_plt_i386::do_adjust_output_section(Output_section
* os
)
582 // UnixWare sets the entsize of .plt to 4, and so does the old GNU
583 // linker, and so do we.
587 // Add an entry to the PLT.
590 Output_data_plt_i386::add_entry(Symbol
* gsym
)
592 gold_assert(!gsym
->has_plt_offset());
594 // Note that when setting the PLT offset we skip the initial
595 // reserved PLT entry.
596 gsym
->set_plt_offset((this->count_
+ 1) * plt_entry_size
);
600 section_offset_type got_offset
= this->got_plt_
->current_data_size();
602 // Every PLT entry needs a GOT entry which points back to the PLT
603 // entry (this will be changed by the dynamic linker, normally
604 // lazily when the function is called).
605 this->got_plt_
->set_current_data_size(got_offset
+ 4);
607 // Every PLT entry needs a reloc.
608 gsym
->set_needs_dynsym_entry();
609 this->rel_
->add_global(gsym
, elfcpp::R_386_JUMP_SLOT
, this->got_plt_
,
612 // Note that we don't need to save the symbol. The contents of the
613 // PLT are independent of which symbols are used. The symbols only
614 // appear in the relocations.
617 // The first entry in the PLT for an executable.
619 unsigned char Output_data_plt_i386::exec_first_plt_entry
[plt_entry_size
] =
621 0xff, 0x35, // pushl contents of memory address
622 0, 0, 0, 0, // replaced with address of .got + 4
623 0xff, 0x25, // jmp indirect
624 0, 0, 0, 0, // replaced with address of .got + 8
628 // The first entry in the PLT for a shared object.
630 unsigned char Output_data_plt_i386::dyn_first_plt_entry
[plt_entry_size
] =
632 0xff, 0xb3, 4, 0, 0, 0, // pushl 4(%ebx)
633 0xff, 0xa3, 8, 0, 0, 0, // jmp *8(%ebx)
637 // Subsequent entries in the PLT for an executable.
639 unsigned char Output_data_plt_i386::exec_plt_entry
[plt_entry_size
] =
641 0xff, 0x25, // jmp indirect
642 0, 0, 0, 0, // replaced with address of symbol in .got
643 0x68, // pushl immediate
644 0, 0, 0, 0, // replaced with offset into relocation table
645 0xe9, // jmp relative
646 0, 0, 0, 0 // replaced with offset to start of .plt
649 // Subsequent entries in the PLT for a shared object.
651 unsigned char Output_data_plt_i386::dyn_plt_entry
[plt_entry_size
] =
653 0xff, 0xa3, // jmp *offset(%ebx)
654 0, 0, 0, 0, // replaced with offset of symbol in .got
655 0x68, // pushl immediate
656 0, 0, 0, 0, // replaced with offset into relocation table
657 0xe9, // jmp relative
658 0, 0, 0, 0 // replaced with offset to start of .plt
661 // Write out the PLT. This uses the hand-coded instructions above,
662 // and adjusts them as needed. This is all specified by the i386 ELF
663 // Processor Supplement.
666 Output_data_plt_i386::do_write(Output_file
* of
)
668 const off_t offset
= this->offset();
669 const section_size_type oview_size
=
670 convert_to_section_size_type(this->data_size());
671 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
673 const off_t got_file_offset
= this->got_plt_
->offset();
674 const section_size_type got_size
=
675 convert_to_section_size_type(this->got_plt_
->data_size());
676 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
679 unsigned char* pov
= oview
;
681 elfcpp::Elf_types
<32>::Elf_Addr plt_address
= this->address();
682 elfcpp::Elf_types
<32>::Elf_Addr got_address
= this->got_plt_
->address();
684 if (parameters
->options().output_is_position_independent())
685 memcpy(pov
, dyn_first_plt_entry
, plt_entry_size
);
688 memcpy(pov
, exec_first_plt_entry
, plt_entry_size
);
689 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_address
+ 4);
690 elfcpp::Swap
<32, false>::writeval(pov
+ 8, got_address
+ 8);
692 pov
+= plt_entry_size
;
694 unsigned char* got_pov
= got_view
;
696 memset(got_pov
, 0, 12);
699 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
701 unsigned int plt_offset
= plt_entry_size
;
702 unsigned int plt_rel_offset
= 0;
703 unsigned int got_offset
= 12;
704 const unsigned int count
= this->count_
;
705 for (unsigned int i
= 0;
708 pov
+= plt_entry_size
,
710 plt_offset
+= plt_entry_size
,
711 plt_rel_offset
+= rel_size
,
714 // Set and adjust the PLT entry itself.
716 if (parameters
->options().output_is_position_independent())
718 memcpy(pov
, dyn_plt_entry
, plt_entry_size
);
719 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_offset
);
723 memcpy(pov
, exec_plt_entry
, plt_entry_size
);
724 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
729 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 7, plt_rel_offset
);
730 elfcpp::Swap
<32, false>::writeval(pov
+ 12,
731 - (plt_offset
+ plt_entry_size
));
733 // Set the entry in the GOT.
734 elfcpp::Swap
<32, false>::writeval(got_pov
, plt_address
+ plt_offset
+ 6);
737 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
738 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
740 of
->write_output_view(offset
, oview_size
, oview
);
741 of
->write_output_view(got_file_offset
, got_size
, got_view
);
744 // Create a PLT entry for a global symbol.
747 Target_i386::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
)
749 if (gsym
->has_plt_offset())
752 if (this->plt_
== NULL
)
754 // Create the GOT sections first.
755 this->got_section(symtab
, layout
);
757 this->plt_
= new Output_data_plt_i386(layout
, this->got_plt_
);
758 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
760 | elfcpp::SHF_EXECINSTR
),
764 this->plt_
->add_entry(gsym
);
767 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
770 Target_i386::define_tls_base_symbol(Symbol_table
* symtab
, Layout
* layout
)
772 if (this->tls_base_symbol_defined_
)
775 Output_segment
* tls_segment
= layout
->tls_segment();
776 if (tls_segment
!= NULL
)
778 bool is_exec
= parameters
->options().output_is_executable();
779 symtab
->define_in_output_segment("_TLS_MODULE_BASE_", NULL
,
783 elfcpp::STV_HIDDEN
, 0,
785 ? Symbol::SEGMENT_END
786 : Symbol::SEGMENT_START
),
789 this->tls_base_symbol_defined_
= true;
792 // Create a GOT entry for the TLS module index.
795 Target_i386::got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
796 Sized_relobj
<32, false>* object
)
798 if (this->got_mod_index_offset_
== -1U)
800 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
801 Reloc_section
* rel_dyn
= this->rel_dyn_section(layout
);
802 Output_data_got
<32, false>* got
= this->got_section(symtab
, layout
);
803 unsigned int got_offset
= got
->add_constant(0);
804 rel_dyn
->add_local(object
, 0, elfcpp::R_386_TLS_DTPMOD32
, got
,
806 got
->add_constant(0);
807 this->got_mod_index_offset_
= got_offset
;
809 return this->got_mod_index_offset_
;
812 // Optimize the TLS relocation type based on what we know about the
813 // symbol. IS_FINAL is true if the final address of this symbol is
814 // known at link time.
816 tls::Tls_optimization
817 Target_i386::optimize_tls_reloc(bool is_final
, int r_type
)
819 // If we are generating a shared library, then we can't do anything
821 if (parameters
->options().shared())
822 return tls::TLSOPT_NONE
;
826 case elfcpp::R_386_TLS_GD
:
827 case elfcpp::R_386_TLS_GOTDESC
:
828 case elfcpp::R_386_TLS_DESC_CALL
:
829 // These are General-Dynamic which permits fully general TLS
830 // access. Since we know that we are generating an executable,
831 // we can convert this to Initial-Exec. If we also know that
832 // this is a local symbol, we can further switch to Local-Exec.
834 return tls::TLSOPT_TO_LE
;
835 return tls::TLSOPT_TO_IE
;
837 case elfcpp::R_386_TLS_LDM
:
838 // This is Local-Dynamic, which refers to a local symbol in the
839 // dynamic TLS block. Since we know that we generating an
840 // executable, we can switch to Local-Exec.
841 return tls::TLSOPT_TO_LE
;
843 case elfcpp::R_386_TLS_LDO_32
:
844 // Another type of Local-Dynamic relocation.
845 return tls::TLSOPT_TO_LE
;
847 case elfcpp::R_386_TLS_IE
:
848 case elfcpp::R_386_TLS_GOTIE
:
849 case elfcpp::R_386_TLS_IE_32
:
850 // These are Initial-Exec relocs which get the thread offset
851 // from the GOT. If we know that we are linking against the
852 // local symbol, we can switch to Local-Exec, which links the
853 // thread offset into the instruction.
855 return tls::TLSOPT_TO_LE
;
856 return tls::TLSOPT_NONE
;
858 case elfcpp::R_386_TLS_LE
:
859 case elfcpp::R_386_TLS_LE_32
:
860 // When we already have Local-Exec, there is nothing further we
862 return tls::TLSOPT_NONE
;
869 // Report an unsupported relocation against a local symbol.
872 Target_i386::Scan::unsupported_reloc_local(Sized_relobj
<32, false>* object
,
875 gold_error(_("%s: unsupported reloc %u against local symbol"),
876 object
->name().c_str(), r_type
);
879 // Scan a relocation for a local symbol.
882 Target_i386::Scan::local(Symbol_table
* symtab
,
885 Sized_relobj
<32, false>* object
,
886 unsigned int data_shndx
,
887 Output_section
* output_section
,
888 const elfcpp::Rel
<32, false>& reloc
,
890 const elfcpp::Sym
<32, false>& lsym
)
894 case elfcpp::R_386_NONE
:
895 case elfcpp::R_386_GNU_VTINHERIT
:
896 case elfcpp::R_386_GNU_VTENTRY
:
899 case elfcpp::R_386_32
:
900 // If building a shared library (or a position-independent
901 // executable), we need to create a dynamic relocation for
902 // this location. The relocation applied at link time will
903 // apply the link-time value, so we flag the location with
904 // an R_386_RELATIVE relocation so the dynamic loader can
905 // relocate it easily.
906 if (parameters
->options().output_is_position_independent())
908 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
909 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
910 rel_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_386_RELATIVE
,
911 output_section
, data_shndx
,
912 reloc
.get_r_offset());
916 case elfcpp::R_386_16
:
917 case elfcpp::R_386_8
:
918 // If building a shared library (or a position-independent
919 // executable), we need to create a dynamic relocation for
920 // this location. Because the addend needs to remain in the
921 // data section, we need to be careful not to apply this
922 // relocation statically.
923 if (parameters
->options().output_is_position_independent())
925 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
926 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
927 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
928 rel_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
929 data_shndx
, reloc
.get_r_offset());
932 gold_assert(lsym
.get_st_value() == 0);
933 unsigned int shndx
= lsym
.get_st_shndx();
935 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
938 object
->error(_("section symbol %u has bad shndx %u"),
941 rel_dyn
->add_local_section(object
, shndx
,
942 r_type
, output_section
,
943 data_shndx
, reloc
.get_r_offset());
948 case elfcpp::R_386_PC32
:
949 case elfcpp::R_386_PC16
:
950 case elfcpp::R_386_PC8
:
953 case elfcpp::R_386_PLT32
:
954 // Since we know this is a local symbol, we can handle this as a
958 case elfcpp::R_386_GOTOFF
:
959 case elfcpp::R_386_GOTPC
:
960 // We need a GOT section.
961 target
->got_section(symtab
, layout
);
964 case elfcpp::R_386_GOT32
:
966 // The symbol requires a GOT entry.
967 Output_data_got
<32, false>* got
= target
->got_section(symtab
, layout
);
968 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
969 if (got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
))
971 // If we are generating a shared object, we need to add a
972 // dynamic RELATIVE relocation for this symbol's GOT entry.
973 if (parameters
->options().output_is_position_independent())
975 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
976 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
977 rel_dyn
->add_local_relative(
978 object
, r_sym
, elfcpp::R_386_RELATIVE
, got
,
979 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
));
985 // These are relocations which should only be seen by the
986 // dynamic linker, and should never be seen here.
987 case elfcpp::R_386_COPY
:
988 case elfcpp::R_386_GLOB_DAT
:
989 case elfcpp::R_386_JUMP_SLOT
:
990 case elfcpp::R_386_RELATIVE
:
991 case elfcpp::R_386_TLS_TPOFF
:
992 case elfcpp::R_386_TLS_DTPMOD32
:
993 case elfcpp::R_386_TLS_DTPOFF32
:
994 case elfcpp::R_386_TLS_TPOFF32
:
995 case elfcpp::R_386_TLS_DESC
:
996 gold_error(_("%s: unexpected reloc %u in object file"),
997 object
->name().c_str(), r_type
);
1000 // These are initial TLS relocs, which are expected when
1002 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1003 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1004 case elfcpp::R_386_TLS_DESC_CALL
:
1005 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1006 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1007 case elfcpp::R_386_TLS_IE
: // Initial-exec
1008 case elfcpp::R_386_TLS_IE_32
:
1009 case elfcpp::R_386_TLS_GOTIE
:
1010 case elfcpp::R_386_TLS_LE
: // Local-exec
1011 case elfcpp::R_386_TLS_LE_32
:
1013 bool output_is_shared
= parameters
->options().shared();
1014 const tls::Tls_optimization optimized_type
1015 = Target_i386::optimize_tls_reloc(!output_is_shared
, r_type
);
1018 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1019 if (optimized_type
== tls::TLSOPT_NONE
)
1021 // Create a pair of GOT entries for the module index and
1022 // dtv-relative offset.
1023 Output_data_got
<32, false>* got
1024 = target
->got_section(symtab
, layout
);
1025 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1026 unsigned int shndx
= lsym
.get_st_shndx();
1028 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1030 object
->error(_("local symbol %u has bad shndx %u"),
1033 got
->add_local_pair_with_rel(object
, r_sym
, shndx
,
1035 target
->rel_dyn_section(layout
),
1036 elfcpp::R_386_TLS_DTPMOD32
, 0);
1038 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1039 unsupported_reloc_local(object
, r_type
);
1042 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva)
1043 target
->define_tls_base_symbol(symtab
, layout
);
1044 if (optimized_type
== tls::TLSOPT_NONE
)
1046 // Create a double GOT entry with an R_386_TLS_DESC reloc.
1047 Output_data_got
<32, false>* got
1048 = target
->got_section(symtab
, layout
);
1049 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1050 unsigned int shndx
= lsym
.get_st_shndx();
1052 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1054 object
->error(_("local symbol %u has bad shndx %u"),
1057 got
->add_local_pair_with_rel(object
, r_sym
, shndx
,
1059 target
->rel_dyn_section(layout
),
1060 elfcpp::R_386_TLS_DESC
, 0);
1062 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1063 unsupported_reloc_local(object
, r_type
);
1066 case elfcpp::R_386_TLS_DESC_CALL
:
1069 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1070 if (optimized_type
== tls::TLSOPT_NONE
)
1072 // Create a GOT entry for the module index.
1073 target
->got_mod_index_entry(symtab
, layout
, object
);
1075 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1076 unsupported_reloc_local(object
, r_type
);
1079 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1082 case elfcpp::R_386_TLS_IE
: // Initial-exec
1083 case elfcpp::R_386_TLS_IE_32
:
1084 case elfcpp::R_386_TLS_GOTIE
:
1085 layout
->set_has_static_tls();
1086 if (optimized_type
== tls::TLSOPT_NONE
)
1088 // For the R_386_TLS_IE relocation, we need to create a
1089 // dynamic relocation when building a shared library.
1090 if (r_type
== elfcpp::R_386_TLS_IE
1091 && parameters
->options().shared())
1093 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1095 = elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1096 rel_dyn
->add_local_relative(object
, r_sym
,
1097 elfcpp::R_386_RELATIVE
,
1098 output_section
, data_shndx
,
1099 reloc
.get_r_offset());
1101 // Create a GOT entry for the tp-relative offset.
1102 Output_data_got
<32, false>* got
1103 = target
->got_section(symtab
, layout
);
1104 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1105 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1106 ? elfcpp::R_386_TLS_TPOFF32
1107 : elfcpp::R_386_TLS_TPOFF
);
1108 unsigned int got_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1109 ? GOT_TYPE_TLS_OFFSET
1110 : GOT_TYPE_TLS_NOFFSET
);
1111 got
->add_local_with_rel(object
, r_sym
, got_type
,
1112 target
->rel_dyn_section(layout
),
1115 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1116 unsupported_reloc_local(object
, r_type
);
1119 case elfcpp::R_386_TLS_LE
: // Local-exec
1120 case elfcpp::R_386_TLS_LE_32
:
1121 layout
->set_has_static_tls();
1122 if (output_is_shared
)
1124 // We need to create a dynamic relocation.
1125 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1126 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1127 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_LE_32
1128 ? elfcpp::R_386_TLS_TPOFF32
1129 : elfcpp::R_386_TLS_TPOFF
);
1130 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1131 rel_dyn
->add_local(object
, r_sym
, dyn_r_type
, output_section
,
1132 data_shndx
, reloc
.get_r_offset());
1142 case elfcpp::R_386_32PLT
:
1143 case elfcpp::R_386_TLS_GD_32
:
1144 case elfcpp::R_386_TLS_GD_PUSH
:
1145 case elfcpp::R_386_TLS_GD_CALL
:
1146 case elfcpp::R_386_TLS_GD_POP
:
1147 case elfcpp::R_386_TLS_LDM_32
:
1148 case elfcpp::R_386_TLS_LDM_PUSH
:
1149 case elfcpp::R_386_TLS_LDM_CALL
:
1150 case elfcpp::R_386_TLS_LDM_POP
:
1151 case elfcpp::R_386_USED_BY_INTEL_200
:
1153 unsupported_reloc_local(object
, r_type
);
1158 // Report an unsupported relocation against a global symbol.
1161 Target_i386::Scan::unsupported_reloc_global(Sized_relobj
<32, false>* object
,
1162 unsigned int r_type
,
1165 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1166 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1169 // Scan a relocation for a global symbol.
1172 Target_i386::Scan::global(Symbol_table
* symtab
,
1174 Target_i386
* target
,
1175 Sized_relobj
<32, false>* object
,
1176 unsigned int data_shndx
,
1177 Output_section
* output_section
,
1178 const elfcpp::Rel
<32, false>& reloc
,
1179 unsigned int r_type
,
1184 case elfcpp::R_386_NONE
:
1185 case elfcpp::R_386_GNU_VTINHERIT
:
1186 case elfcpp::R_386_GNU_VTENTRY
:
1189 case elfcpp::R_386_32
:
1190 case elfcpp::R_386_16
:
1191 case elfcpp::R_386_8
:
1193 // Make a PLT entry if necessary.
1194 if (gsym
->needs_plt_entry())
1196 target
->make_plt_entry(symtab
, layout
, gsym
);
1197 // Since this is not a PC-relative relocation, we may be
1198 // taking the address of a function. In that case we need to
1199 // set the entry in the dynamic symbol table to the address of
1201 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
1202 gsym
->set_needs_dynsym_value();
1204 // Make a dynamic relocation if necessary.
1205 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
1207 if (gsym
->may_need_copy_reloc())
1209 target
->copy_reloc(symtab
, layout
, object
,
1210 data_shndx
, output_section
, gsym
, reloc
);
1212 else if (r_type
== elfcpp::R_386_32
1213 && gsym
->can_use_relative_reloc(false))
1215 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1216 rel_dyn
->add_global_relative(gsym
, elfcpp::R_386_RELATIVE
,
1217 output_section
, object
,
1218 data_shndx
, reloc
.get_r_offset());
1222 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1223 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1224 data_shndx
, reloc
.get_r_offset());
1230 case elfcpp::R_386_PC32
:
1231 case elfcpp::R_386_PC16
:
1232 case elfcpp::R_386_PC8
:
1234 // Make a PLT entry if necessary.
1235 if (gsym
->needs_plt_entry())
1237 // These relocations are used for function calls only in
1238 // non-PIC code. For a 32-bit relocation in a shared library,
1239 // we'll need a text relocation anyway, so we can skip the
1240 // PLT entry and let the dynamic linker bind the call directly
1241 // to the target. For smaller relocations, we should use a
1242 // PLT entry to ensure that the call can reach.
1243 if (!parameters
->options().shared()
1244 || r_type
!= elfcpp::R_386_PC32
)
1245 target
->make_plt_entry(symtab
, layout
, gsym
);
1247 // Make a dynamic relocation if necessary.
1248 int flags
= Symbol::NON_PIC_REF
;
1249 if (gsym
->type() == elfcpp::STT_FUNC
)
1250 flags
|= Symbol::FUNCTION_CALL
;
1251 if (gsym
->needs_dynamic_reloc(flags
))
1253 if (gsym
->may_need_copy_reloc())
1255 target
->copy_reloc(symtab
, layout
, object
,
1256 data_shndx
, output_section
, gsym
, reloc
);
1260 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1261 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1262 data_shndx
, reloc
.get_r_offset());
1268 case elfcpp::R_386_GOT32
:
1270 // The symbol requires a GOT entry.
1271 Output_data_got
<32, false>* got
= target
->got_section(symtab
, layout
);
1272 if (gsym
->final_value_is_known())
1273 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
1276 // If this symbol is not fully resolved, we need to add a
1277 // GOT entry with a dynamic relocation.
1278 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1279 if (gsym
->is_from_dynobj()
1280 || gsym
->is_undefined()
1281 || gsym
->is_preemptible())
1282 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
,
1283 rel_dyn
, elfcpp::R_386_GLOB_DAT
);
1286 if (got
->add_global(gsym
, GOT_TYPE_STANDARD
))
1287 rel_dyn
->add_global_relative(
1288 gsym
, elfcpp::R_386_RELATIVE
, got
,
1289 gsym
->got_offset(GOT_TYPE_STANDARD
));
1295 case elfcpp::R_386_PLT32
:
1296 // If the symbol is fully resolved, this is just a PC32 reloc.
1297 // Otherwise we need a PLT entry.
1298 if (gsym
->final_value_is_known())
1300 // If building a shared library, we can also skip the PLT entry
1301 // if the symbol is defined in the output file and is protected
1303 if (gsym
->is_defined()
1304 && !gsym
->is_from_dynobj()
1305 && !gsym
->is_preemptible())
1307 target
->make_plt_entry(symtab
, layout
, gsym
);
1310 case elfcpp::R_386_GOTOFF
:
1311 case elfcpp::R_386_GOTPC
:
1312 // We need a GOT section.
1313 target
->got_section(symtab
, layout
);
1316 // These are relocations which should only be seen by the
1317 // dynamic linker, and should never be seen here.
1318 case elfcpp::R_386_COPY
:
1319 case elfcpp::R_386_GLOB_DAT
:
1320 case elfcpp::R_386_JUMP_SLOT
:
1321 case elfcpp::R_386_RELATIVE
:
1322 case elfcpp::R_386_TLS_TPOFF
:
1323 case elfcpp::R_386_TLS_DTPMOD32
:
1324 case elfcpp::R_386_TLS_DTPOFF32
:
1325 case elfcpp::R_386_TLS_TPOFF32
:
1326 case elfcpp::R_386_TLS_DESC
:
1327 gold_error(_("%s: unexpected reloc %u in object file"),
1328 object
->name().c_str(), r_type
);
1331 // These are initial tls relocs, which are expected when
1333 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1334 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1335 case elfcpp::R_386_TLS_DESC_CALL
:
1336 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1337 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1338 case elfcpp::R_386_TLS_IE
: // Initial-exec
1339 case elfcpp::R_386_TLS_IE_32
:
1340 case elfcpp::R_386_TLS_GOTIE
:
1341 case elfcpp::R_386_TLS_LE
: // Local-exec
1342 case elfcpp::R_386_TLS_LE_32
:
1344 const bool is_final
= gsym
->final_value_is_known();
1345 const tls::Tls_optimization optimized_type
1346 = Target_i386::optimize_tls_reloc(is_final
, r_type
);
1349 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1350 if (optimized_type
== tls::TLSOPT_NONE
)
1352 // Create a pair of GOT entries for the module index and
1353 // dtv-relative offset.
1354 Output_data_got
<32, false>* got
1355 = target
->got_section(symtab
, layout
);
1356 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
1357 target
->rel_dyn_section(layout
),
1358 elfcpp::R_386_TLS_DTPMOD32
,
1359 elfcpp::R_386_TLS_DTPOFF32
);
1361 else if (optimized_type
== tls::TLSOPT_TO_IE
)
1363 // Create a GOT entry for the tp-relative offset.
1364 Output_data_got
<32, false>* got
1365 = target
->got_section(symtab
, layout
);
1366 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_NOFFSET
,
1367 target
->rel_dyn_section(layout
),
1368 elfcpp::R_386_TLS_TPOFF
);
1370 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1371 unsupported_reloc_global(object
, r_type
, gsym
);
1374 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (~oliva url)
1375 target
->define_tls_base_symbol(symtab
, layout
);
1376 if (optimized_type
== tls::TLSOPT_NONE
)
1378 // Create a double GOT entry with an R_386_TLS_DESC reloc.
1379 Output_data_got
<32, false>* got
1380 = target
->got_section(symtab
, layout
);
1381 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_DESC
,
1382 target
->rel_dyn_section(layout
),
1383 elfcpp::R_386_TLS_DESC
, 0);
1385 else if (optimized_type
== tls::TLSOPT_TO_IE
)
1387 // Create a GOT entry for the tp-relative offset.
1388 Output_data_got
<32, false>* got
1389 = target
->got_section(symtab
, layout
);
1390 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_NOFFSET
,
1391 target
->rel_dyn_section(layout
),
1392 elfcpp::R_386_TLS_TPOFF
);
1394 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1395 unsupported_reloc_global(object
, r_type
, gsym
);
1398 case elfcpp::R_386_TLS_DESC_CALL
:
1401 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1402 if (optimized_type
== tls::TLSOPT_NONE
)
1404 // Create a GOT entry for the module index.
1405 target
->got_mod_index_entry(symtab
, layout
, object
);
1407 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1408 unsupported_reloc_global(object
, r_type
, gsym
);
1411 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1414 case elfcpp::R_386_TLS_IE
: // Initial-exec
1415 case elfcpp::R_386_TLS_IE_32
:
1416 case elfcpp::R_386_TLS_GOTIE
:
1417 layout
->set_has_static_tls();
1418 if (optimized_type
== tls::TLSOPT_NONE
)
1420 // For the R_386_TLS_IE relocation, we need to create a
1421 // dynamic relocation when building a shared library.
1422 if (r_type
== elfcpp::R_386_TLS_IE
1423 && parameters
->options().shared())
1425 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1426 rel_dyn
->add_global_relative(gsym
, elfcpp::R_386_RELATIVE
,
1427 output_section
, object
,
1429 reloc
.get_r_offset());
1431 // Create a GOT entry for the tp-relative offset.
1432 Output_data_got
<32, false>* got
1433 = target
->got_section(symtab
, layout
);
1434 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1435 ? elfcpp::R_386_TLS_TPOFF32
1436 : elfcpp::R_386_TLS_TPOFF
);
1437 unsigned int got_type
= (r_type
== elfcpp::R_386_TLS_IE_32
1438 ? GOT_TYPE_TLS_OFFSET
1439 : GOT_TYPE_TLS_NOFFSET
);
1440 got
->add_global_with_rel(gsym
, got_type
,
1441 target
->rel_dyn_section(layout
),
1444 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1445 unsupported_reloc_global(object
, r_type
, gsym
);
1448 case elfcpp::R_386_TLS_LE
: // Local-exec
1449 case elfcpp::R_386_TLS_LE_32
:
1450 layout
->set_has_static_tls();
1451 if (parameters
->options().shared())
1453 // We need to create a dynamic relocation.
1454 unsigned int dyn_r_type
= (r_type
== elfcpp::R_386_TLS_LE_32
1455 ? elfcpp::R_386_TLS_TPOFF32
1456 : elfcpp::R_386_TLS_TPOFF
);
1457 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1458 rel_dyn
->add_global(gsym
, dyn_r_type
, output_section
, object
,
1459 data_shndx
, reloc
.get_r_offset());
1469 case elfcpp::R_386_32PLT
:
1470 case elfcpp::R_386_TLS_GD_32
:
1471 case elfcpp::R_386_TLS_GD_PUSH
:
1472 case elfcpp::R_386_TLS_GD_CALL
:
1473 case elfcpp::R_386_TLS_GD_POP
:
1474 case elfcpp::R_386_TLS_LDM_32
:
1475 case elfcpp::R_386_TLS_LDM_PUSH
:
1476 case elfcpp::R_386_TLS_LDM_CALL
:
1477 case elfcpp::R_386_TLS_LDM_POP
:
1478 case elfcpp::R_386_USED_BY_INTEL_200
:
1480 unsupported_reloc_global(object
, r_type
, gsym
);
1485 // Process relocations for gc.
1488 Target_i386::gc_process_relocs(Symbol_table
* symtab
,
1490 Sized_relobj
<32, false>* object
,
1491 unsigned int data_shndx
,
1493 const unsigned char* prelocs
,
1495 Output_section
* output_section
,
1496 bool needs_special_offset_handling
,
1497 size_t local_symbol_count
,
1498 const unsigned char* plocal_symbols
)
1500 gold::gc_process_relocs
<32, false, Target_i386
, elfcpp::SHT_REL
,
1510 needs_special_offset_handling
,
1515 // Scan relocations for a section.
1518 Target_i386::scan_relocs(Symbol_table
* symtab
,
1520 Sized_relobj
<32, false>* object
,
1521 unsigned int data_shndx
,
1522 unsigned int sh_type
,
1523 const unsigned char* prelocs
,
1525 Output_section
* output_section
,
1526 bool needs_special_offset_handling
,
1527 size_t local_symbol_count
,
1528 const unsigned char* plocal_symbols
)
1530 if (sh_type
== elfcpp::SHT_RELA
)
1532 gold_error(_("%s: unsupported RELA reloc section"),
1533 object
->name().c_str());
1537 gold::scan_relocs
<32, false, Target_i386
, elfcpp::SHT_REL
,
1547 needs_special_offset_handling
,
1552 // Finalize the sections.
1555 Target_i386::do_finalize_sections(
1557 const Input_objects
*,
1560 // Fill in some more dynamic tags.
1561 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
1564 if (this->got_plt_
!= NULL
1565 && this->got_plt_
->output_section() != NULL
)
1566 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->got_plt_
);
1568 if (this->plt_
!= NULL
1569 && this->plt_
->output_section() != NULL
)
1571 const Output_data
* od
= this->plt_
->rel_plt();
1572 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
1573 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
1574 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_REL
);
1577 if (this->rel_dyn_
!= NULL
1578 && this->rel_dyn_
->output_section() != NULL
)
1580 const Output_data
* od
= this->rel_dyn_
;
1581 odyn
->add_section_address(elfcpp::DT_REL
, od
);
1582 odyn
->add_section_size(elfcpp::DT_RELSZ
, od
);
1583 odyn
->add_constant(elfcpp::DT_RELENT
,
1584 elfcpp::Elf_sizes
<32>::rel_size
);
1587 if (!parameters
->options().shared())
1589 // The value of the DT_DEBUG tag is filled in by the dynamic
1590 // linker at run time, and used by the debugger.
1591 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
1595 // Emit any relocs we saved in an attempt to avoid generating COPY
1597 if (this->copy_relocs_
.any_saved_relocs())
1598 this->copy_relocs_
.emit(this->rel_dyn_section(layout
));
1601 // Return whether a direct absolute static relocation needs to be applied.
1602 // In cases where Scan::local() or Scan::global() has created
1603 // a dynamic relocation other than R_386_RELATIVE, the addend
1604 // of the relocation is carried in the data, and we must not
1605 // apply the static relocation.
1608 Target_i386::Relocate::should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
1611 Output_section
* output_section
)
1613 // If the output section is not allocated, then we didn't call
1614 // scan_relocs, we didn't create a dynamic reloc, and we must apply
1616 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
1619 // For local symbols, we will have created a non-RELATIVE dynamic
1620 // relocation only if (a) the output is position independent,
1621 // (b) the relocation is absolute (not pc- or segment-relative), and
1622 // (c) the relocation is not 32 bits wide.
1624 return !(parameters
->options().output_is_position_independent()
1625 && (ref_flags
& Symbol::ABSOLUTE_REF
)
1628 // For global symbols, we use the same helper routines used in the
1629 // scan pass. If we did not create a dynamic relocation, or if we
1630 // created a RELATIVE dynamic relocation, we should apply the static
1632 bool has_dyn
= gsym
->needs_dynamic_reloc(ref_flags
);
1633 bool is_rel
= (ref_flags
& Symbol::ABSOLUTE_REF
)
1634 && gsym
->can_use_relative_reloc(ref_flags
1635 & Symbol::FUNCTION_CALL
);
1636 return !has_dyn
|| is_rel
;
1639 // Perform a relocation.
1642 Target_i386::Relocate::relocate(const Relocate_info
<32, false>* relinfo
,
1643 Target_i386
* target
,
1644 Output_section
*output_section
,
1646 const elfcpp::Rel
<32, false>& rel
,
1647 unsigned int r_type
,
1648 const Sized_symbol
<32>* gsym
,
1649 const Symbol_value
<32>* psymval
,
1650 unsigned char* view
,
1651 elfcpp::Elf_types
<32>::Elf_Addr address
,
1652 section_size_type view_size
)
1654 if (this->skip_call_tls_get_addr_
)
1656 if ((r_type
!= elfcpp::R_386_PLT32
1657 && r_type
!= elfcpp::R_386_PC32
)
1659 || strcmp(gsym
->name(), "___tls_get_addr") != 0)
1660 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1661 _("missing expected TLS relocation"));
1664 this->skip_call_tls_get_addr_
= false;
1669 // Pick the value to use for symbols defined in shared objects.
1670 Symbol_value
<32> symval
;
1672 && gsym
->use_plt_offset(r_type
== elfcpp::R_386_PC8
1673 || r_type
== elfcpp::R_386_PC16
1674 || r_type
== elfcpp::R_386_PC32
))
1676 symval
.set_output_value(target
->plt_section()->address()
1677 + gsym
->plt_offset());
1681 const Sized_relobj
<32, false>* object
= relinfo
->object
;
1683 // Get the GOT offset if needed.
1684 // The GOT pointer points to the end of the GOT section.
1685 // We need to subtract the size of the GOT section to get
1686 // the actual offset to use in the relocation.
1687 bool have_got_offset
= false;
1688 unsigned int got_offset
= 0;
1691 case elfcpp::R_386_GOT32
:
1694 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
1695 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
1696 - target
->got_size());
1700 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1701 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
1702 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
1703 - target
->got_size());
1705 have_got_offset
= true;
1714 case elfcpp::R_386_NONE
:
1715 case elfcpp::R_386_GNU_VTINHERIT
:
1716 case elfcpp::R_386_GNU_VTENTRY
:
1719 case elfcpp::R_386_32
:
1720 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1722 Relocate_functions
<32, false>::rel32(view
, object
, psymval
);
1725 case elfcpp::R_386_PC32
:
1727 int ref_flags
= Symbol::NON_PIC_REF
;
1728 if (gsym
!= NULL
&& gsym
->type() == elfcpp::STT_FUNC
)
1729 ref_flags
|= Symbol::FUNCTION_CALL
;
1730 if (should_apply_static_reloc(gsym
, ref_flags
, true, output_section
))
1731 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1735 case elfcpp::R_386_16
:
1736 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
1738 Relocate_functions
<32, false>::rel16(view
, object
, psymval
);
1741 case elfcpp::R_386_PC16
:
1743 int ref_flags
= Symbol::NON_PIC_REF
;
1744 if (gsym
!= NULL
&& gsym
->type() == elfcpp::STT_FUNC
)
1745 ref_flags
|= Symbol::FUNCTION_CALL
;
1746 if (should_apply_static_reloc(gsym
, ref_flags
, false, output_section
))
1747 Relocate_functions
<32, false>::pcrel16(view
, object
, psymval
, address
);
1751 case elfcpp::R_386_8
:
1752 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
1754 Relocate_functions
<32, false>::rel8(view
, object
, psymval
);
1757 case elfcpp::R_386_PC8
:
1759 int ref_flags
= Symbol::NON_PIC_REF
;
1760 if (gsym
!= NULL
&& gsym
->type() == elfcpp::STT_FUNC
)
1761 ref_flags
|= Symbol::FUNCTION_CALL
;
1762 if (should_apply_static_reloc(gsym
, ref_flags
, false,
1764 Relocate_functions
<32, false>::pcrel8(view
, object
, psymval
, address
);
1768 case elfcpp::R_386_PLT32
:
1769 gold_assert(gsym
== NULL
1770 || gsym
->has_plt_offset()
1771 || gsym
->final_value_is_known()
1772 || (gsym
->is_defined()
1773 && !gsym
->is_from_dynobj()
1774 && !gsym
->is_preemptible()));
1775 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1778 case elfcpp::R_386_GOT32
:
1779 gold_assert(have_got_offset
);
1780 Relocate_functions
<32, false>::rel32(view
, got_offset
);
1783 case elfcpp::R_386_GOTOFF
:
1785 elfcpp::Elf_types
<32>::Elf_Addr value
;
1786 value
= (psymval
->value(object
, 0)
1787 - target
->got_plt_section()->address());
1788 Relocate_functions
<32, false>::rel32(view
, value
);
1792 case elfcpp::R_386_GOTPC
:
1794 elfcpp::Elf_types
<32>::Elf_Addr value
;
1795 value
= target
->got_plt_section()->address();
1796 Relocate_functions
<32, false>::pcrel32(view
, value
, address
);
1800 case elfcpp::R_386_COPY
:
1801 case elfcpp::R_386_GLOB_DAT
:
1802 case elfcpp::R_386_JUMP_SLOT
:
1803 case elfcpp::R_386_RELATIVE
:
1804 // These are outstanding tls relocs, which are unexpected when
1806 case elfcpp::R_386_TLS_TPOFF
:
1807 case elfcpp::R_386_TLS_DTPMOD32
:
1808 case elfcpp::R_386_TLS_DTPOFF32
:
1809 case elfcpp::R_386_TLS_TPOFF32
:
1810 case elfcpp::R_386_TLS_DESC
:
1811 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1812 _("unexpected reloc %u in object file"),
1816 // These are initial tls relocs, which are expected when
1818 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1819 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1820 case elfcpp::R_386_TLS_DESC_CALL
:
1821 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1822 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
1823 case elfcpp::R_386_TLS_IE
: // Initial-exec
1824 case elfcpp::R_386_TLS_IE_32
:
1825 case elfcpp::R_386_TLS_GOTIE
:
1826 case elfcpp::R_386_TLS_LE
: // Local-exec
1827 case elfcpp::R_386_TLS_LE_32
:
1828 this->relocate_tls(relinfo
, target
, relnum
, rel
, r_type
, gsym
, psymval
,
1829 view
, address
, view_size
);
1832 case elfcpp::R_386_32PLT
:
1833 case elfcpp::R_386_TLS_GD_32
:
1834 case elfcpp::R_386_TLS_GD_PUSH
:
1835 case elfcpp::R_386_TLS_GD_CALL
:
1836 case elfcpp::R_386_TLS_GD_POP
:
1837 case elfcpp::R_386_TLS_LDM_32
:
1838 case elfcpp::R_386_TLS_LDM_PUSH
:
1839 case elfcpp::R_386_TLS_LDM_CALL
:
1840 case elfcpp::R_386_TLS_LDM_POP
:
1841 case elfcpp::R_386_USED_BY_INTEL_200
:
1843 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1844 _("unsupported reloc %u"),
1852 // Perform a TLS relocation.
1855 Target_i386::Relocate::relocate_tls(const Relocate_info
<32, false>* relinfo
,
1856 Target_i386
* target
,
1858 const elfcpp::Rel
<32, false>& rel
,
1859 unsigned int r_type
,
1860 const Sized_symbol
<32>* gsym
,
1861 const Symbol_value
<32>* psymval
,
1862 unsigned char* view
,
1863 elfcpp::Elf_types
<32>::Elf_Addr
,
1864 section_size_type view_size
)
1866 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
1868 const Sized_relobj
<32, false>* object
= relinfo
->object
;
1870 elfcpp::Elf_types
<32>::Elf_Addr value
= psymval
->value(object
, 0);
1872 const bool is_final
=
1874 ? !parameters
->options().output_is_position_independent()
1875 : gsym
->final_value_is_known());
1876 const tls::Tls_optimization optimized_type
1877 = Target_i386::optimize_tls_reloc(is_final
, r_type
);
1880 case elfcpp::R_386_TLS_GD
: // Global-dynamic
1881 if (optimized_type
== tls::TLSOPT_TO_LE
)
1883 gold_assert(tls_segment
!= NULL
);
1884 this->tls_gd_to_le(relinfo
, relnum
, tls_segment
,
1885 rel
, r_type
, value
, view
,
1891 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
1892 ? GOT_TYPE_TLS_NOFFSET
1893 : GOT_TYPE_TLS_PAIR
);
1894 unsigned int got_offset
;
1897 gold_assert(gsym
->has_got_offset(got_type
));
1898 got_offset
= gsym
->got_offset(got_type
) - target
->got_size();
1902 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1903 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
1904 got_offset
= (object
->local_got_offset(r_sym
, got_type
)
1905 - target
->got_size());
1907 if (optimized_type
== tls::TLSOPT_TO_IE
)
1909 gold_assert(tls_segment
!= NULL
);
1910 this->tls_gd_to_ie(relinfo
, relnum
, tls_segment
, rel
, r_type
,
1911 got_offset
, view
, view_size
);
1914 else if (optimized_type
== tls::TLSOPT_NONE
)
1916 // Relocate the field with the offset of the pair of GOT
1918 Relocate_functions
<32, false>::rel32(view
, got_offset
);
1922 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1923 _("unsupported reloc %u"),
1927 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
1928 case elfcpp::R_386_TLS_DESC_CALL
:
1929 this->local_dynamic_type_
= LOCAL_DYNAMIC_GNU
;
1930 if (optimized_type
== tls::TLSOPT_TO_LE
)
1932 gold_assert(tls_segment
!= NULL
);
1933 this->tls_desc_gd_to_le(relinfo
, relnum
, tls_segment
,
1934 rel
, r_type
, value
, view
,
1940 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
1941 ? GOT_TYPE_TLS_NOFFSET
1942 : GOT_TYPE_TLS_DESC
);
1943 unsigned int got_offset
;
1946 gold_assert(gsym
->has_got_offset(got_type
));
1947 got_offset
= gsym
->got_offset(got_type
) - target
->got_size();
1951 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1952 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
1953 got_offset
= (object
->local_got_offset(r_sym
, got_type
)
1954 - target
->got_size());
1956 if (optimized_type
== tls::TLSOPT_TO_IE
)
1958 gold_assert(tls_segment
!= NULL
);
1959 this->tls_desc_gd_to_ie(relinfo
, relnum
, tls_segment
, rel
, r_type
,
1960 got_offset
, view
, view_size
);
1963 else if (optimized_type
== tls::TLSOPT_NONE
)
1965 if (r_type
== elfcpp::R_386_TLS_GOTDESC
)
1967 // Relocate the field with the offset of the pair of GOT
1969 Relocate_functions
<32, false>::rel32(view
, got_offset
);
1974 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1975 _("unsupported reloc %u"),
1979 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
1980 if (this->local_dynamic_type_
== LOCAL_DYNAMIC_SUN
)
1982 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1983 _("both SUN and GNU model "
1984 "TLS relocations"));
1987 this->local_dynamic_type_
= LOCAL_DYNAMIC_GNU
;
1988 if (optimized_type
== tls::TLSOPT_TO_LE
)
1990 gold_assert(tls_segment
!= NULL
);
1991 this->tls_ld_to_le(relinfo
, relnum
, tls_segment
, rel
, r_type
,
1992 value
, view
, view_size
);
1995 else if (optimized_type
== tls::TLSOPT_NONE
)
1997 // Relocate the field with the offset of the GOT entry for
1998 // the module index.
1999 unsigned int got_offset
;
2000 got_offset
= (target
->got_mod_index_entry(NULL
, NULL
, NULL
)
2001 - target
->got_size());
2002 Relocate_functions
<32, false>::rel32(view
, got_offset
);
2005 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2006 _("unsupported reloc %u"),
2010 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
2011 if (optimized_type
== tls::TLSOPT_TO_LE
)
2013 // This reloc can appear in debugging sections, in which
2014 // case we must not convert to local-exec. We decide what
2015 // to do based on whether the section is marked as
2016 // containing executable code. That is what the GNU linker
2018 elfcpp::Shdr
<32, false> shdr(relinfo
->data_shdr
);
2019 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
2021 gold_assert(tls_segment
!= NULL
);
2022 value
-= tls_segment
->memsz();
2025 Relocate_functions
<32, false>::rel32(view
, value
);
2028 case elfcpp::R_386_TLS_IE
: // Initial-exec
2029 case elfcpp::R_386_TLS_GOTIE
:
2030 case elfcpp::R_386_TLS_IE_32
:
2031 if (optimized_type
== tls::TLSOPT_TO_LE
)
2033 gold_assert(tls_segment
!= NULL
);
2034 Target_i386::Relocate::tls_ie_to_le(relinfo
, relnum
, tls_segment
,
2035 rel
, r_type
, value
, view
,
2039 else if (optimized_type
== tls::TLSOPT_NONE
)
2041 // Relocate the field with the offset of the GOT entry for
2042 // the tp-relative offset of the symbol.
2043 unsigned int got_type
= (r_type
== elfcpp::R_386_TLS_IE_32
2044 ? GOT_TYPE_TLS_OFFSET
2045 : GOT_TYPE_TLS_NOFFSET
);
2046 unsigned int got_offset
;
2049 gold_assert(gsym
->has_got_offset(got_type
));
2050 got_offset
= gsym
->got_offset(got_type
);
2054 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
2055 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2056 got_offset
= object
->local_got_offset(r_sym
, got_type
);
2058 // For the R_386_TLS_IE relocation, we need to apply the
2059 // absolute address of the GOT entry.
2060 if (r_type
== elfcpp::R_386_TLS_IE
)
2061 got_offset
+= target
->got_plt_section()->address();
2062 // All GOT offsets are relative to the end of the GOT.
2063 got_offset
-= target
->got_size();
2064 Relocate_functions
<32, false>::rel32(view
, got_offset
);
2067 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2068 _("unsupported reloc %u"),
2072 case elfcpp::R_386_TLS_LE
: // Local-exec
2073 // If we're creating a shared library, a dynamic relocation will
2074 // have been created for this location, so do not apply it now.
2075 if (!parameters
->options().shared())
2077 gold_assert(tls_segment
!= NULL
);
2078 value
-= tls_segment
->memsz();
2079 Relocate_functions
<32, false>::rel32(view
, value
);
2083 case elfcpp::R_386_TLS_LE_32
:
2084 // If we're creating a shared library, a dynamic relocation will
2085 // have been created for this location, so do not apply it now.
2086 if (!parameters
->options().shared())
2088 gold_assert(tls_segment
!= NULL
);
2089 value
= tls_segment
->memsz() - value
;
2090 Relocate_functions
<32, false>::rel32(view
, value
);
2096 // Do a relocation in which we convert a TLS General-Dynamic to a
2100 Target_i386::Relocate::tls_gd_to_le(const Relocate_info
<32, false>* relinfo
,
2102 Output_segment
* tls_segment
,
2103 const elfcpp::Rel
<32, false>& rel
,
2105 elfcpp::Elf_types
<32>::Elf_Addr value
,
2106 unsigned char* view
,
2107 section_size_type view_size
)
2109 // leal foo(,%reg,1),%eax; call ___tls_get_addr
2110 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
2111 // leal foo(%reg),%eax; call ___tls_get_addr
2112 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
2114 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2115 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 9);
2117 unsigned char op1
= view
[-1];
2118 unsigned char op2
= view
[-2];
2120 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2121 op2
== 0x8d || op2
== 0x04);
2122 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[4] == 0xe8);
2128 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -3);
2129 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[-3] == 0x8d);
2130 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2131 ((op1
& 0xc7) == 0x05 && op1
!= (4 << 3)));
2132 memcpy(view
- 3, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2136 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2137 (op1
& 0xf8) == 0x80 && (op1
& 7) != 4);
2138 if (rel
.get_r_offset() + 9 < view_size
2141 // There is a trailing nop. Use the size byte subl.
2142 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2147 // Use the five byte subl.
2148 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2152 value
= tls_segment
->memsz() - value
;
2153 Relocate_functions
<32, false>::rel32(view
+ roff
, value
);
2155 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2157 this->skip_call_tls_get_addr_
= true;
2160 // Do a relocation in which we convert a TLS General-Dynamic to an
2164 Target_i386::Relocate::tls_gd_to_ie(const Relocate_info
<32, false>* relinfo
,
2167 const elfcpp::Rel
<32, false>& rel
,
2169 elfcpp::Elf_types
<32>::Elf_Addr value
,
2170 unsigned char* view
,
2171 section_size_type view_size
)
2173 // leal foo(,%ebx,1),%eax; call ___tls_get_addr
2174 // ==> movl %gs:0,%eax; addl foo@gotntpoff(%ebx),%eax
2176 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2177 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 9);
2179 unsigned char op1
= view
[-1];
2180 unsigned char op2
= view
[-2];
2182 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2183 op2
== 0x8d || op2
== 0x04);
2184 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[4] == 0xe8);
2188 // FIXME: For now, support only the first (SIB) form.
2189 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), op2
== 0x04);
2193 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -3);
2194 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[-3] == 0x8d);
2195 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2196 ((op1
& 0xc7) == 0x05 && op1
!= (4 << 3)));
2197 memcpy(view
- 3, "\x65\xa1\0\0\0\0\x03\x83\0\0\0", 12);
2201 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2202 (op1
& 0xf8) == 0x80 && (op1
& 7) != 4);
2203 if (rel
.get_r_offset() + 9 < view_size
2206 // FIXME: This is not the right instruction sequence.
2207 // There is a trailing nop. Use the size byte subl.
2208 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2213 // FIXME: This is not the right instruction sequence.
2214 // Use the five byte subl.
2215 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2219 Relocate_functions
<32, false>::rel32(view
+ roff
, value
);
2221 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2223 this->skip_call_tls_get_addr_
= true;
2226 // Do a relocation in which we convert a TLS_GOTDESC or TLS_DESC_CALL
2227 // General-Dynamic to a Local-Exec.
2230 Target_i386::Relocate::tls_desc_gd_to_le(
2231 const Relocate_info
<32, false>* relinfo
,
2233 Output_segment
* tls_segment
,
2234 const elfcpp::Rel
<32, false>& rel
,
2235 unsigned int r_type
,
2236 elfcpp::Elf_types
<32>::Elf_Addr value
,
2237 unsigned char* view
,
2238 section_size_type view_size
)
2240 if (r_type
== elfcpp::R_386_TLS_GOTDESC
)
2242 // leal foo@TLSDESC(%ebx), %eax
2243 // ==> leal foo@NTPOFF, %eax
2244 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2245 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2246 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2247 view
[-2] == 0x8d && view
[-1] == 0x83);
2249 value
-= tls_segment
->memsz();
2250 Relocate_functions
<32, false>::rel32(view
, value
);
2254 // call *foo@TLSCALL(%eax)
2256 gold_assert(r_type
== elfcpp::R_386_TLS_DESC_CALL
);
2257 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 2);
2258 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2259 view
[0] == 0xff && view
[1] == 0x10);
2265 // Do a relocation in which we convert a TLS_GOTDESC or TLS_DESC_CALL
2266 // General-Dynamic to an Initial-Exec.
2269 Target_i386::Relocate::tls_desc_gd_to_ie(
2270 const Relocate_info
<32, false>* relinfo
,
2273 const elfcpp::Rel
<32, false>& rel
,
2274 unsigned int r_type
,
2275 elfcpp::Elf_types
<32>::Elf_Addr value
,
2276 unsigned char* view
,
2277 section_size_type view_size
)
2279 if (r_type
== elfcpp::R_386_TLS_GOTDESC
)
2281 // leal foo@TLSDESC(%ebx), %eax
2282 // ==> movl foo@GOTNTPOFF(%ebx), %eax
2283 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2284 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2285 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2286 view
[-2] == 0x8d && view
[-1] == 0x83);
2288 Relocate_functions
<32, false>::rel32(view
, value
);
2292 // call *foo@TLSCALL(%eax)
2294 gold_assert(r_type
== elfcpp::R_386_TLS_DESC_CALL
);
2295 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 2);
2296 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2297 view
[0] == 0xff && view
[1] == 0x10);
2303 // Do a relocation in which we convert a TLS Local-Dynamic to a
2307 Target_i386::Relocate::tls_ld_to_le(const Relocate_info
<32, false>* relinfo
,
2310 const elfcpp::Rel
<32, false>& rel
,
2312 elfcpp::Elf_types
<32>::Elf_Addr
,
2313 unsigned char* view
,
2314 section_size_type view_size
)
2316 // leal foo(%reg), %eax; call ___tls_get_addr
2317 // ==> movl %gs:0,%eax; nop; leal 0(%esi,1),%esi
2319 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2320 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 9);
2322 // FIXME: Does this test really always pass?
2323 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2324 view
[-2] == 0x8d && view
[-1] == 0x83);
2326 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), view
[4] == 0xe8);
2328 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x90\x8d\x74\x26\0", 11);
2330 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2332 this->skip_call_tls_get_addr_
= true;
2335 // Do a relocation in which we convert a TLS Initial-Exec to a
2339 Target_i386::Relocate::tls_ie_to_le(const Relocate_info
<32, false>* relinfo
,
2341 Output_segment
* tls_segment
,
2342 const elfcpp::Rel
<32, false>& rel
,
2343 unsigned int r_type
,
2344 elfcpp::Elf_types
<32>::Elf_Addr value
,
2345 unsigned char* view
,
2346 section_size_type view_size
)
2348 // We have to actually change the instructions, which means that we
2349 // need to examine the opcodes to figure out which instruction we
2351 if (r_type
== elfcpp::R_386_TLS_IE
)
2353 // movl %gs:XX,%eax ==> movl $YY,%eax
2354 // movl %gs:XX,%reg ==> movl $YY,%reg
2355 // addl %gs:XX,%reg ==> addl $YY,%reg
2356 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -1);
2357 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2359 unsigned char op1
= view
[-1];
2362 // movl XX,%eax ==> movl $YY,%eax
2367 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2369 unsigned char op2
= view
[-2];
2372 // movl XX,%reg ==> movl $YY,%reg
2373 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2374 (op1
& 0xc7) == 0x05);
2376 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2378 else if (op2
== 0x03)
2380 // addl XX,%reg ==> addl $YY,%reg
2381 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2382 (op1
& 0xc7) == 0x05);
2384 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2387 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), 0);
2392 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
2393 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
2394 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
2395 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, -2);
2396 tls::check_range(relinfo
, relnum
, rel
.get_r_offset(), view_size
, 4);
2398 unsigned char op1
= view
[-1];
2399 unsigned char op2
= view
[-2];
2400 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(),
2401 (op1
& 0xc0) == 0x80 && (op1
& 7) != 4);
2404 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
2406 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2408 else if (op2
== 0x2b)
2410 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
2412 view
[-1] = 0xe8 | ((op1
>> 3) & 7);
2414 else if (op2
== 0x03)
2416 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
2418 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
2421 tls::check_tls(relinfo
, relnum
, rel
.get_r_offset(), 0);
2424 value
= tls_segment
->memsz() - value
;
2425 if (r_type
== elfcpp::R_386_TLS_IE
|| r_type
== elfcpp::R_386_TLS_GOTIE
)
2428 Relocate_functions
<32, false>::rel32(view
, value
);
2431 // Relocate section data.
2434 Target_i386::relocate_section(const Relocate_info
<32, false>* relinfo
,
2435 unsigned int sh_type
,
2436 const unsigned char* prelocs
,
2438 Output_section
* output_section
,
2439 bool needs_special_offset_handling
,
2440 unsigned char* view
,
2441 elfcpp::Elf_types
<32>::Elf_Addr address
,
2442 section_size_type view_size
,
2443 const Reloc_symbol_changes
* reloc_symbol_changes
)
2445 gold_assert(sh_type
== elfcpp::SHT_REL
);
2447 gold::relocate_section
<32, false, Target_i386
, elfcpp::SHT_REL
,
2448 Target_i386::Relocate
>(
2454 needs_special_offset_handling
,
2458 reloc_symbol_changes
);
2461 // Return the size of a relocation while scanning during a relocatable
2465 Target_i386::Relocatable_size_for_reloc::get_size_for_reloc(
2466 unsigned int r_type
,
2471 case elfcpp::R_386_NONE
:
2472 case elfcpp::R_386_GNU_VTINHERIT
:
2473 case elfcpp::R_386_GNU_VTENTRY
:
2474 case elfcpp::R_386_TLS_GD
: // Global-dynamic
2475 case elfcpp::R_386_TLS_GOTDESC
: // Global-dynamic (from ~oliva url)
2476 case elfcpp::R_386_TLS_DESC_CALL
:
2477 case elfcpp::R_386_TLS_LDM
: // Local-dynamic
2478 case elfcpp::R_386_TLS_LDO_32
: // Alternate local-dynamic
2479 case elfcpp::R_386_TLS_IE
: // Initial-exec
2480 case elfcpp::R_386_TLS_IE_32
:
2481 case elfcpp::R_386_TLS_GOTIE
:
2482 case elfcpp::R_386_TLS_LE
: // Local-exec
2483 case elfcpp::R_386_TLS_LE_32
:
2486 case elfcpp::R_386_32
:
2487 case elfcpp::R_386_PC32
:
2488 case elfcpp::R_386_GOT32
:
2489 case elfcpp::R_386_PLT32
:
2490 case elfcpp::R_386_GOTOFF
:
2491 case elfcpp::R_386_GOTPC
:
2494 case elfcpp::R_386_16
:
2495 case elfcpp::R_386_PC16
:
2498 case elfcpp::R_386_8
:
2499 case elfcpp::R_386_PC8
:
2502 // These are relocations which should only be seen by the
2503 // dynamic linker, and should never be seen here.
2504 case elfcpp::R_386_COPY
:
2505 case elfcpp::R_386_GLOB_DAT
:
2506 case elfcpp::R_386_JUMP_SLOT
:
2507 case elfcpp::R_386_RELATIVE
:
2508 case elfcpp::R_386_TLS_TPOFF
:
2509 case elfcpp::R_386_TLS_DTPMOD32
:
2510 case elfcpp::R_386_TLS_DTPOFF32
:
2511 case elfcpp::R_386_TLS_TPOFF32
:
2512 case elfcpp::R_386_TLS_DESC
:
2513 object
->error(_("unexpected reloc %u in object file"), r_type
);
2516 case elfcpp::R_386_32PLT
:
2517 case elfcpp::R_386_TLS_GD_32
:
2518 case elfcpp::R_386_TLS_GD_PUSH
:
2519 case elfcpp::R_386_TLS_GD_CALL
:
2520 case elfcpp::R_386_TLS_GD_POP
:
2521 case elfcpp::R_386_TLS_LDM_32
:
2522 case elfcpp::R_386_TLS_LDM_PUSH
:
2523 case elfcpp::R_386_TLS_LDM_CALL
:
2524 case elfcpp::R_386_TLS_LDM_POP
:
2525 case elfcpp::R_386_USED_BY_INTEL_200
:
2527 object
->error(_("unsupported reloc %u in object file"), r_type
);
2532 // Scan the relocs during a relocatable link.
2535 Target_i386::scan_relocatable_relocs(Symbol_table
* symtab
,
2537 Sized_relobj
<32, false>* object
,
2538 unsigned int data_shndx
,
2539 unsigned int sh_type
,
2540 const unsigned char* prelocs
,
2542 Output_section
* output_section
,
2543 bool needs_special_offset_handling
,
2544 size_t local_symbol_count
,
2545 const unsigned char* plocal_symbols
,
2546 Relocatable_relocs
* rr
)
2548 gold_assert(sh_type
== elfcpp::SHT_REL
);
2550 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_REL
,
2551 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
2553 gold::scan_relocatable_relocs
<32, false, elfcpp::SHT_REL
,
2554 Scan_relocatable_relocs
>(
2562 needs_special_offset_handling
,
2568 // Relocate a section during a relocatable link.
2571 Target_i386::relocate_for_relocatable(
2572 const Relocate_info
<32, false>* relinfo
,
2573 unsigned int sh_type
,
2574 const unsigned char* prelocs
,
2576 Output_section
* output_section
,
2577 off_t offset_in_output_section
,
2578 const Relocatable_relocs
* rr
,
2579 unsigned char* view
,
2580 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
2581 section_size_type view_size
,
2582 unsigned char* reloc_view
,
2583 section_size_type reloc_view_size
)
2585 gold_assert(sh_type
== elfcpp::SHT_REL
);
2587 gold::relocate_for_relocatable
<32, false, elfcpp::SHT_REL
>(
2592 offset_in_output_section
,
2601 // Return the value to use for a dynamic which requires special
2602 // treatment. This is how we support equality comparisons of function
2603 // pointers across shared library boundaries, as described in the
2604 // processor specific ABI supplement.
2607 Target_i386::do_dynsym_value(const Symbol
* gsym
) const
2609 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
2610 return this->plt_section()->address() + gsym
->plt_offset();
2613 // Return a string used to fill a code section with nops to take up
2614 // the specified length.
2617 Target_i386::do_code_fill(section_size_type length
) const
2621 // Build a jmp instruction to skip over the bytes.
2622 unsigned char jmp
[5];
2624 elfcpp::Swap_unaligned
<32, false>::writeval(jmp
+ 1, length
- 5);
2625 return (std::string(reinterpret_cast<char*>(&jmp
[0]), 5)
2626 + std::string(length
- 5, '\0'));
2629 // Nop sequences of various lengths.
2630 const char nop1
[1] = { 0x90 }; // nop
2631 const char nop2
[2] = { 0x66, 0x90 }; // xchg %ax %ax
2632 const char nop3
[3] = { 0x8d, 0x76, 0x00 }; // leal 0(%esi),%esi
2633 const char nop4
[4] = { 0x8d, 0x74, 0x26, 0x00}; // leal 0(%esi,1),%esi
2634 const char nop5
[5] = { 0x90, 0x8d, 0x74, 0x26, // nop
2635 0x00 }; // leal 0(%esi,1),%esi
2636 const char nop6
[6] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2638 const char nop7
[7] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2640 const char nop8
[8] = { 0x90, 0x8d, 0xb4, 0x26, // nop
2641 0x00, 0x00, 0x00, 0x00 }; // leal 0L(%esi,1),%esi
2642 const char nop9
[9] = { 0x89, 0xf6, 0x8d, 0xbc, // movl %esi,%esi
2643 0x27, 0x00, 0x00, 0x00, // leal 0L(%edi,1),%edi
2645 const char nop10
[10] = { 0x8d, 0x76, 0x00, 0x8d, // leal 0(%esi),%esi
2646 0xbc, 0x27, 0x00, 0x00, // leal 0L(%edi,1),%edi
2648 const char nop11
[11] = { 0x8d, 0x74, 0x26, 0x00, // leal 0(%esi,1),%esi
2649 0x8d, 0xbc, 0x27, 0x00, // leal 0L(%edi,1),%edi
2651 const char nop12
[12] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2652 0x00, 0x00, 0x8d, 0xbf, // leal 0L(%edi),%edi
2653 0x00, 0x00, 0x00, 0x00 };
2654 const char nop13
[13] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2655 0x00, 0x00, 0x8d, 0xbc, // leal 0L(%edi,1),%edi
2656 0x27, 0x00, 0x00, 0x00,
2658 const char nop14
[14] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2659 0x00, 0x00, 0x00, 0x8d, // leal 0L(%edi,1),%edi
2660 0xbc, 0x27, 0x00, 0x00,
2662 const char nop15
[15] = { 0xeb, 0x0d, 0x90, 0x90, // jmp .+15
2663 0x90, 0x90, 0x90, 0x90, // nop,nop,nop,...
2664 0x90, 0x90, 0x90, 0x90,
2667 const char* nops
[16] = {
2669 nop1
, nop2
, nop3
, nop4
, nop5
, nop6
, nop7
,
2670 nop8
, nop9
, nop10
, nop11
, nop12
, nop13
, nop14
, nop15
2673 return std::string(nops
[length
], length
);
2676 // FNOFFSET in section SHNDX in OBJECT is the start of a function
2677 // compiled with -fstack-split. The function calls non-stack-split
2678 // code. We have to change the function so that it always ensures
2679 // that it has enough stack space to run some random function.
2682 Target_i386::do_calls_non_split(Relobj
* object
, unsigned int shndx
,
2683 section_offset_type fnoffset
,
2684 section_size_type fnsize
,
2685 unsigned char* view
,
2686 section_size_type view_size
,
2688 std::string
* to
) const
2690 // The function starts with a comparison of the stack pointer and a
2691 // field in the TCB. This is followed by a jump.
2694 if (this->match_view(view
, view_size
, fnoffset
, "\x65\x3b\x25", 3)
2697 // We will call __morestack if the carry flag is set after this
2698 // comparison. We turn the comparison into an stc instruction
2700 view
[fnoffset
] = '\xf9';
2701 this->set_view_to_nop(view
, view_size
, fnoffset
+ 1, 6);
2703 // lea NN(%esp),%ecx
2704 else if (this->match_view(view
, view_size
, fnoffset
, "\x8d\x8c\x24", 3)
2707 // This is loading an offset from the stack pointer for a
2708 // comparison. The offset is negative, so we decrease the
2709 // offset by the amount of space we need for the stack. This
2710 // means we will avoid calling __morestack if there happens to
2711 // be plenty of space on the stack already.
2712 unsigned char* pval
= view
+ fnoffset
+ 3;
2713 uint32_t val
= elfcpp::Swap_unaligned
<32, false>::readval(pval
);
2714 val
-= parameters
->options().split_stack_adjust_size();
2715 elfcpp::Swap_unaligned
<32, false>::writeval(pval
, val
);
2719 if (!object
->has_no_split_stack())
2720 object
->error(_("failed to match split-stack sequence at "
2721 "section %u offset %0zx"),
2722 shndx
, static_cast<size_t>(fnoffset
));
2726 // We have to change the function so that it calls
2727 // __morestack_non_split instead of __morestack. The former will
2728 // allocate additional stack space.
2729 *from
= "__morestack";
2730 *to
= "__morestack_non_split";
2733 // The selector for i386 object files.
2735 class Target_selector_i386
: public Target_selector_freebsd
2738 Target_selector_i386()
2739 : Target_selector_freebsd(elfcpp::EM_386
, 32, false,
2740 "elf32-i386", "elf32-i386-freebsd")
2744 do_instantiate_target()
2745 { return new Target_i386(); }
2748 Target_selector_i386 target_selector_i386
;
2750 } // End anonymous namespace.