1 // i386.cc -- i386 target support for gold.
8 #include "parameters.h"
16 #include "target-reloc.h"
17 #include "target-select.h"
24 class Output_data_plt_i386
;
26 // The i386 target class.
28 class Target_i386
: public Sized_target
<32, false>
31 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false> Reloc_section
;
34 : Sized_target
<32, false>(&i386_info
),
35 got_(NULL
), plt_(NULL
), got_plt_(NULL
), rel_dyn_(NULL
),
36 copy_relocs_(NULL
), dynbss_(NULL
)
39 // Scan the relocations to look for symbol adjustments.
41 scan_relocs(const General_options
& options
,
44 Sized_relobj
<32, false>* object
,
45 unsigned int data_shndx
,
47 const unsigned char* prelocs
,
49 size_t local_symbol_count
,
50 const unsigned char* plocal_symbols
,
51 Symbol
** global_symbols
);
53 // Finalize the sections.
55 do_finalize_sections(Layout
*);
57 // Relocate a section.
59 relocate_section(const Relocate_info
<32, false>*,
61 const unsigned char* prelocs
,
64 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
67 // Return a string used to fill a code section with nops.
69 do_code_fill(off_t length
);
72 // The class which scans relocations.
76 local(const General_options
& options
, Symbol_table
* symtab
,
77 Layout
* layout
, Target_i386
* target
,
78 Sized_relobj
<32, false>* object
,
79 unsigned int data_shndx
,
80 const elfcpp::Rel
<32, false>& reloc
, unsigned int r_type
,
81 const elfcpp::Sym
<32, false>& lsym
);
84 global(const General_options
& options
, Symbol_table
* symtab
,
85 Layout
* layout
, Target_i386
* target
,
86 Sized_relobj
<32, false>* object
,
87 unsigned int data_shndx
,
88 const elfcpp::Rel
<32, false>& reloc
, unsigned int r_type
,
92 // The class which implements relocation.
97 : skip_call_tls_get_addr_(false)
102 if (this->skip_call_tls_get_addr_
)
104 // FIXME: This needs to specify the location somehow.
105 fprintf(stderr
, _("%s: missing expected TLS relocation\n"),
111 // Do a relocation. Return false if the caller should not issue
112 // any warnings about this relocation.
114 relocate(const Relocate_info
<32, false>*, Target_i386
*, size_t relnum
,
115 const elfcpp::Rel
<32, false>&,
116 unsigned int r_type
, const Sized_symbol
<32>*,
117 const Symbol_value
<32>*,
118 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
,
122 // Do a TLS relocation.
124 relocate_tls(const Relocate_info
<32, false>*, size_t relnum
,
125 const elfcpp::Rel
<32, false>&,
126 unsigned int r_type
, const Sized_symbol
<32>*,
127 const Symbol_value
<32>*,
128 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
, off_t
);
130 // Do a TLS Initial-Exec to Local-Exec transition.
132 tls_ie_to_le(const Relocate_info
<32, false>*, size_t relnum
,
133 Output_segment
* tls_segment
,
134 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
135 elfcpp::Elf_types
<32>::Elf_Addr value
,
139 // Do a TLS Global-Dynamic to Local-Exec transition.
141 tls_gd_to_le(const Relocate_info
<32, false>*, size_t relnum
,
142 Output_segment
* tls_segment
,
143 const elfcpp::Rel
<32, false>&, unsigned int r_type
,
144 elfcpp::Elf_types
<32>::Elf_Addr value
,
148 // Check the range for a TLS relocation.
150 check_range(const Relocate_info
<32, false>*, size_t relnum
,
151 const elfcpp::Rel
<32, false>&, off_t
, off_t
);
153 // Check the validity of a TLS relocation. This is like assert.
155 check_tls(const Relocate_info
<32, false>*, size_t relnum
,
156 const elfcpp::Rel
<32, false>&, bool);
158 // This is set if we should skip the next reloc, which should be a
159 // PLT32 reloc against ___tls_get_addr.
160 bool skip_call_tls_get_addr_
;
163 // Adjust TLS relocation type based on the options and whether this
164 // is a local symbol.
166 optimize_tls_reloc(bool is_final
, int r_type
);
168 // Get the GOT section, creating it if necessary.
169 Output_data_got
<32, false>*
170 got_section(Symbol_table
*, Layout
*);
172 // Create a PLT entry for a global symbol.
174 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
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(Symbol_table
* symtab
, Layout
* layout
)
231 if (this->got_
== NULL
)
233 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
235 this->got_
= new Output_data_got
<32, false>();
237 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
238 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
241 // The old GNU linker creates a .got.plt section. We just
242 // create another set of data in the .got section. Note that we
243 // always create a PLT if we create a GOT, although the PLT
245 this->got_plt_
= new Output_data_space(4);
246 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
247 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
250 // The first three entries are reserved.
251 this->got_plt_
->set_space_size(3 * 4);
253 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
254 symtab
->define_in_output_data(this, "_GLOBAL_OFFSET_TABLE_", NULL
,
256 0, 0, elfcpp::STT_OBJECT
,
258 elfcpp::STV_HIDDEN
, 0,
265 // Get the dynamic reloc section, creating it if necessary.
267 Target_i386::Reloc_section
*
268 Target_i386::rel_dyn_section(Layout
* layout
)
270 if (this->rel_dyn_
== NULL
)
272 gold_assert(layout
!= NULL
);
273 this->rel_dyn_
= new Reloc_section();
274 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
275 elfcpp::SHF_ALLOC
, this->rel_dyn_
);
277 return this->rel_dyn_
;
280 // A class to handle the PLT data.
282 class Output_data_plt_i386
: public Output_section_data
285 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false> Reloc_section
;
287 Output_data_plt_i386(Layout
*, Output_data_space
*);
289 // Add an entry to the PLT.
291 add_entry(Symbol
* gsym
);
293 // Return the .rel.plt section data.
296 { return this->rel_
; }
300 do_adjust_output_section(Output_section
* os
);
303 // The size of an entry in the PLT.
304 static const int plt_entry_size
= 16;
306 // The first entry in the PLT for an executable.
307 static unsigned char exec_first_plt_entry
[plt_entry_size
];
309 // The first entry in the PLT for a shared object.
310 static unsigned char dyn_first_plt_entry
[plt_entry_size
];
312 // Other entries in the PLT for an executable.
313 static unsigned char exec_plt_entry
[plt_entry_size
];
315 // Other entries in the PLT for a shared object.
316 static unsigned char dyn_plt_entry
[plt_entry_size
];
318 // Set the final size.
320 do_set_address(uint64_t, off_t
)
321 { this->set_data_size((this->count_
+ 1) * plt_entry_size
); }
323 // Write out the PLT data.
325 do_write(Output_file
*);
327 // The reloc section.
329 // The .got.plt section.
330 Output_data_space
* got_plt_
;
331 // The number of PLT entries.
335 // Create the PLT section. The ordinary .got section is an argument,
336 // since we need to refer to the start. We also create our own .got
337 // section just for PLT entries.
339 Output_data_plt_i386::Output_data_plt_i386(Layout
* layout
,
340 Output_data_space
* got_plt
)
341 : Output_section_data(4), got_plt_(got_plt
), count_(0)
343 this->rel_
= new Reloc_section();
344 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
345 elfcpp::SHF_ALLOC
, this->rel_
);
351 Output_data_plt_i386::do_adjust_output_section(Output_section
* os
)
353 // UnixWare sets the entsize of .plt to 4, and so does the old GNU
354 // linker, and so do we.
358 // Add an entry to the PLT.
361 Output_data_plt_i386::add_entry(Symbol
* gsym
)
363 gold_assert(!gsym
->has_plt_offset());
365 // Note that when setting the PLT offset we skip the initial
366 // reserved PLT entry.
367 gsym
->set_plt_offset((this->count_
+ 1) * plt_entry_size
);
371 off_t got_offset
= this->got_plt_
->data_size();
373 // Every PLT entry needs a GOT entry which points back to the PLT
374 // entry (this will be changed by the dynamic linker, normally
375 // lazily when the function is called).
376 this->got_plt_
->set_space_size(got_offset
+ 4);
378 // Every PLT entry needs a reloc.
379 gsym
->set_needs_dynsym_entry();
380 this->rel_
->add_global(gsym
, elfcpp::R_386_JUMP_SLOT
, this->got_plt_
,
383 // Note that we don't need to save the symbol. The contents of the
384 // PLT are independent of which symbols are used. The symbols only
385 // appear in the relocations.
388 // The first entry in the PLT for an executable.
390 unsigned char Output_data_plt_i386::exec_first_plt_entry
[plt_entry_size
] =
392 0xff, 0x35, // pushl contents of memory address
393 0, 0, 0, 0, // replaced with address of .got + 4
394 0xff, 0x25, // jmp indirect
395 0, 0, 0, 0, // replaced with address of .got + 8
399 // The first entry in the PLT for a shared object.
401 unsigned char Output_data_plt_i386::dyn_first_plt_entry
[plt_entry_size
] =
403 0xff, 0xb3, 4, 0, 0, 0, // pushl 4(%ebx)
404 0xff, 0xa3, 8, 0, 0, 0, // jmp *8(%ebx)
408 // Subsequent entries in the PLT for an executable.
410 unsigned char Output_data_plt_i386::exec_plt_entry
[plt_entry_size
] =
412 0xff, 0x25, // jmp indirect
413 0, 0, 0, 0, // replaced with address of symbol in .got
414 0x68, // pushl immediate
415 0, 0, 0, 0, // replaced with offset into relocation table
416 0xe9, // jmp relative
417 0, 0, 0, 0 // replaced with offset to start of .plt
420 // Subsequent entries in the PLT for a shared object.
422 unsigned char Output_data_plt_i386::dyn_plt_entry
[plt_entry_size
] =
424 0xff, 0xa3, // jmp *offset(%ebx)
425 0, 0, 0, 0, // replaced with offset of symbol in .got
426 0x68, // pushl immediate
427 0, 0, 0, 0, // replaced with offset into relocation table
428 0xe9, // jmp relative
429 0, 0, 0, 0 // replaced with offset to start of .plt
432 // Write out the PLT. This uses the hand-coded instructions above,
433 // and adjusts them as needed. This is all specified by the i386 ELF
434 // Processor Supplement.
437 Output_data_plt_i386::do_write(Output_file
* of
)
439 const off_t offset
= this->offset();
440 const off_t oview_size
= this->data_size();
441 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
443 const off_t got_file_offset
= this->got_plt_
->offset();
444 const off_t got_size
= this->got_plt_
->data_size();
445 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
448 unsigned char* pov
= oview
;
450 elfcpp::Elf_types
<32>::Elf_Addr plt_address
= this->address();
451 elfcpp::Elf_types
<32>::Elf_Addr got_address
= this->got_plt_
->address();
453 if (parameters
->output_is_shared())
454 memcpy(pov
, dyn_first_plt_entry
, plt_entry_size
);
457 memcpy(pov
, exec_first_plt_entry
, plt_entry_size
);
458 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_address
+ 4);
459 elfcpp::Swap
<32, false>::writeval(pov
+ 8, got_address
+ 8);
461 pov
+= plt_entry_size
;
463 unsigned char* got_pov
= got_view
;
465 memset(got_pov
, 0, 12);
468 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
470 unsigned int plt_offset
= plt_entry_size
;
471 unsigned int plt_rel_offset
= 0;
472 unsigned int got_offset
= 12;
473 const unsigned int count
= this->count_
;
474 for (unsigned int i
= 0;
477 pov
+= plt_entry_size
,
479 plt_offset
+= plt_entry_size
,
480 plt_rel_offset
+= rel_size
,
483 // Set and adjust the PLT entry itself.
485 if (parameters
->output_is_shared())
487 memcpy(pov
, dyn_plt_entry
, plt_entry_size
);
488 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2, got_offset
);
492 memcpy(pov
, exec_plt_entry
, plt_entry_size
);
493 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
498 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 7, plt_rel_offset
);
499 elfcpp::Swap
<32, false>::writeval(pov
+ 12,
500 - (plt_offset
+ plt_entry_size
));
502 // Set the entry in the GOT.
503 elfcpp::Swap
<32, false>::writeval(got_pov
, plt_address
+ plt_offset
+ 6);
506 gold_assert(pov
- oview
== oview_size
);
507 gold_assert(got_pov
- got_view
== got_size
);
509 of
->write_output_view(offset
, oview_size
, oview
);
510 of
->write_output_view(got_file_offset
, got_size
, got_view
);
513 // Create a PLT entry for a global symbol.
516 Target_i386::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
)
518 if (gsym
->has_plt_offset())
521 if (this->plt_
== NULL
)
523 // Create the GOT sections first.
524 this->got_section(symtab
, layout
);
526 this->plt_
= new Output_data_plt_i386(layout
, this->got_plt_
);
527 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
529 | elfcpp::SHF_EXECINSTR
),
533 this->plt_
->add_entry(gsym
);
536 // Handle a relocation against a non-function symbol defined in a
537 // dynamic object. The traditional way to handle this is to generate
538 // a COPY relocation to copy the variable at runtime from the shared
539 // object into the executable's data segment. However, this is
540 // undesirable in general, as if the size of the object changes in the
541 // dynamic object, the executable will no longer work correctly. If
542 // this relocation is in a writable section, then we can create a
543 // dynamic reloc and the dynamic linker will resolve it to the correct
544 // address at runtime. However, we do not want do that if the
545 // relocation is in a read-only section, as it would prevent the
546 // readonly segment from being shared. And if we have to eventually
547 // generate a COPY reloc, then any dynamic relocations will be
548 // useless. So this means that if this is a writable section, we need
549 // to save the relocation until we see whether we have to create a
550 // COPY relocation for this symbol for any other relocation.
553 Target_i386::copy_reloc(const General_options
* options
,
554 Symbol_table
* symtab
,
556 Sized_relobj
<32, false>* object
,
557 unsigned int data_shndx
, Symbol
* gsym
,
558 const elfcpp::Rel
<32, false>& rel
)
560 Sized_symbol
<32>* ssym
;
561 ssym
= symtab
->get_sized_symbol
SELECT_SIZE_NAME(32) (gsym
564 if (!Copy_relocs
<32, false>::need_copy_reloc(options
, object
,
567 // So far we do not need a COPY reloc. Save this relocation.
568 // If it turns out that we never need a COPY reloc for this
569 // symbol, then we will emit the relocation.
570 if (this->copy_relocs_
== NULL
)
571 this->copy_relocs_
= new Copy_relocs
<32, false>();
572 this->copy_relocs_
->save(ssym
, object
, data_shndx
, rel
);
576 // Allocate space for this symbol in the .bss section.
578 elfcpp::Elf_types
<32>::Elf_WXword symsize
= ssym
->symsize();
580 // There is no defined way to determine the required alignment
581 // of the symbol. We pick the alignment based on the size. We
582 // set an arbitrary maximum of 256.
584 for (align
= 1; align
< 512; align
<<= 1)
585 if ((symsize
& align
) != 0)
588 if (this->dynbss_
== NULL
)
590 this->dynbss_
= new Output_data_space(align
);
591 layout
->add_output_section_data(".bss",
594 | elfcpp::SHF_WRITE
),
598 Output_data_space
* dynbss
= this->dynbss_
;
600 if (align
> dynbss
->addralign())
601 dynbss
->set_space_alignment(align
);
603 off_t dynbss_size
= dynbss
->data_size();
604 dynbss_size
= align_address(dynbss_size
, align
);
605 off_t offset
= dynbss_size
;
606 dynbss
->set_space_size(dynbss_size
+ symsize
);
608 // Define the symbol in the .dynbss section.
609 symtab
->define_in_output_data(this, ssym
->name(), ssym
->version(),
610 dynbss
, offset
, symsize
, ssym
->type(),
611 ssym
->binding(), ssym
->visibility(),
612 ssym
->nonvis(), false, false);
614 // Add the COPY reloc.
615 ssym
->set_needs_dynsym_entry();
616 Reloc_section
* rel_dyn
= this->rel_dyn_section(layout
);
617 rel_dyn
->add_global(ssym
, elfcpp::R_386_COPY
, dynbss
, offset
);
621 // Optimize the TLS relocation type based on what we know about the
622 // symbol. IS_FINAL is true if the final address of this symbol is
623 // known at link time.
626 Target_i386::optimize_tls_reloc(bool is_final
, int r_type
)
628 // If we are generating a shared library, then we can't do anything
630 if (parameters
->output_is_shared())
635 case elfcpp::R_386_TLS_GD
:
636 case elfcpp::R_386_TLS_GOTDESC
:
637 case elfcpp::R_386_TLS_DESC_CALL
:
638 // These are Global-Dynamic which permits fully general TLS
639 // access. Since we know that we are generating an executable,
640 // we can convert this to Initial-Exec. If we also know that
641 // this is a local symbol, we can further switch to Local-Exec.
643 return elfcpp::R_386_TLS_LE_32
;
644 return elfcpp::R_386_TLS_IE_32
;
646 case elfcpp::R_386_TLS_LDM
:
647 // This is Local-Dynamic, which refers to a local symbol in the
648 // dynamic TLS block. Since we know that we generating an
649 // executable, we can switch to Local-Exec.
650 return elfcpp::R_386_TLS_LE_32
;
652 case elfcpp::R_386_TLS_LDO_32
:
653 // Another type of Local-Dynamic relocation.
654 return elfcpp::R_386_TLS_LE
;
656 case elfcpp::R_386_TLS_IE
:
657 case elfcpp::R_386_TLS_GOTIE
:
658 case elfcpp::R_386_TLS_IE_32
:
659 // These are Initial-Exec relocs which get the thread offset
660 // from the GOT. If we know that we are linking against the
661 // local symbol, we can switch to Local-Exec, which links the
662 // thread offset into the instruction.
664 return elfcpp::R_386_TLS_LE_32
;
667 case elfcpp::R_386_TLS_LE
:
668 case elfcpp::R_386_TLS_LE_32
:
669 // When we already have Local-Exec, there is nothing further we
678 // Scan a relocation for a local symbol.
681 Target_i386::Scan::local(const General_options
&,
682 Symbol_table
* symtab
,
685 Sized_relobj
<32, false>* object
,
687 const elfcpp::Rel
<32, false>&,
689 const elfcpp::Sym
<32, false>&)
693 case elfcpp::R_386_NONE
:
694 case elfcpp::R_386_GNU_VTINHERIT
:
695 case elfcpp::R_386_GNU_VTENTRY
:
698 case elfcpp::R_386_32
:
699 case elfcpp::R_386_16
:
700 case elfcpp::R_386_8
:
701 // FIXME: If we are generating a shared object we need to copy
702 // this relocation into the object.
703 gold_assert(!parameters
->output_is_shared());
706 case elfcpp::R_386_PC32
:
707 case elfcpp::R_386_PC16
:
708 case elfcpp::R_386_PC8
:
711 case elfcpp::R_386_GOTOFF
:
712 case elfcpp::R_386_GOTPC
:
713 // We need a GOT section.
714 target
->got_section(symtab
, layout
);
717 case elfcpp::R_386_COPY
:
718 case elfcpp::R_386_GLOB_DAT
:
719 case elfcpp::R_386_JUMP_SLOT
:
720 case elfcpp::R_386_RELATIVE
:
721 case elfcpp::R_386_TLS_TPOFF
:
722 case elfcpp::R_386_TLS_DTPMOD32
:
723 case elfcpp::R_386_TLS_DTPOFF32
:
724 case elfcpp::R_386_TLS_TPOFF32
:
725 case elfcpp::R_386_TLS_DESC
:
726 fprintf(stderr
, _("%s: %s: unexpected reloc %u in object file\n"),
727 program_name
, object
->name().c_str(), r_type
);
731 case elfcpp::R_386_TLS_IE
:
732 case elfcpp::R_386_TLS_GOTIE
:
733 case elfcpp::R_386_TLS_LE
:
734 case elfcpp::R_386_TLS_GD
:
735 case elfcpp::R_386_TLS_LDM
:
736 case elfcpp::R_386_TLS_LDO_32
:
737 case elfcpp::R_386_TLS_IE_32
:
738 case elfcpp::R_386_TLS_LE_32
:
739 case elfcpp::R_386_TLS_GOTDESC
:
740 case elfcpp::R_386_TLS_DESC_CALL
:
742 bool output_is_shared
= parameters
->output_is_shared();
743 r_type
= Target_i386::optimize_tls_reloc(!output_is_shared
,
747 case elfcpp::R_386_TLS_LE
:
748 case elfcpp::R_386_TLS_LE_32
:
749 // FIXME: If generating a shared object, we need to copy
750 // this relocation into the object.
751 gold_assert(!output_is_shared
);
754 case elfcpp::R_386_TLS_IE
:
755 case elfcpp::R_386_TLS_GOTIE
:
756 case elfcpp::R_386_TLS_GD
:
757 case elfcpp::R_386_TLS_LDM
:
758 case elfcpp::R_386_TLS_LDO_32
:
759 case elfcpp::R_386_TLS_IE_32
:
760 case elfcpp::R_386_TLS_GOTDESC
:
761 case elfcpp::R_386_TLS_DESC_CALL
:
763 _("%s: %s: unsupported reloc %u against local symbol\n"),
764 program_name
, object
->name().c_str(), r_type
);
770 case elfcpp::R_386_GOT32
:
771 case elfcpp::R_386_PLT32
:
772 case elfcpp::R_386_32PLT
:
773 case elfcpp::R_386_TLS_GD_32
:
774 case elfcpp::R_386_TLS_GD_PUSH
:
775 case elfcpp::R_386_TLS_GD_CALL
:
776 case elfcpp::R_386_TLS_GD_POP
:
777 case elfcpp::R_386_TLS_LDM_32
:
778 case elfcpp::R_386_TLS_LDM_PUSH
:
779 case elfcpp::R_386_TLS_LDM_CALL
:
780 case elfcpp::R_386_TLS_LDM_POP
:
781 case elfcpp::R_386_USED_BY_INTEL_200
:
783 fprintf(stderr
, _("%s: %s: unsupported reloc %u against local symbol\n"),
784 program_name
, object
->name().c_str(), r_type
);
789 // Scan a relocation for a global symbol.
792 Target_i386::Scan::global(const General_options
& options
,
793 Symbol_table
* symtab
,
796 Sized_relobj
<32, false>* object
,
797 unsigned int data_shndx
,
798 const elfcpp::Rel
<32, false>& reloc
,
804 case elfcpp::R_386_NONE
:
805 case elfcpp::R_386_GNU_VTINHERIT
:
806 case elfcpp::R_386_GNU_VTENTRY
:
809 case elfcpp::R_386_32
:
810 case elfcpp::R_386_PC32
:
811 case elfcpp::R_386_16
:
812 case elfcpp::R_386_PC16
:
813 case elfcpp::R_386_8
:
814 case elfcpp::R_386_PC8
:
815 // FIXME: If we are generating a shared object we may need to
816 // copy this relocation into the object. If this symbol is
817 // defined in a shared object, we may need to copy this
818 // relocation in order to avoid a COPY relocation.
819 gold_assert(!parameters
->output_is_shared());
821 if (gsym
->is_from_dynobj())
823 // This symbol is defined in a dynamic object. If it is a
824 // function, we make a PLT entry. Otherwise we need to
825 // either generate a COPY reloc or copy this reloc.
826 if (gsym
->type() == elfcpp::STT_FUNC
)
827 target
->make_plt_entry(symtab
, layout
, gsym
);
829 target
->copy_reloc(&options
, symtab
, layout
, object
, data_shndx
,
835 case elfcpp::R_386_GOT32
:
837 // The symbol requires a GOT entry.
838 Output_data_got
<32, false>* got
= target
->got_section(symtab
, layout
);
839 if (got
->add_global(gsym
))
841 // If this symbol is not fully resolved, we need to add a
842 // dynamic relocation for it.
843 if (!gsym
->final_value_is_known())
845 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
846 rel_dyn
->add_global(gsym
, elfcpp::R_386_GLOB_DAT
, got
,
853 case elfcpp::R_386_PLT32
:
854 // If the symbol is fully resolved, this is just a PC32 reloc.
855 // Otherwise we need a PLT entry.
856 if (gsym
->final_value_is_known())
858 target
->make_plt_entry(symtab
, layout
, gsym
);
861 case elfcpp::R_386_GOTOFF
:
862 case elfcpp::R_386_GOTPC
:
863 // We need a GOT section.
864 target
->got_section(symtab
, layout
);
867 case elfcpp::R_386_COPY
:
868 case elfcpp::R_386_GLOB_DAT
:
869 case elfcpp::R_386_JUMP_SLOT
:
870 case elfcpp::R_386_RELATIVE
:
871 case elfcpp::R_386_TLS_TPOFF
:
872 case elfcpp::R_386_TLS_DTPMOD32
:
873 case elfcpp::R_386_TLS_DTPOFF32
:
874 case elfcpp::R_386_TLS_TPOFF32
:
875 case elfcpp::R_386_TLS_DESC
:
876 fprintf(stderr
, _("%s: %s: unexpected reloc %u in object file\n"),
877 program_name
, object
->name().c_str(), r_type
);
881 case elfcpp::R_386_TLS_IE
:
882 case elfcpp::R_386_TLS_GOTIE
:
883 case elfcpp::R_386_TLS_LE
:
884 case elfcpp::R_386_TLS_GD
:
885 case elfcpp::R_386_TLS_LDM
:
886 case elfcpp::R_386_TLS_LDO_32
:
887 case elfcpp::R_386_TLS_IE_32
:
888 case elfcpp::R_386_TLS_LE_32
:
889 case elfcpp::R_386_TLS_GOTDESC
:
890 case elfcpp::R_386_TLS_DESC_CALL
:
892 const bool is_final
= gsym
->final_value_is_known();
893 r_type
= Target_i386::optimize_tls_reloc(is_final
, r_type
);
896 case elfcpp::R_386_TLS_LE
:
897 case elfcpp::R_386_TLS_LE_32
:
898 // FIXME: If generating a shared object, we need to copy
899 // this relocation into the object.
900 gold_assert(!parameters
->output_is_shared());
903 case elfcpp::R_386_TLS_IE
:
904 case elfcpp::R_386_TLS_GOTIE
:
905 case elfcpp::R_386_TLS_GD
:
906 case elfcpp::R_386_TLS_LDM
:
907 case elfcpp::R_386_TLS_LDO_32
:
908 case elfcpp::R_386_TLS_IE_32
:
909 case elfcpp::R_386_TLS_GOTDESC
:
910 case elfcpp::R_386_TLS_DESC_CALL
:
912 _("%s: %s: unsupported reloc %u "
913 "against global symbol %s\n"),
914 program_name
, object
->name().c_str(), r_type
,
921 case elfcpp::R_386_32PLT
:
922 case elfcpp::R_386_TLS_GD_32
:
923 case elfcpp::R_386_TLS_GD_PUSH
:
924 case elfcpp::R_386_TLS_GD_CALL
:
925 case elfcpp::R_386_TLS_GD_POP
:
926 case elfcpp::R_386_TLS_LDM_32
:
927 case elfcpp::R_386_TLS_LDM_PUSH
:
928 case elfcpp::R_386_TLS_LDM_CALL
:
929 case elfcpp::R_386_TLS_LDM_POP
:
930 case elfcpp::R_386_USED_BY_INTEL_200
:
933 _("%s: %s: unsupported reloc %u against global symbol %s\n"),
934 program_name
, object
->name().c_str(), r_type
, gsym
->name());
939 // Scan relocations for a section.
942 Target_i386::scan_relocs(const General_options
& options
,
943 Symbol_table
* symtab
,
945 Sized_relobj
<32, false>* object
,
946 unsigned int data_shndx
,
947 unsigned int sh_type
,
948 const unsigned char* prelocs
,
950 size_t local_symbol_count
,
951 const unsigned char* plocal_symbols
,
952 Symbol
** global_symbols
)
954 if (sh_type
== elfcpp::SHT_RELA
)
956 fprintf(stderr
, _("%s: %s: unsupported RELA reloc section\n"),
957 program_name
, object
->name().c_str());
961 gold::scan_relocs
<32, false, Target_i386
, elfcpp::SHT_REL
,
976 // Finalize the sections.
979 Target_i386::do_finalize_sections(Layout
* layout
)
981 // Fill in some more dynamic tags.
982 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
985 if (this->got_plt_
!= NULL
)
986 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->got_plt_
);
988 if (this->plt_
!= NULL
)
990 const Output_data
* od
= this->plt_
->rel_plt();
991 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
992 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
993 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_REL
);
996 if (this->rel_dyn_
!= NULL
)
998 const Output_data
* od
= this->rel_dyn_
;
999 odyn
->add_section_address(elfcpp::DT_REL
, od
);
1000 odyn
->add_section_size(elfcpp::DT_RELSZ
, od
);
1001 odyn
->add_constant(elfcpp::DT_RELENT
,
1002 elfcpp::Elf_sizes
<32>::rel_size
);
1005 if (!parameters
->output_is_shared())
1007 // The value of the DT_DEBUG tag is filled in by the dynamic
1008 // linker at run time, and used by the debugger.
1009 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
1013 // Emit any relocs we saved in an attempt to avoid generating COPY
1015 if (this->copy_relocs_
== NULL
)
1017 if (this->copy_relocs_
->any_to_emit())
1019 Reloc_section
* rel_dyn
= this->rel_dyn_section(layout
);
1020 this->copy_relocs_
->emit(rel_dyn
);
1022 delete this->copy_relocs_
;
1023 this->copy_relocs_
= NULL
;
1026 // Perform a relocation.
1029 Target_i386::Relocate::relocate(const Relocate_info
<32, false>* relinfo
,
1030 Target_i386
* target
,
1032 const elfcpp::Rel
<32, false>& rel
,
1033 unsigned int r_type
,
1034 const Sized_symbol
<32>* gsym
,
1035 const Symbol_value
<32>* psymval
,
1036 unsigned char* view
,
1037 elfcpp::Elf_types
<32>::Elf_Addr address
,
1040 if (this->skip_call_tls_get_addr_
)
1042 if (r_type
!= elfcpp::R_386_PLT32
1044 || strcmp(gsym
->name(), "___tls_get_addr") != 0)
1046 fprintf(stderr
, _("%s: %s: missing expected TLS relocation\n"),
1048 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1052 this->skip_call_tls_get_addr_
= false;
1057 // Pick the value to use for symbols defined in shared objects.
1058 Symbol_value
<32> symval
;
1059 if (gsym
!= NULL
&& gsym
->is_from_dynobj() && gsym
->has_plt_offset())
1061 symval
.set_output_value(target
->plt_section()->address()
1062 + gsym
->plt_offset());
1066 const Sized_relobj
<32, false>* object
= relinfo
->object
;
1070 case elfcpp::R_386_NONE
:
1071 case elfcpp::R_386_GNU_VTINHERIT
:
1072 case elfcpp::R_386_GNU_VTENTRY
:
1075 case elfcpp::R_386_32
:
1076 Relocate_functions
<32, false>::rel32(view
, object
, psymval
);
1079 case elfcpp::R_386_PC32
:
1080 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1083 case elfcpp::R_386_16
:
1084 Relocate_functions
<32, false>::rel16(view
, object
, psymval
);
1087 case elfcpp::R_386_PC16
:
1088 Relocate_functions
<32, false>::pcrel16(view
, object
, psymval
, address
);
1091 case elfcpp::R_386_8
:
1092 Relocate_functions
<32, false>::rel8(view
, object
, psymval
);
1095 case elfcpp::R_386_PC8
:
1096 Relocate_functions
<32, false>::pcrel8(view
, object
, psymval
, address
);
1099 case elfcpp::R_386_PLT32
:
1100 gold_assert(gsym
->has_plt_offset()
1101 || gsym
->final_value_is_known());
1102 Relocate_functions
<32, false>::pcrel32(view
, object
, psymval
, address
);
1105 case elfcpp::R_386_GOT32
:
1106 // Local GOT offsets not yet supported.
1108 gold_assert(gsym
->has_got_offset());
1109 Relocate_functions
<32, false>::rel32(view
, gsym
->got_offset());
1112 case elfcpp::R_386_GOTOFF
:
1114 elfcpp::Elf_types
<32>::Elf_Addr value
;
1115 value
= (psymval
->value(object
, 0)
1116 - target
->got_section(NULL
, NULL
)->address());
1117 Relocate_functions
<32, false>::rel32(view
, value
);
1121 case elfcpp::R_386_GOTPC
:
1123 elfcpp::Elf_types
<32>::Elf_Addr value
;
1124 value
= target
->got_section(NULL
, NULL
)->address();
1125 Relocate_functions
<32, false>::pcrel32(view
, value
, address
);
1129 case elfcpp::R_386_COPY
:
1130 case elfcpp::R_386_GLOB_DAT
:
1131 case elfcpp::R_386_JUMP_SLOT
:
1132 case elfcpp::R_386_RELATIVE
:
1133 case elfcpp::R_386_TLS_TPOFF
:
1134 case elfcpp::R_386_TLS_DTPMOD32
:
1135 case elfcpp::R_386_TLS_DTPOFF32
:
1136 case elfcpp::R_386_TLS_TPOFF32
:
1137 case elfcpp::R_386_TLS_DESC
:
1138 fprintf(stderr
, _("%s: %s: unexpected reloc %u in object file\n"),
1140 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1145 case elfcpp::R_386_TLS_IE
:
1146 case elfcpp::R_386_TLS_GOTIE
:
1147 case elfcpp::R_386_TLS_LE
:
1148 case elfcpp::R_386_TLS_GD
:
1149 case elfcpp::R_386_TLS_LDM
:
1150 case elfcpp::R_386_TLS_LDO_32
:
1151 case elfcpp::R_386_TLS_IE_32
:
1152 case elfcpp::R_386_TLS_LE_32
:
1153 case elfcpp::R_386_TLS_GOTDESC
:
1154 case elfcpp::R_386_TLS_DESC_CALL
:
1155 this->relocate_tls(relinfo
, relnum
, rel
, r_type
, gsym
, psymval
, view
,
1156 address
, view_size
);
1159 case elfcpp::R_386_32PLT
:
1160 case elfcpp::R_386_TLS_GD_32
:
1161 case elfcpp::R_386_TLS_GD_PUSH
:
1162 case elfcpp::R_386_TLS_GD_CALL
:
1163 case elfcpp::R_386_TLS_GD_POP
:
1164 case elfcpp::R_386_TLS_LDM_32
:
1165 case elfcpp::R_386_TLS_LDM_PUSH
:
1166 case elfcpp::R_386_TLS_LDM_CALL
:
1167 case elfcpp::R_386_TLS_LDM_POP
:
1168 case elfcpp::R_386_USED_BY_INTEL_200
:
1170 fprintf(stderr
, _("%s: %s: unsupported reloc %u\n"),
1172 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1174 // gold_exit(false);
1181 // Perform a TLS relocation.
1184 Target_i386::Relocate::relocate_tls(const Relocate_info
<32, false>* relinfo
,
1186 const elfcpp::Rel
<32, false>& rel
,
1187 unsigned int r_type
,
1188 const Sized_symbol
<32>* gsym
,
1189 const Symbol_value
<32>* psymval
,
1190 unsigned char* view
,
1191 elfcpp::Elf_types
<32>::Elf_Addr
,
1194 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
1195 if (tls_segment
== NULL
)
1197 fprintf(stderr
, _("%s: %s: TLS reloc but no TLS segment\n"),
1199 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1203 elfcpp::Elf_types
<32>::Elf_Addr value
= psymval
->value(relinfo
->object
, 0);
1205 const bool is_final
= (gsym
== NULL
1206 ? !parameters
->output_is_shared()
1207 : gsym
->final_value_is_known());
1208 const unsigned int opt_r_type
=
1209 Target_i386::optimize_tls_reloc(is_final
, r_type
);
1212 case elfcpp::R_386_TLS_LE_32
:
1213 value
= tls_segment
->vaddr() + tls_segment
->memsz() - value
;
1214 Relocate_functions
<32, false>::rel32(view
, value
);
1217 case elfcpp::R_386_TLS_LE
:
1218 value
= value
- (tls_segment
->vaddr() + tls_segment
->memsz());
1219 Relocate_functions
<32, false>::rel32(view
, value
);
1222 case elfcpp::R_386_TLS_IE
:
1223 case elfcpp::R_386_TLS_GOTIE
:
1224 case elfcpp::R_386_TLS_IE_32
:
1225 if (opt_r_type
== elfcpp::R_386_TLS_LE_32
)
1227 Target_i386::Relocate::tls_ie_to_le(relinfo
, relnum
, tls_segment
,
1228 rel
, r_type
, value
, view
,
1232 fprintf(stderr
, _("%s: %s: unsupported reloc type %u\n"),
1234 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1236 // gold_exit(false);
1239 case elfcpp::R_386_TLS_GD
:
1240 if (opt_r_type
== elfcpp::R_386_TLS_LE_32
)
1242 this->tls_gd_to_le(relinfo
, relnum
, tls_segment
,
1243 rel
, r_type
, value
, view
,
1247 fprintf(stderr
, _("%s: %s: unsupported reloc %u\n"),
1249 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1251 // gold_exit(false);
1254 case elfcpp::R_386_TLS_LDM
:
1255 case elfcpp::R_386_TLS_LDO_32
:
1256 case elfcpp::R_386_TLS_GOTDESC
:
1257 case elfcpp::R_386_TLS_DESC_CALL
:
1258 fprintf(stderr
, _("%s: %s: unsupported reloc %u\n"),
1260 relinfo
->location(relnum
, rel
.get_r_offset()).c_str(),
1262 // gold_exit(false);
1267 // Do a relocation in which we convert a TLS Initial-Exec to a
1271 Target_i386::Relocate::tls_ie_to_le(const Relocate_info
<32, false>* relinfo
,
1273 Output_segment
* tls_segment
,
1274 const elfcpp::Rel
<32, false>& rel
,
1275 unsigned int r_type
,
1276 elfcpp::Elf_types
<32>::Elf_Addr value
,
1277 unsigned char* view
,
1280 // We have to actually change the instructions, which means that we
1281 // need to examine the opcodes to figure out which instruction we
1283 if (r_type
== elfcpp::R_386_TLS_IE
)
1285 // movl %gs:XX,%eax ==> movl $YY,%eax
1286 // movl %gs:XX,%reg ==> movl $YY,%reg
1287 // addl %gs:XX,%reg ==> addl $YY,%reg
1288 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -1);
1289 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, 4);
1291 unsigned char op1
= view
[-1];
1294 // movl XX,%eax ==> movl $YY,%eax
1299 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
,
1302 unsigned char op2
= view
[-2];
1305 // movl XX,%reg ==> movl $YY,%reg
1306 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1307 (op1
& 0xc7) == 0x05);
1309 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1311 else if (op2
== 0x03)
1313 // addl XX,%reg ==> addl $YY,%reg
1314 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1315 (op1
& 0xc7) == 0x05);
1317 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1320 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
, 0);
1325 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
1326 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
1327 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
1328 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -2);
1329 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, 4);
1331 unsigned char op1
= view
[-1];
1332 unsigned char op2
= view
[-2];
1333 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1334 (op1
& 0xc0) == 0x80 && (op1
& 7) != 4);
1337 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
1339 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1341 else if (op2
== 0x2b)
1343 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
1345 view
[-1] = 0xe8 | ((op1
>> 3) & 7);
1347 else if (op2
== 0x03)
1349 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
1351 view
[-1] = 0xc0 | ((op1
>> 3) & 7);
1354 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
, 0);
1357 value
= tls_segment
->vaddr() + tls_segment
->memsz() - value
;
1358 if (r_type
== elfcpp::R_386_TLS_IE
|| r_type
== elfcpp::R_386_TLS_GOTIE
)
1361 Relocate_functions
<32, false>::rel32(view
, value
);
1364 // Do a relocation in which we convert a TLS Global-Dynamic to a
1368 Target_i386::Relocate::tls_gd_to_le(const Relocate_info
<32, false>* relinfo
,
1370 Output_segment
* tls_segment
,
1371 const elfcpp::Rel
<32, false>& rel
,
1373 elfcpp::Elf_types
<32>::Elf_Addr value
,
1374 unsigned char* view
,
1377 // leal foo(,%reg,1),%eax; call ___tls_get_addr
1378 // ==> movl %gs,0,%eax; subl $foo@tpoff,%eax
1379 // leal foo(%reg),%eax; call ___tls_get_addr
1380 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
1382 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -2);
1383 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, 9);
1385 unsigned char op1
= view
[-1];
1386 unsigned char op2
= view
[-2];
1388 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1389 op2
== 0x8d || op2
== 0x04);
1390 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1397 Target_i386::Relocate::check_range(relinfo
, relnum
, rel
, view_size
, -3);
1398 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1400 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1401 ((op1
& 0xc7) == 0x05
1402 && op1
!= (4 << 3)));
1403 memcpy(view
- 3, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
1407 Target_i386::Relocate::check_tls(relinfo
, relnum
, rel
,
1408 (op1
& 0xf8) == 0x80 && (op1
& 7) != 4);
1409 if (rel
.get_r_offset() + 9 < view_size
&& view
[9] == 0x90)
1411 // There is a trailing nop. Use the size byte subl.
1412 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
1417 // Use the five byte subl.
1418 memcpy(view
- 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
1422 value
= tls_segment
->vaddr() + tls_segment
->memsz() - value
;
1423 Relocate_functions
<32, false>::rel32(view
+ roff
, value
);
1425 // The next reloc should be a PLT32 reloc against __tls_get_addr.
1427 this->skip_call_tls_get_addr_
= true;
1430 // Check the range for a TLS relocation.
1433 Target_i386::Relocate::check_range(const Relocate_info
<32, false>* relinfo
,
1435 const elfcpp::Rel
<32, false>& rel
,
1436 off_t view_size
, off_t off
)
1438 off_t offset
= rel
.get_r_offset() + off
;
1439 if (offset
< 0 || offset
> view_size
)
1441 fprintf(stderr
, _("%s: %s: TLS relocation out of range\n"),
1443 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1448 // Check the validity of a TLS relocation. This is like assert.
1451 Target_i386::Relocate::check_tls(const Relocate_info
<32, false>* relinfo
,
1453 const elfcpp::Rel
<32, false>& rel
,
1459 _("%s: %s: TLS relocation against invalid instruction\n"),
1461 relinfo
->location(relnum
, rel
.get_r_offset()).c_str());
1466 // Relocate section data.
1469 Target_i386::relocate_section(const Relocate_info
<32, false>* relinfo
,
1470 unsigned int sh_type
,
1471 const unsigned char* prelocs
,
1473 unsigned char* view
,
1474 elfcpp::Elf_types
<32>::Elf_Addr address
,
1477 gold_assert(sh_type
== elfcpp::SHT_REL
);
1479 gold::relocate_section
<32, false, Target_i386
, elfcpp::SHT_REL
,
1480 Target_i386::Relocate
>(
1490 // Return a string used to fill a code section with nops to take up
1491 // the specified length.
1494 Target_i386::do_code_fill(off_t length
)
1498 // Build a jmp instruction to skip over the bytes.
1499 unsigned char jmp
[5];
1501 elfcpp::Swap_unaligned
<32, false>::writeval(jmp
+ 1, length
- 5);
1502 return (std::string(reinterpret_cast<char*>(&jmp
[0]), 5)
1503 + std::string(length
- 5, '\0'));
1506 // Nop sequences of various lengths.
1507 const char nop1
[1] = { 0x90 }; // nop
1508 const char nop2
[2] = { 0x66, 0x90 }; // xchg %ax %ax
1509 const char nop3
[3] = { 0x8d, 0x76, 0x00 }; // leal 0(%esi),%esi
1510 const char nop4
[4] = { 0x8d, 0x74, 0x26, 0x00}; // leal 0(%esi,1),%esi
1511 const char nop5
[5] = { 0x90, 0x8d, 0x74, 0x26, // nop
1512 0x00 }; // leal 0(%esi,1),%esi
1513 const char nop6
[6] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
1515 const char nop7
[7] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
1517 const char nop8
[8] = { 0x90, 0x8d, 0xb4, 0x26, // nop
1518 0x00, 0x00, 0x00, 0x00 }; // leal 0L(%esi,1),%esi
1519 const char nop9
[9] = { 0x89, 0xf6, 0x8d, 0xbc, // movl %esi,%esi
1520 0x27, 0x00, 0x00, 0x00, // leal 0L(%edi,1),%edi
1522 const char nop10
[10] = { 0x8d, 0x76, 0x00, 0x8d, // leal 0(%esi),%esi
1523 0xbc, 0x27, 0x00, 0x00, // leal 0L(%edi,1),%edi
1525 const char nop11
[11] = { 0x8d, 0x74, 0x26, 0x00, // leal 0(%esi,1),%esi
1526 0x8d, 0xbc, 0x27, 0x00, // leal 0L(%edi,1),%edi
1528 const char nop12
[12] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
1529 0x00, 0x00, 0x8d, 0xbf, // leal 0L(%edi),%edi
1530 0x00, 0x00, 0x00, 0x00 };
1531 const char nop13
[13] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
1532 0x00, 0x00, 0x8d, 0xbc, // leal 0L(%edi,1),%edi
1533 0x27, 0x00, 0x00, 0x00,
1535 const char nop14
[14] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
1536 0x00, 0x00, 0x00, 0x8d, // leal 0L(%edi,1),%edi
1537 0xbc, 0x27, 0x00, 0x00,
1539 const char nop15
[15] = { 0xeb, 0x0d, 0x90, 0x90, // jmp .+15
1540 0x90, 0x90, 0x90, 0x90, // nop,nop,nop,...
1541 0x90, 0x90, 0x90, 0x90,
1544 const char* nops
[16] = {
1546 nop1
, nop2
, nop3
, nop4
, nop5
, nop6
, nop7
,
1547 nop8
, nop9
, nop10
, nop11
, nop12
, nop13
, nop14
, nop15
1550 return std::string(nops
[length
], length
);
1553 // The selector for i386 object files.
1555 class Target_selector_i386
: public Target_selector
1558 Target_selector_i386()
1559 : Target_selector(elfcpp::EM_386
, 32, false)
1563 recognize(int machine
, int osabi
, int abiversion
);
1566 Target_i386
* target_
;
1569 // Recognize an i386 object file when we already know that the machine
1570 // number is EM_386.
1573 Target_selector_i386::recognize(int, int, int)
1575 if (this->target_
== NULL
)
1576 this->target_
= new Target_i386();
1577 return this->target_
;
1580 Target_selector_i386 target_selector_i386
;
1582 } // End anonymous namespace.