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. */
27 #include "elf-vxworks.h"
28 #include "bfd_stdint.h"
32 #include "opcode/i386.h"
34 /* 386 uses REL relocations instead of RELA. */
39 static reloc_howto_type elf_howto_table[]=
41 HOWTO(R_386_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont,
42 bfd_elf_generic_reloc, "R_386_NONE",
43 TRUE, 0x00000000, 0x00000000, FALSE),
44 HOWTO(R_386_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
45 bfd_elf_generic_reloc, "R_386_32",
46 TRUE, 0xffffffff, 0xffffffff, FALSE),
47 HOWTO(R_386_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
48 bfd_elf_generic_reloc, "R_386_PC32",
49 TRUE, 0xffffffff, 0xffffffff, TRUE),
50 HOWTO(R_386_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
51 bfd_elf_generic_reloc, "R_386_GOT32",
52 TRUE, 0xffffffff, 0xffffffff, FALSE),
53 HOWTO(R_386_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
54 bfd_elf_generic_reloc, "R_386_PLT32",
55 TRUE, 0xffffffff, 0xffffffff, TRUE),
56 HOWTO(R_386_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
57 bfd_elf_generic_reloc, "R_386_COPY",
58 TRUE, 0xffffffff, 0xffffffff, FALSE),
59 HOWTO(R_386_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
60 bfd_elf_generic_reloc, "R_386_GLOB_DAT",
61 TRUE, 0xffffffff, 0xffffffff, FALSE),
62 HOWTO(R_386_JUMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
63 bfd_elf_generic_reloc, "R_386_JUMP_SLOT",
64 TRUE, 0xffffffff, 0xffffffff, FALSE),
65 HOWTO(R_386_RELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
66 bfd_elf_generic_reloc, "R_386_RELATIVE",
67 TRUE, 0xffffffff, 0xffffffff, FALSE),
68 HOWTO(R_386_GOTOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
69 bfd_elf_generic_reloc, "R_386_GOTOFF",
70 TRUE, 0xffffffff, 0xffffffff, FALSE),
71 HOWTO(R_386_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
72 bfd_elf_generic_reloc, "R_386_GOTPC",
73 TRUE, 0xffffffff, 0xffffffff, TRUE),
75 /* We have a gap in the reloc numbers here.
76 R_386_standard counts the number up to this point, and
77 R_386_ext_offset is the value to subtract from a reloc type of
78 R_386_16 thru R_386_PC8 to form an index into this table. */
79 #define R_386_standard (R_386_GOTPC + 1)
80 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
82 /* These relocs are a GNU extension. */
83 HOWTO(R_386_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
84 bfd_elf_generic_reloc, "R_386_TLS_TPOFF",
85 TRUE, 0xffffffff, 0xffffffff, FALSE),
86 HOWTO(R_386_TLS_IE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
87 bfd_elf_generic_reloc, "R_386_TLS_IE",
88 TRUE, 0xffffffff, 0xffffffff, FALSE),
89 HOWTO(R_386_TLS_GOTIE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
90 bfd_elf_generic_reloc, "R_386_TLS_GOTIE",
91 TRUE, 0xffffffff, 0xffffffff, FALSE),
92 HOWTO(R_386_TLS_LE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
93 bfd_elf_generic_reloc, "R_386_TLS_LE",
94 TRUE, 0xffffffff, 0xffffffff, FALSE),
95 HOWTO(R_386_TLS_GD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
96 bfd_elf_generic_reloc, "R_386_TLS_GD",
97 TRUE, 0xffffffff, 0xffffffff, FALSE),
98 HOWTO(R_386_TLS_LDM, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
99 bfd_elf_generic_reloc, "R_386_TLS_LDM",
100 TRUE, 0xffffffff, 0xffffffff, FALSE),
101 HOWTO(R_386_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
102 bfd_elf_generic_reloc, "R_386_16",
103 TRUE, 0xffff, 0xffff, FALSE),
104 HOWTO(R_386_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
105 bfd_elf_generic_reloc, "R_386_PC16",
106 TRUE, 0xffff, 0xffff, TRUE),
107 HOWTO(R_386_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
108 bfd_elf_generic_reloc, "R_386_8",
109 TRUE, 0xff, 0xff, FALSE),
110 HOWTO(R_386_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
111 bfd_elf_generic_reloc, "R_386_PC8",
112 TRUE, 0xff, 0xff, TRUE),
114 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
115 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
116 /* These are common with Solaris TLS implementation. */
117 HOWTO(R_386_TLS_LDO_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
118 bfd_elf_generic_reloc, "R_386_TLS_LDO_32",
119 TRUE, 0xffffffff, 0xffffffff, FALSE),
120 HOWTO(R_386_TLS_IE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
121 bfd_elf_generic_reloc, "R_386_TLS_IE_32",
122 TRUE, 0xffffffff, 0xffffffff, FALSE),
123 HOWTO(R_386_TLS_LE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
124 bfd_elf_generic_reloc, "R_386_TLS_LE_32",
125 TRUE, 0xffffffff, 0xffffffff, FALSE),
126 HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
127 bfd_elf_generic_reloc, "R_386_TLS_DTPMOD32",
128 TRUE, 0xffffffff, 0xffffffff, FALSE),
129 HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
130 bfd_elf_generic_reloc, "R_386_TLS_DTPOFF32",
131 TRUE, 0xffffffff, 0xffffffff, FALSE),
132 HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
133 bfd_elf_generic_reloc, "R_386_TLS_TPOFF32",
134 TRUE, 0xffffffff, 0xffffffff, FALSE),
135 HOWTO(R_386_SIZE32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
136 bfd_elf_generic_reloc, "R_386_SIZE32",
137 TRUE, 0xffffffff, 0xffffffff, FALSE),
138 HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
139 bfd_elf_generic_reloc, "R_386_TLS_GOTDESC",
140 TRUE, 0xffffffff, 0xffffffff, FALSE),
141 HOWTO(R_386_TLS_DESC_CALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
142 bfd_elf_generic_reloc, "R_386_TLS_DESC_CALL",
144 HOWTO(R_386_TLS_DESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
145 bfd_elf_generic_reloc, "R_386_TLS_DESC",
146 TRUE, 0xffffffff, 0xffffffff, FALSE),
147 HOWTO(R_386_IRELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
148 bfd_elf_generic_reloc, "R_386_IRELATIVE",
149 TRUE, 0xffffffff, 0xffffffff, FALSE),
150 HOWTO(R_386_GOT32X, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
151 bfd_elf_generic_reloc, "R_386_GOT32X",
152 TRUE, 0xffffffff, 0xffffffff, FALSE),
155 #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
156 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
158 /* GNU extension to record C++ vtable hierarchy. */
159 HOWTO (R_386_GNU_VTINHERIT, /* type */
161 2, /* size (0 = byte, 1 = short, 2 = long) */
163 FALSE, /* pc_relative */
165 complain_overflow_dont, /* complain_on_overflow */
166 NULL, /* special_function */
167 "R_386_GNU_VTINHERIT", /* name */
168 FALSE, /* partial_inplace */
171 FALSE), /* pcrel_offset */
173 /* GNU extension to record C++ vtable member usage. */
174 HOWTO (R_386_GNU_VTENTRY, /* type */
176 2, /* size (0 = byte, 1 = short, 2 = long) */
178 FALSE, /* pc_relative */
180 complain_overflow_dont, /* complain_on_overflow */
181 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
182 "R_386_GNU_VTENTRY", /* name */
183 FALSE, /* partial_inplace */
186 FALSE) /* pcrel_offset */
188 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
192 #ifdef DEBUG_GEN_RELOC
194 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
199 static reloc_howto_type *
200 elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
201 bfd_reloc_code_real_type code)
206 TRACE ("BFD_RELOC_NONE");
207 return &elf_howto_table[R_386_NONE];
210 TRACE ("BFD_RELOC_32");
211 return &elf_howto_table[R_386_32];
214 TRACE ("BFD_RELOC_CTOR");
215 return &elf_howto_table[R_386_32];
217 case BFD_RELOC_32_PCREL:
218 TRACE ("BFD_RELOC_PC32");
219 return &elf_howto_table[R_386_PC32];
221 case BFD_RELOC_386_GOT32:
222 TRACE ("BFD_RELOC_386_GOT32");
223 return &elf_howto_table[R_386_GOT32];
225 case BFD_RELOC_386_PLT32:
226 TRACE ("BFD_RELOC_386_PLT32");
227 return &elf_howto_table[R_386_PLT32];
229 case BFD_RELOC_386_COPY:
230 TRACE ("BFD_RELOC_386_COPY");
231 return &elf_howto_table[R_386_COPY];
233 case BFD_RELOC_386_GLOB_DAT:
234 TRACE ("BFD_RELOC_386_GLOB_DAT");
235 return &elf_howto_table[R_386_GLOB_DAT];
237 case BFD_RELOC_386_JUMP_SLOT:
238 TRACE ("BFD_RELOC_386_JUMP_SLOT");
239 return &elf_howto_table[R_386_JUMP_SLOT];
241 case BFD_RELOC_386_RELATIVE:
242 TRACE ("BFD_RELOC_386_RELATIVE");
243 return &elf_howto_table[R_386_RELATIVE];
245 case BFD_RELOC_386_GOTOFF:
246 TRACE ("BFD_RELOC_386_GOTOFF");
247 return &elf_howto_table[R_386_GOTOFF];
249 case BFD_RELOC_386_GOTPC:
250 TRACE ("BFD_RELOC_386_GOTPC");
251 return &elf_howto_table[R_386_GOTPC];
253 /* These relocs are a GNU extension. */
254 case BFD_RELOC_386_TLS_TPOFF:
255 TRACE ("BFD_RELOC_386_TLS_TPOFF");
256 return &elf_howto_table[R_386_TLS_TPOFF - R_386_ext_offset];
258 case BFD_RELOC_386_TLS_IE:
259 TRACE ("BFD_RELOC_386_TLS_IE");
260 return &elf_howto_table[R_386_TLS_IE - R_386_ext_offset];
262 case BFD_RELOC_386_TLS_GOTIE:
263 TRACE ("BFD_RELOC_386_TLS_GOTIE");
264 return &elf_howto_table[R_386_TLS_GOTIE - R_386_ext_offset];
266 case BFD_RELOC_386_TLS_LE:
267 TRACE ("BFD_RELOC_386_TLS_LE");
268 return &elf_howto_table[R_386_TLS_LE - R_386_ext_offset];
270 case BFD_RELOC_386_TLS_GD:
271 TRACE ("BFD_RELOC_386_TLS_GD");
272 return &elf_howto_table[R_386_TLS_GD - R_386_ext_offset];
274 case BFD_RELOC_386_TLS_LDM:
275 TRACE ("BFD_RELOC_386_TLS_LDM");
276 return &elf_howto_table[R_386_TLS_LDM - R_386_ext_offset];
279 TRACE ("BFD_RELOC_16");
280 return &elf_howto_table[R_386_16 - R_386_ext_offset];
282 case BFD_RELOC_16_PCREL:
283 TRACE ("BFD_RELOC_16_PCREL");
284 return &elf_howto_table[R_386_PC16 - R_386_ext_offset];
287 TRACE ("BFD_RELOC_8");
288 return &elf_howto_table[R_386_8 - R_386_ext_offset];
290 case BFD_RELOC_8_PCREL:
291 TRACE ("BFD_RELOC_8_PCREL");
292 return &elf_howto_table[R_386_PC8 - R_386_ext_offset];
294 /* Common with Sun TLS implementation. */
295 case BFD_RELOC_386_TLS_LDO_32:
296 TRACE ("BFD_RELOC_386_TLS_LDO_32");
297 return &elf_howto_table[R_386_TLS_LDO_32 - R_386_tls_offset];
299 case BFD_RELOC_386_TLS_IE_32:
300 TRACE ("BFD_RELOC_386_TLS_IE_32");
301 return &elf_howto_table[R_386_TLS_IE_32 - R_386_tls_offset];
303 case BFD_RELOC_386_TLS_LE_32:
304 TRACE ("BFD_RELOC_386_TLS_LE_32");
305 return &elf_howto_table[R_386_TLS_LE_32 - R_386_tls_offset];
307 case BFD_RELOC_386_TLS_DTPMOD32:
308 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
309 return &elf_howto_table[R_386_TLS_DTPMOD32 - R_386_tls_offset];
311 case BFD_RELOC_386_TLS_DTPOFF32:
312 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
313 return &elf_howto_table[R_386_TLS_DTPOFF32 - R_386_tls_offset];
315 case BFD_RELOC_386_TLS_TPOFF32:
316 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
317 return &elf_howto_table[R_386_TLS_TPOFF32 - R_386_tls_offset];
319 case BFD_RELOC_SIZE32:
320 TRACE ("BFD_RELOC_SIZE32");
321 return &elf_howto_table[R_386_SIZE32 - R_386_tls_offset];
323 case BFD_RELOC_386_TLS_GOTDESC:
324 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
325 return &elf_howto_table[R_386_TLS_GOTDESC - R_386_tls_offset];
327 case BFD_RELOC_386_TLS_DESC_CALL:
328 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
329 return &elf_howto_table[R_386_TLS_DESC_CALL - R_386_tls_offset];
331 case BFD_RELOC_386_TLS_DESC:
332 TRACE ("BFD_RELOC_386_TLS_DESC");
333 return &elf_howto_table[R_386_TLS_DESC - R_386_tls_offset];
335 case BFD_RELOC_386_IRELATIVE:
336 TRACE ("BFD_RELOC_386_IRELATIVE");
337 return &elf_howto_table[R_386_IRELATIVE - R_386_tls_offset];
339 case BFD_RELOC_386_GOT32X:
340 TRACE ("BFD_RELOC_386_GOT32X");
341 return &elf_howto_table[R_386_GOT32X - R_386_tls_offset];
343 case BFD_RELOC_VTABLE_INHERIT:
344 TRACE ("BFD_RELOC_VTABLE_INHERIT");
345 return &elf_howto_table[R_386_GNU_VTINHERIT - R_386_vt_offset];
347 case BFD_RELOC_VTABLE_ENTRY:
348 TRACE ("BFD_RELOC_VTABLE_ENTRY");
349 return &elf_howto_table[R_386_GNU_VTENTRY - R_386_vt_offset];
359 static reloc_howto_type *
360 elf_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
365 for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++)
366 if (elf_howto_table[i].name != NULL
367 && strcasecmp (elf_howto_table[i].name, r_name) == 0)
368 return &elf_howto_table[i];
373 static reloc_howto_type *
374 elf_i386_rtype_to_howto (bfd *abfd, unsigned r_type)
378 if ((indx = r_type) >= R_386_standard
379 && ((indx = r_type - R_386_ext_offset) - R_386_standard
380 >= R_386_ext - R_386_standard)
381 && ((indx = r_type - R_386_tls_offset) - R_386_ext
382 >= R_386_ext2 - R_386_ext)
383 && ((indx = r_type - R_386_vt_offset) - R_386_ext2
384 >= R_386_vt - R_386_ext2))
386 /* xgettext:c-format */
387 _bfd_error_handler (_("%B: invalid relocation type %d"),
391 /* PR 17512: file: 0f67f69d. */
392 if (elf_howto_table [indx].type != r_type)
394 return &elf_howto_table[indx];
398 elf_i386_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
400 Elf_Internal_Rela *dst)
402 unsigned int r_type = ELF32_R_TYPE (dst->r_info);
403 cache_ptr->howto = elf_i386_rtype_to_howto (abfd, r_type);
406 /* Return whether a symbol name implies a local label. The UnixWare
407 2.1 cc generates temporary symbols that start with .X, so we
408 recognize them here. FIXME: do other SVR4 compilers also use .X?.
409 If so, we should move the .X recognition into
410 _bfd_elf_is_local_label_name. */
413 elf_i386_is_local_label_name (bfd *abfd, const char *name)
415 if (name[0] == '.' && name[1] == 'X')
418 return _bfd_elf_is_local_label_name (abfd, name);
421 /* Support for core dump NOTE sections. */
424 elf_i386_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
429 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
431 int pr_version = bfd_get_32 (abfd, note->descdata);
437 elf_tdata (abfd)->core->signal = bfd_get_32 (abfd, note->descdata + 20);
440 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
444 size = bfd_get_32 (abfd, note->descdata + 8);
448 switch (note->descsz)
453 case 144: /* Linux/i386 */
455 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
458 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
468 /* Make a ".reg/999" section. */
469 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
470 size, note->descpos + offset);
474 elf_i386_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
476 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
478 int pr_version = bfd_get_32 (abfd, note->descdata);
483 elf_tdata (abfd)->core->program
484 = _bfd_elfcore_strndup (abfd, note->descdata + 8, 17);
485 elf_tdata (abfd)->core->command
486 = _bfd_elfcore_strndup (abfd, note->descdata + 25, 81);
490 switch (note->descsz)
495 case 124: /* Linux/i386 elf_prpsinfo. */
496 elf_tdata (abfd)->core->pid
497 = bfd_get_32 (abfd, note->descdata + 12);
498 elf_tdata (abfd)->core->program
499 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
500 elf_tdata (abfd)->core->command
501 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
505 /* Note that for some reason, a spurious space is tacked
506 onto the end of the args in some (at least one anyway)
507 implementations, so strip it off if it exists. */
509 char *command = elf_tdata (abfd)->core->command;
510 int n = strlen (command);
512 if (0 < n && command[n - 1] == ' ')
513 command[n - 1] = '\0';
519 /* Functions for the i386 ELF linker.
521 In order to gain some understanding of code in this file without
522 knowing all the intricate details of the linker, note the
525 Functions named elf_i386_* are called by external routines, other
526 functions are only called locally. elf_i386_* functions appear
527 in this file more or less in the order in which they are called
528 from external routines. eg. elf_i386_check_relocs is called
529 early in the link process, elf_i386_finish_dynamic_sections is
530 one of the last functions. */
533 /* The name of the dynamic interpreter. This is put in the .interp
536 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
538 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
539 copying dynamic variables from a shared lib into an app's dynbss
540 section, and instead use a dynamic relocation to point into the
542 #define ELIMINATE_COPY_RELOCS 1
544 /* The size in bytes of an entry in the lazy procedure linkage table. */
546 #define LAZY_PLT_ENTRY_SIZE 16
548 /* The size in bytes of an entry in the non-lazy procedure linkage
551 #define NON_LAZY_PLT_ENTRY_SIZE 8
553 /* The first entry in an absolute lazy procedure linkage table looks
554 like this. See the SVR4 ABI i386 supplement to see how this works.
555 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
557 static const bfd_byte elf_i386_lazy_plt0_entry[12] =
559 0xff, 0x35, /* pushl contents of address */
560 0, 0, 0, 0, /* replaced with address of .got + 4. */
561 0xff, 0x25, /* jmp indirect */
562 0, 0, 0, 0 /* replaced with address of .got + 8. */
565 /* Subsequent entries in an absolute lazy procedure linkage table look
568 static const bfd_byte elf_i386_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
570 0xff, 0x25, /* jmp indirect */
571 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
572 0x68, /* pushl immediate */
573 0, 0, 0, 0, /* replaced with offset into relocation table. */
574 0xe9, /* jmp relative */
575 0, 0, 0, 0 /* replaced with offset to start of .plt. */
578 /* The first entry in a PIC lazy procedure linkage table look like
579 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
580 lazy_plt->plt0_pad_byte. */
582 static const bfd_byte elf_i386_pic_lazy_plt0_entry[12] =
584 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
585 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
588 /* Subsequent entries in a PIC lazy procedure linkage table look like
591 static const bfd_byte elf_i386_pic_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
593 0xff, 0xa3, /* jmp *offset(%ebx) */
594 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
595 0x68, /* pushl immediate */
596 0, 0, 0, 0, /* replaced with offset into relocation table. */
597 0xe9, /* jmp relative */
598 0, 0, 0, 0 /* replaced with offset to start of .plt. */
601 /* Entries in the non-lazy procedure linkage table look like this. */
603 static const bfd_byte elf_i386_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
605 0xff, 0x25, /* jmp indirect */
606 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
607 0x66, 0x90 /* xchg %ax,%ax */
610 /* Entries in the PIC non-lazy procedure linkage table look like
613 static const bfd_byte elf_i386_pic_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
615 0xff, 0xa3, /* jmp *offset(%ebx) */
616 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
617 0x66, 0x90 /* xchg %ax,%ax */
620 /* The first entry in an absolute IBT-enabled lazy procedure linkage
621 table looks like this. */
623 static const bfd_byte elf_i386_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
625 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
626 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
627 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
630 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
631 table look like this. Subsequent entries for a PIC IBT-enabled lazy
632 procedure linkage table are the same. */
634 static const bfd_byte elf_i386_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
636 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
637 0x68, 0, 0, 0, 0, /* pushl immediate */
638 0xe9, 0, 0, 0, 0, /* jmp relative */
639 0x66, 0x90 /* xchg %ax,%ax */
642 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
645 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
647 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
648 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
649 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
652 /* Entries for branches with IBT-enabled in the absolute non-lazey
653 procedure linkage table look like this. They have the same size
654 as the lazy PLT entry. */
656 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
658 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
659 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
660 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
663 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
664 linkage table look like this. They have the same size as the lazy
667 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
669 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
670 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
671 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
674 /* .eh_frame covering the lazy .plt section. */
676 static const bfd_byte elf_i386_eh_frame_lazy_plt[] =
678 #define PLT_CIE_LENGTH 20
679 #define PLT_FDE_LENGTH 36
680 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
681 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
682 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
683 0, 0, 0, 0, /* CIE ID */
685 'z', 'R', 0, /* Augmentation string */
686 1, /* Code alignment factor */
687 0x7c, /* Data alignment factor */
688 8, /* Return address column */
689 1, /* Augmentation size */
690 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
691 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
692 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
693 DW_CFA_nop, DW_CFA_nop,
695 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
696 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
697 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
698 0, 0, 0, 0, /* .plt size goes here */
699 0, /* Augmentation size */
700 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
701 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
702 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
703 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
704 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
705 11, /* Block length */
706 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
707 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
708 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
709 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
710 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
713 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
715 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt[] =
717 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
718 0, 0, 0, 0, /* CIE ID */
720 'z', 'R', 0, /* Augmentation string */
721 1, /* Code alignment factor */
722 0x7c, /* Data alignment factor */
723 8, /* Return address column */
724 1, /* Augmentation size */
725 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
726 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
727 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
728 DW_CFA_nop, DW_CFA_nop,
730 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
731 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
732 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
733 0, 0, 0, 0, /* .plt size goes here */
734 0, /* Augmentation size */
735 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
736 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
737 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
738 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
739 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
740 11, /* Block length */
741 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
742 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
743 DW_OP_lit15, DW_OP_and, DW_OP_lit9, DW_OP_ge,
744 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
745 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
748 /* .eh_frame covering the non-lazy .plt section. */
750 static const bfd_byte elf_i386_eh_frame_non_lazy_plt[] =
752 #define PLT_GOT_FDE_LENGTH 16
753 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
754 0, 0, 0, 0, /* CIE ID */
756 'z', 'R', 0, /* Augmentation string */
757 1, /* Code alignment factor */
758 0x7c, /* Data alignment factor */
759 8, /* Return address column */
760 1, /* Augmentation size */
761 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
762 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
763 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
764 DW_CFA_nop, DW_CFA_nop,
766 PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */
767 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
768 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
769 0, 0, 0, 0, /* non-lazy .plt size goes here */
770 0, /* Augmentation size */
771 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
774 struct elf_i386_lazy_plt_layout
776 /* The first entry in an absolute lazy procedure linkage table looks
778 const bfd_byte *plt0_entry;
779 unsigned int plt0_entry_size;
781 /* Offsets into plt0_entry that are to be replaced with GOT[1] and
783 unsigned int plt0_got1_offset;
784 unsigned int plt0_got2_offset;
786 /* Later entries in an absolute lazy procedure linkage table look
788 const bfd_byte *plt_entry;
789 unsigned int plt_entry_size;
791 /* Offsets into plt_entry that are to be replaced with... */
792 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
793 unsigned int plt_reloc_offset; /* ... offset into relocation table. */
794 unsigned int plt_plt_offset; /* ... offset to start of .plt. */
796 /* Offset into plt_entry where the initial value of the GOT entry
798 unsigned int plt_lazy_offset;
800 /* The first entry in a PIC lazy procedure linkage table looks like
802 const bfd_byte *pic_plt0_entry;
804 /* Subsequent entries in a PIC lazy procedure linkage table look
806 const bfd_byte *pic_plt_entry;
808 /* .eh_frame covering the lazy .plt section. */
809 const bfd_byte *eh_frame_plt;
810 unsigned int eh_frame_plt_size;
813 struct elf_i386_non_lazy_plt_layout
815 /* Entries in an absolute non-lazy procedure linkage table look like
817 const bfd_byte *plt_entry;
818 /* Entries in a PIC non-lazy procedure linkage table look like this. */
819 const bfd_byte *pic_plt_entry;
821 unsigned int plt_entry_size;
823 /* Offsets into plt_entry that are to be replaced with... */
824 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
826 /* .eh_frame covering the non-lazy .plt section. */
827 const bfd_byte *eh_frame_plt;
828 unsigned int eh_frame_plt_size;
831 struct elf_i386_plt_layout
833 /* The first entry in a lazy procedure linkage table looks like this. */
834 const bfd_byte *plt0_entry;
835 /* Entries in a procedure linkage table look like this. */
836 const bfd_byte *plt_entry;
837 unsigned int plt_entry_size;
840 unsigned int has_plt0;
842 /* Offsets into plt_entry that are to be replaced with... */
843 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
845 /* .eh_frame covering the .plt section. */
846 const bfd_byte *eh_frame_plt;
847 unsigned int eh_frame_plt_size;
850 /* These are the standard parameters. */
851 static const struct elf_i386_lazy_plt_layout elf_i386_lazy_plt =
853 elf_i386_lazy_plt0_entry, /* plt0_entry */
854 sizeof (elf_i386_lazy_plt0_entry), /* plt0_entry_size */
855 2, /* plt0_got1_offset */
856 8, /* plt0_got2_offset */
857 elf_i386_lazy_plt_entry, /* plt_entry */
858 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
859 2, /* plt_got_offset */
860 7, /* plt_reloc_offset */
861 12, /* plt_plt_offset */
862 6, /* plt_lazy_offset */
863 elf_i386_pic_lazy_plt0_entry, /* pic_plt0_entry */
864 elf_i386_pic_lazy_plt_entry, /* pic_plt_entry */
865 elf_i386_eh_frame_lazy_plt, /* eh_frame_plt */
866 sizeof (elf_i386_eh_frame_lazy_plt) /* eh_frame_plt_size */
869 static const struct elf_i386_non_lazy_plt_layout elf_i386_non_lazy_plt =
871 elf_i386_non_lazy_plt_entry, /* plt_entry */
872 elf_i386_pic_non_lazy_plt_entry, /* pic_plt_entry */
873 NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
874 2, /* plt_got_offset */
875 elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */
876 sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
879 static const struct elf_i386_lazy_plt_layout elf_i386_lazy_ibt_plt =
881 elf_i386_lazy_ibt_plt0_entry, /* plt0_entry */
882 sizeof (elf_i386_lazy_ibt_plt0_entry), /* plt0_entry_size */
883 2, /* plt0_got1_offset */
884 8, /* plt0_got2_offset */
885 elf_i386_lazy_ibt_plt_entry, /* plt_entry */
886 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
887 4+2, /* plt_got_offset */
888 4+1, /* plt_reloc_offset */
889 4+6, /* plt_plt_offset */
890 0, /* plt_lazy_offset */
891 elf_i386_pic_lazy_ibt_plt0_entry, /* pic_plt0_entry */
892 elf_i386_lazy_ibt_plt_entry, /* pic_plt_entry */
893 elf_i386_eh_frame_lazy_ibt_plt, /* eh_frame_plt */
894 sizeof (elf_i386_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */
897 static const struct elf_i386_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt =
899 elf_i386_non_lazy_ibt_plt_entry, /* plt_entry */
900 elf_i386_pic_non_lazy_ibt_plt_entry,/* pic_plt_entry */
901 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
902 4+2, /* plt_got_offset */
903 elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */
904 sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
908 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
909 for the PLTResolve stub and then for each PLT entry. */
910 #define PLTRESOLVE_RELOCS_SHLIB 0
911 #define PLTRESOLVE_RELOCS 2
912 #define PLT_NON_JUMP_SLOT_RELOCS 2
914 /* Architecture-specific backend data for i386. */
916 struct elf_i386_backend_data
918 /* Value used to fill the unused bytes of the first PLT entry. */
919 bfd_byte plt0_pad_byte;
930 #define get_elf_i386_backend_data(abfd) \
931 ((const struct elf_i386_backend_data *) \
932 get_elf_backend_data (abfd)->arch_data)
934 /* These are the standard parameters. */
935 static const struct elf_i386_backend_data elf_i386_arch_bed =
937 0, /* plt0_pad_byte */
941 #define elf_backend_arch_data &elf_i386_arch_bed
943 /* Is a undefined weak symbol which is resolved to 0. Reference to an
944 undefined weak symbol is resolved to 0 when building executable if
946 1. Has non-GOT/non-PLT relocations in text section. Or
947 2. Has no GOT/PLT relocation.
948 Local undefined weak symbol is always resolved to 0.
950 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
951 ((EH)->elf.root.type == bfd_link_hash_undefweak \
952 && ((EH)->elf.forced_local \
953 || (bfd_link_executable (INFO) \
954 && (elf_i386_hash_table (INFO)->interp == NULL \
956 || (EH)->has_non_got_reloc \
957 || !(INFO)->dynamic_undefined_weak))))
959 /* Should copy relocation be generated for a symbol. Don't generate
960 copy relocation against a protected symbol defined in a shared
961 object with GNU_PROPERTY_NO_COPY_ON_PROTECTED. */
962 #define SYMBOL_NO_COPYRELOC(INFO, EH) \
963 ((EH)->def_protected \
964 && ((EH)->elf.root.type == bfd_link_hash_defined \
965 || (EH)->elf.root.type == bfd_link_hash_defweak) \
966 && elf_has_no_copy_on_protected ((EH)->elf.root.u.def.section->owner) \
967 && ((EH)->elf.root.u.def.section->owner->flags & DYNAMIC) != 0 \
968 && ((EH)->elf.root.u.def.section->flags & SEC_CODE) == 0)
971 /* i386 ELF linker hash entry. */
973 struct elf_i386_link_hash_entry
975 struct elf_link_hash_entry elf;
977 /* Track dynamic relocs copied for this symbol. */
978 struct elf_dyn_relocs *dyn_relocs;
980 #define GOT_UNKNOWN 0
984 #define GOT_TLS_IE_POS 5
985 #define GOT_TLS_IE_NEG 6
986 #define GOT_TLS_IE_BOTH 7
987 #define GOT_TLS_GDESC 8
988 #define GOT_TLS_GD_BOTH_P(type) \
989 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
990 #define GOT_TLS_GD_P(type) \
991 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
992 #define GOT_TLS_GDESC_P(type) \
993 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
994 #define GOT_TLS_GD_ANY_P(type) \
995 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
996 unsigned char tls_type;
998 /* Symbol is referenced by R_386_GOTOFF relocation. */
999 unsigned int gotoff_ref : 1;
1001 /* Symbol has GOT or PLT relocations. */
1002 unsigned int has_got_reloc : 1;
1004 /* Symbol has non-GOT/non-PLT relocations in text sections. */
1005 unsigned int has_non_got_reloc : 1;
1007 /* Don't call finish_dynamic_symbol on this symbol. */
1008 unsigned int no_finish_dynamic_symbol : 1;
1010 /* TRUE if symbol is __tls_get_addr. */
1011 unsigned int tls_get_addr : 1;
1013 /* TRUE if symbol is defined as a protected symbol. */
1014 unsigned int def_protected : 1;
1016 /* Reference count of C/C++ function pointer relocations in read-write
1017 section which can be resolved at run-time. */
1018 bfd_signed_vma func_pointer_refcount;
1020 /* Information about the GOT PLT entry. Filled when there are both
1021 GOT and PLT relocations against the same function. */
1022 union gotplt_union plt_got;
1024 /* Information about the second PLT entry. */
1025 union gotplt_union plt_second;
1027 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
1028 starting at the end of the jump table. */
1029 bfd_vma tlsdesc_got;
1032 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
1034 struct elf_i386_obj_tdata
1036 struct elf_obj_tdata root;
1038 /* tls_type for each local got entry. */
1039 char *local_got_tls_type;
1041 /* GOTPLT entries for TLS descriptors. */
1042 bfd_vma *local_tlsdesc_gotent;
1045 #define elf_i386_tdata(abfd) \
1046 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
1048 #define elf_i386_local_got_tls_type(abfd) \
1049 (elf_i386_tdata (abfd)->local_got_tls_type)
1051 #define elf_i386_local_tlsdesc_gotent(abfd) \
1052 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
1054 #define is_i386_elf(bfd) \
1055 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1056 && elf_tdata (bfd) != NULL \
1057 && elf_object_id (bfd) == I386_ELF_DATA)
1060 elf_i386_mkobject (bfd *abfd)
1062 return bfd_elf_allocate_object (abfd, sizeof (struct elf_i386_obj_tdata),
1066 /* i386 ELF linker hash table. */
1068 struct elf_i386_link_hash_table
1070 struct elf_link_hash_table elf;
1072 /* Short-cuts to get to dynamic linker sections. */
1074 asection *plt_eh_frame;
1075 asection *plt_second;
1076 asection *plt_second_eh_frame;
1078 asection *plt_got_eh_frame;
1080 /* Parameters describing PLT generation. */
1081 struct elf_i386_plt_layout plt;
1083 /* Parameters describing lazy PLT generation. */
1084 const struct elf_i386_lazy_plt_layout *lazy_plt;
1086 /* Parameters describing non-lazy PLT generation. */
1087 const struct elf_i386_non_lazy_plt_layout *non_lazy_plt;
1091 bfd_signed_vma refcount;
1095 /* The amount of space used by the reserved portion of the sgotplt
1096 section, plus whatever space is used by the jump slots. */
1097 bfd_vma sgotplt_jump_table_size;
1099 /* Small local sym cache. */
1100 struct sym_cache sym_cache;
1102 /* _TLS_MODULE_BASE_ symbol. */
1103 struct bfd_link_hash_entry *tls_module_base;
1105 /* Used by local STT_GNU_IFUNC symbols. */
1106 htab_t loc_hash_table;
1107 void * loc_hash_memory;
1109 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
1112 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
1113 bfd_vma next_tls_desc_index;
1115 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
1116 bfd_vma next_jump_slot_index;
1118 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
1119 bfd_vma next_irelative_index;
1121 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
1122 to read-only sections. */
1123 bfd_boolean readonly_dynrelocs_against_ifunc;
1126 /* Get the i386 ELF linker hash table from a link_info structure. */
1128 #define elf_i386_hash_table(p) \
1129 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
1130 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
1132 #define elf_i386_compute_jump_table_size(htab) \
1133 ((htab)->elf.srelplt->reloc_count * 4)
1135 /* Create an entry in an i386 ELF linker hash table. */
1137 static struct bfd_hash_entry *
1138 elf_i386_link_hash_newfunc (struct bfd_hash_entry *entry,
1139 struct bfd_hash_table *table,
1142 /* Allocate the structure if it has not already been allocated by a
1146 entry = (struct bfd_hash_entry *)
1147 bfd_hash_allocate (table, sizeof (struct elf_i386_link_hash_entry));
1152 /* Call the allocation method of the superclass. */
1153 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
1156 struct elf_i386_link_hash_entry *eh;
1158 eh = (struct elf_i386_link_hash_entry *) entry;
1159 eh->dyn_relocs = NULL;
1160 eh->tls_type = GOT_UNKNOWN;
1162 eh->has_got_reloc = 0;
1163 eh->has_non_got_reloc = 0;
1164 eh->no_finish_dynamic_symbol = 0;
1165 eh->tls_get_addr = 0;
1166 eh->func_pointer_refcount = 0;
1167 eh->plt_got.offset = (bfd_vma) -1;
1168 eh->tlsdesc_got = (bfd_vma) -1;
1174 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1175 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1176 as global symbol. We reuse indx and dynstr_index for local symbol
1177 hash since they aren't used by global symbols in this backend. */
1180 elf_i386_local_htab_hash (const void *ptr)
1182 struct elf_link_hash_entry *h
1183 = (struct elf_link_hash_entry *) ptr;
1184 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
1187 /* Compare local hash entries. */
1190 elf_i386_local_htab_eq (const void *ptr1, const void *ptr2)
1192 struct elf_link_hash_entry *h1
1193 = (struct elf_link_hash_entry *) ptr1;
1194 struct elf_link_hash_entry *h2
1195 = (struct elf_link_hash_entry *) ptr2;
1197 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
1200 /* Find and/or create a hash entry for local symbol. */
1202 static struct elf_link_hash_entry *
1203 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table *htab,
1204 bfd *abfd, const Elf_Internal_Rela *rel,
1207 struct elf_i386_link_hash_entry e, *ret;
1208 asection *sec = abfd->sections;
1209 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
1210 ELF32_R_SYM (rel->r_info));
1213 e.elf.indx = sec->id;
1214 e.elf.dynstr_index = ELF32_R_SYM (rel->r_info);
1215 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
1216 create ? INSERT : NO_INSERT);
1223 ret = (struct elf_i386_link_hash_entry *) *slot;
1227 ret = (struct elf_i386_link_hash_entry *)
1228 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
1229 sizeof (struct elf_i386_link_hash_entry));
1232 memset (ret, 0, sizeof (*ret));
1233 ret->elf.indx = sec->id;
1234 ret->elf.dynstr_index = ELF32_R_SYM (rel->r_info);
1235 ret->elf.dynindx = -1;
1236 ret->func_pointer_refcount = 0;
1237 ret->plt_got.offset = (bfd_vma) -1;
1243 /* Destroy an i386 ELF linker hash table. */
1246 elf_i386_link_hash_table_free (bfd *obfd)
1248 struct elf_i386_link_hash_table *htab
1249 = (struct elf_i386_link_hash_table *) obfd->link.hash;
1251 if (htab->loc_hash_table)
1252 htab_delete (htab->loc_hash_table);
1253 if (htab->loc_hash_memory)
1254 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
1255 _bfd_elf_link_hash_table_free (obfd);
1258 /* Create an i386 ELF linker hash table. */
1260 static struct bfd_link_hash_table *
1261 elf_i386_link_hash_table_create (bfd *abfd)
1263 struct elf_i386_link_hash_table *ret;
1264 bfd_size_type amt = sizeof (struct elf_i386_link_hash_table);
1266 ret = (struct elf_i386_link_hash_table *) bfd_zmalloc (amt);
1270 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1271 elf_i386_link_hash_newfunc,
1272 sizeof (struct elf_i386_link_hash_entry),
1279 ret->loc_hash_table = htab_try_create (1024,
1280 elf_i386_local_htab_hash,
1281 elf_i386_local_htab_eq,
1283 ret->loc_hash_memory = objalloc_create ();
1284 if (!ret->loc_hash_table || !ret->loc_hash_memory)
1286 elf_i386_link_hash_table_free (abfd);
1289 ret->elf.root.hash_table_free = elf_i386_link_hash_table_free;
1291 return &ret->elf.root;
1294 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1297 elf_i386_copy_indirect_symbol (struct bfd_link_info *info,
1298 struct elf_link_hash_entry *dir,
1299 struct elf_link_hash_entry *ind)
1301 struct elf_i386_link_hash_entry *edir, *eind;
1303 edir = (struct elf_i386_link_hash_entry *) dir;
1304 eind = (struct elf_i386_link_hash_entry *) ind;
1306 if (eind->dyn_relocs != NULL)
1308 if (edir->dyn_relocs != NULL)
1310 struct elf_dyn_relocs **pp;
1311 struct elf_dyn_relocs *p;
1313 /* Add reloc counts against the indirect sym to the direct sym
1314 list. Merge any entries against the same section. */
1315 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1317 struct elf_dyn_relocs *q;
1319 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1320 if (q->sec == p->sec)
1322 q->pc_count += p->pc_count;
1323 q->count += p->count;
1330 *pp = edir->dyn_relocs;
1333 edir->dyn_relocs = eind->dyn_relocs;
1334 eind->dyn_relocs = NULL;
1337 if (ind->root.type == bfd_link_hash_indirect
1338 && dir->got.refcount <= 0)
1340 edir->tls_type = eind->tls_type;
1341 eind->tls_type = GOT_UNKNOWN;
1344 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1345 generate a R_386_COPY reloc. */
1346 edir->gotoff_ref |= eind->gotoff_ref;
1348 edir->has_got_reloc |= eind->has_got_reloc;
1349 edir->has_non_got_reloc |= eind->has_non_got_reloc;
1351 if (ELIMINATE_COPY_RELOCS
1352 && ind->root.type != bfd_link_hash_indirect
1353 && dir->dynamic_adjusted)
1355 /* If called to transfer flags for a weakdef during processing
1356 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1357 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1358 if (dir->versioned != versioned_hidden)
1359 dir->ref_dynamic |= ind->ref_dynamic;
1360 dir->ref_regular |= ind->ref_regular;
1361 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
1362 dir->needs_plt |= ind->needs_plt;
1363 dir->pointer_equality_needed |= ind->pointer_equality_needed;
1367 if (eind->func_pointer_refcount > 0)
1369 edir->func_pointer_refcount += eind->func_pointer_refcount;
1370 eind->func_pointer_refcount = 0;
1373 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1377 /* Return TRUE if the TLS access code sequence support transition
1381 elf_i386_check_tls_transition (asection *sec,
1383 Elf_Internal_Shdr *symtab_hdr,
1384 struct elf_link_hash_entry **sym_hashes,
1385 unsigned int r_type,
1386 const Elf_Internal_Rela *rel,
1387 const Elf_Internal_Rela *relend)
1389 unsigned int val, type, reg;
1390 unsigned long r_symndx;
1391 struct elf_link_hash_entry *h;
1394 bfd_boolean indirect_call;
1396 offset = rel->r_offset;
1401 if (offset < 2 || (rel + 1) >= relend)
1404 indirect_call = FALSE;
1405 call = contents + offset + 4;
1408 if (r_type == R_386_TLS_GD)
1410 /* Check transition from GD access model. Only
1411 leal foo@tlsgd(,%ebx,1), %eax
1412 call ___tls_get_addr@PLT
1414 leal foo@tlsgd(%ebx) %eax
1415 call ___tls_get_addr@PLT
1418 leal foo@tlsgd(%reg), %eax
1419 call *___tls_get_addr@GOT(%reg)
1420 which may be converted to
1421 addr32 call ___tls_get_addr
1422 can transit to different access model. */
1423 if ((offset + 10) > sec->size
1424 || (type != 0x8d && type != 0x04))
1429 /* leal foo@tlsgd(,%ebx,1), %eax
1430 call ___tls_get_addr@PLT */
1434 if (*(call - 7) != 0x8d
1442 leal foo@tlsgd(%ebx), %eax
1443 call ___tls_get_addr@PLT
1446 leal foo@tlsgd(%reg), %eax
1447 call *___tls_get_addr@GOT(%reg)
1448 which may be converted to
1449 addr32 call ___tls_get_addr
1451 %eax can't be used as the GOT base register since it
1452 is used to pass parameter to ___tls_get_addr. */
1454 if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0)
1457 indirect_call = call[0] == 0xff;
1458 if (!(reg == 3 && call[0] == 0xe8 && call[5] == 0x90)
1459 && !(call[0] == 0x67 && call[1] == 0xe8)
1461 && (call[1] & 0xf8) == 0x90
1462 && (call[1] & 0x7) == reg))
1468 /* Check transition from LD access model. Only
1469 leal foo@tlsldm(%ebx), %eax
1470 call ___tls_get_addr@PLT
1472 leal foo@tlsldm(%reg), %eax
1473 call *___tls_get_addr@GOT(%reg)
1474 which may be converted to
1475 addr32 call ___tls_get_addr
1476 can transit to different access model. */
1477 if (type != 0x8d || (offset + 9) > sec->size)
1480 /* %eax can't be used as the GOT base register since it is
1481 used to pass parameter to ___tls_get_addr. */
1483 if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0)
1486 indirect_call = call[0] == 0xff;
1487 if (!(reg == 3 && call[0] == 0xe8)
1488 && !(call[0] == 0x67 && call[1] == 0xe8)
1490 && (call[1] & 0xf8) == 0x90
1491 && (call[1] & 0x7) == reg))
1495 r_symndx = ELF32_R_SYM (rel[1].r_info);
1496 if (r_symndx < symtab_hdr->sh_info)
1499 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1501 || !((struct elf_i386_link_hash_entry *) h)->tls_get_addr)
1503 else if (indirect_call)
1504 return (ELF32_R_TYPE (rel[1].r_info) == R_386_GOT32X);
1506 return (ELF32_R_TYPE (rel[1].r_info) == R_386_PC32
1507 || ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
1510 /* Check transition from IE access model:
1511 movl foo@indntpoff(%rip), %eax
1512 movl foo@indntpoff(%rip), %reg
1513 addl foo@indntpoff(%rip), %reg
1516 if (offset < 1 || (offset + 4) > sec->size)
1519 /* Check "movl foo@tpoff(%rip), %eax" first. */
1520 val = bfd_get_8 (abfd, contents + offset - 1);
1527 /* Check movl|addl foo@tpoff(%rip), %reg. */
1528 type = bfd_get_8 (abfd, contents + offset - 2);
1529 return ((type == 0x8b || type == 0x03)
1530 && (val & 0xc7) == 0x05);
1532 case R_386_TLS_GOTIE:
1533 case R_386_TLS_IE_32:
1534 /* Check transition from {IE_32,GOTIE} access model:
1535 subl foo@{tpoff,gontoff}(%reg1), %reg2
1536 movl foo@{tpoff,gontoff}(%reg1), %reg2
1537 addl foo@{tpoff,gontoff}(%reg1), %reg2
1540 if (offset < 2 || (offset + 4) > sec->size)
1543 val = bfd_get_8 (abfd, contents + offset - 1);
1544 if ((val & 0xc0) != 0x80 || (val & 7) == 4)
1547 type = bfd_get_8 (abfd, contents + offset - 2);
1548 return type == 0x8b || type == 0x2b || type == 0x03;
1550 case R_386_TLS_GOTDESC:
1551 /* Check transition from GDesc access model:
1552 leal x@tlsdesc(%ebx), %eax
1554 Make sure it's a leal adding ebx to a 32-bit offset
1555 into any register, although it's probably almost always
1558 if (offset < 2 || (offset + 4) > sec->size)
1561 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1564 val = bfd_get_8 (abfd, contents + offset - 1);
1565 return (val & 0xc7) == 0x83;
1567 case R_386_TLS_DESC_CALL:
1568 /* Check transition from GDesc access model:
1569 call *x@tlsdesc(%eax)
1571 if (offset + 2 <= sec->size)
1573 /* Make sure that it's a call *x@tlsdesc(%eax). */
1574 call = contents + offset;
1575 return call[0] == 0xff && call[1] == 0x10;
1585 /* Return TRUE if the TLS access transition is OK or no transition
1586 will be performed. Update R_TYPE if there is a transition. */
1589 elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd,
1590 asection *sec, bfd_byte *contents,
1591 Elf_Internal_Shdr *symtab_hdr,
1592 struct elf_link_hash_entry **sym_hashes,
1593 unsigned int *r_type, int tls_type,
1594 const Elf_Internal_Rela *rel,
1595 const Elf_Internal_Rela *relend,
1596 struct elf_link_hash_entry *h,
1597 unsigned long r_symndx,
1598 bfd_boolean from_relocate_section)
1600 unsigned int from_type = *r_type;
1601 unsigned int to_type = from_type;
1602 bfd_boolean check = TRUE;
1604 /* Skip TLS transition for functions. */
1606 && (h->type == STT_FUNC
1607 || h->type == STT_GNU_IFUNC))
1613 case R_386_TLS_GOTDESC:
1614 case R_386_TLS_DESC_CALL:
1615 case R_386_TLS_IE_32:
1617 case R_386_TLS_GOTIE:
1618 if (bfd_link_executable (info))
1621 to_type = R_386_TLS_LE_32;
1622 else if (from_type != R_386_TLS_IE
1623 && from_type != R_386_TLS_GOTIE)
1624 to_type = R_386_TLS_IE_32;
1627 /* When we are called from elf_i386_relocate_section, there may
1628 be additional transitions based on TLS_TYPE. */
1629 if (from_relocate_section)
1631 unsigned int new_to_type = to_type;
1633 if (bfd_link_executable (info)
1636 && (tls_type & GOT_TLS_IE))
1637 new_to_type = R_386_TLS_LE_32;
1639 if (to_type == R_386_TLS_GD
1640 || to_type == R_386_TLS_GOTDESC
1641 || to_type == R_386_TLS_DESC_CALL)
1643 if (tls_type == GOT_TLS_IE_POS)
1644 new_to_type = R_386_TLS_GOTIE;
1645 else if (tls_type & GOT_TLS_IE)
1646 new_to_type = R_386_TLS_IE_32;
1649 /* We checked the transition before when we were called from
1650 elf_i386_check_relocs. We only want to check the new
1651 transition which hasn't been checked before. */
1652 check = new_to_type != to_type && from_type == to_type;
1653 to_type = new_to_type;
1659 if (bfd_link_executable (info))
1660 to_type = R_386_TLS_LE_32;
1667 /* Return TRUE if there is no transition. */
1668 if (from_type == to_type)
1671 /* Check if the transition can be performed. */
1673 && ! elf_i386_check_tls_transition (sec, contents,
1674 symtab_hdr, sym_hashes,
1675 from_type, rel, relend))
1677 reloc_howto_type *from, *to;
1680 from = elf_i386_rtype_to_howto (abfd, from_type);
1681 to = elf_i386_rtype_to_howto (abfd, to_type);
1684 name = h->root.root.string;
1687 struct elf_i386_link_hash_table *htab;
1689 htab = elf_i386_hash_table (info);
1694 Elf_Internal_Sym *isym;
1696 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1698 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1703 /* xgettext:c-format */
1704 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1705 "in section `%A' failed"),
1706 abfd, from->name, to->name, name,
1707 rel->r_offset, sec);
1708 bfd_set_error (bfd_error_bad_value);
1716 /* With the local symbol, foo, we convert
1717 mov foo@GOT[(%reg1)], %reg2
1719 lea foo[@GOTOFF(%reg1)], %reg2
1721 call/jmp *foo@GOT[(%reg)]
1723 nop call foo/jmp foo nop
1724 When PIC is false, convert
1725 test %reg1, foo@GOT[(%reg2)]
1729 binop foo@GOT[(%reg1)], %reg2
1732 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1737 elf_i386_convert_load_reloc (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
1739 Elf_Internal_Rela *irel,
1740 struct elf_link_hash_entry *h,
1741 bfd_boolean *converted,
1742 struct bfd_link_info *link_info)
1744 struct elf_i386_link_hash_table *htab;
1745 unsigned int opcode;
1747 bfd_boolean baseless;
1748 Elf_Internal_Sym *isym;
1749 unsigned int addend;
1753 bfd_boolean to_reloc_32;
1754 unsigned int r_type;
1755 unsigned int r_symndx;
1756 bfd_vma roff = irel->r_offset;
1761 /* Addend for R_386_GOT32X relocations must be 0. */
1762 addend = bfd_get_32 (abfd, contents + roff);
1766 htab = elf_i386_hash_table (link_info);
1767 is_pic = bfd_link_pic (link_info);
1769 r_type = ELF32_R_TYPE (irel->r_info);
1770 r_symndx = ELF32_R_SYM (irel->r_info);
1772 modrm = bfd_get_8 (abfd, contents + roff - 1);
1773 baseless = (modrm & 0xc7) == 0x5;
1775 if (baseless && is_pic)
1777 /* For PIC, disallow R_386_GOT32X without a base register
1778 since we don't know what the GOT base is. */
1783 isym = bfd_sym_from_r_symndx (&htab->sym_cache, abfd,
1785 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1788 name = h->root.root.string;
1791 /* xgettext:c-format */
1792 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1793 " register can not be used when making a shared object"),
1798 opcode = bfd_get_8 (abfd, contents + roff - 2);
1800 /* Convert to R_386_32 if PIC is false or there is no base
1802 to_reloc_32 = !is_pic || baseless;
1804 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1808 if (opcode == 0x0ff)
1809 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1810 goto convert_branch;
1812 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1813 "test %reg1, foo@GOT(%reg2)" and
1814 "binop foo@GOT[(%reg1)], %reg2". */
1818 /* Undefined weak symbol is only bound locally in executable
1819 and its reference is resolved as 0. */
1820 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info, TRUE,
1821 elf_i386_hash_entry (h)))
1825 /* No direct branch to 0 for PIC. */
1829 goto convert_branch;
1833 /* We can convert load of address 0 to R_386_32. */
1841 /* We have "call/jmp *foo@GOT[(%reg)]". */
1842 if ((h->root.type == bfd_link_hash_defined
1843 || h->root.type == bfd_link_hash_defweak)
1844 && SYMBOL_REFERENCES_LOCAL (link_info, h))
1846 /* The function is locally defined. */
1848 /* Convert R_386_GOT32X to R_386_PC32. */
1849 if (modrm == 0x15 || (modrm & 0xf8) == 0x90)
1851 struct elf_i386_link_hash_entry *eh
1852 = (struct elf_i386_link_hash_entry *) h;
1854 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1857 /* To support TLS optimization, always use addr32 prefix
1858 for "call *___tls_get_addr@GOT(%reg)". */
1859 if (eh && eh->tls_get_addr)
1862 nop_offset = irel->r_offset - 2;
1866 nop = link_info->call_nop_byte;
1867 if (link_info->call_nop_as_suffix)
1869 nop_offset = roff + 3;
1870 irel->r_offset -= 1;
1873 nop_offset = roff - 2;
1878 /* Convert to "jmp foo nop". */
1881 nop_offset = roff + 3;
1882 irel->r_offset -= 1;
1885 bfd_put_8 (abfd, nop, contents + nop_offset);
1886 bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1);
1887 /* When converting to PC-relative relocation, we
1888 need to adjust addend by -4. */
1889 bfd_put_32 (abfd, -4, contents + irel->r_offset);
1890 irel->r_info = ELF32_R_INFO (r_symndx, R_386_PC32);
1897 /* We have "mov foo@GOT[(%re1g)], %reg2",
1898 "test %reg1, foo@GOT(%reg2)" and
1899 "binop foo@GOT[(%reg1)], %reg2".
1901 Avoid optimizing _DYNAMIC since ld.so may use its
1902 link-time address. */
1903 if (h == htab->elf.hdynamic)
1906 /* def_regular is set by an assignment in a linker script in
1907 bfd_elf_record_link_assignment. start_stop is set on
1908 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1911 || h->root.type == bfd_link_hash_defined
1912 || h->root.type == bfd_link_hash_defweak)
1913 && SYMBOL_REFERENCES_LOCAL (link_info, h)))
1920 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1921 "mov $foo, %reg2" with R_386_32. */
1923 modrm = 0xc0 | (modrm & 0x38) >> 3;
1924 bfd_put_8 (abfd, modrm, contents + roff - 1);
1929 /* Convert "mov foo@GOT(%reg1), %reg2" to
1930 "lea foo@GOTOFF(%reg1), %reg2". */
1931 r_type = R_386_GOTOFF;
1937 /* Only R_386_32 is supported. */
1943 /* Convert "test %reg1, foo@GOT(%reg2)" to
1944 "test $foo, %reg1". */
1945 modrm = 0xc0 | (modrm & 0x38) >> 3;
1950 /* Convert "binop foo@GOT(%reg1), %reg2" to
1951 "binop $foo, %reg2". */
1953 | (modrm & 0x38) >> 3
1957 bfd_put_8 (abfd, modrm, contents + roff - 1);
1961 bfd_put_8 (abfd, opcode, contents + roff - 2);
1962 irel->r_info = ELF32_R_INFO (r_symndx, r_type);
1971 /* Rename some of the generic section flags to better document how they
1973 #define need_convert_load sec_flg0
1974 #define check_relocs_failed sec_flg1
1976 /* Look through the relocs for a section during the first phase, and
1977 calculate needed space in the global offset table, procedure linkage
1978 table, and dynamic reloc sections. */
1981 elf_i386_check_relocs (bfd *abfd,
1982 struct bfd_link_info *info,
1984 const Elf_Internal_Rela *relocs)
1986 struct elf_i386_link_hash_table *htab;
1987 Elf_Internal_Shdr *symtab_hdr;
1988 struct elf_link_hash_entry **sym_hashes;
1989 const Elf_Internal_Rela *rel;
1990 const Elf_Internal_Rela *rel_end;
1994 if (bfd_link_relocatable (info))
1997 /* Don't do anything special with non-loaded, non-alloced sections.
1998 In particular, any relocs in such sections should not affect GOT
1999 and PLT reference counting (ie. we don't allow them to create GOT
2000 or PLT entries), there's no possibility or desire to optimize TLS
2001 relocs, and there's not much point in propagating relocs to shared
2002 libs that the dynamic linker won't relocate. */
2003 if ((sec->flags & SEC_ALLOC) == 0)
2006 BFD_ASSERT (is_i386_elf (abfd));
2008 htab = elf_i386_hash_table (info);
2011 sec->check_relocs_failed = 1;
2015 /* Get the section contents. */
2016 if (elf_section_data (sec)->this_hdr.contents != NULL)
2017 contents = elf_section_data (sec)->this_hdr.contents;
2018 else if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2020 sec->check_relocs_failed = 1;
2024 symtab_hdr = &elf_symtab_hdr (abfd);
2025 sym_hashes = elf_sym_hashes (abfd);
2029 rel_end = relocs + sec->reloc_count;
2030 for (rel = relocs; rel < rel_end; rel++)
2032 unsigned int r_type;
2033 unsigned int r_symndx;
2034 struct elf_link_hash_entry *h;
2035 struct elf_i386_link_hash_entry *eh;
2036 Elf_Internal_Sym *isym;
2038 bfd_boolean size_reloc;
2040 r_symndx = ELF32_R_SYM (rel->r_info);
2041 r_type = ELF32_R_TYPE (rel->r_info);
2043 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
2045 /* xgettext:c-format */
2046 _bfd_error_handler (_("%B: bad symbol index: %d"),
2051 if (r_symndx < symtab_hdr->sh_info)
2053 /* A local symbol. */
2054 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2059 /* Check relocation against local STT_GNU_IFUNC symbol. */
2060 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
2062 h = elf_i386_get_local_sym_hash (htab, abfd, rel, TRUE);
2066 /* Fake a STT_GNU_IFUNC symbol. */
2067 h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr,
2069 h->type = STT_GNU_IFUNC;
2072 h->forced_local = 1;
2073 h->root.type = bfd_link_hash_defined;
2081 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2082 while (h->root.type == bfd_link_hash_indirect
2083 || h->root.type == bfd_link_hash_warning)
2084 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2087 eh = (struct elf_i386_link_hash_entry *) h;
2090 if (r_type == R_386_GOTOFF)
2093 /* It is referenced by a non-shared object. */
2095 h->root.non_ir_ref_regular = 1;
2097 if (h->type == STT_GNU_IFUNC)
2098 elf_tdata (info->output_bfd)->has_gnu_symbols
2099 |= elf_gnu_symbol_ifunc;
2102 if (! elf_i386_tls_transition (info, abfd, sec, contents,
2103 symtab_hdr, sym_hashes,
2104 &r_type, GOT_UNKNOWN,
2105 rel, rel_end, h, r_symndx, FALSE))
2111 htab->tls_ldm_got.refcount += 1;
2115 /* This symbol requires a procedure linkage table entry. We
2116 actually build the entry in adjust_dynamic_symbol,
2117 because this might be a case of linking PIC code which is
2118 never referenced by a dynamic object, in which case we
2119 don't need to generate a procedure linkage table entry
2122 /* If this is a local symbol, we resolve it directly without
2123 creating a procedure linkage table entry. */
2127 eh->has_got_reloc = 1;
2129 h->plt.refcount += 1;
2136 case R_386_TLS_IE_32:
2138 case R_386_TLS_GOTIE:
2139 if (!bfd_link_executable (info))
2140 info->flags |= DF_STATIC_TLS;
2146 case R_386_TLS_GOTDESC:
2147 case R_386_TLS_DESC_CALL:
2148 /* This symbol requires a global offset table entry. */
2150 int tls_type, old_tls_type;
2157 tls_type = GOT_NORMAL;
2159 case R_386_TLS_GD: tls_type = GOT_TLS_GD; break;
2160 case R_386_TLS_GOTDESC:
2161 case R_386_TLS_DESC_CALL:
2162 tls_type = GOT_TLS_GDESC; break;
2163 case R_386_TLS_IE_32:
2164 if (ELF32_R_TYPE (rel->r_info) == r_type)
2165 tls_type = GOT_TLS_IE_NEG;
2167 /* If this is a GD->IE transition, we may use either of
2168 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
2169 tls_type = GOT_TLS_IE;
2172 case R_386_TLS_GOTIE:
2173 tls_type = GOT_TLS_IE_POS; break;
2178 h->got.refcount += 1;
2179 old_tls_type = elf_i386_hash_entry(h)->tls_type;
2183 bfd_signed_vma *local_got_refcounts;
2185 /* This is a global offset table entry for a local symbol. */
2186 local_got_refcounts = elf_local_got_refcounts (abfd);
2187 if (local_got_refcounts == NULL)
2191 size = symtab_hdr->sh_info;
2192 size *= (sizeof (bfd_signed_vma)
2193 + sizeof (bfd_vma) + sizeof(char));
2194 local_got_refcounts = (bfd_signed_vma *)
2195 bfd_zalloc (abfd, size);
2196 if (local_got_refcounts == NULL)
2198 elf_local_got_refcounts (abfd) = local_got_refcounts;
2199 elf_i386_local_tlsdesc_gotent (abfd)
2200 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
2201 elf_i386_local_got_tls_type (abfd)
2202 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
2204 local_got_refcounts[r_symndx] += 1;
2205 old_tls_type = elf_i386_local_got_tls_type (abfd) [r_symndx];
2208 if ((old_tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_IE))
2209 tls_type |= old_tls_type;
2210 /* If a TLS symbol is accessed using IE at least once,
2211 there is no point to use dynamic model for it. */
2212 else if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
2213 && (! GOT_TLS_GD_ANY_P (old_tls_type)
2214 || (tls_type & GOT_TLS_IE) == 0))
2216 if ((old_tls_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (tls_type))
2217 tls_type = old_tls_type;
2218 else if (GOT_TLS_GD_ANY_P (old_tls_type)
2219 && GOT_TLS_GD_ANY_P (tls_type))
2220 tls_type |= old_tls_type;
2224 name = h->root.root.string;
2226 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
2229 /* xgettext:c-format */
2230 (_("%B: `%s' accessed both as normal and "
2231 "thread local symbol"),
2233 bfd_set_error (bfd_error_bad_value);
2238 if (old_tls_type != tls_type)
2241 elf_i386_hash_entry (h)->tls_type = tls_type;
2243 elf_i386_local_got_tls_type (abfd) [r_symndx] = tls_type;
2251 if (r_type != R_386_TLS_IE)
2254 eh->has_got_reloc = 1;
2259 case R_386_TLS_LE_32:
2262 eh->has_got_reloc = 1;
2263 if (bfd_link_executable (info))
2265 info->flags |= DF_STATIC_TLS;
2270 if (eh != NULL && (sec->flags & SEC_CODE) != 0)
2271 eh->has_non_got_reloc = 1;
2273 /* We are called after all symbols have been resolved. Only
2274 relocation against STT_GNU_IFUNC symbol must go through
2277 && (bfd_link_executable (info)
2278 || h->type == STT_GNU_IFUNC))
2280 /* If this reloc is in a read-only section, we might
2281 need a copy reloc. We can't check reliably at this
2282 stage whether the section is read-only, as input
2283 sections have not yet been mapped to output sections.
2284 Tentatively set the flag for now, and correct in
2285 adjust_dynamic_symbol. */
2288 /* We may need a .plt entry if the symbol is a function
2289 defined in a shared lib or is a STT_GNU_IFUNC function
2290 referenced from the code or read-only section. */
2292 || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
2293 h->plt.refcount += 1;
2295 if (r_type == R_386_PC32)
2297 /* Since something like ".long foo - ." may be used
2298 as pointer, make sure that PLT is used if foo is
2299 a function defined in a shared library. */
2300 if ((sec->flags & SEC_CODE) == 0)
2301 h->pointer_equality_needed = 1;
2302 else if (h->type == STT_GNU_IFUNC
2303 && bfd_link_pic (info))
2306 /* xgettext:c-format */
2307 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
2308 abfd, h->root.root.string);
2309 bfd_set_error (bfd_error_bad_value);
2315 h->pointer_equality_needed = 1;
2316 /* R_386_32 can be resolved at run-time. */
2317 if (r_type == R_386_32
2318 && (sec->flags & SEC_READONLY) == 0)
2319 eh->func_pointer_refcount += 1;
2325 /* If we are creating a shared library, and this is a reloc
2326 against a global symbol, or a non PC relative reloc
2327 against a local symbol, then we need to copy the reloc
2328 into the shared library. However, if we are linking with
2329 -Bsymbolic, we do not need to copy a reloc against a
2330 global symbol which is defined in an object we are
2331 including in the link (i.e., DEF_REGULAR is set). At
2332 this point we have not seen all the input files, so it is
2333 possible that DEF_REGULAR is not set now but will be set
2334 later (it is never cleared). In case of a weak definition,
2335 DEF_REGULAR may be cleared later by a strong definition in
2336 a shared library. We account for that possibility below by
2337 storing information in the relocs_copied field of the hash
2338 table entry. A similar situation occurs when creating
2339 shared libraries and symbol visibility changes render the
2342 If on the other hand, we are creating an executable, we
2343 may need to keep relocations for symbols satisfied by a
2344 dynamic library if we manage to avoid copy relocs for the
2347 Generate dynamic pointer relocation against STT_GNU_IFUNC
2348 symbol in the non-code section. */
2349 if ((bfd_link_pic (info)
2350 && (r_type != R_386_PC32
2352 && (! (bfd_link_pie (info)
2353 || SYMBOLIC_BIND (info, h))
2354 || h->root.type == bfd_link_hash_defweak
2355 || !h->def_regular))))
2357 && h->type == STT_GNU_IFUNC
2358 && r_type == R_386_32
2359 && (sec->flags & SEC_CODE) == 0)
2360 || (ELIMINATE_COPY_RELOCS
2361 && !bfd_link_pic (info)
2363 && (h->root.type == bfd_link_hash_defweak
2364 || !h->def_regular)))
2366 struct elf_dyn_relocs *p;
2367 struct elf_dyn_relocs **head;
2369 /* We must copy these reloc types into the output file.
2370 Create a reloc section in dynobj and make room for
2374 sreloc = _bfd_elf_make_dynamic_reloc_section
2375 (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ FALSE);
2381 /* If this is a global symbol, we count the number of
2382 relocations we need for this symbol. */
2385 head = &eh->dyn_relocs;
2389 /* Track dynamic relocs needed for local syms too.
2390 We really need local syms available to do this
2395 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2400 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2404 vpp = &elf_section_data (s)->local_dynrel;
2405 head = (struct elf_dyn_relocs **)vpp;
2409 if (p == NULL || p->sec != sec)
2411 bfd_size_type amt = sizeof *p;
2412 p = (struct elf_dyn_relocs *) bfd_alloc (htab->elf.dynobj,
2424 /* Count size relocation as PC-relative relocation. */
2425 if (r_type == R_386_PC32 || size_reloc)
2430 /* This relocation describes the C++ object vtable hierarchy.
2431 Reconstruct it for later use during GC. */
2432 case R_386_GNU_VTINHERIT:
2433 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2437 /* This relocation describes which C++ vtable entries are actually
2438 used. Record for later use during GC. */
2439 case R_386_GNU_VTENTRY:
2440 BFD_ASSERT (h != NULL);
2442 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
2450 if (r_type == R_386_GOT32X
2451 && (h == NULL || h->type != STT_GNU_IFUNC))
2452 sec->need_convert_load = 1;
2455 if (elf_section_data (sec)->this_hdr.contents != contents)
2457 if (!info->keep_memory)
2461 /* Cache the section contents for elf_link_input_bfd. */
2462 elf_section_data (sec)->this_hdr.contents = contents;
2469 if (elf_section_data (sec)->this_hdr.contents != contents)
2471 sec->check_relocs_failed = 1;
2475 /* Return the section that should be marked against GC for a given
2479 elf_i386_gc_mark_hook (asection *sec,
2480 struct bfd_link_info *info,
2481 Elf_Internal_Rela *rel,
2482 struct elf_link_hash_entry *h,
2483 Elf_Internal_Sym *sym)
2486 switch (ELF32_R_TYPE (rel->r_info))
2488 case R_386_GNU_VTINHERIT:
2489 case R_386_GNU_VTENTRY:
2493 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2496 /* Remove undefined weak symbol from the dynamic symbol table if it
2497 is resolved to 0. */
2500 elf_i386_fixup_symbol (struct bfd_link_info *info,
2501 struct elf_link_hash_entry *h)
2503 if (h->dynindx != -1
2504 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
2505 elf_i386_hash_entry (h)->has_got_reloc,
2506 elf_i386_hash_entry (h)))
2509 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
2515 /* Adjust a symbol defined by a dynamic object and referenced by a
2516 regular object. The current definition is in some section of the
2517 dynamic object, but we're not including those sections. We have to
2518 change the definition to something the rest of the link can
2522 elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
2523 struct elf_link_hash_entry *h)
2525 struct elf_i386_link_hash_table *htab;
2527 struct elf_i386_link_hash_entry *eh;
2528 struct elf_dyn_relocs *p;
2530 /* STT_GNU_IFUNC symbol must go through PLT. */
2531 if (h->type == STT_GNU_IFUNC)
2533 /* All local STT_GNU_IFUNC references must be treate as local
2534 calls via local PLT. */
2536 && SYMBOL_CALLS_LOCAL (info, h))
2538 bfd_size_type pc_count = 0, count = 0;
2539 struct elf_dyn_relocs **pp;
2541 eh = (struct elf_i386_link_hash_entry *) h;
2542 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2544 pc_count += p->pc_count;
2545 p->count -= p->pc_count;
2554 if (pc_count || count)
2559 /* Increment PLT reference count only for PC-relative
2562 if (h->plt.refcount <= 0)
2563 h->plt.refcount = 1;
2565 h->plt.refcount += 1;
2570 if (h->plt.refcount <= 0)
2572 h->plt.offset = (bfd_vma) -1;
2578 /* If this is a function, put it in the procedure linkage table. We
2579 will fill in the contents of the procedure linkage table later,
2580 when we know the address of the .got section. */
2581 if (h->type == STT_FUNC
2584 if (h->plt.refcount <= 0
2585 || SYMBOL_CALLS_LOCAL (info, h)
2586 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2587 && h->root.type == bfd_link_hash_undefweak))
2589 /* This case can occur if we saw a PLT32 reloc in an input
2590 file, but the symbol was never referred to by a dynamic
2591 object, or if all references were garbage collected. In
2592 such a case, we don't actually need to build a procedure
2593 linkage table, and we can just do a PC32 reloc instead. */
2594 h->plt.offset = (bfd_vma) -1;
2601 /* It's possible that we incorrectly decided a .plt reloc was
2602 needed for an R_386_PC32 reloc to a non-function sym in
2603 check_relocs. We can't decide accurately between function and
2604 non-function syms in check-relocs; Objects loaded later in
2605 the link may change h->type. So fix it now. */
2606 h->plt.offset = (bfd_vma) -1;
2608 eh = (struct elf_i386_link_hash_entry *) h;
2610 /* If this is a weak symbol, and there is a real definition, the
2611 processor independent code will have arranged for us to see the
2612 real definition first, and we can just use the same value. */
2613 if (h->u.weakdef != NULL)
2615 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2616 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2617 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2618 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2619 if (ELIMINATE_COPY_RELOCS
2620 || info->nocopyreloc
2621 || SYMBOL_NO_COPYRELOC (info, eh))
2622 h->non_got_ref = h->u.weakdef->non_got_ref;
2626 /* This is a reference to a symbol defined by a dynamic object which
2627 is not a function. */
2629 /* If we are creating a shared library, we must presume that the
2630 only references to the symbol are via the global offset table.
2631 For such cases we need not do anything here; the relocations will
2632 be handled correctly by relocate_section. */
2633 if (!bfd_link_executable (info))
2636 /* If there are no references to this symbol that do not use the
2637 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2639 if (!h->non_got_ref && !eh->gotoff_ref)
2642 /* If -z nocopyreloc was given, we won't generate them either. */
2643 if (info->nocopyreloc || SYMBOL_NO_COPYRELOC (info, eh))
2649 htab = elf_i386_hash_table (info);
2653 /* If there aren't any dynamic relocs in read-only sections nor
2654 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2655 avoid the copy reloc. This doesn't work on VxWorks, where we can
2656 not have dynamic relocations (other than copy and jump slot
2657 relocations) in an executable. */
2658 if (ELIMINATE_COPY_RELOCS
2660 && get_elf_i386_backend_data (info->output_bfd)->os != is_vxworks)
2662 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2664 s = p->sec->output_section;
2665 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2676 /* We must allocate the symbol in our .dynbss section, which will
2677 become part of the .bss section of the executable. There will be
2678 an entry for this symbol in the .dynsym section. The dynamic
2679 object will contain position independent code, so all references
2680 from the dynamic object to this symbol will go through the global
2681 offset table. The dynamic linker will use the .dynsym entry to
2682 determine the address it must put in the global offset table, so
2683 both the dynamic object and the regular object will refer to the
2684 same memory location for the variable. */
2686 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2687 copy the initial value out of the dynamic object and into the
2688 runtime process image. */
2689 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2691 s = htab->elf.sdynrelro;
2692 srel = htab->elf.sreldynrelro;
2696 s = htab->elf.sdynbss;
2697 srel = htab->elf.srelbss;
2699 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2701 srel->size += sizeof (Elf32_External_Rel);
2705 return _bfd_elf_adjust_dynamic_copy (info, h, s);
2708 /* Allocate space in .plt, .got and associated reloc sections for
2712 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
2714 struct bfd_link_info *info;
2715 struct elf_i386_link_hash_table *htab;
2716 struct elf_i386_link_hash_entry *eh;
2717 struct elf_dyn_relocs *p;
2718 unsigned plt_entry_size;
2719 bfd_boolean resolved_to_zero;
2720 const struct elf_i386_backend_data *bed;
2722 if (h->root.type == bfd_link_hash_indirect)
2725 eh = (struct elf_i386_link_hash_entry *) h;
2727 info = (struct bfd_link_info *) inf;
2728 htab = elf_i386_hash_table (info);
2732 bed = get_elf_i386_backend_data (info->output_bfd);
2734 plt_entry_size = htab->plt.plt_entry_size;
2736 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
2740 /* Clear the reference count of function pointer relocations if
2741 symbol isn't a normal function. */
2742 if (h->type != STT_FUNC)
2743 eh->func_pointer_refcount = 0;
2745 /* We can't use the GOT PLT if pointer equality is needed since
2746 finish_dynamic_symbol won't clear symbol value and the dynamic
2747 linker won't update the GOT slot. We will get into an infinite
2748 loop at run-time. */
2749 if (htab->plt_got != NULL
2750 && h->type != STT_GNU_IFUNC
2751 && !h->pointer_equality_needed
2752 && h->plt.refcount > 0
2753 && h->got.refcount > 0)
2755 /* Don't use the regular PLT if there are both GOT and GOTPLT
2757 h->plt.offset = (bfd_vma) -1;
2759 /* Use the GOT PLT. */
2760 eh->plt_got.refcount = 1;
2763 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2764 here if it is defined and referenced in a non-shared object. */
2765 if (h->type == STT_GNU_IFUNC
2768 if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h, &eh->dyn_relocs,
2769 &htab->readonly_dynrelocs_against_ifunc,
2771 (htab->plt.has_plt0 *
2775 asection *s = htab->plt_second;
2776 if (h->plt.offset != (bfd_vma) -1 && s != NULL)
2778 /* Use the second PLT section if it is created. */
2779 eh->plt_second.offset = s->size;
2781 /* Make room for this entry in the second PLT section. */
2782 s->size += htab->non_lazy_plt->plt_entry_size;
2790 /* Don't create the PLT entry if there are only function pointer
2791 relocations which can be resolved at run-time. */
2792 else if (htab->elf.dynamic_sections_created
2793 && (h->plt.refcount > eh->func_pointer_refcount
2794 || eh->plt_got.refcount > 0))
2796 bfd_boolean use_plt_got = eh->plt_got.refcount > 0;
2798 /* Clear the reference count of function pointer relocations
2800 eh->func_pointer_refcount = 0;
2802 /* Make sure this symbol is output as a dynamic symbol.
2803 Undefined weak syms won't yet be marked as dynamic. */
2804 if (h->dynindx == -1
2806 && !resolved_to_zero
2807 && h->root.type == bfd_link_hash_undefweak)
2809 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2813 if (bfd_link_pic (info)
2814 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2816 asection *s = htab->elf.splt;
2817 asection *second_s = htab->plt_second;
2818 asection *got_s = htab->plt_got;
2820 /* If this is the first .plt entry, make room for the special
2821 first entry. The .plt section is used by prelink to undo
2822 prelinking for dynamic relocations. */
2824 s->size = htab->plt.has_plt0 * plt_entry_size;
2827 eh->plt_got.offset = got_s->size;
2830 h->plt.offset = s->size;
2832 eh->plt_second.offset = second_s->size;
2835 /* If this symbol is not defined in a regular file, and we are
2836 not generating a shared library, then set the symbol to this
2837 location in the .plt. This is required to make function
2838 pointers compare as equal between the normal executable and
2839 the shared library. */
2840 if (! bfd_link_pic (info)
2845 /* We need to make a call to the entry of the GOT PLT
2846 instead of regular PLT entry. */
2847 h->root.u.def.section = got_s;
2848 h->root.u.def.value = eh->plt_got.offset;
2854 /* We need to make a call to the entry of the
2855 second PLT instead of regular PLT entry. */
2856 h->root.u.def.section = second_s;
2857 h->root.u.def.value = eh->plt_second.offset;
2861 h->root.u.def.section = s;
2862 h->root.u.def.value = h->plt.offset;
2867 /* Make room for this entry. */
2869 got_s->size += htab->non_lazy_plt->plt_entry_size;
2872 s->size += plt_entry_size;
2874 second_s->size += htab->non_lazy_plt->plt_entry_size;
2876 /* We also need to make an entry in the .got.plt section,
2877 which will be placed in the .got section by the linker
2879 htab->elf.sgotplt->size += 4;
2881 /* There should be no PLT relocation against resolved
2882 undefined weak symbol in executable. */
2883 if (!resolved_to_zero)
2885 /* We also need to make an entry in the .rel.plt
2887 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
2888 htab->elf.srelplt->reloc_count++;
2892 if (bed->os == is_vxworks && !bfd_link_pic (info))
2894 /* VxWorks has a second set of relocations for each PLT entry
2895 in executables. They go in a separate relocation section,
2896 which is processed by the kernel loader. */
2898 /* There are two relocations for the initial PLT entry: an
2899 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2900 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2902 if (h->plt.offset == plt_entry_size)
2903 htab->srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
2905 /* There are two extra relocations for each subsequent PLT entry:
2906 an R_386_32 relocation for the GOT entry, and an R_386_32
2907 relocation for the PLT entry. */
2909 htab->srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
2914 eh->plt_got.offset = (bfd_vma) -1;
2915 h->plt.offset = (bfd_vma) -1;
2921 eh->plt_got.offset = (bfd_vma) -1;
2922 h->plt.offset = (bfd_vma) -1;
2926 eh->tlsdesc_got = (bfd_vma) -1;
2928 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2929 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2930 if (h->got.refcount > 0
2931 && bfd_link_executable (info)
2933 && (elf_i386_hash_entry(h)->tls_type & GOT_TLS_IE))
2934 h->got.offset = (bfd_vma) -1;
2935 else if (h->got.refcount > 0)
2939 int tls_type = elf_i386_hash_entry(h)->tls_type;
2941 /* Make sure this symbol is output as a dynamic symbol.
2942 Undefined weak syms won't yet be marked as dynamic. */
2943 if (h->dynindx == -1
2945 && !resolved_to_zero
2946 && h->root.type == bfd_link_hash_undefweak)
2948 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2953 if (GOT_TLS_GDESC_P (tls_type))
2955 eh->tlsdesc_got = htab->elf.sgotplt->size
2956 - elf_i386_compute_jump_table_size (htab);
2957 htab->elf.sgotplt->size += 8;
2958 h->got.offset = (bfd_vma) -2;
2960 if (! GOT_TLS_GDESC_P (tls_type)
2961 || GOT_TLS_GD_P (tls_type))
2963 h->got.offset = s->size;
2965 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2966 if (GOT_TLS_GD_P (tls_type) || tls_type == GOT_TLS_IE_BOTH)
2969 dyn = htab->elf.dynamic_sections_created;
2970 /* R_386_TLS_IE_32 needs one dynamic relocation,
2971 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2972 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2973 need two), R_386_TLS_GD needs one if local symbol and two if
2974 global. No dynamic relocation against resolved undefined weak
2975 symbol in executable. */
2976 if (tls_type == GOT_TLS_IE_BOTH)
2977 htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel);
2978 else if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
2979 || (tls_type & GOT_TLS_IE))
2980 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
2981 else if (GOT_TLS_GD_P (tls_type))
2982 htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel);
2983 else if (! GOT_TLS_GDESC_P (tls_type)
2984 && ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2985 && !resolved_to_zero)
2986 || h->root.type != bfd_link_hash_undefweak)
2987 && (bfd_link_pic (info)
2988 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2989 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
2990 if (GOT_TLS_GDESC_P (tls_type))
2991 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
2994 h->got.offset = (bfd_vma) -1;
2996 if (eh->dyn_relocs == NULL)
2999 /* In the shared -Bsymbolic case, discard space allocated for
3000 dynamic pc-relative relocs against symbols which turn out to be
3001 defined in regular objects. For the normal shared case, discard
3002 space for pc-relative relocs that have become local due to symbol
3003 visibility changes. */
3005 if (bfd_link_pic (info))
3007 /* The only reloc that uses pc_count is R_386_PC32, which will
3008 appear on a call or on something like ".long foo - .". We
3009 want calls to protected symbols to resolve directly to the
3010 function rather than going via the plt. If people want
3011 function pointer comparisons to work as expected then they
3012 should avoid writing assembly like ".long foo - .". */
3013 if (SYMBOL_CALLS_LOCAL (info, h))
3015 struct elf_dyn_relocs **pp;
3017 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3019 p->count -= p->pc_count;
3028 if (bed->os == is_vxworks)
3030 struct elf_dyn_relocs **pp;
3031 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3033 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
3040 /* Also discard relocs on undefined weak syms with non-default
3041 visibility or in PIE. */
3042 if (eh->dyn_relocs != NULL
3043 && h->root.type == bfd_link_hash_undefweak)
3045 /* Undefined weak symbol is never bound locally in shared
3047 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3048 || resolved_to_zero)
3052 /* Keep dynamic non-GOT/non-PLT relocation so that we
3053 can branch to 0 without PLT. */
3054 struct elf_dyn_relocs **pp;
3056 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3057 if (p->pc_count == 0)
3061 /* Remove non-R_386_PC32 relocation. */
3062 p->count = p->pc_count;
3066 if (eh->dyn_relocs != NULL)
3068 /* Make sure undefined weak symbols are output
3069 as dynamic symbols in PIEs for dynamic non-GOT
3070 non-PLT reloations. */
3071 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3076 eh->dyn_relocs = NULL;
3078 else if (h->dynindx == -1
3079 && !h->forced_local)
3081 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3086 else if (ELIMINATE_COPY_RELOCS)
3088 /* For the non-shared case, discard space for relocs against
3089 symbols which turn out to need copy relocs or are not
3090 dynamic. Keep dynamic relocations for run-time function
3091 pointer initialization. */
3093 if ((!h->non_got_ref
3094 || eh->func_pointer_refcount > 0
3095 || (h->root.type == bfd_link_hash_undefweak
3096 && !resolved_to_zero))
3099 || (htab->elf.dynamic_sections_created
3100 && (h->root.type == bfd_link_hash_undefweak
3101 || h->root.type == bfd_link_hash_undefined))))
3103 /* Make sure this symbol is output as a dynamic symbol.
3104 Undefined weak syms won't yet be marked as dynamic. */
3105 if (h->dynindx == -1
3107 && !resolved_to_zero
3108 && h->root.type == bfd_link_hash_undefweak)
3110 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3114 /* If that succeeded, we know we'll be keeping all the
3116 if (h->dynindx != -1)
3120 eh->dyn_relocs = NULL;
3121 eh->func_pointer_refcount = 0;
3126 /* Finally, allocate space. */
3127 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3131 sreloc = elf_section_data (p->sec)->sreloc;
3133 BFD_ASSERT (sreloc != NULL);
3134 sreloc->size += p->count * sizeof (Elf32_External_Rel);
3140 /* Allocate space in .plt, .got and associated reloc sections for
3141 local dynamic relocs. */
3144 elf_i386_allocate_local_dynrelocs (void **slot, void *inf)
3146 struct elf_link_hash_entry *h
3147 = (struct elf_link_hash_entry *) *slot;
3149 if (h->type != STT_GNU_IFUNC
3153 || h->root.type != bfd_link_hash_defined)
3156 return elf_i386_allocate_dynrelocs (h, inf);
3159 /* Find any dynamic relocs that apply to read-only sections. */
3162 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3164 struct elf_i386_link_hash_entry *eh;
3165 struct elf_dyn_relocs *p;
3167 /* Skip local IFUNC symbols. */
3168 if (h->forced_local && h->type == STT_GNU_IFUNC)
3171 eh = (struct elf_i386_link_hash_entry *) h;
3172 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3174 asection *s = p->sec->output_section;
3176 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3178 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3180 info->flags |= DF_TEXTREL;
3182 if ((info->warn_shared_textrel && bfd_link_pic (info))
3183 || info->error_textrel)
3184 /* xgettext:c-format */
3185 info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3186 p->sec->owner, h->root.root.string,
3189 /* Not an error, just cut short the traversal. */
3196 /* Convert load via the GOT slot to load immediate. */
3199 elf_i386_convert_load (bfd *abfd, asection *sec,
3200 struct bfd_link_info *link_info)
3202 struct elf_i386_link_hash_table *htab;
3203 Elf_Internal_Shdr *symtab_hdr;
3204 Elf_Internal_Rela *internal_relocs;
3205 Elf_Internal_Rela *irel, *irelend;
3207 bfd_boolean changed;
3208 bfd_signed_vma *local_got_refcounts;
3210 /* Don't even try to convert non-ELF outputs. */
3211 if (!is_elf_hash_table (link_info->hash))
3214 /* Nothing to do if there is no need or no output. */
3215 if ((sec->flags & (SEC_CODE | SEC_RELOC)) != (SEC_CODE | SEC_RELOC)
3216 || sec->need_convert_load == 0
3217 || bfd_is_abs_section (sec->output_section))
3220 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3222 /* Load the relocations for this section. */
3223 internal_relocs = (_bfd_elf_link_read_relocs
3224 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
3225 link_info->keep_memory));
3226 if (internal_relocs == NULL)
3230 htab = elf_i386_hash_table (link_info);
3231 local_got_refcounts = elf_local_got_refcounts (abfd);
3233 /* Get the section contents. */
3234 if (elf_section_data (sec)->this_hdr.contents != NULL)
3235 contents = elf_section_data (sec)->this_hdr.contents;
3238 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
3242 irelend = internal_relocs + sec->reloc_count;
3243 for (irel = internal_relocs; irel < irelend; irel++)
3245 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
3246 unsigned int r_symndx;
3247 struct elf_link_hash_entry *h;
3248 bfd_boolean converted;
3250 /* Don't convert R_386_GOT32 since we can't tell if it is applied
3251 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
3252 if (r_type != R_386_GOT32X)
3255 r_symndx = ELF32_R_SYM (irel->r_info);
3256 if (r_symndx < symtab_hdr->sh_info)
3257 h = elf_i386_get_local_sym_hash (htab, sec->owner,
3258 (const Elf_Internal_Rela *) irel,
3262 h = elf_sym_hashes (abfd)[r_symndx - symtab_hdr->sh_info];
3263 while (h->root.type == bfd_link_hash_indirect
3264 || h->root.type == bfd_link_hash_warning)
3265 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3268 /* STT_GNU_IFUNC must keep GOT32 relocations. */
3269 if (h != NULL && h->type == STT_GNU_IFUNC)
3273 if (!elf_i386_convert_load_reloc (abfd, symtab_hdr, contents,
3274 irel, h, &converted, link_info))
3279 changed = converted;
3282 if (h->got.refcount > 0)
3283 h->got.refcount -= 1;
3287 if (local_got_refcounts != NULL
3288 && local_got_refcounts[r_symndx] > 0)
3289 local_got_refcounts[r_symndx] -= 1;
3294 if (contents != NULL
3295 && elf_section_data (sec)->this_hdr.contents != contents)
3297 if (!changed && !link_info->keep_memory)
3301 /* Cache the section contents for elf_link_input_bfd. */
3302 elf_section_data (sec)->this_hdr.contents = contents;
3306 if (elf_section_data (sec)->relocs != internal_relocs)
3309 free (internal_relocs);
3311 elf_section_data (sec)->relocs = internal_relocs;
3317 if (contents != NULL
3318 && elf_section_data (sec)->this_hdr.contents != contents)
3320 if (internal_relocs != NULL
3321 && elf_section_data (sec)->relocs != internal_relocs)
3322 free (internal_relocs);
3326 /* Set the sizes of the dynamic sections. */
3329 elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
3331 struct elf_i386_link_hash_table *htab;
3337 htab = elf_i386_hash_table (info);
3340 dynobj = htab->elf.dynobj;
3344 /* Set up .got offsets for local syms, and space for local dynamic
3346 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3348 bfd_signed_vma *local_got;
3349 bfd_signed_vma *end_local_got;
3350 char *local_tls_type;
3351 bfd_vma *local_tlsdesc_gotent;
3352 bfd_size_type locsymcount;
3353 Elf_Internal_Shdr *symtab_hdr;
3356 if (! is_i386_elf (ibfd))
3359 for (s = ibfd->sections; s != NULL; s = s->next)
3361 struct elf_dyn_relocs *p;
3363 if (!elf_i386_convert_load (ibfd, s, info))
3366 for (p = ((struct elf_dyn_relocs *)
3367 elf_section_data (s)->local_dynrel);
3371 if (!bfd_is_abs_section (p->sec)
3372 && bfd_is_abs_section (p->sec->output_section))
3374 /* Input section has been discarded, either because
3375 it is a copy of a linkonce section or due to
3376 linker script /DISCARD/, so we'll be discarding
3379 else if ((get_elf_i386_backend_data (output_bfd)->os
3381 && strcmp (p->sec->output_section->name,
3384 /* Relocations in vxworks .tls_vars sections are
3385 handled specially by the loader. */
3387 else if (p->count != 0)
3389 srel = elf_section_data (p->sec)->sreloc;
3390 srel->size += p->count * sizeof (Elf32_External_Rel);
3391 if ((p->sec->output_section->flags & SEC_READONLY) != 0
3392 && (info->flags & DF_TEXTREL) == 0)
3394 info->flags |= DF_TEXTREL;
3395 if ((info->warn_shared_textrel && bfd_link_pic (info))
3396 || info->error_textrel)
3397 /* xgettext:c-format */
3398 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3399 p->sec->owner, p->sec);
3405 local_got = elf_local_got_refcounts (ibfd);
3409 symtab_hdr = &elf_symtab_hdr (ibfd);
3410 locsymcount = symtab_hdr->sh_info;
3411 end_local_got = local_got + locsymcount;
3412 local_tls_type = elf_i386_local_got_tls_type (ibfd);
3413 local_tlsdesc_gotent = elf_i386_local_tlsdesc_gotent (ibfd);
3415 srel = htab->elf.srelgot;
3416 for (; local_got < end_local_got;
3417 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
3419 *local_tlsdesc_gotent = (bfd_vma) -1;
3422 if (GOT_TLS_GDESC_P (*local_tls_type))
3424 *local_tlsdesc_gotent = htab->elf.sgotplt->size
3425 - elf_i386_compute_jump_table_size (htab);
3426 htab->elf.sgotplt->size += 8;
3427 *local_got = (bfd_vma) -2;
3429 if (! GOT_TLS_GDESC_P (*local_tls_type)
3430 || GOT_TLS_GD_P (*local_tls_type))
3432 *local_got = s->size;
3434 if (GOT_TLS_GD_P (*local_tls_type)
3435 || *local_tls_type == GOT_TLS_IE_BOTH)
3438 if (bfd_link_pic (info)
3439 || GOT_TLS_GD_ANY_P (*local_tls_type)
3440 || (*local_tls_type & GOT_TLS_IE))
3442 if (*local_tls_type == GOT_TLS_IE_BOTH)
3443 srel->size += 2 * sizeof (Elf32_External_Rel);
3444 else if (GOT_TLS_GD_P (*local_tls_type)
3445 || ! GOT_TLS_GDESC_P (*local_tls_type))
3446 srel->size += sizeof (Elf32_External_Rel);
3447 if (GOT_TLS_GDESC_P (*local_tls_type))
3448 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
3452 *local_got = (bfd_vma) -1;
3456 if (htab->tls_ldm_got.refcount > 0)
3458 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
3460 htab->tls_ldm_got.offset = htab->elf.sgot->size;
3461 htab->elf.sgot->size += 8;
3462 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
3465 htab->tls_ldm_got.offset = -1;
3467 /* Allocate global sym .plt and .got entries, and space for global
3468 sym dynamic relocs. */
3469 elf_link_hash_traverse (&htab->elf, elf_i386_allocate_dynrelocs, info);
3471 /* Allocate .plt and .got entries, and space for local symbols. */
3472 htab_traverse (htab->loc_hash_table,
3473 elf_i386_allocate_local_dynrelocs,
3476 /* For every jump slot reserved in the sgotplt, reloc_count is
3477 incremented. However, when we reserve space for TLS descriptors,
3478 it's not incremented, so in order to compute the space reserved
3479 for them, it suffices to multiply the reloc count by the jump
3482 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3483 so that R_386_IRELATIVE entries come last. */
3484 if (htab->elf.srelplt)
3486 htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
3487 htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;
3488 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
3490 else if (htab->elf.irelplt)
3491 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
3494 if (htab->elf.sgotplt)
3496 /* Don't allocate .got.plt section if there are no GOT nor PLT
3497 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
3498 if ((htab->elf.hgot == NULL
3499 || !htab->elf.hgot->ref_regular_nonweak)
3500 && (htab->elf.sgotplt->size
3501 == get_elf_backend_data (output_bfd)->got_header_size)
3502 && (htab->elf.splt == NULL
3503 || htab->elf.splt->size == 0)
3504 && (htab->elf.sgot == NULL
3505 || htab->elf.sgot->size == 0)
3506 && (htab->elf.iplt == NULL
3507 || htab->elf.iplt->size == 0)
3508 && (htab->elf.igotplt == NULL
3509 || htab->elf.igotplt->size == 0))
3510 htab->elf.sgotplt->size = 0;
3513 if (_bfd_elf_eh_frame_present (info))
3515 if (htab->plt_eh_frame != NULL
3516 && htab->elf.splt != NULL
3517 && htab->elf.splt->size != 0
3518 && !bfd_is_abs_section (htab->elf.splt->output_section))
3519 htab->plt_eh_frame->size = htab->plt.eh_frame_plt_size;
3521 if (htab->plt_got_eh_frame != NULL
3522 && htab->plt_got != NULL
3523 && htab->plt_got->size != 0
3524 && !bfd_is_abs_section (htab->plt_got->output_section))
3525 htab->plt_got_eh_frame->size
3526 = htab->non_lazy_plt->eh_frame_plt_size;
3528 /* Unwind info for the second PLT and .plt.got sections are
3530 if (htab->plt_second_eh_frame != NULL
3531 && htab->plt_second != NULL
3532 && htab->plt_second->size != 0
3533 && !bfd_is_abs_section (htab->plt_second->output_section))
3534 htab->plt_second_eh_frame->size
3535 = htab->non_lazy_plt->eh_frame_plt_size;
3538 /* We now have determined the sizes of the various dynamic sections.
3539 Allocate memory for them. */
3541 for (s = dynobj->sections; s != NULL; s = s->next)
3543 bfd_boolean strip_section = TRUE;
3545 if ((s->flags & SEC_LINKER_CREATED) == 0)
3548 if (s == htab->elf.splt
3549 || s == htab->elf.sgot)
3551 /* Strip this section if we don't need it; see the
3553 /* We'd like to strip these sections if they aren't needed, but if
3554 we've exported dynamic symbols from them we must leave them.
3555 It's too late to tell BFD to get rid of the symbols. */
3557 if (htab->elf.hplt != NULL)
3558 strip_section = FALSE;
3560 else if (s == htab->elf.sgotplt
3561 || s == htab->elf.iplt
3562 || s == htab->elf.igotplt
3563 || s == htab->plt_second
3564 || s == htab->plt_got
3565 || s == htab->plt_eh_frame
3566 || s == htab->plt_got_eh_frame
3567 || s == htab->plt_second_eh_frame
3568 || s == htab->elf.sdynbss
3569 || s == htab->elf.sdynrelro)
3571 /* Strip these too. */
3573 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rel"))
3576 && s != htab->elf.srelplt
3577 && s != htab->srelplt2)
3580 /* We use the reloc_count field as a counter if we need
3581 to copy relocs into the output file. */
3586 /* It's not one of our sections, so don't allocate space. */
3592 /* If we don't need this section, strip it from the
3593 output file. This is mostly to handle .rel.bss and
3594 .rel.plt. We must create both sections in
3595 create_dynamic_sections, because they must be created
3596 before the linker maps input sections to output
3597 sections. The linker does that before
3598 adjust_dynamic_symbol is called, and it is that
3599 function which decides whether anything needs to go
3600 into these sections. */
3602 s->flags |= SEC_EXCLUDE;
3606 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3609 /* Allocate memory for the section contents. We use bfd_zalloc
3610 here in case unused entries are not reclaimed before the
3611 section's contents are written out. This should not happen,
3612 but this way if it does, we get a R_386_NONE reloc instead
3614 s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
3615 if (s->contents == NULL)
3619 if (htab->plt_eh_frame != NULL
3620 && htab->plt_eh_frame->contents != NULL)
3622 memcpy (htab->plt_eh_frame->contents,
3623 htab->plt.eh_frame_plt,
3624 htab->plt_eh_frame->size);
3625 bfd_put_32 (dynobj, htab->elf.splt->size,
3626 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
3629 if (htab->plt_got_eh_frame != NULL
3630 && htab->plt_got_eh_frame->contents != NULL)
3632 memcpy (htab->plt_got_eh_frame->contents,
3633 htab->non_lazy_plt->eh_frame_plt,
3634 htab->plt_got_eh_frame->size);
3635 bfd_put_32 (dynobj, htab->plt_got->size,
3636 (htab->plt_got_eh_frame->contents
3637 + PLT_FDE_LEN_OFFSET));
3640 if (htab->plt_second_eh_frame != NULL
3641 && htab->plt_second_eh_frame->contents != NULL)
3643 memcpy (htab->plt_second_eh_frame->contents,
3644 htab->non_lazy_plt->eh_frame_plt,
3645 htab->plt_second_eh_frame->size);
3646 bfd_put_32 (dynobj, htab->plt_second->size,
3647 (htab->plt_second_eh_frame->contents
3648 + PLT_FDE_LEN_OFFSET));
3651 if (htab->elf.dynamic_sections_created)
3653 /* Add some entries to the .dynamic section. We fill in the
3654 values later, in elf_i386_finish_dynamic_sections, but we
3655 must add the entries now so that we get the correct size for
3656 the .dynamic section. The DT_DEBUG entry is filled in by the
3657 dynamic linker and used by the debugger. */
3658 #define add_dynamic_entry(TAG, VAL) \
3659 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3661 if (bfd_link_executable (info))
3663 if (!add_dynamic_entry (DT_DEBUG, 0))
3667 if (htab->elf.splt->size != 0)
3669 /* DT_PLTGOT is used by prelink even if there is no PLT
3671 if (!add_dynamic_entry (DT_PLTGOT, 0))
3675 if (htab->elf.srelplt->size != 0)
3677 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
3678 || !add_dynamic_entry (DT_PLTREL, DT_REL)
3679 || !add_dynamic_entry (DT_JMPREL, 0))
3685 if (!add_dynamic_entry (DT_REL, 0)
3686 || !add_dynamic_entry (DT_RELSZ, 0)
3687 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
3690 /* If any dynamic relocs apply to a read-only section,
3691 then we need a DT_TEXTREL entry. */
3692 if ((info->flags & DF_TEXTREL) == 0)
3693 elf_link_hash_traverse (&htab->elf,
3694 elf_i386_readonly_dynrelocs, info);
3696 if ((info->flags & DF_TEXTREL) != 0)
3698 if (htab->readonly_dynrelocs_against_ifunc)
3700 info->callbacks->einfo
3701 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3702 bfd_set_error (bfd_error_bad_value);
3706 if (!add_dynamic_entry (DT_TEXTREL, 0))
3710 if (get_elf_i386_backend_data (output_bfd)->os == is_vxworks
3711 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
3714 #undef add_dynamic_entry
3720 elf_i386_always_size_sections (bfd *output_bfd,
3721 struct bfd_link_info *info)
3723 asection *tls_sec = elf_hash_table (info)->tls_sec;
3727 struct elf_link_hash_entry *tlsbase;
3729 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
3730 "_TLS_MODULE_BASE_",
3731 FALSE, FALSE, FALSE);
3733 if (tlsbase && tlsbase->type == STT_TLS)
3735 struct elf_i386_link_hash_table *htab;
3736 struct bfd_link_hash_entry *bh = NULL;
3737 const struct elf_backend_data *bed
3738 = get_elf_backend_data (output_bfd);
3740 htab = elf_i386_hash_table (info);
3744 if (!(_bfd_generic_link_add_one_symbol
3745 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
3746 tls_sec, 0, NULL, FALSE,
3747 bed->collect, &bh)))
3750 htab->tls_module_base = bh;
3752 tlsbase = (struct elf_link_hash_entry *)bh;
3753 tlsbase->def_regular = 1;
3754 tlsbase->other = STV_HIDDEN;
3755 tlsbase->root.linker_def = 1;
3756 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
3763 /* Set the correct type for an x86 ELF section. We do this by the
3764 section name, which is a hack, but ought to work. */
3767 elf_i386_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
3768 Elf_Internal_Shdr *hdr,
3773 name = bfd_get_section_name (abfd, sec);
3775 /* This is an ugly, but unfortunately necessary hack that is
3776 needed when producing EFI binaries on x86. It tells
3777 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3778 containing ELF relocation info. We need this hack in order to
3779 be able to generate ELF binaries that can be translated into
3780 EFI applications (which are essentially COFF objects). Those
3781 files contain a COFF ".reloc" section inside an ELFNN object,
3782 which would normally cause BFD to segfault because it would
3783 attempt to interpret this section as containing relocation
3784 entries for section "oc". With this hack enabled, ".reloc"
3785 will be treated as a normal data section, which will avoid the
3786 segfault. However, you won't be able to create an ELFNN binary
3787 with a section named "oc" that needs relocations, but that's
3788 the kind of ugly side-effects you get when detecting section
3789 types based on their names... In practice, this limitation is
3790 unlikely to bite. */
3791 if (strcmp (name, ".reloc") == 0)
3792 hdr->sh_type = SHT_PROGBITS;
3797 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3798 executables. Rather than setting it to the beginning of the TLS
3799 section, we have to set it to the end. This function may be called
3800 multiple times, it is idempotent. */
3803 elf_i386_set_tls_module_base (struct bfd_link_info *info)
3805 struct elf_i386_link_hash_table *htab;
3806 struct bfd_link_hash_entry *base;
3808 if (!bfd_link_executable (info))
3811 htab = elf_i386_hash_table (info);
3815 base = htab->tls_module_base;
3819 base->u.def.value = htab->elf.tls_size;
3822 /* Return the base VMA address which should be subtracted from real addresses
3823 when resolving @dtpoff relocation.
3824 This is PT_TLS segment p_vaddr. */
3827 elf_i386_dtpoff_base (struct bfd_link_info *info)
3829 /* If tls_sec is NULL, we should have signalled an error already. */
3830 if (elf_hash_table (info)->tls_sec == NULL)
3832 return elf_hash_table (info)->tls_sec->vma;
3835 /* Return the relocation value for @tpoff relocation
3836 if STT_TLS virtual address is ADDRESS. */
3839 elf_i386_tpoff (struct bfd_link_info *info, bfd_vma address)
3841 struct elf_link_hash_table *htab = elf_hash_table (info);
3842 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
3843 bfd_vma static_tls_size;
3845 /* If tls_sec is NULL, we should have signalled an error already. */
3846 if (htab->tls_sec == NULL)
3849 /* Consider special static TLS alignment requirements. */
3850 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
3851 return static_tls_size + htab->tls_sec->vma - address;
3854 /* Relocate an i386 ELF section. */
3857 elf_i386_relocate_section (bfd *output_bfd,
3858 struct bfd_link_info *info,
3860 asection *input_section,
3862 Elf_Internal_Rela *relocs,
3863 Elf_Internal_Sym *local_syms,
3864 asection **local_sections)
3866 struct elf_i386_link_hash_table *htab;
3867 Elf_Internal_Shdr *symtab_hdr;
3868 struct elf_link_hash_entry **sym_hashes;
3869 bfd_vma *local_got_offsets;
3870 bfd_vma *local_tlsdesc_gotents;
3871 Elf_Internal_Rela *rel;
3872 Elf_Internal_Rela *wrel;
3873 Elf_Internal_Rela *relend;
3874 bfd_boolean is_vxworks_tls;
3875 unsigned plt_entry_size;
3877 BFD_ASSERT (is_i386_elf (input_bfd));
3879 /* Skip if check_relocs failed. */
3880 if (input_section->check_relocs_failed)
3883 htab = elf_i386_hash_table (info);
3886 symtab_hdr = &elf_symtab_hdr (input_bfd);
3887 sym_hashes = elf_sym_hashes (input_bfd);
3888 local_got_offsets = elf_local_got_offsets (input_bfd);
3889 local_tlsdesc_gotents = elf_i386_local_tlsdesc_gotent (input_bfd);
3890 /* We have to handle relocations in vxworks .tls_vars sections
3891 specially, because the dynamic loader is 'weird'. */
3892 is_vxworks_tls = ((get_elf_i386_backend_data (output_bfd)->os
3894 && bfd_link_pic (info)
3895 && !strcmp (input_section->output_section->name,
3898 elf_i386_set_tls_module_base (info);
3900 plt_entry_size = htab->plt.plt_entry_size;
3902 rel = wrel = relocs;
3903 relend = relocs + input_section->reloc_count;
3904 for (; rel < relend; wrel++, rel++)
3906 unsigned int r_type;
3907 reloc_howto_type *howto;
3908 unsigned long r_symndx;
3909 struct elf_link_hash_entry *h;
3910 struct elf_i386_link_hash_entry *eh;
3911 Elf_Internal_Sym *sym;
3913 bfd_vma off, offplt, plt_offset;
3915 bfd_boolean unresolved_reloc;
3916 bfd_reloc_status_type r;
3920 asection *resolved_plt;
3921 bfd_boolean resolved_to_zero;
3922 bfd_boolean relative_reloc;
3924 r_type = ELF32_R_TYPE (rel->r_info);
3925 if (r_type == R_386_GNU_VTINHERIT
3926 || r_type == R_386_GNU_VTENTRY)
3933 if ((indx = r_type) >= R_386_standard
3934 && ((indx = r_type - R_386_ext_offset) - R_386_standard
3935 >= R_386_ext - R_386_standard)
3936 && ((indx = r_type - R_386_tls_offset) - R_386_ext
3937 >= R_386_ext2 - R_386_ext))
3938 return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
3940 howto = elf_howto_table + indx;
3942 r_symndx = ELF32_R_SYM (rel->r_info);
3946 unresolved_reloc = FALSE;
3947 if (r_symndx < symtab_hdr->sh_info)
3949 sym = local_syms + r_symndx;
3950 sec = local_sections[r_symndx];
3951 relocation = (sec->output_section->vma
3952 + sec->output_offset
3954 st_size = sym->st_size;
3956 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION
3957 && ((sec->flags & SEC_MERGE) != 0
3958 || (bfd_link_relocatable (info)
3959 && sec->output_offset != 0)))
3962 bfd_byte *where = contents + rel->r_offset;
3964 switch (howto->size)
3967 addend = bfd_get_8 (input_bfd, where);
3968 if (howto->pc_relative)
3970 addend = (addend ^ 0x80) - 0x80;
3975 addend = bfd_get_16 (input_bfd, where);
3976 if (howto->pc_relative)
3978 addend = (addend ^ 0x8000) - 0x8000;
3983 addend = bfd_get_32 (input_bfd, where);
3984 if (howto->pc_relative)
3986 addend = (addend ^ 0x80000000) - 0x80000000;
3994 if (bfd_link_relocatable (info))
3995 addend += sec->output_offset;
3998 asection *msec = sec;
3999 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec,
4001 addend -= relocation;
4002 addend += msec->output_section->vma + msec->output_offset;
4005 switch (howto->size)
4008 /* FIXME: overflow checks. */
4009 if (howto->pc_relative)
4011 bfd_put_8 (input_bfd, addend, where);
4014 if (howto->pc_relative)
4016 bfd_put_16 (input_bfd, addend, where);
4019 if (howto->pc_relative)
4021 bfd_put_32 (input_bfd, addend, where);
4025 else if (!bfd_link_relocatable (info)
4026 && ELF32_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
4028 /* Relocate against local STT_GNU_IFUNC symbol. */
4029 h = elf_i386_get_local_sym_hash (htab, input_bfd, rel,
4034 /* Set STT_GNU_IFUNC symbol value. */
4035 h->root.u.def.value = sym->st_value;
4036 h->root.u.def.section = sec;
4041 bfd_boolean warned ATTRIBUTE_UNUSED;
4042 bfd_boolean ignored ATTRIBUTE_UNUSED;
4044 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4045 r_symndx, symtab_hdr, sym_hashes,
4047 unresolved_reloc, warned, ignored);
4051 if (sec != NULL && discarded_section (sec))
4053 _bfd_clear_contents (howto, input_bfd, input_section,
4054 contents + rel->r_offset);
4055 wrel->r_offset = rel->r_offset;
4059 /* For ld -r, remove relocations in debug sections against
4060 sections defined in discarded sections. Not done for
4061 eh_frame editing code expects to be present. */
4062 if (bfd_link_relocatable (info)
4063 && (input_section->flags & SEC_DEBUGGING))
4069 if (bfd_link_relocatable (info))
4076 eh = (struct elf_i386_link_hash_entry *) h;
4078 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4079 it here if it is defined in a non-shared object. */
4081 && h->type == STT_GNU_IFUNC
4084 asection *gotplt, *base_got;
4088 if ((input_section->flags & SEC_ALLOC) == 0)
4090 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4091 sections because such sections are not SEC_ALLOC and
4092 thus ld.so will not process them. */
4093 if ((input_section->flags & SEC_DEBUGGING) != 0)
4098 /* STT_GNU_IFUNC symbol must go through PLT. */
4099 if (htab->elf.splt != NULL)
4101 if (htab->plt_second != NULL)
4103 resolved_plt = htab->plt_second;
4104 plt_offset = eh->plt_second.offset;
4108 resolved_plt = htab->elf.splt;
4109 plt_offset = h->plt.offset;
4111 gotplt = htab->elf.sgotplt;
4115 resolved_plt = htab->elf.iplt;
4116 plt_offset = h->plt.offset;
4117 gotplt = htab->elf.igotplt;
4127 base_got = htab->elf.sgot;
4128 off = h->got.offset;
4130 if (base_got == NULL)
4133 if (off == (bfd_vma) -1)
4135 /* We can't use h->got.offset here to save state, or
4136 even just remember the offset, as finish_dynamic_symbol
4137 would use that as offset into .got. */
4139 if (h->plt.offset == (bfd_vma) -1)
4142 if (htab->elf.splt != NULL)
4144 plt_index = (h->plt.offset / plt_entry_size
4145 - htab->plt.has_plt0);
4146 off = (plt_index + 3) * 4;
4147 base_got = htab->elf.sgotplt;
4151 plt_index = h->plt.offset / plt_entry_size;
4152 off = plt_index * 4;
4153 base_got = htab->elf.igotplt;
4156 if (h->dynindx == -1
4160 /* This references the local defitionion. We must
4161 initialize this entry in the global offset table.
4162 Since the offset must always be a multiple of 8,
4163 we use the least significant bit to record
4164 whether we have initialized it already.
4166 When doing a dynamic link, we create a .rela.got
4167 relocation entry to initialize the value. This
4168 is done in the finish_dynamic_symbol routine. */
4173 bfd_put_32 (output_bfd, relocation,
4174 base_got->contents + off);
4182 relocation = (base_got->output_section->vma
4183 + base_got->output_offset + off
4184 - gotplt->output_section->vma
4185 - gotplt->output_offset);
4187 if (rel->r_offset > 1
4188 && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5
4189 && *(contents + rel->r_offset - 2) != 0x8d)
4191 if (bfd_link_pic (info))
4192 goto disallow_got32;
4194 /* Add the GOT base if there is no base register. */
4195 relocation += (gotplt->output_section->vma
4196 + gotplt->output_offset);
4198 else if (htab->elf.splt == NULL)
4200 /* Adjust for static executables. */
4201 relocation += gotplt->output_offset;
4207 if (h->plt.offset == (bfd_vma) -1)
4209 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4210 if (r_type == R_386_32
4211 && (input_section->flags & SEC_CODE) == 0)
4212 goto do_ifunc_pointer;
4213 goto bad_ifunc_reloc;
4216 relocation = (resolved_plt->output_section->vma
4217 + resolved_plt->output_offset + plt_offset);
4223 if (h->root.root.string)
4224 name = h->root.root.string;
4226 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4229 /* xgettext:c-format */
4230 (_("%B: relocation %s against STT_GNU_IFUNC "
4231 "symbol `%s' isn't supported"), input_bfd,
4233 bfd_set_error (bfd_error_bad_value);
4237 /* Generate dynamic relcoation only when there is a
4238 non-GOT reference in a shared object. */
4239 if ((bfd_link_pic (info) && h->non_got_ref)
4240 || h->plt.offset == (bfd_vma) -1)
4242 Elf_Internal_Rela outrel;
4247 /* Need a dynamic relocation to get the real function
4249 offset = _bfd_elf_section_offset (output_bfd,
4253 if (offset == (bfd_vma) -1
4254 || offset == (bfd_vma) -2)
4257 outrel.r_offset = (input_section->output_section->vma
4258 + input_section->output_offset
4261 if (h->dynindx == -1
4263 || bfd_link_executable (info))
4265 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
4266 h->root.root.string,
4267 h->root.u.def.section->owner);
4269 /* This symbol is resolved locally. */
4270 outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
4271 bfd_put_32 (output_bfd,
4272 (h->root.u.def.value
4273 + h->root.u.def.section->output_section->vma
4274 + h->root.u.def.section->output_offset),
4278 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4280 /* Dynamic relocations are stored in
4281 1. .rel.ifunc section in PIC object.
4282 2. .rel.got section in dynamic executable.
4283 3. .rel.iplt section in static executable. */
4284 if (bfd_link_pic (info))
4285 sreloc = htab->elf.irelifunc;
4286 else if (htab->elf.splt != NULL)
4287 sreloc = htab->elf.srelgot;
4289 sreloc = htab->elf.irelplt;
4290 elf_append_rel (output_bfd, sreloc, &outrel);
4292 /* If this reloc is against an external symbol, we
4293 do not want to fiddle with the addend. Otherwise,
4294 we need to include the symbol value so that it
4295 becomes an addend for the dynamic reloc. For an
4296 internal symbol, we have updated addend. */
4305 relocation -= (gotplt->output_section->vma
4306 + gotplt->output_offset);
4311 resolved_to_zero = (eh != NULL
4312 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
4319 /* Avoid optimizing _DYNAMIC since ld.so may use its
4320 link-time address. */
4321 if (h == htab->elf.hdynamic)
4324 if (bfd_link_pic (info))
4326 /* It is OK to convert mov to lea and convert indirect
4327 branch to direct branch. It is OK to convert adc,
4328 add, and, cmp, or, sbb, sub, test, xor only when PIC
4330 unsigned int opcode, addend;
4331 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4334 opcode = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
4335 if (opcode != 0x8b && opcode != 0xff)
4339 /* Resolve "mov GOT[(%reg)], %reg",
4340 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
4341 and "binop foo@GOT[(%reg)], %reg". */
4343 || (h->plt.offset == (bfd_vma) -1
4344 && h->got.offset == (bfd_vma) -1)
4345 || htab->elf.sgotplt == NULL)
4348 offplt = (htab->elf.sgotplt->output_section->vma
4349 + htab->elf.sgotplt->output_offset);
4351 /* It is relative to .got.plt section. */
4352 if (h->got.offset != (bfd_vma) -1)
4353 /* Use GOT entry. Mask off the least significant bit in
4354 GOT offset which may be set by R_386_GOT32 processing
4356 relocation = (htab->elf.sgot->output_section->vma
4357 + htab->elf.sgot->output_offset
4358 + (h->got.offset & ~1) - offplt);
4360 /* Use GOTPLT entry. */
4361 relocation = (h->plt.offset / plt_entry_size
4362 - htab->plt.has_plt0 + 3) * 4;
4364 if (!bfd_link_pic (info))
4366 /* If not PIC, add the .got.plt section address for
4367 baseless addressing. */
4369 modrm = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
4370 if ((modrm & 0xc7) == 0x5)
4371 relocation += offplt;
4374 unresolved_reloc = FALSE;
4379 /* Relocation is to the entry for this symbol in the global
4381 if (htab->elf.sgot == NULL)
4384 relative_reloc = FALSE;
4389 off = h->got.offset;
4390 dyn = htab->elf.dynamic_sections_created;
4391 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
4392 bfd_link_pic (info),
4394 || (bfd_link_pic (info)
4395 && SYMBOL_REFERENCES_LOCAL (info, h))
4396 || (ELF_ST_VISIBILITY (h->other)
4397 && h->root.type == bfd_link_hash_undefweak))
4399 /* This is actually a static link, or it is a
4400 -Bsymbolic link and the symbol is defined
4401 locally, or the symbol was forced to be local
4402 because of a version file. We must initialize
4403 this entry in the global offset table. Since the
4404 offset must always be a multiple of 4, we use the
4405 least significant bit to record whether we have
4406 initialized it already.
4408 When doing a dynamic link, we create a .rel.got
4409 relocation entry to initialize the value. This
4410 is done in the finish_dynamic_symbol routine. */
4415 bfd_put_32 (output_bfd, relocation,
4416 htab->elf.sgot->contents + off);
4419 if (h->dynindx == -1
4421 && h->root.type != bfd_link_hash_undefweak
4422 && bfd_link_pic (info))
4424 /* PR ld/21402: If this symbol isn't dynamic
4425 in PIC, generate R_386_RELATIVE here. */
4426 eh->no_finish_dynamic_symbol = 1;
4427 relative_reloc = TRUE;
4432 unresolved_reloc = FALSE;
4436 if (local_got_offsets == NULL)
4439 off = local_got_offsets[r_symndx];
4441 /* The offset must always be a multiple of 4. We use
4442 the least significant bit to record whether we have
4443 already generated the necessary reloc. */
4448 bfd_put_32 (output_bfd, relocation,
4449 htab->elf.sgot->contents + off);
4450 local_got_offsets[r_symndx] |= 1;
4452 if (bfd_link_pic (info))
4453 relative_reloc = TRUE;
4460 Elf_Internal_Rela outrel;
4462 s = htab->elf.srelgot;
4466 outrel.r_offset = (htab->elf.sgot->output_section->vma
4467 + htab->elf.sgot->output_offset
4469 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
4470 elf_append_rel (output_bfd, s, &outrel);
4473 if (off >= (bfd_vma) -2)
4476 relocation = (htab->elf.sgot->output_section->vma
4477 + htab->elf.sgot->output_offset + off);
4478 if (rel->r_offset > 1
4479 && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5
4480 && *(contents + rel->r_offset - 2) != 0x8d)
4482 if (bfd_link_pic (info))
4484 /* For PIC, disallow R_386_GOT32 without a base
4485 register, except for "lea foo@GOT, %reg", since
4486 we don't know what the GOT base is. */
4490 if (h == NULL || h->root.root.string == NULL)
4491 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4494 name = h->root.root.string;
4497 /* xgettext:c-format */
4498 (_("%B: direct GOT relocation %s against `%s'"
4499 " without base register can not be used"
4500 " when making a shared object"),
4501 input_bfd, howto->name, name);
4502 bfd_set_error (bfd_error_bad_value);
4508 /* Subtract the .got.plt section address only with a base
4510 relocation -= (htab->elf.sgotplt->output_section->vma
4511 + htab->elf.sgotplt->output_offset);
4517 /* Relocation is relative to the start of the global offset
4520 /* Check to make sure it isn't a protected function or data
4521 symbol for shared library since it may not be local when
4522 used as function address or with copy relocation. We also
4523 need to make sure that a symbol is referenced locally. */
4524 if (!bfd_link_executable (info) && h)
4526 if (!h->def_regular)
4530 switch (ELF_ST_VISIBILITY (h->other))
4533 v = _("hidden symbol");
4536 v = _("internal symbol");
4539 v = _("protected symbol");
4547 /* xgettext:c-format */
4548 (_("%B: relocation R_386_GOTOFF against undefined %s"
4549 " `%s' can not be used when making a shared object"),
4550 input_bfd, v, h->root.root.string);
4551 bfd_set_error (bfd_error_bad_value);
4554 else if (!SYMBOL_REFERENCES_LOCAL (info, h)
4555 && (h->type == STT_FUNC
4556 || h->type == STT_OBJECT)
4557 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
4560 /* xgettext:c-format */
4561 (_("%B: relocation R_386_GOTOFF against protected %s"
4562 " `%s' can not be used when making a shared object"),
4564 h->type == STT_FUNC ? "function" : "data",
4565 h->root.root.string);
4566 bfd_set_error (bfd_error_bad_value);
4571 /* Note that sgot is not involved in this
4572 calculation. We always want the start of .got.plt. If we
4573 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4574 permitted by the ABI, we might have to change this
4576 relocation -= htab->elf.sgotplt->output_section->vma
4577 + htab->elf.sgotplt->output_offset;
4581 /* Use global offset table as symbol value. */
4582 relocation = htab->elf.sgotplt->output_section->vma
4583 + htab->elf.sgotplt->output_offset;
4584 unresolved_reloc = FALSE;
4588 /* Relocation is to the entry for this symbol in the
4589 procedure linkage table. */
4591 /* Resolve a PLT32 reloc against a local symbol directly,
4592 without using the procedure linkage table. */
4596 if ((h->plt.offset == (bfd_vma) -1
4597 && eh->plt_got.offset == (bfd_vma) -1)
4598 || htab->elf.splt == NULL)
4600 /* We didn't make a PLT entry for this symbol. This
4601 happens when statically linking PIC code, or when
4602 using -Bsymbolic. */
4606 if (h->plt.offset != (bfd_vma) -1)
4608 if (htab->plt_second != NULL)
4610 resolved_plt = htab->plt_second;
4611 plt_offset = eh->plt_second.offset;
4615 resolved_plt = htab->elf.splt;
4616 plt_offset = h->plt.offset;
4621 resolved_plt = htab->plt_got;
4622 plt_offset = eh->plt_got.offset;
4625 relocation = (resolved_plt->output_section->vma
4626 + resolved_plt->output_offset
4628 unresolved_reloc = FALSE;
4632 /* Set to symbol size. */
4633 relocation = st_size;
4638 if ((input_section->flags & SEC_ALLOC) == 0
4642 /* Copy dynamic function pointer relocations. Don't generate
4643 dynamic relocations against resolved undefined weak symbols
4644 in PIE, except for R_386_PC32. */
4645 if ((bfd_link_pic (info)
4647 || ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4648 && (!resolved_to_zero
4649 || r_type == R_386_PC32))
4650 || h->root.type != bfd_link_hash_undefweak))
4651 && ((r_type != R_386_PC32 && r_type != R_386_SIZE32)
4652 || !SYMBOL_CALLS_LOCAL (info, h)))
4653 || (ELIMINATE_COPY_RELOCS
4654 && !bfd_link_pic (info)
4658 || eh->func_pointer_refcount > 0
4659 || (h->root.type == bfd_link_hash_undefweak
4660 && !resolved_to_zero))
4661 && ((h->def_dynamic && !h->def_regular)
4662 /* Undefined weak symbol is bound locally when
4664 || h->root.type == bfd_link_hash_undefweak)))
4666 Elf_Internal_Rela outrel;
4667 bfd_boolean skip, relocate;
4670 /* When generating a shared object, these relocations
4671 are copied into the output file to be resolved at run
4678 _bfd_elf_section_offset (output_bfd, info, input_section,
4680 if (outrel.r_offset == (bfd_vma) -1)
4682 else if (outrel.r_offset == (bfd_vma) -2)
4683 skip = TRUE, relocate = TRUE;
4684 outrel.r_offset += (input_section->output_section->vma
4685 + input_section->output_offset);
4688 memset (&outrel, 0, sizeof outrel);
4691 && (r_type == R_386_PC32
4692 || !(bfd_link_executable (info)
4693 || SYMBOLIC_BIND (info, h))
4694 || !h->def_regular))
4695 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4698 /* This symbol is local, or marked to become local. */
4700 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
4703 sreloc = elf_section_data (input_section)->sreloc;
4705 if (sreloc == NULL || sreloc->contents == NULL)
4707 r = bfd_reloc_notsupported;
4708 goto check_relocation_error;
4711 elf_append_rel (output_bfd, sreloc, &outrel);
4713 /* If this reloc is against an external symbol, we do
4714 not want to fiddle with the addend. Otherwise, we
4715 need to include the symbol value so that it becomes
4716 an addend for the dynamic reloc. */
4723 if (!bfd_link_executable (info))
4725 Elf_Internal_Rela outrel;
4728 outrel.r_offset = rel->r_offset
4729 + input_section->output_section->vma
4730 + input_section->output_offset;
4731 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
4732 sreloc = elf_section_data (input_section)->sreloc;
4735 elf_append_rel (output_bfd, sreloc, &outrel);
4740 case R_386_TLS_GOTDESC:
4741 case R_386_TLS_DESC_CALL:
4742 case R_386_TLS_IE_32:
4743 case R_386_TLS_GOTIE:
4744 tls_type = GOT_UNKNOWN;
4745 if (h == NULL && local_got_offsets)
4746 tls_type = elf_i386_local_got_tls_type (input_bfd) [r_symndx];
4748 tls_type = elf_i386_hash_entry(h)->tls_type;
4749 if (tls_type == GOT_TLS_IE)
4750 tls_type = GOT_TLS_IE_NEG;
4752 if (! elf_i386_tls_transition (info, input_bfd,
4753 input_section, contents,
4754 symtab_hdr, sym_hashes,
4755 &r_type, tls_type, rel,
4756 relend, h, r_symndx, TRUE))
4759 if (r_type == R_386_TLS_LE_32)
4761 BFD_ASSERT (! unresolved_reloc);
4762 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
4767 /* GD->LE transition. */
4768 type = *(contents + rel->r_offset - 2);
4772 leal foo@tlsgd(,%ebx,1), %eax
4773 call ___tls_get_addr@PLT
4776 subl $foo@tpoff, %eax
4777 (6 byte form of subl). */
4778 roff = rel->r_offset + 5;
4783 leal foo@tlsgd(%ebx), %eax
4784 call ___tls_get_addr@PLT
4787 leal foo@tlsgd(%reg), %eax
4788 call *___tls_get_addr@GOT(%reg)
4789 which may be converted to
4790 addr32 call ___tls_get_addr
4792 movl %gs:0, %eax; subl $foo@tpoff, %eax
4793 (6 byte form of subl). */
4794 roff = rel->r_offset + 6;
4796 memcpy (contents + roff - 8,
4797 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4798 bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
4800 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4805 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
4807 /* GDesc -> LE transition.
4808 It's originally something like:
4809 leal x@tlsdesc(%ebx), %eax
4813 Registers other than %eax may be set up here. */
4818 roff = rel->r_offset;
4819 val = bfd_get_8 (input_bfd, contents + roff - 1);
4821 /* Now modify the instruction as appropriate. */
4822 /* aoliva FIXME: remove the above and xor the byte
4824 bfd_put_8 (output_bfd, val ^ 0x86,
4825 contents + roff - 1);
4826 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
4830 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
4832 /* GDesc -> LE transition.
4840 roff = rel->r_offset;
4841 bfd_put_8 (output_bfd, 0x66, contents + roff);
4842 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
4845 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_IE)
4849 /* IE->LE transition:
4850 Originally it can be one of:
4858 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
4861 /* movl foo, %eax. */
4862 bfd_put_8 (output_bfd, 0xb8,
4863 contents + rel->r_offset - 1);
4869 type = bfd_get_8 (input_bfd,
4870 contents + rel->r_offset - 2);
4875 bfd_put_8 (output_bfd, 0xc7,
4876 contents + rel->r_offset - 2);
4877 bfd_put_8 (output_bfd,
4878 0xc0 | ((val >> 3) & 7),
4879 contents + rel->r_offset - 1);
4883 bfd_put_8 (output_bfd, 0x81,
4884 contents + rel->r_offset - 2);
4885 bfd_put_8 (output_bfd,
4886 0xc0 | ((val >> 3) & 7),
4887 contents + rel->r_offset - 1);
4894 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
4895 contents + rel->r_offset);
4900 unsigned int val, type;
4902 /* {IE_32,GOTIE}->LE transition:
4903 Originally it can be one of:
4904 subl foo(%reg1), %reg2
4905 movl foo(%reg1), %reg2
4906 addl foo(%reg1), %reg2
4909 movl $foo, %reg2 (6 byte form)
4910 addl $foo, %reg2. */
4911 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
4912 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
4916 bfd_put_8 (output_bfd, 0xc7,
4917 contents + rel->r_offset - 2);
4918 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
4919 contents + rel->r_offset - 1);
4921 else if (type == 0x2b)
4924 bfd_put_8 (output_bfd, 0x81,
4925 contents + rel->r_offset - 2);
4926 bfd_put_8 (output_bfd, 0xe8 | ((val >> 3) & 7),
4927 contents + rel->r_offset - 1);
4929 else if (type == 0x03)
4932 bfd_put_8 (output_bfd, 0x81,
4933 contents + rel->r_offset - 2);
4934 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
4935 contents + rel->r_offset - 1);
4939 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTIE)
4940 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
4941 contents + rel->r_offset);
4943 bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
4944 contents + rel->r_offset);
4949 if (htab->elf.sgot == NULL)
4954 off = h->got.offset;
4955 offplt = elf_i386_hash_entry (h)->tlsdesc_got;
4959 if (local_got_offsets == NULL)
4962 off = local_got_offsets[r_symndx];
4963 offplt = local_tlsdesc_gotents[r_symndx];
4970 Elf_Internal_Rela outrel;
4974 if (htab->elf.srelgot == NULL)
4977 indx = h && h->dynindx != -1 ? h->dynindx : 0;
4979 if (GOT_TLS_GDESC_P (tls_type))
4982 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
4983 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
4984 <= htab->elf.sgotplt->size);
4985 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
4986 + htab->elf.sgotplt->output_offset
4988 + htab->sgotplt_jump_table_size);
4989 sreloc = htab->elf.srelplt;
4990 loc = sreloc->contents;
4991 loc += (htab->next_tls_desc_index++
4992 * sizeof (Elf32_External_Rel));
4993 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
4994 <= sreloc->contents + sreloc->size);
4995 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
4998 BFD_ASSERT (! unresolved_reloc);
4999 bfd_put_32 (output_bfd,
5000 relocation - elf_i386_dtpoff_base (info),
5001 htab->elf.sgotplt->contents + offplt
5002 + htab->sgotplt_jump_table_size + 4);
5006 bfd_put_32 (output_bfd, 0,
5007 htab->elf.sgotplt->contents + offplt
5008 + htab->sgotplt_jump_table_size + 4);
5012 sreloc = htab->elf.srelgot;
5014 outrel.r_offset = (htab->elf.sgot->output_section->vma
5015 + htab->elf.sgot->output_offset + off);
5017 if (GOT_TLS_GD_P (tls_type))
5018 dr_type = R_386_TLS_DTPMOD32;
5019 else if (GOT_TLS_GDESC_P (tls_type))
5021 else if (tls_type == GOT_TLS_IE_POS)
5022 dr_type = R_386_TLS_TPOFF;
5024 dr_type = R_386_TLS_TPOFF32;
5026 if (dr_type == R_386_TLS_TPOFF && indx == 0)
5027 bfd_put_32 (output_bfd,
5028 relocation - elf_i386_dtpoff_base (info),
5029 htab->elf.sgot->contents + off);
5030 else if (dr_type == R_386_TLS_TPOFF32 && indx == 0)
5031 bfd_put_32 (output_bfd,
5032 elf_i386_dtpoff_base (info) - relocation,
5033 htab->elf.sgot->contents + off);
5034 else if (dr_type != R_386_TLS_DESC)
5035 bfd_put_32 (output_bfd, 0,
5036 htab->elf.sgot->contents + off);
5037 outrel.r_info = ELF32_R_INFO (indx, dr_type);
5039 elf_append_rel (output_bfd, sreloc, &outrel);
5041 if (GOT_TLS_GD_P (tls_type))
5045 BFD_ASSERT (! unresolved_reloc);
5046 bfd_put_32 (output_bfd,
5047 relocation - elf_i386_dtpoff_base (info),
5048 htab->elf.sgot->contents + off + 4);
5052 bfd_put_32 (output_bfd, 0,
5053 htab->elf.sgot->contents + off + 4);
5054 outrel.r_info = ELF32_R_INFO (indx,
5055 R_386_TLS_DTPOFF32);
5056 outrel.r_offset += 4;
5057 elf_append_rel (output_bfd, sreloc, &outrel);
5060 else if (tls_type == GOT_TLS_IE_BOTH)
5062 bfd_put_32 (output_bfd,
5064 ? relocation - elf_i386_dtpoff_base (info)
5066 htab->elf.sgot->contents + off + 4);
5067 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
5068 outrel.r_offset += 4;
5069 elf_append_rel (output_bfd, sreloc, &outrel);
5076 local_got_offsets[r_symndx] |= 1;
5079 if (off >= (bfd_vma) -2
5080 && ! GOT_TLS_GDESC_P (tls_type))
5082 if (r_type == R_386_TLS_GOTDESC
5083 || r_type == R_386_TLS_DESC_CALL)
5085 relocation = htab->sgotplt_jump_table_size + offplt;
5086 unresolved_reloc = FALSE;
5088 else if (r_type == ELF32_R_TYPE (rel->r_info))
5090 bfd_vma g_o_t = htab->elf.sgotplt->output_section->vma
5091 + htab->elf.sgotplt->output_offset;
5092 relocation = htab->elf.sgot->output_section->vma
5093 + htab->elf.sgot->output_offset + off - g_o_t;
5094 if ((r_type == R_386_TLS_IE || r_type == R_386_TLS_GOTIE)
5095 && tls_type == GOT_TLS_IE_BOTH)
5097 if (r_type == R_386_TLS_IE)
5098 relocation += g_o_t;
5099 unresolved_reloc = FALSE;
5101 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
5103 unsigned int val, type;
5106 /* GD->IE transition. */
5107 type = *(contents + rel->r_offset - 2);
5108 val = *(contents + rel->r_offset - 1);
5112 leal foo@tlsgd(,%ebx,1), %eax
5113 call ___tls_get_addr@PLT
5116 subl $foo@gottpoff(%ebx), %eax. */
5118 roff = rel->r_offset - 3;
5123 leal foo@tlsgd(%ebx), %eax
5124 call ___tls_get_addr@PLT
5127 leal foo@tlsgd(%reg), %eax
5128 call *___tls_get_addr@GOT(%reg)
5129 which may be converted to
5130 addr32 call ___tls_get_addr
5133 subl $foo@gottpoff(%reg), %eax. */
5134 roff = rel->r_offset - 2;
5136 memcpy (contents + roff,
5137 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
5138 contents[roff + 7] = 0x80 | (val & 7);
5139 /* If foo is used only with foo@gotntpoff(%reg) and
5140 foo@indntpoff, but not with foo@gottpoff(%reg), change
5141 subl $foo@gottpoff(%reg), %eax
5143 addl $foo@gotntpoff(%reg), %eax. */
5144 if (tls_type == GOT_TLS_IE_POS)
5145 contents[roff + 6] = 0x03;
5146 bfd_put_32 (output_bfd,
5147 htab->elf.sgot->output_section->vma
5148 + htab->elf.sgot->output_offset + off
5149 - htab->elf.sgotplt->output_section->vma
5150 - htab->elf.sgotplt->output_offset,
5151 contents + roff + 8);
5152 /* Skip R_386_PLT32 and R_386_GOT32X. */
5157 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
5159 /* GDesc -> IE transition.
5160 It's originally something like:
5161 leal x@tlsdesc(%ebx), %eax
5164 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
5166 movl x@gottpoff(%ebx), %eax # before negl %eax
5168 Registers other than %eax may be set up here. */
5172 /* First, make sure it's a leal adding ebx to a 32-bit
5173 offset into any register, although it's probably
5174 almost always going to be eax. */
5175 roff = rel->r_offset;
5177 /* Now modify the instruction as appropriate. */
5178 /* To turn a leal into a movl in the form we use it, it
5179 suffices to change the first byte from 0x8d to 0x8b.
5180 aoliva FIXME: should we decide to keep the leal, all
5181 we have to do is remove the statement below, and
5182 adjust the relaxation of R_386_TLS_DESC_CALL. */
5183 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
5185 if (tls_type == GOT_TLS_IE_BOTH)
5188 bfd_put_32 (output_bfd,
5189 htab->elf.sgot->output_section->vma
5190 + htab->elf.sgot->output_offset + off
5191 - htab->elf.sgotplt->output_section->vma
5192 - htab->elf.sgotplt->output_offset,
5196 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
5198 /* GDesc -> IE transition.
5206 depending on how we transformed the TLS_GOTDESC above.
5211 roff = rel->r_offset;
5213 /* Now modify the instruction as appropriate. */
5214 if (tls_type != GOT_TLS_IE_NEG)
5217 bfd_put_8 (output_bfd, 0x66, contents + roff);
5218 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
5223 bfd_put_8 (output_bfd, 0xf7, contents + roff);
5224 bfd_put_8 (output_bfd, 0xd8, contents + roff + 1);
5234 if (! elf_i386_tls_transition (info, input_bfd,
5235 input_section, contents,
5236 symtab_hdr, sym_hashes,
5237 &r_type, GOT_UNKNOWN, rel,
5238 relend, h, r_symndx, TRUE))
5241 if (r_type != R_386_TLS_LDM)
5243 /* LD->LE transition. Change
5244 leal foo@tlsldm(%ebx) %eax
5245 call ___tls_get_addr@PLT
5249 leal 0(%esi,1), %esi
5251 leal foo@tlsldm(%reg) %eax
5252 call *___tls_get_addr@GOT(%reg)
5253 which may be converted to
5254 addr32 call ___tls_get_addr
5257 leal 0(%esi), %esi */
5258 BFD_ASSERT (r_type == R_386_TLS_LE_32);
5259 if (*(contents + rel->r_offset + 4) == 0xff
5260 || *(contents + rel->r_offset + 4) == 0x67)
5261 memcpy (contents + rel->r_offset - 2,
5262 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
5264 memcpy (contents + rel->r_offset - 2,
5265 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
5266 /* Skip R_386_PC32/R_386_PLT32. */
5272 if (htab->elf.sgot == NULL)
5275 off = htab->tls_ldm_got.offset;
5280 Elf_Internal_Rela outrel;
5282 if (htab->elf.srelgot == NULL)
5285 outrel.r_offset = (htab->elf.sgot->output_section->vma
5286 + htab->elf.sgot->output_offset + off);
5288 bfd_put_32 (output_bfd, 0,
5289 htab->elf.sgot->contents + off);
5290 bfd_put_32 (output_bfd, 0,
5291 htab->elf.sgot->contents + off + 4);
5292 outrel.r_info = ELF32_R_INFO (0, R_386_TLS_DTPMOD32);
5293 elf_append_rel (output_bfd, htab->elf.srelgot, &outrel);
5294 htab->tls_ldm_got.offset |= 1;
5296 relocation = htab->elf.sgot->output_section->vma
5297 + htab->elf.sgot->output_offset + off
5298 - htab->elf.sgotplt->output_section->vma
5299 - htab->elf.sgotplt->output_offset;
5300 unresolved_reloc = FALSE;
5303 case R_386_TLS_LDO_32:
5304 if (!bfd_link_executable (info)
5305 || (input_section->flags & SEC_CODE) == 0)
5306 relocation -= elf_i386_dtpoff_base (info);
5308 /* When converting LDO to LE, we must negate. */
5309 relocation = -elf_i386_tpoff (info, relocation);
5312 case R_386_TLS_LE_32:
5314 if (!bfd_link_executable (info))
5316 Elf_Internal_Rela outrel;
5319 outrel.r_offset = rel->r_offset
5320 + input_section->output_section->vma
5321 + input_section->output_offset;
5322 if (h != NULL && h->dynindx != -1)
5326 if (r_type == R_386_TLS_LE_32)
5327 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF32);
5329 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
5330 sreloc = elf_section_data (input_section)->sreloc;
5333 elf_append_rel (output_bfd, sreloc, &outrel);
5336 else if (r_type == R_386_TLS_LE_32)
5337 relocation = elf_i386_dtpoff_base (info) - relocation;
5339 relocation -= elf_i386_dtpoff_base (info);
5341 else if (r_type == R_386_TLS_LE_32)
5342 relocation = elf_i386_tpoff (info, relocation);
5344 relocation = -elf_i386_tpoff (info, relocation);
5351 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5352 because such sections are not SEC_ALLOC and thus ld.so will
5353 not process them. */
5354 if (unresolved_reloc
5355 && !((input_section->flags & SEC_DEBUGGING) != 0
5357 && _bfd_elf_section_offset (output_bfd, info, input_section,
5358 rel->r_offset) != (bfd_vma) -1)
5361 /* xgettext:c-format */
5362 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
5367 h->root.root.string);
5372 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5373 contents, rel->r_offset,
5376 check_relocation_error:
5377 if (r != bfd_reloc_ok)
5382 name = h->root.root.string;
5385 name = bfd_elf_string_from_elf_section (input_bfd,
5386 symtab_hdr->sh_link,
5391 name = bfd_section_name (input_bfd, sec);
5394 if (r == bfd_reloc_overflow)
5395 (*info->callbacks->reloc_overflow)
5396 (info, (h ? &h->root : NULL), name, howto->name,
5397 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
5401 /* xgettext:c-format */
5402 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
5403 input_bfd, input_section,
5404 rel->r_offset, name, (int) r);
5415 Elf_Internal_Shdr *rel_hdr;
5416 size_t deleted = rel - wrel;
5418 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
5419 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5420 if (rel_hdr->sh_size == 0)
5422 /* It is too late to remove an empty reloc section. Leave
5424 ??? What is wrong with an empty section??? */
5425 rel_hdr->sh_size = rel_hdr->sh_entsize;
5428 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
5429 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5430 input_section->reloc_count -= deleted;
5436 /* Finish up dynamic symbol handling. We set the contents of various
5437 dynamic sections here. */
5440 elf_i386_finish_dynamic_symbol (bfd *output_bfd,
5441 struct bfd_link_info *info,
5442 struct elf_link_hash_entry *h,
5443 Elf_Internal_Sym *sym)
5445 struct elf_i386_link_hash_table *htab;
5446 unsigned plt_entry_size;
5447 const struct elf_i386_backend_data *abed;
5448 struct elf_i386_link_hash_entry *eh;
5449 bfd_boolean local_undefweak;
5450 bfd_boolean use_plt_second;
5452 htab = elf_i386_hash_table (info);
5456 abed = get_elf_i386_backend_data (output_bfd);
5457 plt_entry_size = htab->plt.plt_entry_size;
5459 /* Use the second PLT section only if there is .plt section. */
5460 use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL;
5462 eh = (struct elf_i386_link_hash_entry *) h;
5463 if (eh->no_finish_dynamic_symbol)
5466 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5467 resolved undefined weak symbols in executable so that their
5468 references have value 0 at run-time. */
5469 local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
5473 if (h->plt.offset != (bfd_vma) -1)
5475 bfd_vma plt_index, plt_offset;
5477 Elf_Internal_Rela rel;
5479 asection *plt, *resolved_plt, *gotplt, *relplt;
5481 /* When building a static executable, use .iplt, .igot.plt and
5482 .rel.iplt sections for STT_GNU_IFUNC symbols. */
5483 if (htab->elf.splt != NULL)
5485 plt = htab->elf.splt;
5486 gotplt = htab->elf.sgotplt;
5487 relplt = htab->elf.srelplt;
5491 plt = htab->elf.iplt;
5492 gotplt = htab->elf.igotplt;
5493 relplt = htab->elf.irelplt;
5496 /* This symbol has an entry in the procedure linkage table. Set
5499 if ((h->dynindx == -1
5501 && !((h->forced_local || bfd_link_executable (info))
5503 && h->type == STT_GNU_IFUNC))
5509 /* Get the index in the procedure linkage table which
5510 corresponds to this symbol. This is the index of this symbol
5511 in all the symbols for which we are making plt entries. The
5512 first entry in the procedure linkage table is reserved.
5514 Get the offset into the .got table of the entry that
5515 corresponds to this function. Each .got entry is 4 bytes.
5516 The first three are reserved.
5518 For static executables, we don't reserve anything. */
5520 if (plt == htab->elf.splt)
5522 got_offset = (h->plt.offset / plt_entry_size
5523 - htab->plt.has_plt0);
5524 got_offset = (got_offset + 3) * 4;
5528 got_offset = h->plt.offset / plt_entry_size;
5529 got_offset = got_offset * 4;
5532 /* Fill in the entry in the procedure linkage table and update
5534 memcpy (plt->contents + h->plt.offset, htab->plt.plt_entry,
5539 const bfd_byte *plt_entry;
5540 if (bfd_link_pic (info))
5541 plt_entry = htab->non_lazy_plt->pic_plt_entry;
5543 plt_entry = htab->non_lazy_plt->plt_entry;
5544 memcpy (htab->plt_second->contents + eh->plt_second.offset,
5545 plt_entry, htab->non_lazy_plt->plt_entry_size);
5547 resolved_plt = htab->plt_second;
5548 plt_offset = eh->plt_second.offset;
5553 plt_offset = h->plt.offset;
5556 if (! bfd_link_pic (info))
5558 bfd_put_32 (output_bfd,
5559 (gotplt->output_section->vma
5560 + gotplt->output_offset
5562 resolved_plt->contents + plt_offset
5563 + htab->plt.plt_got_offset);
5565 if (abed->os == is_vxworks)
5567 int s, k, reloc_index;
5569 /* Create the R_386_32 relocation referencing the GOT
5570 for this PLT entry. */
5572 /* S: Current slot number (zero-based). */
5573 s = ((h->plt.offset - htab->plt.plt_entry_size)
5574 / htab->plt.plt_entry_size);
5575 /* K: Number of relocations for PLTResolve. */
5576 if (bfd_link_pic (info))
5577 k = PLTRESOLVE_RELOCS_SHLIB;
5579 k = PLTRESOLVE_RELOCS;
5580 /* Skip the PLTresolve relocations, and the relocations for
5581 the other PLT slots. */
5582 reloc_index = k + s * PLT_NON_JUMP_SLOT_RELOCS;
5583 loc = (htab->srelplt2->contents + reloc_index
5584 * sizeof (Elf32_External_Rel));
5586 rel.r_offset = (plt->output_section->vma
5587 + plt->output_offset
5588 + h->plt.offset + 2),
5589 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
5590 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5592 /* Create the R_386_32 relocation referencing the beginning of
5593 the PLT for this GOT entry. */
5594 rel.r_offset = (htab->elf.sgotplt->output_section->vma
5595 + htab->elf.sgotplt->output_offset
5597 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32);
5598 bfd_elf32_swap_reloc_out (output_bfd, &rel,
5599 loc + sizeof (Elf32_External_Rel));
5604 bfd_put_32 (output_bfd, got_offset,
5605 resolved_plt->contents + plt_offset
5606 + htab->plt.plt_got_offset);
5609 /* Fill in the entry in the global offset table. Leave the entry
5610 as zero for undefined weak symbol in PIE. No PLT relocation
5611 against undefined weak symbol in PIE. */
5612 if (!local_undefweak)
5614 if (htab->plt.has_plt0)
5615 bfd_put_32 (output_bfd,
5616 (plt->output_section->vma
5617 + plt->output_offset
5619 + htab->lazy_plt->plt_lazy_offset),
5620 gotplt->contents + got_offset);
5622 /* Fill in the entry in the .rel.plt section. */
5623 rel.r_offset = (gotplt->output_section->vma
5624 + gotplt->output_offset
5626 if (h->dynindx == -1
5627 || ((bfd_link_executable (info)
5628 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
5630 && h->type == STT_GNU_IFUNC))
5632 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
5633 h->root.root.string,
5634 h->root.u.def.section->owner);
5636 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5637 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5638 in the .got.plt section. */
5639 bfd_put_32 (output_bfd,
5640 (h->root.u.def.value
5641 + h->root.u.def.section->output_section->vma
5642 + h->root.u.def.section->output_offset),
5643 gotplt->contents + got_offset);
5644 rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
5645 /* R_386_IRELATIVE comes last. */
5646 plt_index = htab->next_irelative_index--;
5650 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
5651 plt_index = htab->next_jump_slot_index++;
5654 loc = relplt->contents + plt_index * sizeof (Elf32_External_Rel);
5655 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5657 /* Don't fill the second and third slots in PLT entry for
5658 static executables nor without PLT0. */
5659 if (plt == htab->elf.splt && htab->plt.has_plt0)
5661 bfd_put_32 (output_bfd,
5662 plt_index * sizeof (Elf32_External_Rel),
5663 plt->contents + h->plt.offset
5664 + htab->lazy_plt->plt_reloc_offset);
5665 bfd_put_32 (output_bfd,
5667 + htab->lazy_plt->plt_plt_offset + 4),
5668 (plt->contents + h->plt.offset
5669 + htab->lazy_plt->plt_plt_offset));
5673 else if (eh->plt_got.offset != (bfd_vma) -1)
5675 bfd_vma got_offset, plt_offset;
5676 asection *plt, *got, *gotplt;
5677 const bfd_byte *got_plt_entry;
5679 /* Set the entry in the GOT procedure linkage table. */
5680 plt = htab->plt_got;
5681 got = htab->elf.sgot;
5682 gotplt = htab->elf.sgotplt;
5683 got_offset = h->got.offset;
5685 if (got_offset == (bfd_vma) -1
5691 /* Fill in the entry in the GOT procedure linkage table. */
5692 if (! bfd_link_pic (info))
5694 got_plt_entry = htab->non_lazy_plt->plt_entry;
5695 got_offset += got->output_section->vma + got->output_offset;
5699 got_plt_entry = htab->non_lazy_plt->pic_plt_entry;
5700 got_offset += (got->output_section->vma
5701 + got->output_offset
5702 - gotplt->output_section->vma
5703 - gotplt->output_offset);
5706 plt_offset = eh->plt_got.offset;
5707 memcpy (plt->contents + plt_offset, got_plt_entry,
5708 htab->non_lazy_plt->plt_entry_size);
5709 bfd_put_32 (output_bfd, got_offset,
5710 (plt->contents + plt_offset
5711 + htab->non_lazy_plt->plt_got_offset));
5714 if (!local_undefweak
5716 && (h->plt.offset != (bfd_vma) -1
5717 || eh->plt_got.offset != (bfd_vma) -1))
5719 /* Mark the symbol as undefined, rather than as defined in
5720 the .plt section. Leave the value if there were any
5721 relocations where pointer equality matters (this is a clue
5722 for the dynamic linker, to make function pointer
5723 comparisons work between an application and shared
5724 library), otherwise set it to zero. If a function is only
5725 called from a binary, there is no need to slow down
5726 shared libraries because of that. */
5727 sym->st_shndx = SHN_UNDEF;
5728 if (!h->pointer_equality_needed)
5732 /* Don't generate dynamic GOT relocation against undefined weak
5733 symbol in executable. */
5734 if (h->got.offset != (bfd_vma) -1
5735 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h)->tls_type)
5736 && (elf_i386_hash_entry(h)->tls_type & GOT_TLS_IE) == 0
5737 && !local_undefweak)
5739 Elf_Internal_Rela rel;
5740 asection *relgot = htab->elf.srelgot;
5742 /* This symbol has an entry in the global offset table. Set it
5745 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
5748 rel.r_offset = (htab->elf.sgot->output_section->vma
5749 + htab->elf.sgot->output_offset
5750 + (h->got.offset & ~(bfd_vma) 1));
5752 /* If this is a static link, or it is a -Bsymbolic link and the
5753 symbol is defined locally or was forced to be local because
5754 of a version file, we just want to emit a RELATIVE reloc.
5755 The entry in the global offset table will already have been
5756 initialized in the relocate_section function. */
5758 && h->type == STT_GNU_IFUNC)
5760 if (h->plt.offset == (bfd_vma) -1)
5762 /* STT_GNU_IFUNC is referenced without PLT. */
5763 if (htab->elf.splt == NULL)
5765 /* use .rel[a].iplt section to store .got relocations
5766 in static executable. */
5767 relgot = htab->elf.irelplt;
5769 if (SYMBOL_REFERENCES_LOCAL (info, h))
5771 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
5772 h->root.root.string,
5773 h->root.u.def.section->owner);
5775 bfd_put_32 (output_bfd,
5776 (h->root.u.def.value
5777 + h->root.u.def.section->output_section->vma
5778 + h->root.u.def.section->output_offset),
5779 htab->elf.sgot->contents + h->got.offset);
5780 rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
5785 else if (bfd_link_pic (info))
5787 /* Generate R_386_GLOB_DAT. */
5795 if (!h->pointer_equality_needed)
5798 /* For non-shared object, we can't use .got.plt, which
5799 contains the real function addres if we need pointer
5800 equality. We load the GOT entry with the PLT entry. */
5801 if (htab->plt_second != NULL)
5803 plt = htab->plt_second;
5804 plt_offset = eh->plt_second.offset;
5808 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
5809 plt_offset = h->plt.offset;
5811 bfd_put_32 (output_bfd,
5812 (plt->output_section->vma
5813 + plt->output_offset + plt_offset),
5814 htab->elf.sgot->contents + h->got.offset);
5818 else if (bfd_link_pic (info)
5819 && SYMBOL_REFERENCES_LOCAL (info, h))
5821 BFD_ASSERT((h->got.offset & 1) != 0);
5822 rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
5826 BFD_ASSERT((h->got.offset & 1) == 0);
5828 bfd_put_32 (output_bfd, (bfd_vma) 0,
5829 htab->elf.sgot->contents + h->got.offset);
5830 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
5833 elf_append_rel (output_bfd, relgot, &rel);
5838 Elf_Internal_Rela rel;
5841 /* This symbol needs a copy reloc. Set it up. */
5843 if (h->dynindx == -1
5844 || (h->root.type != bfd_link_hash_defined
5845 && h->root.type != bfd_link_hash_defweak)
5846 || htab->elf.srelbss == NULL
5847 || htab->elf.sreldynrelro == NULL)
5850 rel.r_offset = (h->root.u.def.value
5851 + h->root.u.def.section->output_section->vma
5852 + h->root.u.def.section->output_offset);
5853 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
5854 if (h->root.u.def.section == htab->elf.sdynrelro)
5855 s = htab->elf.sreldynrelro;
5857 s = htab->elf.srelbss;
5858 elf_append_rel (output_bfd, s, &rel);
5864 /* Finish up local dynamic symbol handling. We set the contents of
5865 various dynamic sections here. */
5868 elf_i386_finish_local_dynamic_symbol (void **slot, void *inf)
5870 struct elf_link_hash_entry *h
5871 = (struct elf_link_hash_entry *) *slot;
5872 struct bfd_link_info *info
5873 = (struct bfd_link_info *) inf;
5875 return elf_i386_finish_dynamic_symbol (info->output_bfd, info,
5879 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5880 here since undefined weak symbol may not be dynamic and may not be
5881 called for elf_i386_finish_dynamic_symbol. */
5884 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
5887 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
5888 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5890 if (h->root.type != bfd_link_hash_undefweak
5891 || h->dynindx != -1)
5894 return elf_i386_finish_dynamic_symbol (info->output_bfd,
5898 /* Used to decide how to sort relocs in an optimal manner for the
5899 dynamic linker, before writing them out. */
5901 static enum elf_reloc_type_class
5902 elf_i386_reloc_type_class (const struct bfd_link_info *info,
5903 const asection *rel_sec ATTRIBUTE_UNUSED,
5904 const Elf_Internal_Rela *rela)
5906 bfd *abfd = info->output_bfd;
5907 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
5908 struct elf_link_hash_table *htab = elf_hash_table (info);
5910 if (htab->dynsym != NULL
5911 && htab->dynsym->contents != NULL)
5913 /* Check relocation against STT_GNU_IFUNC symbol if there are
5915 unsigned long r_symndx = ELF32_R_SYM (rela->r_info);
5916 if (r_symndx != STN_UNDEF)
5918 Elf_Internal_Sym sym;
5919 if (!bed->s->swap_symbol_in (abfd,
5920 (htab->dynsym->contents
5921 + r_symndx * sizeof (Elf32_External_Sym)),
5925 if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
5926 return reloc_class_ifunc;
5930 switch (ELF32_R_TYPE (rela->r_info))
5932 case R_386_IRELATIVE:
5933 return reloc_class_ifunc;
5934 case R_386_RELATIVE:
5935 return reloc_class_relative;
5936 case R_386_JUMP_SLOT:
5937 return reloc_class_plt;
5939 return reloc_class_copy;
5941 return reloc_class_normal;
5945 /* Finish up the dynamic sections. */
5948 elf_i386_finish_dynamic_sections (bfd *output_bfd,
5949 struct bfd_link_info *info)
5951 struct elf_i386_link_hash_table *htab;
5954 const struct elf_i386_backend_data *abed;
5956 htab = elf_i386_hash_table (info);
5960 dynobj = htab->elf.dynobj;
5961 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
5962 abed = get_elf_i386_backend_data (output_bfd);
5964 if (htab->elf.dynamic_sections_created)
5966 Elf32_External_Dyn *dyncon, *dynconend;
5968 if (sdyn == NULL || htab->elf.sgot == NULL)
5971 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5972 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5973 for (; dyncon < dynconend; dyncon++)
5975 Elf_Internal_Dyn dyn;
5978 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5983 if (abed->os == is_vxworks
5984 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
5989 s = htab->elf.sgotplt;
5990 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
5994 s = htab->elf.srelplt;
5995 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
5999 s = htab->elf.srelplt;
6000 dyn.d_un.d_val = s->size;
6004 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6007 if (htab->elf.splt && htab->elf.splt->size > 0)
6009 /* UnixWare sets the entsize of .plt to 4, although that doesn't
6010 really seem like the right value. */
6011 elf_section_data (htab->elf.splt->output_section)
6012 ->this_hdr.sh_entsize = 4;
6014 if (htab->plt.has_plt0)
6016 /* Fill in the special first entry in the procedure linkage
6018 memcpy (htab->elf.splt->contents, htab->plt.plt0_entry,
6019 htab->lazy_plt->plt0_entry_size);
6020 memset (htab->elf.splt->contents + htab->lazy_plt->plt0_entry_size,
6021 abed->plt0_pad_byte,
6022 htab->plt.plt_entry_size - htab->lazy_plt->plt0_entry_size);
6023 if (!bfd_link_pic (info))
6025 bfd_put_32 (output_bfd,
6026 (htab->elf.sgotplt->output_section->vma
6027 + htab->elf.sgotplt->output_offset
6029 htab->elf.splt->contents
6030 + htab->lazy_plt->plt0_got1_offset);
6031 bfd_put_32 (output_bfd,
6032 (htab->elf.sgotplt->output_section->vma
6033 + htab->elf.sgotplt->output_offset
6035 htab->elf.splt->contents
6036 + htab->lazy_plt->plt0_got2_offset);
6038 if (abed->os == is_vxworks)
6040 Elf_Internal_Rela rel;
6041 int num_plts = (htab->elf.splt->size
6042 / htab->plt.plt_entry_size) - 1;
6045 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6046 + 4. On IA32 we use REL relocations so the
6047 addend goes in the PLT directly. */
6048 rel.r_offset = (htab->elf.splt->output_section->vma
6049 + htab->elf.splt->output_offset
6050 + htab->lazy_plt->plt0_got1_offset);
6051 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
6053 bfd_elf32_swap_reloc_out (output_bfd, &rel,
6054 htab->srelplt2->contents);
6055 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6057 rel.r_offset = (htab->elf.splt->output_section->vma
6058 + htab->elf.splt->output_offset
6059 + htab->lazy_plt->plt0_got2_offset);
6060 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
6062 bfd_elf32_swap_reloc_out (output_bfd, &rel,
6063 htab->srelplt2->contents +
6064 sizeof (Elf32_External_Rel));
6065 /* Correct the .rel.plt.unloaded relocations. */
6066 p = htab->srelplt2->contents;
6067 if (bfd_link_pic (info))
6068 p += PLTRESOLVE_RELOCS_SHLIB * sizeof (Elf32_External_Rel);
6070 p += PLTRESOLVE_RELOCS * sizeof (Elf32_External_Rel);
6072 for (; num_plts; num_plts--)
6074 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
6075 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
6077 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
6078 p += sizeof (Elf32_External_Rel);
6080 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
6081 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
6083 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
6084 p += sizeof (Elf32_External_Rel);
6091 if (htab->plt_got != NULL && htab->plt_got->size > 0)
6092 elf_section_data (htab->plt_got->output_section)
6093 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
6095 if (htab->plt_second != NULL && htab->plt_second->size > 0)
6096 elf_section_data (htab->plt_second->output_section)
6097 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
6100 /* Fill in the first three entries in the global offset table. */
6101 if (htab->elf.sgotplt && htab->elf.sgotplt->size > 0)
6103 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
6106 (_("discarded output section: `%A'"), htab->elf.sgotplt);
6110 bfd_put_32 (output_bfd,
6112 : sdyn->output_section->vma + sdyn->output_offset),
6113 htab->elf.sgotplt->contents);
6114 bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 4);
6115 bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 8);
6117 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize = 4;
6120 /* Adjust .eh_frame for .plt section. */
6121 if (htab->plt_eh_frame != NULL
6122 && htab->plt_eh_frame->contents != NULL)
6124 if (htab->elf.splt != NULL
6125 && htab->elf.splt->size != 0
6126 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
6127 && htab->elf.splt->output_section != NULL
6128 && htab->plt_eh_frame->output_section != NULL)
6130 bfd_vma plt_start = htab->elf.splt->output_section->vma;
6131 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
6132 + htab->plt_eh_frame->output_offset
6133 + PLT_FDE_START_OFFSET;
6134 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6135 htab->plt_eh_frame->contents
6136 + PLT_FDE_START_OFFSET);
6138 if (htab->plt_eh_frame->sec_info_type
6139 == SEC_INFO_TYPE_EH_FRAME)
6141 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6143 htab->plt_eh_frame->contents))
6148 /* Adjust .eh_frame for .plt.got section. */
6149 if (htab->plt_got_eh_frame != NULL
6150 && htab->plt_got_eh_frame->contents != NULL)
6152 if (htab->plt_got != NULL
6153 && htab->plt_got->size != 0
6154 && (htab->plt_got->flags & SEC_EXCLUDE) == 0
6155 && htab->plt_got->output_section != NULL
6156 && htab->plt_got_eh_frame->output_section != NULL)
6158 bfd_vma plt_start = htab->plt_got->output_section->vma;
6159 bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma
6160 + htab->plt_got_eh_frame->output_offset
6161 + PLT_FDE_START_OFFSET;
6162 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6163 htab->plt_got_eh_frame->contents
6164 + PLT_FDE_START_OFFSET);
6166 if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
6168 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6169 htab->plt_got_eh_frame,
6170 htab->plt_got_eh_frame->contents))
6175 /* Adjust .eh_frame for the second PLT section. */
6176 if (htab->plt_second_eh_frame != NULL
6177 && htab->plt_second_eh_frame->contents != NULL)
6179 if (htab->plt_second != NULL
6180 && htab->plt_second->size != 0
6181 && (htab->plt_second->flags & SEC_EXCLUDE) == 0
6182 && htab->plt_second->output_section != NULL
6183 && htab->plt_second_eh_frame->output_section != NULL)
6185 bfd_vma plt_start = htab->plt_second->output_section->vma;
6186 bfd_vma eh_frame_start
6187 = (htab->plt_second_eh_frame->output_section->vma
6188 + htab->plt_second_eh_frame->output_offset
6189 + PLT_FDE_START_OFFSET);
6190 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6191 htab->plt_second_eh_frame->contents
6192 + PLT_FDE_START_OFFSET);
6194 if (htab->plt_second_eh_frame->sec_info_type
6195 == SEC_INFO_TYPE_EH_FRAME)
6197 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6198 htab->plt_second_eh_frame,
6199 htab->plt_second_eh_frame->contents))
6204 if (htab->elf.sgot && htab->elf.sgot->size > 0)
6205 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4;
6207 /* Fill PLT entries for undefined weak symbols in PIE. */
6208 if (bfd_link_pie (info))
6209 bfd_hash_traverse (&info->hash->table,
6210 elf_i386_pie_finish_undefweak_symbol,
6216 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6217 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6218 It has to be done before elf_link_sort_relocs is called so that
6219 dynamic relocations are properly sorted. */
6222 elf_i386_output_arch_local_syms
6223 (bfd *output_bfd ATTRIBUTE_UNUSED,
6224 struct bfd_link_info *info,
6225 void *flaginfo ATTRIBUTE_UNUSED,
6226 int (*func) (void *, const char *,
6229 struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
6231 struct elf_i386_link_hash_table *htab = elf_i386_hash_table (info);
6235 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6236 htab_traverse (htab->loc_hash_table,
6237 elf_i386_finish_local_dynamic_symbol,
6243 /* Sort relocs into address order. */
6246 compare_relocs (const void *ap, const void *bp)
6248 const arelent *a = * (const arelent **) ap;
6249 const arelent *b = * (const arelent **) bp;
6251 if (a->address > b->address)
6253 else if (a->address < b->address)
6259 enum elf_i386_plt_type
6264 plt_second = 1 << 2,
6273 enum elf_i386_plt_type type;
6274 unsigned int plt_got_offset;
6275 unsigned int plt_entry_size;
6279 /* Forward declaration. */
6280 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt;
6282 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
6283 dynamic relocations. */
6286 elf_i386_get_synthetic_symtab (bfd *abfd,
6287 long symcount ATTRIBUTE_UNUSED,
6288 asymbol **syms ATTRIBUTE_UNUSED,
6293 long size, count, i, n, len;
6295 unsigned int plt_got_offset, plt_entry_size;
6297 bfd_byte *plt_contents;
6298 long dynrelcount, relsize;
6299 arelent **dynrelbuf, *p;
6300 const struct elf_i386_lazy_plt_layout *lazy_plt;
6301 const struct elf_i386_non_lazy_plt_layout *non_lazy_plt;
6302 const struct elf_i386_lazy_plt_layout *lazy_ibt_plt;
6303 const struct elf_i386_non_lazy_plt_layout *non_lazy_ibt_plt;
6307 enum elf_i386_plt_type plt_type;
6308 struct elf_i386_plt plts[] =
6310 { ".plt", NULL, NULL, plt_unknown, 0, 0, 0 },
6311 { ".plt.got", NULL, NULL, plt_non_lazy, 0, 0, 0 },
6312 { ".plt.sec", NULL, NULL, plt_second, 0, 0, 0 },
6313 { NULL, NULL, NULL, plt_non_lazy, 0, 0, 0 }
6318 if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
6321 if (dynsymcount <= 0)
6324 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
6328 dynrelbuf = (arelent **) bfd_malloc (relsize);
6329 if (dynrelbuf == NULL)
6332 dynrelcount = bfd_canonicalize_dynamic_reloc (abfd, dynrelbuf,
6335 /* Sort the relocs by address. */
6336 qsort (dynrelbuf, dynrelcount, sizeof (arelent *), compare_relocs);
6338 non_lazy_plt = NULL;
6339 /* Silence GCC 6. */
6341 non_lazy_ibt_plt = NULL;
6342 lazy_ibt_plt = NULL;
6343 switch (get_elf_i386_backend_data (abfd)->os)
6346 non_lazy_plt = &elf_i386_non_lazy_plt;
6347 lazy_ibt_plt = &elf_i386_lazy_ibt_plt;
6348 non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt;
6351 lazy_plt = &elf_i386_lazy_plt;
6354 lazy_plt = &elf_i386_nacl_plt;
6361 for (j = 0; plts[j].name != NULL; j++)
6363 plt = bfd_get_section_by_name (abfd, plts[j].name);
6367 /* Get the PLT section contents. */
6368 plt_contents = (bfd_byte *) bfd_malloc (plt->size);
6369 if (plt_contents == NULL)
6371 if (!bfd_get_section_contents (abfd, (asection *) plt,
6372 plt_contents, 0, plt->size))
6374 free (plt_contents);
6378 /* Check what kind of PLT it is. */
6379 plt_type = plt_unknown;
6380 if (plts[j].type == plt_unknown)
6382 /* Match lazy PLT first. */
6383 if (memcmp (plt_contents, lazy_plt->plt0_entry,
6384 lazy_plt->plt0_got1_offset) == 0)
6386 /* The fist entry in the lazy IBT PLT is the same as the
6388 if (lazy_ibt_plt != NULL
6389 && (memcmp (plt_contents + lazy_ibt_plt->plt_entry_size,
6390 lazy_ibt_plt->plt_entry,
6391 lazy_ibt_plt->plt_got_offset) == 0))
6392 plt_type = plt_lazy | plt_second;
6394 plt_type = plt_lazy;
6396 else if (memcmp (plt_contents, lazy_plt->pic_plt0_entry,
6397 lazy_plt->plt0_got1_offset) == 0)
6399 /* The fist entry in the PIC lazy IBT PLT is the same as
6400 the normal PIC lazy PLT. */
6401 if (lazy_ibt_plt != NULL
6402 && (memcmp (plt_contents + lazy_ibt_plt->plt_entry_size,
6403 lazy_ibt_plt->pic_plt_entry,
6404 lazy_ibt_plt->plt_got_offset) == 0))
6405 plt_type = plt_lazy | plt_pic | plt_second;
6407 plt_type = plt_lazy | plt_pic;
6411 if (non_lazy_plt != NULL
6412 && (plt_type == plt_unknown || plt_type == plt_non_lazy))
6414 /* Match non-lazy PLT. */
6415 if (memcmp (plt_contents, non_lazy_plt->plt_entry,
6416 non_lazy_plt->plt_got_offset) == 0)
6417 plt_type = plt_non_lazy;
6418 else if (memcmp (plt_contents, non_lazy_plt->pic_plt_entry,
6419 non_lazy_plt->plt_got_offset) == 0)
6423 if ((non_lazy_ibt_plt != NULL)
6424 && (plt_type == plt_unknown || plt_type == plt_second))
6426 if (memcmp (plt_contents,
6427 non_lazy_ibt_plt->plt_entry,
6428 non_lazy_ibt_plt->plt_got_offset) == 0)
6430 /* Match IBT PLT. */
6431 plt_type = plt_second;
6432 non_lazy_plt = non_lazy_ibt_plt;
6434 else if (memcmp (plt_contents,
6435 non_lazy_ibt_plt->pic_plt_entry,
6436 non_lazy_ibt_plt->plt_got_offset) == 0)
6438 /* Match PIC IBT PLT. */
6439 plt_type = plt_second | plt_pic;
6440 non_lazy_plt = non_lazy_ibt_plt;
6444 if (plt_type == plt_unknown)
6448 plts[j].type = plt_type;
6450 if ((plt_type & plt_lazy))
6452 plts[j].plt_got_offset = lazy_plt->plt_got_offset;
6453 plts[j].plt_entry_size = lazy_plt->plt_entry_size;
6454 /* Skip PLT0 in lazy PLT. */
6459 plts[j].plt_got_offset = non_lazy_plt->plt_got_offset;
6460 plts[j].plt_entry_size = non_lazy_plt->plt_entry_size;
6464 /* Skip lazy PLT when the second PLT is used. */
6465 if ((plt_type & (plt_lazy | plt_second))
6466 == (plt_lazy | plt_second))
6470 n = plt->size / plts[j].plt_entry_size;
6475 plts[j].contents = plt_contents;
6477 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
6478 if ((plt_type & plt_pic))
6479 got_addr = (bfd_vma) -1;
6482 size = count * sizeof (asymbol);
6484 /* Allocate space for @plt suffixes. */
6486 for (i = 0; i < dynrelcount; i++)
6489 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
6491 size += sizeof ("+0x") - 1 + 8;
6494 s = *ret = (asymbol *) bfd_zmalloc (size);
6498 for (j = 0; plts[j].name != NULL; j++)
6499 if (plts[j].contents != NULL)
6500 free (plts[j].contents);
6507 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
6509 asection *sec = bfd_get_section_by_name (abfd, ".got.plt");
6511 got_addr = sec->vma;
6514 sec = bfd_get_section_by_name (abfd, ".got");
6516 got_addr = sec->vma;
6519 if (got_addr == (bfd_vma) -1)
6523 /* Check for each PLT section. */
6524 names = (char *) (s + count);
6527 for (j = 0; plts[j].name != NULL; j++)
6528 if ((plt_contents = plts[j].contents) != NULL)
6533 plt_got_offset = plts[j].plt_got_offset;
6534 plt_entry_size = plts[j].plt_entry_size;
6538 if ((plts[j].type & plt_lazy))
6540 /* Skip PLT0 in lazy PLT. */
6542 offset = plt_entry_size;
6550 /* Check each PLT entry against dynamic relocations. */
6551 for (; k < plts[j].count; k++)
6557 /* Get the GOT offset, a signed 32-bit integer. */
6558 off = H_GET_32 (abfd, (plt_contents + offset
6560 got_vma = got_addr + off;
6562 /* Binary search. */
6566 while ((min + 1) < max)
6570 mid = (min + max) / 2;
6572 if (got_vma > r->address)
6574 else if (got_vma < r->address)
6583 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6584 if (got_vma == p->address
6586 && (p->howto->type == R_386_JUMP_SLOT
6587 || p->howto->type == R_386_GLOB_DAT
6588 || p->howto->type == R_386_IRELATIVE))
6590 *s = **p->sym_ptr_ptr;
6591 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6592 set. Since we are defining a symbol, ensure one
6594 if ((s->flags & BSF_LOCAL) == 0)
6595 s->flags |= BSF_GLOBAL;
6596 s->flags |= BSF_SYNTHETIC;
6597 /* This is no longer a section symbol. */
6598 s->flags &= ~BSF_SECTION_SYM;
6600 s->the_bfd = plt->owner;
6604 len = strlen ((*p->sym_ptr_ptr)->name);
6605 memcpy (names, (*p->sym_ptr_ptr)->name, len);
6611 memcpy (names, "+0x", sizeof ("+0x") - 1);
6612 names += sizeof ("+0x") - 1;
6613 bfd_sprintf_vma (abfd, buf, p->addend);
6614 for (a = buf; *a == '0'; ++a)
6617 memcpy (names, a, size);
6620 memcpy (names, "@plt", sizeof ("@plt"));
6621 names += sizeof ("@plt");
6625 offset += plt_entry_size;
6629 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
6635 for (j = 0; plts[j].name != NULL; j++)
6636 if (plts[j].contents != NULL)
6637 free (plts[j].contents);
6644 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6647 elf_i386_hash_symbol (struct elf_link_hash_entry *h)
6649 if (h->plt.offset != (bfd_vma) -1
6651 && !h->pointer_equality_needed)
6654 return _bfd_elf_hash_symbol (h);
6657 /* Parse i386 GNU properties. */
6659 static enum elf_property_kind
6660 elf_i386_parse_gnu_properties (bfd *abfd, unsigned int type,
6661 bfd_byte *ptr, unsigned int datasz)
6667 case GNU_PROPERTY_X86_ISA_1_USED:
6668 case GNU_PROPERTY_X86_ISA_1_NEEDED:
6669 case GNU_PROPERTY_X86_FEATURE_1_AND:
6673 ((type == GNU_PROPERTY_X86_ISA_1_USED
6674 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6675 : (type == GNU_PROPERTY_X86_ISA_1_NEEDED
6676 ? _("error: %B: <corrupt x86 ISA needed size: 0x%x>")
6677 : _("error: %B: <corrupt x86 feature size: 0x%x>"))),
6679 return property_corrupt;
6681 prop = _bfd_elf_get_property (abfd, type, datasz);
6682 /* Combine properties of the same type. */
6683 prop->u.number |= bfd_h_get_32 (abfd, ptr);
6684 prop->pr_kind = property_number;
6688 return property_ignored;
6691 return property_number;
6694 /* Merge i386 GNU property BPROP with APROP. If APROP isn't NULL,
6695 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6696 should be merged with ABFD. */
6699 elf_i386_merge_gnu_properties (struct bfd_link_info *info,
6700 bfd *abfd ATTRIBUTE_UNUSED,
6701 elf_property *aprop,
6702 elf_property *bprop)
6704 unsigned int number, features;
6705 bfd_boolean updated = FALSE;
6706 unsigned int pr_type = aprop != NULL ? aprop->pr_type : bprop->pr_type;
6710 case GNU_PROPERTY_X86_ISA_1_USED:
6711 case GNU_PROPERTY_X86_ISA_1_NEEDED:
6712 if (aprop != NULL && bprop != NULL)
6714 number = aprop->u.number;
6715 aprop->u.number = number | bprop->u.number;
6716 updated = number != (unsigned int) aprop->u.number;
6720 /* Return TRUE if APROP is NULL to indicate that BPROP should
6721 be added to ABFD. */
6722 updated = aprop == NULL;
6726 case GNU_PROPERTY_X86_FEATURE_1_AND:
6727 /* Only one of APROP and BPROP can be NULL:
6728 1. APROP & BPROP when both APROP and BPROP aren't NULL.
6729 2. If APROP is NULL, remove x86 feature.
6730 3. Otherwise, do nothing.
6732 if (aprop != NULL && bprop != NULL)
6736 features = GNU_PROPERTY_X86_FEATURE_1_IBT;
6738 features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
6739 number = aprop->u.number;
6740 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6741 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6742 aprop->u.number = (number & bprop->u.number) | features;
6743 updated = number != (unsigned int) aprop->u.number;
6744 /* Remove the property if all feature bits are cleared. */
6745 if (aprop->u.number == 0)
6746 aprop->pr_kind = property_remove;
6752 features = GNU_PROPERTY_X86_FEATURE_1_IBT;
6754 features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
6757 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6758 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6761 number = aprop->u.number;
6762 aprop->u.number = number | features;
6763 updated = number != (unsigned int) aprop->u.number;
6767 bprop->u.number |= features;
6771 else if (aprop != NULL)
6773 aprop->pr_kind = property_remove;
6780 /* Never should happen. */
6787 /* Set up i386 GNU properties. Return the first relocatable ELF input
6788 with GNU properties if found. Otherwise, return NULL. */
6791 elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
6793 bfd_boolean normal_target;
6794 bfd_boolean lazy_plt;
6795 asection *sec, *pltsec;
6797 bfd_boolean use_ibt_plt;
6798 unsigned int plt_alignment, features;
6799 struct elf_i386_link_hash_table *htab;
6806 features = GNU_PROPERTY_X86_FEATURE_1_IBT;
6808 features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
6810 /* Find a normal input file with GNU property note. */
6811 for (pbfd = info->input_bfds;
6813 pbfd = pbfd->link.next)
6814 if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
6815 && bfd_count_sections (pbfd) != 0)
6819 if (elf_properties (pbfd) != NULL)
6823 if (ebfd != NULL && features)
6825 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
6826 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6827 prop = _bfd_elf_get_property (ebfd,
6828 GNU_PROPERTY_X86_FEATURE_1_AND,
6830 prop->u.number |= features;
6831 prop->pr_kind = property_number;
6833 /* Create the GNU property note section if needed. */
6836 sec = bfd_make_section_with_flags (ebfd,
6837 NOTE_GNU_PROPERTY_SECTION_NAME,
6845 info->callbacks->einfo (_("%F: failed to create GNU property section\n"));
6847 if (!bfd_set_section_alignment (ebfd, sec, 2))
6850 info->callbacks->einfo (_("%F%A: failed to align section\n"),
6854 elf_section_type (sec) = SHT_NOTE;
6858 pbfd = _bfd_elf_link_setup_gnu_properties (info);
6860 if (bfd_link_relocatable (info))
6863 htab = elf_i386_hash_table (info);
6867 use_ibt_plt = info->ibtplt || info->ibt;
6868 if (!use_ibt_plt && pbfd != NULL)
6870 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
6871 elf_property_list *p;
6873 /* The property list is sorted in order of type. */
6874 for (p = elf_properties (pbfd); p; p = p->next)
6876 if (GNU_PROPERTY_X86_FEATURE_1_AND == p->property.pr_type)
6878 use_ibt_plt = !!(p->property.u.number
6879 & GNU_PROPERTY_X86_FEATURE_1_IBT);
6882 else if (GNU_PROPERTY_X86_FEATURE_1_AND < p->property.pr_type)
6887 dynobj = htab->elf.dynobj;
6889 /* Set htab->elf.dynobj here so that there is no need to check and
6890 set it in check_relocs. */
6895 htab->elf.dynobj = pbfd;
6902 /* Find a normal input file to hold linker created
6904 for (abfd = info->input_bfds;
6906 abfd = abfd->link.next)
6907 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
6909 & (DYNAMIC | BFD_LINKER_CREATED | BFD_PLUGIN)) == 0)
6911 htab->elf.dynobj = abfd;
6918 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
6919 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
6920 canonical function address. */
6921 htab->plt.has_plt0 = 1;
6922 normal_target = FALSE;
6924 switch (get_elf_i386_backend_data (info->output_bfd)->os)
6929 htab->lazy_plt = &elf_i386_lazy_ibt_plt;
6930 htab->non_lazy_plt = &elf_i386_non_lazy_ibt_plt;
6934 htab->lazy_plt = &elf_i386_lazy_plt;
6935 htab->non_lazy_plt = &elf_i386_non_lazy_plt;
6937 normal_target = TRUE;
6940 htab->lazy_plt = &elf_i386_lazy_plt;
6941 htab->non_lazy_plt = NULL;
6942 if (!elf_vxworks_create_dynamic_sections (dynobj, info,
6944 info->callbacks->einfo (_("%F: failed to create VxWorks dynamic sections\n"));
6947 htab->lazy_plt = &elf_i386_nacl_plt;
6948 htab->non_lazy_plt = NULL;
6952 pltsec = htab->elf.splt;
6954 /* If the non-lazy PLT is available, use it for all PLT entries if
6955 there are no PLT0 or no .plt section. */
6956 if (htab->non_lazy_plt != NULL
6957 && (!htab->plt.has_plt0 || pltsec == NULL))
6960 if (bfd_link_pic (info))
6962 = htab->non_lazy_plt->pic_plt_entry;
6965 = htab->non_lazy_plt->plt_entry;
6966 htab->plt.plt_entry_size
6967 = htab->non_lazy_plt->plt_entry_size;
6968 htab->plt.plt_got_offset
6969 = htab->non_lazy_plt->plt_got_offset;
6970 htab->plt.eh_frame_plt_size
6971 = htab->non_lazy_plt->eh_frame_plt_size;
6972 htab->plt.eh_frame_plt
6973 = htab->non_lazy_plt->eh_frame_plt;
6978 if (bfd_link_pic (info))
6980 htab->plt.plt0_entry
6981 = htab->lazy_plt->pic_plt0_entry;
6983 = htab->lazy_plt->pic_plt_entry;
6987 htab->plt.plt0_entry
6988 = htab->lazy_plt->plt0_entry;
6990 = htab->lazy_plt->plt_entry;
6992 htab->plt.plt_entry_size
6993 = htab->lazy_plt->plt_entry_size;
6994 htab->plt.plt_got_offset
6995 = htab->lazy_plt->plt_got_offset;
6996 htab->plt.eh_frame_plt_size
6997 = htab->lazy_plt->eh_frame_plt_size;
6998 htab->plt.eh_frame_plt
6999 = htab->lazy_plt->eh_frame_plt;
7002 /* Return if there are no normal input files. */
7006 /* Since create_dynamic_sections isn't always called, but GOT
7007 relocations need GOT sections, create them here so that we
7008 don't need to do it in check_relocs. */
7009 if (htab->elf.sgot == NULL
7010 && !_bfd_elf_create_got_section (dynobj, info))
7011 info->callbacks->einfo (_("%F: failed to create GOT sections\n"));
7013 /* Create the ifunc sections here so that check_relocs can be
7015 if (!_bfd_elf_create_ifunc_sections (dynobj, info))
7016 info->callbacks->einfo (_("%F: failed to create ifunc sections\n"));
7018 plt_alignment = bfd_log2 (htab->plt.plt_entry_size);
7022 /* Whe creating executable, set the contents of the .interp
7023 section to the interpreter. */
7024 if (bfd_link_executable (info) && !info->nointerp)
7026 asection *s = bfd_get_linker_section (dynobj, ".interp");
7029 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7030 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7034 /* Don't change PLT section alignment for NaCl since it uses
7035 64-byte PLT entry and sets PLT section alignment to 32
7039 const struct elf_backend_data *bed
7040 = get_elf_backend_data (dynobj);
7041 flagword pltflags = (bed->dynamic_sec_flags
7046 unsigned int non_lazy_plt_alignment
7047 = bfd_log2 (htab->non_lazy_plt->plt_entry_size);
7050 if (!bfd_set_section_alignment (sec->owner, sec,
7052 goto error_alignment;
7054 /* Create the GOT procedure linkage table. */
7055 sec = bfd_make_section_anyway_with_flags (dynobj,
7059 info->callbacks->einfo (_("%F: failed to create GOT PLT section\n"));
7061 if (!bfd_set_section_alignment (dynobj, sec,
7062 non_lazy_plt_alignment))
7063 goto error_alignment;
7065 htab->plt_got = sec;
7073 /* Create the second PLT for Intel IBT support. IBT
7074 PLT is supported only for non-NaCl target and is
7075 is needed only for lazy binding. */
7076 sec = bfd_make_section_anyway_with_flags (dynobj,
7080 info->callbacks->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
7082 if (!bfd_set_section_alignment (dynobj, sec,
7084 goto error_alignment;
7087 htab->plt_second = sec;
7091 if (!info->no_ld_generated_unwind_info)
7093 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
7094 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
7095 | SEC_LINKER_CREATED);
7097 sec = bfd_make_section_anyway_with_flags (dynobj,
7101 info->callbacks->einfo (_("%F: failed to create PLT .eh_frame section\n"));
7103 if (!bfd_set_section_alignment (dynobj, sec, 2))
7104 goto error_alignment;
7106 htab->plt_eh_frame = sec;
7108 if (htab->plt_got != NULL)
7110 sec = bfd_make_section_anyway_with_flags (dynobj,
7114 info->callbacks->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
7116 if (!bfd_set_section_alignment (dynobj, sec, 2))
7117 goto error_alignment;
7119 htab->plt_got_eh_frame = sec;
7126 /* The .iplt section is used for IFUNC symbols in static
7128 sec = htab->elf.iplt;
7130 && !bfd_set_section_alignment (sec->owner, sec,
7132 goto error_alignment;
7139 elf_i386_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
7141 if (!bfd_link_relocatable (info))
7143 /* Check for ___tls_get_addr reference. */
7144 struct elf_link_hash_entry *h;
7145 h = elf_link_hash_lookup (elf_hash_table (info), "___tls_get_addr",
7146 FALSE, FALSE, FALSE);
7148 ((struct elf_i386_link_hash_entry *) h)->tls_get_addr = 1;
7151 /* Invoke the regular ELF backend linker to do all the work. */
7152 return _bfd_elf_link_check_relocs (abfd, info);
7156 elf_i386_merge_symbol_attribute (struct elf_link_hash_entry *h,
7157 const Elf_Internal_Sym *isym,
7158 bfd_boolean definition,
7159 bfd_boolean dynamic ATTRIBUTE_UNUSED)
7163 struct elf_i386_link_hash_entry *eh
7164 = (struct elf_i386_link_hash_entry *) h;
7165 eh->def_protected = (ELF_ST_VISIBILITY (isym->st_other)
7170 #define TARGET_LITTLE_SYM i386_elf32_vec
7171 #define TARGET_LITTLE_NAME "elf32-i386"
7172 #define ELF_ARCH bfd_arch_i386
7173 #define ELF_TARGET_ID I386_ELF_DATA
7174 #define ELF_MACHINE_CODE EM_386
7175 #define ELF_MAXPAGESIZE 0x1000
7177 #define elf_backend_can_gc_sections 1
7178 #define elf_backend_can_refcount 1
7179 #define elf_backend_want_got_plt 1
7180 #define elf_backend_plt_readonly 1
7181 #define elf_backend_want_plt_sym 0
7182 #define elf_backend_got_header_size 12
7183 #define elf_backend_plt_alignment 4
7184 #define elf_backend_dtrel_excludes_plt 1
7185 #define elf_backend_extern_protected_data 1
7186 #define elf_backend_caches_rawsize 1
7187 #define elf_backend_want_dynrelro 1
7189 /* Support RELA for objdump of prelink objects. */
7190 #define elf_info_to_howto elf_i386_info_to_howto_rel
7191 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
7193 #define bfd_elf32_mkobject elf_i386_mkobject
7195 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
7196 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
7197 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
7198 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
7199 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
7200 #define bfd_elf32_bfd_link_check_relocs elf_i386_link_check_relocs
7202 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
7203 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
7204 #define elf_backend_check_relocs elf_i386_check_relocs
7205 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
7206 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
7207 #define elf_backend_fake_sections elf_i386_fake_sections
7208 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
7209 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
7210 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
7211 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
7212 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
7213 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
7214 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
7215 #define elf_backend_relocate_section elf_i386_relocate_section
7216 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
7217 #define elf_backend_always_size_sections elf_i386_always_size_sections
7218 #define elf_backend_omit_section_dynsym \
7219 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7220 #define elf_backend_hash_symbol elf_i386_hash_symbol
7221 #define elf_backend_fixup_symbol elf_i386_fixup_symbol
7222 #define elf_backend_parse_gnu_properties elf_i386_parse_gnu_properties
7223 #define elf_backend_merge_gnu_properties elf_i386_merge_gnu_properties
7224 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
7225 #define elf_backend_merge_symbol_attribute elf_i386_merge_symbol_attribute
7227 #include "elf32-target.h"
7229 /* FreeBSD support. */
7231 #undef TARGET_LITTLE_SYM
7232 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
7233 #undef TARGET_LITTLE_NAME
7234 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
7236 #define ELF_OSABI ELFOSABI_FREEBSD
7238 /* The kernel recognizes executables as valid only if they carry a
7239 "FreeBSD" label in the ELF header. So we put this label on all
7240 executables and (for simplicity) also all other object files. */
7243 elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info)
7245 _bfd_elf_post_process_headers (abfd, info);
7247 #ifdef OLD_FREEBSD_ABI_LABEL
7249 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
7250 Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
7251 memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
7256 #undef elf_backend_post_process_headers
7257 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
7259 #define elf32_bed elf32_i386_fbsd_bed
7261 #undef elf_backend_add_symbol_hook
7263 #include "elf32-target.h"
7267 #undef TARGET_LITTLE_SYM
7268 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
7269 #undef TARGET_LITTLE_NAME
7270 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
7272 #undef elf_backend_post_process_headers
7274 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7275 objects won't be recognized. */
7279 #define elf32_bed elf32_i386_sol2_bed
7281 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
7283 #undef elf_backend_static_tls_alignment
7284 #define elf_backend_static_tls_alignment 8
7286 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7288 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7290 #undef elf_backend_want_plt_sym
7291 #define elf_backend_want_plt_sym 1
7293 #undef elf_backend_strtab_flags
7294 #define elf_backend_strtab_flags SHF_STRINGS
7296 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
7297 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
7298 FALSE otherwise. ISECTION is the best guess matching section from the
7299 input bfd IBFD, but it might be NULL. */
7302 elf32_i386_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
7303 bfd *obfd ATTRIBUTE_UNUSED,
7304 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
7305 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
7307 /* PR 19938: FIXME: Need to add code for setting the sh_info
7308 and sh_link fields of Solaris specific section types. */
7311 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
7312 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
7314 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
7316 The following values should be set:
7319 -----------------------------------------------------------------------------
7320 SHT_SUNW_ancillary The section header index of 0
7321 [0x6fffffee] the associated string table.
7323 SHT_SUNW_capinfo The section header index of For a dynamic object, the
7324 [0x6ffffff0] the associated symbol table. section header index of
7326 SHT_SUNW_capchain table,
7329 SHT_SUNW_symsort The section header index of 0
7330 [0x6ffffff1] the associated symbol table.
7332 SHT_SUNW_tlssort The section header index of 0
7333 [0x6ffffff2] the associated symbol table.
7335 SHT_SUNW_LDYNSYM The section header index of One greater than the
7336 [0x6ffffff3] the associated string table. symbol table index of the
7337 This index is the same string last local symbol,
7338 table used by the SHT_DYNSYM STB_LOCAL. Since
7339 section. SHT_SUNW_LDYNSYM only
7340 contains local symbols,
7341 sh_info is equivalent to
7342 the number of symbols in
7345 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
7346 [0x6ffffff5] the section header index of to named strings, the
7347 the associated section header index of
7348 SHT_SUNW_capinfo table, the associated string
7349 otherwise 0. table, otherwise 0.
7351 SHT_SUNW_move The section header index of 0
7352 [0x6ffffffa] the associated symbol table.
7357 SHT_SUNW_syminfo The section header index of The section header index
7358 [0x6ffffffc] the associated symbol table. of the associated
7361 SHT_SUNW_verdef The section header index of The number of version
7362 [0x6ffffffd] the associated string table. definitions within the
7365 SHT_SUNW_verneed The section header index of The number of version
7366 [0x6ffffffe] the associated string table. dependencies within the
7369 SHT_SUNW_versym The section header index of 0
7370 [0x6fffffff] the associated symbol table. */
7373 #undef elf_backend_copy_special_section_fields
7374 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
7376 #include "elf32-target.h"
7378 /* Intel MCU support. */
7381 elf32_iamcu_elf_object_p (bfd *abfd)
7383 /* Set the right machine number for an IAMCU elf32 file. */
7384 bfd_default_set_arch_mach (abfd, bfd_arch_iamcu, bfd_mach_i386_iamcu);
7388 #undef TARGET_LITTLE_SYM
7389 #define TARGET_LITTLE_SYM iamcu_elf32_vec
7390 #undef TARGET_LITTLE_NAME
7391 #define TARGET_LITTLE_NAME "elf32-iamcu"
7393 #define ELF_ARCH bfd_arch_iamcu
7395 #undef ELF_MACHINE_CODE
7396 #define ELF_MACHINE_CODE EM_IAMCU
7401 #define elf32_bed elf32_iamcu_bed
7403 #undef elf_backend_object_p
7404 #define elf_backend_object_p elf32_iamcu_elf_object_p
7406 #undef elf_backend_static_tls_alignment
7408 #undef elf_backend_want_plt_sym
7409 #define elf_backend_want_plt_sym 0
7411 #undef elf_backend_strtab_flags
7412 #undef elf_backend_copy_special_section_fields
7414 #include "elf32-target.h"
7416 /* Restore defaults. */
7418 #define ELF_ARCH bfd_arch_i386
7419 #undef ELF_MACHINE_CODE
7420 #define ELF_MACHINE_CODE EM_386
7422 /* Native Client support. */
7424 #undef TARGET_LITTLE_SYM
7425 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
7426 #undef TARGET_LITTLE_NAME
7427 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
7429 #define elf32_bed elf32_i386_nacl_bed
7431 #undef ELF_MAXPAGESIZE
7432 #define ELF_MAXPAGESIZE 0x10000
7434 /* Restore defaults. */
7436 #undef elf_backend_want_plt_sym
7437 #define elf_backend_want_plt_sym 0
7438 #undef elf_backend_post_process_headers
7439 #undef elf_backend_static_tls_alignment
7441 /* NaCl uses substantially different PLT entries for the same effects. */
7443 #undef elf_backend_plt_alignment
7444 #define elf_backend_plt_alignment 5
7445 #define NACL_PLT_ENTRY_SIZE 64
7446 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7448 static const bfd_byte elf_i386_nacl_plt0_entry[] =
7450 0xff, 0x35, /* pushl contents of address */
7451 0, 0, 0, 0, /* replaced with address of .got + 4. */
7452 0x8b, 0x0d, /* movl contents of address, %ecx */
7453 0, 0, 0, 0, /* replaced with address of .got + 8. */
7454 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */
7455 0xff, 0xe1 /* jmp *%ecx */
7458 static const bfd_byte elf_i386_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
7460 0x8b, 0x0d, /* movl contents of address, %ecx */
7461 0, 0, 0, 0, /* replaced with GOT slot address. */
7462 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */
7463 0xff, 0xe1, /* jmp *%ecx */
7465 /* Pad to the next 32-byte boundary with nop instructions. */
7467 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7468 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7470 /* Lazy GOT entries point here (32-byte aligned). */
7471 0x68, /* pushl immediate */
7472 0, 0, 0, 0, /* replaced with reloc offset. */
7473 0xe9, /* jmp relative */
7474 0, 0, 0, 0, /* replaced with offset to .plt. */
7476 /* Pad to the next 32-byte boundary with nop instructions. */
7477 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7478 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7482 static const bfd_byte
7483 elf_i386_nacl_pic_plt0_entry[sizeof (elf_i386_nacl_plt0_entry)] =
7485 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
7486 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
7487 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
7488 0xff, 0xe1, /* jmp *%ecx */
7490 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
7491 so pad to that size with nop instructions. */
7492 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
7495 static const bfd_byte elf_i386_nacl_pic_plt_entry[NACL_PLT_ENTRY_SIZE] =
7497 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
7498 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
7499 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
7500 0xff, 0xe1, /* jmp *%ecx */
7502 /* Pad to the next 32-byte boundary with nop instructions. */
7504 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7505 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7507 /* Lazy GOT entries point here (32-byte aligned). */
7508 0x68, /* pushl immediate */
7509 0, 0, 0, 0, /* replaced with offset into relocation table. */
7510 0xe9, /* jmp relative */
7511 0, 0, 0, 0, /* replaced with offset to start of .plt. */
7513 /* Pad to the next 32-byte boundary with nop instructions. */
7514 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7515 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7519 static const bfd_byte elf_i386_nacl_eh_frame_plt[] =
7521 #if (PLT_CIE_LENGTH != 20 \
7522 || PLT_FDE_LENGTH != 36 \
7523 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7524 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7525 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
7527 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
7528 0, 0, 0, 0, /* CIE ID */
7529 1, /* CIE version */
7530 'z', 'R', 0, /* Augmentation string */
7531 1, /* Code alignment factor */
7532 0x7c, /* Data alignment factor: -4 */
7533 8, /* Return address column */
7534 1, /* Augmentation size */
7535 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
7536 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
7537 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
7538 DW_CFA_nop, DW_CFA_nop,
7540 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
7541 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
7542 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
7543 0, 0, 0, 0, /* .plt size goes here */
7544 0, /* Augmentation size */
7545 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
7546 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7547 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
7548 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7549 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
7550 13, /* Block length */
7551 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
7552 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
7553 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
7554 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
7555 DW_CFA_nop, DW_CFA_nop
7558 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt =
7560 elf_i386_nacl_plt0_entry, /* plt0_entry */
7561 sizeof (elf_i386_nacl_plt0_entry), /* plt0_entry_size */
7562 2, /* plt0_got1_offset */
7563 8, /* plt0_got2_offset */
7564 elf_i386_nacl_plt_entry, /* plt_entry */
7565 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
7566 2, /* plt_got_offset */
7567 33, /* plt_reloc_offset */
7568 38, /* plt_plt_offset */
7569 32, /* plt_lazy_offset */
7570 elf_i386_nacl_pic_plt0_entry, /* pic_plt0_entry */
7571 elf_i386_nacl_pic_plt_entry, /* pic_plt_entry */
7572 elf_i386_nacl_eh_frame_plt, /* eh_frame_plt */
7573 sizeof (elf_i386_nacl_eh_frame_plt) /* eh_frame_plt_size */
7576 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed =
7578 0x90, /* plt0_pad_byte: nop insn */
7583 elf32_i386_nacl_elf_object_p (bfd *abfd)
7585 /* Set the right machine number for a NaCl i386 ELF32 file. */
7586 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386_nacl);
7590 #undef elf_backend_arch_data
7591 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
7593 #undef elf_backend_object_p
7594 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
7595 #undef elf_backend_modify_segment_map
7596 #define elf_backend_modify_segment_map nacl_modify_segment_map
7597 #undef elf_backend_modify_program_headers
7598 #define elf_backend_modify_program_headers nacl_modify_program_headers
7599 #undef elf_backend_final_write_processing
7600 #define elf_backend_final_write_processing nacl_final_write_processing
7602 #include "elf32-target.h"
7604 /* Restore defaults. */
7605 #undef elf_backend_object_p
7606 #undef elf_backend_modify_segment_map
7607 #undef elf_backend_modify_program_headers
7608 #undef elf_backend_final_write_processing
7610 /* VxWorks support. */
7612 #undef TARGET_LITTLE_SYM
7613 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
7614 #undef TARGET_LITTLE_NAME
7615 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
7617 #undef ELF_MAXPAGESIZE
7618 #define ELF_MAXPAGESIZE 0x1000
7619 #undef elf_backend_plt_alignment
7620 #define elf_backend_plt_alignment 4
7622 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed =
7624 0x90, /* plt0_pad_byte */
7628 #undef elf_backend_arch_data
7629 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
7631 #undef elf_backend_relocs_compatible
7632 #undef elf_backend_add_symbol_hook
7633 #define elf_backend_add_symbol_hook \
7634 elf_vxworks_add_symbol_hook
7635 #undef elf_backend_link_output_symbol_hook
7636 #define elf_backend_link_output_symbol_hook \
7637 elf_vxworks_link_output_symbol_hook
7638 #undef elf_backend_emit_relocs
7639 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7640 #undef elf_backend_final_write_processing
7641 #define elf_backend_final_write_processing \
7642 elf_vxworks_final_write_processing
7643 #undef elf_backend_static_tls_alignment
7645 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
7647 #undef elf_backend_want_plt_sym
7648 #define elf_backend_want_plt_sym 1
7651 #define elf32_bed elf32_i386_vxworks_bed
7653 #include "elf32-target.h"