1 // i386.cc -- i386 target support for gold.
15 #include "target-reloc.h"
16 #include "target-select.h"
23 class Output_data_plt_i386
;
25 // The i386 target class.
27 class Target_i386
: public Sized_target
<32, false>
30 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false> Reloc_section
;
33 : Sized_target
<32, false>(&i386_info
),
34 got_(NULL
), plt_(NULL
), got_plt_(NULL
), rel_dyn_(NULL
),
35 copy_relocs_(NULL
), dynbss_(NULL
)
38 // Scan the relocations to look for symbol adjustments.
40 scan_relocs(const General_options
& options
,
43 Sized_relobj
<32, false>* object
,
44 unsigned int data_shndx
,
46 const unsigned char* prelocs
,
48 size_t local_symbol_count
,
49 const unsigned char* plocal_symbols
,
50 Symbol
** global_symbols
);
52 // Finalize the sections.
54 do_finalize_sections(const General_options
*, Layout
*);
56 // Relocate a section.
58 relocate_section(const Relocate_info
<32, false>*,
60 const unsigned char* prelocs
,
63 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
66 // Return a string used to fill a code section with nops.
68 do_code_fill(off_t length
);
71 // The class which scans relocations.
75 local(const General_options
& options
, Symbol_table
* symtab
,
76 Layout
* layout
, Target_i386
* target
,
77 Sized_relobj
<32, false>* object
,
78 unsigned int data_shndx
,
79 const elfcpp::Rel
<32, false>& reloc
, unsigned int r_type
,
80 const elfcpp::Sym
<32, false>& lsym
);
83 global(const General_options
& options
, Symbol_table
* symtab
,
84 Layout
* layout
, Target_i386
* target
,
85 Sized_relobj
<32, false>* object
,
86 unsigned int data_shndx
,
87 const elfcpp::Rel
<32, false>& reloc
, unsigned int r_type
,
91 // The class which implements relocation.
96 : skip_call_tls_get_addr_(false)
101 if (this->skip_call_tls_get_addr_
)
103 // FIXME: This needs to specify the location somehow.
104 fprintf(stderr
, _("%s: missing expected TLS relocation\n"),
110 // Do a relocation. Return false if the caller should not issue
111 // any warnings about this relocation.
113 relocate(const Relocate_info
<32, false>*, Target_i386
*, size_t relnum
,
114 const elfcpp::Rel
<32, false>&,
115 unsigned int r_type
, const Sized_symbol
<32>*,
116 const Symbol_value
<32>*,
117 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
,
121 // Do a TLS relocation.
123 relocate_tls(const Relocate_info
<32, false>*, size_t relnum
,
124 const elfcpp::Rel
<32, false>&,
125 unsigned int r_type
, const Sized_symbol
<32>*,
126 const Symbol_value
<32>*,
127 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
, off_t
);
129 // Do a TLS Initial-Exec to Local-Exec transition.
131 tls_ie_to_le(const Relocate_info
<32, false>*, size_t relnum
,
132 Output_segment
* tls_segment
,
133 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
134 elfcpp::Elf_types
<32>::Elf_Addr value
,
138 // Do a TLS Global-Dynamic to Local-Exec transition.
140 tls_gd_to_le(const Relocate_info
<32, false>*, size_t relnum
,
141 Output_segment
* tls_segment
,
142 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
143 elfcpp::Elf_types
<32>::Elf_Addr value
,
147 // Check the range for a TLS relocation.
149 check_range(const Relocate_info
<32, false>*, size_t relnum
,
150 const elfcpp::Rel
<32, false>&, off_t
, off_t
);
152 // Check the validity of a TLS relocation. This is like assert.
154 check_tls(const Relocate_info
<32, false>*, size_t relnum
,
155 const elfcpp::Rel
<32, false>&, bool);
157 // This is set if we should skip the next reloc, which should be a
158 // PLT32 reloc against ___tls_get_addr.
159 bool skip_call_tls_get_addr_
;
162 // Adjust TLS relocation type based on the options and whether this
163 // is a local symbol.
165 optimize_tls_reloc(const General_options
*, bool is_final
, int r_type
);
167 // Get the GOT section, creating it if necessary.
168 Output_data_got
<32, false>*
169 got_section(const General_options
*, Symbol_table
*, Layout
*);
171 // Create a PLT entry for a global symbol.
173 make_plt_entry(const General_options
* options
, Symbol_table
*,
176 // Get the PLT section.
177 Output_data_plt_i386
*
180 gold_assert(this->plt_
!= NULL
);
184 // Get the dynamic reloc section, creating it if necessary.
186 rel_dyn_section(Layout
*);
188 // Copy a relocation against a global symbol.
190 copy_reloc(const General_options
*, Symbol_table
*, Layout
*,
191 Sized_relobj
<32, false>*, unsigned int,
192 Symbol
*, const elfcpp::Rel
<32, false>&);
194 // Information about this specific target which we pass to the
195 // general Target structure.
196 static const Target::Target_info i386_info
;
199 Output_data_got
<32, false>* got_
;
201 Output_data_plt_i386
* plt_
;
202 // The GOT PLT section.
203 Output_data_space
* got_plt_
;
204 // The dynamic reloc section.
205 Reloc_section
* rel_dyn_
;
206 // Relocs saved to avoid a COPY reloc.
207 Copy_relocs
<32, false>* copy_relocs_
;
208 // Space for variables copied with a COPY reloc.
209 Output_data_space
* dynbss_
;
212 const Target::Target_info
Target_i386::i386_info
=
215 false, // is_big_endian
216 elfcpp::EM_386
, // machine_code
217 false, // has_make_symbol
218 false, // has_resolve
219 true, // has_code_fill
220 "/usr/lib/libc.so.1", // dynamic_linker
221 0x08048000, // text_segment_address
222 0x1000, // abi_pagesize
223 0x1000 // common_pagesize
226 // Get the GOT section, creating it if necessary.
228 Output_data_got
<32, false>*
229 Target_i386::got_section(const General_options
* options
, Symbol_table
* symtab
,
232 if (this->got_
== NULL
)
234 gold_assert(options
!= NULL
&& symtab
!= NULL
&& layout
!= NULL
);
236 this->got_
= new Output_data_got
<32, false>(options
);
238 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
239 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
242 // The old GNU linker creates a .got.plt section. We just
243 // create another set of data in the .got section. Note that we
244 // always create a PLT if we create a GOT, although the PLT
246 this->got_plt_
= new Output_data_space(4);
247 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
248 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
251 // The first three entries are reserved.
252 this->got_plt_
->set_space_size(3 * 4);
254 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
255 symtab
->define_in_output_data(this, "_GLOBAL_OFFSET_TABLE_", NULL
,
257 0, 0, elfcpp::STT_OBJECT
,
259 elfcpp::STV_HIDDEN
, 0,
266 // Get the dynamic reloc section, creating it if necessary.
268 Target_i386::Reloc_section
*
269 Target_i386::rel_dyn_section(Layout
* layout
)
271 if (this->rel_dyn_
== NULL
)
273 gold_assert(layout
!= NULL
);
274 this->rel_dyn_
= new Reloc_section();
275 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
276 elfcpp::SHF_ALLOC
, this->rel_dyn_
);
278 return this->rel_dyn_
;
281 // A class to handle the PLT data.
283 class Output_data_plt_i386
: public Output_section_data
286 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false> Reloc_section
;
288 Output_data_plt_i386(Layout
*, Output_data_space
*, bool is_shared
);
290 // Add an entry to the PLT.
292 add_entry(Symbol
* gsym
);
294 // Return the .rel.plt section data.
297 { return this->rel_
; }
301 do_adjust_output_section(Output_section
* os
);
304 // The size of an entry in the PLT.
305 static const int plt_entry_size
= 16;
307 // The first entry in the PLT for an executable.
308 static unsigned char exec_first_plt_entry
[plt_entry_size
];
310 // The first entry in the PLT for a shared object.
311 static unsigned char dyn_first_plt_entry
[plt_entry_size
];
313 // Other entries in the PLT for an executable.
314 static unsigned char exec_plt_entry
[plt_entry_size
];
316 // Other entries in the PLT for a shared object.
317 static unsigned char dyn_plt_entry
[plt_entry_size
];
319 // Set the final size.
321 do_set_address(uint64_t, off_t
)
322 { this->set_data_size((this->count_
+ 1) * plt_entry_size
); }
324 // Write out the PLT data.
326 do_write(Output_file
*);
328 // The reloc section.
330 // The .got.plt section.
331 Output_data_space
* got_plt_
;
332 // The number of PLT entries.
334 // Whether we are generated a shared object.
338 // Create the PLT section. The ordinary .got section is an argument,
339 // since we need to refer to the start. We also create our own .got
340 // section just for PLT entries.
342 Output_data_plt_i386::Output_data_plt_i386(Layout
* layout
,
343 Output_data_space
* got_plt
,
345 : Output_section_data(4), got_plt_(got_plt
), is_shared_(is_shared
)
347 this->rel_
= new Reloc_section();
348 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
349 elfcpp::SHF_ALLOC
, this->rel_
);
355 Output_data_plt_i386::do_adjust_output_section(Output_section
* os
)
357 // UnixWare sets the entsize of .plt to 4, and so does the old GNU
358 // linker, and so do we.
362 // Add an entry to the PLT.
365 Output_data_plt_i386::add_entry(Symbol
* gsym
)
367 gold_assert(!gsym
->has_plt_offset());
369 // Note that when setting the PLT offset we skip the initial
370 // reserved PLT entry.
371 gsym
->set_plt_offset((this->count_
+ 1) * plt_entry_size
);
375 off_t got_offset
= this->got_plt_
->data_size();
377 // Every PLT entry needs a GOT entry which points back to the PLT
378 // entry (this will be changed by the dynamic linker, normally
379 // lazily when the function is called).
380 this->got_plt_
->set_space_size(got_offset
+ 4);
382 // Every PLT entry needs a reloc.
383 gsym
->set_needs_dynsym_entry();
384 this->rel_
->add_global(gsym
, elfcpp::R_386_JUMP_SLOT
, this->got_plt_
,
387 // Note that we don't need to save the symbol. The contents of the
388 // PLT are independent of which symbols are used. The symbols only
389 // appear in the relocations.
392 // The first entry in the PLT for an executable.
394 unsigned char Output_data_plt_i386::exec_first_plt_entry
[plt_entry_size
] =
396 0xff, 0x35, // pushl contents of memory address
397 0, 0, 0, 0, // replaced with address of .got + 4
398 0xff, 0x25, // jmp indirect
399 0, 0, 0, 0, // replaced with address of .got + 8
403 // The first entry in the PLT for a shared object.
405 unsigned char Output_data_plt_i386::dyn_first_plt_entry
[plt_entry_size
] =
407 0xff, 0xb3, 4, 0, 0, 0, // pushl 4(%ebx)
408 0xff, 0xa3, 8, 0, 0, 0, // jmp *8(%ebx)
412 // Subsequent entries in the PLT for an executable.
414 unsigned char Output_data_plt_i386::exec_plt_entry
[plt_entry_size
] =
416 0xff, 0x25, // jmp indirect
417 0, 0, 0, 0, // replaced with address of symbol in .got
418 0x68, // pushl immediate
419 0, 0, 0, 0, // replaced with offset into relocation table
420 0xe9, // jmp relative
421 0, 0, 0, 0 // replaced with offset to start of .plt
424 // Subsequent entries in the PLT for a shared object.
426 unsigned char Output_data_plt_i386::dyn_plt_entry
[plt_entry_size
] =
428 0xff, 0xa3, // jmp *offset(%ebx)
429 0, 0, 0, 0, // replaced with offset of symbol in .got
430 0x68, // pushl immediate
431 0, 0, 0, 0, // replaced with offset into relocation table
432 0xe9, // jmp relative
433 0, 0, 0, 0 // replaced with offset to start of .plt
436 // Write out the PLT. This uses the hand-coded instructions above,
437 // and adjusts them as needed. This is all specified by the i386 ELF
438 // Processor Supplement.
441 Output_data_plt_i386::do_write(Output_file
* of
)
443 const off_t offset
= this->offset();
444 const off_t oview_size
= this->data_size();
445 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
447 const off_t got_file_offset
= this->got_plt_
->offset();
448 const off_t got_size
= this->got_plt_
->data_size();
449 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
452 unsigned char* pov
= oview
;
454 elfcpp::Elf_types
<32>::Elf_Addr plt_address
= this->address();
455 elfcpp::Elf_types
<32>::Elf_Addr got_address
= this->got_plt_
->address();
457 if (this->is_shared_
)
458 memcpy(pov
, dyn_first_plt_entry
, plt_entry_size
);
461 memcpy(pov
, exec_first_plt_entry
, plt_entry_size
);
462 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_address
+ 4);
463 elfcpp::Swap
<32, false>::writeval(pov
+ 8, got_address
+ 8);
465 pov
+= plt_entry_size
;
467 unsigned char* got_pov
= got_view
;
469 memset(got_pov
, 0, 12);
472 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
474 unsigned int plt_offset
= plt_entry_size
;
475 unsigned int plt_rel_offset
= 0;
476 unsigned int got_offset
= 12;
477 const unsigned int count
= this->count_
;
478 for (unsigned int i
= 0;
481 pov
+= plt_entry_size
,
483 plt_offset
+= plt_entry_size
,
484 plt_rel_offset
+= rel_size
,
487 // Set and adjust the PLT entry itself.
489 if (this->is_shared_
)
491 memcpy(pov
, dyn_plt_entry
, plt_entry_size
);
492 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_offset
);
496 memcpy(pov
, exec_plt_entry
, plt_entry_size
);
497 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
502 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 7, plt_rel_offset
);
503 elfcpp::Swap
<32, false>::writeval(pov
+ 12,
504 - (plt_offset
+ plt_entry_size
));
506 // Set the entry in the GOT.
507 elfcpp::Swap
<32, false>::writeval(got_pov
, plt_address
+ plt_offset
+ 6);
510 gold_assert(pov
- oview
== oview_size
);
511 gold_assert(got_pov
- got_view
== got_size
);
513 of
->write_output_view(offset
, oview_size
, oview
);
514 of
->write_output_view(got_file_offset
, got_size
, got_view
);
517 // Create a PLT entry for a global symbol.
520 Target_i386::make_plt_entry(const General_options
* options
,
521 Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
)
523 if (gsym
->has_plt_offset())
526 if (this->plt_
== NULL
)
528 // Create the GOT sections first.
529 this->got_section(options
, symtab
, layout
);
531 this->plt_
= new Output_data_plt_i386(layout
, this->got_plt_
,
532 options
->is_shared());
533 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
535 | elfcpp::SHF_EXECINSTR
),
539 this->plt_
->add_entry(gsym
);
542 // Handle a relocation against a non-function symbol defined in a
543 // dynamic object. The traditional way to handle this is to generate
544 // a COPY relocation to copy the variable at runtime from the shared
545 // object into the executable's data segment. However, this is
546 // undesirable in general, as if the size of the object changes in the
547 // dynamic object, the executable will no longer work correctly. If
548 // this relocation is in a writable section, then we can create a
549 // dynamic reloc and the dynamic linker will resolve it to the correct
550 // address at runtime. However, we do not want do that if the
551 // relocation is in a read-only section, as it would prevent the
552 // readonly segment from being shared. And if we have to eventually
553 // generate a COPY reloc, then any dynamic relocations will be
554 // useless. So this means that if this is a writable section, we need
555 // to save the relocation until we see whether we have to create a
556 // COPY relocation for this symbol for any other relocation.
559 Target_i386::copy_reloc(const General_options
* options
,
560 Symbol_table
* symtab
,
562 Sized_relobj
<32, false>* object
,
563 unsigned int data_shndx
, Symbol
* gsym
,
564 const elfcpp::Rel
<32, false>& rel
)
566 Sized_symbol
<32>* ssym
;
567 ssym
= symtab
->get_sized_symbol
SELECT_SIZE_NAME(32) (gsym
570 if (!Copy_relocs
<32, false>::need_copy_reloc(options
, object
,
573 // So far we do not need a COPY reloc. Save this relocation.
574 // If it turns out that we never need a COPY reloc for this
575 // symbol, then we will emit the relocation.
576 if (this->copy_relocs_
== NULL
)
577 this->copy_relocs_
= new Copy_relocs
<32, false>();
578 this->copy_relocs_
->save(ssym
, object
, data_shndx
, rel
);
582 // Allocate space for this symbol in the .bss section.
584 elfcpp::Elf_types
<32>::Elf_WXword symsize
= ssym
->symsize();
586 // There is no defined way to determine the required alignment
587 // of the symbol. We pick the alignment based on the size. We
588 // set an arbitrary maximum of 256.
590 for (align
= 1; align
< 512; align
<<= 1)
591 if ((symsize
& align
) != 0)
594 if (this->dynbss_
== NULL
)
596 this->dynbss_
= new Output_data_space(align
);
597 layout
->add_output_section_data(".bss",
600 | elfcpp::SHF_WRITE
),
604 Output_data_space
* dynbss
= this->dynbss_
;
606 if (align
> dynbss
->addralign())
607 dynbss
->set_space_alignment(align
);
609 off_t dynbss_size
= dynbss
->data_size();
610 dynbss_size
= align_address(dynbss_size
, align
);
611 off_t offset
= dynbss_size
;
612 dynbss
->set_space_size(dynbss_size
+ symsize
);
614 // Define the symbol in the .dynbss section.
615 symtab
->define_in_output_data(this, ssym
->name(), ssym
->version(),
616 dynbss
, offset
, symsize
, ssym
->type(),
617 ssym
->binding(), ssym
->visibility(),
618 ssym
->nonvis(), false, false);
620 // Add the COPY reloc.
621 ssym
->set_needs_dynsym_entry();
622 Reloc_section
* rel_dyn
= this->rel_dyn_section(layout
);
623 rel_dyn
->add_global(ssym
, elfcpp::R_386_COPY
, dynbss
, offset
);
627 // Optimize the TLS relocation type based on what we know about the
628 // symbol. IS_FINAL is true if the final address of this symbol is
629 // known at link time.
632 Target_i386::optimize_tls_reloc(const General_options
* options
,
636 // If we are generating a shared library, then we can't do anything
638 if (options
->is_shared())
643 case elfcpp::R_386_TLS_GD
:
644 case elfcpp::R_386_TLS_GOTDESC
:
645 case elfcpp::R_386_TLS_DESC_CALL
:
646 // These are Global-Dynamic which permits fully general TLS
647 // access. Since we know that we are generating an executable,
648 // we can convert this to Initial-Exec. If we also know that
649 // this is a local symbol, we can further switch to Local-Exec.
651 return elfcpp::R_386_TLS_LE_32
;
652 return elfcpp::R_386_TLS_IE_32
;
654 case elfcpp::R_386_TLS_LDM
:
655 // This is Local-Dynamic, which refers to a local symbol in the
656 // dynamic TLS block. Since we know that we generating an
657 // executable, we can switch to Local-Exec.
658 return elfcpp::R_386_TLS_LE_32
;
660 case elfcpp::R_386_TLS_LDO_32
:
661 // Another type of Local-Dynamic relocation.
662 return elfcpp::R_386_TLS_LE
;
664 case elfcpp::R_386_TLS_IE
:
665 case elfcpp::R_386_TLS_GOTIE
:
666 case elfcpp::R_386_TLS_IE_32
:
667 // These are Initial-Exec relocs which get the thread offset
668 // from the GOT. If we know that we are linking against the
669 // local symbol, we can switch to Local-Exec, which links the
670 // thread offset into the instruction.
672 return elfcpp::R_386_TLS_LE_32
;
675 case elfcpp::R_386_TLS_LE
:
676 case elfcpp::R_386_TLS_LE_32
:
677 // When we already have Local-Exec, there is nothing further we
686 // Scan a relocation for a local symbol.
689 Target_i386::Scan::local(const General_options
& options
,
690 Symbol_table
* symtab
,
693 Sized_relobj
<32, false>* object
,
695 const elfcpp::Rel
<32, false>&,
697 const elfcpp::Sym
<32, false>&)
701 case elfcpp::R_386_NONE
:
702 case elfcpp::R_386_GNU_VTINHERIT
:
703 case elfcpp::R_386_GNU_VTENTRY
:
706 case elfcpp::R_386_32
:
707 case elfcpp::R_386_16
:
708 case elfcpp::R_386_8
:
709 // FIXME: If we are generating a shared object we need to copy
710 // this relocation into the object.
711 gold_assert(!options
.is_shared());
714 case elfcpp::R_386_PC32
:
715 case elfcpp::R_386_PC16
:
716 case elfcpp::R_386_PC8
:
719 case elfcpp::R_386_GOTOFF
:
720 case elfcpp::R_386_GOTPC
:
721 // We need a GOT section.
722 target
->got_section(&options
, symtab
, layout
);
725 case elfcpp::R_386_COPY
:
726 case elfcpp::R_386_GLOB_DAT
:
727 case elfcpp::R_386_JUMP_SLOT
:
728 case elfcpp::R_386_RELATIVE
:
729 case elfcpp::R_386_TLS_TPOFF
:
730 case elfcpp::R_386_TLS_DTPMOD32
:
731 case elfcpp::R_386_TLS_DTPOFF32
:
732 case elfcpp::R_386_TLS_TPOFF32
:
733 case elfcpp::R_386_TLS_DESC
:
734 fprintf(stderr
, _("%s: %s: unexpected reloc %u in object file\n"),
735 program_name
, object
->name().c_str(), r_type
);
739 case elfcpp::R_386_TLS_IE
:
740 case elfcpp::R_386_TLS_GOTIE
:
741 case elfcpp::R_386_TLS_LE
:
742 case elfcpp::R_386_TLS_GD
:
743 case elfcpp::R_386_TLS_LDM
:
744 case elfcpp::R_386_TLS_LDO_32
:
745 case elfcpp::R_386_TLS_IE_32
:
746 case elfcpp::R_386_TLS_LE_32
:
747 case elfcpp::R_386_TLS_GOTDESC
:
748 case elfcpp::R_386_TLS_DESC_CALL
:
749 r_type
= Target_i386::optimize_tls_reloc(&options
,
750 !options
.is_shared(),
754 case elfcpp::R_386_TLS_LE
:
755 case elfcpp::R_386_TLS_LE_32
:
756 // FIXME: If generating a shared object, we need to copy
757 // this relocation into the object.
758 gold_assert(!options
.is_shared());
761 case elfcpp::R_386_TLS_IE
:
762 case elfcpp::R_386_TLS_GOTIE
:
763 case elfcpp::R_386_TLS_GD
:
764 case elfcpp::R_386_TLS_LDM
:
765 case elfcpp::R_386_TLS_LDO_32
:
766 case elfcpp::R_386_TLS_IE_32
:
767 case elfcpp::R_386_TLS_GOTDESC
:
768 case elfcpp::R_386_TLS_DESC_CALL
:
770 _("%s: %s: unsupported reloc %u against local symbol\n"),
771 program_name
, object
->name().c_str(), r_type
);
776 case elfcpp::R_386_GOT32
:
777 case elfcpp::R_386_PLT32
:
778 case elfcpp::R_386_32PLT
:
779 case elfcpp::R_386_TLS_GD_32
:
780 case elfcpp::R_386_TLS_GD_PUSH
:
781 case elfcpp::R_386_TLS_GD_CALL
:
782 case elfcpp::R_386_TLS_GD_POP
:
783 case elfcpp::R_386_TLS_LDM_32
:
784 case elfcpp::R_386_TLS_LDM_PUSH
:
785 case elfcpp::R_386_TLS_LDM_CALL
:
786 case elfcpp::R_386_TLS_LDM_POP
:
787 case elfcpp::R_386_USED_BY_INTEL_200
:
789 fprintf(stderr
, _("%s: %s: unsupported reloc %u against local symbol\n"),
790 program_name
, object
->name().c_str(), r_type
);
795 // Scan a relocation for a global symbol.
798 Target_i386::Scan::global(const General_options
& options
,
799 Symbol_table
* symtab
,
802 Sized_relobj
<32, false>* object
,
803 unsigned int data_shndx
,
804 const elfcpp::Rel
<32, false>& reloc
,
810 case elfcpp::R_386_NONE
:
811 case elfcpp::R_386_GNU_VTINHERIT
:
812 case elfcpp::R_386_GNU_VTENTRY
:
815 case elfcpp::R_386_32
:
816 case elfcpp::R_386_PC32
:
817 case elfcpp::R_386_16
:
818 case elfcpp::R_386_PC16
:
819 case elfcpp::R_386_8
:
820 case elfcpp::R_386_PC8
:
821 // FIXME: If we are generating a shared object we may need to
822 // copy this relocation into the object. If this symbol is
823 // defined in a shared object, we may need to copy this
824 // relocation in order to avoid a COPY relocation.
825 gold_assert(!options
.is_shared());
827 if (gsym
->is_from_dynobj())
829 // This symbol is defined in a dynamic object. If it is a
830 // function, we make a PLT entry. Otherwise we need to
831 // either generate a COPY reloc or copy this reloc.
832 if (gsym
->type() == elfcpp::STT_FUNC
)
833 target
->make_plt_entry(&options
, symtab
, layout
, gsym
);
835 target
->copy_reloc(&options
, symtab
, layout
, object
, data_shndx
,
841 case elfcpp::R_386_GOT32
:
843 // The symbol requires a GOT entry.
844 Output_data_got
<32, false>* got
= target
->got_section(&options
, symtab
,
846 if (got
->add_global(gsym
))
848 // If this symbol is not fully resolved, we need to add a
849 // dynamic relocation for it.
850 if (!gsym
->final_value_is_known(&options
))
852 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
853 rel_dyn
->add_global(gsym
, elfcpp::R_386_GLOB_DAT
, got
,
860 case elfcpp::R_386_PLT32
:
861 // If the symbol is fully resolved, this is just a PC32 reloc.
862 // Otherwise we need a PLT entry.
863 if (gsym
->final_value_is_known(&options
))
865 target
->make_plt_entry(&options
, symtab
, layout
, gsym
);
868 case elfcpp::R_386_GOTOFF
:
869 case elfcpp::R_386_GOTPC
:
870 // We need a GOT section.
871 target
->got_section(&options
, symtab
, layout
);
874 case elfcpp::R_386_COPY
:
875 case elfcpp::R_386_GLOB_DAT
:
876 case elfcpp::R_386_JUMP_SLOT
:
877 case elfcpp::R_386_RELATIVE
:
878 case elfcpp::R_386_TLS_TPOFF
:
879 case elfcpp::R_386_TLS_DTPMOD32
:
880 case elfcpp::R_386_TLS_DTPOFF32
:
881 case elfcpp::R_386_TLS_TPOFF32
:
882 case elfcpp::R_386_TLS_DESC
:
883 fprintf(stderr
, _("%s: %s: unexpected reloc %u in object file\n"),
884 program_name
, object
->name().c_str(), r_type
);
888 case elfcpp::R_386_TLS_IE
:
889 case elfcpp::R_386_TLS_GOTIE
:
890 case elfcpp::R_386_TLS_LE
:
891 case elfcpp::R_386_TLS_GD
:
892 case elfcpp::R_386_TLS_LDM
:
893 case elfcpp::R_386_TLS_LDO_32
:
894 case elfcpp::R_386_TLS_IE_32
:
895 case elfcpp::R_386_TLS_LE_32
:
896 case elfcpp::R_386_TLS_GOTDESC
:
897 case elfcpp::R_386_TLS_DESC_CALL
:
899 const bool is_final
= gsym
->final_value_is_known(&options
);
900 r_type
= Target_i386::optimize_tls_reloc(&options
, is_final
, r_type
);
903 case elfcpp::R_386_TLS_LE
:
904 case elfcpp::R_386_TLS_LE_32
:
905 // FIXME: If generating a shared object, we need to copy
906 // this relocation into the object.
907 gold_assert(!options
.is_shared());
910 case elfcpp::R_386_TLS_IE
:
911 case elfcpp::R_386_TLS_GOTIE
:
912 case elfcpp::R_386_TLS_GD
:
913 case elfcpp::R_386_TLS_LDM
:
914 case elfcpp::R_386_TLS_LDO_32
:
915 case elfcpp::R_386_TLS_IE_32
:
916 case elfcpp::R_386_TLS_GOTDESC
:
917 case elfcpp::R_386_TLS_DESC_CALL
:
919 _("%s: %s: unsupported reloc %u "
920 "against global symbol %s\n"),
921 program_name
, object
->name().c_str(), r_type
,
928 case elfcpp::R_386_32PLT
:
929 case elfcpp::R_386_TLS_GD_32
:
930 case elfcpp::R_386_TLS_GD_PUSH
:
931 case elfcpp::R_386_TLS_GD_CALL
:
932 case elfcpp::R_386_TLS_GD_POP
:
933 case elfcpp::R_386_TLS_LDM_32
:
934 case elfcpp::R_386_TLS_LDM_PUSH
:
935 case elfcpp::R_386_TLS_LDM_CALL
:
936 case elfcpp::R_386_TLS_LDM_POP
:
937 case elfcpp::R_386_USED_BY_INTEL_200
:
940 _("%s: %s: unsupported reloc %u against global symbol %s\n"),
941 program_name
, object
->name().c_str(), r_type
, gsym
->name());
946 // Scan relocations for a section.
949 Target_i386::scan_relocs(const General_options
& options
,
950 Symbol_table
* symtab
,
952 Sized_relobj
<32, false>* object
,
953 unsigned int data_shndx
,
954 unsigned int sh_type
,
955 const unsigned char* prelocs
,
957 size_t local_symbol_count
,
958 const unsigned char* plocal_symbols
,
959 Symbol
** global_symbols
)
961 if (sh_type
== elfcpp::SHT_RELA
)
963 fprintf(stderr
, _("%s: %s: unsupported RELA reloc section\n"),
964 program_name
, object
->name().c_str());
968 gold::scan_relocs
<32, false, Target_i386
, elfcpp::SHT_REL
,
983 // Finalize the sections.
986 Target_i386::do_finalize_sections(const General_options
* options
,
989 // Fill in some more dynamic tags.
990 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
993 if (this->got_plt_
!= NULL
)
994 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->got_plt_
);
996 if (this->plt_
!= NULL
)
998 const Output_data
* od
= this->plt_
->rel_plt();
999 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
1000 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
1001 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_REL
);
1004 if (this->rel_dyn_
!= NULL
)
1006 const Output_data
* od
= this->rel_dyn_
;
1007 odyn
->add_section_address(elfcpp::DT_REL
, od
);
1008 odyn
->add_section_size(elfcpp::DT_RELSZ
, od
);
1009 odyn
->add_constant(elfcpp::DT_RELENT
,
1010 elfcpp::Elf_sizes
<32>::rel_size
);
1013 if (!options
->is_shared())
1015 // The value of the DT_DEBUG tag is filled in by the dynamic
1016 // linker at run time, and used by the debugger.
1017 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
1021 // Emit any relocs we saved in an attempt to avoid generating COPY
1023 if (this->copy_relocs_
== NULL
)
1025 if (this->copy_relocs_
->any_to_emit())
1027 Reloc_section
* rel_dyn
= this->rel_dyn_section(layout
);
1028 this->copy_relocs_
->emit(rel_dyn
);
1030 delete this->copy_relocs_
;
1031 this->copy_relocs_
= NULL
;
1034 // Perform a relocation.
1037 Target_i386::Relocate::relocate(const Relocate_info
<32, false>* relinfo
,
1038 Target_i386
* target
,
1040 const elfcpp::Rel
<32, false>& rel
,
1041 unsigned int r_type
,
1042 const Sized_symbol
<32>* gsym
,
1043 const Symbol_value
<32>* psymval
,
1044 unsigned char* view
,
1045 elfcpp::Elf_types
<32>::Elf_Addr address
,
1048 if (this->skip_call_tls_get_addr_
)
1050 if (r_type
!= elfcpp::R_386_PLT32
1052 || strcmp(gsym
->name(), "___tls_get_addr") != 0)
1054 fprintf(stderr
, _("%s: %s: missing expected TLS relocation\n"),
1056 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1060 this->skip_call_tls_get_addr_
= false;
1065 // Pick the value to use for symbols defined in shared objects.
1066 Symbol_value
<32> symval
;
1067 if (gsym
!= NULL
&& gsym
->is_from_dynobj() && gsym
->has_plt_offset())
1069 symval
.set_output_value(target
->plt_section()->address()
1070 + gsym
->plt_offset());
1074 const Sized_relobj
<32, false>* object
= relinfo
->object
;
1078 case elfcpp::R_386_NONE
:
1079 case elfcpp::R_386_GNU_VTINHERIT
:
1080 case elfcpp::R_386_GNU_VTENTRY
:
1083 case elfcpp::R_386_32
:
1084 Relocate_functions
<32, false>::rel32(view
, object
, psymval
);
1087 case elfcpp::R_386_PC32
:
1088 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1091 case elfcpp::R_386_16
:
1092 Relocate_functions
<32, false>::rel16(view
, object
, psymval
);
1095 case elfcpp::R_386_PC16
:
1096 Relocate_functions
<32, false>::pcrel16(view
, object
, psymval
, address
);
1099 case elfcpp::R_386_8
:
1100 Relocate_functions
<32, false>::rel8(view
, object
, psymval
);
1103 case elfcpp::R_386_PC8
:
1104 Relocate_functions
<32, false>::pcrel8(view
, object
, psymval
, address
);
1107 case elfcpp::R_386_PLT32
:
1108 gold_assert(gsym
->has_plt_offset()
1109 || gsym
->final_value_is_known(relinfo
->options
));
1110 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1113 case elfcpp::R_386_GOT32
:
1114 // Local GOT offsets not yet supported.
1116 gold_assert(gsym
->has_got_offset());
1117 Relocate_functions
<32, false>::rel32(view
, gsym
->got_offset());
1120 case elfcpp::R_386_GOTOFF
:
1122 elfcpp::Elf_types
<32>::Elf_Addr value
;
1123 value
= (psymval
->value(object
, 0)
1124 - target
->got_section(NULL
, NULL
, NULL
)->address());
1125 Relocate_functions
<32, false>::rel32(view
, value
);
1129 case elfcpp::R_386_GOTPC
:
1131 elfcpp::Elf_types
<32>::Elf_Addr value
;
1132 value
= target
->got_section(NULL
, NULL
, NULL
)->address();
1133 Relocate_functions
<32, false>::pcrel32(view
, value
, address
);
1137 case elfcpp::R_386_COPY
:
1138 case elfcpp::R_386_GLOB_DAT
:
1139 case elfcpp::R_386_JUMP_SLOT
:
1140 case elfcpp::R_386_RELATIVE
:
1141 case elfcpp::R_386_TLS_TPOFF
:
1142 case elfcpp::R_386_TLS_DTPMOD32
:
1143 case elfcpp::R_386_TLS_DTPOFF32
:
1144 case elfcpp::R_386_TLS_TPOFF32
:
1145 case elfcpp::R_386_TLS_DESC
:
1146 fprintf(stderr
, _("%s: %s: unexpected reloc %u in object file\n"),
1148 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1153 case elfcpp::R_386_TLS_IE
:
1154 case elfcpp::R_386_TLS_GOTIE
:
1155 case elfcpp::R_386_TLS_LE
:
1156 case elfcpp::R_386_TLS_GD
:
1157 case elfcpp::R_386_TLS_LDM
:
1158 case elfcpp::R_386_TLS_LDO_32
:
1159 case elfcpp::R_386_TLS_IE_32
:
1160 case elfcpp::R_386_TLS_LE_32
:
1161 case elfcpp::R_386_TLS_GOTDESC
:
1162 case elfcpp::R_386_TLS_DESC_CALL
:
1163 this->relocate_tls(relinfo
, relnum
, rel
, r_type
, gsym
, psymval
, view
,
1164 address
, view_size
);
1167 case elfcpp::R_386_32PLT
:
1168 case elfcpp::R_386_TLS_GD_32
:
1169 case elfcpp::R_386_TLS_GD_PUSH
:
1170 case elfcpp::R_386_TLS_GD_CALL
:
1171 case elfcpp::R_386_TLS_GD_POP
:
1172 case elfcpp::R_386_TLS_LDM_32
:
1173 case elfcpp::R_386_TLS_LDM_PUSH
:
1174 case elfcpp::R_386_TLS_LDM_CALL
:
1175 case elfcpp::R_386_TLS_LDM_POP
:
1176 case elfcpp::R_386_USED_BY_INTEL_200
:
1178 fprintf(stderr
, _("%s: %s: unsupported reloc %u\n"),
1180 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1182 // gold_exit(false);
1189 // Perform a TLS relocation.
1192 Target_i386::Relocate::relocate_tls(const Relocate_info
<32, false>* relinfo
,
1194 const elfcpp::Rel
<32, false>& rel
,
1195 unsigned int r_type
,
1196 const Sized_symbol
<32>* gsym
,
1197 const Symbol_value
<32>* psymval
,
1198 unsigned char* view
,
1199 elfcpp::Elf_types
<32>::Elf_Addr
,
1202 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
1203 if (tls_segment
== NULL
)
1205 fprintf(stderr
, _("%s: %s: TLS reloc but no TLS segment\n"),
1207 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1211 elfcpp::Elf_types
<32>::Elf_Addr value
= psymval
->value(relinfo
->object
, 0);
1213 const bool is_final
= (gsym
== NULL
1214 ? !relinfo
->options
->is_shared()
1215 : gsym
->final_value_is_known(relinfo
->options
));
1216 const unsigned int opt_r_type
=
1217 Target_i386::optimize_tls_reloc(relinfo
->options
, is_final
, r_type
);
1220 case elfcpp::R_386_TLS_LE_32
:
1221 value
= tls_segment
->vaddr() + tls_segment
->memsz() - value
;
1222 Relocate_functions
<32, false>::rel32(view
, value
);
1225 case elfcpp::R_386_TLS_LE
:
1226 value
= value
- (tls_segment
->vaddr() + tls_segment
->memsz());
1227 Relocate_functions
<32, false>::rel32(view
, value
);
1230 case elfcpp::R_386_TLS_IE
:
1231 case elfcpp::R_386_TLS_GOTIE
:
1232 case elfcpp::R_386_TLS_IE_32
:
1233 if (opt_r_type
== elfcpp::R_386_TLS_LE_32
)
1235 Target_i386::Relocate::tls_ie_to_le(relinfo
, relnum
, tls_segment
,
1236 rel
, r_type
, value
, view
,
1240 fprintf(stderr
, _("%s: %s: unsupported reloc type %u\n"),
1242 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1244 // gold_exit(false);
1247 case elfcpp::R_386_TLS_GD
:
1248 if (opt_r_type
== elfcpp::R_386_TLS_LE_32
)
1250 this->tls_gd_to_le(relinfo
, relnum
, tls_segment
,
1251 rel
, r_type
, value
, view
,
1255 fprintf(stderr
, _("%s: %s: unsupported reloc %u\n"),
1257 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1259 // gold_exit(false);
1262 case elfcpp::R_386_TLS_LDM
:
1263 case elfcpp::R_386_TLS_LDO_32
:
1264 case elfcpp::R_386_TLS_GOTDESC
:
1265 case elfcpp::R_386_TLS_DESC_CALL
:
1266 fprintf(stderr
, _("%s: %s: unsupported reloc %u\n"),
1268 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1270 // gold_exit(false);
1275 // Do a relocation in which we convert a TLS Initial-Exec to a
1279 Target_i386::Relocate::tls_ie_to_le(const Relocate_info
<32, false>* relinfo
,
1281 Output_segment
* tls_segment
,
1282 const elfcpp::Rel
<32, false>& rel
,
1283 unsigned int r_type
,
1284 elfcpp::Elf_types
<32>::Elf_Addr value
,
1285 unsigned char* view
,
1288 // We have to actually change the instructions, which means that we
1289 // need to examine the opcodes to figure out which instruction we
1291 if (r_type
== elfcpp::R_386_TLS_IE
)
1293 // movl %gs:XX,%eax ==> movl $YY,%eax
1294 // movl %gs:XX,%reg ==> movl $YY,%reg
1295 // addl %gs:XX,%reg ==> addl $YY,%reg
1296 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -1);
1297 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, 4);
1299 unsigned char op1
= view
[-1];
1302 // movl XX,%eax ==> movl $YY,%eax
1307 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
,
1310 unsigned char op2
= view
[-2];
1313 // movl XX,%reg ==> movl $YY,%reg
1314 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1315 (op1
& 0xc7) == 0x05);
1317 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1319 else if (op2
== 0x03)
1321 // addl XX,%reg ==> addl $YY,%reg
1322 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1323 (op1
& 0xc7) == 0x05);
1325 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1328 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
, 0);
1333 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
1334 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
1335 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
1336 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -2);
1337 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, 4);
1339 unsigned char op1
= view
[-1];
1340 unsigned char op2
= view
[-2];
1341 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1342 (op1
& 0xc0) == 0x80 && (op1
& 7) != 4);
1345 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
1347 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1349 else if (op2
== 0x2b)
1351 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
1353 view
[-1] = 0xe8 | ((op1
>> 3) & 7);
1355 else if (op2
== 0x03)
1357 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
1359 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1362 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
, 0);
1365 value
= tls_segment
->vaddr() + tls_segment
->memsz() - value
;
1366 if (r_type
== elfcpp::R_386_TLS_IE
|| r_type
== elfcpp::R_386_TLS_GOTIE
)
1369 Relocate_functions
<32, false>::rel32(view
, value
);
1372 // Do a relocation in which we convert a TLS Global-Dynamic to a
1376 Target_i386::Relocate::tls_gd_to_le(const Relocate_info
<32, false>* relinfo
,
1378 Output_segment
* tls_segment
,
1379 const elfcpp::Rel
<32, false>& rel
,
1381 elfcpp::Elf_types
<32>::Elf_Addr value
,
1382 unsigned char* view
,
1385 // leal foo(,%reg,1),%eax; call ___tls_get_addr
1386 // ==> movl %gs,0,%eax; subl $foo@tpoff,%eax
1387 // leal foo(%reg),%eax; call ___tls_get_addr
1388 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
1390 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -2);
1391 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, 9);
1393 unsigned char op1
= view
[-1];
1394 unsigned char op2
= view
[-2];
1396 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1397 op2
== 0x8d || op2
== 0x04);
1398 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1405 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -3);
1406 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1408 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1409 ((op1
& 0xc7) == 0x05
1410 && op1
!= (4 << 3)));
1411 memcpy(view
- 3, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
1415 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1416 (op1
& 0xf8) == 0x80 && (op1
& 7) != 4);
1417 if (rel
.get_r_offset() + 9 < view_size
&& view
[9] == 0x90)
1419 // There is a trailing nop. Use the size byte subl.
1420 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
1425 // Use the five byte subl.
1426 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
1430 value
= tls_segment
->vaddr() + tls_segment
->memsz() - value
;
1431 Relocate_functions
<32, false>::rel32(view
+ roff
, value
);
1433 // The next reloc should be a PLT32 reloc against __tls_get_addr.
1435 this->skip_call_tls_get_addr_
= true;
1438 // Check the range for a TLS relocation.
1441 Target_i386::Relocate::check_range(const Relocate_info
<32, false>* relinfo
,
1443 const elfcpp::Rel
<32, false>& rel
,
1444 off_t view_size
, off_t off
)
1446 off_t offset
= rel
.get_r_offset() + off
;
1447 if (offset
< 0 || offset
> view_size
)
1449 fprintf(stderr
, _("%s: %s: TLS relocation out of range\n"),
1451 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1456 // Check the validity of a TLS relocation. This is like assert.
1459 Target_i386::Relocate::check_tls(const Relocate_info
<32, false>* relinfo
,
1461 const elfcpp::Rel
<32, false>& rel
,
1467 _("%s: %s: TLS relocation against invalid instruction\n"),
1469 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1474 // Relocate section data.
1477 Target_i386::relocate_section(const Relocate_info
<32, false>* relinfo
,
1478 unsigned int sh_type
,
1479 const unsigned char* prelocs
,
1481 unsigned char* view
,
1482 elfcpp::Elf_types
<32>::Elf_Addr address
,
1485 gold_assert(sh_type
== elfcpp::SHT_REL
);
1487 gold::relocate_section
<32, false, Target_i386
, elfcpp::SHT_REL
,
1488 Target_i386::Relocate
>(
1498 // Return a string used to fill a code section with nops to take up
1499 // the specified length.
1502 Target_i386::do_code_fill(off_t length
)
1506 // Build a jmp instruction to skip over the bytes.
1507 unsigned char jmp
[5];
1509 elfcpp::Swap_unaligned
<32, false>::writeval(jmp
+ 1, length
- 5);
1510 return (std::string(reinterpret_cast<char*>(&jmp
[0]), 5)
1511 + std::string(length
- 5, '\0'));
1514 // Nop sequences of various lengths.
1515 const char nop1
[1] = { 0x90 }; // nop
1516 const char nop2
[2] = { 0x66, 0x90 }; // xchg %ax %ax
1517 const char nop3
[3] = { 0x8d, 0x76, 0x00 }; // leal 0(%esi),%esi
1518 const char nop4
[4] = { 0x8d, 0x74, 0x26, 0x00}; // leal 0(%esi,1),%esi
1519 const char nop5
[5] = { 0x90, 0x8d, 0x74, 0x26, // nop
1520 0x00 }; // leal 0(%esi,1),%esi
1521 const char nop6
[6] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
1523 const char nop7
[7] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
1525 const char nop8
[8] = { 0x90, 0x8d, 0xb4, 0x26, // nop
1526 0x00, 0x00, 0x00, 0x00 }; // leal 0L(%esi,1),%esi
1527 const char nop9
[9] = { 0x89, 0xf6, 0x8d, 0xbc, // movl %esi,%esi
1528 0x27, 0x00, 0x00, 0x00, // leal 0L(%edi,1),%edi
1530 const char nop10
[10] = { 0x8d, 0x76, 0x00, 0x8d, // leal 0(%esi),%esi
1531 0xbc, 0x27, 0x00, 0x00, // leal 0L(%edi,1),%edi
1533 const char nop11
[11] = { 0x8d, 0x74, 0x26, 0x00, // leal 0(%esi,1),%esi
1534 0x8d, 0xbc, 0x27, 0x00, // leal 0L(%edi,1),%edi
1536 const char nop12
[12] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
1537 0x00, 0x00, 0x8d, 0xbf, // leal 0L(%edi),%edi
1538 0x00, 0x00, 0x00, 0x00 };
1539 const char nop13
[13] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
1540 0x00, 0x00, 0x8d, 0xbc, // leal 0L(%edi,1),%edi
1541 0x27, 0x00, 0x00, 0x00,
1543 const char nop14
[14] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
1544 0x00, 0x00, 0x00, 0x8d, // leal 0L(%edi,1),%edi
1545 0xbc, 0x27, 0x00, 0x00,
1547 const char nop15
[15] = { 0xeb, 0x0d, 0x90, 0x90, // jmp .+15
1548 0x90, 0x90, 0x90, 0x90, // nop,nop,nop,...
1549 0x90, 0x90, 0x90, 0x90,
1552 const char* nops
[16] = {
1554 nop1
, nop2
, nop3
, nop4
, nop5
, nop6
, nop7
,
1555 nop8
, nop9
, nop10
, nop11
, nop12
, nop13
, nop14
, nop15
1558 return std::string(nops
[length
], length
);
1561 // The selector for i386 object files.
1563 class Target_selector_i386
: public Target_selector
1566 Target_selector_i386()
1567 : Target_selector(elfcpp::EM_386
, 32, false)
1571 recognize(int machine
, int osabi
, int abiversion
);
1574 Target_i386
* target_
;
1577 // Recognize an i386 object file when we already know that the machine
1578 // number is EM_386.
1581 Target_selector_i386::recognize(int, int, int)
1583 if (this->target_
== NULL
)
1584 this->target_
= new Target_i386();
1585 return this->target_
;
1588 Target_selector_i386 target_selector_i386
;
1590 } // End anonymous namespace.