1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #include "elfxx-x86.h"
23 #include "elf-vxworks.h"
25 #include "opcode/i386.h"
27 /* 386 uses REL relocations instead of RELA. */
32 static reloc_howto_type elf_howto_table[]=
34 HOWTO(R_386_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont,
35 bfd_elf_generic_reloc, "R_386_NONE",
36 TRUE, 0x00000000, 0x00000000, FALSE),
37 HOWTO(R_386_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
38 bfd_elf_generic_reloc, "R_386_32",
39 TRUE, 0xffffffff, 0xffffffff, FALSE),
40 HOWTO(R_386_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
41 bfd_elf_generic_reloc, "R_386_PC32",
42 TRUE, 0xffffffff, 0xffffffff, TRUE),
43 HOWTO(R_386_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
44 bfd_elf_generic_reloc, "R_386_GOT32",
45 TRUE, 0xffffffff, 0xffffffff, FALSE),
46 HOWTO(R_386_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
47 bfd_elf_generic_reloc, "R_386_PLT32",
48 TRUE, 0xffffffff, 0xffffffff, TRUE),
49 HOWTO(R_386_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
50 bfd_elf_generic_reloc, "R_386_COPY",
51 TRUE, 0xffffffff, 0xffffffff, FALSE),
52 HOWTO(R_386_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
53 bfd_elf_generic_reloc, "R_386_GLOB_DAT",
54 TRUE, 0xffffffff, 0xffffffff, FALSE),
55 HOWTO(R_386_JUMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
56 bfd_elf_generic_reloc, "R_386_JUMP_SLOT",
57 TRUE, 0xffffffff, 0xffffffff, FALSE),
58 HOWTO(R_386_RELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
59 bfd_elf_generic_reloc, "R_386_RELATIVE",
60 TRUE, 0xffffffff, 0xffffffff, FALSE),
61 HOWTO(R_386_GOTOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
62 bfd_elf_generic_reloc, "R_386_GOTOFF",
63 TRUE, 0xffffffff, 0xffffffff, FALSE),
64 HOWTO(R_386_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
65 bfd_elf_generic_reloc, "R_386_GOTPC",
66 TRUE, 0xffffffff, 0xffffffff, TRUE),
68 /* We have a gap in the reloc numbers here.
69 R_386_standard counts the number up to this point, and
70 R_386_ext_offset is the value to subtract from a reloc type of
71 R_386_16 thru R_386_PC8 to form an index into this table. */
72 #define R_386_standard (R_386_GOTPC + 1)
73 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
75 /* These relocs are a GNU extension. */
76 HOWTO(R_386_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
77 bfd_elf_generic_reloc, "R_386_TLS_TPOFF",
78 TRUE, 0xffffffff, 0xffffffff, FALSE),
79 HOWTO(R_386_TLS_IE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
80 bfd_elf_generic_reloc, "R_386_TLS_IE",
81 TRUE, 0xffffffff, 0xffffffff, FALSE),
82 HOWTO(R_386_TLS_GOTIE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
83 bfd_elf_generic_reloc, "R_386_TLS_GOTIE",
84 TRUE, 0xffffffff, 0xffffffff, FALSE),
85 HOWTO(R_386_TLS_LE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
86 bfd_elf_generic_reloc, "R_386_TLS_LE",
87 TRUE, 0xffffffff, 0xffffffff, FALSE),
88 HOWTO(R_386_TLS_GD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
89 bfd_elf_generic_reloc, "R_386_TLS_GD",
90 TRUE, 0xffffffff, 0xffffffff, FALSE),
91 HOWTO(R_386_TLS_LDM, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
92 bfd_elf_generic_reloc, "R_386_TLS_LDM",
93 TRUE, 0xffffffff, 0xffffffff, FALSE),
94 HOWTO(R_386_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
95 bfd_elf_generic_reloc, "R_386_16",
96 TRUE, 0xffff, 0xffff, FALSE),
97 HOWTO(R_386_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
98 bfd_elf_generic_reloc, "R_386_PC16",
99 TRUE, 0xffff, 0xffff, TRUE),
100 HOWTO(R_386_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
101 bfd_elf_generic_reloc, "R_386_8",
102 TRUE, 0xff, 0xff, FALSE),
103 HOWTO(R_386_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
104 bfd_elf_generic_reloc, "R_386_PC8",
105 TRUE, 0xff, 0xff, TRUE),
107 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
108 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
109 /* These are common with Solaris TLS implementation. */
110 HOWTO(R_386_TLS_LDO_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
111 bfd_elf_generic_reloc, "R_386_TLS_LDO_32",
112 TRUE, 0xffffffff, 0xffffffff, FALSE),
113 HOWTO(R_386_TLS_IE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
114 bfd_elf_generic_reloc, "R_386_TLS_IE_32",
115 TRUE, 0xffffffff, 0xffffffff, FALSE),
116 HOWTO(R_386_TLS_LE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
117 bfd_elf_generic_reloc, "R_386_TLS_LE_32",
118 TRUE, 0xffffffff, 0xffffffff, FALSE),
119 HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
120 bfd_elf_generic_reloc, "R_386_TLS_DTPMOD32",
121 TRUE, 0xffffffff, 0xffffffff, FALSE),
122 HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
123 bfd_elf_generic_reloc, "R_386_TLS_DTPOFF32",
124 TRUE, 0xffffffff, 0xffffffff, FALSE),
125 HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
126 bfd_elf_generic_reloc, "R_386_TLS_TPOFF32",
127 TRUE, 0xffffffff, 0xffffffff, FALSE),
128 HOWTO(R_386_SIZE32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
129 bfd_elf_generic_reloc, "R_386_SIZE32",
130 TRUE, 0xffffffff, 0xffffffff, FALSE),
131 HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
132 bfd_elf_generic_reloc, "R_386_TLS_GOTDESC",
133 TRUE, 0xffffffff, 0xffffffff, FALSE),
134 HOWTO(R_386_TLS_DESC_CALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
135 bfd_elf_generic_reloc, "R_386_TLS_DESC_CALL",
137 HOWTO(R_386_TLS_DESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
138 bfd_elf_generic_reloc, "R_386_TLS_DESC",
139 TRUE, 0xffffffff, 0xffffffff, FALSE),
140 HOWTO(R_386_IRELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
141 bfd_elf_generic_reloc, "R_386_IRELATIVE",
142 TRUE, 0xffffffff, 0xffffffff, FALSE),
143 HOWTO(R_386_GOT32X, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
144 bfd_elf_generic_reloc, "R_386_GOT32X",
145 TRUE, 0xffffffff, 0xffffffff, FALSE),
148 #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
149 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
151 /* GNU extension to record C++ vtable hierarchy. */
152 HOWTO (R_386_GNU_VTINHERIT, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE, /* pc_relative */
158 complain_overflow_dont, /* complain_on_overflow */
159 NULL, /* special_function */
160 "R_386_GNU_VTINHERIT", /* name */
161 FALSE, /* partial_inplace */
164 FALSE), /* pcrel_offset */
166 /* GNU extension to record C++ vtable member usage. */
167 HOWTO (R_386_GNU_VTENTRY, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE, /* pc_relative */
173 complain_overflow_dont, /* complain_on_overflow */
174 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
175 "R_386_GNU_VTENTRY", /* name */
176 FALSE, /* partial_inplace */
179 FALSE) /* pcrel_offset */
181 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
185 #ifdef DEBUG_GEN_RELOC
187 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
192 static reloc_howto_type *
193 elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
194 bfd_reloc_code_real_type code)
199 TRACE ("BFD_RELOC_NONE");
200 return &elf_howto_table[R_386_NONE];
203 TRACE ("BFD_RELOC_32");
204 return &elf_howto_table[R_386_32];
207 TRACE ("BFD_RELOC_CTOR");
208 return &elf_howto_table[R_386_32];
210 case BFD_RELOC_32_PCREL:
211 TRACE ("BFD_RELOC_PC32");
212 return &elf_howto_table[R_386_PC32];
214 case BFD_RELOC_386_GOT32:
215 TRACE ("BFD_RELOC_386_GOT32");
216 return &elf_howto_table[R_386_GOT32];
218 case BFD_RELOC_386_PLT32:
219 TRACE ("BFD_RELOC_386_PLT32");
220 return &elf_howto_table[R_386_PLT32];
222 case BFD_RELOC_386_COPY:
223 TRACE ("BFD_RELOC_386_COPY");
224 return &elf_howto_table[R_386_COPY];
226 case BFD_RELOC_386_GLOB_DAT:
227 TRACE ("BFD_RELOC_386_GLOB_DAT");
228 return &elf_howto_table[R_386_GLOB_DAT];
230 case BFD_RELOC_386_JUMP_SLOT:
231 TRACE ("BFD_RELOC_386_JUMP_SLOT");
232 return &elf_howto_table[R_386_JUMP_SLOT];
234 case BFD_RELOC_386_RELATIVE:
235 TRACE ("BFD_RELOC_386_RELATIVE");
236 return &elf_howto_table[R_386_RELATIVE];
238 case BFD_RELOC_386_GOTOFF:
239 TRACE ("BFD_RELOC_386_GOTOFF");
240 return &elf_howto_table[R_386_GOTOFF];
242 case BFD_RELOC_386_GOTPC:
243 TRACE ("BFD_RELOC_386_GOTPC");
244 return &elf_howto_table[R_386_GOTPC];
246 /* These relocs are a GNU extension. */
247 case BFD_RELOC_386_TLS_TPOFF:
248 TRACE ("BFD_RELOC_386_TLS_TPOFF");
249 return &elf_howto_table[R_386_TLS_TPOFF - R_386_ext_offset];
251 case BFD_RELOC_386_TLS_IE:
252 TRACE ("BFD_RELOC_386_TLS_IE");
253 return &elf_howto_table[R_386_TLS_IE - R_386_ext_offset];
255 case BFD_RELOC_386_TLS_GOTIE:
256 TRACE ("BFD_RELOC_386_TLS_GOTIE");
257 return &elf_howto_table[R_386_TLS_GOTIE - R_386_ext_offset];
259 case BFD_RELOC_386_TLS_LE:
260 TRACE ("BFD_RELOC_386_TLS_LE");
261 return &elf_howto_table[R_386_TLS_LE - R_386_ext_offset];
263 case BFD_RELOC_386_TLS_GD:
264 TRACE ("BFD_RELOC_386_TLS_GD");
265 return &elf_howto_table[R_386_TLS_GD - R_386_ext_offset];
267 case BFD_RELOC_386_TLS_LDM:
268 TRACE ("BFD_RELOC_386_TLS_LDM");
269 return &elf_howto_table[R_386_TLS_LDM - R_386_ext_offset];
272 TRACE ("BFD_RELOC_16");
273 return &elf_howto_table[R_386_16 - R_386_ext_offset];
275 case BFD_RELOC_16_PCREL:
276 TRACE ("BFD_RELOC_16_PCREL");
277 return &elf_howto_table[R_386_PC16 - R_386_ext_offset];
280 TRACE ("BFD_RELOC_8");
281 return &elf_howto_table[R_386_8 - R_386_ext_offset];
283 case BFD_RELOC_8_PCREL:
284 TRACE ("BFD_RELOC_8_PCREL");
285 return &elf_howto_table[R_386_PC8 - R_386_ext_offset];
287 /* Common with Sun TLS implementation. */
288 case BFD_RELOC_386_TLS_LDO_32:
289 TRACE ("BFD_RELOC_386_TLS_LDO_32");
290 return &elf_howto_table[R_386_TLS_LDO_32 - R_386_tls_offset];
292 case BFD_RELOC_386_TLS_IE_32:
293 TRACE ("BFD_RELOC_386_TLS_IE_32");
294 return &elf_howto_table[R_386_TLS_IE_32 - R_386_tls_offset];
296 case BFD_RELOC_386_TLS_LE_32:
297 TRACE ("BFD_RELOC_386_TLS_LE_32");
298 return &elf_howto_table[R_386_TLS_LE_32 - R_386_tls_offset];
300 case BFD_RELOC_386_TLS_DTPMOD32:
301 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
302 return &elf_howto_table[R_386_TLS_DTPMOD32 - R_386_tls_offset];
304 case BFD_RELOC_386_TLS_DTPOFF32:
305 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
306 return &elf_howto_table[R_386_TLS_DTPOFF32 - R_386_tls_offset];
308 case BFD_RELOC_386_TLS_TPOFF32:
309 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
310 return &elf_howto_table[R_386_TLS_TPOFF32 - R_386_tls_offset];
312 case BFD_RELOC_SIZE32:
313 TRACE ("BFD_RELOC_SIZE32");
314 return &elf_howto_table[R_386_SIZE32 - R_386_tls_offset];
316 case BFD_RELOC_386_TLS_GOTDESC:
317 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
318 return &elf_howto_table[R_386_TLS_GOTDESC - R_386_tls_offset];
320 case BFD_RELOC_386_TLS_DESC_CALL:
321 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
322 return &elf_howto_table[R_386_TLS_DESC_CALL - R_386_tls_offset];
324 case BFD_RELOC_386_TLS_DESC:
325 TRACE ("BFD_RELOC_386_TLS_DESC");
326 return &elf_howto_table[R_386_TLS_DESC - R_386_tls_offset];
328 case BFD_RELOC_386_IRELATIVE:
329 TRACE ("BFD_RELOC_386_IRELATIVE");
330 return &elf_howto_table[R_386_IRELATIVE - R_386_tls_offset];
332 case BFD_RELOC_386_GOT32X:
333 TRACE ("BFD_RELOC_386_GOT32X");
334 return &elf_howto_table[R_386_GOT32X - R_386_tls_offset];
336 case BFD_RELOC_VTABLE_INHERIT:
337 TRACE ("BFD_RELOC_VTABLE_INHERIT");
338 return &elf_howto_table[R_386_GNU_VTINHERIT - R_386_vt_offset];
340 case BFD_RELOC_VTABLE_ENTRY:
341 TRACE ("BFD_RELOC_VTABLE_ENTRY");
342 return &elf_howto_table[R_386_GNU_VTENTRY - R_386_vt_offset];
352 static reloc_howto_type *
353 elf_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
358 for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++)
359 if (elf_howto_table[i].name != NULL
360 && strcasecmp (elf_howto_table[i].name, r_name) == 0)
361 return &elf_howto_table[i];
366 static reloc_howto_type *
367 elf_i386_rtype_to_howto (bfd *abfd, unsigned r_type)
371 if ((indx = r_type) >= R_386_standard
372 && ((indx = r_type - R_386_ext_offset) - R_386_standard
373 >= R_386_ext - R_386_standard)
374 && ((indx = r_type - R_386_tls_offset) - R_386_ext
375 >= R_386_ext2 - R_386_ext)
376 && ((indx = r_type - R_386_vt_offset) - R_386_ext2
377 >= R_386_vt - R_386_ext2))
379 /* xgettext:c-format */
380 _bfd_error_handler (_("%B: invalid relocation type %d"),
384 /* PR 17512: file: 0f67f69d. */
385 if (elf_howto_table [indx].type != r_type)
387 return &elf_howto_table[indx];
391 elf_i386_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
393 Elf_Internal_Rela *dst)
395 unsigned int r_type = ELF32_R_TYPE (dst->r_info);
396 cache_ptr->howto = elf_i386_rtype_to_howto (abfd, r_type);
399 /* Return whether a symbol name implies a local label. The UnixWare
400 2.1 cc generates temporary symbols that start with .X, so we
401 recognize them here. FIXME: do other SVR4 compilers also use .X?.
402 If so, we should move the .X recognition into
403 _bfd_elf_is_local_label_name. */
406 elf_i386_is_local_label_name (bfd *abfd, const char *name)
408 if (name[0] == '.' && name[1] == 'X')
411 return _bfd_elf_is_local_label_name (abfd, name);
414 /* Support for core dump NOTE sections. */
417 elf_i386_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
422 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
424 int pr_version = bfd_get_32 (abfd, note->descdata);
430 elf_tdata (abfd)->core->signal = bfd_get_32 (abfd, note->descdata + 20);
433 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
437 size = bfd_get_32 (abfd, note->descdata + 8);
441 switch (note->descsz)
446 case 144: /* Linux/i386 */
448 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
451 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
461 /* Make a ".reg/999" section. */
462 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
463 size, note->descpos + offset);
467 elf_i386_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
469 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
471 int pr_version = bfd_get_32 (abfd, note->descdata);
476 elf_tdata (abfd)->core->program
477 = _bfd_elfcore_strndup (abfd, note->descdata + 8, 17);
478 elf_tdata (abfd)->core->command
479 = _bfd_elfcore_strndup (abfd, note->descdata + 25, 81);
483 switch (note->descsz)
488 case 124: /* Linux/i386 elf_prpsinfo. */
489 elf_tdata (abfd)->core->pid
490 = bfd_get_32 (abfd, note->descdata + 12);
491 elf_tdata (abfd)->core->program
492 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
493 elf_tdata (abfd)->core->command
494 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
498 /* Note that for some reason, a spurious space is tacked
499 onto the end of the args in some (at least one anyway)
500 implementations, so strip it off if it exists. */
502 char *command = elf_tdata (abfd)->core->command;
503 int n = strlen (command);
505 if (0 < n && command[n - 1] == ' ')
506 command[n - 1] = '\0';
512 /* Functions for the i386 ELF linker.
514 In order to gain some understanding of code in this file without
515 knowing all the intricate details of the linker, note the
518 Functions named elf_i386_* are called by external routines, other
519 functions are only called locally. elf_i386_* functions appear
520 in this file more or less in the order in which they are called
521 from external routines. eg. elf_i386_check_relocs is called
522 early in the link process, elf_i386_finish_dynamic_sections is
523 one of the last functions. */
525 /* The size in bytes of an entry in the lazy procedure linkage table. */
527 #define LAZY_PLT_ENTRY_SIZE 16
529 /* The size in bytes of an entry in the non-lazy procedure linkage
532 #define NON_LAZY_PLT_ENTRY_SIZE 8
534 /* The first entry in an absolute lazy procedure linkage table looks
535 like this. See the SVR4 ABI i386 supplement to see how this works.
536 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
538 static const bfd_byte elf_i386_lazy_plt0_entry[12] =
540 0xff, 0x35, /* pushl contents of address */
541 0, 0, 0, 0, /* replaced with address of .got + 4. */
542 0xff, 0x25, /* jmp indirect */
543 0, 0, 0, 0 /* replaced with address of .got + 8. */
546 /* Subsequent entries in an absolute lazy procedure linkage table look
549 static const bfd_byte elf_i386_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
551 0xff, 0x25, /* jmp indirect */
552 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
553 0x68, /* pushl immediate */
554 0, 0, 0, 0, /* replaced with offset into relocation table. */
555 0xe9, /* jmp relative */
556 0, 0, 0, 0 /* replaced with offset to start of .plt. */
559 /* The first entry in a PIC lazy procedure linkage table look like
560 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
561 lazy_plt->plt0_pad_byte. */
563 static const bfd_byte elf_i386_pic_lazy_plt0_entry[12] =
565 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
566 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
569 /* Subsequent entries in a PIC lazy procedure linkage table look like
572 static const bfd_byte elf_i386_pic_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
574 0xff, 0xa3, /* jmp *offset(%ebx) */
575 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
576 0x68, /* pushl immediate */
577 0, 0, 0, 0, /* replaced with offset into relocation table. */
578 0xe9, /* jmp relative */
579 0, 0, 0, 0 /* replaced with offset to start of .plt. */
582 /* Entries in the non-lazy procedure linkage table look like this. */
584 static const bfd_byte elf_i386_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
586 0xff, 0x25, /* jmp indirect */
587 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
588 0x66, 0x90 /* xchg %ax,%ax */
591 /* Entries in the PIC non-lazy procedure linkage table look like
594 static const bfd_byte elf_i386_pic_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
596 0xff, 0xa3, /* jmp *offset(%ebx) */
597 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
598 0x66, 0x90 /* xchg %ax,%ax */
601 /* The first entry in an absolute IBT-enabled lazy procedure linkage
602 table looks like this. */
604 static const bfd_byte elf_i386_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
606 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
607 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
608 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
611 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
612 table look like this. Subsequent entries for a PIC IBT-enabled lazy
613 procedure linkage table are the same. */
615 static const bfd_byte elf_i386_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
617 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
618 0x68, 0, 0, 0, 0, /* pushl immediate */
619 0xe9, 0, 0, 0, 0, /* jmp relative */
620 0x66, 0x90 /* xchg %ax,%ax */
623 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
626 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
628 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
629 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
630 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
633 /* Entries for branches with IBT-enabled in the absolute non-lazey
634 procedure linkage table look like this. They have the same size
635 as the lazy PLT entry. */
637 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
639 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
640 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
641 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
644 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
645 linkage table look like this. They have the same size as the lazy
648 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
650 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
651 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
652 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
655 /* .eh_frame covering the lazy .plt section. */
657 static const bfd_byte elf_i386_eh_frame_lazy_plt[] =
659 #define PLT_CIE_LENGTH 20
660 #define PLT_FDE_LENGTH 36
661 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
662 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
663 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
664 0, 0, 0, 0, /* CIE ID */
666 'z', 'R', 0, /* Augmentation string */
667 1, /* Code alignment factor */
668 0x7c, /* Data alignment factor */
669 8, /* Return address column */
670 1, /* Augmentation size */
671 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
672 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
673 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
674 DW_CFA_nop, DW_CFA_nop,
676 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
677 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
678 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
679 0, 0, 0, 0, /* .plt size goes here */
680 0, /* Augmentation size */
681 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
682 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
683 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
684 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
685 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
686 11, /* Block length */
687 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
688 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
689 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
690 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
691 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
694 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
696 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt[] =
698 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
699 0, 0, 0, 0, /* CIE ID */
701 'z', 'R', 0, /* Augmentation string */
702 1, /* Code alignment factor */
703 0x7c, /* Data alignment factor */
704 8, /* Return address column */
705 1, /* Augmentation size */
706 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
707 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
708 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
709 DW_CFA_nop, DW_CFA_nop,
711 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
712 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
713 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
714 0, 0, 0, 0, /* .plt size goes here */
715 0, /* Augmentation size */
716 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
717 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
718 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
719 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
720 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
721 11, /* Block length */
722 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
723 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
724 DW_OP_lit15, DW_OP_and, DW_OP_lit9, DW_OP_ge,
725 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
726 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
729 /* .eh_frame covering the non-lazy .plt section. */
731 static const bfd_byte elf_i386_eh_frame_non_lazy_plt[] =
733 #define PLT_GOT_FDE_LENGTH 16
734 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
735 0, 0, 0, 0, /* CIE ID */
737 'z', 'R', 0, /* Augmentation string */
738 1, /* Code alignment factor */
739 0x7c, /* Data alignment factor */
740 8, /* Return address column */
741 1, /* Augmentation size */
742 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
743 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
744 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
745 DW_CFA_nop, DW_CFA_nop,
747 PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */
748 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
749 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
750 0, 0, 0, 0, /* non-lazy .plt size goes here */
751 0, /* Augmentation size */
752 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
755 /* These are the standard parameters. */
756 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt =
758 elf_i386_lazy_plt0_entry, /* plt0_entry */
759 sizeof (elf_i386_lazy_plt0_entry), /* plt0_entry_size */
760 elf_i386_lazy_plt_entry, /* plt_entry */
761 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
762 2, /* plt0_got1_offset */
763 8, /* plt0_got2_offset */
764 0, /* plt0_got2_insn_end */
765 2, /* plt_got_offset */
766 7, /* plt_reloc_offset */
767 12, /* plt_plt_offset */
768 0, /* plt_got_insn_size */
769 0, /* plt_plt_insn_end */
770 6, /* plt_lazy_offset */
771 elf_i386_pic_lazy_plt0_entry, /* pic_plt0_entry */
772 elf_i386_pic_lazy_plt_entry, /* pic_plt_entry */
773 elf_i386_eh_frame_lazy_plt, /* eh_frame_plt */
774 sizeof (elf_i386_eh_frame_lazy_plt) /* eh_frame_plt_size */
777 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt =
779 elf_i386_non_lazy_plt_entry, /* plt_entry */
780 elf_i386_pic_non_lazy_plt_entry, /* pic_plt_entry */
781 NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
782 2, /* plt_got_offset */
783 0, /* plt_got_insn_size */
784 elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */
785 sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
788 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt =
790 elf_i386_lazy_ibt_plt0_entry, /* plt0_entry */
791 sizeof (elf_i386_lazy_ibt_plt0_entry), /* plt0_entry_size */
792 elf_i386_lazy_ibt_plt_entry, /* plt_entry */
793 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
794 2, /* plt0_got1_offset */
795 8, /* plt0_got2_offset */
796 0, /* plt0_got2_insn_end */
797 4+2, /* plt_got_offset */
798 4+1, /* plt_reloc_offset */
799 4+6, /* plt_plt_offset */
800 0, /* plt_got_insn_size */
801 0, /* plt_plt_insn_end */
802 0, /* plt_lazy_offset */
803 elf_i386_pic_lazy_ibt_plt0_entry, /* pic_plt0_entry */
804 elf_i386_lazy_ibt_plt_entry, /* pic_plt_entry */
805 elf_i386_eh_frame_lazy_ibt_plt, /* eh_frame_plt */
806 sizeof (elf_i386_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */
809 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt =
811 elf_i386_non_lazy_ibt_plt_entry, /* plt_entry */
812 elf_i386_pic_non_lazy_ibt_plt_entry,/* pic_plt_entry */
813 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
814 4+2, /* plt_got_offset */
815 0, /* plt_got_insn_size */
816 elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */
817 sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
821 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
822 for the PLTResolve stub and then for each PLT entry. */
823 #define PLTRESOLVE_RELOCS_SHLIB 0
824 #define PLTRESOLVE_RELOCS 2
825 #define PLT_NON_JUMP_SLOT_RELOCS 2
827 /* Architecture-specific backend data for i386. */
829 struct elf_i386_backend_data
831 /* Value used to fill the unused bytes of the first PLT entry. */
832 bfd_byte plt0_pad_byte;
843 #define get_elf_i386_backend_data(abfd) \
844 ((const struct elf_i386_backend_data *) \
845 get_elf_backend_data (abfd)->arch_data)
847 /* These are the standard parameters. */
848 static const struct elf_i386_backend_data elf_i386_arch_bed =
850 0, /* plt0_pad_byte */
854 #define elf_backend_arch_data &elf_i386_arch_bed
856 /* Return TRUE if the TLS access code sequence support transition
860 elf_i386_check_tls_transition (asection *sec,
862 Elf_Internal_Shdr *symtab_hdr,
863 struct elf_link_hash_entry **sym_hashes,
865 const Elf_Internal_Rela *rel,
866 const Elf_Internal_Rela *relend)
868 unsigned int val, type, reg;
869 unsigned long r_symndx;
870 struct elf_link_hash_entry *h;
873 bfd_boolean indirect_call;
875 offset = rel->r_offset;
880 if (offset < 2 || (rel + 1) >= relend)
883 indirect_call = FALSE;
884 call = contents + offset + 4;
887 if (r_type == R_386_TLS_GD)
889 /* Check transition from GD access model. Only
890 leal foo@tlsgd(,%ebx,1), %eax
891 call ___tls_get_addr@PLT
893 leal foo@tlsgd(%ebx) %eax
894 call ___tls_get_addr@PLT
897 leal foo@tlsgd(%reg), %eax
898 call *___tls_get_addr@GOT(%reg)
899 which may be converted to
900 addr32 call ___tls_get_addr
901 can transit to different access model. */
902 if ((offset + 10) > sec->size
903 || (type != 0x8d && type != 0x04))
908 /* leal foo@tlsgd(,%ebx,1), %eax
909 call ___tls_get_addr@PLT */
913 if (*(call - 7) != 0x8d
921 leal foo@tlsgd(%ebx), %eax
922 call ___tls_get_addr@PLT
925 leal foo@tlsgd(%reg), %eax
926 call *___tls_get_addr@GOT(%reg)
927 which may be converted to
928 addr32 call ___tls_get_addr
930 %eax can't be used as the GOT base register since it
931 is used to pass parameter to ___tls_get_addr. */
933 if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0)
936 indirect_call = call[0] == 0xff;
937 if (!(reg == 3 && call[0] == 0xe8 && call[5] == 0x90)
938 && !(call[0] == 0x67 && call[1] == 0xe8)
940 && (call[1] & 0xf8) == 0x90
941 && (call[1] & 0x7) == reg))
947 /* Check transition from LD access model. Only
948 leal foo@tlsldm(%ebx), %eax
949 call ___tls_get_addr@PLT
951 leal foo@tlsldm(%reg), %eax
952 call *___tls_get_addr@GOT(%reg)
953 which may be converted to
954 addr32 call ___tls_get_addr
955 can transit to different access model. */
956 if (type != 0x8d || (offset + 9) > sec->size)
959 /* %eax can't be used as the GOT base register since it is
960 used to pass parameter to ___tls_get_addr. */
962 if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0)
965 indirect_call = call[0] == 0xff;
966 if (!(reg == 3 && call[0] == 0xe8)
967 && !(call[0] == 0x67 && call[1] == 0xe8)
969 && (call[1] & 0xf8) == 0x90
970 && (call[1] & 0x7) == reg))
974 r_symndx = ELF32_R_SYM (rel[1].r_info);
975 if (r_symndx < symtab_hdr->sh_info)
978 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
980 || !((struct elf_x86_link_hash_entry *) h)->tls_get_addr)
982 else if (indirect_call)
983 return (ELF32_R_TYPE (rel[1].r_info) == R_386_GOT32X);
985 return (ELF32_R_TYPE (rel[1].r_info) == R_386_PC32
986 || ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
989 /* Check transition from IE access model:
990 movl foo@indntpoff(%rip), %eax
991 movl foo@indntpoff(%rip), %reg
992 addl foo@indntpoff(%rip), %reg
995 if (offset < 1 || (offset + 4) > sec->size)
998 /* Check "movl foo@tpoff(%rip), %eax" first. */
999 val = bfd_get_8 (abfd, contents + offset - 1);
1006 /* Check movl|addl foo@tpoff(%rip), %reg. */
1007 type = bfd_get_8 (abfd, contents + offset - 2);
1008 return ((type == 0x8b || type == 0x03)
1009 && (val & 0xc7) == 0x05);
1011 case R_386_TLS_GOTIE:
1012 case R_386_TLS_IE_32:
1013 /* Check transition from {IE_32,GOTIE} access model:
1014 subl foo@{tpoff,gontoff}(%reg1), %reg2
1015 movl foo@{tpoff,gontoff}(%reg1), %reg2
1016 addl foo@{tpoff,gontoff}(%reg1), %reg2
1019 if (offset < 2 || (offset + 4) > sec->size)
1022 val = bfd_get_8 (abfd, contents + offset - 1);
1023 if ((val & 0xc0) != 0x80 || (val & 7) == 4)
1026 type = bfd_get_8 (abfd, contents + offset - 2);
1027 return type == 0x8b || type == 0x2b || type == 0x03;
1029 case R_386_TLS_GOTDESC:
1030 /* Check transition from GDesc access model:
1031 leal x@tlsdesc(%ebx), %eax
1033 Make sure it's a leal adding ebx to a 32-bit offset
1034 into any register, although it's probably almost always
1037 if (offset < 2 || (offset + 4) > sec->size)
1040 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1043 val = bfd_get_8 (abfd, contents + offset - 1);
1044 return (val & 0xc7) == 0x83;
1046 case R_386_TLS_DESC_CALL:
1047 /* Check transition from GDesc access model:
1048 call *x@tlsdesc(%eax)
1050 if (offset + 2 <= sec->size)
1052 /* Make sure that it's a call *x@tlsdesc(%eax). */
1053 call = contents + offset;
1054 return call[0] == 0xff && call[1] == 0x10;
1064 /* Return TRUE if the TLS access transition is OK or no transition
1065 will be performed. Update R_TYPE if there is a transition. */
1068 elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd,
1069 asection *sec, bfd_byte *contents,
1070 Elf_Internal_Shdr *symtab_hdr,
1071 struct elf_link_hash_entry **sym_hashes,
1072 unsigned int *r_type, int tls_type,
1073 const Elf_Internal_Rela *rel,
1074 const Elf_Internal_Rela *relend,
1075 struct elf_link_hash_entry *h,
1076 unsigned long r_symndx,
1077 bfd_boolean from_relocate_section)
1079 unsigned int from_type = *r_type;
1080 unsigned int to_type = from_type;
1081 bfd_boolean check = TRUE;
1083 /* Skip TLS transition for functions. */
1085 && (h->type == STT_FUNC
1086 || h->type == STT_GNU_IFUNC))
1092 case R_386_TLS_GOTDESC:
1093 case R_386_TLS_DESC_CALL:
1094 case R_386_TLS_IE_32:
1096 case R_386_TLS_GOTIE:
1097 if (bfd_link_executable (info))
1100 to_type = R_386_TLS_LE_32;
1101 else if (from_type != R_386_TLS_IE
1102 && from_type != R_386_TLS_GOTIE)
1103 to_type = R_386_TLS_IE_32;
1106 /* When we are called from elf_i386_relocate_section, there may
1107 be additional transitions based on TLS_TYPE. */
1108 if (from_relocate_section)
1110 unsigned int new_to_type = to_type;
1112 if (bfd_link_executable (info)
1115 && (tls_type & GOT_TLS_IE))
1116 new_to_type = R_386_TLS_LE_32;
1118 if (to_type == R_386_TLS_GD
1119 || to_type == R_386_TLS_GOTDESC
1120 || to_type == R_386_TLS_DESC_CALL)
1122 if (tls_type == GOT_TLS_IE_POS)
1123 new_to_type = R_386_TLS_GOTIE;
1124 else if (tls_type & GOT_TLS_IE)
1125 new_to_type = R_386_TLS_IE_32;
1128 /* We checked the transition before when we were called from
1129 elf_i386_check_relocs. We only want to check the new
1130 transition which hasn't been checked before. */
1131 check = new_to_type != to_type && from_type == to_type;
1132 to_type = new_to_type;
1138 if (bfd_link_executable (info))
1139 to_type = R_386_TLS_LE_32;
1146 /* Return TRUE if there is no transition. */
1147 if (from_type == to_type)
1150 /* Check if the transition can be performed. */
1152 && ! elf_i386_check_tls_transition (sec, contents,
1153 symtab_hdr, sym_hashes,
1154 from_type, rel, relend))
1156 reloc_howto_type *from, *to;
1159 from = elf_i386_rtype_to_howto (abfd, from_type);
1160 to = elf_i386_rtype_to_howto (abfd, to_type);
1163 name = h->root.root.string;
1166 struct elf_x86_link_hash_table *htab;
1168 htab = elf_x86_hash_table (info, I386_ELF_DATA);
1173 Elf_Internal_Sym *isym;
1175 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1177 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1182 /* xgettext:c-format */
1183 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1184 "in section `%A' failed"),
1185 abfd, from->name, to->name, name,
1186 rel->r_offset, sec);
1187 bfd_set_error (bfd_error_bad_value);
1195 /* With the local symbol, foo, we convert
1196 mov foo@GOT[(%reg1)], %reg2
1198 lea foo[@GOTOFF(%reg1)], %reg2
1200 call/jmp *foo@GOT[(%reg)]
1202 nop call foo/jmp foo nop
1203 When PIC is false, convert
1204 test %reg1, foo@GOT[(%reg2)]
1208 binop foo@GOT[(%reg1)], %reg2
1211 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1216 elf_i386_convert_load_reloc (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
1218 Elf_Internal_Rela *irel,
1219 struct elf_link_hash_entry *h,
1220 bfd_boolean *converted,
1221 struct bfd_link_info *link_info)
1223 struct elf_x86_link_hash_table *htab;
1224 unsigned int opcode;
1226 bfd_boolean baseless;
1227 Elf_Internal_Sym *isym;
1228 unsigned int addend;
1232 bfd_boolean to_reloc_32;
1233 unsigned int r_type;
1234 unsigned int r_symndx;
1235 bfd_vma roff = irel->r_offset;
1240 /* Addend for R_386_GOT32X relocations must be 0. */
1241 addend = bfd_get_32 (abfd, contents + roff);
1245 htab = elf_x86_hash_table (link_info, I386_ELF_DATA);
1246 is_pic = bfd_link_pic (link_info);
1248 r_type = ELF32_R_TYPE (irel->r_info);
1249 r_symndx = ELF32_R_SYM (irel->r_info);
1251 modrm = bfd_get_8 (abfd, contents + roff - 1);
1252 baseless = (modrm & 0xc7) == 0x5;
1254 if (baseless && is_pic)
1256 /* For PIC, disallow R_386_GOT32X without a base register
1257 since we don't know what the GOT base is. */
1262 isym = bfd_sym_from_r_symndx (&htab->sym_cache, abfd,
1264 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1267 name = h->root.root.string;
1270 /* xgettext:c-format */
1271 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1272 " register can not be used when making a shared object"),
1277 opcode = bfd_get_8 (abfd, contents + roff - 2);
1279 /* Convert to R_386_32 if PIC is false or there is no base
1281 to_reloc_32 = !is_pic || baseless;
1283 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1287 if (opcode == 0x0ff)
1288 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1289 goto convert_branch;
1291 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1292 "test %reg1, foo@GOT(%reg2)" and
1293 "binop foo@GOT[(%reg1)], %reg2". */
1297 /* Undefined weak symbol is only bound locally in executable
1298 and its reference is resolved as 0. */
1299 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info, I386_ELF_DATA, TRUE,
1300 elf_x86_hash_entry (h)))
1304 /* No direct branch to 0 for PIC. */
1308 goto convert_branch;
1312 /* We can convert load of address 0 to R_386_32. */
1320 /* We have "call/jmp *foo@GOT[(%reg)]". */
1321 if ((h->root.type == bfd_link_hash_defined
1322 || h->root.type == bfd_link_hash_defweak)
1323 && SYMBOL_REFERENCES_LOCAL (link_info, h))
1325 /* The function is locally defined. */
1327 /* Convert R_386_GOT32X to R_386_PC32. */
1328 if (modrm == 0x15 || (modrm & 0xf8) == 0x90)
1330 struct elf_x86_link_hash_entry *eh
1331 = (struct elf_x86_link_hash_entry *) h;
1333 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1336 /* To support TLS optimization, always use addr32 prefix
1337 for "call *___tls_get_addr@GOT(%reg)". */
1338 if (eh && eh->tls_get_addr)
1341 nop_offset = irel->r_offset - 2;
1345 nop = link_info->call_nop_byte;
1346 if (link_info->call_nop_as_suffix)
1348 nop_offset = roff + 3;
1349 irel->r_offset -= 1;
1352 nop_offset = roff - 2;
1357 /* Convert to "jmp foo nop". */
1360 nop_offset = roff + 3;
1361 irel->r_offset -= 1;
1364 bfd_put_8 (abfd, nop, contents + nop_offset);
1365 bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1);
1366 /* When converting to PC-relative relocation, we
1367 need to adjust addend by -4. */
1368 bfd_put_32 (abfd, -4, contents + irel->r_offset);
1369 irel->r_info = ELF32_R_INFO (r_symndx, R_386_PC32);
1376 /* We have "mov foo@GOT[(%re1g)], %reg2",
1377 "test %reg1, foo@GOT(%reg2)" and
1378 "binop foo@GOT[(%reg1)], %reg2".
1380 Avoid optimizing _DYNAMIC since ld.so may use its
1381 link-time address. */
1382 if (h == htab->elf.hdynamic)
1385 /* def_regular is set by an assignment in a linker script in
1386 bfd_elf_record_link_assignment. start_stop is set on
1387 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1390 || h->root.type == bfd_link_hash_defined
1391 || h->root.type == bfd_link_hash_defweak)
1392 && SYMBOL_REFERENCES_LOCAL (link_info, h)))
1399 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1400 "mov $foo, %reg2" with R_386_32. */
1402 modrm = 0xc0 | (modrm & 0x38) >> 3;
1403 bfd_put_8 (abfd, modrm, contents + roff - 1);
1408 /* Convert "mov foo@GOT(%reg1), %reg2" to
1409 "lea foo@GOTOFF(%reg1), %reg2". */
1410 r_type = R_386_GOTOFF;
1416 /* Only R_386_32 is supported. */
1422 /* Convert "test %reg1, foo@GOT(%reg2)" to
1423 "test $foo, %reg1". */
1424 modrm = 0xc0 | (modrm & 0x38) >> 3;
1429 /* Convert "binop foo@GOT(%reg1), %reg2" to
1430 "binop $foo, %reg2". */
1432 | (modrm & 0x38) >> 3
1436 bfd_put_8 (abfd, modrm, contents + roff - 1);
1440 bfd_put_8 (abfd, opcode, contents + roff - 2);
1441 irel->r_info = ELF32_R_INFO (r_symndx, r_type);
1450 /* Rename some of the generic section flags to better document how they
1452 #define need_convert_load sec_flg0
1453 #define check_relocs_failed sec_flg1
1455 /* Look through the relocs for a section during the first phase, and
1456 calculate needed space in the global offset table, procedure linkage
1457 table, and dynamic reloc sections. */
1460 elf_i386_check_relocs (bfd *abfd,
1461 struct bfd_link_info *info,
1463 const Elf_Internal_Rela *relocs)
1465 struct elf_x86_link_hash_table *htab;
1466 Elf_Internal_Shdr *symtab_hdr;
1467 struct elf_link_hash_entry **sym_hashes;
1468 const Elf_Internal_Rela *rel;
1469 const Elf_Internal_Rela *rel_end;
1473 if (bfd_link_relocatable (info))
1476 /* Don't do anything special with non-loaded, non-alloced sections.
1477 In particular, any relocs in such sections should not affect GOT
1478 and PLT reference counting (ie. we don't allow them to create GOT
1479 or PLT entries), there's no possibility or desire to optimize TLS
1480 relocs, and there's not much point in propagating relocs to shared
1481 libs that the dynamic linker won't relocate. */
1482 if ((sec->flags & SEC_ALLOC) == 0)
1485 htab = elf_x86_hash_table (info, I386_ELF_DATA);
1488 sec->check_relocs_failed = 1;
1492 BFD_ASSERT (is_x86_elf (abfd, htab));
1494 /* Get the section contents. */
1495 if (elf_section_data (sec)->this_hdr.contents != NULL)
1496 contents = elf_section_data (sec)->this_hdr.contents;
1497 else if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1499 sec->check_relocs_failed = 1;
1503 symtab_hdr = &elf_symtab_hdr (abfd);
1504 sym_hashes = elf_sym_hashes (abfd);
1508 rel_end = relocs + sec->reloc_count;
1509 for (rel = relocs; rel < rel_end; rel++)
1511 unsigned int r_type;
1512 unsigned int r_symndx;
1513 struct elf_link_hash_entry *h;
1514 struct elf_x86_link_hash_entry *eh;
1515 Elf_Internal_Sym *isym;
1517 bfd_boolean size_reloc;
1519 r_symndx = ELF32_R_SYM (rel->r_info);
1520 r_type = ELF32_R_TYPE (rel->r_info);
1522 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1524 /* xgettext:c-format */
1525 _bfd_error_handler (_("%B: bad symbol index: %d"),
1530 if (r_symndx < symtab_hdr->sh_info)
1532 /* A local symbol. */
1533 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1538 /* Check relocation against local STT_GNU_IFUNC symbol. */
1539 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1541 h = _bfd_elf_x86_get_local_sym_hash (htab, abfd, rel, TRUE);
1545 /* Fake a STT_GNU_IFUNC symbol. */
1546 h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr,
1548 h->type = STT_GNU_IFUNC;
1551 h->forced_local = 1;
1552 h->root.type = bfd_link_hash_defined;
1560 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1561 while (h->root.type == bfd_link_hash_indirect
1562 || h->root.type == bfd_link_hash_warning)
1563 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1566 eh = (struct elf_x86_link_hash_entry *) h;
1569 if (r_type == R_386_GOTOFF)
1572 /* It is referenced by a non-shared object. */
1574 h->root.non_ir_ref_regular = 1;
1576 if (h->type == STT_GNU_IFUNC)
1577 elf_tdata (info->output_bfd)->has_gnu_symbols
1578 |= elf_gnu_symbol_ifunc;
1581 if (! elf_i386_tls_transition (info, abfd, sec, contents,
1582 symtab_hdr, sym_hashes,
1583 &r_type, GOT_UNKNOWN,
1584 rel, rel_end, h, r_symndx, FALSE))
1590 htab->tls_ld_or_ldm_got.refcount += 1;
1594 /* This symbol requires a procedure linkage table entry. We
1595 actually build the entry in adjust_dynamic_symbol,
1596 because this might be a case of linking PIC code which is
1597 never referenced by a dynamic object, in which case we
1598 don't need to generate a procedure linkage table entry
1601 /* If this is a local symbol, we resolve it directly without
1602 creating a procedure linkage table entry. */
1606 eh->has_got_reloc = 1;
1608 h->plt.refcount += 1;
1615 case R_386_TLS_IE_32:
1617 case R_386_TLS_GOTIE:
1618 if (!bfd_link_executable (info))
1619 info->flags |= DF_STATIC_TLS;
1625 case R_386_TLS_GOTDESC:
1626 case R_386_TLS_DESC_CALL:
1627 /* This symbol requires a global offset table entry. */
1629 int tls_type, old_tls_type;
1636 tls_type = GOT_NORMAL;
1638 case R_386_TLS_GD: tls_type = GOT_TLS_GD; break;
1639 case R_386_TLS_GOTDESC:
1640 case R_386_TLS_DESC_CALL:
1641 tls_type = GOT_TLS_GDESC; break;
1642 case R_386_TLS_IE_32:
1643 if (ELF32_R_TYPE (rel->r_info) == r_type)
1644 tls_type = GOT_TLS_IE_NEG;
1646 /* If this is a GD->IE transition, we may use either of
1647 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1648 tls_type = GOT_TLS_IE;
1651 case R_386_TLS_GOTIE:
1652 tls_type = GOT_TLS_IE_POS; break;
1657 h->got.refcount += 1;
1658 old_tls_type = elf_x86_hash_entry (h)->tls_type;
1662 bfd_signed_vma *local_got_refcounts;
1664 /* This is a global offset table entry for a local symbol. */
1665 local_got_refcounts = elf_local_got_refcounts (abfd);
1666 if (local_got_refcounts == NULL)
1670 size = symtab_hdr->sh_info;
1671 size *= (sizeof (bfd_signed_vma)
1672 + sizeof (bfd_vma) + sizeof(char));
1673 local_got_refcounts = (bfd_signed_vma *)
1674 bfd_zalloc (abfd, size);
1675 if (local_got_refcounts == NULL)
1677 elf_local_got_refcounts (abfd) = local_got_refcounts;
1678 elf_x86_local_tlsdesc_gotent (abfd)
1679 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1680 elf_x86_local_got_tls_type (abfd)
1681 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1683 local_got_refcounts[r_symndx] += 1;
1684 old_tls_type = elf_x86_local_got_tls_type (abfd) [r_symndx];
1687 if ((old_tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_IE))
1688 tls_type |= old_tls_type;
1689 /* If a TLS symbol is accessed using IE at least once,
1690 there is no point to use dynamic model for it. */
1691 else if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1692 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1693 || (tls_type & GOT_TLS_IE) == 0))
1695 if ((old_tls_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (tls_type))
1696 tls_type = old_tls_type;
1697 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1698 && GOT_TLS_GD_ANY_P (tls_type))
1699 tls_type |= old_tls_type;
1703 name = h->root.root.string;
1705 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1708 /* xgettext:c-format */
1709 (_("%B: `%s' accessed both as normal and "
1710 "thread local symbol"),
1712 bfd_set_error (bfd_error_bad_value);
1717 if (old_tls_type != tls_type)
1720 elf_x86_hash_entry (h)->tls_type = tls_type;
1722 elf_x86_local_got_tls_type (abfd) [r_symndx] = tls_type;
1730 if (r_type != R_386_TLS_IE)
1733 eh->has_got_reloc = 1;
1738 case R_386_TLS_LE_32:
1741 eh->has_got_reloc = 1;
1742 if (bfd_link_executable (info))
1744 info->flags |= DF_STATIC_TLS;
1749 if (eh != NULL && (sec->flags & SEC_CODE) != 0)
1750 eh->has_non_got_reloc = 1;
1752 /* We are called after all symbols have been resolved. Only
1753 relocation against STT_GNU_IFUNC symbol must go through
1756 && (bfd_link_executable (info)
1757 || h->type == STT_GNU_IFUNC))
1759 /* If this reloc is in a read-only section, we might
1760 need a copy reloc. We can't check reliably at this
1761 stage whether the section is read-only, as input
1762 sections have not yet been mapped to output sections.
1763 Tentatively set the flag for now, and correct in
1764 adjust_dynamic_symbol. */
1767 /* We may need a .plt entry if the symbol is a function
1768 defined in a shared lib or is a STT_GNU_IFUNC function
1769 referenced from the code or read-only section. */
1771 || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
1772 h->plt.refcount += 1;
1774 if (r_type == R_386_PC32)
1776 /* Since something like ".long foo - ." may be used
1777 as pointer, make sure that PLT is used if foo is
1778 a function defined in a shared library. */
1779 if ((sec->flags & SEC_CODE) == 0)
1780 h->pointer_equality_needed = 1;
1781 else if (h->type == STT_GNU_IFUNC
1782 && bfd_link_pic (info))
1785 /* xgettext:c-format */
1786 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
1787 abfd, h->root.root.string);
1788 bfd_set_error (bfd_error_bad_value);
1794 h->pointer_equality_needed = 1;
1795 /* R_386_32 can be resolved at run-time. */
1796 if (r_type == R_386_32
1797 && (sec->flags & SEC_READONLY) == 0)
1798 eh->func_pointer_refcount += 1;
1804 /* If we are creating a shared library, and this is a reloc
1805 against a global symbol, or a non PC relative reloc
1806 against a local symbol, then we need to copy the reloc
1807 into the shared library. However, if we are linking with
1808 -Bsymbolic, we do not need to copy a reloc against a
1809 global symbol which is defined in an object we are
1810 including in the link (i.e., DEF_REGULAR is set). At
1811 this point we have not seen all the input files, so it is
1812 possible that DEF_REGULAR is not set now but will be set
1813 later (it is never cleared). In case of a weak definition,
1814 DEF_REGULAR may be cleared later by a strong definition in
1815 a shared library. We account for that possibility below by
1816 storing information in the relocs_copied field of the hash
1817 table entry. A similar situation occurs when creating
1818 shared libraries and symbol visibility changes render the
1821 If on the other hand, we are creating an executable, we
1822 may need to keep relocations for symbols satisfied by a
1823 dynamic library if we manage to avoid copy relocs for the
1826 Generate dynamic pointer relocation against STT_GNU_IFUNC
1827 symbol in the non-code section. */
1828 if ((bfd_link_pic (info)
1829 && (r_type != R_386_PC32
1831 && (! (bfd_link_pie (info)
1832 || SYMBOLIC_BIND (info, h))
1833 || h->root.type == bfd_link_hash_defweak
1834 || !h->def_regular))))
1836 && h->type == STT_GNU_IFUNC
1837 && r_type == R_386_32
1838 && (sec->flags & SEC_CODE) == 0)
1839 || (ELIMINATE_COPY_RELOCS
1840 && !bfd_link_pic (info)
1842 && (h->root.type == bfd_link_hash_defweak
1843 || !h->def_regular)))
1845 struct elf_dyn_relocs *p;
1846 struct elf_dyn_relocs **head;
1848 /* We must copy these reloc types into the output file.
1849 Create a reloc section in dynobj and make room for
1853 sreloc = _bfd_elf_make_dynamic_reloc_section
1854 (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ FALSE);
1860 /* If this is a global symbol, we count the number of
1861 relocations we need for this symbol. */
1864 head = &eh->dyn_relocs;
1868 /* Track dynamic relocs needed for local syms too.
1869 We really need local syms available to do this
1874 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1879 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
1883 vpp = &elf_section_data (s)->local_dynrel;
1884 head = (struct elf_dyn_relocs **)vpp;
1888 if (p == NULL || p->sec != sec)
1890 bfd_size_type amt = sizeof *p;
1891 p = (struct elf_dyn_relocs *) bfd_alloc (htab->elf.dynobj,
1903 /* Count size relocation as PC-relative relocation. */
1904 if (r_type == R_386_PC32 || size_reloc)
1909 /* This relocation describes the C++ object vtable hierarchy.
1910 Reconstruct it for later use during GC. */
1911 case R_386_GNU_VTINHERIT:
1912 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1916 /* This relocation describes which C++ vtable entries are actually
1917 used. Record for later use during GC. */
1918 case R_386_GNU_VTENTRY:
1919 BFD_ASSERT (h != NULL);
1921 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
1929 if (r_type == R_386_GOT32X
1930 && (h == NULL || h->type != STT_GNU_IFUNC))
1931 sec->need_convert_load = 1;
1934 if (elf_section_data (sec)->this_hdr.contents != contents)
1936 if (!info->keep_memory)
1940 /* Cache the section contents for elf_link_input_bfd. */
1941 elf_section_data (sec)->this_hdr.contents = contents;
1948 if (elf_section_data (sec)->this_hdr.contents != contents)
1950 sec->check_relocs_failed = 1;
1954 /* Allocate space in .plt, .got and associated reloc sections for
1958 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
1960 struct bfd_link_info *info;
1961 struct elf_x86_link_hash_table *htab;
1962 struct elf_x86_link_hash_entry *eh;
1963 struct elf_dyn_relocs *p;
1964 unsigned plt_entry_size;
1965 bfd_boolean resolved_to_zero;
1967 if (h->root.type == bfd_link_hash_indirect)
1970 eh = (struct elf_x86_link_hash_entry *) h;
1972 info = (struct bfd_link_info *) inf;
1973 htab = elf_x86_hash_table (info, I386_ELF_DATA);
1977 plt_entry_size = htab->plt.plt_entry_size;
1979 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
1984 /* Clear the reference count of function pointer relocations if
1985 symbol isn't a normal function. */
1986 if (h->type != STT_FUNC)
1987 eh->func_pointer_refcount = 0;
1989 /* We can't use the GOT PLT if pointer equality is needed since
1990 finish_dynamic_symbol won't clear symbol value and the dynamic
1991 linker won't update the GOT slot. We will get into an infinite
1992 loop at run-time. */
1993 if (htab->plt_got != NULL
1994 && h->type != STT_GNU_IFUNC
1995 && !h->pointer_equality_needed
1996 && h->plt.refcount > 0
1997 && h->got.refcount > 0)
1999 /* Don't use the regular PLT if there are both GOT and GOTPLT
2001 h->plt.offset = (bfd_vma) -1;
2003 /* Use the GOT PLT. */
2004 eh->plt_got.refcount = 1;
2007 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2008 here if it is defined and referenced in a non-shared object. */
2009 if (h->type == STT_GNU_IFUNC
2012 if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h, &eh->dyn_relocs,
2013 &htab->readonly_dynrelocs_against_ifunc,
2019 asection *s = htab->plt_second;
2020 if (h->plt.offset != (bfd_vma) -1 && s != NULL)
2022 /* Use the second PLT section if it is created. */
2023 eh->plt_second.offset = s->size;
2025 /* Make room for this entry in the second PLT section. */
2026 s->size += htab->non_lazy_plt->plt_entry_size;
2034 /* Don't create the PLT entry if there are only function pointer
2035 relocations which can be resolved at run-time. */
2036 else if (htab->elf.dynamic_sections_created
2037 && (h->plt.refcount > eh->func_pointer_refcount
2038 || eh->plt_got.refcount > 0))
2040 bfd_boolean use_plt_got = eh->plt_got.refcount > 0;
2042 /* Clear the reference count of function pointer relocations
2044 eh->func_pointer_refcount = 0;
2046 /* Make sure this symbol is output as a dynamic symbol.
2047 Undefined weak syms won't yet be marked as dynamic. */
2048 if (h->dynindx == -1
2050 && !resolved_to_zero
2051 && h->root.type == bfd_link_hash_undefweak)
2053 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2057 if (bfd_link_pic (info)
2058 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2060 asection *s = htab->elf.splt;
2061 asection *second_s = htab->plt_second;
2062 asection *got_s = htab->plt_got;
2064 /* If this is the first .plt entry, make room for the special
2065 first entry. The .plt section is used by prelink to undo
2066 prelinking for dynamic relocations. */
2068 s->size = htab->plt.has_plt0 * plt_entry_size;
2071 eh->plt_got.offset = got_s->size;
2074 h->plt.offset = s->size;
2076 eh->plt_second.offset = second_s->size;
2079 /* If this symbol is not defined in a regular file, and we are
2080 not generating a shared library, then set the symbol to this
2081 location in the .plt. This is required to make function
2082 pointers compare as equal between the normal executable and
2083 the shared library. */
2084 if (! bfd_link_pic (info)
2089 /* We need to make a call to the entry of the GOT PLT
2090 instead of regular PLT entry. */
2091 h->root.u.def.section = got_s;
2092 h->root.u.def.value = eh->plt_got.offset;
2098 /* We need to make a call to the entry of the
2099 second PLT instead of regular PLT entry. */
2100 h->root.u.def.section = second_s;
2101 h->root.u.def.value = eh->plt_second.offset;
2105 h->root.u.def.section = s;
2106 h->root.u.def.value = h->plt.offset;
2111 /* Make room for this entry. */
2113 got_s->size += htab->non_lazy_plt->plt_entry_size;
2116 s->size += plt_entry_size;
2118 second_s->size += htab->non_lazy_plt->plt_entry_size;
2120 /* We also need to make an entry in the .got.plt section,
2121 which will be placed in the .got section by the linker
2123 htab->elf.sgotplt->size += 4;
2125 /* There should be no PLT relocation against resolved
2126 undefined weak symbol in executable. */
2127 if (!resolved_to_zero)
2129 /* We also need to make an entry in the .rel.plt
2131 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
2132 htab->elf.srelplt->reloc_count++;
2136 if (htab->is_vxworks && !bfd_link_pic (info))
2138 /* VxWorks has a second set of relocations for each PLT entry
2139 in executables. They go in a separate relocation section,
2140 which is processed by the kernel loader. */
2142 /* There are two relocations for the initial PLT entry: an
2143 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2144 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2146 asection *srelplt2 = htab->srelplt2;
2147 if (h->plt.offset == plt_entry_size)
2148 srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
2150 /* There are two extra relocations for each subsequent PLT entry:
2151 an R_386_32 relocation for the GOT entry, and an R_386_32
2152 relocation for the PLT entry. */
2154 srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
2159 eh->plt_got.offset = (bfd_vma) -1;
2160 h->plt.offset = (bfd_vma) -1;
2166 eh->plt_got.offset = (bfd_vma) -1;
2167 h->plt.offset = (bfd_vma) -1;
2171 eh->tlsdesc_got = (bfd_vma) -1;
2173 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2174 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2175 if (h->got.refcount > 0
2176 && bfd_link_executable (info)
2178 && (elf_x86_hash_entry (h)->tls_type & GOT_TLS_IE))
2179 h->got.offset = (bfd_vma) -1;
2180 else if (h->got.refcount > 0)
2184 int tls_type = elf_x86_hash_entry (h)->tls_type;
2186 /* Make sure this symbol is output as a dynamic symbol.
2187 Undefined weak syms won't yet be marked as dynamic. */
2188 if (h->dynindx == -1
2190 && !resolved_to_zero
2191 && h->root.type == bfd_link_hash_undefweak)
2193 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2198 if (GOT_TLS_GDESC_P (tls_type))
2200 eh->tlsdesc_got = htab->elf.sgotplt->size
2201 - elf_x86_compute_jump_table_size (htab);
2202 htab->elf.sgotplt->size += 8;
2203 h->got.offset = (bfd_vma) -2;
2205 if (! GOT_TLS_GDESC_P (tls_type)
2206 || GOT_TLS_GD_P (tls_type))
2208 h->got.offset = s->size;
2210 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2211 if (GOT_TLS_GD_P (tls_type) || tls_type == GOT_TLS_IE_BOTH)
2214 dyn = htab->elf.dynamic_sections_created;
2215 /* R_386_TLS_IE_32 needs one dynamic relocation,
2216 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2217 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2218 need two), R_386_TLS_GD needs one if local symbol and two if
2219 global. No dynamic relocation against resolved undefined weak
2220 symbol in executable. */
2221 if (tls_type == GOT_TLS_IE_BOTH)
2222 htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel);
2223 else if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
2224 || (tls_type & GOT_TLS_IE))
2225 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
2226 else if (GOT_TLS_GD_P (tls_type))
2227 htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel);
2228 else if (! GOT_TLS_GDESC_P (tls_type)
2229 && ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2230 && !resolved_to_zero)
2231 || h->root.type != bfd_link_hash_undefweak)
2232 && (bfd_link_pic (info)
2233 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2234 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
2235 if (GOT_TLS_GDESC_P (tls_type))
2236 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
2239 h->got.offset = (bfd_vma) -1;
2241 if (eh->dyn_relocs == NULL)
2244 /* In the shared -Bsymbolic case, discard space allocated for
2245 dynamic pc-relative relocs against symbols which turn out to be
2246 defined in regular objects. For the normal shared case, discard
2247 space for pc-relative relocs that have become local due to symbol
2248 visibility changes. */
2250 if (bfd_link_pic (info))
2252 /* The only reloc that uses pc_count is R_386_PC32, which will
2253 appear on a call or on something like ".long foo - .". We
2254 want calls to protected symbols to resolve directly to the
2255 function rather than going via the plt. If people want
2256 function pointer comparisons to work as expected then they
2257 should avoid writing assembly like ".long foo - .". */
2258 if (SYMBOL_CALLS_LOCAL (info, h))
2260 struct elf_dyn_relocs **pp;
2262 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2264 p->count -= p->pc_count;
2273 if (htab->is_vxworks)
2275 struct elf_dyn_relocs **pp;
2276 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2278 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
2285 /* Also discard relocs on undefined weak syms with non-default
2286 visibility or in PIE. */
2287 if (eh->dyn_relocs != NULL
2288 && h->root.type == bfd_link_hash_undefweak)
2290 /* Undefined weak symbol is never bound locally in shared
2292 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2293 || resolved_to_zero)
2297 /* Keep dynamic non-GOT/non-PLT relocation so that we
2298 can branch to 0 without PLT. */
2299 struct elf_dyn_relocs **pp;
2301 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2302 if (p->pc_count == 0)
2306 /* Remove non-R_386_PC32 relocation. */
2307 p->count = p->pc_count;
2311 if (eh->dyn_relocs != NULL)
2313 /* Make sure undefined weak symbols are output
2314 as dynamic symbols in PIEs for dynamic non-GOT
2315 non-PLT reloations. */
2316 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2321 eh->dyn_relocs = NULL;
2323 else if (h->dynindx == -1
2324 && !h->forced_local)
2326 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2331 else if (ELIMINATE_COPY_RELOCS)
2333 /* For the non-shared case, discard space for relocs against
2334 symbols which turn out to need copy relocs or are not
2335 dynamic. Keep dynamic relocations for run-time function
2336 pointer initialization. */
2338 if ((!h->non_got_ref
2339 || eh->func_pointer_refcount > 0
2340 || (h->root.type == bfd_link_hash_undefweak
2341 && !resolved_to_zero))
2344 || (htab->elf.dynamic_sections_created
2345 && (h->root.type == bfd_link_hash_undefweak
2346 || h->root.type == bfd_link_hash_undefined))))
2348 /* Make sure this symbol is output as a dynamic symbol.
2349 Undefined weak syms won't yet be marked as dynamic. */
2350 if (h->dynindx == -1
2352 && !resolved_to_zero
2353 && h->root.type == bfd_link_hash_undefweak)
2355 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2359 /* If that succeeded, we know we'll be keeping all the
2361 if (h->dynindx != -1)
2365 eh->dyn_relocs = NULL;
2366 eh->func_pointer_refcount = 0;
2371 /* Finally, allocate space. */
2372 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2376 sreloc = elf_section_data (p->sec)->sreloc;
2378 BFD_ASSERT (sreloc != NULL);
2379 sreloc->size += p->count * sizeof (Elf32_External_Rel);
2385 /* Allocate space in .plt, .got and associated reloc sections for
2386 local dynamic relocs. */
2389 elf_i386_allocate_local_dynrelocs (void **slot, void *inf)
2391 struct elf_link_hash_entry *h
2392 = (struct elf_link_hash_entry *) *slot;
2394 if (h->type != STT_GNU_IFUNC
2398 || h->root.type != bfd_link_hash_defined)
2401 return elf_i386_allocate_dynrelocs (h, inf);
2404 /* Convert load via the GOT slot to load immediate. */
2407 elf_i386_convert_load (bfd *abfd, asection *sec,
2408 struct bfd_link_info *link_info)
2410 struct elf_x86_link_hash_table *htab;
2411 Elf_Internal_Shdr *symtab_hdr;
2412 Elf_Internal_Rela *internal_relocs;
2413 Elf_Internal_Rela *irel, *irelend;
2415 bfd_boolean changed;
2416 bfd_signed_vma *local_got_refcounts;
2418 /* Don't even try to convert non-ELF outputs. */
2419 if (!is_elf_hash_table (link_info->hash))
2422 /* Nothing to do if there is no need or no output. */
2423 if ((sec->flags & (SEC_CODE | SEC_RELOC)) != (SEC_CODE | SEC_RELOC)
2424 || sec->need_convert_load == 0
2425 || bfd_is_abs_section (sec->output_section))
2428 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2430 /* Load the relocations for this section. */
2431 internal_relocs = (_bfd_elf_link_read_relocs
2432 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
2433 link_info->keep_memory));
2434 if (internal_relocs == NULL)
2438 htab = elf_x86_hash_table (link_info, I386_ELF_DATA);
2439 local_got_refcounts = elf_local_got_refcounts (abfd);
2441 /* Get the section contents. */
2442 if (elf_section_data (sec)->this_hdr.contents != NULL)
2443 contents = elf_section_data (sec)->this_hdr.contents;
2446 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2450 irelend = internal_relocs + sec->reloc_count;
2451 for (irel = internal_relocs; irel < irelend; irel++)
2453 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
2454 unsigned int r_symndx;
2455 struct elf_link_hash_entry *h;
2456 bfd_boolean converted;
2458 /* Don't convert R_386_GOT32 since we can't tell if it is applied
2459 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
2460 if (r_type != R_386_GOT32X)
2463 r_symndx = ELF32_R_SYM (irel->r_info);
2464 if (r_symndx < symtab_hdr->sh_info)
2465 h = _bfd_elf_x86_get_local_sym_hash (htab, sec->owner,
2466 (const Elf_Internal_Rela *) irel,
2470 h = elf_sym_hashes (abfd)[r_symndx - symtab_hdr->sh_info];
2471 while (h->root.type == bfd_link_hash_indirect
2472 || h->root.type == bfd_link_hash_warning)
2473 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2476 /* STT_GNU_IFUNC must keep GOT32 relocations. */
2477 if (h != NULL && h->type == STT_GNU_IFUNC)
2481 if (!elf_i386_convert_load_reloc (abfd, symtab_hdr, contents,
2482 irel, h, &converted, link_info))
2487 changed = converted;
2490 if (h->got.refcount > 0)
2491 h->got.refcount -= 1;
2495 if (local_got_refcounts != NULL
2496 && local_got_refcounts[r_symndx] > 0)
2497 local_got_refcounts[r_symndx] -= 1;
2502 if (contents != NULL
2503 && elf_section_data (sec)->this_hdr.contents != contents)
2505 if (!changed && !link_info->keep_memory)
2509 /* Cache the section contents for elf_link_input_bfd. */
2510 elf_section_data (sec)->this_hdr.contents = contents;
2514 if (elf_section_data (sec)->relocs != internal_relocs)
2517 free (internal_relocs);
2519 elf_section_data (sec)->relocs = internal_relocs;
2525 if (contents != NULL
2526 && elf_section_data (sec)->this_hdr.contents != contents)
2528 if (internal_relocs != NULL
2529 && elf_section_data (sec)->relocs != internal_relocs)
2530 free (internal_relocs);
2534 /* Set the sizes of the dynamic sections. */
2537 elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
2539 struct elf_x86_link_hash_table *htab;
2545 htab = elf_x86_hash_table (info, I386_ELF_DATA);
2548 dynobj = htab->elf.dynobj;
2552 /* Set up .got offsets for local syms, and space for local dynamic
2554 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
2556 bfd_signed_vma *local_got;
2557 bfd_signed_vma *end_local_got;
2558 char *local_tls_type;
2559 bfd_vma *local_tlsdesc_gotent;
2560 bfd_size_type locsymcount;
2561 Elf_Internal_Shdr *symtab_hdr;
2564 if (! is_x86_elf (ibfd, htab))
2567 for (s = ibfd->sections; s != NULL; s = s->next)
2569 struct elf_dyn_relocs *p;
2571 if (!elf_i386_convert_load (ibfd, s, info))
2574 for (p = ((struct elf_dyn_relocs *)
2575 elf_section_data (s)->local_dynrel);
2579 if (!bfd_is_abs_section (p->sec)
2580 && bfd_is_abs_section (p->sec->output_section))
2582 /* Input section has been discarded, either because
2583 it is a copy of a linkonce section or due to
2584 linker script /DISCARD/, so we'll be discarding
2587 else if (htab->is_vxworks
2588 && strcmp (p->sec->output_section->name,
2591 /* Relocations in vxworks .tls_vars sections are
2592 handled specially by the loader. */
2594 else if (p->count != 0)
2596 srel = elf_section_data (p->sec)->sreloc;
2597 srel->size += p->count * sizeof (Elf32_External_Rel);
2598 if ((p->sec->output_section->flags & SEC_READONLY) != 0
2599 && (info->flags & DF_TEXTREL) == 0)
2601 info->flags |= DF_TEXTREL;
2602 if ((info->warn_shared_textrel && bfd_link_pic (info))
2603 || info->error_textrel)
2604 /* xgettext:c-format */
2605 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
2606 p->sec->owner, p->sec);
2612 local_got = elf_local_got_refcounts (ibfd);
2616 symtab_hdr = &elf_symtab_hdr (ibfd);
2617 locsymcount = symtab_hdr->sh_info;
2618 end_local_got = local_got + locsymcount;
2619 local_tls_type = elf_x86_local_got_tls_type (ibfd);
2620 local_tlsdesc_gotent = elf_x86_local_tlsdesc_gotent (ibfd);
2622 srel = htab->elf.srelgot;
2623 for (; local_got < end_local_got;
2624 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
2626 *local_tlsdesc_gotent = (bfd_vma) -1;
2629 if (GOT_TLS_GDESC_P (*local_tls_type))
2631 *local_tlsdesc_gotent = htab->elf.sgotplt->size
2632 - elf_x86_compute_jump_table_size (htab);
2633 htab->elf.sgotplt->size += 8;
2634 *local_got = (bfd_vma) -2;
2636 if (! GOT_TLS_GDESC_P (*local_tls_type)
2637 || GOT_TLS_GD_P (*local_tls_type))
2639 *local_got = s->size;
2641 if (GOT_TLS_GD_P (*local_tls_type)
2642 || *local_tls_type == GOT_TLS_IE_BOTH)
2645 if (bfd_link_pic (info)
2646 || GOT_TLS_GD_ANY_P (*local_tls_type)
2647 || (*local_tls_type & GOT_TLS_IE))
2649 if (*local_tls_type == GOT_TLS_IE_BOTH)
2650 srel->size += 2 * sizeof (Elf32_External_Rel);
2651 else if (GOT_TLS_GD_P (*local_tls_type)
2652 || ! GOT_TLS_GDESC_P (*local_tls_type))
2653 srel->size += sizeof (Elf32_External_Rel);
2654 if (GOT_TLS_GDESC_P (*local_tls_type))
2655 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
2659 *local_got = (bfd_vma) -1;
2663 if (htab->tls_ld_or_ldm_got.refcount > 0)
2665 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2667 htab->tls_ld_or_ldm_got.offset = htab->elf.sgot->size;
2668 htab->elf.sgot->size += 8;
2669 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
2672 htab->tls_ld_or_ldm_got.offset = -1;
2674 /* Allocate global sym .plt and .got entries, and space for global
2675 sym dynamic relocs. */
2676 elf_link_hash_traverse (&htab->elf, elf_i386_allocate_dynrelocs, info);
2678 /* Allocate .plt and .got entries, and space for local symbols. */
2679 htab_traverse (htab->loc_hash_table,
2680 elf_i386_allocate_local_dynrelocs,
2683 /* For every jump slot reserved in the sgotplt, reloc_count is
2684 incremented. However, when we reserve space for TLS descriptors,
2685 it's not incremented, so in order to compute the space reserved
2686 for them, it suffices to multiply the reloc count by the jump
2689 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2690 so that R_386_IRELATIVE entries come last. */
2691 if (htab->elf.srelplt)
2693 htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
2694 htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;
2695 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
2697 else if (htab->elf.irelplt)
2698 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
2701 if (htab->elf.sgotplt)
2703 /* Don't allocate .got.plt section if there are no GOT nor PLT
2704 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
2705 if ((htab->elf.hgot == NULL
2706 || !htab->elf.hgot->ref_regular_nonweak)
2707 && (htab->elf.sgotplt->size
2708 == get_elf_backend_data (output_bfd)->got_header_size)
2709 && (htab->elf.splt == NULL
2710 || htab->elf.splt->size == 0)
2711 && (htab->elf.sgot == NULL
2712 || htab->elf.sgot->size == 0)
2713 && (htab->elf.iplt == NULL
2714 || htab->elf.iplt->size == 0)
2715 && (htab->elf.igotplt == NULL
2716 || htab->elf.igotplt->size == 0))
2717 htab->elf.sgotplt->size = 0;
2720 if (_bfd_elf_eh_frame_present (info))
2722 if (htab->plt_eh_frame != NULL
2723 && htab->elf.splt != NULL
2724 && htab->elf.splt->size != 0
2725 && !bfd_is_abs_section (htab->elf.splt->output_section))
2726 htab->plt_eh_frame->size = htab->plt.eh_frame_plt_size;
2728 if (htab->plt_got_eh_frame != NULL
2729 && htab->plt_got != NULL
2730 && htab->plt_got->size != 0
2731 && !bfd_is_abs_section (htab->plt_got->output_section))
2732 htab->plt_got_eh_frame->size
2733 = htab->non_lazy_plt->eh_frame_plt_size;
2735 /* Unwind info for the second PLT and .plt.got sections are
2737 if (htab->plt_second_eh_frame != NULL
2738 && htab->plt_second != NULL
2739 && htab->plt_second->size != 0
2740 && !bfd_is_abs_section (htab->plt_second->output_section))
2741 htab->plt_second_eh_frame->size
2742 = htab->non_lazy_plt->eh_frame_plt_size;
2745 /* We now have determined the sizes of the various dynamic sections.
2746 Allocate memory for them. */
2748 for (s = dynobj->sections; s != NULL; s = s->next)
2750 bfd_boolean strip_section = TRUE;
2752 if ((s->flags & SEC_LINKER_CREATED) == 0)
2755 if (s == htab->elf.splt
2756 || s == htab->elf.sgot)
2758 /* Strip this section if we don't need it; see the
2760 /* We'd like to strip these sections if they aren't needed, but if
2761 we've exported dynamic symbols from them we must leave them.
2762 It's too late to tell BFD to get rid of the symbols. */
2764 if (htab->elf.hplt != NULL)
2765 strip_section = FALSE;
2767 else if (s == htab->elf.sgotplt
2768 || s == htab->elf.iplt
2769 || s == htab->elf.igotplt
2770 || s == htab->plt_second
2771 || s == htab->plt_got
2772 || s == htab->plt_eh_frame
2773 || s == htab->plt_got_eh_frame
2774 || s == htab->plt_second_eh_frame
2775 || s == htab->elf.sdynbss
2776 || s == htab->elf.sdynrelro)
2778 /* Strip these too. */
2780 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rel"))
2783 && s != htab->elf.srelplt
2784 && s != htab->srelplt2)
2787 /* We use the reloc_count field as a counter if we need
2788 to copy relocs into the output file. */
2793 /* It's not one of our sections, so don't allocate space. */
2799 /* If we don't need this section, strip it from the
2800 output file. This is mostly to handle .rel.bss and
2801 .rel.plt. We must create both sections in
2802 create_dynamic_sections, because they must be created
2803 before the linker maps input sections to output
2804 sections. The linker does that before
2805 adjust_dynamic_symbol is called, and it is that
2806 function which decides whether anything needs to go
2807 into these sections. */
2809 s->flags |= SEC_EXCLUDE;
2813 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2816 /* Allocate memory for the section contents. We use bfd_zalloc
2817 here in case unused entries are not reclaimed before the
2818 section's contents are written out. This should not happen,
2819 but this way if it does, we get a R_386_NONE reloc instead
2821 s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
2822 if (s->contents == NULL)
2826 if (htab->plt_eh_frame != NULL
2827 && htab->plt_eh_frame->contents != NULL)
2829 memcpy (htab->plt_eh_frame->contents,
2830 htab->plt.eh_frame_plt,
2831 htab->plt_eh_frame->size);
2832 bfd_put_32 (dynobj, htab->elf.splt->size,
2833 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
2836 if (htab->plt_got_eh_frame != NULL
2837 && htab->plt_got_eh_frame->contents != NULL)
2839 memcpy (htab->plt_got_eh_frame->contents,
2840 htab->non_lazy_plt->eh_frame_plt,
2841 htab->plt_got_eh_frame->size);
2842 bfd_put_32 (dynobj, htab->plt_got->size,
2843 (htab->plt_got_eh_frame->contents
2844 + PLT_FDE_LEN_OFFSET));
2847 if (htab->plt_second_eh_frame != NULL
2848 && htab->plt_second_eh_frame->contents != NULL)
2850 memcpy (htab->plt_second_eh_frame->contents,
2851 htab->non_lazy_plt->eh_frame_plt,
2852 htab->plt_second_eh_frame->size);
2853 bfd_put_32 (dynobj, htab->plt_second->size,
2854 (htab->plt_second_eh_frame->contents
2855 + PLT_FDE_LEN_OFFSET));
2858 if (htab->elf.dynamic_sections_created)
2860 /* Add some entries to the .dynamic section. We fill in the
2861 values later, in elf_i386_finish_dynamic_sections, but we
2862 must add the entries now so that we get the correct size for
2863 the .dynamic section. The DT_DEBUG entry is filled in by the
2864 dynamic linker and used by the debugger. */
2865 #define add_dynamic_entry(TAG, VAL) \
2866 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2868 if (bfd_link_executable (info))
2870 if (!add_dynamic_entry (DT_DEBUG, 0))
2874 if (htab->elf.splt->size != 0)
2876 /* DT_PLTGOT is used by prelink even if there is no PLT
2878 if (!add_dynamic_entry (DT_PLTGOT, 0))
2882 if (htab->elf.srelplt->size != 0)
2884 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
2885 || !add_dynamic_entry (DT_PLTREL, DT_REL)
2886 || !add_dynamic_entry (DT_JMPREL, 0))
2892 if (!add_dynamic_entry (DT_REL, 0)
2893 || !add_dynamic_entry (DT_RELSZ, 0)
2894 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
2897 /* If any dynamic relocs apply to a read-only section,
2898 then we need a DT_TEXTREL entry. */
2899 if ((info->flags & DF_TEXTREL) == 0)
2900 elf_link_hash_traverse (&htab->elf,
2901 _bfd_x86_elf_readonly_dynrelocs,
2904 if ((info->flags & DF_TEXTREL) != 0)
2906 if (htab->readonly_dynrelocs_against_ifunc)
2908 info->callbacks->einfo
2909 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
2910 bfd_set_error (bfd_error_bad_value);
2914 if (!add_dynamic_entry (DT_TEXTREL, 0))
2918 if (htab->is_vxworks
2919 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
2922 #undef add_dynamic_entry
2927 /* Set the correct type for an x86 ELF section. We do this by the
2928 section name, which is a hack, but ought to work. */
2931 elf_i386_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
2932 Elf_Internal_Shdr *hdr,
2937 name = bfd_get_section_name (abfd, sec);
2939 /* This is an ugly, but unfortunately necessary hack that is
2940 needed when producing EFI binaries on x86. It tells
2941 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2942 containing ELF relocation info. We need this hack in order to
2943 be able to generate ELF binaries that can be translated into
2944 EFI applications (which are essentially COFF objects). Those
2945 files contain a COFF ".reloc" section inside an ELFNN object,
2946 which would normally cause BFD to segfault because it would
2947 attempt to interpret this section as containing relocation
2948 entries for section "oc". With this hack enabled, ".reloc"
2949 will be treated as a normal data section, which will avoid the
2950 segfault. However, you won't be able to create an ELFNN binary
2951 with a section named "oc" that needs relocations, but that's
2952 the kind of ugly side-effects you get when detecting section
2953 types based on their names... In practice, this limitation is
2954 unlikely to bite. */
2955 if (strcmp (name, ".reloc") == 0)
2956 hdr->sh_type = SHT_PROGBITS;
2961 /* Return the relocation value for @tpoff relocation
2962 if STT_TLS virtual address is ADDRESS. */
2965 elf_i386_tpoff (struct bfd_link_info *info, bfd_vma address)
2967 struct elf_link_hash_table *htab = elf_hash_table (info);
2968 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
2969 bfd_vma static_tls_size;
2971 /* If tls_sec is NULL, we should have signalled an error already. */
2972 if (htab->tls_sec == NULL)
2975 /* Consider special static TLS alignment requirements. */
2976 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
2977 return static_tls_size + htab->tls_sec->vma - address;
2980 /* Relocate an i386 ELF section. */
2983 elf_i386_relocate_section (bfd *output_bfd,
2984 struct bfd_link_info *info,
2986 asection *input_section,
2988 Elf_Internal_Rela *relocs,
2989 Elf_Internal_Sym *local_syms,
2990 asection **local_sections)
2992 struct elf_x86_link_hash_table *htab;
2993 Elf_Internal_Shdr *symtab_hdr;
2994 struct elf_link_hash_entry **sym_hashes;
2995 bfd_vma *local_got_offsets;
2996 bfd_vma *local_tlsdesc_gotents;
2997 Elf_Internal_Rela *rel;
2998 Elf_Internal_Rela *wrel;
2999 Elf_Internal_Rela *relend;
3000 bfd_boolean is_vxworks_tls;
3001 unsigned plt_entry_size;
3003 /* Skip if check_relocs failed. */
3004 if (input_section->check_relocs_failed)
3007 htab = elf_x86_hash_table (info, I386_ELF_DATA);
3011 BFD_ASSERT (is_x86_elf (input_bfd, htab));
3013 symtab_hdr = &elf_symtab_hdr (input_bfd);
3014 sym_hashes = elf_sym_hashes (input_bfd);
3015 local_got_offsets = elf_local_got_offsets (input_bfd);
3016 local_tlsdesc_gotents = elf_x86_local_tlsdesc_gotent (input_bfd);
3017 /* We have to handle relocations in vxworks .tls_vars sections
3018 specially, because the dynamic loader is 'weird'. */
3019 is_vxworks_tls = (htab->is_vxworks
3020 && bfd_link_pic (info)
3021 && !strcmp (input_section->output_section->name,
3024 _bfd_x86_elf_set_tls_module_base (info);
3026 plt_entry_size = htab->plt.plt_entry_size;
3028 rel = wrel = relocs;
3029 relend = relocs + input_section->reloc_count;
3030 for (; rel < relend; wrel++, rel++)
3032 unsigned int r_type;
3033 reloc_howto_type *howto;
3034 unsigned long r_symndx;
3035 struct elf_link_hash_entry *h;
3036 struct elf_x86_link_hash_entry *eh;
3037 Elf_Internal_Sym *sym;
3039 bfd_vma off, offplt, plt_offset;
3041 bfd_boolean unresolved_reloc;
3042 bfd_reloc_status_type r;
3046 asection *resolved_plt;
3047 bfd_boolean resolved_to_zero;
3048 bfd_boolean relative_reloc;
3050 r_type = ELF32_R_TYPE (rel->r_info);
3051 if (r_type == R_386_GNU_VTINHERIT
3052 || r_type == R_386_GNU_VTENTRY)
3059 if ((indx = r_type) >= R_386_standard
3060 && ((indx = r_type - R_386_ext_offset) - R_386_standard
3061 >= R_386_ext - R_386_standard)
3062 && ((indx = r_type - R_386_tls_offset) - R_386_ext
3063 >= R_386_ext2 - R_386_ext))
3064 return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
3066 howto = elf_howto_table + indx;
3068 r_symndx = ELF32_R_SYM (rel->r_info);
3072 unresolved_reloc = FALSE;
3073 if (r_symndx < symtab_hdr->sh_info)
3075 sym = local_syms + r_symndx;
3076 sec = local_sections[r_symndx];
3077 relocation = (sec->output_section->vma
3078 + sec->output_offset
3080 st_size = sym->st_size;
3082 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION
3083 && ((sec->flags & SEC_MERGE) != 0
3084 || (bfd_link_relocatable (info)
3085 && sec->output_offset != 0)))
3088 bfd_byte *where = contents + rel->r_offset;
3090 switch (howto->size)
3093 addend = bfd_get_8 (input_bfd, where);
3094 if (howto->pc_relative)
3096 addend = (addend ^ 0x80) - 0x80;
3101 addend = bfd_get_16 (input_bfd, where);
3102 if (howto->pc_relative)
3104 addend = (addend ^ 0x8000) - 0x8000;
3109 addend = bfd_get_32 (input_bfd, where);
3110 if (howto->pc_relative)
3112 addend = (addend ^ 0x80000000) - 0x80000000;
3120 if (bfd_link_relocatable (info))
3121 addend += sec->output_offset;
3124 asection *msec = sec;
3125 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec,
3127 addend -= relocation;
3128 addend += msec->output_section->vma + msec->output_offset;
3131 switch (howto->size)
3134 /* FIXME: overflow checks. */
3135 if (howto->pc_relative)
3137 bfd_put_8 (input_bfd, addend, where);
3140 if (howto->pc_relative)
3142 bfd_put_16 (input_bfd, addend, where);
3145 if (howto->pc_relative)
3147 bfd_put_32 (input_bfd, addend, where);
3151 else if (!bfd_link_relocatable (info)
3152 && ELF32_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
3154 /* Relocate against local STT_GNU_IFUNC symbol. */
3155 h = _bfd_elf_x86_get_local_sym_hash (htab, input_bfd, rel,
3160 /* Set STT_GNU_IFUNC symbol value. */
3161 h->root.u.def.value = sym->st_value;
3162 h->root.u.def.section = sec;
3167 bfd_boolean warned ATTRIBUTE_UNUSED;
3168 bfd_boolean ignored ATTRIBUTE_UNUSED;
3170 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3171 r_symndx, symtab_hdr, sym_hashes,
3173 unresolved_reloc, warned, ignored);
3177 if (sec != NULL && discarded_section (sec))
3179 _bfd_clear_contents (howto, input_bfd, input_section,
3180 contents + rel->r_offset);
3181 wrel->r_offset = rel->r_offset;
3185 /* For ld -r, remove relocations in debug sections against
3186 sections defined in discarded sections. Not done for
3187 eh_frame editing code expects to be present. */
3188 if (bfd_link_relocatable (info)
3189 && (input_section->flags & SEC_DEBUGGING))
3195 if (bfd_link_relocatable (info))
3202 eh = (struct elf_x86_link_hash_entry *) h;
3204 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3205 it here if it is defined in a non-shared object. */
3207 && h->type == STT_GNU_IFUNC
3210 asection *gotplt, *base_got;
3214 if ((input_section->flags & SEC_ALLOC) == 0)
3216 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3217 sections because such sections are not SEC_ALLOC and
3218 thus ld.so will not process them. */
3219 if ((input_section->flags & SEC_DEBUGGING) != 0)
3224 /* STT_GNU_IFUNC symbol must go through PLT. */
3225 if (htab->elf.splt != NULL)
3227 if (htab->plt_second != NULL)
3229 resolved_plt = htab->plt_second;
3230 plt_offset = eh->plt_second.offset;
3234 resolved_plt = htab->elf.splt;
3235 plt_offset = h->plt.offset;
3237 gotplt = htab->elf.sgotplt;
3241 resolved_plt = htab->elf.iplt;
3242 plt_offset = h->plt.offset;
3243 gotplt = htab->elf.igotplt;
3253 base_got = htab->elf.sgot;
3254 off = h->got.offset;
3256 if (base_got == NULL)
3259 if (off == (bfd_vma) -1)
3261 /* We can't use h->got.offset here to save state, or
3262 even just remember the offset, as finish_dynamic_symbol
3263 would use that as offset into .got. */
3265 if (h->plt.offset == (bfd_vma) -1)
3268 if (htab->elf.splt != NULL)
3270 plt_index = (h->plt.offset / plt_entry_size
3271 - htab->plt.has_plt0);
3272 off = (plt_index + 3) * 4;
3273 base_got = htab->elf.sgotplt;
3277 plt_index = h->plt.offset / plt_entry_size;
3278 off = plt_index * 4;
3279 base_got = htab->elf.igotplt;
3282 if (h->dynindx == -1
3286 /* This references the local defitionion. We must
3287 initialize this entry in the global offset table.
3288 Since the offset must always be a multiple of 8,
3289 we use the least significant bit to record
3290 whether we have initialized it already.
3292 When doing a dynamic link, we create a .rela.got
3293 relocation entry to initialize the value. This
3294 is done in the finish_dynamic_symbol routine. */
3299 bfd_put_32 (output_bfd, relocation,
3300 base_got->contents + off);
3308 relocation = (base_got->output_section->vma
3309 + base_got->output_offset + off
3310 - gotplt->output_section->vma
3311 - gotplt->output_offset);
3313 if (rel->r_offset > 1
3314 && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5
3315 && *(contents + rel->r_offset - 2) != 0x8d)
3317 if (bfd_link_pic (info))
3318 goto disallow_got32;
3320 /* Add the GOT base if there is no base register. */
3321 relocation += (gotplt->output_section->vma
3322 + gotplt->output_offset);
3324 else if (htab->elf.splt == NULL)
3326 /* Adjust for static executables. */
3327 relocation += gotplt->output_offset;
3333 if (h->plt.offset == (bfd_vma) -1)
3335 /* Handle static pointers of STT_GNU_IFUNC symbols. */
3336 if (r_type == R_386_32
3337 && (input_section->flags & SEC_CODE) == 0)
3338 goto do_ifunc_pointer;
3339 goto bad_ifunc_reloc;
3342 relocation = (resolved_plt->output_section->vma
3343 + resolved_plt->output_offset + plt_offset);
3349 if (h->root.root.string)
3350 name = h->root.root.string;
3352 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3355 /* xgettext:c-format */
3356 (_("%B: relocation %s against STT_GNU_IFUNC "
3357 "symbol `%s' isn't supported"), input_bfd,
3359 bfd_set_error (bfd_error_bad_value);
3363 /* Generate dynamic relcoation only when there is a
3364 non-GOT reference in a shared object. */
3365 if ((bfd_link_pic (info) && h->non_got_ref)
3366 || h->plt.offset == (bfd_vma) -1)
3368 Elf_Internal_Rela outrel;
3373 /* Need a dynamic relocation to get the real function
3375 offset = _bfd_elf_section_offset (output_bfd,
3379 if (offset == (bfd_vma) -1
3380 || offset == (bfd_vma) -2)
3383 outrel.r_offset = (input_section->output_section->vma
3384 + input_section->output_offset
3387 if (h->dynindx == -1
3389 || bfd_link_executable (info))
3391 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
3392 h->root.root.string,
3393 h->root.u.def.section->owner);
3395 /* This symbol is resolved locally. */
3396 outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
3397 bfd_put_32 (output_bfd,
3398 (h->root.u.def.value
3399 + h->root.u.def.section->output_section->vma
3400 + h->root.u.def.section->output_offset),
3404 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3406 /* Dynamic relocations are stored in
3407 1. .rel.ifunc section in PIC object.
3408 2. .rel.got section in dynamic executable.
3409 3. .rel.iplt section in static executable. */
3410 if (bfd_link_pic (info))
3411 sreloc = htab->elf.irelifunc;
3412 else if (htab->elf.splt != NULL)
3413 sreloc = htab->elf.srelgot;
3415 sreloc = htab->elf.irelplt;
3416 elf_append_rel (output_bfd, sreloc, &outrel);
3418 /* If this reloc is against an external symbol, we
3419 do not want to fiddle with the addend. Otherwise,
3420 we need to include the symbol value so that it
3421 becomes an addend for the dynamic reloc. For an
3422 internal symbol, we have updated addend. */
3431 relocation -= (gotplt->output_section->vma
3432 + gotplt->output_offset);
3437 resolved_to_zero = (eh != NULL
3438 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
3446 /* Avoid optimizing _DYNAMIC since ld.so may use its
3447 link-time address. */
3448 if (h == htab->elf.hdynamic)
3451 if (bfd_link_pic (info))
3453 /* It is OK to convert mov to lea and convert indirect
3454 branch to direct branch. It is OK to convert adc,
3455 add, and, cmp, or, sbb, sub, test, xor only when PIC
3457 unsigned int opcode, addend;
3458 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
3461 opcode = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
3462 if (opcode != 0x8b && opcode != 0xff)
3466 /* Resolve "mov GOT[(%reg)], %reg",
3467 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
3468 and "binop foo@GOT[(%reg)], %reg". */
3470 || (h->plt.offset == (bfd_vma) -1
3471 && h->got.offset == (bfd_vma) -1)
3472 || htab->elf.sgotplt == NULL)
3475 offplt = (htab->elf.sgotplt->output_section->vma
3476 + htab->elf.sgotplt->output_offset);
3478 /* It is relative to .got.plt section. */
3479 if (h->got.offset != (bfd_vma) -1)
3480 /* Use GOT entry. Mask off the least significant bit in
3481 GOT offset which may be set by R_386_GOT32 processing
3483 relocation = (htab->elf.sgot->output_section->vma
3484 + htab->elf.sgot->output_offset
3485 + (h->got.offset & ~1) - offplt);
3487 /* Use GOTPLT entry. */
3488 relocation = (h->plt.offset / plt_entry_size
3489 - htab->plt.has_plt0 + 3) * 4;
3491 if (!bfd_link_pic (info))
3493 /* If not PIC, add the .got.plt section address for
3494 baseless addressing. */
3496 modrm = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
3497 if ((modrm & 0xc7) == 0x5)
3498 relocation += offplt;
3501 unresolved_reloc = FALSE;
3506 /* Relocation is to the entry for this symbol in the global
3508 if (htab->elf.sgot == NULL)
3511 relative_reloc = FALSE;
3516 off = h->got.offset;
3517 dyn = htab->elf.dynamic_sections_created;
3518 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
3519 bfd_link_pic (info),
3521 || (bfd_link_pic (info)
3522 && SYMBOL_REFERENCES_LOCAL (info, h))
3523 || (ELF_ST_VISIBILITY (h->other)
3524 && h->root.type == bfd_link_hash_undefweak))
3526 /* This is actually a static link, or it is a
3527 -Bsymbolic link and the symbol is defined
3528 locally, or the symbol was forced to be local
3529 because of a version file. We must initialize
3530 this entry in the global offset table. Since the
3531 offset must always be a multiple of 4, we use the
3532 least significant bit to record whether we have
3533 initialized it already.
3535 When doing a dynamic link, we create a .rel.got
3536 relocation entry to initialize the value. This
3537 is done in the finish_dynamic_symbol routine. */
3542 bfd_put_32 (output_bfd, relocation,
3543 htab->elf.sgot->contents + off);
3546 if (h->dynindx == -1
3548 && h->root.type != bfd_link_hash_undefweak
3549 && bfd_link_pic (info))
3551 /* PR ld/21402: If this symbol isn't dynamic
3552 in PIC, generate R_386_RELATIVE here. */
3553 eh->no_finish_dynamic_symbol = 1;
3554 relative_reloc = TRUE;
3559 unresolved_reloc = FALSE;
3563 if (local_got_offsets == NULL)
3566 off = local_got_offsets[r_symndx];
3568 /* The offset must always be a multiple of 4. We use
3569 the least significant bit to record whether we have
3570 already generated the necessary reloc. */
3575 bfd_put_32 (output_bfd, relocation,
3576 htab->elf.sgot->contents + off);
3577 local_got_offsets[r_symndx] |= 1;
3579 if (bfd_link_pic (info))
3580 relative_reloc = TRUE;
3587 Elf_Internal_Rela outrel;
3589 s = htab->elf.srelgot;
3593 outrel.r_offset = (htab->elf.sgot->output_section->vma
3594 + htab->elf.sgot->output_offset
3596 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
3597 elf_append_rel (output_bfd, s, &outrel);
3600 if (off >= (bfd_vma) -2)
3603 relocation = (htab->elf.sgot->output_section->vma
3604 + htab->elf.sgot->output_offset + off);
3605 if (rel->r_offset > 1
3606 && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5
3607 && *(contents + rel->r_offset - 2) != 0x8d)
3609 if (bfd_link_pic (info))
3611 /* For PIC, disallow R_386_GOT32 without a base
3612 register, except for "lea foo@GOT, %reg", since
3613 we don't know what the GOT base is. */
3617 if (h == NULL || h->root.root.string == NULL)
3618 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3621 name = h->root.root.string;
3624 /* xgettext:c-format */
3625 (_("%B: direct GOT relocation %s against `%s'"
3626 " without base register can not be used"
3627 " when making a shared object"),
3628 input_bfd, howto->name, name);
3629 bfd_set_error (bfd_error_bad_value);
3635 /* Subtract the .got.plt section address only with a base
3637 relocation -= (htab->elf.sgotplt->output_section->vma
3638 + htab->elf.sgotplt->output_offset);
3644 /* Relocation is relative to the start of the global offset
3647 /* Check to make sure it isn't a protected function or data
3648 symbol for shared library since it may not be local when
3649 used as function address or with copy relocation. We also
3650 need to make sure that a symbol is referenced locally. */
3651 if (!bfd_link_executable (info) && h)
3653 if (!h->def_regular)
3657 switch (ELF_ST_VISIBILITY (h->other))
3660 v = _("hidden symbol");
3663 v = _("internal symbol");
3666 v = _("protected symbol");
3674 /* xgettext:c-format */
3675 (_("%B: relocation R_386_GOTOFF against undefined %s"
3676 " `%s' can not be used when making a shared object"),
3677 input_bfd, v, h->root.root.string);
3678 bfd_set_error (bfd_error_bad_value);
3681 else if (!SYMBOL_REFERENCES_LOCAL (info, h)
3682 && (h->type == STT_FUNC
3683 || h->type == STT_OBJECT)
3684 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
3687 /* xgettext:c-format */
3688 (_("%B: relocation R_386_GOTOFF against protected %s"
3689 " `%s' can not be used when making a shared object"),
3691 h->type == STT_FUNC ? "function" : "data",
3692 h->root.root.string);
3693 bfd_set_error (bfd_error_bad_value);
3698 /* Note that sgot is not involved in this
3699 calculation. We always want the start of .got.plt. If we
3700 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3701 permitted by the ABI, we might have to change this
3703 relocation -= htab->elf.sgotplt->output_section->vma
3704 + htab->elf.sgotplt->output_offset;
3708 /* Use global offset table as symbol value. */
3709 relocation = htab->elf.sgotplt->output_section->vma
3710 + htab->elf.sgotplt->output_offset;
3711 unresolved_reloc = FALSE;
3715 /* Relocation is to the entry for this symbol in the
3716 procedure linkage table. */
3718 /* Resolve a PLT32 reloc against a local symbol directly,
3719 without using the procedure linkage table. */
3723 if ((h->plt.offset == (bfd_vma) -1
3724 && eh->plt_got.offset == (bfd_vma) -1)
3725 || htab->elf.splt == NULL)
3727 /* We didn't make a PLT entry for this symbol. This
3728 happens when statically linking PIC code, or when
3729 using -Bsymbolic. */
3733 if (h->plt.offset != (bfd_vma) -1)
3735 if (htab->plt_second != NULL)
3737 resolved_plt = htab->plt_second;
3738 plt_offset = eh->plt_second.offset;
3742 resolved_plt = htab->elf.splt;
3743 plt_offset = h->plt.offset;
3748 resolved_plt = htab->plt_got;
3749 plt_offset = eh->plt_got.offset;
3752 relocation = (resolved_plt->output_section->vma
3753 + resolved_plt->output_offset
3755 unresolved_reloc = FALSE;
3759 /* Set to symbol size. */
3760 relocation = st_size;
3765 if ((input_section->flags & SEC_ALLOC) == 0
3769 /* Copy dynamic function pointer relocations. Don't generate
3770 dynamic relocations against resolved undefined weak symbols
3771 in PIE, except for R_386_PC32. */
3772 if ((bfd_link_pic (info)
3774 || ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3775 && (!resolved_to_zero
3776 || r_type == R_386_PC32))
3777 || h->root.type != bfd_link_hash_undefweak))
3778 && ((r_type != R_386_PC32 && r_type != R_386_SIZE32)
3779 || !SYMBOL_CALLS_LOCAL (info, h)))
3780 || (ELIMINATE_COPY_RELOCS
3781 && !bfd_link_pic (info)
3785 || eh->func_pointer_refcount > 0
3786 || (h->root.type == bfd_link_hash_undefweak
3787 && !resolved_to_zero))
3788 && ((h->def_dynamic && !h->def_regular)
3789 /* Undefined weak symbol is bound locally when
3791 || h->root.type == bfd_link_hash_undefweak)))
3793 Elf_Internal_Rela outrel;
3794 bfd_boolean skip, relocate;
3797 /* When generating a shared object, these relocations
3798 are copied into the output file to be resolved at run
3805 _bfd_elf_section_offset (output_bfd, info, input_section,
3807 if (outrel.r_offset == (bfd_vma) -1)
3809 else if (outrel.r_offset == (bfd_vma) -2)
3810 skip = TRUE, relocate = TRUE;
3811 outrel.r_offset += (input_section->output_section->vma
3812 + input_section->output_offset);
3815 memset (&outrel, 0, sizeof outrel);
3818 && (r_type == R_386_PC32
3819 || !(bfd_link_executable (info)
3820 || SYMBOLIC_BIND (info, h))
3821 || !h->def_regular))
3822 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3825 /* This symbol is local, or marked to become local. */
3827 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
3830 sreloc = elf_section_data (input_section)->sreloc;
3832 if (sreloc == NULL || sreloc->contents == NULL)
3834 r = bfd_reloc_notsupported;
3835 goto check_relocation_error;
3838 elf_append_rel (output_bfd, sreloc, &outrel);
3840 /* If this reloc is against an external symbol, we do
3841 not want to fiddle with the addend. Otherwise, we
3842 need to include the symbol value so that it becomes
3843 an addend for the dynamic reloc. */
3850 if (!bfd_link_executable (info))
3852 Elf_Internal_Rela outrel;
3855 outrel.r_offset = rel->r_offset
3856 + input_section->output_section->vma
3857 + input_section->output_offset;
3858 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
3859 sreloc = elf_section_data (input_section)->sreloc;
3862 elf_append_rel (output_bfd, sreloc, &outrel);
3867 case R_386_TLS_GOTDESC:
3868 case R_386_TLS_DESC_CALL:
3869 case R_386_TLS_IE_32:
3870 case R_386_TLS_GOTIE:
3871 tls_type = GOT_UNKNOWN;
3872 if (h == NULL && local_got_offsets)
3873 tls_type = elf_x86_local_got_tls_type (input_bfd) [r_symndx];
3875 tls_type = elf_x86_hash_entry(h)->tls_type;
3876 if (tls_type == GOT_TLS_IE)
3877 tls_type = GOT_TLS_IE_NEG;
3879 if (! elf_i386_tls_transition (info, input_bfd,
3880 input_section, contents,
3881 symtab_hdr, sym_hashes,
3882 &r_type, tls_type, rel,
3883 relend, h, r_symndx, TRUE))
3886 if (r_type == R_386_TLS_LE_32)
3888 BFD_ASSERT (! unresolved_reloc);
3889 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
3894 /* GD->LE transition. */
3895 type = *(contents + rel->r_offset - 2);
3899 leal foo@tlsgd(,%ebx,1), %eax
3900 call ___tls_get_addr@PLT
3903 subl $foo@tpoff, %eax
3904 (6 byte form of subl). */
3905 roff = rel->r_offset + 5;
3910 leal foo@tlsgd(%ebx), %eax
3911 call ___tls_get_addr@PLT
3914 leal foo@tlsgd(%reg), %eax
3915 call *___tls_get_addr@GOT(%reg)
3916 which may be converted to
3917 addr32 call ___tls_get_addr
3919 movl %gs:0, %eax; subl $foo@tpoff, %eax
3920 (6 byte form of subl). */
3921 roff = rel->r_offset + 6;
3923 memcpy (contents + roff - 8,
3924 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3925 bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
3927 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
3932 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
3934 /* GDesc -> LE transition.
3935 It's originally something like:
3936 leal x@tlsdesc(%ebx), %eax
3940 Registers other than %eax may be set up here. */
3945 roff = rel->r_offset;
3946 val = bfd_get_8 (input_bfd, contents + roff - 1);
3948 /* Now modify the instruction as appropriate. */
3949 /* aoliva FIXME: remove the above and xor the byte
3951 bfd_put_8 (output_bfd, val ^ 0x86,
3952 contents + roff - 1);
3953 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
3957 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
3959 /* GDesc -> LE transition.
3967 roff = rel->r_offset;
3968 bfd_put_8 (output_bfd, 0x66, contents + roff);
3969 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3972 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_IE)
3976 /* IE->LE transition:
3977 Originally it can be one of:
3985 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
3988 /* movl foo, %eax. */
3989 bfd_put_8 (output_bfd, 0xb8,
3990 contents + rel->r_offset - 1);
3996 type = bfd_get_8 (input_bfd,
3997 contents + rel->r_offset - 2);
4002 bfd_put_8 (output_bfd, 0xc7,
4003 contents + rel->r_offset - 2);
4004 bfd_put_8 (output_bfd,
4005 0xc0 | ((val >> 3) & 7),
4006 contents + rel->r_offset - 1);
4010 bfd_put_8 (output_bfd, 0x81,
4011 contents + rel->r_offset - 2);
4012 bfd_put_8 (output_bfd,
4013 0xc0 | ((val >> 3) & 7),
4014 contents + rel->r_offset - 1);
4021 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
4022 contents + rel->r_offset);
4027 unsigned int val, type;
4029 /* {IE_32,GOTIE}->LE transition:
4030 Originally it can be one of:
4031 subl foo(%reg1), %reg2
4032 movl foo(%reg1), %reg2
4033 addl foo(%reg1), %reg2
4036 movl $foo, %reg2 (6 byte form)
4037 addl $foo, %reg2. */
4038 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
4039 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
4043 bfd_put_8 (output_bfd, 0xc7,
4044 contents + rel->r_offset - 2);
4045 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
4046 contents + rel->r_offset - 1);
4048 else if (type == 0x2b)
4051 bfd_put_8 (output_bfd, 0x81,
4052 contents + rel->r_offset - 2);
4053 bfd_put_8 (output_bfd, 0xe8 | ((val >> 3) & 7),
4054 contents + rel->r_offset - 1);
4056 else if (type == 0x03)
4059 bfd_put_8 (output_bfd, 0x81,
4060 contents + rel->r_offset - 2);
4061 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
4062 contents + rel->r_offset - 1);
4066 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTIE)
4067 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
4068 contents + rel->r_offset);
4070 bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
4071 contents + rel->r_offset);
4076 if (htab->elf.sgot == NULL)
4081 off = h->got.offset;
4082 offplt = elf_x86_hash_entry (h)->tlsdesc_got;
4086 if (local_got_offsets == NULL)
4089 off = local_got_offsets[r_symndx];
4090 offplt = local_tlsdesc_gotents[r_symndx];
4097 Elf_Internal_Rela outrel;
4101 if (htab->elf.srelgot == NULL)
4104 indx = h && h->dynindx != -1 ? h->dynindx : 0;
4106 if (GOT_TLS_GDESC_P (tls_type))
4109 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
4110 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
4111 <= htab->elf.sgotplt->size);
4112 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
4113 + htab->elf.sgotplt->output_offset
4115 + htab->sgotplt_jump_table_size);
4116 sreloc = htab->elf.srelplt;
4117 loc = sreloc->contents;
4118 loc += (htab->next_tls_desc_index++
4119 * sizeof (Elf32_External_Rel));
4120 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
4121 <= sreloc->contents + sreloc->size);
4122 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
4125 BFD_ASSERT (! unresolved_reloc);
4126 bfd_put_32 (output_bfd,
4127 relocation - _bfd_x86_elf_dtpoff_base (info),
4128 htab->elf.sgotplt->contents + offplt
4129 + htab->sgotplt_jump_table_size + 4);
4133 bfd_put_32 (output_bfd, 0,
4134 htab->elf.sgotplt->contents + offplt
4135 + htab->sgotplt_jump_table_size + 4);
4139 sreloc = htab->elf.srelgot;
4141 outrel.r_offset = (htab->elf.sgot->output_section->vma
4142 + htab->elf.sgot->output_offset + off);
4144 if (GOT_TLS_GD_P (tls_type))
4145 dr_type = R_386_TLS_DTPMOD32;
4146 else if (GOT_TLS_GDESC_P (tls_type))
4148 else if (tls_type == GOT_TLS_IE_POS)
4149 dr_type = R_386_TLS_TPOFF;
4151 dr_type = R_386_TLS_TPOFF32;
4153 if (dr_type == R_386_TLS_TPOFF && indx == 0)
4154 bfd_put_32 (output_bfd,
4155 relocation - _bfd_x86_elf_dtpoff_base (info),
4156 htab->elf.sgot->contents + off);
4157 else if (dr_type == R_386_TLS_TPOFF32 && indx == 0)
4158 bfd_put_32 (output_bfd,
4159 _bfd_x86_elf_dtpoff_base (info) - relocation,
4160 htab->elf.sgot->contents + off);
4161 else if (dr_type != R_386_TLS_DESC)
4162 bfd_put_32 (output_bfd, 0,
4163 htab->elf.sgot->contents + off);
4164 outrel.r_info = ELF32_R_INFO (indx, dr_type);
4166 elf_append_rel (output_bfd, sreloc, &outrel);
4168 if (GOT_TLS_GD_P (tls_type))
4172 BFD_ASSERT (! unresolved_reloc);
4173 bfd_put_32 (output_bfd,
4174 relocation - _bfd_x86_elf_dtpoff_base (info),
4175 htab->elf.sgot->contents + off + 4);
4179 bfd_put_32 (output_bfd, 0,
4180 htab->elf.sgot->contents + off + 4);
4181 outrel.r_info = ELF32_R_INFO (indx,
4182 R_386_TLS_DTPOFF32);
4183 outrel.r_offset += 4;
4184 elf_append_rel (output_bfd, sreloc, &outrel);
4187 else if (tls_type == GOT_TLS_IE_BOTH)
4189 bfd_put_32 (output_bfd,
4191 ? relocation - _bfd_x86_elf_dtpoff_base (info)
4193 htab->elf.sgot->contents + off + 4);
4194 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
4195 outrel.r_offset += 4;
4196 elf_append_rel (output_bfd, sreloc, &outrel);
4203 local_got_offsets[r_symndx] |= 1;
4206 if (off >= (bfd_vma) -2
4207 && ! GOT_TLS_GDESC_P (tls_type))
4209 if (r_type == R_386_TLS_GOTDESC
4210 || r_type == R_386_TLS_DESC_CALL)
4212 relocation = htab->sgotplt_jump_table_size + offplt;
4213 unresolved_reloc = FALSE;
4215 else if (r_type == ELF32_R_TYPE (rel->r_info))
4217 bfd_vma g_o_t = htab->elf.sgotplt->output_section->vma
4218 + htab->elf.sgotplt->output_offset;
4219 relocation = htab->elf.sgot->output_section->vma
4220 + htab->elf.sgot->output_offset + off - g_o_t;
4221 if ((r_type == R_386_TLS_IE || r_type == R_386_TLS_GOTIE)
4222 && tls_type == GOT_TLS_IE_BOTH)
4224 if (r_type == R_386_TLS_IE)
4225 relocation += g_o_t;
4226 unresolved_reloc = FALSE;
4228 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
4230 unsigned int val, type;
4233 /* GD->IE transition. */
4234 type = *(contents + rel->r_offset - 2);
4235 val = *(contents + rel->r_offset - 1);
4239 leal foo@tlsgd(,%ebx,1), %eax
4240 call ___tls_get_addr@PLT
4243 subl $foo@gottpoff(%ebx), %eax. */
4245 roff = rel->r_offset - 3;
4250 leal foo@tlsgd(%ebx), %eax
4251 call ___tls_get_addr@PLT
4254 leal foo@tlsgd(%reg), %eax
4255 call *___tls_get_addr@GOT(%reg)
4256 which may be converted to
4257 addr32 call ___tls_get_addr
4260 subl $foo@gottpoff(%reg), %eax. */
4261 roff = rel->r_offset - 2;
4263 memcpy (contents + roff,
4264 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4265 contents[roff + 7] = 0x80 | (val & 7);
4266 /* If foo is used only with foo@gotntpoff(%reg) and
4267 foo@indntpoff, but not with foo@gottpoff(%reg), change
4268 subl $foo@gottpoff(%reg), %eax
4270 addl $foo@gotntpoff(%reg), %eax. */
4271 if (tls_type == GOT_TLS_IE_POS)
4272 contents[roff + 6] = 0x03;
4273 bfd_put_32 (output_bfd,
4274 htab->elf.sgot->output_section->vma
4275 + htab->elf.sgot->output_offset + off
4276 - htab->elf.sgotplt->output_section->vma
4277 - htab->elf.sgotplt->output_offset,
4278 contents + roff + 8);
4279 /* Skip R_386_PLT32 and R_386_GOT32X. */
4284 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
4286 /* GDesc -> IE transition.
4287 It's originally something like:
4288 leal x@tlsdesc(%ebx), %eax
4291 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4293 movl x@gottpoff(%ebx), %eax # before negl %eax
4295 Registers other than %eax may be set up here. */
4299 /* First, make sure it's a leal adding ebx to a 32-bit
4300 offset into any register, although it's probably
4301 almost always going to be eax. */
4302 roff = rel->r_offset;
4304 /* Now modify the instruction as appropriate. */
4305 /* To turn a leal into a movl in the form we use it, it
4306 suffices to change the first byte from 0x8d to 0x8b.
4307 aoliva FIXME: should we decide to keep the leal, all
4308 we have to do is remove the statement below, and
4309 adjust the relaxation of R_386_TLS_DESC_CALL. */
4310 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
4312 if (tls_type == GOT_TLS_IE_BOTH)
4315 bfd_put_32 (output_bfd,
4316 htab->elf.sgot->output_section->vma
4317 + htab->elf.sgot->output_offset + off
4318 - htab->elf.sgotplt->output_section->vma
4319 - htab->elf.sgotplt->output_offset,
4323 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
4325 /* GDesc -> IE transition.
4333 depending on how we transformed the TLS_GOTDESC above.
4338 roff = rel->r_offset;
4340 /* Now modify the instruction as appropriate. */
4341 if (tls_type != GOT_TLS_IE_NEG)
4344 bfd_put_8 (output_bfd, 0x66, contents + roff);
4345 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
4350 bfd_put_8 (output_bfd, 0xf7, contents + roff);
4351 bfd_put_8 (output_bfd, 0xd8, contents + roff + 1);
4361 if (! elf_i386_tls_transition (info, input_bfd,
4362 input_section, contents,
4363 symtab_hdr, sym_hashes,
4364 &r_type, GOT_UNKNOWN, rel,
4365 relend, h, r_symndx, TRUE))
4368 if (r_type != R_386_TLS_LDM)
4370 /* LD->LE transition. Change
4371 leal foo@tlsldm(%ebx) %eax
4372 call ___tls_get_addr@PLT
4376 leal 0(%esi,1), %esi
4378 leal foo@tlsldm(%reg) %eax
4379 call *___tls_get_addr@GOT(%reg)
4380 which may be converted to
4381 addr32 call ___tls_get_addr
4384 leal 0(%esi), %esi */
4385 BFD_ASSERT (r_type == R_386_TLS_LE_32);
4386 if (*(contents + rel->r_offset + 4) == 0xff
4387 || *(contents + rel->r_offset + 4) == 0x67)
4388 memcpy (contents + rel->r_offset - 2,
4389 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
4391 memcpy (contents + rel->r_offset - 2,
4392 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4393 /* Skip R_386_PC32/R_386_PLT32. */
4399 if (htab->elf.sgot == NULL)
4402 off = htab->tls_ld_or_ldm_got.offset;
4407 Elf_Internal_Rela outrel;
4409 if (htab->elf.srelgot == NULL)
4412 outrel.r_offset = (htab->elf.sgot->output_section->vma
4413 + htab->elf.sgot->output_offset + off);
4415 bfd_put_32 (output_bfd, 0,
4416 htab->elf.sgot->contents + off);
4417 bfd_put_32 (output_bfd, 0,
4418 htab->elf.sgot->contents + off + 4);
4419 outrel.r_info = ELF32_R_INFO (0, R_386_TLS_DTPMOD32);
4420 elf_append_rel (output_bfd, htab->elf.srelgot, &outrel);
4421 htab->tls_ld_or_ldm_got.offset |= 1;
4423 relocation = htab->elf.sgot->output_section->vma
4424 + htab->elf.sgot->output_offset + off
4425 - htab->elf.sgotplt->output_section->vma
4426 - htab->elf.sgotplt->output_offset;
4427 unresolved_reloc = FALSE;
4430 case R_386_TLS_LDO_32:
4431 if (!bfd_link_executable (info)
4432 || (input_section->flags & SEC_CODE) == 0)
4433 relocation -= _bfd_x86_elf_dtpoff_base (info);
4435 /* When converting LDO to LE, we must negate. */
4436 relocation = -elf_i386_tpoff (info, relocation);
4439 case R_386_TLS_LE_32:
4441 if (!bfd_link_executable (info))
4443 Elf_Internal_Rela outrel;
4446 outrel.r_offset = rel->r_offset
4447 + input_section->output_section->vma
4448 + input_section->output_offset;
4449 if (h != NULL && h->dynindx != -1)
4453 if (r_type == R_386_TLS_LE_32)
4454 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF32);
4456 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
4457 sreloc = elf_section_data (input_section)->sreloc;
4460 elf_append_rel (output_bfd, sreloc, &outrel);
4463 else if (r_type == R_386_TLS_LE_32)
4464 relocation = _bfd_x86_elf_dtpoff_base (info) - relocation;
4466 relocation -= _bfd_x86_elf_dtpoff_base (info);
4468 else if (r_type == R_386_TLS_LE_32)
4469 relocation = elf_i386_tpoff (info, relocation);
4471 relocation = -elf_i386_tpoff (info, relocation);
4478 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4479 because such sections are not SEC_ALLOC and thus ld.so will
4480 not process them. */
4481 if (unresolved_reloc
4482 && !((input_section->flags & SEC_DEBUGGING) != 0
4484 && _bfd_elf_section_offset (output_bfd, info, input_section,
4485 rel->r_offset) != (bfd_vma) -1)
4488 /* xgettext:c-format */
4489 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
4494 h->root.root.string);
4499 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4500 contents, rel->r_offset,
4503 check_relocation_error:
4504 if (r != bfd_reloc_ok)
4509 name = h->root.root.string;
4512 name = bfd_elf_string_from_elf_section (input_bfd,
4513 symtab_hdr->sh_link,
4518 name = bfd_section_name (input_bfd, sec);
4521 if (r == bfd_reloc_overflow)
4522 (*info->callbacks->reloc_overflow)
4523 (info, (h ? &h->root : NULL), name, howto->name,
4524 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4528 /* xgettext:c-format */
4529 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
4530 input_bfd, input_section,
4531 rel->r_offset, name, (int) r);
4542 Elf_Internal_Shdr *rel_hdr;
4543 size_t deleted = rel - wrel;
4545 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
4546 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
4547 if (rel_hdr->sh_size == 0)
4549 /* It is too late to remove an empty reloc section. Leave
4551 ??? What is wrong with an empty section??? */
4552 rel_hdr->sh_size = rel_hdr->sh_entsize;
4555 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
4556 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
4557 input_section->reloc_count -= deleted;
4563 /* Finish up dynamic symbol handling. We set the contents of various
4564 dynamic sections here. */
4567 elf_i386_finish_dynamic_symbol (bfd *output_bfd,
4568 struct bfd_link_info *info,
4569 struct elf_link_hash_entry *h,
4570 Elf_Internal_Sym *sym)
4572 struct elf_x86_link_hash_table *htab;
4573 unsigned plt_entry_size;
4574 struct elf_x86_link_hash_entry *eh;
4575 bfd_boolean local_undefweak;
4576 bfd_boolean use_plt_second;
4578 htab = elf_x86_hash_table (info, I386_ELF_DATA);
4582 plt_entry_size = htab->plt.plt_entry_size;
4584 /* Use the second PLT section only if there is .plt section. */
4585 use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL;
4587 eh = (struct elf_x86_link_hash_entry *) h;
4588 if (eh->no_finish_dynamic_symbol)
4591 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4592 resolved undefined weak symbols in executable so that their
4593 references have value 0 at run-time. */
4594 local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, I386_ELF_DATA,
4598 if (h->plt.offset != (bfd_vma) -1)
4600 bfd_vma plt_index, plt_offset;
4602 Elf_Internal_Rela rel;
4604 asection *plt, *resolved_plt, *gotplt, *relplt;
4606 /* When building a static executable, use .iplt, .igot.plt and
4607 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4608 if (htab->elf.splt != NULL)
4610 plt = htab->elf.splt;
4611 gotplt = htab->elf.sgotplt;
4612 relplt = htab->elf.srelplt;
4616 plt = htab->elf.iplt;
4617 gotplt = htab->elf.igotplt;
4618 relplt = htab->elf.irelplt;
4621 /* This symbol has an entry in the procedure linkage table. Set
4624 if ((h->dynindx == -1
4626 && !((h->forced_local || bfd_link_executable (info))
4628 && h->type == STT_GNU_IFUNC))
4634 /* Get the index in the procedure linkage table which
4635 corresponds to this symbol. This is the index of this symbol
4636 in all the symbols for which we are making plt entries. The
4637 first entry in the procedure linkage table is reserved.
4639 Get the offset into the .got table of the entry that
4640 corresponds to this function. Each .got entry is 4 bytes.
4641 The first three are reserved.
4643 For static executables, we don't reserve anything. */
4645 if (plt == htab->elf.splt)
4647 got_offset = (h->plt.offset / plt_entry_size
4648 - htab->plt.has_plt0);
4649 got_offset = (got_offset + 3) * 4;
4653 got_offset = h->plt.offset / plt_entry_size;
4654 got_offset = got_offset * 4;
4657 /* Fill in the entry in the procedure linkage table and update
4659 memcpy (plt->contents + h->plt.offset, htab->plt.plt_entry,
4664 const bfd_byte *plt_entry;
4665 if (bfd_link_pic (info))
4666 plt_entry = htab->non_lazy_plt->pic_plt_entry;
4668 plt_entry = htab->non_lazy_plt->plt_entry;
4669 memcpy (htab->plt_second->contents + eh->plt_second.offset,
4670 plt_entry, htab->non_lazy_plt->plt_entry_size);
4672 resolved_plt = htab->plt_second;
4673 plt_offset = eh->plt_second.offset;
4678 plt_offset = h->plt.offset;
4681 if (! bfd_link_pic (info))
4683 bfd_put_32 (output_bfd,
4684 (gotplt->output_section->vma
4685 + gotplt->output_offset
4687 resolved_plt->contents + plt_offset
4688 + htab->plt.plt_got_offset);
4690 if (htab->is_vxworks)
4692 int s, k, reloc_index;
4694 /* Create the R_386_32 relocation referencing the GOT
4695 for this PLT entry. */
4697 /* S: Current slot number (zero-based). */
4698 s = ((h->plt.offset - htab->plt.plt_entry_size)
4699 / htab->plt.plt_entry_size);
4700 /* K: Number of relocations for PLTResolve. */
4701 if (bfd_link_pic (info))
4702 k = PLTRESOLVE_RELOCS_SHLIB;
4704 k = PLTRESOLVE_RELOCS;
4705 /* Skip the PLTresolve relocations, and the relocations for
4706 the other PLT slots. */
4707 reloc_index = k + s * PLT_NON_JUMP_SLOT_RELOCS;
4708 loc = (htab->srelplt2->contents + reloc_index
4709 * sizeof (Elf32_External_Rel));
4711 rel.r_offset = (plt->output_section->vma
4712 + plt->output_offset
4713 + h->plt.offset + 2),
4714 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
4715 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4717 /* Create the R_386_32 relocation referencing the beginning of
4718 the PLT for this GOT entry. */
4719 rel.r_offset = (htab->elf.sgotplt->output_section->vma
4720 + htab->elf.sgotplt->output_offset
4722 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32);
4723 bfd_elf32_swap_reloc_out (output_bfd, &rel,
4724 loc + sizeof (Elf32_External_Rel));
4729 bfd_put_32 (output_bfd, got_offset,
4730 resolved_plt->contents + plt_offset
4731 + htab->plt.plt_got_offset);
4734 /* Fill in the entry in the global offset table. Leave the entry
4735 as zero for undefined weak symbol in PIE. No PLT relocation
4736 against undefined weak symbol in PIE. */
4737 if (!local_undefweak)
4739 if (htab->plt.has_plt0)
4740 bfd_put_32 (output_bfd,
4741 (plt->output_section->vma
4742 + plt->output_offset
4744 + htab->lazy_plt->plt_lazy_offset),
4745 gotplt->contents + got_offset);
4747 /* Fill in the entry in the .rel.plt section. */
4748 rel.r_offset = (gotplt->output_section->vma
4749 + gotplt->output_offset
4751 if (h->dynindx == -1
4752 || ((bfd_link_executable (info)
4753 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4755 && h->type == STT_GNU_IFUNC))
4757 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
4758 h->root.root.string,
4759 h->root.u.def.section->owner);
4761 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4762 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4763 in the .got.plt section. */
4764 bfd_put_32 (output_bfd,
4765 (h->root.u.def.value
4766 + h->root.u.def.section->output_section->vma
4767 + h->root.u.def.section->output_offset),
4768 gotplt->contents + got_offset);
4769 rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
4770 /* R_386_IRELATIVE comes last. */
4771 plt_index = htab->next_irelative_index--;
4775 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
4776 plt_index = htab->next_jump_slot_index++;
4779 loc = relplt->contents + plt_index * sizeof (Elf32_External_Rel);
4780 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4782 /* Don't fill the second and third slots in PLT entry for
4783 static executables nor without PLT0. */
4784 if (plt == htab->elf.splt && htab->plt.has_plt0)
4786 bfd_put_32 (output_bfd,
4787 plt_index * sizeof (Elf32_External_Rel),
4788 plt->contents + h->plt.offset
4789 + htab->lazy_plt->plt_reloc_offset);
4790 bfd_put_32 (output_bfd,
4792 + htab->lazy_plt->plt_plt_offset + 4),
4793 (plt->contents + h->plt.offset
4794 + htab->lazy_plt->plt_plt_offset));
4798 else if (eh->plt_got.offset != (bfd_vma) -1)
4800 bfd_vma got_offset, plt_offset;
4801 asection *plt, *got, *gotplt;
4802 const bfd_byte *got_plt_entry;
4804 /* Set the entry in the GOT procedure linkage table. */
4805 plt = htab->plt_got;
4806 got = htab->elf.sgot;
4807 gotplt = htab->elf.sgotplt;
4808 got_offset = h->got.offset;
4810 if (got_offset == (bfd_vma) -1
4816 /* Fill in the entry in the GOT procedure linkage table. */
4817 if (! bfd_link_pic (info))
4819 got_plt_entry = htab->non_lazy_plt->plt_entry;
4820 got_offset += got->output_section->vma + got->output_offset;
4824 got_plt_entry = htab->non_lazy_plt->pic_plt_entry;
4825 got_offset += (got->output_section->vma
4826 + got->output_offset
4827 - gotplt->output_section->vma
4828 - gotplt->output_offset);
4831 plt_offset = eh->plt_got.offset;
4832 memcpy (plt->contents + plt_offset, got_plt_entry,
4833 htab->non_lazy_plt->plt_entry_size);
4834 bfd_put_32 (output_bfd, got_offset,
4835 (plt->contents + plt_offset
4836 + htab->non_lazy_plt->plt_got_offset));
4839 if (!local_undefweak
4841 && (h->plt.offset != (bfd_vma) -1
4842 || eh->plt_got.offset != (bfd_vma) -1))
4844 /* Mark the symbol as undefined, rather than as defined in
4845 the .plt section. Leave the value if there were any
4846 relocations where pointer equality matters (this is a clue
4847 for the dynamic linker, to make function pointer
4848 comparisons work between an application and shared
4849 library), otherwise set it to zero. If a function is only
4850 called from a binary, there is no need to slow down
4851 shared libraries because of that. */
4852 sym->st_shndx = SHN_UNDEF;
4853 if (!h->pointer_equality_needed)
4857 /* Don't generate dynamic GOT relocation against undefined weak
4858 symbol in executable. */
4859 if (h->got.offset != (bfd_vma) -1
4860 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h)->tls_type)
4861 && (elf_x86_hash_entry(h)->tls_type & GOT_TLS_IE) == 0
4862 && !local_undefweak)
4864 Elf_Internal_Rela rel;
4865 asection *relgot = htab->elf.srelgot;
4867 /* This symbol has an entry in the global offset table. Set it
4870 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
4873 rel.r_offset = (htab->elf.sgot->output_section->vma
4874 + htab->elf.sgot->output_offset
4875 + (h->got.offset & ~(bfd_vma) 1));
4877 /* If this is a static link, or it is a -Bsymbolic link and the
4878 symbol is defined locally or was forced to be local because
4879 of a version file, we just want to emit a RELATIVE reloc.
4880 The entry in the global offset table will already have been
4881 initialized in the relocate_section function. */
4883 && h->type == STT_GNU_IFUNC)
4885 if (h->plt.offset == (bfd_vma) -1)
4887 /* STT_GNU_IFUNC is referenced without PLT. */
4888 if (htab->elf.splt == NULL)
4890 /* use .rel[a].iplt section to store .got relocations
4891 in static executable. */
4892 relgot = htab->elf.irelplt;
4894 if (SYMBOL_REFERENCES_LOCAL (info, h))
4896 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
4897 h->root.root.string,
4898 h->root.u.def.section->owner);
4900 bfd_put_32 (output_bfd,
4901 (h->root.u.def.value
4902 + h->root.u.def.section->output_section->vma
4903 + h->root.u.def.section->output_offset),
4904 htab->elf.sgot->contents + h->got.offset);
4905 rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
4910 else if (bfd_link_pic (info))
4912 /* Generate R_386_GLOB_DAT. */
4920 if (!h->pointer_equality_needed)
4923 /* For non-shared object, we can't use .got.plt, which
4924 contains the real function addres if we need pointer
4925 equality. We load the GOT entry with the PLT entry. */
4926 if (htab->plt_second != NULL)
4928 plt = htab->plt_second;
4929 plt_offset = eh->plt_second.offset;
4933 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
4934 plt_offset = h->plt.offset;
4936 bfd_put_32 (output_bfd,
4937 (plt->output_section->vma
4938 + plt->output_offset + plt_offset),
4939 htab->elf.sgot->contents + h->got.offset);
4943 else if (bfd_link_pic (info)
4944 && SYMBOL_REFERENCES_LOCAL (info, h))
4946 BFD_ASSERT((h->got.offset & 1) != 0);
4947 rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
4951 BFD_ASSERT((h->got.offset & 1) == 0);
4953 bfd_put_32 (output_bfd, (bfd_vma) 0,
4954 htab->elf.sgot->contents + h->got.offset);
4955 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
4958 elf_append_rel (output_bfd, relgot, &rel);
4963 Elf_Internal_Rela rel;
4966 /* This symbol needs a copy reloc. Set it up. */
4968 if (h->dynindx == -1
4969 || (h->root.type != bfd_link_hash_defined
4970 && h->root.type != bfd_link_hash_defweak)
4971 || htab->elf.srelbss == NULL
4972 || htab->elf.sreldynrelro == NULL)
4975 rel.r_offset = (h->root.u.def.value
4976 + h->root.u.def.section->output_section->vma
4977 + h->root.u.def.section->output_offset);
4978 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
4979 if (h->root.u.def.section == htab->elf.sdynrelro)
4980 s = htab->elf.sreldynrelro;
4982 s = htab->elf.srelbss;
4983 elf_append_rel (output_bfd, s, &rel);
4989 /* Finish up local dynamic symbol handling. We set the contents of
4990 various dynamic sections here. */
4993 elf_i386_finish_local_dynamic_symbol (void **slot, void *inf)
4995 struct elf_link_hash_entry *h
4996 = (struct elf_link_hash_entry *) *slot;
4997 struct bfd_link_info *info
4998 = (struct bfd_link_info *) inf;
5000 return elf_i386_finish_dynamic_symbol (info->output_bfd, info,
5004 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5005 here since undefined weak symbol may not be dynamic and may not be
5006 called for elf_i386_finish_dynamic_symbol. */
5009 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
5012 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
5013 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5015 if (h->root.type != bfd_link_hash_undefweak
5016 || h->dynindx != -1)
5019 return elf_i386_finish_dynamic_symbol (info->output_bfd,
5023 /* Used to decide how to sort relocs in an optimal manner for the
5024 dynamic linker, before writing them out. */
5026 static enum elf_reloc_type_class
5027 elf_i386_reloc_type_class (const struct bfd_link_info *info,
5028 const asection *rel_sec ATTRIBUTE_UNUSED,
5029 const Elf_Internal_Rela *rela)
5031 bfd *abfd = info->output_bfd;
5032 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
5033 struct elf_link_hash_table *htab = elf_hash_table (info);
5035 if (htab->dynsym != NULL
5036 && htab->dynsym->contents != NULL)
5038 /* Check relocation against STT_GNU_IFUNC symbol if there are
5040 unsigned long r_symndx = ELF32_R_SYM (rela->r_info);
5041 if (r_symndx != STN_UNDEF)
5043 Elf_Internal_Sym sym;
5044 if (!bed->s->swap_symbol_in (abfd,
5045 (htab->dynsym->contents
5046 + r_symndx * sizeof (Elf32_External_Sym)),
5050 if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
5051 return reloc_class_ifunc;
5055 switch (ELF32_R_TYPE (rela->r_info))
5057 case R_386_IRELATIVE:
5058 return reloc_class_ifunc;
5059 case R_386_RELATIVE:
5060 return reloc_class_relative;
5061 case R_386_JUMP_SLOT:
5062 return reloc_class_plt;
5064 return reloc_class_copy;
5066 return reloc_class_normal;
5070 /* Finish up the dynamic sections. */
5073 elf_i386_finish_dynamic_sections (bfd *output_bfd,
5074 struct bfd_link_info *info)
5076 struct elf_x86_link_hash_table *htab;
5079 const struct elf_i386_backend_data *abed;
5081 htab = elf_x86_hash_table (info, I386_ELF_DATA);
5085 dynobj = htab->elf.dynobj;
5086 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
5087 abed = get_elf_i386_backend_data (output_bfd);
5089 if (htab->elf.dynamic_sections_created)
5091 Elf32_External_Dyn *dyncon, *dynconend;
5093 if (sdyn == NULL || htab->elf.sgot == NULL)
5096 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5097 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5098 for (; dyncon < dynconend; dyncon++)
5100 Elf_Internal_Dyn dyn;
5103 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5108 if (htab->is_vxworks
5109 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
5114 s = htab->elf.sgotplt;
5115 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
5119 s = htab->elf.srelplt;
5120 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
5124 s = htab->elf.srelplt;
5125 dyn.d_un.d_val = s->size;
5129 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5132 if (htab->elf.splt && htab->elf.splt->size > 0)
5134 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5135 really seem like the right value. */
5136 elf_section_data (htab->elf.splt->output_section)
5137 ->this_hdr.sh_entsize = 4;
5139 if (htab->plt.has_plt0)
5141 /* Fill in the special first entry in the procedure linkage
5143 memcpy (htab->elf.splt->contents, htab->plt.plt0_entry,
5144 htab->lazy_plt->plt0_entry_size);
5145 memset (htab->elf.splt->contents + htab->lazy_plt->plt0_entry_size,
5146 abed->plt0_pad_byte,
5147 htab->plt.plt_entry_size - htab->lazy_plt->plt0_entry_size);
5148 if (!bfd_link_pic (info))
5150 bfd_put_32 (output_bfd,
5151 (htab->elf.sgotplt->output_section->vma
5152 + htab->elf.sgotplt->output_offset
5154 htab->elf.splt->contents
5155 + htab->lazy_plt->plt0_got1_offset);
5156 bfd_put_32 (output_bfd,
5157 (htab->elf.sgotplt->output_section->vma
5158 + htab->elf.sgotplt->output_offset
5160 htab->elf.splt->contents
5161 + htab->lazy_plt->plt0_got2_offset);
5163 if (htab->is_vxworks)
5165 Elf_Internal_Rela rel;
5166 int num_plts = (htab->elf.splt->size
5167 / htab->plt.plt_entry_size) - 1;
5169 asection *srelplt2 = htab->srelplt2;
5171 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5172 + 4. On IA32 we use REL relocations so the
5173 addend goes in the PLT directly. */
5174 rel.r_offset = (htab->elf.splt->output_section->vma
5175 + htab->elf.splt->output_offset
5176 + htab->lazy_plt->plt0_got1_offset);
5177 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
5179 bfd_elf32_swap_reloc_out (output_bfd, &rel,
5180 srelplt2->contents);
5181 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5183 rel.r_offset = (htab->elf.splt->output_section->vma
5184 + htab->elf.splt->output_offset
5185 + htab->lazy_plt->plt0_got2_offset);
5186 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
5188 bfd_elf32_swap_reloc_out (output_bfd, &rel,
5189 srelplt2->contents +
5190 sizeof (Elf32_External_Rel));
5191 /* Correct the .rel.plt.unloaded relocations. */
5192 p = srelplt2->contents;
5193 if (bfd_link_pic (info))
5194 p += PLTRESOLVE_RELOCS_SHLIB * sizeof (Elf32_External_Rel);
5196 p += PLTRESOLVE_RELOCS * sizeof (Elf32_External_Rel);
5198 for (; num_plts; num_plts--)
5200 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
5201 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
5203 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
5204 p += sizeof (Elf32_External_Rel);
5206 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
5207 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
5209 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
5210 p += sizeof (Elf32_External_Rel);
5217 if (htab->plt_got != NULL && htab->plt_got->size > 0)
5218 elf_section_data (htab->plt_got->output_section)
5219 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
5221 if (htab->plt_second != NULL && htab->plt_second->size > 0)
5222 elf_section_data (htab->plt_second->output_section)
5223 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
5226 /* Fill in the first three entries in the global offset table. */
5227 if (htab->elf.sgotplt && htab->elf.sgotplt->size > 0)
5229 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
5232 (_("discarded output section: `%A'"), htab->elf.sgotplt);
5236 bfd_put_32 (output_bfd,
5238 : sdyn->output_section->vma + sdyn->output_offset),
5239 htab->elf.sgotplt->contents);
5240 bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 4);
5241 bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 8);
5243 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize = 4;
5246 /* Adjust .eh_frame for .plt section. */
5247 if (htab->plt_eh_frame != NULL
5248 && htab->plt_eh_frame->contents != NULL)
5250 if (htab->elf.splt != NULL
5251 && htab->elf.splt->size != 0
5252 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
5253 && htab->elf.splt->output_section != NULL
5254 && htab->plt_eh_frame->output_section != NULL)
5256 bfd_vma plt_start = htab->elf.splt->output_section->vma;
5257 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
5258 + htab->plt_eh_frame->output_offset
5259 + PLT_FDE_START_OFFSET;
5260 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
5261 htab->plt_eh_frame->contents
5262 + PLT_FDE_START_OFFSET);
5264 if (htab->plt_eh_frame->sec_info_type
5265 == SEC_INFO_TYPE_EH_FRAME)
5267 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
5269 htab->plt_eh_frame->contents))
5274 /* Adjust .eh_frame for .plt.got section. */
5275 if (htab->plt_got_eh_frame != NULL
5276 && htab->plt_got_eh_frame->contents != NULL)
5278 if (htab->plt_got != NULL
5279 && htab->plt_got->size != 0
5280 && (htab->plt_got->flags & SEC_EXCLUDE) == 0
5281 && htab->plt_got->output_section != NULL
5282 && htab->plt_got_eh_frame->output_section != NULL)
5284 bfd_vma plt_start = htab->plt_got->output_section->vma;
5285 bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma
5286 + htab->plt_got_eh_frame->output_offset
5287 + PLT_FDE_START_OFFSET;
5288 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
5289 htab->plt_got_eh_frame->contents
5290 + PLT_FDE_START_OFFSET);
5292 if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
5294 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
5295 htab->plt_got_eh_frame,
5296 htab->plt_got_eh_frame->contents))
5301 /* Adjust .eh_frame for the second PLT section. */
5302 if (htab->plt_second_eh_frame != NULL
5303 && htab->plt_second_eh_frame->contents != NULL)
5305 if (htab->plt_second != NULL
5306 && htab->plt_second->size != 0
5307 && (htab->plt_second->flags & SEC_EXCLUDE) == 0
5308 && htab->plt_second->output_section != NULL
5309 && htab->plt_second_eh_frame->output_section != NULL)
5311 bfd_vma plt_start = htab->plt_second->output_section->vma;
5312 bfd_vma eh_frame_start
5313 = (htab->plt_second_eh_frame->output_section->vma
5314 + htab->plt_second_eh_frame->output_offset
5315 + PLT_FDE_START_OFFSET);
5316 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
5317 htab->plt_second_eh_frame->contents
5318 + PLT_FDE_START_OFFSET);
5320 if (htab->plt_second_eh_frame->sec_info_type
5321 == SEC_INFO_TYPE_EH_FRAME)
5323 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
5324 htab->plt_second_eh_frame,
5325 htab->plt_second_eh_frame->contents))
5330 if (htab->elf.sgot && htab->elf.sgot->size > 0)
5331 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4;
5333 /* Fill PLT entries for undefined weak symbols in PIE. */
5334 if (bfd_link_pie (info))
5335 bfd_hash_traverse (&info->hash->table,
5336 elf_i386_pie_finish_undefweak_symbol,
5342 /* Fill PLT/GOT entries and allocate dynamic relocations for local
5343 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
5344 It has to be done before elf_link_sort_relocs is called so that
5345 dynamic relocations are properly sorted. */
5348 elf_i386_output_arch_local_syms
5349 (bfd *output_bfd ATTRIBUTE_UNUSED,
5350 struct bfd_link_info *info,
5351 void *flaginfo ATTRIBUTE_UNUSED,
5352 int (*func) (void *, const char *,
5355 struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
5357 struct elf_x86_link_hash_table *htab
5358 = elf_x86_hash_table (info, I386_ELF_DATA);
5362 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5363 htab_traverse (htab->loc_hash_table,
5364 elf_i386_finish_local_dynamic_symbol,
5370 /* Forward declaration. */
5371 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt;
5373 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
5374 dynamic relocations. */
5377 elf_i386_get_synthetic_symtab (bfd *abfd,
5378 long symcount ATTRIBUTE_UNUSED,
5379 asymbol **syms ATTRIBUTE_UNUSED,
5386 bfd_byte *plt_contents;
5388 const struct elf_x86_lazy_plt_layout *lazy_plt;
5389 const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
5390 const struct elf_x86_lazy_plt_layout *lazy_ibt_plt;
5391 const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt;
5394 enum elf_x86_plt_type plt_type;
5395 struct elf_x86_plt plts[] =
5397 { ".plt", NULL, NULL, plt_unknown, 0, 0, 0, 0 },
5398 { ".plt.got", NULL, NULL, plt_non_lazy, 0, 0, 0, 0 },
5399 { ".plt.sec", NULL, NULL, plt_second, 0, 0, 0, 0 },
5400 { NULL, NULL, NULL, plt_non_lazy, 0, 0, 0, 0 }
5405 if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
5408 if (dynsymcount <= 0)
5411 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
5415 non_lazy_plt = NULL;
5416 /* Silence GCC 6. */
5418 non_lazy_ibt_plt = NULL;
5419 lazy_ibt_plt = NULL;
5420 switch (get_elf_i386_backend_data (abfd)->os)
5423 non_lazy_plt = &elf_i386_non_lazy_plt;
5424 lazy_ibt_plt = &elf_i386_lazy_ibt_plt;
5425 non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt;
5428 lazy_plt = &elf_i386_lazy_plt;
5431 lazy_plt = &elf_i386_nacl_plt;
5438 for (j = 0; plts[j].name != NULL; j++)
5440 plt = bfd_get_section_by_name (abfd, plts[j].name);
5441 if (plt == NULL || plt->size == 0)
5444 /* Get the PLT section contents. */
5445 plt_contents = (bfd_byte *) bfd_malloc (plt->size);
5446 if (plt_contents == NULL)
5448 if (!bfd_get_section_contents (abfd, (asection *) plt,
5449 plt_contents, 0, plt->size))
5451 free (plt_contents);
5455 /* Check what kind of PLT it is. */
5456 plt_type = plt_unknown;
5457 if (plts[j].type == plt_unknown
5458 && (plt->size >= (lazy_plt->plt0_entry_size
5459 + lazy_plt->plt_entry_size)))
5461 /* Match lazy PLT first. */
5462 if (memcmp (plt_contents, lazy_plt->plt0_entry,
5463 lazy_plt->plt0_got1_offset) == 0)
5465 /* The fist entry in the lazy IBT PLT is the same as the
5467 if (lazy_ibt_plt != NULL
5468 && (memcmp (plt_contents + lazy_ibt_plt->plt0_entry_size,
5469 lazy_ibt_plt->plt_entry,
5470 lazy_ibt_plt->plt_got_offset) == 0))
5471 plt_type = plt_lazy | plt_second;
5473 plt_type = plt_lazy;
5475 else if (memcmp (plt_contents, lazy_plt->pic_plt0_entry,
5476 lazy_plt->plt0_got1_offset) == 0)
5478 /* The fist entry in the PIC lazy IBT PLT is the same as
5479 the normal PIC lazy PLT. */
5480 if (lazy_ibt_plt != NULL
5481 && (memcmp (plt_contents + lazy_ibt_plt->plt0_entry_size,
5482 lazy_ibt_plt->pic_plt_entry,
5483 lazy_ibt_plt->plt_got_offset) == 0))
5484 plt_type = plt_lazy | plt_pic | plt_second;
5486 plt_type = plt_lazy | plt_pic;
5490 if (non_lazy_plt != NULL
5491 && (plt_type == plt_unknown || plt_type == plt_non_lazy)
5492 && plt->size >= non_lazy_plt->plt_entry_size)
5494 /* Match non-lazy PLT. */
5495 if (memcmp (plt_contents, non_lazy_plt->plt_entry,
5496 non_lazy_plt->plt_got_offset) == 0)
5497 plt_type = plt_non_lazy;
5498 else if (memcmp (plt_contents, non_lazy_plt->pic_plt_entry,
5499 non_lazy_plt->plt_got_offset) == 0)
5503 if ((non_lazy_ibt_plt != NULL)
5504 && (plt_type == plt_unknown || plt_type == plt_second)
5505 && plt->size >= non_lazy_ibt_plt->plt_entry_size)
5507 if (memcmp (plt_contents,
5508 non_lazy_ibt_plt->plt_entry,
5509 non_lazy_ibt_plt->plt_got_offset) == 0)
5511 /* Match IBT PLT. */
5512 plt_type = plt_second;
5513 non_lazy_plt = non_lazy_ibt_plt;
5515 else if (memcmp (plt_contents,
5516 non_lazy_ibt_plt->pic_plt_entry,
5517 non_lazy_ibt_plt->plt_got_offset) == 0)
5519 /* Match PIC IBT PLT. */
5520 plt_type = plt_second | plt_pic;
5521 non_lazy_plt = non_lazy_ibt_plt;
5525 if (plt_type == plt_unknown)
5527 free (plt_contents);
5532 plts[j].type = plt_type;
5534 if ((plt_type & plt_lazy))
5536 plts[j].plt_got_offset = lazy_plt->plt_got_offset;
5537 plts[j].plt_entry_size = lazy_plt->plt_entry_size;
5538 /* Skip PLT0 in lazy PLT. */
5543 plts[j].plt_got_offset = non_lazy_plt->plt_got_offset;
5544 plts[j].plt_entry_size = non_lazy_plt->plt_entry_size;
5548 /* Skip lazy PLT when the second PLT is used. */
5549 if ((plt_type & (plt_lazy | plt_second))
5550 == (plt_lazy | plt_second))
5554 n = plt->size / plts[j].plt_entry_size;
5559 plts[j].contents = plt_contents;
5561 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
5562 if ((plt_type & plt_pic))
5563 got_addr = (bfd_vma) -1;
5566 return _bfd_x86_elf_get_synthetic_symtab (abfd, count, relsize,
5567 got_addr, plts, dynsyms,
5571 /* Set up i386 GNU properties. Return the first relocatable ELF input
5572 with GNU properties if found. Otherwise, return NULL. */
5575 elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
5577 struct elf_x86_plt_layout_table plt_layout;
5579 plt_layout.normal_target = FALSE;
5580 plt_layout.is_vxworks = FALSE;
5581 switch (get_elf_i386_backend_data (info->output_bfd)->os)
5584 plt_layout.lazy_plt = &elf_i386_lazy_plt;
5585 plt_layout.non_lazy_plt = &elf_i386_non_lazy_plt;
5586 plt_layout.lazy_ibt_plt = &elf_i386_lazy_ibt_plt;
5587 plt_layout.non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt;
5588 plt_layout.normal_target = TRUE;
5591 plt_layout.lazy_plt = &elf_i386_lazy_plt;
5592 plt_layout.non_lazy_plt = NULL;
5593 plt_layout.lazy_ibt_plt = NULL;
5594 plt_layout.non_lazy_ibt_plt = NULL;
5595 plt_layout.is_vxworks = TRUE;
5598 plt_layout.lazy_plt = &elf_i386_nacl_plt;
5599 plt_layout.non_lazy_plt = NULL;
5600 plt_layout.lazy_ibt_plt = NULL;
5601 plt_layout.non_lazy_ibt_plt = NULL;
5605 return _bfd_x86_elf_link_setup_gnu_properties (info, &plt_layout);
5608 #define TARGET_LITTLE_SYM i386_elf32_vec
5609 #define TARGET_LITTLE_NAME "elf32-i386"
5610 #define ELF_ARCH bfd_arch_i386
5611 #define ELF_TARGET_ID I386_ELF_DATA
5612 #define ELF_MACHINE_CODE EM_386
5613 #define ELF_MAXPAGESIZE 0x1000
5615 #define elf_backend_can_gc_sections 1
5616 #define elf_backend_can_refcount 1
5617 #define elf_backend_want_got_plt 1
5618 #define elf_backend_plt_readonly 1
5619 #define elf_backend_want_plt_sym 0
5620 #define elf_backend_got_header_size 12
5621 #define elf_backend_plt_alignment 4
5622 #define elf_backend_dtrel_excludes_plt 1
5623 #define elf_backend_extern_protected_data 1
5624 #define elf_backend_caches_rawsize 1
5625 #define elf_backend_want_dynrelro 1
5627 /* Support RELA for objdump of prelink objects. */
5628 #define elf_info_to_howto elf_i386_info_to_howto_rel
5629 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
5631 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
5632 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
5633 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
5634 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
5636 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
5637 #define elf_backend_check_relocs elf_i386_check_relocs
5638 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5639 #define elf_backend_fake_sections elf_i386_fake_sections
5640 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
5641 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
5642 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
5643 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
5644 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
5645 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
5646 #define elf_backend_relocate_section elf_i386_relocate_section
5647 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
5648 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
5650 #include "elf32-target.h"
5652 /* FreeBSD support. */
5654 #undef TARGET_LITTLE_SYM
5655 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
5656 #undef TARGET_LITTLE_NAME
5657 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
5659 #define ELF_OSABI ELFOSABI_FREEBSD
5661 /* The kernel recognizes executables as valid only if they carry a
5662 "FreeBSD" label in the ELF header. So we put this label on all
5663 executables and (for simplicity) also all other object files. */
5666 elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info)
5668 _bfd_elf_post_process_headers (abfd, info);
5670 #ifdef OLD_FREEBSD_ABI_LABEL
5672 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5673 Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
5674 memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
5679 #undef elf_backend_post_process_headers
5680 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
5682 #define elf32_bed elf32_i386_fbsd_bed
5684 #undef elf_backend_add_symbol_hook
5686 #include "elf32-target.h"
5690 #undef TARGET_LITTLE_SYM
5691 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
5692 #undef TARGET_LITTLE_NAME
5693 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
5695 #undef elf_backend_post_process_headers
5697 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5698 objects won't be recognized. */
5702 #define elf32_bed elf32_i386_sol2_bed
5704 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5706 #undef elf_backend_static_tls_alignment
5707 #define elf_backend_static_tls_alignment 8
5709 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5711 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5713 #undef elf_backend_want_plt_sym
5714 #define elf_backend_want_plt_sym 1
5716 #undef elf_backend_strtab_flags
5717 #define elf_backend_strtab_flags SHF_STRINGS
5719 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
5720 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
5721 FALSE otherwise. ISECTION is the best guess matching section from the
5722 input bfd IBFD, but it might be NULL. */
5725 elf32_i386_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
5726 bfd *obfd ATTRIBUTE_UNUSED,
5727 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
5728 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
5730 /* PR 19938: FIXME: Need to add code for setting the sh_info
5731 and sh_link fields of Solaris specific section types. */
5734 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
5735 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
5737 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
5739 The following values should be set:
5742 -----------------------------------------------------------------------------
5743 SHT_SUNW_ancillary The section header index of 0
5744 [0x6fffffee] the associated string table.
5746 SHT_SUNW_capinfo The section header index of For a dynamic object, the
5747 [0x6ffffff0] the associated symbol table. section header index of
5749 SHT_SUNW_capchain table,
5752 SHT_SUNW_symsort The section header index of 0
5753 [0x6ffffff1] the associated symbol table.
5755 SHT_SUNW_tlssort The section header index of 0
5756 [0x6ffffff2] the associated symbol table.
5758 SHT_SUNW_LDYNSYM The section header index of One greater than the
5759 [0x6ffffff3] the associated string table. symbol table index of the
5760 This index is the same string last local symbol,
5761 table used by the SHT_DYNSYM STB_LOCAL. Since
5762 section. SHT_SUNW_LDYNSYM only
5763 contains local symbols,
5764 sh_info is equivalent to
5765 the number of symbols in
5768 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
5769 [0x6ffffff5] the section header index of to named strings, the
5770 the associated section header index of
5771 SHT_SUNW_capinfo table, the associated string
5772 otherwise 0. table, otherwise 0.
5774 SHT_SUNW_move The section header index of 0
5775 [0x6ffffffa] the associated symbol table.
5780 SHT_SUNW_syminfo The section header index of The section header index
5781 [0x6ffffffc] the associated symbol table. of the associated
5784 SHT_SUNW_verdef The section header index of The number of version
5785 [0x6ffffffd] the associated string table. definitions within the
5788 SHT_SUNW_verneed The section header index of The number of version
5789 [0x6ffffffe] the associated string table. dependencies within the
5792 SHT_SUNW_versym The section header index of 0
5793 [0x6fffffff] the associated symbol table. */
5796 #undef elf_backend_copy_special_section_fields
5797 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
5799 #include "elf32-target.h"
5801 /* Intel MCU support. */
5804 elf32_iamcu_elf_object_p (bfd *abfd)
5806 /* Set the right machine number for an IAMCU elf32 file. */
5807 bfd_default_set_arch_mach (abfd, bfd_arch_iamcu, bfd_mach_i386_iamcu);
5811 #undef TARGET_LITTLE_SYM
5812 #define TARGET_LITTLE_SYM iamcu_elf32_vec
5813 #undef TARGET_LITTLE_NAME
5814 #define TARGET_LITTLE_NAME "elf32-iamcu"
5816 #define ELF_ARCH bfd_arch_iamcu
5818 #undef ELF_MACHINE_CODE
5819 #define ELF_MACHINE_CODE EM_IAMCU
5824 #define elf32_bed elf32_iamcu_bed
5826 #undef elf_backend_object_p
5827 #define elf_backend_object_p elf32_iamcu_elf_object_p
5829 #undef elf_backend_static_tls_alignment
5831 #undef elf_backend_want_plt_sym
5832 #define elf_backend_want_plt_sym 0
5834 #undef elf_backend_strtab_flags
5835 #undef elf_backend_copy_special_section_fields
5837 #include "elf32-target.h"
5839 /* Restore defaults. */
5841 #define ELF_ARCH bfd_arch_i386
5842 #undef ELF_MACHINE_CODE
5843 #define ELF_MACHINE_CODE EM_386
5845 /* Native Client support. */
5847 #undef TARGET_LITTLE_SYM
5848 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
5849 #undef TARGET_LITTLE_NAME
5850 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
5852 #define elf32_bed elf32_i386_nacl_bed
5854 #undef ELF_MAXPAGESIZE
5855 #define ELF_MAXPAGESIZE 0x10000
5857 /* Restore defaults. */
5859 #undef elf_backend_want_plt_sym
5860 #define elf_backend_want_plt_sym 0
5861 #undef elf_backend_post_process_headers
5862 #undef elf_backend_static_tls_alignment
5864 /* NaCl uses substantially different PLT entries for the same effects. */
5866 #undef elf_backend_plt_alignment
5867 #define elf_backend_plt_alignment 5
5868 #define NACL_PLT_ENTRY_SIZE 64
5869 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5871 static const bfd_byte elf_i386_nacl_plt0_entry[] =
5873 0xff, 0x35, /* pushl contents of address */
5874 0, 0, 0, 0, /* replaced with address of .got + 4. */
5875 0x8b, 0x0d, /* movl contents of address, %ecx */
5876 0, 0, 0, 0, /* replaced with address of .got + 8. */
5877 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */
5878 0xff, 0xe1 /* jmp *%ecx */
5881 static const bfd_byte elf_i386_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
5883 0x8b, 0x0d, /* movl contents of address, %ecx */
5884 0, 0, 0, 0, /* replaced with GOT slot address. */
5885 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */
5886 0xff, 0xe1, /* jmp *%ecx */
5888 /* Pad to the next 32-byte boundary with nop instructions. */
5890 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5891 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5893 /* Lazy GOT entries point here (32-byte aligned). */
5894 0x68, /* pushl immediate */
5895 0, 0, 0, 0, /* replaced with reloc offset. */
5896 0xe9, /* jmp relative */
5897 0, 0, 0, 0, /* replaced with offset to .plt. */
5899 /* Pad to the next 32-byte boundary with nop instructions. */
5900 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5901 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5905 static const bfd_byte
5906 elf_i386_nacl_pic_plt0_entry[sizeof (elf_i386_nacl_plt0_entry)] =
5908 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5909 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5910 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5911 0xff, 0xe1, /* jmp *%ecx */
5913 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
5914 so pad to that size with nop instructions. */
5915 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
5918 static const bfd_byte elf_i386_nacl_pic_plt_entry[NACL_PLT_ENTRY_SIZE] =
5920 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5921 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5922 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5923 0xff, 0xe1, /* jmp *%ecx */
5925 /* Pad to the next 32-byte boundary with nop instructions. */
5927 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5928 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5930 /* Lazy GOT entries point here (32-byte aligned). */
5931 0x68, /* pushl immediate */
5932 0, 0, 0, 0, /* replaced with offset into relocation table. */
5933 0xe9, /* jmp relative */
5934 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5936 /* Pad to the next 32-byte boundary with nop instructions. */
5937 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5938 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5942 static const bfd_byte elf_i386_nacl_eh_frame_plt[] =
5944 #if (PLT_CIE_LENGTH != 20 \
5945 || PLT_FDE_LENGTH != 36 \
5946 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5947 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5948 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5950 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
5951 0, 0, 0, 0, /* CIE ID */
5952 1, /* CIE version */
5953 'z', 'R', 0, /* Augmentation string */
5954 1, /* Code alignment factor */
5955 0x7c, /* Data alignment factor: -4 */
5956 8, /* Return address column */
5957 1, /* Augmentation size */
5958 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
5959 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5960 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5961 DW_CFA_nop, DW_CFA_nop,
5963 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
5964 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
5965 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5966 0, 0, 0, 0, /* .plt size goes here */
5967 0, /* Augmentation size */
5968 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
5969 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5970 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
5971 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5972 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
5973 13, /* Block length */
5974 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
5975 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
5976 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
5977 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
5978 DW_CFA_nop, DW_CFA_nop
5981 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt =
5983 elf_i386_nacl_plt0_entry, /* plt0_entry */
5984 sizeof (elf_i386_nacl_plt0_entry), /* plt0_entry_size */
5985 elf_i386_nacl_plt_entry, /* plt_entry */
5986 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
5987 2, /* plt0_got1_offset */
5988 8, /* plt0_got2_offset */
5989 0, /* plt0_got2_insn_end */
5990 2, /* plt_got_offset */
5991 33, /* plt_reloc_offset */
5992 38, /* plt_plt_offset */
5993 0, /* plt_got_insn_size */
5994 0, /* plt_plt_insn_end */
5995 32, /* plt_lazy_offset */
5996 elf_i386_nacl_pic_plt0_entry, /* pic_plt0_entry */
5997 elf_i386_nacl_pic_plt_entry, /* pic_plt_entry */
5998 elf_i386_nacl_eh_frame_plt, /* eh_frame_plt */
5999 sizeof (elf_i386_nacl_eh_frame_plt) /* eh_frame_plt_size */
6002 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed =
6004 0x90, /* plt0_pad_byte: nop insn */
6009 elf32_i386_nacl_elf_object_p (bfd *abfd)
6011 /* Set the right machine number for a NaCl i386 ELF32 file. */
6012 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386_nacl);
6016 #undef elf_backend_arch_data
6017 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
6019 #undef elf_backend_object_p
6020 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
6021 #undef elf_backend_modify_segment_map
6022 #define elf_backend_modify_segment_map nacl_modify_segment_map
6023 #undef elf_backend_modify_program_headers
6024 #define elf_backend_modify_program_headers nacl_modify_program_headers
6025 #undef elf_backend_final_write_processing
6026 #define elf_backend_final_write_processing nacl_final_write_processing
6028 #include "elf32-target.h"
6030 /* Restore defaults. */
6031 #undef elf_backend_object_p
6032 #undef elf_backend_modify_segment_map
6033 #undef elf_backend_modify_program_headers
6034 #undef elf_backend_final_write_processing
6036 /* VxWorks support. */
6038 #undef TARGET_LITTLE_SYM
6039 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
6040 #undef TARGET_LITTLE_NAME
6041 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
6043 #undef ELF_MAXPAGESIZE
6044 #define ELF_MAXPAGESIZE 0x1000
6045 #undef elf_backend_plt_alignment
6046 #define elf_backend_plt_alignment 4
6048 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed =
6050 0x90, /* plt0_pad_byte */
6054 #undef elf_backend_arch_data
6055 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
6057 #undef elf_backend_relocs_compatible
6058 #undef elf_backend_add_symbol_hook
6059 #define elf_backend_add_symbol_hook \
6060 elf_vxworks_add_symbol_hook
6061 #undef elf_backend_link_output_symbol_hook
6062 #define elf_backend_link_output_symbol_hook \
6063 elf_vxworks_link_output_symbol_hook
6064 #undef elf_backend_emit_relocs
6065 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
6066 #undef elf_backend_final_write_processing
6067 #define elf_backend_final_write_processing \
6068 elf_vxworks_final_write_processing
6069 #undef elf_backend_static_tls_alignment
6071 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
6073 #undef elf_backend_want_plt_sym
6074 #define elf_backend_want_plt_sym 1
6077 #define elf32_bed elf32_i386_vxworks_bed
6079 #include "elf32-target.h"