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