cpu/
[deliverable/binutils-gdb.git] / gold / i386.cc
CommitLineData
14bfc3f5
ILT
1// i386.cc -- i386 target support for gold.
2
6d03d481 3// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6cb15b7f
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
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.
12
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.
17
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.
22
14bfc3f5 23#include "gold.h"
ead1e424
ILT
24
25#include <cstring>
26
14bfc3f5 27#include "elfcpp.h"
7e1edb90 28#include "parameters.h"
92e059d8 29#include "reloc.h"
61ba1cf9
ILT
30#include "i386.h"
31#include "object.h"
ead1e424 32#include "symtab.h"
92e059d8
ILT
33#include "layout.h"
34#include "output.h"
12c0daef 35#include "copy-relocs.h"
14bfc3f5 36#include "target.h"
61ba1cf9 37#include "target-reloc.h"
14bfc3f5 38#include "target-select.h"
af6359d5 39#include "tls.h"
36959681 40#include "freebsd.h"
14bfc3f5
ILT
41
42namespace
43{
44
45using namespace gold;
46
a3ad94ed
ILT
47class Output_data_plt_i386;
48
14bfc3f5 49// The i386 target class.
e041f13d
ILT
50// TLS info comes from
51// http://people.redhat.com/drepper/tls.pdf
52// http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt
14bfc3f5 53
36959681 54class Target_i386 : public Target_freebsd<32, false>
14bfc3f5
ILT
55{
56 public:
5a6f7e2d
ILT
57 typedef Output_data_reloc<elfcpp::SHT_REL, true, 32, false> Reloc_section;
58
14bfc3f5 59 Target_i386()
36959681 60 : Target_freebsd<32, false>(&i386_info),
5a6f7e2d 61 got_(NULL), plt_(NULL), got_plt_(NULL), rel_dyn_(NULL),
12c0daef 62 copy_relocs_(elfcpp::R_386_COPY), dynbss_(NULL),
edfbb029 63 got_mod_index_offset_(-1U), tls_base_symbol_defined_(false)
14bfc3f5 64 { }
75f65a3e 65
6d03d481
ST
66 // Process the relocations to determine unreferenced sections for
67 // garbage collection.
68 void
69 gc_process_relocs(const General_options& options,
70 Symbol_table* symtab,
71 Layout* layout,
72 Sized_relobj<32, false>* object,
73 unsigned int data_shndx,
74 unsigned int sh_type,
75 const unsigned char* prelocs,
76 size_t reloc_count,
77 Output_section* output_section,
78 bool needs_special_offset_handling,
79 size_t local_symbol_count,
80 const unsigned char* plocal_symbols);
81
92e059d8 82 // Scan the relocations to look for symbol adjustments.
61ba1cf9 83 void
92e059d8
ILT
84 scan_relocs(const General_options& options,
85 Symbol_table* symtab,
ead1e424 86 Layout* layout,
f6ce93d6 87 Sized_relobj<32, false>* object,
a3ad94ed 88 unsigned int data_shndx,
92e059d8
ILT
89 unsigned int sh_type,
90 const unsigned char* prelocs,
91 size_t reloc_count,
730cdc88
ILT
92 Output_section* output_section,
93 bool needs_special_offset_handling,
92e059d8 94 size_t local_symbol_count,
730cdc88 95 const unsigned char* plocal_symbols);
61ba1cf9 96
5a6f7e2d
ILT
97 // Finalize the sections.
98 void
7e1edb90 99 do_finalize_sections(Layout*);
5a6f7e2d 100
ab5c9e90
ILT
101 // Return the value to use for a dynamic which requires special
102 // treatment.
103 uint64_t
104 do_dynsym_value(const Symbol*) const;
105
92e059d8
ILT
106 // Relocate a section.
107 void
108 relocate_section(const Relocate_info<32, false>*,
109 unsigned int sh_type,
110 const unsigned char* prelocs,
111 size_t reloc_count,
730cdc88
ILT
112 Output_section* output_section,
113 bool needs_special_offset_handling,
92e059d8
ILT
114 unsigned char* view,
115 elfcpp::Elf_types<32>::Elf_Addr view_address,
fe8718a4 116 section_size_type view_size);
92e059d8 117
6a74a719
ILT
118 // Scan the relocs during a relocatable link.
119 void
120 scan_relocatable_relocs(const General_options& options,
121 Symbol_table* symtab,
122 Layout* layout,
123 Sized_relobj<32, false>* object,
124 unsigned int data_shndx,
125 unsigned int sh_type,
126 const unsigned char* prelocs,
127 size_t reloc_count,
128 Output_section* output_section,
129 bool needs_special_offset_handling,
130 size_t local_symbol_count,
131 const unsigned char* plocal_symbols,
132 Relocatable_relocs*);
133
134 // Relocate a section during a relocatable link.
135 void
136 relocate_for_relocatable(const Relocate_info<32, false>*,
137 unsigned int sh_type,
138 const unsigned char* prelocs,
139 size_t reloc_count,
140 Output_section* output_section,
141 off_t offset_in_output_section,
142 const Relocatable_relocs*,
143 unsigned char* view,
144 elfcpp::Elf_types<32>::Elf_Addr view_address,
145 section_size_type view_size,
146 unsigned char* reloc_view,
147 section_size_type reloc_view_size);
148
c51e6221
ILT
149 // Return a string used to fill a code section with nops.
150 std::string
8851ecca 151 do_code_fill(section_size_type length) const;
c51e6221 152
9a2d6984
ILT
153 // Return whether SYM is defined by the ABI.
154 bool
9c2d0ef9 155 do_is_defined_by_abi(const Symbol* sym) const
9a2d6984
ILT
156 { return strcmp(sym->name(), "___tls_get_addr") == 0; }
157
bb04269c
DK
158 // Return whether a symbol name implies a local label. The UnixWare
159 // 2.1 cc generates temporary symbols that start with .X, so we
160 // recognize them here. FIXME: do other SVR4 compilers also use .X?.
161 // If so, we should move the .X recognition into
162 // Target::do_is_local_label_name.
163 bool
164 do_is_local_label_name(const char* name) const
165 {
166 if (name[0] == '.' && name[1] == 'X')
167 return true;
168 return Target::do_is_local_label_name(name);
169 }
170
96f2030e 171 // Return the size of the GOT section.
fe8718a4 172 section_size_type
96f2030e
ILT
173 got_size()
174 {
175 gold_assert(this->got_ != NULL);
176 return this->got_->data_size();
177 }
178
92e059d8
ILT
179 private:
180 // The class which scans relocations.
181 struct Scan
61ba1cf9
ILT
182 {
183 inline void
ead1e424
ILT
184 local(const General_options& options, Symbol_table* symtab,
185 Layout* layout, Target_i386* target,
f6ce93d6 186 Sized_relobj<32, false>* object,
a3ad94ed 187 unsigned int data_shndx,
07f397ab 188 Output_section* output_section,
92e059d8
ILT
189 const elfcpp::Rel<32, false>& reloc, unsigned int r_type,
190 const elfcpp::Sym<32, false>& lsym);
61ba1cf9 191
92e059d8 192 inline void
ead1e424
ILT
193 global(const General_options& options, Symbol_table* symtab,
194 Layout* layout, Target_i386* target,
f6ce93d6 195 Sized_relobj<32, false>* object,
a3ad94ed 196 unsigned int data_shndx,
07f397ab 197 Output_section* output_section,
92e059d8
ILT
198 const elfcpp::Rel<32, false>& reloc, unsigned int r_type,
199 Symbol* gsym);
af6359d5
ILT
200
201 static void
202 unsupported_reloc_local(Sized_relobj<32, false>*, unsigned int r_type);
203
204 static void
205 unsupported_reloc_global(Sized_relobj<32, false>*, unsigned int r_type,
206 Symbol*);
61ba1cf9
ILT
207 };
208
92e059d8
ILT
209 // The class which implements relocation.
210 class Relocate
211 {
212 public:
ead1e424 213 Relocate()
46cf9fa2
ILT
214 : skip_call_tls_get_addr_(false),
215 local_dynamic_type_(LOCAL_DYNAMIC_NONE)
ead1e424
ILT
216 { }
217
218 ~Relocate()
219 {
220 if (this->skip_call_tls_get_addr_)
221 {
222 // FIXME: This needs to specify the location somehow.
75f2446e 223 gold_error(_("missing expected TLS relocation"));
ead1e424
ILT
224 }
225 }
226
86849f1f
ILT
227 // Return whether the static relocation needs to be applied.
228 inline bool
229 should_apply_static_reloc(const Sized_symbol<32>* gsym,
0700cf32 230 int ref_flags,
031cdbed
ILT
231 bool is_32bit,
232 Output_section* output_section);
86849f1f 233
ead1e424
ILT
234 // Do a relocation. Return false if the caller should not issue
235 // any warnings about this relocation.
236 inline bool
031cdbed
ILT
237 relocate(const Relocate_info<32, false>*, Target_i386*, Output_section*,
238 size_t relnum, const elfcpp::Rel<32, false>&,
c06b7b0b 239 unsigned int r_type, const Sized_symbol<32>*,
b8e6aad9 240 const Symbol_value<32>*,
92e059d8 241 unsigned char*, elfcpp::Elf_types<32>::Elf_Addr,
fe8718a4 242 section_size_type);
92e059d8
ILT
243
244 private:
245 // Do a TLS relocation.
ead1e424 246 inline void
07f397ab
ILT
247 relocate_tls(const Relocate_info<32, false>*, Target_i386* target,
248 size_t relnum, const elfcpp::Rel<32, false>&,
c06b7b0b 249 unsigned int r_type, const Sized_symbol<32>*,
b8e6aad9 250 const Symbol_value<32>*,
fe8718a4
ILT
251 unsigned char*, elfcpp::Elf_types<32>::Elf_Addr,
252 section_size_type);
92e059d8 253
07f397ab
ILT
254 // Do a TLS General-Dynamic to Initial-Exec transition.
255 inline void
256 tls_gd_to_ie(const Relocate_info<32, false>*, size_t relnum,
257 Output_segment* tls_segment,
258 const elfcpp::Rel<32, false>&, unsigned int r_type,
259 elfcpp::Elf_types<32>::Elf_Addr value,
260 unsigned char* view,
fe8718a4 261 section_size_type view_size);
07f397ab 262
56622147
ILT
263 // Do a TLS General-Dynamic to Local-Exec transition.
264 inline void
265 tls_gd_to_le(const Relocate_info<32, false>*, size_t relnum,
92e059d8
ILT
266 Output_segment* tls_segment,
267 const elfcpp::Rel<32, false>&, unsigned int r_type,
268 elfcpp::Elf_types<32>::Elf_Addr value,
269 unsigned char* view,
fe8718a4 270 section_size_type view_size);
92e059d8 271
c2b45e22
CC
272 // Do a TLS_GOTDESC or TLS_DESC_CALL General-Dynamic to Initial-Exec
273 // transition.
274 inline void
275 tls_desc_gd_to_ie(const Relocate_info<32, false>*, size_t relnum,
276 Output_segment* tls_segment,
277 const elfcpp::Rel<32, false>&, unsigned int r_type,
278 elfcpp::Elf_types<32>::Elf_Addr value,
279 unsigned char* view,
280 section_size_type view_size);
281
282 // Do a TLS_GOTDESC or TLS_DESC_CALL General-Dynamic to Local-Exec
283 // transition.
284 inline void
285 tls_desc_gd_to_le(const Relocate_info<32, false>*, size_t relnum,
286 Output_segment* tls_segment,
287 const elfcpp::Rel<32, false>&, unsigned int r_type,
288 elfcpp::Elf_types<32>::Elf_Addr value,
289 unsigned char* view,
290 section_size_type view_size);
291
56622147 292 // Do a TLS Local-Dynamic to Local-Exec transition.
ead1e424 293 inline void
56622147 294 tls_ld_to_le(const Relocate_info<32, false>*, size_t relnum,
ead1e424
ILT
295 Output_segment* tls_segment,
296 const elfcpp::Rel<32, false>&, unsigned int r_type,
297 elfcpp::Elf_types<32>::Elf_Addr value,
298 unsigned char* view,
fe8718a4 299 section_size_type view_size);
ead1e424 300
56622147
ILT
301 // Do a TLS Initial-Exec to Local-Exec transition.
302 static inline void
303 tls_ie_to_le(const Relocate_info<32, false>*, size_t relnum,
46cf9fa2
ILT
304 Output_segment* tls_segment,
305 const elfcpp::Rel<32, false>&, unsigned int r_type,
306 elfcpp::Elf_types<32>::Elf_Addr value,
307 unsigned char* view,
fe8718a4 308 section_size_type view_size);
46cf9fa2 309
46cf9fa2
ILT
310 // We need to keep track of which type of local dynamic relocation
311 // we have seen, so that we can optimize R_386_TLS_LDO_32 correctly.
312 enum Local_dynamic_type
313 {
314 LOCAL_DYNAMIC_NONE,
315 LOCAL_DYNAMIC_SUN,
316 LOCAL_DYNAMIC_GNU
317 };
318
ead1e424
ILT
319 // This is set if we should skip the next reloc, which should be a
320 // PLT32 reloc against ___tls_get_addr.
321 bool skip_call_tls_get_addr_;
46cf9fa2
ILT
322 // The type of local dynamic relocation we have seen in the section
323 // being relocated, if any.
324 Local_dynamic_type local_dynamic_type_;
92e059d8
ILT
325 };
326
6a74a719
ILT
327 // A class which returns the size required for a relocation type,
328 // used while scanning relocs during a relocatable link.
329 class Relocatable_size_for_reloc
330 {
331 public:
332 unsigned int
333 get_size_for_reloc(unsigned int, Relobj*);
334 };
335
92e059d8
ILT
336 // Adjust TLS relocation type based on the options and whether this
337 // is a local symbol.
af6359d5 338 static tls::Tls_optimization
7e1edb90 339 optimize_tls_reloc(bool is_final, int r_type);
92e059d8 340
ead1e424 341 // Get the GOT section, creating it if necessary.
dbe717ef 342 Output_data_got<32, false>*
7e1edb90 343 got_section(Symbol_table*, Layout*);
a3ad94ed 344
96f2030e
ILT
345 // Get the GOT PLT section.
346 Output_data_space*
347 got_plt_section() const
348 {
349 gold_assert(this->got_plt_ != NULL);
350 return this->got_plt_;
351 }
352
a3ad94ed
ILT
353 // Create a PLT entry for a global symbol.
354 void
7e1edb90 355 make_plt_entry(Symbol_table*, Layout*, Symbol*);
a3ad94ed 356
9fa33bee 357 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
edfbb029
CC
358 void
359 define_tls_base_symbol(Symbol_table*, Layout*);
360
94c4710f
ILT
361 // Create a GOT entry for the TLS module index.
362 unsigned int
363 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
364 Sized_relobj<32, false>* object);
365
a3ad94ed 366 // Get the PLT section.
7bb3655e 367 const Output_data_plt_i386*
a3ad94ed
ILT
368 plt_section() const
369 {
370 gold_assert(this->plt_ != NULL);
371 return this->plt_;
372 }
373
5a6f7e2d
ILT
374 // Get the dynamic reloc section, creating it if necessary.
375 Reloc_section*
376 rel_dyn_section(Layout*);
377
d61c6bd4
ILT
378 // Return true if the symbol may need a COPY relocation.
379 // References from an executable object to non-function symbols
380 // defined in a dynamic object may need a COPY relocation.
381 bool
382 may_need_copy_reloc(Symbol* gsym)
383 {
8851ecca 384 return (!parameters->options().shared()
d61c6bd4
ILT
385 && gsym->is_from_dynobj()
386 && gsym->type() != elfcpp::STT_FUNC);
387 }
388
12c0daef 389 // Add a potential copy relocation.
a3ad94ed 390 void
ef9beddf
ILT
391 copy_reloc(Symbol_table* symtab, Layout* layout,
392 Sized_relobj<32, false>* object,
12c0daef
ILT
393 unsigned int shndx, Output_section* output_section,
394 Symbol* sym, const elfcpp::Rel<32, false>& reloc)
395 {
396 this->copy_relocs_.copy_reloc(symtab, layout,
397 symtab->get_sized_symbol<32>(sym),
398 object, shndx, output_section, reloc,
399 this->rel_dyn_section(layout));
400 }
ead1e424 401
92e059d8
ILT
402 // Information about this specific target which we pass to the
403 // general Target structure.
75f65a3e 404 static const Target::Target_info i386_info;
ead1e424 405
0a65a3a7
CC
406 // The types of GOT entries needed for this platform.
407 enum Got_type
408 {
409 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
c2b45e22
CC
410 GOT_TYPE_TLS_NOFFSET = 1, // GOT entry for negative TLS offset
411 GOT_TYPE_TLS_OFFSET = 2, // GOT entry for positive TLS offset
412 GOT_TYPE_TLS_PAIR = 3, // GOT entry for TLS module/offset pair
413 GOT_TYPE_TLS_DESC = 4 // GOT entry for TLS_DESC pair
0a65a3a7
CC
414 };
415
ead1e424 416 // The GOT section.
dbe717ef 417 Output_data_got<32, false>* got_;
a3ad94ed
ILT
418 // The PLT section.
419 Output_data_plt_i386* plt_;
420 // The GOT PLT section.
421 Output_data_space* got_plt_;
5a6f7e2d
ILT
422 // The dynamic reloc section.
423 Reloc_section* rel_dyn_;
424 // Relocs saved to avoid a COPY reloc.
12c0daef 425 Copy_relocs<elfcpp::SHT_REL, 32, false> copy_relocs_;
5a6f7e2d
ILT
426 // Space for variables copied with a COPY reloc.
427 Output_data_space* dynbss_;
c2b45e22 428 // Offset of the GOT entry for the TLS module index.
94c4710f 429 unsigned int got_mod_index_offset_;
edfbb029
CC
430 // True if the _TLS_MODULE_BASE_ symbol has been defined.
431 bool tls_base_symbol_defined_;
75f65a3e
ILT
432};
433
434const Target::Target_info Target_i386::i386_info =
435{
61ba1cf9
ILT
436 32, // size
437 false, // is_big_endian
438 elfcpp::EM_386, // machine_code
439 false, // has_make_symbol
dbe717ef 440 false, // has_resolve
c51e6221 441 true, // has_code_fill
35cdfc9a 442 true, // is_default_stack_executable
0864d551 443 '\0', // wrap_char
dbe717ef 444 "/usr/lib/libc.so.1", // dynamic_linker
0c5e9c22 445 0x08048000, // default_text_segment_address
cd72c291
ILT
446 0x1000, // abi_pagesize (overridable by -z max-page-size)
447 0x1000 // common_pagesize (overridable by -z common-page-size)
14bfc3f5
ILT
448};
449
ead1e424
ILT
450// Get the GOT section, creating it if necessary.
451
dbe717ef 452Output_data_got<32, false>*
7e1edb90 453Target_i386::got_section(Symbol_table* symtab, Layout* layout)
ead1e424
ILT
454{
455 if (this->got_ == NULL)
456 {
7e1edb90 457 gold_assert(symtab != NULL && layout != NULL);
a3ad94ed 458
7e1edb90 459 this->got_ = new Output_data_got<32, false>();
ead1e424 460
9f1d377b
ILT
461 Output_section* os;
462 os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
463 (elfcpp::SHF_ALLOC
464 | elfcpp::SHF_WRITE),
465 this->got_);
466 os->set_is_relro();
ead1e424 467
a3ad94ed
ILT
468 // The old GNU linker creates a .got.plt section. We just
469 // create another set of data in the .got section. Note that we
470 // always create a PLT if we create a GOT, although the PLT
471 // might be empty.
7d9e3d98 472 this->got_plt_ = new Output_data_space(4, "** GOT PLT");
9f1d377b
ILT
473 os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
474 (elfcpp::SHF_ALLOC
475 | elfcpp::SHF_WRITE),
476 this->got_plt_);
477 os->set_is_relro();
a3ad94ed 478
ead1e424 479 // The first three entries are reserved.
27bc2bce 480 this->got_plt_->set_current_data_size(3 * 4);
ead1e424 481
a3ad94ed 482 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
9b07f471 483 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
a3ad94ed 484 this->got_plt_,
ead1e424 485 0, 0, elfcpp::STT_OBJECT,
16649710 486 elfcpp::STB_LOCAL,
ead1e424
ILT
487 elfcpp::STV_HIDDEN, 0,
488 false, false);
489 }
a3ad94ed 490
ead1e424
ILT
491 return this->got_;
492}
493
5a6f7e2d
ILT
494// Get the dynamic reloc section, creating it if necessary.
495
496Target_i386::Reloc_section*
497Target_i386::rel_dyn_section(Layout* layout)
498{
499 if (this->rel_dyn_ == NULL)
500 {
501 gold_assert(layout != NULL);
d98bc257 502 this->rel_dyn_ = new Reloc_section(parameters->options().combreloc());
5a6f7e2d
ILT
503 layout->add_output_section_data(".rel.dyn", elfcpp::SHT_REL,
504 elfcpp::SHF_ALLOC, this->rel_dyn_);
505 }
506 return this->rel_dyn_;
507}
508
a3ad94ed
ILT
509// A class to handle the PLT data.
510
511class Output_data_plt_i386 : public Output_section_data
512{
513 public:
514 typedef Output_data_reloc<elfcpp::SHT_REL, true, 32, false> Reloc_section;
515
7e1edb90 516 Output_data_plt_i386(Layout*, Output_data_space*);
a3ad94ed
ILT
517
518 // Add an entry to the PLT.
519 void
520 add_entry(Symbol* gsym);
521
16649710
ILT
522 // Return the .rel.plt section data.
523 const Reloc_section*
524 rel_plt() const
525 { return this->rel_; }
526
527 protected:
528 void
529 do_adjust_output_section(Output_section* os);
530
7d9e3d98
ILT
531 // Write to a map file.
532 void
533 do_print_to_mapfile(Mapfile* mapfile) const
534 { mapfile->print_output_data(this, _("** PLT")); }
535
a3ad94ed
ILT
536 private:
537 // The size of an entry in the PLT.
538 static const int plt_entry_size = 16;
539
540 // The first entry in the PLT for an executable.
541 static unsigned char exec_first_plt_entry[plt_entry_size];
542
543 // The first entry in the PLT for a shared object.
544 static unsigned char dyn_first_plt_entry[plt_entry_size];
545
546 // Other entries in the PLT for an executable.
547 static unsigned char exec_plt_entry[plt_entry_size];
548
549 // Other entries in the PLT for a shared object.
550 static unsigned char dyn_plt_entry[plt_entry_size];
551
552 // Set the final size.
553 void
27bc2bce 554 set_final_data_size()
a3ad94ed
ILT
555 { this->set_data_size((this->count_ + 1) * plt_entry_size); }
556
557 // Write out the PLT data.
558 void
559 do_write(Output_file*);
560
561 // The reloc section.
562 Reloc_section* rel_;
563 // The .got.plt section.
564 Output_data_space* got_plt_;
565 // The number of PLT entries.
566 unsigned int count_;
a3ad94ed
ILT
567};
568
569// Create the PLT section. The ordinary .got section is an argument,
570// since we need to refer to the start. We also create our own .got
571// section just for PLT entries.
572
573Output_data_plt_i386::Output_data_plt_i386(Layout* layout,
7e1edb90 574 Output_data_space* got_plt)
80576242 575 : Output_section_data(4), got_plt_(got_plt), count_(0)
a3ad94ed 576{
d98bc257 577 this->rel_ = new Reloc_section(false);
a3ad94ed
ILT
578 layout->add_output_section_data(".rel.plt", elfcpp::SHT_REL,
579 elfcpp::SHF_ALLOC, this->rel_);
580}
581
16649710
ILT
582void
583Output_data_plt_i386::do_adjust_output_section(Output_section* os)
584{
585 // UnixWare sets the entsize of .plt to 4, and so does the old GNU
586 // linker, and so do we.
587 os->set_entsize(4);
588}
589
a3ad94ed
ILT
590// Add an entry to the PLT.
591
592void
593Output_data_plt_i386::add_entry(Symbol* gsym)
594{
595 gold_assert(!gsym->has_plt_offset());
596
597 // Note that when setting the PLT offset we skip the initial
598 // reserved PLT entry.
599 gsym->set_plt_offset((this->count_ + 1) * plt_entry_size);
600
601 ++this->count_;
602
fe8718a4 603 section_offset_type got_offset = this->got_plt_->current_data_size();
a3ad94ed
ILT
604
605 // Every PLT entry needs a GOT entry which points back to the PLT
606 // entry (this will be changed by the dynamic linker, normally
607 // lazily when the function is called).
27bc2bce 608 this->got_plt_->set_current_data_size(got_offset + 4);
a3ad94ed
ILT
609
610 // Every PLT entry needs a reloc.
16649710 611 gsym->set_needs_dynsym_entry();
a3ad94ed
ILT
612 this->rel_->add_global(gsym, elfcpp::R_386_JUMP_SLOT, this->got_plt_,
613 got_offset);
614
615 // Note that we don't need to save the symbol. The contents of the
616 // PLT are independent of which symbols are used. The symbols only
617 // appear in the relocations.
618}
619
620// The first entry in the PLT for an executable.
621
622unsigned char Output_data_plt_i386::exec_first_plt_entry[plt_entry_size] =
623{
624 0xff, 0x35, // pushl contents of memory address
625 0, 0, 0, 0, // replaced with address of .got + 4
626 0xff, 0x25, // jmp indirect
627 0, 0, 0, 0, // replaced with address of .got + 8
628 0, 0, 0, 0 // unused
629};
630
631// The first entry in the PLT for a shared object.
632
633unsigned char Output_data_plt_i386::dyn_first_plt_entry[plt_entry_size] =
634{
635 0xff, 0xb3, 4, 0, 0, 0, // pushl 4(%ebx)
636 0xff, 0xa3, 8, 0, 0, 0, // jmp *8(%ebx)
637 0, 0, 0, 0 // unused
638};
639
640// Subsequent entries in the PLT for an executable.
641
642unsigned char Output_data_plt_i386::exec_plt_entry[plt_entry_size] =
643{
644 0xff, 0x25, // jmp indirect
645 0, 0, 0, 0, // replaced with address of symbol in .got
646 0x68, // pushl immediate
647 0, 0, 0, 0, // replaced with offset into relocation table
648 0xe9, // jmp relative
649 0, 0, 0, 0 // replaced with offset to start of .plt
650};
651
652// Subsequent entries in the PLT for a shared object.
653
654unsigned char Output_data_plt_i386::dyn_plt_entry[plt_entry_size] =
655{
656 0xff, 0xa3, // jmp *offset(%ebx)
657 0, 0, 0, 0, // replaced with offset of symbol in .got
658 0x68, // pushl immediate
659 0, 0, 0, 0, // replaced with offset into relocation table
660 0xe9, // jmp relative
661 0, 0, 0, 0 // replaced with offset to start of .plt
662};
663
664// Write out the PLT. This uses the hand-coded instructions above,
665// and adjusts them as needed. This is all specified by the i386 ELF
666// Processor Supplement.
667
668void
669Output_data_plt_i386::do_write(Output_file* of)
670{
671 const off_t offset = this->offset();
fe8718a4
ILT
672 const section_size_type oview_size =
673 convert_to_section_size_type(this->data_size());
a3ad94ed
ILT
674 unsigned char* const oview = of->get_output_view(offset, oview_size);
675
676 const off_t got_file_offset = this->got_plt_->offset();
fe8718a4
ILT
677 const section_size_type got_size =
678 convert_to_section_size_type(this->got_plt_->data_size());
a3ad94ed
ILT
679 unsigned char* const got_view = of->get_output_view(got_file_offset,
680 got_size);
681
682 unsigned char* pov = oview;
683
684 elfcpp::Elf_types<32>::Elf_Addr plt_address = this->address();
685 elfcpp::Elf_types<32>::Elf_Addr got_address = this->got_plt_->address();
686
8851ecca 687 if (parameters->options().shared())
a3ad94ed
ILT
688 memcpy(pov, dyn_first_plt_entry, plt_entry_size);
689 else
690 {
691 memcpy(pov, exec_first_plt_entry, plt_entry_size);
692 elfcpp::Swap_unaligned<32, false>::writeval(pov + 2, got_address + 4);
693 elfcpp::Swap<32, false>::writeval(pov + 8, got_address + 8);
694 }
695 pov += plt_entry_size;
696
697 unsigned char* got_pov = got_view;
698
699 memset(got_pov, 0, 12);
700 got_pov += 12;
701
702 const int rel_size = elfcpp::Elf_sizes<32>::rel_size;
703
704 unsigned int plt_offset = plt_entry_size;
705 unsigned int plt_rel_offset = 0;
706 unsigned int got_offset = 12;
707 const unsigned int count = this->count_;
708 for (unsigned int i = 0;
709 i < count;
710 ++i,
711 pov += plt_entry_size,
712 got_pov += 4,
713 plt_offset += plt_entry_size,
714 plt_rel_offset += rel_size,
715 got_offset += 4)
716 {
717 // Set and adjust the PLT entry itself.
718
8851ecca 719 if (parameters->options().shared())
a3ad94ed
ILT
720 {
721 memcpy(pov, dyn_plt_entry, plt_entry_size);
722 elfcpp::Swap_unaligned<32, false>::writeval(pov + 2, got_offset);
723 }
724 else
725 {
726 memcpy(pov, exec_plt_entry, plt_entry_size);
727 elfcpp::Swap_unaligned<32, false>::writeval(pov + 2,
728 (got_address
729 + got_offset));
730 }
731
732 elfcpp::Swap_unaligned<32, false>::writeval(pov + 7, plt_rel_offset);
733 elfcpp::Swap<32, false>::writeval(pov + 12,
734 - (plt_offset + plt_entry_size));
735
736 // Set the entry in the GOT.
737 elfcpp::Swap<32, false>::writeval(got_pov, plt_address + plt_offset + 6);
738 }
739
fe8718a4
ILT
740 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
741 gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
a3ad94ed
ILT
742
743 of->write_output_view(offset, oview_size, oview);
744 of->write_output_view(got_file_offset, got_size, got_view);
745}
746
747// Create a PLT entry for a global symbol.
748
749void
7e1edb90 750Target_i386::make_plt_entry(Symbol_table* symtab, Layout* layout, Symbol* gsym)
a3ad94ed
ILT
751{
752 if (gsym->has_plt_offset())
753 return;
754
755 if (this->plt_ == NULL)
756 {
757 // Create the GOT sections first.
7e1edb90 758 this->got_section(symtab, layout);
a3ad94ed 759
7e1edb90 760 this->plt_ = new Output_data_plt_i386(layout, this->got_plt_);
16649710
ILT
761 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
762 (elfcpp::SHF_ALLOC
763 | elfcpp::SHF_EXECINSTR),
764 this->plt_);
a3ad94ed
ILT
765 }
766
767 this->plt_->add_entry(gsym);
768}
769
9fa33bee 770// Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
edfbb029
CC
771
772void
773Target_i386::define_tls_base_symbol(Symbol_table* symtab, Layout* layout)
774{
775 if (this->tls_base_symbol_defined_)
776 return;
777
778 Output_segment* tls_segment = layout->tls_segment();
779 if (tls_segment != NULL)
780 {
183fd0e3 781 bool is_exec = parameters->options().output_is_executable();
edfbb029
CC
782 symtab->define_in_output_segment("_TLS_MODULE_BASE_", NULL,
783 tls_segment, 0, 0,
784 elfcpp::STT_TLS,
785 elfcpp::STB_LOCAL,
786 elfcpp::STV_HIDDEN, 0,
183fd0e3
AO
787 (is_exec
788 ? Symbol::SEGMENT_END
789 : Symbol::SEGMENT_START),
790 true);
edfbb029
CC
791 }
792 this->tls_base_symbol_defined_ = true;
793}
794
94c4710f
ILT
795// Create a GOT entry for the TLS module index.
796
797unsigned int
798Target_i386::got_mod_index_entry(Symbol_table* symtab, Layout* layout,
799 Sized_relobj<32, false>* object)
800{
801 if (this->got_mod_index_offset_ == -1U)
802 {
803 gold_assert(symtab != NULL && layout != NULL && object != NULL);
804 Reloc_section* rel_dyn = this->rel_dyn_section(layout);
805 Output_data_got<32, false>* got = this->got_section(symtab, layout);
806 unsigned int got_offset = got->add_constant(0);
807 rel_dyn->add_local(object, 0, elfcpp::R_386_TLS_DTPMOD32, got,
808 got_offset);
009a67a2 809 got->add_constant(0);
94c4710f
ILT
810 this->got_mod_index_offset_ = got_offset;
811 }
812 return this->got_mod_index_offset_;
813}
814
92e059d8 815// Optimize the TLS relocation type based on what we know about the
a3ad94ed
ILT
816// symbol. IS_FINAL is true if the final address of this symbol is
817// known at link time.
92e059d8 818
af6359d5 819tls::Tls_optimization
7e1edb90 820Target_i386::optimize_tls_reloc(bool is_final, int r_type)
92e059d8
ILT
821{
822 // If we are generating a shared library, then we can't do anything
823 // in the linker.
8851ecca 824 if (parameters->options().shared())
af6359d5 825 return tls::TLSOPT_NONE;
92e059d8
ILT
826
827 switch (r_type)
828 {
829 case elfcpp::R_386_TLS_GD:
830 case elfcpp::R_386_TLS_GOTDESC:
831 case elfcpp::R_386_TLS_DESC_CALL:
e041f13d 832 // These are General-Dynamic which permits fully general TLS
92e059d8
ILT
833 // access. Since we know that we are generating an executable,
834 // we can convert this to Initial-Exec. If we also know that
835 // this is a local symbol, we can further switch to Local-Exec.
a3ad94ed 836 if (is_final)
af6359d5
ILT
837 return tls::TLSOPT_TO_LE;
838 return tls::TLSOPT_TO_IE;
92e059d8
ILT
839
840 case elfcpp::R_386_TLS_LDM:
841 // This is Local-Dynamic, which refers to a local symbol in the
842 // dynamic TLS block. Since we know that we generating an
843 // executable, we can switch to Local-Exec.
af6359d5 844 return tls::TLSOPT_TO_LE;
92e059d8
ILT
845
846 case elfcpp::R_386_TLS_LDO_32:
af6359d5
ILT
847 // Another type of Local-Dynamic relocation.
848 return tls::TLSOPT_TO_LE;
92e059d8
ILT
849
850 case elfcpp::R_386_TLS_IE:
851 case elfcpp::R_386_TLS_GOTIE:
852 case elfcpp::R_386_TLS_IE_32:
853 // These are Initial-Exec relocs which get the thread offset
854 // from the GOT. If we know that we are linking against the
855 // local symbol, we can switch to Local-Exec, which links the
856 // thread offset into the instruction.
a3ad94ed 857 if (is_final)
af6359d5
ILT
858 return tls::TLSOPT_TO_LE;
859 return tls::TLSOPT_NONE;
8462ae85 860
92e059d8
ILT
861 case elfcpp::R_386_TLS_LE:
862 case elfcpp::R_386_TLS_LE_32:
863 // When we already have Local-Exec, there is nothing further we
864 // can do.
af6359d5 865 return tls::TLSOPT_NONE;
92e059d8
ILT
866
867 default:
a3ad94ed 868 gold_unreachable();
92e059d8
ILT
869 }
870}
871
af6359d5
ILT
872// Report an unsupported relocation against a local symbol.
873
874void
875Target_i386::Scan::unsupported_reloc_local(Sized_relobj<32, false>* object,
876 unsigned int r_type)
877{
75f2446e
ILT
878 gold_error(_("%s: unsupported reloc %u against local symbol"),
879 object->name().c_str(), r_type);
af6359d5
ILT
880}
881
92e059d8
ILT
882// Scan a relocation for a local symbol.
883
884inline void
7e1edb90 885Target_i386::Scan::local(const General_options&,
ead1e424
ILT
886 Symbol_table* symtab,
887 Layout* layout,
888 Target_i386* target,
f6ce93d6 889 Sized_relobj<32, false>* object,
1b64748b 890 unsigned int data_shndx,
07f397ab 891 Output_section* output_section,
1b64748b 892 const elfcpp::Rel<32, false>& reloc,
a3ad94ed 893 unsigned int r_type,
7bf1f802 894 const elfcpp::Sym<32, false>& lsym)
92e059d8
ILT
895{
896 switch (r_type)
897 {
898 case elfcpp::R_386_NONE:
899 case elfcpp::R_386_GNU_VTINHERIT:
900 case elfcpp::R_386_GNU_VTENTRY:
901 break;
902
903 case elfcpp::R_386_32:
436ca963
ILT
904 // If building a shared library (or a position-independent
905 // executable), we need to create a dynamic relocation for
906 // this location. The relocation applied at link time will
907 // apply the link-time value, so we flag the location with
908 // an R_386_RELATIVE relocation so the dynamic loader can
909 // relocate it easily.
8851ecca 910 if (parameters->options().output_is_position_independent())
436ca963
ILT
911 {
912 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
e8c846c3
ILT
913 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
914 rel_dyn->add_local_relative(object, r_sym, elfcpp::R_386_RELATIVE,
915 output_section, data_shndx,
916 reloc.get_r_offset());
d61c6bd4
ILT
917 }
918 break;
919
920 case elfcpp::R_386_16:
921 case elfcpp::R_386_8:
922 // If building a shared library (or a position-independent
923 // executable), we need to create a dynamic relocation for
924 // this location. Because the addend needs to remain in the
925 // data section, we need to be careful not to apply this
926 // relocation statically.
8851ecca 927 if (parameters->options().output_is_position_independent())
d61c6bd4
ILT
928 {
929 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
d491d34e 930 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
dceae3c1 931 if (lsym.get_st_type() != elfcpp::STT_SECTION)
d491d34e
ILT
932 rel_dyn->add_local(object, r_sym, r_type, output_section,
933 data_shndx, reloc.get_r_offset());
dceae3c1
ILT
934 else
935 {
936 gold_assert(lsym.get_st_value() == 0);
d491d34e
ILT
937 unsigned int shndx = lsym.get_st_shndx();
938 bool is_ordinary;
939 shndx = object->adjust_sym_shndx(r_sym, shndx,
940 &is_ordinary);
941 if (!is_ordinary)
942 object->error(_("section symbol %u has bad shndx %u"),
943 r_sym, shndx);
944 else
945 rel_dyn->add_local_section(object, shndx,
946 r_type, output_section,
947 data_shndx, reloc.get_r_offset());
dceae3c1 948 }
436ca963 949 }
92e059d8
ILT
950 break;
951
952 case elfcpp::R_386_PC32:
953 case elfcpp::R_386_PC16:
954 case elfcpp::R_386_PC8:
955 break;
956
df2efe71
ILT
957 case elfcpp::R_386_PLT32:
958 // Since we know this is a local symbol, we can handle this as a
959 // PC32 reloc.
960 break;
961
ead1e424
ILT
962 case elfcpp::R_386_GOTOFF:
963 case elfcpp::R_386_GOTPC:
964 // We need a GOT section.
7e1edb90 965 target->got_section(symtab, layout);
ead1e424
ILT
966 break;
967
1b64748b
ILT
968 case elfcpp::R_386_GOT32:
969 {
970 // The symbol requires a GOT entry.
971 Output_data_got<32, false>* got = target->got_section(symtab, layout);
972 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
0a65a3a7 973 if (got->add_local(object, r_sym, GOT_TYPE_STANDARD))
1b64748b
ILT
974 {
975 // If we are generating a shared object, we need to add a
7bf1f802 976 // dynamic RELATIVE relocation for this symbol's GOT entry.
8851ecca 977 if (parameters->options().output_is_position_independent())
1b64748b
ILT
978 {
979 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
e8c846c3 980 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
0a65a3a7
CC
981 rel_dyn->add_local_relative(
982 object, r_sym, elfcpp::R_386_RELATIVE, got,
983 object->local_got_offset(r_sym, GOT_TYPE_STANDARD));
1b64748b
ILT
984 }
985 }
986 }
987 break;
988
af6359d5
ILT
989 // These are relocations which should only be seen by the
990 // dynamic linker, and should never be seen here.
92e059d8
ILT
991 case elfcpp::R_386_COPY:
992 case elfcpp::R_386_GLOB_DAT:
993 case elfcpp::R_386_JUMP_SLOT:
994 case elfcpp::R_386_RELATIVE:
995 case elfcpp::R_386_TLS_TPOFF:
996 case elfcpp::R_386_TLS_DTPMOD32:
997 case elfcpp::R_386_TLS_DTPOFF32:
998 case elfcpp::R_386_TLS_TPOFF32:
999 case elfcpp::R_386_TLS_DESC:
a0c4fb0a 1000 gold_error(_("%s: unexpected reloc %u in object file"),
75f2446e 1001 object->name().c_str(), r_type);
92e059d8
ILT
1002 break;
1003
af6359d5 1004 // These are initial TLS relocs, which are expected when
d61c17ea 1005 // linking.
56622147
ILT
1006 case elfcpp::R_386_TLS_GD: // Global-dynamic
1007 case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (from ~oliva url)
1008 case elfcpp::R_386_TLS_DESC_CALL:
1009 case elfcpp::R_386_TLS_LDM: // Local-dynamic
1010 case elfcpp::R_386_TLS_LDO_32: // Alternate local-dynamic
1011 case elfcpp::R_386_TLS_IE: // Initial-exec
92e059d8 1012 case elfcpp::R_386_TLS_IE_32:
56622147
ILT
1013 case elfcpp::R_386_TLS_GOTIE:
1014 case elfcpp::R_386_TLS_LE: // Local-exec
92e059d8 1015 case elfcpp::R_386_TLS_LE_32:
7e1edb90 1016 {
8851ecca 1017 bool output_is_shared = parameters->options().shared();
af6359d5
ILT
1018 const tls::Tls_optimization optimized_type
1019 = Target_i386::optimize_tls_reloc(!output_is_shared, r_type);
7e1edb90
ILT
1020 switch (r_type)
1021 {
56622147 1022 case elfcpp::R_386_TLS_GD: // Global-dynamic
07f397ab
ILT
1023 if (optimized_type == tls::TLSOPT_NONE)
1024 {
1025 // Create a pair of GOT entries for the module index and
1026 // dtv-relative offset.
1027 Output_data_got<32, false>* got
1028 = target->got_section(symtab, layout);
1029 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
d491d34e
ILT
1030 unsigned int shndx = lsym.get_st_shndx();
1031 bool is_ordinary;
1032 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
1033 if (!is_ordinary)
1034 object->error(_("local symbol %u has bad shndx %u"),
1035 r_sym, shndx);
1036 else
1037 got->add_local_pair_with_rel(object, r_sym, shndx,
1038 GOT_TYPE_TLS_PAIR,
1039 target->rel_dyn_section(layout),
1040 elfcpp::R_386_TLS_DTPMOD32, 0);
07f397ab
ILT
1041 }
1042 else if (optimized_type != tls::TLSOPT_TO_LE)
1043 unsupported_reloc_local(object, r_type);
1044 break;
1045
56622147 1046 case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (from ~oliva)
edfbb029 1047 target->define_tls_base_symbol(symtab, layout);
c2b45e22
CC
1048 if (optimized_type == tls::TLSOPT_NONE)
1049 {
1050 // Create a double GOT entry with an R_386_TLS_DESC reloc.
1051 Output_data_got<32, false>* got
1052 = target->got_section(symtab, layout);
1053 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
d491d34e
ILT
1054 unsigned int shndx = lsym.get_st_shndx();
1055 bool is_ordinary;
1056 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
1057 if (!is_ordinary)
1058 object->error(_("local symbol %u has bad shndx %u"),
1059 r_sym, shndx);
1060 else
1061 got->add_local_pair_with_rel(object, r_sym, shndx,
1062 GOT_TYPE_TLS_DESC,
1063 target->rel_dyn_section(layout),
1064 elfcpp::R_386_TLS_DESC, 0);
c2b45e22
CC
1065 }
1066 else if (optimized_type != tls::TLSOPT_TO_LE)
7bf1f802 1067 unsupported_reloc_local(object, r_type);
af6359d5
ILT
1068 break;
1069
c2b45e22
CC
1070 case elfcpp::R_386_TLS_DESC_CALL:
1071 break;
1072
56622147 1073 case elfcpp::R_386_TLS_LDM: // Local-dynamic
07f397ab
ILT
1074 if (optimized_type == tls::TLSOPT_NONE)
1075 {
1076 // Create a GOT entry for the module index.
94c4710f 1077 target->got_mod_index_entry(symtab, layout, object);
07f397ab
ILT
1078 }
1079 else if (optimized_type != tls::TLSOPT_TO_LE)
af6359d5
ILT
1080 unsupported_reloc_local(object, r_type);
1081 break;
1082
56622147 1083 case elfcpp::R_386_TLS_LDO_32: // Alternate local-dynamic
46cf9fa2
ILT
1084 break;
1085
56622147
ILT
1086 case elfcpp::R_386_TLS_IE: // Initial-exec
1087 case elfcpp::R_386_TLS_IE_32:
1088 case elfcpp::R_386_TLS_GOTIE:
535890bb 1089 layout->set_has_static_tls();
07f397ab
ILT
1090 if (optimized_type == tls::TLSOPT_NONE)
1091 {
7bf1f802
ILT
1092 // For the R_386_TLS_IE relocation, we need to create a
1093 // dynamic relocation when building a shared library.
1094 if (r_type == elfcpp::R_386_TLS_IE
8851ecca 1095 && parameters->options().shared())
7bf1f802
ILT
1096 {
1097 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
e8c846c3
ILT
1098 unsigned int r_sym
1099 = elfcpp::elf_r_sym<32>(reloc.get_r_info());
1100 rel_dyn->add_local_relative(object, r_sym,
1101 elfcpp::R_386_RELATIVE,
1102 output_section, data_shndx,
1103 reloc.get_r_offset());
7bf1f802 1104 }
07f397ab
ILT
1105 // Create a GOT entry for the tp-relative offset.
1106 Output_data_got<32, false>* got
1107 = target->got_section(symtab, layout);
1108 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
7bf1f802
ILT
1109 unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_IE_32
1110 ? elfcpp::R_386_TLS_TPOFF32
1111 : elfcpp::R_386_TLS_TPOFF);
c2b45e22
CC
1112 unsigned int got_type = (r_type == elfcpp::R_386_TLS_IE_32
1113 ? GOT_TYPE_TLS_OFFSET
1114 : GOT_TYPE_TLS_NOFFSET);
1115 got->add_local_with_rel(object, r_sym, got_type,
7bf1f802
ILT
1116 target->rel_dyn_section(layout),
1117 dyn_r_type);
07f397ab
ILT
1118 }
1119 else if (optimized_type != tls::TLSOPT_TO_LE)
af6359d5 1120 unsupported_reloc_local(object, r_type);
7e1edb90 1121 break;
af6359d5 1122
56622147
ILT
1123 case elfcpp::R_386_TLS_LE: // Local-exec
1124 case elfcpp::R_386_TLS_LE_32:
535890bb 1125 layout->set_has_static_tls();
07f397ab 1126 if (output_is_shared)
7bf1f802
ILT
1127 {
1128 // We need to create a dynamic relocation.
dceae3c1 1129 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
7bf1f802
ILT
1130 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
1131 unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_LE_32
1132 ? elfcpp::R_386_TLS_TPOFF32
1133 : elfcpp::R_386_TLS_TPOFF);
1134 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1135 rel_dyn->add_local(object, r_sym, dyn_r_type, output_section,
1136 data_shndx, reloc.get_r_offset());
1137 }
56622147
ILT
1138 break;
1139
af6359d5
ILT
1140 default:
1141 gold_unreachable();
7e1edb90
ILT
1142 }
1143 }
92e059d8
ILT
1144 break;
1145
92e059d8
ILT
1146 case elfcpp::R_386_32PLT:
1147 case elfcpp::R_386_TLS_GD_32:
1148 case elfcpp::R_386_TLS_GD_PUSH:
1149 case elfcpp::R_386_TLS_GD_CALL:
1150 case elfcpp::R_386_TLS_GD_POP:
1151 case elfcpp::R_386_TLS_LDM_32:
1152 case elfcpp::R_386_TLS_LDM_PUSH:
1153 case elfcpp::R_386_TLS_LDM_CALL:
1154 case elfcpp::R_386_TLS_LDM_POP:
1155 case elfcpp::R_386_USED_BY_INTEL_200:
1156 default:
af6359d5 1157 unsupported_reloc_local(object, r_type);
92e059d8
ILT
1158 break;
1159 }
1160}
1161
af6359d5
ILT
1162// Report an unsupported relocation against a global symbol.
1163
1164void
1165Target_i386::Scan::unsupported_reloc_global(Sized_relobj<32, false>* object,
1166 unsigned int r_type,
1167 Symbol* gsym)
1168{
75f2446e 1169 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
a2b1aa12 1170 object->name().c_str(), r_type, gsym->demangled_name().c_str());
af6359d5
ILT
1171}
1172
92e059d8
ILT
1173// Scan a relocation for a global symbol.
1174
1175inline void
12c0daef 1176Target_i386::Scan::global(const General_options&,
ead1e424
ILT
1177 Symbol_table* symtab,
1178 Layout* layout,
1179 Target_i386* target,
f6ce93d6 1180 Sized_relobj<32, false>* object,
a3ad94ed 1181 unsigned int data_shndx,
07f397ab 1182 Output_section* output_section,
a3ad94ed
ILT
1183 const elfcpp::Rel<32, false>& reloc,
1184 unsigned int r_type,
92e059d8
ILT
1185 Symbol* gsym)
1186{
1187 switch (r_type)
1188 {
1189 case elfcpp::R_386_NONE:
1190 case elfcpp::R_386_GNU_VTINHERIT:
8462ae85 1191 case elfcpp::R_386_GNU_VTENTRY:
92e059d8
ILT
1192 break;
1193
1194 case elfcpp::R_386_32:
92e059d8 1195 case elfcpp::R_386_16:
92e059d8 1196 case elfcpp::R_386_8:
96f2030e 1197 {
d61c6bd4
ILT
1198 // Make a PLT entry if necessary.
1199 if (gsym->needs_plt_entry())
1200 {
1201 target->make_plt_entry(symtab, layout, gsym);
1202 // Since this is not a PC-relative relocation, we may be
1203 // taking the address of a function. In that case we need to
1204 // set the entry in the dynamic symbol table to the address of
1205 // the PLT entry.
8851ecca 1206 if (gsym->is_from_dynobj() && !parameters->options().shared())
d61c6bd4
ILT
1207 gsym->set_needs_dynsym_value();
1208 }
1209 // Make a dynamic relocation if necessary.
0700cf32 1210 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
d61c6bd4
ILT
1211 {
1212 if (target->may_need_copy_reloc(gsym))
1213 {
12c0daef 1214 target->copy_reloc(symtab, layout, object,
4f4c5f80 1215 data_shndx, output_section, gsym, reloc);
d61c6bd4
ILT
1216 }
1217 else if (r_type == elfcpp::R_386_32
1218 && gsym->can_use_relative_reloc(false))
1219 {
1220 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
e8c846c3
ILT
1221 rel_dyn->add_global_relative(gsym, elfcpp::R_386_RELATIVE,
1222 output_section, object,
1223 data_shndx, reloc.get_r_offset());
d61c6bd4
ILT
1224 }
1225 else
1226 {
96f2030e 1227 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
4f4c5f80
ILT
1228 rel_dyn->add_global(gsym, r_type, output_section, object,
1229 data_shndx, reloc.get_r_offset());
d61c6bd4
ILT
1230 }
1231 }
1232 }
1233 break;
1234
1235 case elfcpp::R_386_PC32:
1236 case elfcpp::R_386_PC16:
1237 case elfcpp::R_386_PC8:
1238 {
1239 // Make a PLT entry if necessary.
1240 if (gsym->needs_plt_entry())
7bf1f802
ILT
1241 {
1242 // These relocations are used for function calls only in
1243 // non-PIC code. For a 32-bit relocation in a shared library,
1244 // we'll need a text relocation anyway, so we can skip the
1245 // PLT entry and let the dynamic linker bind the call directly
1246 // to the target. For smaller relocations, we should use a
1247 // PLT entry to ensure that the call can reach.
8851ecca 1248 if (!parameters->options().shared()
7bf1f802
ILT
1249 || r_type != elfcpp::R_386_PC32)
1250 target->make_plt_entry(symtab, layout, gsym);
1251 }
d61c6bd4 1252 // Make a dynamic relocation if necessary.
0700cf32
ILT
1253 int flags = Symbol::NON_PIC_REF;
1254 if (gsym->type() == elfcpp::STT_FUNC)
1255 flags |= Symbol::FUNCTION_CALL;
1256 if (gsym->needs_dynamic_reloc(flags))
96f2030e 1257 {
d61c6bd4
ILT
1258 if (target->may_need_copy_reloc(gsym))
1259 {
12c0daef 1260 target->copy_reloc(symtab, layout, object,
4f4c5f80 1261 data_shndx, output_section, gsym, reloc);
d61c6bd4 1262 }
86849f1f 1263 else
d61c6bd4
ILT
1264 {
1265 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
4f4c5f80
ILT
1266 rel_dyn->add_global(gsym, r_type, output_section, object,
1267 data_shndx, reloc.get_r_offset());
d61c6bd4 1268 }
96f2030e
ILT
1269 }
1270 }
92e059d8
ILT
1271 break;
1272
ead1e424 1273 case elfcpp::R_386_GOT32:
8462ae85
ILT
1274 {
1275 // The symbol requires a GOT entry.
7e1edb90 1276 Output_data_got<32, false>* got = target->got_section(symtab, layout);
7bf1f802 1277 if (gsym->final_value_is_known())
0a65a3a7 1278 got->add_global(gsym, GOT_TYPE_STANDARD);
7bf1f802
ILT
1279 else
1280 {
8462ae85 1281 // If this symbol is not fully resolved, we need to add a
7bf1f802
ILT
1282 // GOT entry with a dynamic relocation.
1283 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
8fc19601
ILT
1284 if (gsym->is_from_dynobj()
1285 || gsym->is_undefined()
1286 || gsym->is_preemptible())
0a65a3a7
CC
1287 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD,
1288 rel_dyn, elfcpp::R_386_GLOB_DAT);
7bf1f802 1289 else
8462ae85 1290 {
0a65a3a7
CC
1291 if (got->add_global(gsym, GOT_TYPE_STANDARD))
1292 rel_dyn->add_global_relative(
1293 gsym, elfcpp::R_386_RELATIVE, got,
1294 gsym->got_offset(GOT_TYPE_STANDARD));
8462ae85
ILT
1295 }
1296 }
1297 }
ead1e424
ILT
1298 break;
1299
1300 case elfcpp::R_386_PLT32:
a3ad94ed
ILT
1301 // If the symbol is fully resolved, this is just a PC32 reloc.
1302 // Otherwise we need a PLT entry.
7e1edb90 1303 if (gsym->final_value_is_known())
ead1e424 1304 break;
436ca963
ILT
1305 // If building a shared library, we can also skip the PLT entry
1306 // if the symbol is defined in the output file and is protected
1307 // or hidden.
1308 if (gsym->is_defined()
1309 && !gsym->is_from_dynobj()
1310 && !gsym->is_preemptible())
1311 break;
7e1edb90 1312 target->make_plt_entry(symtab, layout, gsym);
ead1e424
ILT
1313 break;
1314
1315 case elfcpp::R_386_GOTOFF:
1316 case elfcpp::R_386_GOTPC:
1317 // We need a GOT section.
7e1edb90 1318 target->got_section(symtab, layout);
ead1e424
ILT
1319 break;
1320
af6359d5
ILT
1321 // These are relocations which should only be seen by the
1322 // dynamic linker, and should never be seen here.
92e059d8
ILT
1323 case elfcpp::R_386_COPY:
1324 case elfcpp::R_386_GLOB_DAT:
1325 case elfcpp::R_386_JUMP_SLOT:
1326 case elfcpp::R_386_RELATIVE:
1327 case elfcpp::R_386_TLS_TPOFF:
1328 case elfcpp::R_386_TLS_DTPMOD32:
1329 case elfcpp::R_386_TLS_DTPOFF32:
1330 case elfcpp::R_386_TLS_TPOFF32:
1331 case elfcpp::R_386_TLS_DESC:
75f2446e
ILT
1332 gold_error(_("%s: unexpected reloc %u in object file"),
1333 object->name().c_str(), r_type);
92e059d8
ILT
1334 break;
1335
d61c17ea
ILT
1336 // These are initial tls relocs, which are expected when
1337 // linking.
56622147
ILT
1338 case elfcpp::R_386_TLS_GD: // Global-dynamic
1339 case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (from ~oliva url)
1340 case elfcpp::R_386_TLS_DESC_CALL:
1341 case elfcpp::R_386_TLS_LDM: // Local-dynamic
1342 case elfcpp::R_386_TLS_LDO_32: // Alternate local-dynamic
1343 case elfcpp::R_386_TLS_IE: // Initial-exec
92e059d8 1344 case elfcpp::R_386_TLS_IE_32:
56622147
ILT
1345 case elfcpp::R_386_TLS_GOTIE:
1346 case elfcpp::R_386_TLS_LE: // Local-exec
92e059d8 1347 case elfcpp::R_386_TLS_LE_32:
a3ad94ed 1348 {
7e1edb90 1349 const bool is_final = gsym->final_value_is_known();
af6359d5
ILT
1350 const tls::Tls_optimization optimized_type
1351 = Target_i386::optimize_tls_reloc(is_final, r_type);
a3ad94ed
ILT
1352 switch (r_type)
1353 {
56622147 1354 case elfcpp::R_386_TLS_GD: // Global-dynamic
07f397ab
ILT
1355 if (optimized_type == tls::TLSOPT_NONE)
1356 {
1357 // Create a pair of GOT entries for the module index and
1358 // dtv-relative offset.
1359 Output_data_got<32, false>* got
1360 = target->got_section(symtab, layout);
0a65a3a7 1361 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
7bf1f802
ILT
1362 target->rel_dyn_section(layout),
1363 elfcpp::R_386_TLS_DTPMOD32,
1364 elfcpp::R_386_TLS_DTPOFF32);
07f397ab
ILT
1365 }
1366 else if (optimized_type == tls::TLSOPT_TO_IE)
1367 {
1368 // Create a GOT entry for the tp-relative offset.
1369 Output_data_got<32, false>* got
1370 = target->got_section(symtab, layout);
c2b45e22 1371 got->add_global_with_rel(gsym, GOT_TYPE_TLS_NOFFSET,
0a65a3a7 1372 target->rel_dyn_section(layout),
c2b45e22 1373 elfcpp::R_386_TLS_TPOFF);
07f397ab
ILT
1374 }
1375 else if (optimized_type != tls::TLSOPT_TO_LE)
1376 unsupported_reloc_global(object, r_type, gsym);
1377 break;
1378
56622147 1379 case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (~oliva url)
edfbb029 1380 target->define_tls_base_symbol(symtab, layout);
c2b45e22
CC
1381 if (optimized_type == tls::TLSOPT_NONE)
1382 {
1383 // Create a double GOT entry with an R_386_TLS_DESC reloc.
1384 Output_data_got<32, false>* got
1385 = target->got_section(symtab, layout);
1386 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_DESC,
1387 target->rel_dyn_section(layout),
1388 elfcpp::R_386_TLS_DESC, 0);
1389 }
1390 else if (optimized_type == tls::TLSOPT_TO_IE)
1391 {
1392 // Create a GOT entry for the tp-relative offset.
1393 Output_data_got<32, false>* got
1394 = target->got_section(symtab, layout);
1395 got->add_global_with_rel(gsym, GOT_TYPE_TLS_NOFFSET,
1396 target->rel_dyn_section(layout),
1397 elfcpp::R_386_TLS_TPOFF);
1398 }
1399 else if (optimized_type != tls::TLSOPT_TO_LE)
7bf1f802 1400 unsupported_reloc_global(object, r_type, gsym);
c2b45e22
CC
1401 break;
1402
1403 case elfcpp::R_386_TLS_DESC_CALL:
af6359d5
ILT
1404 break;
1405
56622147 1406 case elfcpp::R_386_TLS_LDM: // Local-dynamic
07f397ab
ILT
1407 if (optimized_type == tls::TLSOPT_NONE)
1408 {
1409 // Create a GOT entry for the module index.
94c4710f 1410 target->got_mod_index_entry(symtab, layout, object);
07f397ab
ILT
1411 }
1412 else if (optimized_type != tls::TLSOPT_TO_LE)
af6359d5
ILT
1413 unsupported_reloc_global(object, r_type, gsym);
1414 break;
1415
56622147 1416 case elfcpp::R_386_TLS_LDO_32: // Alternate local-dynamic
46cf9fa2
ILT
1417 break;
1418
56622147
ILT
1419 case elfcpp::R_386_TLS_IE: // Initial-exec
1420 case elfcpp::R_386_TLS_IE_32:
1421 case elfcpp::R_386_TLS_GOTIE:
535890bb 1422 layout->set_has_static_tls();
07f397ab
ILT
1423 if (optimized_type == tls::TLSOPT_NONE)
1424 {
7bf1f802
ILT
1425 // For the R_386_TLS_IE relocation, we need to create a
1426 // dynamic relocation when building a shared library.
1427 if (r_type == elfcpp::R_386_TLS_IE
8851ecca 1428 && parameters->options().shared())
07f397ab 1429 {
07f397ab 1430 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
e8c846c3
ILT
1431 rel_dyn->add_global_relative(gsym, elfcpp::R_386_RELATIVE,
1432 output_section, object,
1433 data_shndx,
1434 reloc.get_r_offset());
07f397ab 1435 }
7bf1f802
ILT
1436 // Create a GOT entry for the tp-relative offset.
1437 Output_data_got<32, false>* got
1438 = target->got_section(symtab, layout);
1439 unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_IE_32
1440 ? elfcpp::R_386_TLS_TPOFF32
1441 : elfcpp::R_386_TLS_TPOFF);
c2b45e22
CC
1442 unsigned int got_type = (r_type == elfcpp::R_386_TLS_IE_32
1443 ? GOT_TYPE_TLS_OFFSET
1444 : GOT_TYPE_TLS_NOFFSET);
1445 got->add_global_with_rel(gsym, got_type,
7bf1f802
ILT
1446 target->rel_dyn_section(layout),
1447 dyn_r_type);
07f397ab
ILT
1448 }
1449 else if (optimized_type != tls::TLSOPT_TO_LE)
af6359d5 1450 unsupported_reloc_global(object, r_type, gsym);
a3ad94ed 1451 break;
af6359d5 1452
56622147
ILT
1453 case elfcpp::R_386_TLS_LE: // Local-exec
1454 case elfcpp::R_386_TLS_LE_32:
535890bb 1455 layout->set_has_static_tls();
8851ecca 1456 if (parameters->options().shared())
7bf1f802
ILT
1457 {
1458 // We need to create a dynamic relocation.
1459 unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_LE_32
1460 ? elfcpp::R_386_TLS_TPOFF32
1461 : elfcpp::R_386_TLS_TPOFF);
1462 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1463 rel_dyn->add_global(gsym, dyn_r_type, output_section, object,
1464 data_shndx, reloc.get_r_offset());
1465 }
56622147
ILT
1466 break;
1467
af6359d5
ILT
1468 default:
1469 gold_unreachable();
a3ad94ed
ILT
1470 }
1471 }
92e059d8
ILT
1472 break;
1473
92e059d8
ILT
1474 case elfcpp::R_386_32PLT:
1475 case elfcpp::R_386_TLS_GD_32:
1476 case elfcpp::R_386_TLS_GD_PUSH:
1477 case elfcpp::R_386_TLS_GD_CALL:
1478 case elfcpp::R_386_TLS_GD_POP:
1479 case elfcpp::R_386_TLS_LDM_32:
1480 case elfcpp::R_386_TLS_LDM_PUSH:
1481 case elfcpp::R_386_TLS_LDM_CALL:
1482 case elfcpp::R_386_TLS_LDM_POP:
1483 case elfcpp::R_386_USED_BY_INTEL_200:
1484 default:
af6359d5 1485 unsupported_reloc_global(object, r_type, gsym);
92e059d8
ILT
1486 break;
1487 }
1488}
1489
6d03d481
ST
1490// Process relocations for gc.
1491
1492void
1493Target_i386::gc_process_relocs(const General_options& options,
1494 Symbol_table* symtab,
1495 Layout* layout,
1496 Sized_relobj<32, false>* object,
1497 unsigned int data_shndx,
1498 unsigned int,
1499 const unsigned char* prelocs,
1500 size_t reloc_count,
1501 Output_section* output_section,
1502 bool needs_special_offset_handling,
1503 size_t local_symbol_count,
1504 const unsigned char* plocal_symbols)
1505{
1506 gold::gc_process_relocs<32, false, Target_i386, elfcpp::SHT_REL,
1507 Target_i386::Scan>(
1508 options,
1509 symtab,
1510 layout,
1511 this,
1512 object,
1513 data_shndx,
1514 prelocs,
1515 reloc_count,
1516 output_section,
1517 needs_special_offset_handling,
1518 local_symbol_count,
1519 plocal_symbols);
1520}
1521
92e059d8
ILT
1522// Scan relocations for a section.
1523
1524void
1525Target_i386::scan_relocs(const General_options& options,
1526 Symbol_table* symtab,
ead1e424 1527 Layout* layout,
f6ce93d6 1528 Sized_relobj<32, false>* object,
a3ad94ed 1529 unsigned int data_shndx,
92e059d8
ILT
1530 unsigned int sh_type,
1531 const unsigned char* prelocs,
1532 size_t reloc_count,
730cdc88
ILT
1533 Output_section* output_section,
1534 bool needs_special_offset_handling,
92e059d8 1535 size_t local_symbol_count,
730cdc88 1536 const unsigned char* plocal_symbols)
92e059d8
ILT
1537{
1538 if (sh_type == elfcpp::SHT_RELA)
1539 {
75f2446e
ILT
1540 gold_error(_("%s: unsupported RELA reloc section"),
1541 object->name().c_str());
1542 return;
92e059d8
ILT
1543 }
1544
ead1e424
ILT
1545 gold::scan_relocs<32, false, Target_i386, elfcpp::SHT_REL,
1546 Target_i386::Scan>(
92e059d8
ILT
1547 options,
1548 symtab,
ead1e424
ILT
1549 layout,
1550 this,
92e059d8 1551 object,
a3ad94ed 1552 data_shndx,
92e059d8
ILT
1553 prelocs,
1554 reloc_count,
730cdc88
ILT
1555 output_section,
1556 needs_special_offset_handling,
92e059d8 1557 local_symbol_count,
730cdc88 1558 plocal_symbols);
92e059d8
ILT
1559}
1560
16649710 1561// Finalize the sections.
5a6f7e2d
ILT
1562
1563void
7e1edb90 1564Target_i386::do_finalize_sections(Layout* layout)
5a6f7e2d 1565{
16649710
ILT
1566 // Fill in some more dynamic tags.
1567 Output_data_dynamic* const odyn = layout->dynamic_data();
1568 if (odyn != NULL)
1569 {
1570 if (this->got_plt_ != NULL)
1571 odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_);
1572
1573 if (this->plt_ != NULL)
1574 {
1575 const Output_data* od = this->plt_->rel_plt();
1576 odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
1577 odyn->add_section_address(elfcpp::DT_JMPREL, od);
1578 odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_REL);
1579 }
1580
1581 if (this->rel_dyn_ != NULL)
1582 {
1583 const Output_data* od = this->rel_dyn_;
1584 odyn->add_section_address(elfcpp::DT_REL, od);
1585 odyn->add_section_size(elfcpp::DT_RELSZ, od);
1586 odyn->add_constant(elfcpp::DT_RELENT,
1587 elfcpp::Elf_sizes<32>::rel_size);
1588 }
1589
8851ecca 1590 if (!parameters->options().shared())
16649710
ILT
1591 {
1592 // The value of the DT_DEBUG tag is filled in by the dynamic
1593 // linker at run time, and used by the debugger.
1594 odyn->add_constant(elfcpp::DT_DEBUG, 0);
1595 }
1596 }
1597
1598 // Emit any relocs we saved in an attempt to avoid generating COPY
1599 // relocs.
12c0daef
ILT
1600 if (this->copy_relocs_.any_saved_relocs())
1601 this->copy_relocs_.emit(this->rel_dyn_section(layout));
5a6f7e2d
ILT
1602}
1603
86849f1f
ILT
1604// Return whether a direct absolute static relocation needs to be applied.
1605// In cases where Scan::local() or Scan::global() has created
1606// a dynamic relocation other than R_386_RELATIVE, the addend
1607// of the relocation is carried in the data, and we must not
1608// apply the static relocation.
1609
1610inline bool
1611Target_i386::Relocate::should_apply_static_reloc(const Sized_symbol<32>* gsym,
0700cf32 1612 int ref_flags,
031cdbed
ILT
1613 bool is_32bit,
1614 Output_section* output_section)
86849f1f 1615{
031cdbed
ILT
1616 // If the output section is not allocated, then we didn't call
1617 // scan_relocs, we didn't create a dynamic reloc, and we must apply
1618 // the reloc here.
1619 if ((output_section->flags() & elfcpp::SHF_ALLOC) == 0)
1620 return true;
1621
d61c6bd4
ILT
1622 // For local symbols, we will have created a non-RELATIVE dynamic
1623 // relocation only if (a) the output is position independent,
1624 // (b) the relocation is absolute (not pc- or segment-relative), and
1625 // (c) the relocation is not 32 bits wide.
86849f1f 1626 if (gsym == NULL)
8851ecca 1627 return !(parameters->options().output_is_position_independent()
0700cf32 1628 && (ref_flags & Symbol::ABSOLUTE_REF)
d61c6bd4 1629 && !is_32bit);
86849f1f 1630
0700cf32
ILT
1631 // For global symbols, we use the same helper routines used in the
1632 // scan pass. If we did not create a dynamic relocation, or if we
1633 // created a RELATIVE dynamic relocation, we should apply the static
1634 // relocation.
1635 bool has_dyn = gsym->needs_dynamic_reloc(ref_flags);
1636 bool is_rel = (ref_flags & Symbol::ABSOLUTE_REF)
1637 && gsym->can_use_relative_reloc(ref_flags
1638 & Symbol::FUNCTION_CALL);
1639 return !has_dyn || is_rel;
86849f1f
ILT
1640}
1641
61ba1cf9
ILT
1642// Perform a relocation.
1643
ead1e424 1644inline bool
92e059d8 1645Target_i386::Relocate::relocate(const Relocate_info<32, false>* relinfo,
ead1e424 1646 Target_i386* target,
031cdbed 1647 Output_section *output_section,
92e059d8
ILT
1648 size_t relnum,
1649 const elfcpp::Rel<32, false>& rel,
1650 unsigned int r_type,
c06b7b0b 1651 const Sized_symbol<32>* gsym,
b8e6aad9 1652 const Symbol_value<32>* psymval,
92e059d8
ILT
1653 unsigned char* view,
1654 elfcpp::Elf_types<32>::Elf_Addr address,
fe8718a4 1655 section_size_type view_size)
61ba1cf9 1656{
ead1e424
ILT
1657 if (this->skip_call_tls_get_addr_)
1658 {
5efc7cd2
CC
1659 if ((r_type != elfcpp::R_386_PLT32
1660 && r_type != elfcpp::R_386_PC32)
ead1e424
ILT
1661 || gsym == NULL
1662 || strcmp(gsym->name(), "___tls_get_addr") != 0)
75f2446e
ILT
1663 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1664 _("missing expected TLS relocation"));
1665 else
ead1e424 1666 {
75f2446e
ILT
1667 this->skip_call_tls_get_addr_ = false;
1668 return false;
ead1e424 1669 }
ead1e424
ILT
1670 }
1671
a3ad94ed 1672 // Pick the value to use for symbols defined in shared objects.
b8e6aad9 1673 Symbol_value<32> symval;
436ca963 1674 if (gsym != NULL
de4c45bd
ILT
1675 && gsym->use_plt_offset(r_type == elfcpp::R_386_PC8
1676 || r_type == elfcpp::R_386_PC16
1677 || r_type == elfcpp::R_386_PC32))
a3ad94ed 1678 {
b8e6aad9
ILT
1679 symval.set_output_value(target->plt_section()->address()
1680 + gsym->plt_offset());
1681 psymval = &symval;
a3ad94ed
ILT
1682 }
1683
b8e6aad9
ILT
1684 const Sized_relobj<32, false>* object = relinfo->object;
1685
1b64748b 1686 // Get the GOT offset if needed.
96f2030e
ILT
1687 // The GOT pointer points to the end of the GOT section.
1688 // We need to subtract the size of the GOT section to get
1689 // the actual offset to use in the relocation.
1b64748b
ILT
1690 bool have_got_offset = false;
1691 unsigned int got_offset = 0;
1692 switch (r_type)
1693 {
1694 case elfcpp::R_386_GOT32:
1695 if (gsym != NULL)
1696 {
0a65a3a7
CC
1697 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
1698 got_offset = (gsym->got_offset(GOT_TYPE_STANDARD)
1699 - target->got_size());
1b64748b
ILT
1700 }
1701 else
1702 {
1703 unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
0a65a3a7
CC
1704 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
1705 got_offset = (object->local_got_offset(r_sym, GOT_TYPE_STANDARD)
1706 - target->got_size());
1b64748b
ILT
1707 }
1708 have_got_offset = true;
1709 break;
1710
1711 default:
1712 break;
1713 }
1714
61ba1cf9
ILT
1715 switch (r_type)
1716 {
1717 case elfcpp::R_386_NONE:
92e059d8
ILT
1718 case elfcpp::R_386_GNU_VTINHERIT:
1719 case elfcpp::R_386_GNU_VTENTRY:
61ba1cf9
ILT
1720 break;
1721
1722 case elfcpp::R_386_32:
031cdbed
ILT
1723 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
1724 output_section))
86849f1f 1725 Relocate_functions<32, false>::rel32(view, object, psymval);
61ba1cf9
ILT
1726 break;
1727
1728 case elfcpp::R_386_PC32:
d61c6bd4 1729 {
0700cf32
ILT
1730 int ref_flags = Symbol::NON_PIC_REF;
1731 if (gsym != NULL && gsym->type() == elfcpp::STT_FUNC)
1732 ref_flags |= Symbol::FUNCTION_CALL;
031cdbed 1733 if (should_apply_static_reloc(gsym, ref_flags, true, output_section))
d61c6bd4
ILT
1734 Relocate_functions<32, false>::pcrel32(view, object, psymval, address);
1735 }
92e059d8
ILT
1736 break;
1737
1738 case elfcpp::R_386_16:
031cdbed
ILT
1739 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
1740 output_section))
86849f1f 1741 Relocate_functions<32, false>::rel16(view, object, psymval);
92e059d8
ILT
1742 break;
1743
1744 case elfcpp::R_386_PC16:
d61c6bd4 1745 {
0700cf32
ILT
1746 int ref_flags = Symbol::NON_PIC_REF;
1747 if (gsym != NULL && gsym->type() == elfcpp::STT_FUNC)
1748 ref_flags |= Symbol::FUNCTION_CALL;
031cdbed 1749 if (should_apply_static_reloc(gsym, ref_flags, false, output_section))
d09e9154 1750 Relocate_functions<32, false>::pcrel16(view, object, psymval, address);
d61c6bd4 1751 }
61ba1cf9
ILT
1752 break;
1753
92e059d8 1754 case elfcpp::R_386_8:
031cdbed
ILT
1755 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
1756 output_section))
86849f1f 1757 Relocate_functions<32, false>::rel8(view, object, psymval);
92e059d8
ILT
1758 break;
1759
1760 case elfcpp::R_386_PC8:
d61c6bd4 1761 {
0700cf32
ILT
1762 int ref_flags = Symbol::NON_PIC_REF;
1763 if (gsym != NULL && gsym->type() == elfcpp::STT_FUNC)
1764 ref_flags |= Symbol::FUNCTION_CALL;
031cdbed
ILT
1765 if (should_apply_static_reloc(gsym, ref_flags, false,
1766 output_section))
d09e9154 1767 Relocate_functions<32, false>::pcrel8(view, object, psymval, address);
d61c6bd4 1768 }
92e059d8
ILT
1769 break;
1770
ead1e424 1771 case elfcpp::R_386_PLT32:
df2efe71
ILT
1772 gold_assert(gsym == NULL
1773 || gsym->has_plt_offset()
99f8faca
ILT
1774 || gsym->final_value_is_known()
1775 || (gsym->is_defined()
1776 && !gsym->is_from_dynobj()
1777 && !gsym->is_preemptible()));
b8e6aad9 1778 Relocate_functions<32, false>::pcrel32(view, object, psymval, address);
ead1e424
ILT
1779 break;
1780
1781 case elfcpp::R_386_GOT32:
1b64748b
ILT
1782 gold_assert(have_got_offset);
1783 Relocate_functions<32, false>::rel32(view, got_offset);
ead1e424
ILT
1784 break;
1785
1786 case elfcpp::R_386_GOTOFF:
b8e6aad9
ILT
1787 {
1788 elfcpp::Elf_types<32>::Elf_Addr value;
1789 value = (psymval->value(object, 0)
96f2030e 1790 - target->got_plt_section()->address());
b8e6aad9
ILT
1791 Relocate_functions<32, false>::rel32(view, value);
1792 }
ead1e424
ILT
1793 break;
1794
1795 case elfcpp::R_386_GOTPC:
b8e6aad9
ILT
1796 {
1797 elfcpp::Elf_types<32>::Elf_Addr value;
96f2030e 1798 value = target->got_plt_section()->address();
b8e6aad9
ILT
1799 Relocate_functions<32, false>::pcrel32(view, value, address);
1800 }
ead1e424
ILT
1801 break;
1802
92e059d8
ILT
1803 case elfcpp::R_386_COPY:
1804 case elfcpp::R_386_GLOB_DAT:
1805 case elfcpp::R_386_JUMP_SLOT:
1806 case elfcpp::R_386_RELATIVE:
d61c17ea
ILT
1807 // These are outstanding tls relocs, which are unexpected when
1808 // linking.
92e059d8
ILT
1809 case elfcpp::R_386_TLS_TPOFF:
1810 case elfcpp::R_386_TLS_DTPMOD32:
1811 case elfcpp::R_386_TLS_DTPOFF32:
1812 case elfcpp::R_386_TLS_TPOFF32:
1813 case elfcpp::R_386_TLS_DESC:
75f2446e
ILT
1814 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1815 _("unexpected reloc %u in object file"),
1816 r_type);
92e059d8
ILT
1817 break;
1818
d61c17ea
ILT
1819 // These are initial tls relocs, which are expected when
1820 // linking.
56622147
ILT
1821 case elfcpp::R_386_TLS_GD: // Global-dynamic
1822 case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (from ~oliva url)
1823 case elfcpp::R_386_TLS_DESC_CALL:
1824 case elfcpp::R_386_TLS_LDM: // Local-dynamic
1825 case elfcpp::R_386_TLS_LDO_32: // Alternate local-dynamic
1826 case elfcpp::R_386_TLS_IE: // Initial-exec
92e059d8 1827 case elfcpp::R_386_TLS_IE_32:
56622147
ILT
1828 case elfcpp::R_386_TLS_GOTIE:
1829 case elfcpp::R_386_TLS_LE: // Local-exec
92e059d8 1830 case elfcpp::R_386_TLS_LE_32:
07f397ab
ILT
1831 this->relocate_tls(relinfo, target, relnum, rel, r_type, gsym, psymval,
1832 view, address, view_size);
92e059d8
ILT
1833 break;
1834
92e059d8
ILT
1835 case elfcpp::R_386_32PLT:
1836 case elfcpp::R_386_TLS_GD_32:
1837 case elfcpp::R_386_TLS_GD_PUSH:
1838 case elfcpp::R_386_TLS_GD_CALL:
1839 case elfcpp::R_386_TLS_GD_POP:
1840 case elfcpp::R_386_TLS_LDM_32:
1841 case elfcpp::R_386_TLS_LDM_PUSH:
1842 case elfcpp::R_386_TLS_LDM_CALL:
1843 case elfcpp::R_386_TLS_LDM_POP:
1844 case elfcpp::R_386_USED_BY_INTEL_200:
61ba1cf9 1845 default:
75f2446e
ILT
1846 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1847 _("unsupported reloc %u"),
1848 r_type);
92e059d8
ILT
1849 break;
1850 }
ead1e424
ILT
1851
1852 return true;
92e059d8
ILT
1853}
1854
1855// Perform a TLS relocation.
1856
1857inline void
1858Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
07f397ab 1859 Target_i386* target,
92e059d8
ILT
1860 size_t relnum,
1861 const elfcpp::Rel<32, false>& rel,
1862 unsigned int r_type,
c06b7b0b 1863 const Sized_symbol<32>* gsym,
b8e6aad9 1864 const Symbol_value<32>* psymval,
92e059d8
ILT
1865 unsigned char* view,
1866 elfcpp::Elf_types<32>::Elf_Addr,
fe8718a4 1867 section_size_type view_size)
92e059d8
ILT
1868{
1869 Output_segment* tls_segment = relinfo->layout->tls_segment();
92e059d8 1870
07f397ab
ILT
1871 const Sized_relobj<32, false>* object = relinfo->object;
1872
1873 elfcpp::Elf_types<32>::Elf_Addr value = psymval->value(object, 0);
b8e6aad9 1874
8851ecca
ILT
1875 const bool is_final =
1876 (gsym == NULL
1877 ? !parameters->options().output_is_position_independent()
1878 : gsym->final_value_is_known());
af6359d5
ILT
1879 const tls::Tls_optimization optimized_type
1880 = Target_i386::optimize_tls_reloc(is_final, r_type);
92e059d8
ILT
1881 switch (r_type)
1882 {
56622147 1883 case elfcpp::R_386_TLS_GD: // Global-dynamic
af6359d5 1884 if (optimized_type == tls::TLSOPT_TO_LE)
92e059d8 1885 {
07f397ab 1886 gold_assert(tls_segment != NULL);
56622147
ILT
1887 this->tls_gd_to_le(relinfo, relnum, tls_segment,
1888 rel, r_type, value, view,
1889 view_size);
92e059d8
ILT
1890 break;
1891 }
07f397ab
ILT
1892 else
1893 {
c2b45e22
CC
1894 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
1895 ? GOT_TYPE_TLS_NOFFSET
1896 : GOT_TYPE_TLS_PAIR);
07f397ab
ILT
1897 unsigned int got_offset;
1898 if (gsym != NULL)
1899 {
c2b45e22
CC
1900 gold_assert(gsym->has_got_offset(got_type));
1901 got_offset = gsym->got_offset(got_type) - target->got_size();
07f397ab
ILT
1902 }
1903 else
1904 {
1905 unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
c2b45e22
CC
1906 gold_assert(object->local_has_got_offset(r_sym, got_type));
1907 got_offset = (object->local_got_offset(r_sym, got_type)
07f397ab
ILT
1908 - target->got_size());
1909 }
1910 if (optimized_type == tls::TLSOPT_TO_IE)
1911 {
1912 gold_assert(tls_segment != NULL);
7bf1f802
ILT
1913 this->tls_gd_to_ie(relinfo, relnum, tls_segment, rel, r_type,
1914 got_offset, view, view_size);
07f397ab
ILT
1915 break;
1916 }
1917 else if (optimized_type == tls::TLSOPT_NONE)
1918 {
1919 // Relocate the field with the offset of the pair of GOT
1920 // entries.
1921 Relocate_functions<32, false>::rel32(view, got_offset);
1922 break;
1923 }
1924 }
75f2446e
ILT
1925 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1926 _("unsupported reloc %u"),
1927 r_type);
92e059d8
ILT
1928 break;
1929
56622147
ILT
1930 case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (from ~oliva url)
1931 case elfcpp::R_386_TLS_DESC_CALL:
497897f9 1932 this->local_dynamic_type_ = LOCAL_DYNAMIC_GNU;
c2b45e22
CC
1933 if (optimized_type == tls::TLSOPT_TO_LE)
1934 {
1935 gold_assert(tls_segment != NULL);
1936 this->tls_desc_gd_to_le(relinfo, relnum, tls_segment,
1937 rel, r_type, value, view,
1938 view_size);
1939 break;
1940 }
1941 else
1942 {
1943 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
1944 ? GOT_TYPE_TLS_NOFFSET
1945 : GOT_TYPE_TLS_DESC);
1946 unsigned int got_offset;
1947 if (gsym != NULL)
1948 {
1949 gold_assert(gsym->has_got_offset(got_type));
1950 got_offset = gsym->got_offset(got_type) - target->got_size();
1951 }
1952 else
1953 {
1954 unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
1955 gold_assert(object->local_has_got_offset(r_sym, got_type));
1956 got_offset = (object->local_got_offset(r_sym, got_type)
1957 - target->got_size());
1958 }
1959 if (optimized_type == tls::TLSOPT_TO_IE)
1960 {
1961 gold_assert(tls_segment != NULL);
1962 this->tls_desc_gd_to_ie(relinfo, relnum, tls_segment, rel, r_type,
1963 got_offset, view, view_size);
1964 break;
1965 }
1966 else if (optimized_type == tls::TLSOPT_NONE)
1967 {
1968 if (r_type == elfcpp::R_386_TLS_GOTDESC)
1969 {
1970 // Relocate the field with the offset of the pair of GOT
1971 // entries.
1972 Relocate_functions<32, false>::rel32(view, got_offset);
1973 }
1974 break;
1975 }
1976 }
75f2446e
ILT
1977 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1978 _("unsupported reloc %u"),
1979 r_type);
ead1e424
ILT
1980 break;
1981
56622147 1982 case elfcpp::R_386_TLS_LDM: // Local-dynamic
46cf9fa2
ILT
1983 if (this->local_dynamic_type_ == LOCAL_DYNAMIC_SUN)
1984 {
75f2446e
ILT
1985 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1986 _("both SUN and GNU model "
1987 "TLS relocations"));
1988 break;
46cf9fa2
ILT
1989 }
1990 this->local_dynamic_type_ = LOCAL_DYNAMIC_GNU;
af6359d5 1991 if (optimized_type == tls::TLSOPT_TO_LE)
46cf9fa2 1992 {
07f397ab 1993 gold_assert(tls_segment != NULL);
46cf9fa2
ILT
1994 this->tls_ld_to_le(relinfo, relnum, tls_segment, rel, r_type,
1995 value, view, view_size);
1996 break;
1997 }
07f397ab
ILT
1998 else if (optimized_type == tls::TLSOPT_NONE)
1999 {
2000 // Relocate the field with the offset of the GOT entry for
2001 // the module index.
2002 unsigned int got_offset;
94c4710f
ILT
2003 got_offset = (target->got_mod_index_entry(NULL, NULL, NULL)
2004 - target->got_size());
07f397ab
ILT
2005 Relocate_functions<32, false>::rel32(view, got_offset);
2006 break;
2007 }
75f2446e
ILT
2008 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
2009 _("unsupported reloc %u"),
2010 r_type);
46cf9fa2
ILT
2011 break;
2012
56622147 2013 case elfcpp::R_386_TLS_LDO_32: // Alternate local-dynamic
46cf9fa2
ILT
2014 // This reloc can appear in debugging sections, in which case we
2015 // won't see the TLS_LDM reloc. The local_dynamic_type field
2016 // tells us this.
497897f9
ILT
2017 if (optimized_type == tls::TLSOPT_TO_LE
2018 && this->local_dynamic_type_ != LOCAL_DYNAMIC_NONE)
94c4710f
ILT
2019 {
2020 gold_assert(tls_segment != NULL);
2021 value -= tls_segment->memsz();
2022 }
46cf9fa2
ILT
2023 Relocate_functions<32, false>::rel32(view, value);
2024 break;
2025
56622147
ILT
2026 case elfcpp::R_386_TLS_IE: // Initial-exec
2027 case elfcpp::R_386_TLS_GOTIE:
2028 case elfcpp::R_386_TLS_IE_32:
2029 if (optimized_type == tls::TLSOPT_TO_LE)
2030 {
07f397ab 2031 gold_assert(tls_segment != NULL);
56622147
ILT
2032 Target_i386::Relocate::tls_ie_to_le(relinfo, relnum, tls_segment,
2033 rel, r_type, value, view,
2034 view_size);
2035 break;
2036 }
07f397ab
ILT
2037 else if (optimized_type == tls::TLSOPT_NONE)
2038 {
2039 // Relocate the field with the offset of the GOT entry for
2040 // the tp-relative offset of the symbol.
c2b45e22
CC
2041 unsigned int got_type = (r_type == elfcpp::R_386_TLS_IE_32
2042 ? GOT_TYPE_TLS_OFFSET
2043 : GOT_TYPE_TLS_NOFFSET);
07f397ab
ILT
2044 unsigned int got_offset;
2045 if (gsym != NULL)
2046 {
c2b45e22
CC
2047 gold_assert(gsym->has_got_offset(got_type));
2048 got_offset = gsym->got_offset(got_type);
07f397ab
ILT
2049 }
2050 else
2051 {
2052 unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
c2b45e22
CC
2053 gold_assert(object->local_has_got_offset(r_sym, got_type));
2054 got_offset = object->local_got_offset(r_sym, got_type);
07f397ab
ILT
2055 }
2056 // For the R_386_TLS_IE relocation, we need to apply the
2057 // absolute address of the GOT entry.
2058 if (r_type == elfcpp::R_386_TLS_IE)
2059 got_offset += target->got_plt_section()->address();
2060 // All GOT offsets are relative to the end of the GOT.
2061 got_offset -= target->got_size();
2062 Relocate_functions<32, false>::rel32(view, got_offset);
2063 break;
2064 }
75f2446e
ILT
2065 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
2066 _("unsupported reloc %u"),
2067 r_type);
92e059d8 2068 break;
92e059d8 2069
56622147 2070 case elfcpp::R_386_TLS_LE: // Local-exec
7bf1f802
ILT
2071 // If we're creating a shared library, a dynamic relocation will
2072 // have been created for this location, so do not apply it now.
8851ecca 2073 if (!parameters->options().shared())
7bf1f802
ILT
2074 {
2075 gold_assert(tls_segment != NULL);
2076 value -= tls_segment->memsz();
2077 Relocate_functions<32, false>::rel32(view, value);
2078 }
56622147 2079 break;
92e059d8 2080
56622147 2081 case elfcpp::R_386_TLS_LE_32:
7bf1f802
ILT
2082 // If we're creating a shared library, a dynamic relocation will
2083 // have been created for this location, so do not apply it now.
8851ecca 2084 if (!parameters->options().shared())
7bf1f802
ILT
2085 {
2086 gold_assert(tls_segment != NULL);
2087 value = tls_segment->memsz() - value;
2088 Relocate_functions<32, false>::rel32(view, value);
2089 }
56622147 2090 break;
92e059d8 2091 }
92e059d8
ILT
2092}
2093
e041f13d 2094// Do a relocation in which we convert a TLS General-Dynamic to a
ead1e424
ILT
2095// Local-Exec.
2096
2097inline void
2098Target_i386::Relocate::tls_gd_to_le(const Relocate_info<32, false>* relinfo,
2099 size_t relnum,
2100 Output_segment* tls_segment,
2101 const elfcpp::Rel<32, false>& rel,
2102 unsigned int,
2103 elfcpp::Elf_types<32>::Elf_Addr value,
2104 unsigned char* view,
fe8718a4 2105 section_size_type view_size)
ead1e424
ILT
2106{
2107 // leal foo(,%reg,1),%eax; call ___tls_get_addr
46cf9fa2 2108 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
ead1e424
ILT
2109 // leal foo(%reg),%eax; call ___tls_get_addr
2110 // ==> movl %gs:0,%eax; subl $foo@tpoff,%eax
2111
af6359d5
ILT
2112 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -2);
2113 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 9);
ead1e424
ILT
2114
2115 unsigned char op1 = view[-1];
2116 unsigned char op2 = view[-2];
2117
af6359d5
ILT
2118 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2119 op2 == 0x8d || op2 == 0x04);
2120 tls::check_tls(relinfo, relnum, rel.get_r_offset(), view[4] == 0xe8);
ead1e424
ILT
2121
2122 int roff = 5;
2123
2124 if (op2 == 0x04)
2125 {
af6359d5
ILT
2126 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -3);
2127 tls::check_tls(relinfo, relnum, rel.get_r_offset(), view[-3] == 0x8d);
2128 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2129 ((op1 & 0xc7) == 0x05 && op1 != (4 << 3)));
ead1e424
ILT
2130 memcpy(view - 3, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2131 }
2132 else
2133 {
af6359d5
ILT
2134 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2135 (op1 & 0xf8) == 0x80 && (op1 & 7) != 4);
fe8718a4 2136 if (rel.get_r_offset() + 9 < view_size
d61c17ea 2137 && view[9] == 0x90)
ead1e424
ILT
2138 {
2139 // There is a trailing nop. Use the size byte subl.
2140 memcpy(view - 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2141 roff = 6;
2142 }
2143 else
2144 {
2145 // Use the five byte subl.
2146 memcpy(view - 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2147 }
2148 }
2149
7bf1f802 2150 value = tls_segment->memsz() - value;
ead1e424
ILT
2151 Relocate_functions<32, false>::rel32(view + roff, value);
2152
2153 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2154 // We can skip it.
2155 this->skip_call_tls_get_addr_ = true;
2156}
2157
7bf1f802 2158// Do a relocation in which we convert a TLS General-Dynamic to an
07f397ab
ILT
2159// Initial-Exec.
2160
2161inline void
2162Target_i386::Relocate::tls_gd_to_ie(const Relocate_info<32, false>* relinfo,
2163 size_t relnum,
c2b45e22 2164 Output_segment*,
07f397ab
ILT
2165 const elfcpp::Rel<32, false>& rel,
2166 unsigned int,
2167 elfcpp::Elf_types<32>::Elf_Addr value,
2168 unsigned char* view,
fe8718a4 2169 section_size_type view_size)
07f397ab
ILT
2170{
2171 // leal foo(,%ebx,1),%eax; call ___tls_get_addr
2172 // ==> movl %gs:0,%eax; addl foo@gotntpoff(%ebx),%eax
2173
2174 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -2);
2175 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 9);
2176
2177 unsigned char op1 = view[-1];
2178 unsigned char op2 = view[-2];
2179
2180 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2181 op2 == 0x8d || op2 == 0x04);
2182 tls::check_tls(relinfo, relnum, rel.get_r_offset(), view[4] == 0xe8);
2183
2184 int roff = 5;
2185
c2b45e22
CC
2186 // FIXME: For now, support only the first (SIB) form.
2187 tls::check_tls(relinfo, relnum, rel.get_r_offset(), op2 == 0x04);
07f397ab
ILT
2188
2189 if (op2 == 0x04)
2190 {
2191 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -3);
2192 tls::check_tls(relinfo, relnum, rel.get_r_offset(), view[-3] == 0x8d);
2193 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2194 ((op1 & 0xc7) == 0x05 && op1 != (4 << 3)));
2195 memcpy(view - 3, "\x65\xa1\0\0\0\0\x03\x83\0\0\0", 12);
2196 }
2197 else
2198 {
2199 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2200 (op1 & 0xf8) == 0x80 && (op1 & 7) != 4);
fe8718a4 2201 if (rel.get_r_offset() + 9 < view_size
07f397ab
ILT
2202 && view[9] == 0x90)
2203 {
2204 // FIXME: This is not the right instruction sequence.
2205 // There is a trailing nop. Use the size byte subl.
2206 memcpy(view - 2, "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2207 roff = 6;
2208 }
2209 else
2210 {
2211 // FIXME: This is not the right instruction sequence.
2212 // Use the five byte subl.
2213 memcpy(view - 2, "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2214 }
2215 }
2216
07f397ab
ILT
2217 Relocate_functions<32, false>::rel32(view + roff, value);
2218
2219 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2220 // We can skip it.
2221 this->skip_call_tls_get_addr_ = true;
2222}
2223
c2b45e22
CC
2224// Do a relocation in which we convert a TLS_GOTDESC or TLS_DESC_CALL
2225// General-Dynamic to a Local-Exec.
2226
2227inline void
2228Target_i386::Relocate::tls_desc_gd_to_le(
2229 const Relocate_info<32, false>* relinfo,
2230 size_t relnum,
2231 Output_segment* tls_segment,
2232 const elfcpp::Rel<32, false>& rel,
2233 unsigned int r_type,
2234 elfcpp::Elf_types<32>::Elf_Addr value,
2235 unsigned char* view,
2236 section_size_type view_size)
2237{
2238 if (r_type == elfcpp::R_386_TLS_GOTDESC)
2239 {
2240 // leal foo@TLSDESC(%ebx), %eax
2241 // ==> leal foo@NTPOFF, %eax
2242 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -2);
2243 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 4);
2244 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2245 view[-2] == 0x8d && view[-1] == 0x83);
2246 view[-1] = 0x05;
2247 value -= tls_segment->memsz();
2248 Relocate_functions<32, false>::rel32(view, value);
2249 }
2250 else
2251 {
2252 // call *foo@TLSCALL(%eax)
2253 // ==> nop; nop
2254 gold_assert(r_type == elfcpp::R_386_TLS_DESC_CALL);
2255 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 2);
2256 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2257 view[0] == 0xff && view[1] == 0x10);
2258 view[0] = 0x66;
2259 view[1] = 0x90;
2260 }
2261}
2262
2263// Do a relocation in which we convert a TLS_GOTDESC or TLS_DESC_CALL
2264// General-Dynamic to an Initial-Exec.
2265
2266inline void
2267Target_i386::Relocate::tls_desc_gd_to_ie(
2268 const Relocate_info<32, false>* relinfo,
2269 size_t relnum,
2270 Output_segment*,
2271 const elfcpp::Rel<32, false>& rel,
2272 unsigned int r_type,
2273 elfcpp::Elf_types<32>::Elf_Addr value,
2274 unsigned char* view,
2275 section_size_type view_size)
2276{
2277 if (r_type == elfcpp::R_386_TLS_GOTDESC)
2278 {
2279 // leal foo@TLSDESC(%ebx), %eax
2280 // ==> movl foo@GOTNTPOFF(%ebx), %eax
2281 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -2);
2282 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 4);
2283 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2284 view[-2] == 0x8d && view[-1] == 0x83);
2285 view[-2] = 0x8b;
2286 Relocate_functions<32, false>::rel32(view, value);
2287 }
2288 else
2289 {
2290 // call *foo@TLSCALL(%eax)
2291 // ==> nop; nop
2292 gold_assert(r_type == elfcpp::R_386_TLS_DESC_CALL);
2293 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 2);
2294 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2295 view[0] == 0xff && view[1] == 0x10);
2296 view[0] = 0x66;
2297 view[1] = 0x90;
2298 }
2299}
2300
46cf9fa2
ILT
2301// Do a relocation in which we convert a TLS Local-Dynamic to a
2302// Local-Exec.
2303
2304inline void
2305Target_i386::Relocate::tls_ld_to_le(const Relocate_info<32, false>* relinfo,
2306 size_t relnum,
2307 Output_segment*,
2308 const elfcpp::Rel<32, false>& rel,
2309 unsigned int,
2310 elfcpp::Elf_types<32>::Elf_Addr,
2311 unsigned char* view,
fe8718a4 2312 section_size_type view_size)
46cf9fa2
ILT
2313{
2314 // leal foo(%reg), %eax; call ___tls_get_addr
2315 // ==> movl %gs:0,%eax; nop; leal 0(%esi,1),%esi
2316
af6359d5
ILT
2317 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -2);
2318 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 9);
46cf9fa2
ILT
2319
2320 // FIXME: Does this test really always pass?
af6359d5
ILT
2321 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2322 view[-2] == 0x8d && view[-1] == 0x83);
46cf9fa2 2323
af6359d5 2324 tls::check_tls(relinfo, relnum, rel.get_r_offset(), view[4] == 0xe8);
46cf9fa2
ILT
2325
2326 memcpy(view - 2, "\x65\xa1\0\0\0\0\x90\x8d\x74\x26\0", 11);
2327
2328 // The next reloc should be a PLT32 reloc against __tls_get_addr.
2329 // We can skip it.
2330 this->skip_call_tls_get_addr_ = true;
2331}
2332
56622147
ILT
2333// Do a relocation in which we convert a TLS Initial-Exec to a
2334// Local-Exec.
2335
2336inline void
2337Target_i386::Relocate::tls_ie_to_le(const Relocate_info<32, false>* relinfo,
2338 size_t relnum,
2339 Output_segment* tls_segment,
2340 const elfcpp::Rel<32, false>& rel,
2341 unsigned int r_type,
2342 elfcpp::Elf_types<32>::Elf_Addr value,
2343 unsigned char* view,
fe8718a4 2344 section_size_type view_size)
56622147
ILT
2345{
2346 // We have to actually change the instructions, which means that we
2347 // need to examine the opcodes to figure out which instruction we
2348 // are looking at.
2349 if (r_type == elfcpp::R_386_TLS_IE)
2350 {
2351 // movl %gs:XX,%eax ==> movl $YY,%eax
2352 // movl %gs:XX,%reg ==> movl $YY,%reg
2353 // addl %gs:XX,%reg ==> addl $YY,%reg
2354 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -1);
2355 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 4);
2356
2357 unsigned char op1 = view[-1];
2358 if (op1 == 0xa1)
2359 {
2360 // movl XX,%eax ==> movl $YY,%eax
2361 view[-1] = 0xb8;
2362 }
2363 else
2364 {
2365 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -2);
2366
2367 unsigned char op2 = view[-2];
2368 if (op2 == 0x8b)
2369 {
2370 // movl XX,%reg ==> movl $YY,%reg
2371 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2372 (op1 & 0xc7) == 0x05);
2373 view[-2] = 0xc7;
2374 view[-1] = 0xc0 | ((op1 >> 3) & 7);
2375 }
2376 else if (op2 == 0x03)
2377 {
2378 // addl XX,%reg ==> addl $YY,%reg
2379 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2380 (op1 & 0xc7) == 0x05);
2381 view[-2] = 0x81;
2382 view[-1] = 0xc0 | ((op1 >> 3) & 7);
2383 }
2384 else
2385 tls::check_tls(relinfo, relnum, rel.get_r_offset(), 0);
2386 }
2387 }
2388 else
2389 {
2390 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
2391 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
2392 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
2393 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, -2);
2394 tls::check_range(relinfo, relnum, rel.get_r_offset(), view_size, 4);
2395
2396 unsigned char op1 = view[-1];
2397 unsigned char op2 = view[-2];
2398 tls::check_tls(relinfo, relnum, rel.get_r_offset(),
2399 (op1 & 0xc0) == 0x80 && (op1 & 7) != 4);
2400 if (op2 == 0x8b)
2401 {
2402 // movl %gs:XX(%reg1),%reg2 ==> movl $YY,%reg2
2403 view[-2] = 0xc7;
2404 view[-1] = 0xc0 | ((op1 >> 3) & 7);
2405 }
2406 else if (op2 == 0x2b)
2407 {
2408 // subl %gs:XX(%reg1),%reg2 ==> subl $YY,%reg2
2409 view[-2] = 0x81;
2410 view[-1] = 0xe8 | ((op1 >> 3) & 7);
2411 }
2412 else if (op2 == 0x03)
2413 {
2414 // addl %gs:XX(%reg1),%reg2 ==> addl $YY,$reg2
2415 view[-2] = 0x81;
2416 view[-1] = 0xc0 | ((op1 >> 3) & 7);
2417 }
2418 else
2419 tls::check_tls(relinfo, relnum, rel.get_r_offset(), 0);
2420 }
2421
7bf1f802 2422 value = tls_segment->memsz() - value;
56622147
ILT
2423 if (r_type == elfcpp::R_386_TLS_IE || r_type == elfcpp::R_386_TLS_GOTIE)
2424 value = - value;
2425
2426 Relocate_functions<32, false>::rel32(view, value);
2427}
2428
61ba1cf9
ILT
2429// Relocate section data.
2430
2431void
92e059d8 2432Target_i386::relocate_section(const Relocate_info<32, false>* relinfo,
61ba1cf9
ILT
2433 unsigned int sh_type,
2434 const unsigned char* prelocs,
2435 size_t reloc_count,
730cdc88
ILT
2436 Output_section* output_section,
2437 bool needs_special_offset_handling,
61ba1cf9
ILT
2438 unsigned char* view,
2439 elfcpp::Elf_types<32>::Elf_Addr address,
fe8718a4 2440 section_size_type view_size)
61ba1cf9 2441{
a3ad94ed 2442 gold_assert(sh_type == elfcpp::SHT_REL);
61ba1cf9 2443
ead1e424
ILT
2444 gold::relocate_section<32, false, Target_i386, elfcpp::SHT_REL,
2445 Target_i386::Relocate>(
92e059d8 2446 relinfo,
ead1e424 2447 this,
61ba1cf9
ILT
2448 prelocs,
2449 reloc_count,
730cdc88
ILT
2450 output_section,
2451 needs_special_offset_handling,
61ba1cf9
ILT
2452 view,
2453 address,
2454 view_size);
2455}
2456
6a74a719
ILT
2457// Return the size of a relocation while scanning during a relocatable
2458// link.
2459
2460unsigned int
2461Target_i386::Relocatable_size_for_reloc::get_size_for_reloc(
2462 unsigned int r_type,
2463 Relobj* object)
2464{
2465 switch (r_type)
2466 {
2467 case elfcpp::R_386_NONE:
2468 case elfcpp::R_386_GNU_VTINHERIT:
2469 case elfcpp::R_386_GNU_VTENTRY:
2470 case elfcpp::R_386_TLS_GD: // Global-dynamic
2471 case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (from ~oliva url)
2472 case elfcpp::R_386_TLS_DESC_CALL:
2473 case elfcpp::R_386_TLS_LDM: // Local-dynamic
2474 case elfcpp::R_386_TLS_LDO_32: // Alternate local-dynamic
2475 case elfcpp::R_386_TLS_IE: // Initial-exec
2476 case elfcpp::R_386_TLS_IE_32:
2477 case elfcpp::R_386_TLS_GOTIE:
2478 case elfcpp::R_386_TLS_LE: // Local-exec
2479 case elfcpp::R_386_TLS_LE_32:
2480 return 0;
2481
2482 case elfcpp::R_386_32:
2483 case elfcpp::R_386_PC32:
2484 case elfcpp::R_386_GOT32:
2485 case elfcpp::R_386_PLT32:
2486 case elfcpp::R_386_GOTOFF:
2487 case elfcpp::R_386_GOTPC:
2488 return 4;
2489
2490 case elfcpp::R_386_16:
2491 case elfcpp::R_386_PC16:
2492 return 2;
2493
2494 case elfcpp::R_386_8:
2495 case elfcpp::R_386_PC8:
2496 return 1;
2497
2498 // These are relocations which should only be seen by the
2499 // dynamic linker, and should never be seen here.
2500 case elfcpp::R_386_COPY:
2501 case elfcpp::R_386_GLOB_DAT:
2502 case elfcpp::R_386_JUMP_SLOT:
2503 case elfcpp::R_386_RELATIVE:
2504 case elfcpp::R_386_TLS_TPOFF:
2505 case elfcpp::R_386_TLS_DTPMOD32:
2506 case elfcpp::R_386_TLS_DTPOFF32:
2507 case elfcpp::R_386_TLS_TPOFF32:
2508 case elfcpp::R_386_TLS_DESC:
2509 object->error(_("unexpected reloc %u in object file"), r_type);
2510 return 0;
2511
2512 case elfcpp::R_386_32PLT:
2513 case elfcpp::R_386_TLS_GD_32:
2514 case elfcpp::R_386_TLS_GD_PUSH:
2515 case elfcpp::R_386_TLS_GD_CALL:
2516 case elfcpp::R_386_TLS_GD_POP:
2517 case elfcpp::R_386_TLS_LDM_32:
2518 case elfcpp::R_386_TLS_LDM_PUSH:
2519 case elfcpp::R_386_TLS_LDM_CALL:
2520 case elfcpp::R_386_TLS_LDM_POP:
2521 case elfcpp::R_386_USED_BY_INTEL_200:
2522 default:
2523 object->error(_("unsupported reloc %u in object file"), r_type);
2524 return 0;
2525 }
2526}
2527
2528// Scan the relocs during a relocatable link.
2529
2530void
2531Target_i386::scan_relocatable_relocs(const General_options& options,
2532 Symbol_table* symtab,
2533 Layout* layout,
2534 Sized_relobj<32, false>* object,
2535 unsigned int data_shndx,
2536 unsigned int sh_type,
2537 const unsigned char* prelocs,
2538 size_t reloc_count,
2539 Output_section* output_section,
2540 bool needs_special_offset_handling,
2541 size_t local_symbol_count,
2542 const unsigned char* plocal_symbols,
2543 Relocatable_relocs* rr)
2544{
2545 gold_assert(sh_type == elfcpp::SHT_REL);
2546
2547 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_REL,
2548 Relocatable_size_for_reloc> Scan_relocatable_relocs;
2549
7019cd25 2550 gold::scan_relocatable_relocs<32, false, elfcpp::SHT_REL,
6a74a719
ILT
2551 Scan_relocatable_relocs>(
2552 options,
2553 symtab,
2554 layout,
2555 object,
2556 data_shndx,
2557 prelocs,
2558 reloc_count,
2559 output_section,
2560 needs_special_offset_handling,
2561 local_symbol_count,
2562 plocal_symbols,
2563 rr);
2564}
2565
2566// Relocate a section during a relocatable link.
2567
2568void
2569Target_i386::relocate_for_relocatable(
2570 const Relocate_info<32, false>* relinfo,
2571 unsigned int sh_type,
2572 const unsigned char* prelocs,
2573 size_t reloc_count,
2574 Output_section* output_section,
2575 off_t offset_in_output_section,
2576 const Relocatable_relocs* rr,
2577 unsigned char* view,
2578 elfcpp::Elf_types<32>::Elf_Addr view_address,
2579 section_size_type view_size,
2580 unsigned char* reloc_view,
2581 section_size_type reloc_view_size)
2582{
2583 gold_assert(sh_type == elfcpp::SHT_REL);
2584
7019cd25 2585 gold::relocate_for_relocatable<32, false, elfcpp::SHT_REL>(
6a74a719
ILT
2586 relinfo,
2587 prelocs,
2588 reloc_count,
2589 output_section,
2590 offset_in_output_section,
2591 rr,
2592 view,
2593 view_address,
2594 view_size,
2595 reloc_view,
2596 reloc_view_size);
2597}
2598
ab5c9e90
ILT
2599// Return the value to use for a dynamic which requires special
2600// treatment. This is how we support equality comparisons of function
2601// pointers across shared library boundaries, as described in the
2602// processor specific ABI supplement.
2603
2604uint64_t
2605Target_i386::do_dynsym_value(const Symbol* gsym) const
2606{
2607 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
2608 return this->plt_section()->address() + gsym->plt_offset();
2609}
2610
c51e6221
ILT
2611// Return a string used to fill a code section with nops to take up
2612// the specified length.
2613
2614std::string
8851ecca 2615Target_i386::do_code_fill(section_size_type length) const
c51e6221
ILT
2616{
2617 if (length >= 16)
2618 {
2619 // Build a jmp instruction to skip over the bytes.
2620 unsigned char jmp[5];
2621 jmp[0] = 0xe9;
2622 elfcpp::Swap_unaligned<32, false>::writeval(jmp + 1, length - 5);
2623 return (std::string(reinterpret_cast<char*>(&jmp[0]), 5)
2624 + std::string(length - 5, '\0'));
2625 }
2626
2627 // Nop sequences of various lengths.
2628 const char nop1[1] = { 0x90 }; // nop
2629 const char nop2[2] = { 0x66, 0x90 }; // xchg %ax %ax
2630 const char nop3[3] = { 0x8d, 0x76, 0x00 }; // leal 0(%esi),%esi
2631 const char nop4[4] = { 0x8d, 0x74, 0x26, 0x00}; // leal 0(%esi,1),%esi
2632 const char nop5[5] = { 0x90, 0x8d, 0x74, 0x26, // nop
2633 0x00 }; // leal 0(%esi,1),%esi
2634 const char nop6[6] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2635 0x00, 0x00 };
2636 const char nop7[7] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2637 0x00, 0x00, 0x00 };
2638 const char nop8[8] = { 0x90, 0x8d, 0xb4, 0x26, // nop
2639 0x00, 0x00, 0x00, 0x00 }; // leal 0L(%esi,1),%esi
2640 const char nop9[9] = { 0x89, 0xf6, 0x8d, 0xbc, // movl %esi,%esi
2641 0x27, 0x00, 0x00, 0x00, // leal 0L(%edi,1),%edi
2642 0x00 };
2643 const char nop10[10] = { 0x8d, 0x76, 0x00, 0x8d, // leal 0(%esi),%esi
2644 0xbc, 0x27, 0x00, 0x00, // leal 0L(%edi,1),%edi
2645 0x00, 0x00 };
2646 const char nop11[11] = { 0x8d, 0x74, 0x26, 0x00, // leal 0(%esi,1),%esi
2647 0x8d, 0xbc, 0x27, 0x00, // leal 0L(%edi,1),%edi
2648 0x00, 0x00, 0x00 };
2649 const char nop12[12] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2650 0x00, 0x00, 0x8d, 0xbf, // leal 0L(%edi),%edi
2651 0x00, 0x00, 0x00, 0x00 };
2652 const char nop13[13] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2653 0x00, 0x00, 0x8d, 0xbc, // leal 0L(%edi,1),%edi
2654 0x27, 0x00, 0x00, 0x00,
2655 0x00 };
2656 const char nop14[14] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2657 0x00, 0x00, 0x00, 0x8d, // leal 0L(%edi,1),%edi
2658 0xbc, 0x27, 0x00, 0x00,
2659 0x00, 0x00 };
2660 const char nop15[15] = { 0xeb, 0x0d, 0x90, 0x90, // jmp .+15
2661 0x90, 0x90, 0x90, 0x90, // nop,nop,nop,...
2662 0x90, 0x90, 0x90, 0x90,
2663 0x90, 0x90, 0x90 };
2664
2665 const char* nops[16] = {
2666 NULL,
2667 nop1, nop2, nop3, nop4, nop5, nop6, nop7,
2668 nop8, nop9, nop10, nop11, nop12, nop13, nop14, nop15
2669 };
2670
2671 return std::string(nops[length], length);
2672}
2673
14bfc3f5
ILT
2674// The selector for i386 object files.
2675
36959681 2676class Target_selector_i386 : public Target_selector_freebsd
14bfc3f5
ILT
2677{
2678public:
2679 Target_selector_i386()
36959681
ILT
2680 : Target_selector_freebsd(elfcpp::EM_386, 32, false,
2681 "elf32-i386", "elf32-i386-freebsd")
14bfc3f5
ILT
2682 { }
2683
2684 Target*
e96caa79
ILT
2685 do_instantiate_target()
2686 { return new Target_i386(); }
14bfc3f5
ILT
2687};
2688
14bfc3f5
ILT
2689Target_selector_i386 target_selector_i386;
2690
2691} // End anonymous namespace.
This page took 0.305319 seconds and 4 git commands to generate.