1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright (C) 1993-2021 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #include "elfxx-x86.h"
22 #include "elf-vxworks.h"
24 #include "opcode/i386.h"
25 #include "libiberty.h"
27 /* 386 uses REL relocations instead of RELA. */
32 static reloc_howto_type elf_howto_table
[]=
34 HOWTO(R_386_NONE
, 0, 3, 0, false, 0, complain_overflow_dont
,
35 bfd_elf_generic_reloc
, "R_386_NONE",
36 true, 0x00000000, 0x00000000, false),
37 HOWTO(R_386_32
, 0, 2, 32, false, 0, complain_overflow_dont
,
38 bfd_elf_generic_reloc
, "R_386_32",
39 true, 0xffffffff, 0xffffffff, false),
40 HOWTO(R_386_PC32
, 0, 2, 32, true, 0, complain_overflow_dont
,
41 bfd_elf_generic_reloc
, "R_386_PC32",
42 true, 0xffffffff, 0xffffffff, true),
43 HOWTO(R_386_GOT32
, 0, 2, 32, false, 0, complain_overflow_dont
,
44 bfd_elf_generic_reloc
, "R_386_GOT32",
45 true, 0xffffffff, 0xffffffff, false),
46 HOWTO(R_386_PLT32
, 0, 2, 32, true, 0, complain_overflow_dont
,
47 bfd_elf_generic_reloc
, "R_386_PLT32",
48 true, 0xffffffff, 0xffffffff, true),
49 HOWTO(R_386_COPY
, 0, 2, 32, false, 0, complain_overflow_dont
,
50 bfd_elf_generic_reloc
, "R_386_COPY",
51 true, 0xffffffff, 0xffffffff, false),
52 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, false, 0, complain_overflow_dont
,
53 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
54 true, 0xffffffff, 0xffffffff, false),
55 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, false, 0, complain_overflow_dont
,
56 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
57 true, 0xffffffff, 0xffffffff, false),
58 HOWTO(R_386_RELATIVE
, 0, 2, 32, false, 0, complain_overflow_dont
,
59 bfd_elf_generic_reloc
, "R_386_RELATIVE",
60 true, 0xffffffff, 0xffffffff, false),
61 HOWTO(R_386_GOTOFF
, 0, 2, 32, false, 0, complain_overflow_dont
,
62 bfd_elf_generic_reloc
, "R_386_GOTOFF",
63 true, 0xffffffff, 0xffffffff, false),
64 HOWTO(R_386_GOTPC
, 0, 2, 32, true, 0, complain_overflow_dont
,
65 bfd_elf_generic_reloc
, "R_386_GOTPC",
66 true, 0xffffffff, 0xffffffff, true),
68 /* We have a gap in the reloc numbers here.
69 R_386_standard counts the number up to this point, and
70 R_386_ext_offset is the value to subtract from a reloc type of
71 R_386_16 thru R_386_PC8 to form an index into this table. */
72 #define R_386_standard (R_386_GOTPC + 1)
73 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
75 /* These relocs are a GNU extension. */
76 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, false, 0, complain_overflow_dont
,
77 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
78 true, 0xffffffff, 0xffffffff, false),
79 HOWTO(R_386_TLS_IE
, 0, 2, 32, false, 0, complain_overflow_dont
,
80 bfd_elf_generic_reloc
, "R_386_TLS_IE",
81 true, 0xffffffff, 0xffffffff, false),
82 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, false, 0, complain_overflow_dont
,
83 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
84 true, 0xffffffff, 0xffffffff, false),
85 HOWTO(R_386_TLS_LE
, 0, 2, 32, false, 0, complain_overflow_dont
,
86 bfd_elf_generic_reloc
, "R_386_TLS_LE",
87 true, 0xffffffff, 0xffffffff, false),
88 HOWTO(R_386_TLS_GD
, 0, 2, 32, false, 0, complain_overflow_dont
,
89 bfd_elf_generic_reloc
, "R_386_TLS_GD",
90 true, 0xffffffff, 0xffffffff, false),
91 HOWTO(R_386_TLS_LDM
, 0, 2, 32, false, 0, complain_overflow_dont
,
92 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
93 true, 0xffffffff, 0xffffffff, false),
94 HOWTO(R_386_16
, 0, 1, 16, false, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_386_16",
96 true, 0xffff, 0xffff, false),
97 HOWTO(R_386_PC16
, 0, 1, 16, true, 0, complain_overflow_signed
,
98 bfd_elf_generic_reloc
, "R_386_PC16",
99 true, 0xffff, 0xffff, true),
100 HOWTO(R_386_8
, 0, 0, 8, false, 0, complain_overflow_bitfield
,
101 bfd_elf_generic_reloc
, "R_386_8",
102 true, 0xff, 0xff, false),
103 HOWTO(R_386_PC8
, 0, 0, 8, true, 0, complain_overflow_signed
,
104 bfd_elf_generic_reloc
, "R_386_PC8",
105 true, 0xff, 0xff, true),
107 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
108 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
109 /* These are common with Solaris TLS implementation. */
110 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, false, 0, complain_overflow_dont
,
111 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
112 true, 0xffffffff, 0xffffffff, false),
113 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, false, 0, complain_overflow_dont
,
114 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
115 true, 0xffffffff, 0xffffffff, false),
116 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, false, 0, complain_overflow_dont
,
117 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
118 true, 0xffffffff, 0xffffffff, false),
119 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, false, 0, complain_overflow_dont
,
120 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
121 true, 0xffffffff, 0xffffffff, false),
122 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, false, 0, complain_overflow_dont
,
123 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
124 true, 0xffffffff, 0xffffffff, false),
125 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, false, 0, complain_overflow_dont
,
126 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
127 true, 0xffffffff, 0xffffffff, false),
128 HOWTO(R_386_SIZE32
, 0, 2, 32, false, 0, complain_overflow_dont
,
129 bfd_elf_generic_reloc
, "R_386_SIZE32",
130 true, 0xffffffff, 0xffffffff, false),
131 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, false, 0, complain_overflow_dont
,
132 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
133 true, 0xffffffff, 0xffffffff, false),
134 HOWTO(R_386_TLS_DESC_CALL
, 0, 3, 0, false, 0, complain_overflow_dont
,
135 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
137 HOWTO(R_386_TLS_DESC
, 0, 2, 32, false, 0, complain_overflow_dont
,
138 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
139 true, 0xffffffff, 0xffffffff, false),
140 HOWTO(R_386_IRELATIVE
, 0, 2, 32, false, 0, complain_overflow_dont
,
141 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
142 true, 0xffffffff, 0xffffffff, false),
143 HOWTO(R_386_GOT32X
, 0, 2, 32, false, 0, complain_overflow_dont
,
144 bfd_elf_generic_reloc
, "R_386_GOT32X",
145 true, 0xffffffff, 0xffffffff, false),
148 #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
149 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
151 /* GNU extension to record C++ vtable hierarchy. */
152 HOWTO (R_386_GNU_VTINHERIT
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 false, /* pc_relative */
158 complain_overflow_dont
, /* complain_on_overflow */
159 NULL
, /* special_function */
160 "R_386_GNU_VTINHERIT", /* name */
161 false, /* partial_inplace */
164 false), /* pcrel_offset */
166 /* GNU extension to record C++ vtable member usage. */
167 HOWTO (R_386_GNU_VTENTRY
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 false, /* pc_relative */
173 complain_overflow_dont
, /* complain_on_overflow */
174 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
175 "R_386_GNU_VTENTRY", /* name */
176 false, /* partial_inplace */
179 false), /* pcrel_offset */
181 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
183 /* Use complain_overflow_bitfield on R_386_PC16 for code16. */
184 HOWTO(R_386_PC16
, 0, 1, 16, true, 0, complain_overflow_bitfield
,
185 bfd_elf_generic_reloc
, "R_386_PC16",
186 true, 0xffff, 0xffff, true)
189 #define X86_PCREL_TYPE_P(TYPE) ((TYPE) == R_386_PC32)
191 #define X86_SIZE_TYPE_P(TYPE) ((TYPE) == R_386_SIZE32)
193 #ifdef DEBUG_GEN_RELOC
195 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
200 static reloc_howto_type
*
201 elf_i386_reloc_type_lookup (bfd
*abfd
,
202 bfd_reloc_code_real_type code
)
207 TRACE ("BFD_RELOC_NONE");
208 return &elf_howto_table
[R_386_NONE
];
211 TRACE ("BFD_RELOC_32");
212 return &elf_howto_table
[R_386_32
];
215 TRACE ("BFD_RELOC_CTOR");
216 return &elf_howto_table
[R_386_32
];
218 case BFD_RELOC_32_PCREL
:
219 TRACE ("BFD_RELOC_PC32");
220 return &elf_howto_table
[R_386_PC32
];
222 case BFD_RELOC_386_GOT32
:
223 TRACE ("BFD_RELOC_386_GOT32");
224 return &elf_howto_table
[R_386_GOT32
];
226 case BFD_RELOC_386_PLT32
:
227 TRACE ("BFD_RELOC_386_PLT32");
228 return &elf_howto_table
[R_386_PLT32
];
230 case BFD_RELOC_386_COPY
:
231 TRACE ("BFD_RELOC_386_COPY");
232 return &elf_howto_table
[R_386_COPY
];
234 case BFD_RELOC_386_GLOB_DAT
:
235 TRACE ("BFD_RELOC_386_GLOB_DAT");
236 return &elf_howto_table
[R_386_GLOB_DAT
];
238 case BFD_RELOC_386_JUMP_SLOT
:
239 TRACE ("BFD_RELOC_386_JUMP_SLOT");
240 return &elf_howto_table
[R_386_JUMP_SLOT
];
242 case BFD_RELOC_386_RELATIVE
:
243 TRACE ("BFD_RELOC_386_RELATIVE");
244 return &elf_howto_table
[R_386_RELATIVE
];
246 case BFD_RELOC_386_GOTOFF
:
247 TRACE ("BFD_RELOC_386_GOTOFF");
248 return &elf_howto_table
[R_386_GOTOFF
];
250 case BFD_RELOC_386_GOTPC
:
251 TRACE ("BFD_RELOC_386_GOTPC");
252 return &elf_howto_table
[R_386_GOTPC
];
254 /* These relocs are a GNU extension. */
255 case BFD_RELOC_386_TLS_TPOFF
:
256 TRACE ("BFD_RELOC_386_TLS_TPOFF");
257 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
259 case BFD_RELOC_386_TLS_IE
:
260 TRACE ("BFD_RELOC_386_TLS_IE");
261 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
263 case BFD_RELOC_386_TLS_GOTIE
:
264 TRACE ("BFD_RELOC_386_TLS_GOTIE");
265 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
267 case BFD_RELOC_386_TLS_LE
:
268 TRACE ("BFD_RELOC_386_TLS_LE");
269 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
271 case BFD_RELOC_386_TLS_GD
:
272 TRACE ("BFD_RELOC_386_TLS_GD");
273 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
275 case BFD_RELOC_386_TLS_LDM
:
276 TRACE ("BFD_RELOC_386_TLS_LDM");
277 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
280 TRACE ("BFD_RELOC_16");
281 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
283 case BFD_RELOC_16_PCREL
:
284 TRACE ("BFD_RELOC_16_PCREL");
285 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
288 TRACE ("BFD_RELOC_8");
289 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
291 case BFD_RELOC_8_PCREL
:
292 TRACE ("BFD_RELOC_8_PCREL");
293 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
295 /* Common with Sun TLS implementation. */
296 case BFD_RELOC_386_TLS_LDO_32
:
297 TRACE ("BFD_RELOC_386_TLS_LDO_32");
298 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
300 case BFD_RELOC_386_TLS_IE_32
:
301 TRACE ("BFD_RELOC_386_TLS_IE_32");
302 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
304 case BFD_RELOC_386_TLS_LE_32
:
305 TRACE ("BFD_RELOC_386_TLS_LE_32");
306 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
308 case BFD_RELOC_386_TLS_DTPMOD32
:
309 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
310 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
312 case BFD_RELOC_386_TLS_DTPOFF32
:
313 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
314 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
316 case BFD_RELOC_386_TLS_TPOFF32
:
317 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
318 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
320 case BFD_RELOC_SIZE32
:
321 TRACE ("BFD_RELOC_SIZE32");
322 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
324 case BFD_RELOC_386_TLS_GOTDESC
:
325 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
326 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
328 case BFD_RELOC_386_TLS_DESC_CALL
:
329 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
330 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
332 case BFD_RELOC_386_TLS_DESC
:
333 TRACE ("BFD_RELOC_386_TLS_DESC");
334 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
336 case BFD_RELOC_386_IRELATIVE
:
337 TRACE ("BFD_RELOC_386_IRELATIVE");
338 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
340 case BFD_RELOC_386_GOT32X
:
341 TRACE ("BFD_RELOC_386_GOT32X");
342 return &elf_howto_table
[R_386_GOT32X
- R_386_tls_offset
];
344 case BFD_RELOC_VTABLE_INHERIT
:
345 TRACE ("BFD_RELOC_VTABLE_INHERIT");
346 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
348 case BFD_RELOC_VTABLE_ENTRY
:
349 TRACE ("BFD_RELOC_VTABLE_ENTRY");
350 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
354 /* xgettext:c-format */
355 _bfd_error_handler (_("%pB: unsupported relocation type: %#x"),
357 bfd_set_error (bfd_error_bad_value
);
362 static reloc_howto_type
*
363 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
368 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
369 if (elf_howto_table
[i
].name
!= NULL
370 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
371 return &elf_howto_table
[i
];
376 static reloc_howto_type
*
377 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
381 if ((indx
= r_type
) >= R_386_standard
382 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
383 >= R_386_ext
- R_386_standard
)
384 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
385 >= R_386_ext2
- R_386_ext
)
386 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
387 >= R_386_vt
- R_386_ext2
))
389 /* PR 17512: file: 0f67f69d. */
390 if (elf_howto_table
[indx
].type
!= r_type
)
393 /* Use complain_overflow_bitfield on R_386_PC16 for code16. */
394 if (r_type
== (unsigned int) R_386_PC16
&& elf_x86_has_code16 (abfd
))
395 indx
= ARRAY_SIZE (elf_howto_table
) - 1;
397 return &elf_howto_table
[indx
];
401 elf_i386_info_to_howto_rel (bfd
*abfd
,
403 Elf_Internal_Rela
*dst
)
405 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
407 if ((cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
))
410 /* xgettext:c-format */
411 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
413 bfd_set_error (bfd_error_bad_value
);
420 /* Return whether a symbol name implies a local label. The UnixWare
421 2.1 cc generates temporary symbols that start with .X, so we
422 recognize them here. FIXME: do other SVR4 compilers also use .X?.
423 If so, we should move the .X recognition into
424 _bfd_elf_is_local_label_name. */
427 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
429 if (name
[0] == '.' && name
[1] == 'X')
432 return _bfd_elf_is_local_label_name (abfd
, name
);
435 /* Support for core dump NOTE sections. */
438 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
443 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
445 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
451 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
454 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
458 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
462 switch (note
->descsz
)
467 case 144: /* Linux/i386 */
469 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
472 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
482 /* Make a ".reg/999" section. */
483 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
484 size
, note
->descpos
+ offset
);
488 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
490 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
492 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
497 elf_tdata (abfd
)->core
->program
498 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
499 elf_tdata (abfd
)->core
->command
500 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
504 switch (note
->descsz
)
509 case 124: /* Linux/i386 elf_prpsinfo. */
510 elf_tdata (abfd
)->core
->pid
511 = bfd_get_32 (abfd
, note
->descdata
+ 12);
512 elf_tdata (abfd
)->core
->program
513 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
514 elf_tdata (abfd
)->core
->command
515 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
519 /* Note that for some reason, a spurious space is tacked
520 onto the end of the args in some (at least one anyway)
521 implementations, so strip it off if it exists. */
523 char *command
= elf_tdata (abfd
)->core
->command
;
524 int n
= strlen (command
);
526 if (0 < n
&& command
[n
- 1] == ' ')
527 command
[n
- 1] = '\0';
533 /* Functions for the i386 ELF linker.
535 In order to gain some understanding of code in this file without
536 knowing all the intricate details of the linker, note the
539 Functions named elf_i386_* are called by external routines, other
540 functions are only called locally. elf_i386_* functions appear
541 in this file more or less in the order in which they are called
542 from external routines. eg. elf_i386_check_relocs is called
543 early in the link process, elf_i386_finish_dynamic_sections is
544 one of the last functions. */
546 /* The size in bytes of an entry in the lazy procedure linkage table. */
548 #define LAZY_PLT_ENTRY_SIZE 16
550 /* The size in bytes of an entry in the non-lazy procedure linkage
553 #define NON_LAZY_PLT_ENTRY_SIZE 8
555 /* The first entry in an absolute lazy procedure linkage table looks
556 like this. See the SVR4 ABI i386 supplement to see how this works.
557 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
559 static const bfd_byte elf_i386_lazy_plt0_entry
[12] =
561 0xff, 0x35, /* pushl contents of address */
562 0, 0, 0, 0, /* replaced with address of .got + 4. */
563 0xff, 0x25, /* jmp indirect */
564 0, 0, 0, 0 /* replaced with address of .got + 8. */
567 /* Subsequent entries in an absolute lazy procedure linkage table look
570 static const bfd_byte elf_i386_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
572 0xff, 0x25, /* jmp indirect */
573 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
574 0x68, /* pushl immediate */
575 0, 0, 0, 0, /* replaced with offset into relocation table. */
576 0xe9, /* jmp relative */
577 0, 0, 0, 0 /* replaced with offset to start of .plt. */
580 /* The first entry in a PIC lazy procedure linkage table look like
581 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
582 lazy_plt->plt0_pad_byte. */
584 static const bfd_byte elf_i386_pic_lazy_plt0_entry
[12] =
586 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
587 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
590 /* Subsequent entries in a PIC lazy procedure linkage table look like
593 static const bfd_byte elf_i386_pic_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
595 0xff, 0xa3, /* jmp *offset(%ebx) */
596 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
597 0x68, /* pushl immediate */
598 0, 0, 0, 0, /* replaced with offset into relocation table. */
599 0xe9, /* jmp relative */
600 0, 0, 0, 0 /* replaced with offset to start of .plt. */
603 /* Entries in the non-lazy procedure linkage table look like this. */
605 static const bfd_byte elf_i386_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
607 0xff, 0x25, /* jmp indirect */
608 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
609 0x66, 0x90 /* xchg %ax,%ax */
612 /* Entries in the PIC non-lazy procedure linkage table look like
615 static const bfd_byte elf_i386_pic_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
617 0xff, 0xa3, /* jmp *offset(%ebx) */
618 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
619 0x66, 0x90 /* xchg %ax,%ax */
622 /* The first entry in an absolute IBT-enabled lazy procedure linkage
623 table looks like this. */
625 static const bfd_byte elf_i386_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
627 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
628 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
629 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
632 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
633 table look like this. Subsequent entries for a PIC IBT-enabled lazy
634 procedure linkage table are the same. */
636 static const bfd_byte elf_i386_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
638 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
639 0x68, 0, 0, 0, 0, /* pushl immediate */
640 0xe9, 0, 0, 0, 0, /* jmp relative */
641 0x66, 0x90 /* xchg %ax,%ax */
644 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
647 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
649 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
650 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
651 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
654 /* Entries for branches with IBT-enabled in the absolute non-lazey
655 procedure linkage table look like this. They have the same size
656 as the lazy PLT entry. */
658 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
660 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
661 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
662 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
665 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
666 linkage table look like this. They have the same size as the lazy
669 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
671 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
672 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
673 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
676 /* .eh_frame covering the lazy .plt section. */
678 static const bfd_byte elf_i386_eh_frame_lazy_plt
[] =
680 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
681 0, 0, 0, 0, /* CIE ID */
683 'z', 'R', 0, /* Augmentation string */
684 1, /* Code alignment factor */
685 0x7c, /* Data alignment factor */
686 8, /* Return address column */
687 1, /* Augmentation size */
688 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
689 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
690 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
691 DW_CFA_nop
, DW_CFA_nop
,
693 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
694 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
695 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
696 0, 0, 0, 0, /* .plt size goes here */
697 0, /* Augmentation size */
698 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
699 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
700 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
701 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
702 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
703 11, /* Block length */
704 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
705 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
706 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
707 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
708 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
711 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
713 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt
[] =
715 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
716 0, 0, 0, 0, /* CIE ID */
718 'z', 'R', 0, /* Augmentation string */
719 1, /* Code alignment factor */
720 0x7c, /* Data alignment factor */
721 8, /* Return address column */
722 1, /* Augmentation size */
723 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
724 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
725 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
726 DW_CFA_nop
, DW_CFA_nop
,
728 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
729 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
730 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
731 0, 0, 0, 0, /* .plt size goes here */
732 0, /* Augmentation size */
733 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
734 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
735 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
736 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
737 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
738 11, /* Block length */
739 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
740 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
741 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
742 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
743 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
746 /* .eh_frame covering the non-lazy .plt section. */
748 static const bfd_byte elf_i386_eh_frame_non_lazy_plt
[] =
750 #define PLT_GOT_FDE_LENGTH 16
751 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
752 0, 0, 0, 0, /* CIE ID */
754 'z', 'R', 0, /* Augmentation string */
755 1, /* Code alignment factor */
756 0x7c, /* Data alignment factor */
757 8, /* Return address column */
758 1, /* Augmentation size */
759 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
760 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
761 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
762 DW_CFA_nop
, DW_CFA_nop
,
764 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
765 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
766 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
767 0, 0, 0, 0, /* non-lazy .plt size goes here */
768 0, /* Augmentation size */
769 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
772 /* These are the standard parameters. */
773 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt
=
775 elf_i386_lazy_plt0_entry
, /* plt0_entry */
776 sizeof (elf_i386_lazy_plt0_entry
), /* plt0_entry_size */
777 elf_i386_lazy_plt_entry
, /* plt_entry */
778 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
779 NULL
, /* plt_tlsdesc_entry */
780 0, /* plt_tlsdesc_entry_size*/
781 0, /* plt_tlsdesc_got1_offset */
782 0, /* plt_tlsdesc_got2_offset */
783 0, /* plt_tlsdesc_got1_insn_end */
784 0, /* plt_tlsdesc_got2_insn_end */
785 2, /* plt0_got1_offset */
786 8, /* plt0_got2_offset */
787 0, /* plt0_got2_insn_end */
788 2, /* plt_got_offset */
789 7, /* plt_reloc_offset */
790 12, /* plt_plt_offset */
791 0, /* plt_got_insn_size */
792 0, /* plt_plt_insn_end */
793 6, /* plt_lazy_offset */
794 elf_i386_pic_lazy_plt0_entry
, /* pic_plt0_entry */
795 elf_i386_pic_lazy_plt_entry
, /* pic_plt_entry */
796 elf_i386_eh_frame_lazy_plt
, /* eh_frame_plt */
797 sizeof (elf_i386_eh_frame_lazy_plt
) /* eh_frame_plt_size */
800 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt
=
802 elf_i386_non_lazy_plt_entry
, /* plt_entry */
803 elf_i386_pic_non_lazy_plt_entry
, /* pic_plt_entry */
804 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
805 2, /* plt_got_offset */
806 0, /* plt_got_insn_size */
807 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
808 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
811 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt
=
813 elf_i386_lazy_ibt_plt0_entry
, /* plt0_entry */
814 sizeof (elf_i386_lazy_ibt_plt0_entry
), /* plt0_entry_size */
815 elf_i386_lazy_ibt_plt_entry
, /* plt_entry */
816 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
817 NULL
, /* plt_tlsdesc_entry */
818 0, /* plt_tlsdesc_entry_size*/
819 0, /* plt_tlsdesc_got1_offset */
820 0, /* plt_tlsdesc_got2_offset */
821 0, /* plt_tlsdesc_got1_insn_end */
822 0, /* plt_tlsdesc_got2_insn_end */
823 2, /* plt0_got1_offset */
824 8, /* plt0_got2_offset */
825 0, /* plt0_got2_insn_end */
826 4+2, /* plt_got_offset */
827 4+1, /* plt_reloc_offset */
828 4+6, /* plt_plt_offset */
829 0, /* plt_got_insn_size */
830 0, /* plt_plt_insn_end */
831 0, /* plt_lazy_offset */
832 elf_i386_pic_lazy_ibt_plt0_entry
, /* pic_plt0_entry */
833 elf_i386_lazy_ibt_plt_entry
, /* pic_plt_entry */
834 elf_i386_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
835 sizeof (elf_i386_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
838 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt
=
840 elf_i386_non_lazy_ibt_plt_entry
, /* plt_entry */
841 elf_i386_pic_non_lazy_ibt_plt_entry
,/* pic_plt_entry */
842 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
843 4+2, /* plt_got_offset */
844 0, /* plt_got_insn_size */
845 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
846 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
850 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
851 for the PLTResolve stub and then for each PLT entry. */
852 #define PLTRESOLVE_RELOCS_SHLIB 0
853 #define PLTRESOLVE_RELOCS 2
854 #define PLT_NON_JUMP_SLOT_RELOCS 2
856 /* Return TRUE if the TLS access code sequence support transition
860 elf_i386_check_tls_transition (asection
*sec
,
862 Elf_Internal_Shdr
*symtab_hdr
,
863 struct elf_link_hash_entry
**sym_hashes
,
865 const Elf_Internal_Rela
*rel
,
866 const Elf_Internal_Rela
*relend
)
868 unsigned int val
, type
, reg
;
869 unsigned long r_symndx
;
870 struct elf_link_hash_entry
*h
;
875 offset
= rel
->r_offset
;
880 if (offset
< 2 || (rel
+ 1) >= relend
)
883 indirect_call
= false;
884 call
= contents
+ offset
+ 4;
887 if (r_type
== R_386_TLS_GD
)
889 /* Check transition from GD access model. Only
890 leal foo@tlsgd(,%ebx,1), %eax
891 call ___tls_get_addr@PLT
893 leal foo@tlsgd(%ebx) %eax
894 call ___tls_get_addr@PLT
897 leal foo@tlsgd(%reg), %eax
898 call *___tls_get_addr@GOT(%reg)
899 which may be converted to
900 addr32 call ___tls_get_addr
901 can transit to different access model. */
902 if ((offset
+ 10) > sec
->size
903 || (type
!= 0x8d && type
!= 0x04))
908 /* leal foo@tlsgd(,%ebx,1), %eax
909 call ___tls_get_addr@PLT */
913 if (*(call
- 7) != 0x8d
921 leal foo@tlsgd(%ebx), %eax
922 call ___tls_get_addr@PLT
925 leal foo@tlsgd(%reg), %eax
926 call *___tls_get_addr@GOT(%reg)
927 which may be converted to
928 addr32 call ___tls_get_addr
930 %eax can't be used as the GOT base register since it
931 is used to pass parameter to ___tls_get_addr. */
933 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
936 indirect_call
= call
[0] == 0xff;
937 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
938 && !(call
[0] == 0x67 && call
[1] == 0xe8)
940 && (call
[1] & 0xf8) == 0x90
941 && (call
[1] & 0x7) == reg
))
947 /* Check transition from LD access model. Only
948 leal foo@tlsldm(%ebx), %eax
949 call ___tls_get_addr@PLT
951 leal foo@tlsldm(%reg), %eax
952 call *___tls_get_addr@GOT(%reg)
953 which may be converted to
954 addr32 call ___tls_get_addr
955 can transit to different access model. */
956 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
959 /* %eax can't be used as the GOT base register since it is
960 used to pass parameter to ___tls_get_addr. */
962 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
965 indirect_call
= call
[0] == 0xff;
966 if (!(reg
== 3 && call
[0] == 0xe8)
967 && !(call
[0] == 0x67 && call
[1] == 0xe8)
969 && (call
[1] & 0xf8) == 0x90
970 && (call
[1] & 0x7) == reg
))
974 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
975 if (r_symndx
< symtab_hdr
->sh_info
)
978 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
980 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
982 else if (indirect_call
)
983 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
985 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
986 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
989 /* Check transition from IE access model:
990 movl foo@indntpoff(%rip), %eax
991 movl foo@indntpoff(%rip), %reg
992 addl foo@indntpoff(%rip), %reg
995 if (offset
< 1 || (offset
+ 4) > sec
->size
)
998 /* Check "movl foo@tpoff(%rip), %eax" first. */
999 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1006 /* Check movl|addl foo@tpoff(%rip), %reg. */
1007 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1008 return ((type
== 0x8b || type
== 0x03)
1009 && (val
& 0xc7) == 0x05);
1011 case R_386_TLS_GOTIE
:
1012 case R_386_TLS_IE_32
:
1013 /* Check transition from {IE_32,GOTIE} access model:
1014 subl foo@{tpoff,gontoff}(%reg1), %reg2
1015 movl foo@{tpoff,gontoff}(%reg1), %reg2
1016 addl foo@{tpoff,gontoff}(%reg1), %reg2
1019 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1022 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1023 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1026 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1027 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1029 case R_386_TLS_GOTDESC
:
1030 /* Check transition from GDesc access model:
1031 leal x@tlsdesc(%ebx), %eax
1033 Make sure it's a leal adding ebx to a 32-bit offset
1034 into any register, although it's probably almost always
1037 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1040 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1043 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1044 return (val
& 0xc7) == 0x83;
1046 case R_386_TLS_DESC_CALL
:
1047 /* Check transition from GDesc access model:
1048 call *x@tlsdesc(%eax)
1050 if (offset
+ 2 <= sec
->size
)
1052 /* Make sure that it's a call *x@tlsdesc(%eax). */
1053 call
= contents
+ offset
;
1054 return call
[0] == 0xff && call
[1] == 0x10;
1064 /* Return TRUE if the TLS access transition is OK or no transition
1065 will be performed. Update R_TYPE if there is a transition. */
1068 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1069 asection
*sec
, bfd_byte
*contents
,
1070 Elf_Internal_Shdr
*symtab_hdr
,
1071 struct elf_link_hash_entry
**sym_hashes
,
1072 unsigned int *r_type
, int tls_type
,
1073 const Elf_Internal_Rela
*rel
,
1074 const Elf_Internal_Rela
*relend
,
1075 struct elf_link_hash_entry
*h
,
1076 unsigned long r_symndx
,
1077 bool from_relocate_section
)
1079 unsigned int from_type
= *r_type
;
1080 unsigned int to_type
= from_type
;
1083 /* Skip TLS transition for functions. */
1085 && (h
->type
== STT_FUNC
1086 || h
->type
== STT_GNU_IFUNC
))
1092 case R_386_TLS_GOTDESC
:
1093 case R_386_TLS_DESC_CALL
:
1094 case R_386_TLS_IE_32
:
1096 case R_386_TLS_GOTIE
:
1097 if (bfd_link_executable (info
))
1100 to_type
= R_386_TLS_LE_32
;
1101 else if (from_type
!= R_386_TLS_IE
1102 && from_type
!= R_386_TLS_GOTIE
)
1103 to_type
= R_386_TLS_IE_32
;
1106 /* When we are called from elf_i386_relocate_section, there may
1107 be additional transitions based on TLS_TYPE. */
1108 if (from_relocate_section
)
1110 unsigned int new_to_type
= to_type
;
1112 if (TLS_TRANSITION_IE_TO_LE_P (info
, h
, tls_type
))
1113 new_to_type
= R_386_TLS_LE_32
;
1115 if (to_type
== R_386_TLS_GD
1116 || to_type
== R_386_TLS_GOTDESC
1117 || to_type
== R_386_TLS_DESC_CALL
)
1119 if (tls_type
== GOT_TLS_IE_POS
)
1120 new_to_type
= R_386_TLS_GOTIE
;
1121 else if (tls_type
& GOT_TLS_IE
)
1122 new_to_type
= R_386_TLS_IE_32
;
1125 /* We checked the transition before when we were called from
1126 elf_i386_check_relocs. We only want to check the new
1127 transition which hasn't been checked before. */
1128 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1129 to_type
= new_to_type
;
1135 if (bfd_link_executable (info
))
1136 to_type
= R_386_TLS_LE_32
;
1143 /* Return TRUE if there is no transition. */
1144 if (from_type
== to_type
)
1147 /* Check if the transition can be performed. */
1149 && ! elf_i386_check_tls_transition (sec
, contents
,
1150 symtab_hdr
, sym_hashes
,
1151 from_type
, rel
, relend
))
1153 reloc_howto_type
*from
, *to
;
1156 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1157 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1160 name
= h
->root
.root
.string
;
1163 struct elf_x86_link_hash_table
*htab
;
1165 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1170 Elf_Internal_Sym
*isym
;
1172 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
1174 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1179 /* xgettext:c-format */
1180 (_("%pB: TLS transition from %s to %s against `%s'"
1181 " at %#" PRIx64
" in section `%pA' failed"),
1182 abfd
, from
->name
, to
->name
, name
,
1183 (uint64_t) rel
->r_offset
, sec
);
1184 bfd_set_error (bfd_error_bad_value
);
1192 /* With the local symbol, foo, we convert
1193 mov foo@GOT[(%reg1)], %reg2
1195 lea foo[@GOTOFF(%reg1)], %reg2
1197 call/jmp *foo@GOT[(%reg)]
1199 nop call foo/jmp foo nop
1200 When PIC is false, convert
1201 test %reg1, foo@GOT[(%reg2)]
1205 binop foo@GOT[(%reg1)], %reg2
1208 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1213 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1215 unsigned int *r_type_p
,
1216 Elf_Internal_Rela
*irel
,
1217 struct elf_link_hash_entry
*h
,
1219 struct bfd_link_info
*link_info
)
1221 struct elf_x86_link_hash_table
*htab
;
1222 unsigned int opcode
;
1225 Elf_Internal_Sym
*isym
;
1226 unsigned int addend
;
1232 unsigned int r_type
;
1233 unsigned int r_symndx
;
1234 bfd_vma roff
= irel
->r_offset
;
1236 struct elf_x86_link_hash_entry
*eh
;
1241 /* Addend for R_386_GOT32X relocations must be 0. */
1242 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1246 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
1247 is_pic
= bfd_link_pic (link_info
);
1250 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1252 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1253 baseless
= (modrm
& 0xc7) == 0x5;
1257 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1258 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1260 abs_symbol
= ABS_SYMBOL_P (h
);
1265 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, abfd
,
1267 abs_symbol
= isym
->st_shndx
== SHN_ABS
;
1270 if (baseless
&& is_pic
)
1272 /* For PIC, disallow R_386_GOT32X without a base register
1273 since we don't know what the GOT base is. */
1277 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1279 name
= h
->root
.root
.string
;
1282 /* xgettext:c-format */
1283 (_("%pB: direct GOT relocation R_386_GOT32X against `%s' without base"
1284 " register can not be used when making a shared object"),
1289 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1291 /* Convert to R_386_32 if PIC is false or there is no base
1293 to_reloc_32
= !is_pic
|| baseless
;
1295 eh
= elf_x86_hash_entry (h
);
1297 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1301 if (opcode
== 0x0ff)
1302 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1303 goto convert_branch
;
1305 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1306 "test %reg1, foo@GOT(%reg2)" and
1307 "binop foo@GOT[(%reg1)], %reg2". */
1311 /* Undefined weak symbol is only bound locally in executable
1312 and its reference is resolved as 0. */
1313 if (h
->root
.type
== bfd_link_hash_undefweak
1319 /* No direct branch to 0 for PIC. */
1323 goto convert_branch
;
1327 /* We can convert load of address 0 to R_386_32. */
1335 /* We have "call/jmp *foo@GOT[(%reg)]". */
1336 if ((h
->root
.type
== bfd_link_hash_defined
1337 || h
->root
.type
== bfd_link_hash_defweak
)
1340 /* The function is locally defined. */
1342 /* Convert R_386_GOT32X to R_386_PC32. */
1343 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1345 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1348 /* To support TLS optimization, always use addr32 prefix
1349 for "call *___tls_get_addr@GOT(%reg)". */
1350 if (eh
&& eh
->tls_get_addr
)
1353 nop_offset
= irel
->r_offset
- 2;
1357 nop
= htab
->params
->call_nop_byte
;
1358 if (htab
->params
->call_nop_as_suffix
)
1360 nop_offset
= roff
+ 3;
1361 irel
->r_offset
-= 1;
1364 nop_offset
= roff
- 2;
1369 /* Convert to "jmp foo nop". */
1372 nop_offset
= roff
+ 3;
1373 irel
->r_offset
-= 1;
1376 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1377 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1378 /* When converting to PC-relative relocation, we
1379 need to adjust addend by -4. */
1380 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1381 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1382 *r_type_p
= R_386_PC32
;
1388 /* We have "mov foo@GOT[(%re1g)], %reg2",
1389 "test %reg1, foo@GOT(%reg2)" and
1390 "binop foo@GOT[(%reg1)], %reg2".
1392 Avoid optimizing _DYNAMIC since ld.so may use its
1393 link-time address. */
1394 if (h
== htab
->elf
.hdynamic
)
1397 /* def_regular is set by an assignment in a linker script in
1398 bfd_elf_record_link_assignment. start_stop is set on
1399 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1403 || h
->root
.type
== bfd_link_hash_defined
1404 || h
->root
.type
== bfd_link_hash_defweak
)
1410 if (abs_symbol
&& local_ref
)
1415 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1416 "mov $foo, %reg2" with R_386_32. */
1418 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1419 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1424 /* Convert "mov foo@GOT(%reg1), %reg2" to
1425 "lea foo@GOTOFF(%reg1), %reg2". */
1426 r_type
= R_386_GOTOFF
;
1432 /* Only R_386_32 is supported. */
1438 /* Convert "test %reg1, foo@GOT(%reg2)" to
1439 "test $foo, %reg1". */
1440 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1445 /* Convert "binop foo@GOT(%reg1), %reg2" to
1446 "binop $foo, %reg2". */
1448 | (modrm
& 0x38) >> 3
1452 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1456 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1457 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1466 /* Rename some of the generic section flags to better document how they
1468 #define check_relocs_failed sec_flg0
1470 /* Look through the relocs for a section during the first phase, and
1471 calculate needed space in the global offset table, procedure linkage
1472 table, and dynamic reloc sections. */
1475 elf_i386_check_relocs (bfd
*abfd
,
1476 struct bfd_link_info
*info
,
1478 const Elf_Internal_Rela
*relocs
)
1480 struct elf_x86_link_hash_table
*htab
;
1481 Elf_Internal_Shdr
*symtab_hdr
;
1482 struct elf_link_hash_entry
**sym_hashes
;
1483 const Elf_Internal_Rela
*rel
;
1484 const Elf_Internal_Rela
*rel_end
;
1489 if (bfd_link_relocatable (info
))
1492 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1495 sec
->check_relocs_failed
= 1;
1499 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1501 /* Get the section contents. */
1502 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1503 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1504 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1506 sec
->check_relocs_failed
= 1;
1510 symtab_hdr
= &elf_symtab_hdr (abfd
);
1511 sym_hashes
= elf_sym_hashes (abfd
);
1517 rel_end
= relocs
+ sec
->reloc_count
;
1518 for (rel
= relocs
; rel
< rel_end
; rel
++)
1520 unsigned int r_type
;
1521 unsigned int r_symndx
;
1522 struct elf_link_hash_entry
*h
;
1523 struct elf_x86_link_hash_entry
*eh
;
1524 Elf_Internal_Sym
*isym
;
1529 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1530 r_type
= ELF32_R_TYPE (rel
->r_info
);
1532 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1534 /* xgettext:c-format */
1535 _bfd_error_handler (_("%pB: bad symbol index: %d"),
1540 if (r_symndx
< symtab_hdr
->sh_info
)
1542 /* A local symbol. */
1543 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
1548 /* Check relocation against local STT_GNU_IFUNC symbol. */
1549 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1551 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
, true);
1555 /* Fake a STT_GNU_IFUNC symbol. */
1556 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1558 h
->type
= STT_GNU_IFUNC
;
1561 h
->forced_local
= 1;
1562 h
->root
.type
= bfd_link_hash_defined
;
1570 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1571 while (h
->root
.type
== bfd_link_hash_indirect
1572 || h
->root
.type
== bfd_link_hash_warning
)
1573 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1576 eh
= (struct elf_x86_link_hash_entry
*) h
;
1579 if (r_type
== R_386_GOTOFF
)
1582 /* It is referenced by a non-shared object. */
1586 if (r_type
== R_386_GOT32X
1587 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1589 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
1590 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
1596 if (!_bfd_elf_x86_valid_reloc_p (sec
, info
, htab
, rel
, h
, isym
,
1597 symtab_hdr
, &no_dynreloc
))
1600 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1601 symtab_hdr
, sym_hashes
,
1602 &r_type
, GOT_UNKNOWN
,
1603 rel
, rel_end
, h
, r_symndx
, false))
1606 /* Check if _GLOBAL_OFFSET_TABLE_ is referenced. */
1607 if (h
== htab
->elf
.hgot
)
1608 htab
->got_referenced
= true;
1613 htab
->tls_ld_or_ldm_got
.refcount
= 1;
1617 /* This symbol requires a procedure linkage table entry. We
1618 actually build the entry in adjust_dynamic_symbol,
1619 because this might be a case of linking PIC code which is
1620 never referenced by a dynamic object, in which case we
1621 don't need to generate a procedure linkage table entry
1624 /* If this is a local symbol, we resolve it directly without
1625 creating a procedure linkage table entry. */
1629 eh
->zero_undefweak
&= 0x2;
1631 h
->plt
.refcount
= 1;
1638 case R_386_TLS_IE_32
:
1640 case R_386_TLS_GOTIE
:
1641 if (!bfd_link_executable (info
))
1642 info
->flags
|= DF_STATIC_TLS
;
1648 case R_386_TLS_GOTDESC
:
1649 case R_386_TLS_DESC_CALL
:
1650 /* This symbol requires a global offset table entry. */
1652 int tls_type
, old_tls_type
;
1659 tls_type
= GOT_NORMAL
;
1661 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1662 case R_386_TLS_GOTDESC
:
1663 case R_386_TLS_DESC_CALL
:
1664 tls_type
= GOT_TLS_GDESC
; break;
1665 case R_386_TLS_IE_32
:
1666 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1667 tls_type
= GOT_TLS_IE_NEG
;
1669 /* If this is a GD->IE transition, we may use either of
1670 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1671 tls_type
= GOT_TLS_IE
;
1674 case R_386_TLS_GOTIE
:
1675 tls_type
= GOT_TLS_IE_POS
; break;
1680 h
->got
.refcount
= 1;
1681 old_tls_type
= elf_x86_hash_entry (h
)->tls_type
;
1685 bfd_signed_vma
*local_got_refcounts
;
1687 /* This is a global offset table entry for a local symbol. */
1688 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1689 if (local_got_refcounts
== NULL
)
1693 size
= symtab_hdr
->sh_info
;
1694 size
*= (sizeof (bfd_signed_vma
)
1695 + sizeof (bfd_vma
) + sizeof(char));
1696 local_got_refcounts
= (bfd_signed_vma
*)
1697 bfd_zalloc (abfd
, size
);
1698 if (local_got_refcounts
== NULL
)
1700 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1701 elf_x86_local_tlsdesc_gotent (abfd
)
1702 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1703 elf_x86_local_got_tls_type (abfd
)
1704 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1706 local_got_refcounts
[r_symndx
] = 1;
1707 old_tls_type
= elf_x86_local_got_tls_type (abfd
) [r_symndx
];
1710 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1711 tls_type
|= old_tls_type
;
1712 /* If a TLS symbol is accessed using IE at least once,
1713 there is no point to use dynamic model for it. */
1714 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1715 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1716 || (tls_type
& GOT_TLS_IE
) == 0))
1718 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1719 tls_type
= old_tls_type
;
1720 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1721 && GOT_TLS_GD_ANY_P (tls_type
))
1722 tls_type
|= old_tls_type
;
1726 name
= h
->root
.root
.string
;
1728 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1731 /* xgettext:c-format */
1732 (_("%pB: `%s' accessed both as normal and "
1733 "thread local symbol"),
1735 bfd_set_error (bfd_error_bad_value
);
1740 if (old_tls_type
!= tls_type
)
1743 elf_x86_hash_entry (h
)->tls_type
= tls_type
;
1745 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1753 if (r_type
!= R_386_TLS_IE
)
1757 eh
->zero_undefweak
&= 0x2;
1759 /* Need GOT to resolve undefined weak symbol to 0. */
1760 if (r_type
== R_386_GOTOFF
1761 && h
->root
.type
== bfd_link_hash_undefweak
1762 && bfd_link_executable (info
))
1763 htab
->got_referenced
= true;
1769 case R_386_TLS_LE_32
:
1772 eh
->zero_undefweak
&= 0x2;
1773 if (bfd_link_executable (info
))
1775 info
->flags
|= DF_STATIC_TLS
;
1780 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
1781 eh
->zero_undefweak
|= 0x2;
1783 /* We are called after all symbols have been resolved. Only
1784 relocation against STT_GNU_IFUNC symbol must go through
1787 && (bfd_link_executable (info
)
1788 || h
->type
== STT_GNU_IFUNC
))
1790 bool func_pointer_ref
= false;
1792 if (r_type
== R_386_PC32
)
1794 /* Since something like ".long foo - ." may be used
1795 as pointer, make sure that PLT is used if foo is
1796 a function defined in a shared library. */
1797 if ((sec
->flags
& SEC_CODE
) == 0)
1798 h
->pointer_equality_needed
= 1;
1799 else if (h
->type
== STT_GNU_IFUNC
1800 && bfd_link_pic (info
))
1803 /* xgettext:c-format */
1804 (_("%pB: unsupported non-PIC call to IFUNC `%s'"),
1805 abfd
, h
->root
.root
.string
);
1806 bfd_set_error (bfd_error_bad_value
);
1812 h
->pointer_equality_needed
= 1;
1813 /* R_386_32 can be resolved at run-time. */
1814 if (r_type
== R_386_32
1815 && (sec
->flags
& SEC_READONLY
) == 0)
1816 func_pointer_ref
= true;
1819 if (!func_pointer_ref
)
1821 /* If this reloc is in a read-only section, we might
1822 need a copy reloc. We can't check reliably at this
1823 stage whether the section is read-only, as input
1824 sections have not yet been mapped to output sections.
1825 Tentatively set the flag for now, and correct in
1826 adjust_dynamic_symbol. */
1829 /* We may need a .plt entry if the symbol is a function
1830 defined in a shared lib or is a function referenced
1831 from the code or read-only section. */
1833 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
1834 h
->plt
.refcount
= 1;
1841 && NEED_DYNAMIC_RELOCATION_P (info
, false, h
, sec
, r_type
,
1844 struct elf_dyn_relocs
*p
;
1845 struct elf_dyn_relocs
**head
;
1847 /* We must copy these reloc types into the output file.
1848 Create a reloc section in dynobj and make room for
1852 sreloc
= _bfd_elf_make_dynamic_reloc_section
1853 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ false);
1859 /* If this is a global symbol, we count the number of
1860 relocations we need for this symbol. */
1863 head
= &h
->dyn_relocs
;
1867 /* Track dynamic relocs needed for local syms too.
1868 We really need local syms available to do this
1873 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
1878 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1882 vpp
= &elf_section_data (s
)->local_dynrel
;
1883 head
= (struct elf_dyn_relocs
**)vpp
;
1887 if (p
== NULL
|| p
->sec
!= sec
)
1889 size_t amt
= sizeof *p
;
1890 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1902 /* Count size relocation as PC-relative relocation. */
1903 if (r_type
== R_386_PC32
|| size_reloc
)
1908 /* This relocation describes the C++ object vtable hierarchy.
1909 Reconstruct it for later use during GC. */
1910 case R_386_GNU_VTINHERIT
:
1911 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1915 /* This relocation describes which C++ vtable entries are actually
1916 used. Record for later use during GC. */
1917 case R_386_GNU_VTENTRY
:
1918 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1927 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1929 if (!converted
&& !info
->keep_memory
)
1933 /* Cache the section contents for elf_link_input_bfd if any
1934 load is converted or --no-keep-memory isn't used. */
1935 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1939 /* Cache relocations if any load is converted. */
1940 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
1941 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
1946 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1948 sec
->check_relocs_failed
= 1;
1952 /* Set the correct type for an x86 ELF section. We do this by the
1953 section name, which is a hack, but ought to work. */
1956 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1957 Elf_Internal_Shdr
*hdr
,
1962 name
= bfd_section_name (sec
);
1964 /* This is an ugly, but unfortunately necessary hack that is
1965 needed when producing EFI binaries on x86. It tells
1966 elf.c:elf_fake_sections() not to consider ".reloc" as a section
1967 containing ELF relocation info. We need this hack in order to
1968 be able to generate ELF binaries that can be translated into
1969 EFI applications (which are essentially COFF objects). Those
1970 files contain a COFF ".reloc" section inside an ELFNN object,
1971 which would normally cause BFD to segfault because it would
1972 attempt to interpret this section as containing relocation
1973 entries for section "oc". With this hack enabled, ".reloc"
1974 will be treated as a normal data section, which will avoid the
1975 segfault. However, you won't be able to create an ELFNN binary
1976 with a section named "oc" that needs relocations, but that's
1977 the kind of ugly side-effects you get when detecting section
1978 types based on their names... In practice, this limitation is
1979 unlikely to bite. */
1980 if (strcmp (name
, ".reloc") == 0)
1981 hdr
->sh_type
= SHT_PROGBITS
;
1986 /* Return the relocation value for @tpoff relocation
1987 if STT_TLS virtual address is ADDRESS. */
1990 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
1992 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1993 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
1994 bfd_vma static_tls_size
;
1996 /* If tls_sec is NULL, we should have signalled an error already. */
1997 if (htab
->tls_sec
== NULL
)
2000 /* Consider special static TLS alignment requirements. */
2001 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2002 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
2005 /* Relocate an i386 ELF section. */
2008 elf_i386_relocate_section (bfd
*output_bfd
,
2009 struct bfd_link_info
*info
,
2011 asection
*input_section
,
2013 Elf_Internal_Rela
*relocs
,
2014 Elf_Internal_Sym
*local_syms
,
2015 asection
**local_sections
)
2017 struct elf_x86_link_hash_table
*htab
;
2018 Elf_Internal_Shdr
*symtab_hdr
;
2019 struct elf_link_hash_entry
**sym_hashes
;
2020 bfd_vma
*local_got_offsets
;
2021 bfd_vma
*local_tlsdesc_gotents
;
2022 Elf_Internal_Rela
*rel
;
2023 Elf_Internal_Rela
*wrel
;
2024 Elf_Internal_Rela
*relend
;
2025 bool is_vxworks_tls
;
2026 unsigned plt_entry_size
;
2028 /* Skip if check_relocs failed. */
2029 if (input_section
->check_relocs_failed
)
2032 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2036 if (!is_x86_elf (input_bfd
, htab
))
2038 bfd_set_error (bfd_error_wrong_format
);
2042 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2043 sym_hashes
= elf_sym_hashes (input_bfd
);
2044 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2045 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2046 /* We have to handle relocations in vxworks .tls_vars sections
2047 specially, because the dynamic loader is 'weird'. */
2048 is_vxworks_tls
= (htab
->elf
.target_os
== is_vxworks
2049 && bfd_link_pic (info
)
2050 && !strcmp (input_section
->output_section
->name
,
2053 _bfd_x86_elf_set_tls_module_base (info
);
2055 plt_entry_size
= htab
->plt
.plt_entry_size
;
2057 rel
= wrel
= relocs
;
2058 relend
= relocs
+ input_section
->reloc_count
;
2059 for (; rel
< relend
; wrel
++, rel
++)
2061 unsigned int r_type
, r_type_tls
;
2062 reloc_howto_type
*howto
;
2063 unsigned long r_symndx
;
2064 struct elf_link_hash_entry
*h
;
2065 struct elf_x86_link_hash_entry
*eh
;
2066 Elf_Internal_Sym
*sym
;
2068 bfd_vma off
, offplt
, plt_offset
;
2070 bool unresolved_reloc
;
2071 bfd_reloc_status_type r
;
2075 asection
*resolved_plt
;
2076 bool resolved_to_zero
;
2077 bool relative_reloc
;
2079 r_type
= ELF32_R_TYPE (rel
->r_info
);
2080 if (r_type
== R_386_GNU_VTINHERIT
2081 || r_type
== R_386_GNU_VTENTRY
)
2088 howto
= elf_i386_rtype_to_howto (input_bfd
, r_type
);
2090 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2092 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2096 unresolved_reloc
= false;
2097 if (r_symndx
< symtab_hdr
->sh_info
)
2099 sym
= local_syms
+ r_symndx
;
2100 sec
= local_sections
[r_symndx
];
2101 relocation
= (sec
->output_section
->vma
2102 + sec
->output_offset
2104 st_size
= sym
->st_size
;
2106 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2107 && ((sec
->flags
& SEC_MERGE
) != 0
2108 || (bfd_link_relocatable (info
)
2109 && sec
->output_offset
!= 0)))
2112 bfd_byte
*where
= contents
+ rel
->r_offset
;
2114 switch (howto
->size
)
2117 addend
= bfd_get_8 (input_bfd
, where
);
2118 if (howto
->pc_relative
)
2120 addend
= (addend
^ 0x80) - 0x80;
2125 addend
= bfd_get_16 (input_bfd
, where
);
2126 if (howto
->pc_relative
)
2128 addend
= (addend
^ 0x8000) - 0x8000;
2133 addend
= bfd_get_32 (input_bfd
, where
);
2134 if (howto
->pc_relative
)
2136 addend
= (addend
^ 0x80000000) - 0x80000000;
2144 if (bfd_link_relocatable (info
))
2145 addend
+= sec
->output_offset
;
2148 asection
*msec
= sec
;
2149 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2151 addend
-= relocation
;
2152 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2155 switch (howto
->size
)
2158 /* FIXME: overflow checks. */
2159 if (howto
->pc_relative
)
2161 bfd_put_8 (input_bfd
, addend
, where
);
2164 if (howto
->pc_relative
)
2166 bfd_put_16 (input_bfd
, addend
, where
);
2169 if (howto
->pc_relative
)
2171 bfd_put_32 (input_bfd
, addend
, where
);
2175 else if (!bfd_link_relocatable (info
)
2176 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2178 /* Relocate against local STT_GNU_IFUNC symbol. */
2179 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
, rel
,
2184 /* Set STT_GNU_IFUNC symbol value. */
2185 h
->root
.u
.def
.value
= sym
->st_value
;
2186 h
->root
.u
.def
.section
= sec
;
2191 bool warned ATTRIBUTE_UNUSED
;
2192 bool ignored ATTRIBUTE_UNUSED
;
2194 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2195 r_symndx
, symtab_hdr
, sym_hashes
,
2197 unresolved_reloc
, warned
, ignored
);
2201 if (sec
!= NULL
&& discarded_section (sec
))
2203 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2204 contents
, rel
->r_offset
);
2205 wrel
->r_offset
= rel
->r_offset
;
2209 /* For ld -r, remove relocations in debug sections against
2210 sections defined in discarded sections. Not done for
2211 eh_frame editing code expects to be present. */
2212 if (bfd_link_relocatable (info
)
2213 && (input_section
->flags
& SEC_DEBUGGING
))
2219 if (bfd_link_relocatable (info
))
2226 eh
= (struct elf_x86_link_hash_entry
*) h
;
2228 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2229 it here if it is defined in a non-shared object. */
2231 && h
->type
== STT_GNU_IFUNC
2234 asection
*gotplt
, *base_got
;
2238 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2240 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
2241 STT_GNU_IFUNC symbol as STT_FUNC. */
2242 if (elf_section_type (input_section
) == SHT_NOTE
)
2244 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2245 sections because such sections are not SEC_ALLOC and
2246 thus ld.so will not process them. */
2247 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2252 /* STT_GNU_IFUNC symbol must go through PLT. */
2253 if (htab
->elf
.splt
!= NULL
)
2255 if (htab
->plt_second
!= NULL
)
2257 resolved_plt
= htab
->plt_second
;
2258 plt_offset
= eh
->plt_second
.offset
;
2262 resolved_plt
= htab
->elf
.splt
;
2263 plt_offset
= h
->plt
.offset
;
2265 gotplt
= htab
->elf
.sgotplt
;
2269 resolved_plt
= htab
->elf
.iplt
;
2270 plt_offset
= h
->plt
.offset
;
2271 gotplt
= htab
->elf
.igotplt
;
2281 base_got
= htab
->elf
.sgot
;
2282 off
= h
->got
.offset
;
2284 if (base_got
== NULL
)
2287 if (off
== (bfd_vma
) -1)
2289 /* We can't use h->got.offset here to save state, or
2290 even just remember the offset, as finish_dynamic_symbol
2291 would use that as offset into .got. */
2293 if (h
->plt
.offset
== (bfd_vma
) -1)
2296 if (htab
->elf
.splt
!= NULL
)
2298 plt_index
= (h
->plt
.offset
/ plt_entry_size
2299 - htab
->plt
.has_plt0
);
2300 off
= (plt_index
+ 3) * 4;
2301 base_got
= htab
->elf
.sgotplt
;
2305 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2306 off
= plt_index
* 4;
2307 base_got
= htab
->elf
.igotplt
;
2310 if (h
->dynindx
== -1
2314 /* This references the local defitionion. We must
2315 initialize this entry in the global offset table.
2316 Since the offset must always be a multiple of 8,
2317 we use the least significant bit to record
2318 whether we have initialized it already.
2320 When doing a dynamic link, we create a .rela.got
2321 relocation entry to initialize the value. This
2322 is done in the finish_dynamic_symbol routine. */
2327 bfd_put_32 (output_bfd
, relocation
,
2328 base_got
->contents
+ off
);
2336 relocation
= (base_got
->output_section
->vma
2337 + base_got
->output_offset
+ off
2338 - gotplt
->output_section
->vma
2339 - gotplt
->output_offset
);
2341 if (rel
->r_offset
> 1
2342 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2343 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2345 if (bfd_link_pic (info
))
2346 goto disallow_got32
;
2348 /* Add the GOT base if there is no base register. */
2349 relocation
+= (gotplt
->output_section
->vma
2350 + gotplt
->output_offset
);
2352 else if (htab
->elf
.splt
== NULL
)
2354 /* Adjust for static executables. */
2355 relocation
+= gotplt
->output_offset
;
2361 if (h
->plt
.offset
== (bfd_vma
) -1)
2363 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2364 if (r_type
== R_386_32
2365 && (input_section
->flags
& SEC_CODE
) == 0)
2366 goto do_ifunc_pointer
;
2367 goto bad_ifunc_reloc
;
2370 relocation
= (resolved_plt
->output_section
->vma
2371 + resolved_plt
->output_offset
+ plt_offset
);
2377 if (h
->root
.root
.string
)
2378 name
= h
->root
.root
.string
;
2380 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2383 /* xgettext:c-format */
2384 (_("%pB: relocation %s against STT_GNU_IFUNC "
2385 "symbol `%s' isn't supported"), input_bfd
,
2387 bfd_set_error (bfd_error_bad_value
);
2391 /* Generate dynamic relcoation only when there is a
2392 non-GOT reference in a shared object. */
2393 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2394 || h
->plt
.offset
== (bfd_vma
) -1)
2396 Elf_Internal_Rela outrel
;
2401 /* Need a dynamic relocation to get the real function
2403 offset
= _bfd_elf_section_offset (output_bfd
,
2407 if (offset
== (bfd_vma
) -1
2408 || offset
== (bfd_vma
) -2)
2411 outrel
.r_offset
= (input_section
->output_section
->vma
2412 + input_section
->output_offset
2415 if (POINTER_LOCAL_IFUNC_P (info
, h
))
2417 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
2418 h
->root
.root
.string
,
2419 h
->root
.u
.def
.section
->owner
);
2421 /* This symbol is resolved locally. */
2422 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
2424 if (htab
->params
->report_relative_reloc
)
2425 _bfd_x86_elf_link_report_relative_reloc
2426 (info
, input_section
, h
, sym
,
2427 "R_386_IRELATIVE", &outrel
);
2429 bfd_put_32 (output_bfd
,
2430 (h
->root
.u
.def
.value
2431 + h
->root
.u
.def
.section
->output_section
->vma
2432 + h
->root
.u
.def
.section
->output_offset
),
2436 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2438 /* Dynamic relocations are stored in
2439 1. .rel.ifunc section in PIC object.
2440 2. .rel.got section in dynamic executable.
2441 3. .rel.iplt section in static executable. */
2442 if (bfd_link_pic (info
))
2443 sreloc
= htab
->elf
.irelifunc
;
2444 else if (htab
->elf
.splt
!= NULL
)
2445 sreloc
= htab
->elf
.srelgot
;
2447 sreloc
= htab
->elf
.irelplt
;
2448 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2450 /* If this reloc is against an external symbol, we
2451 do not want to fiddle with the addend. Otherwise,
2452 we need to include the symbol value so that it
2453 becomes an addend for the dynamic reloc. For an
2454 internal symbol, we have updated addend. */
2463 relocation
-= (gotplt
->output_section
->vma
2464 + gotplt
->output_offset
);
2470 resolved_to_zero
= (eh
!= NULL
2471 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2477 /* Relocation is to the entry for this symbol in the global
2479 if (htab
->elf
.sgot
== NULL
)
2482 relative_reloc
= false;
2485 off
= h
->got
.offset
;
2486 if (RESOLVED_LOCALLY_P (info
, h
, htab
))
2488 /* We must initialize this entry in the global offset
2489 table. Since the offset must always be a multiple
2490 of 4, we use the least significant bit to record
2491 whether we have initialized it already.
2493 When doing a dynamic link, we create a .rel.got
2494 relocation entry to initialize the value. This
2495 is done in the finish_dynamic_symbol routine. */
2500 bfd_put_32 (output_bfd
, relocation
,
2501 htab
->elf
.sgot
->contents
+ off
);
2504 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
2506 /* PR ld/21402: If this symbol isn't dynamic
2507 in PIC, generate R_386_RELATIVE here. */
2508 eh
->no_finish_dynamic_symbol
= 1;
2509 relative_reloc
= true;
2514 unresolved_reloc
= false;
2518 if (local_got_offsets
== NULL
)
2521 off
= local_got_offsets
[r_symndx
];
2523 /* The offset must always be a multiple of 4. We use
2524 the least significant bit to record whether we have
2525 already generated the necessary reloc. */
2530 bfd_put_32 (output_bfd
, relocation
,
2531 htab
->elf
.sgot
->contents
+ off
);
2532 local_got_offsets
[r_symndx
] |= 1;
2534 if (bfd_link_pic (info
))
2535 relative_reloc
= true;
2542 Elf_Internal_Rela outrel
;
2544 s
= htab
->elf
.srelgot
;
2548 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
2549 + htab
->elf
.sgot
->output_offset
2551 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2553 if (htab
->params
->report_relative_reloc
)
2554 _bfd_x86_elf_link_report_relative_reloc
2555 (info
, input_section
, h
, sym
, "R_386_RELATIVE",
2558 elf_append_rel (output_bfd
, s
, &outrel
);
2561 if (off
>= (bfd_vma
) -2)
2564 relocation
= (htab
->elf
.sgot
->output_section
->vma
2565 + htab
->elf
.sgot
->output_offset
+ off
);
2566 if (rel
->r_offset
> 1
2567 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2568 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2570 if (bfd_link_pic (info
))
2572 /* For PIC, disallow R_386_GOT32 without a base
2573 register, except for "lea foo@GOT, %reg", since
2574 we don't know what the GOT base is. */
2578 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
2579 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2582 name
= h
->root
.root
.string
;
2585 /* xgettext:c-format */
2586 (_("%pB: direct GOT relocation %s against `%s'"
2587 " without base register can not be used"
2588 " when making a shared object"),
2589 input_bfd
, howto
->name
, name
);
2590 bfd_set_error (bfd_error_bad_value
);
2596 /* Subtract the .got.plt section address only with a base
2598 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
2599 + htab
->elf
.sgotplt
->output_offset
);
2605 /* Relocation is relative to the start of the global offset
2608 /* Check to make sure it isn't a protected function or data
2609 symbol for shared library since it may not be local when
2610 used as function address or with copy relocation. We also
2611 need to make sure that a symbol is referenced locally. */
2612 if (!bfd_link_executable (info
) && h
)
2614 if (!h
->def_regular
)
2618 switch (ELF_ST_VISIBILITY (h
->other
))
2621 v
= _("hidden symbol");
2624 v
= _("internal symbol");
2627 v
= _("protected symbol");
2635 /* xgettext:c-format */
2636 (_("%pB: relocation R_386_GOTOFF against undefined %s"
2637 " `%s' can not be used when making a shared object"),
2638 input_bfd
, v
, h
->root
.root
.string
);
2639 bfd_set_error (bfd_error_bad_value
);
2642 else if (!SYMBOL_REFERENCES_LOCAL_P (info
, h
)
2643 && (h
->type
== STT_FUNC
2644 || h
->type
== STT_OBJECT
)
2645 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2648 /* xgettext:c-format */
2649 (_("%pB: relocation R_386_GOTOFF against protected %s"
2650 " `%s' can not be used when making a shared object"),
2652 h
->type
== STT_FUNC
? "function" : "data",
2653 h
->root
.root
.string
);
2654 bfd_set_error (bfd_error_bad_value
);
2659 /* Note that sgot is not involved in this
2660 calculation. We always want the start of .got.plt. If we
2661 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2662 permitted by the ABI, we might have to change this
2664 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2665 + htab
->elf
.sgotplt
->output_offset
;
2669 /* Use global offset table as symbol value. */
2670 relocation
= htab
->elf
.sgotplt
->output_section
->vma
2671 + htab
->elf
.sgotplt
->output_offset
;
2672 unresolved_reloc
= false;
2676 /* Relocation is to the entry for this symbol in the
2677 procedure linkage table. */
2679 /* Resolve a PLT32 reloc against a local symbol directly,
2680 without using the procedure linkage table. */
2684 if ((h
->plt
.offset
== (bfd_vma
) -1
2685 && eh
->plt_got
.offset
== (bfd_vma
) -1)
2686 || htab
->elf
.splt
== NULL
)
2688 /* We didn't make a PLT entry for this symbol. This
2689 happens when statically linking PIC code, or when
2690 using -Bsymbolic. */
2694 if (h
->plt
.offset
!= (bfd_vma
) -1)
2696 if (htab
->plt_second
!= NULL
)
2698 resolved_plt
= htab
->plt_second
;
2699 plt_offset
= eh
->plt_second
.offset
;
2703 resolved_plt
= htab
->elf
.splt
;
2704 plt_offset
= h
->plt
.offset
;
2709 resolved_plt
= htab
->plt_got
;
2710 plt_offset
= eh
->plt_got
.offset
;
2713 relocation
= (resolved_plt
->output_section
->vma
2714 + resolved_plt
->output_offset
2716 unresolved_reloc
= false;
2720 /* Set to symbol size. */
2721 relocation
= st_size
;
2726 if ((input_section
->flags
& SEC_ALLOC
) == 0
2730 if (GENERATE_DYNAMIC_RELOCATION_P (info
, eh
, r_type
, sec
,
2731 false, resolved_to_zero
,
2732 (r_type
== R_386_PC32
)))
2734 Elf_Internal_Rela outrel
;
2735 bool skip
, relocate
;
2738 /* When generating a shared object, these relocations
2739 are copied into the output file to be resolved at run
2746 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2748 if (outrel
.r_offset
== (bfd_vma
) -1)
2750 else if (outrel
.r_offset
== (bfd_vma
) -2)
2751 skip
= true, relocate
= true;
2752 outrel
.r_offset
+= (input_section
->output_section
->vma
2753 + input_section
->output_offset
);
2756 memset (&outrel
, 0, sizeof outrel
);
2757 else if (COPY_INPUT_RELOC_P (info
, h
, r_type
))
2758 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2761 /* This symbol is local, or marked to become local. */
2763 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2765 if (htab
->params
->report_relative_reloc
)
2766 _bfd_x86_elf_link_report_relative_reloc
2767 (info
, input_section
, h
, sym
, "R_386_RELATIVE",
2771 sreloc
= elf_section_data (input_section
)->sreloc
;
2773 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
2775 r
= bfd_reloc_notsupported
;
2776 goto check_relocation_error
;
2779 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2781 /* If this reloc is against an external symbol, we do
2782 not want to fiddle with the addend. Otherwise, we
2783 need to include the symbol value so that it becomes
2784 an addend for the dynamic reloc. */
2791 if (!bfd_link_executable (info
))
2793 Elf_Internal_Rela outrel
;
2796 outrel
.r_offset
= rel
->r_offset
2797 + input_section
->output_section
->vma
2798 + input_section
->output_offset
;
2799 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2801 if (htab
->params
->report_relative_reloc
)
2802 _bfd_x86_elf_link_report_relative_reloc
2803 (info
, input_section
, h
, sym
, "R_386_RELATIVE",
2806 sreloc
= elf_section_data (input_section
)->sreloc
;
2809 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2814 case R_386_TLS_GOTDESC
:
2815 case R_386_TLS_DESC_CALL
:
2816 case R_386_TLS_IE_32
:
2817 case R_386_TLS_GOTIE
:
2818 tls_type
= GOT_UNKNOWN
;
2819 if (h
== NULL
&& local_got_offsets
)
2820 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
2822 tls_type
= elf_x86_hash_entry(h
)->tls_type
;
2823 if (tls_type
== GOT_TLS_IE
)
2824 tls_type
= GOT_TLS_IE_NEG
;
2826 r_type_tls
= r_type
;
2827 if (! elf_i386_tls_transition (info
, input_bfd
,
2828 input_section
, contents
,
2829 symtab_hdr
, sym_hashes
,
2830 &r_type_tls
, tls_type
, rel
,
2831 relend
, h
, r_symndx
, true))
2834 if (r_type_tls
== R_386_TLS_LE_32
)
2836 BFD_ASSERT (! unresolved_reloc
);
2837 if (r_type
== R_386_TLS_GD
)
2842 /* GD->LE transition. */
2843 type
= *(contents
+ rel
->r_offset
- 2);
2847 leal foo@tlsgd(,%ebx,1), %eax
2848 call ___tls_get_addr@PLT
2851 subl $foo@tpoff, %eax
2852 (6 byte form of subl). */
2853 roff
= rel
->r_offset
+ 5;
2858 leal foo@tlsgd(%ebx), %eax
2859 call ___tls_get_addr@PLT
2862 leal foo@tlsgd(%reg), %eax
2863 call *___tls_get_addr@GOT(%reg)
2864 which may be converted to
2865 addr32 call ___tls_get_addr
2867 movl %gs:0, %eax; subl $foo@tpoff, %eax
2868 (6 byte form of subl). */
2869 roff
= rel
->r_offset
+ 6;
2871 memcpy (contents
+ roff
- 8,
2872 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2873 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
2875 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
2880 else if (r_type
== R_386_TLS_GOTDESC
)
2882 /* GDesc -> LE transition.
2883 It's originally something like:
2884 leal x@tlsdesc(%ebx), %eax
2888 Registers other than %eax may be set up here. */
2893 roff
= rel
->r_offset
;
2894 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2896 /* Now modify the instruction as appropriate. */
2897 /* aoliva FIXME: remove the above and xor the byte
2899 bfd_put_8 (output_bfd
, val
^ 0x86,
2900 contents
+ roff
- 1);
2901 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
2905 else if (r_type
== R_386_TLS_DESC_CALL
)
2907 /* GDesc -> LE transition.
2915 roff
= rel
->r_offset
;
2916 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
2917 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
2920 else if (r_type
== R_386_TLS_IE
)
2924 /* IE->LE transition:
2925 Originally it can be one of:
2933 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2936 /* movl foo, %eax. */
2937 bfd_put_8 (output_bfd
, 0xb8,
2938 contents
+ rel
->r_offset
- 1);
2944 type
= bfd_get_8 (input_bfd
,
2945 contents
+ rel
->r_offset
- 2);
2950 bfd_put_8 (output_bfd
, 0xc7,
2951 contents
+ rel
->r_offset
- 2);
2952 bfd_put_8 (output_bfd
,
2953 0xc0 | ((val
>> 3) & 7),
2954 contents
+ rel
->r_offset
- 1);
2958 bfd_put_8 (output_bfd
, 0x81,
2959 contents
+ rel
->r_offset
- 2);
2960 bfd_put_8 (output_bfd
,
2961 0xc0 | ((val
>> 3) & 7),
2962 contents
+ rel
->r_offset
- 1);
2969 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
2970 contents
+ rel
->r_offset
);
2975 unsigned int val
, type
;
2977 /* {IE_32,GOTIE}->LE transition:
2978 Originally it can be one of:
2979 subl foo(%reg1), %reg2
2980 movl foo(%reg1), %reg2
2981 addl foo(%reg1), %reg2
2984 movl $foo, %reg2 (6 byte form)
2985 addl $foo, %reg2. */
2986 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2987 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2991 bfd_put_8 (output_bfd
, 0xc7,
2992 contents
+ rel
->r_offset
- 2);
2993 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
2994 contents
+ rel
->r_offset
- 1);
2996 else if (type
== 0x2b)
2999 bfd_put_8 (output_bfd
, 0x81,
3000 contents
+ rel
->r_offset
- 2);
3001 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3002 contents
+ rel
->r_offset
- 1);
3004 else if (type
== 0x03)
3007 bfd_put_8 (output_bfd
, 0x81,
3008 contents
+ rel
->r_offset
- 2);
3009 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3010 contents
+ rel
->r_offset
- 1);
3014 if (r_type
== R_386_TLS_GOTIE
)
3015 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3016 contents
+ rel
->r_offset
);
3018 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3019 contents
+ rel
->r_offset
);
3024 if (htab
->elf
.sgot
== NULL
)
3029 off
= h
->got
.offset
;
3030 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3034 if (local_got_offsets
== NULL
)
3037 off
= local_got_offsets
[r_symndx
];
3038 offplt
= local_tlsdesc_gotents
[r_symndx
];
3045 Elf_Internal_Rela outrel
;
3049 if (htab
->elf
.srelgot
== NULL
)
3052 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3054 if (GOT_TLS_GDESC_P (tls_type
))
3057 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3058 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3059 <= htab
->elf
.sgotplt
->size
);
3060 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3061 + htab
->elf
.sgotplt
->output_offset
3063 + htab
->sgotplt_jump_table_size
);
3064 sreloc
= htab
->elf
.srelplt
;
3065 loc
= sreloc
->contents
;
3066 loc
+= (htab
->next_tls_desc_index
++
3067 * sizeof (Elf32_External_Rel
));
3068 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3069 <= sreloc
->contents
+ sreloc
->size
);
3070 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3073 BFD_ASSERT (! unresolved_reloc
);
3074 bfd_put_32 (output_bfd
,
3075 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3076 htab
->elf
.sgotplt
->contents
+ offplt
3077 + htab
->sgotplt_jump_table_size
+ 4);
3081 bfd_put_32 (output_bfd
, 0,
3082 htab
->elf
.sgotplt
->contents
+ offplt
3083 + htab
->sgotplt_jump_table_size
+ 4);
3087 sreloc
= htab
->elf
.srelgot
;
3089 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3090 + htab
->elf
.sgot
->output_offset
+ off
);
3092 if (GOT_TLS_GD_P (tls_type
))
3093 dr_type
= R_386_TLS_DTPMOD32
;
3094 else if (GOT_TLS_GDESC_P (tls_type
))
3096 else if (tls_type
== GOT_TLS_IE_POS
)
3097 dr_type
= R_386_TLS_TPOFF
;
3099 dr_type
= R_386_TLS_TPOFF32
;
3101 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3102 bfd_put_32 (output_bfd
,
3103 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3104 htab
->elf
.sgot
->contents
+ off
);
3105 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3106 bfd_put_32 (output_bfd
,
3107 _bfd_x86_elf_dtpoff_base (info
) - relocation
,
3108 htab
->elf
.sgot
->contents
+ off
);
3109 else if (dr_type
!= R_386_TLS_DESC
)
3110 bfd_put_32 (output_bfd
, 0,
3111 htab
->elf
.sgot
->contents
+ off
);
3112 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3114 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3116 if (GOT_TLS_GD_P (tls_type
))
3120 BFD_ASSERT (! unresolved_reloc
);
3121 bfd_put_32 (output_bfd
,
3122 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3123 htab
->elf
.sgot
->contents
+ off
+ 4);
3127 bfd_put_32 (output_bfd
, 0,
3128 htab
->elf
.sgot
->contents
+ off
+ 4);
3129 outrel
.r_info
= ELF32_R_INFO (indx
,
3130 R_386_TLS_DTPOFF32
);
3131 outrel
.r_offset
+= 4;
3132 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3135 else if (tls_type
== GOT_TLS_IE_BOTH
)
3137 bfd_put_32 (output_bfd
,
3139 ? relocation
- _bfd_x86_elf_dtpoff_base (info
)
3141 htab
->elf
.sgot
->contents
+ off
+ 4);
3142 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3143 outrel
.r_offset
+= 4;
3144 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3151 local_got_offsets
[r_symndx
] |= 1;
3154 if (off
>= (bfd_vma
) -2
3155 && ! GOT_TLS_GDESC_P (tls_type
))
3157 if (r_type_tls
== R_386_TLS_GOTDESC
3158 || r_type_tls
== R_386_TLS_DESC_CALL
)
3160 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3161 unresolved_reloc
= false;
3163 else if (r_type_tls
== r_type
)
3165 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3166 + htab
->elf
.sgotplt
->output_offset
;
3167 relocation
= htab
->elf
.sgot
->output_section
->vma
3168 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3169 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3170 && tls_type
== GOT_TLS_IE_BOTH
)
3172 if (r_type
== R_386_TLS_IE
)
3173 relocation
+= g_o_t
;
3174 unresolved_reloc
= false;
3176 else if (r_type
== R_386_TLS_GD
)
3178 unsigned int val
, type
;
3181 /* GD->IE transition. */
3182 type
= *(contents
+ rel
->r_offset
- 2);
3183 val
= *(contents
+ rel
->r_offset
- 1);
3187 leal foo@tlsgd(,%ebx,1), %eax
3188 call ___tls_get_addr@PLT
3191 subl $foo@gottpoff(%ebx), %eax. */
3193 roff
= rel
->r_offset
- 3;
3198 leal foo@tlsgd(%ebx), %eax
3199 call ___tls_get_addr@PLT
3202 leal foo@tlsgd(%reg), %eax
3203 call *___tls_get_addr@GOT(%reg)
3204 which may be converted to
3205 addr32 call ___tls_get_addr
3208 subl $foo@gottpoff(%reg), %eax. */
3209 roff
= rel
->r_offset
- 2;
3211 memcpy (contents
+ roff
,
3212 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3213 contents
[roff
+ 7] = 0x80 | (val
& 7);
3214 /* If foo is used only with foo@gotntpoff(%reg) and
3215 foo@indntpoff, but not with foo@gottpoff(%reg), change
3216 subl $foo@gottpoff(%reg), %eax
3218 addl $foo@gotntpoff(%reg), %eax. */
3219 if (tls_type
== GOT_TLS_IE_POS
)
3220 contents
[roff
+ 6] = 0x03;
3221 bfd_put_32 (output_bfd
,
3222 htab
->elf
.sgot
->output_section
->vma
3223 + htab
->elf
.sgot
->output_offset
+ off
3224 - htab
->elf
.sgotplt
->output_section
->vma
3225 - htab
->elf
.sgotplt
->output_offset
,
3226 contents
+ roff
+ 8);
3227 /* Skip R_386_PLT32 and R_386_GOT32X. */
3232 else if (r_type
== R_386_TLS_GOTDESC
)
3234 /* GDesc -> IE transition.
3235 It's originally something like:
3236 leal x@tlsdesc(%ebx), %eax
3239 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3241 movl x@gottpoff(%ebx), %eax # before negl %eax
3243 Registers other than %eax may be set up here. */
3247 /* First, make sure it's a leal adding ebx to a 32-bit
3248 offset into any register, although it's probably
3249 almost always going to be eax. */
3250 roff
= rel
->r_offset
;
3252 /* Now modify the instruction as appropriate. */
3253 /* To turn a leal into a movl in the form we use it, it
3254 suffices to change the first byte from 0x8d to 0x8b.
3255 aoliva FIXME: should we decide to keep the leal, all
3256 we have to do is remove the statement below, and
3257 adjust the relaxation of R_386_TLS_DESC_CALL. */
3258 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3260 if (tls_type
== GOT_TLS_IE_BOTH
)
3263 bfd_put_32 (output_bfd
,
3264 htab
->elf
.sgot
->output_section
->vma
3265 + htab
->elf
.sgot
->output_offset
+ off
3266 - htab
->elf
.sgotplt
->output_section
->vma
3267 - htab
->elf
.sgotplt
->output_offset
,
3271 else if (r_type
== R_386_TLS_DESC_CALL
)
3273 /* GDesc -> IE transition.
3281 depending on how we transformed the TLS_GOTDESC above.
3286 roff
= rel
->r_offset
;
3288 /* Now modify the instruction as appropriate. */
3289 if (tls_type
!= GOT_TLS_IE_NEG
)
3292 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3293 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3298 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3299 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3309 if (! elf_i386_tls_transition (info
, input_bfd
,
3310 input_section
, contents
,
3311 symtab_hdr
, sym_hashes
,
3312 &r_type
, GOT_UNKNOWN
, rel
,
3313 relend
, h
, r_symndx
, true))
3316 if (r_type
!= R_386_TLS_LDM
)
3318 /* LD->LE transition. Change
3319 leal foo@tlsldm(%ebx) %eax
3320 call ___tls_get_addr@PLT
3324 leal 0(%esi,1), %esi
3326 leal foo@tlsldm(%reg) %eax
3327 call *___tls_get_addr@GOT(%reg)
3328 which may be converted to
3329 addr32 call ___tls_get_addr
3332 leal 0(%esi), %esi */
3333 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3334 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
3335 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
3336 memcpy (contents
+ rel
->r_offset
- 2,
3337 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
3339 memcpy (contents
+ rel
->r_offset
- 2,
3340 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3341 /* Skip R_386_PC32/R_386_PLT32. */
3347 if (htab
->elf
.sgot
== NULL
)
3350 off
= htab
->tls_ld_or_ldm_got
.offset
;
3355 Elf_Internal_Rela outrel
;
3357 if (htab
->elf
.srelgot
== NULL
)
3360 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3361 + htab
->elf
.sgot
->output_offset
+ off
);
3363 bfd_put_32 (output_bfd
, 0,
3364 htab
->elf
.sgot
->contents
+ off
);
3365 bfd_put_32 (output_bfd
, 0,
3366 htab
->elf
.sgot
->contents
+ off
+ 4);
3367 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3368 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3369 htab
->tls_ld_or_ldm_got
.offset
|= 1;
3371 relocation
= htab
->elf
.sgot
->output_section
->vma
3372 + htab
->elf
.sgot
->output_offset
+ off
3373 - htab
->elf
.sgotplt
->output_section
->vma
3374 - htab
->elf
.sgotplt
->output_offset
;
3375 unresolved_reloc
= false;
3378 case R_386_TLS_LDO_32
:
3379 if (!bfd_link_executable (info
)
3380 || (input_section
->flags
& SEC_CODE
) == 0)
3381 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3383 /* When converting LDO to LE, we must negate. */
3384 relocation
= -elf_i386_tpoff (info
, relocation
);
3387 case R_386_TLS_LE_32
:
3389 if (!bfd_link_executable (info
))
3391 Elf_Internal_Rela outrel
;
3394 outrel
.r_offset
= rel
->r_offset
3395 + input_section
->output_section
->vma
3396 + input_section
->output_offset
;
3397 if (h
!= NULL
&& h
->dynindx
!= -1)
3401 if (r_type
== R_386_TLS_LE_32
)
3402 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3404 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3405 sreloc
= elf_section_data (input_section
)->sreloc
;
3408 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3411 else if (r_type
== R_386_TLS_LE_32
)
3412 relocation
= _bfd_x86_elf_dtpoff_base (info
) - relocation
;
3414 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3416 else if (r_type
== R_386_TLS_LE_32
)
3417 relocation
= elf_i386_tpoff (info
, relocation
);
3419 relocation
= -elf_i386_tpoff (info
, relocation
);
3426 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3427 because such sections are not SEC_ALLOC and thus ld.so will
3428 not process them. */
3429 if (unresolved_reloc
3430 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3432 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3433 rel
->r_offset
) != (bfd_vma
) -1)
3436 /* xgettext:c-format */
3437 (_("%pB(%pA+%#" PRIx64
"): unresolvable %s relocation against symbol `%s'"),
3440 (uint64_t) rel
->r_offset
,
3442 h
->root
.root
.string
);
3447 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3448 contents
, rel
->r_offset
,
3451 check_relocation_error
:
3452 if (r
!= bfd_reloc_ok
)
3457 name
= h
->root
.root
.string
;
3460 name
= bfd_elf_string_from_elf_section (input_bfd
,
3461 symtab_hdr
->sh_link
,
3466 name
= bfd_section_name (sec
);
3469 if (r
== bfd_reloc_overflow
)
3470 (*info
->callbacks
->reloc_overflow
)
3471 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3472 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3476 /* xgettext:c-format */
3477 (_("%pB(%pA+%#" PRIx64
"): reloc against `%s': error %d"),
3478 input_bfd
, input_section
,
3479 (uint64_t) rel
->r_offset
, name
, (int) r
);
3490 Elf_Internal_Shdr
*rel_hdr
;
3491 size_t deleted
= rel
- wrel
;
3493 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
3494 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3495 if (rel_hdr
->sh_size
== 0)
3497 /* It is too late to remove an empty reloc section. Leave
3499 ??? What is wrong with an empty section??? */
3500 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
3503 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
3504 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3505 input_section
->reloc_count
-= deleted
;
3511 /* Finish up dynamic symbol handling. We set the contents of various
3512 dynamic sections here. */
3515 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3516 struct bfd_link_info
*info
,
3517 struct elf_link_hash_entry
*h
,
3518 Elf_Internal_Sym
*sym
)
3520 struct elf_x86_link_hash_table
*htab
;
3521 unsigned plt_entry_size
;
3522 struct elf_x86_link_hash_entry
*eh
;
3523 bool local_undefweak
;
3524 bool use_plt_second
;
3526 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
3530 plt_entry_size
= htab
->plt
.plt_entry_size
;
3532 /* Use the second PLT section only if there is .plt section. */
3533 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
3535 eh
= (struct elf_x86_link_hash_entry
*) h
;
3536 if (eh
->no_finish_dynamic_symbol
)
3539 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
3540 resolved undefined weak symbols in executable so that their
3541 references have value 0 at run-time. */
3542 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
3544 if (h
->plt
.offset
!= (bfd_vma
) -1)
3546 bfd_vma plt_index
, plt_offset
;
3548 Elf_Internal_Rela rel
;
3550 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
3552 /* When building a static executable, use .iplt, .igot.plt and
3553 .rel.iplt sections for STT_GNU_IFUNC symbols. */
3554 if (htab
->elf
.splt
!= NULL
)
3556 plt
= htab
->elf
.splt
;
3557 gotplt
= htab
->elf
.sgotplt
;
3558 relplt
= htab
->elf
.srelplt
;
3562 plt
= htab
->elf
.iplt
;
3563 gotplt
= htab
->elf
.igotplt
;
3564 relplt
= htab
->elf
.irelplt
;
3567 VERIFY_PLT_ENTRY (info
, h
, plt
, gotplt
, relplt
, local_undefweak
)
3569 /* Get the index in the procedure linkage table which
3570 corresponds to this symbol. This is the index of this symbol
3571 in all the symbols for which we are making plt entries. The
3572 first entry in the procedure linkage table is reserved.
3574 Get the offset into the .got table of the entry that
3575 corresponds to this function. Each .got entry is 4 bytes.
3576 The first three are reserved.
3578 For static executables, we don't reserve anything. */
3580 if (plt
== htab
->elf
.splt
)
3582 got_offset
= (h
->plt
.offset
/ plt_entry_size
3583 - htab
->plt
.has_plt0
);
3584 got_offset
= (got_offset
+ 3) * 4;
3588 got_offset
= h
->plt
.offset
/ plt_entry_size
;
3589 got_offset
= got_offset
* 4;
3592 /* Fill in the entry in the procedure linkage table and update
3594 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
3599 const bfd_byte
*plt_entry
;
3600 if (bfd_link_pic (info
))
3601 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3603 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3604 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
3605 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
3607 resolved_plt
= htab
->plt_second
;
3608 plt_offset
= eh
->plt_second
.offset
;
3613 plt_offset
= h
->plt
.offset
;
3616 if (! bfd_link_pic (info
))
3618 bfd_put_32 (output_bfd
,
3619 (gotplt
->output_section
->vma
3620 + gotplt
->output_offset
3622 resolved_plt
->contents
+ plt_offset
3623 + htab
->plt
.plt_got_offset
);
3625 if (htab
->elf
.target_os
== is_vxworks
)
3627 int s
, k
, reloc_index
;
3629 /* Create the R_386_32 relocation referencing the GOT
3630 for this PLT entry. */
3632 /* S: Current slot number (zero-based). */
3633 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
3634 / htab
->plt
.plt_entry_size
);
3635 /* K: Number of relocations for PLTResolve. */
3636 if (bfd_link_pic (info
))
3637 k
= PLTRESOLVE_RELOCS_SHLIB
;
3639 k
= PLTRESOLVE_RELOCS
;
3640 /* Skip the PLTresolve relocations, and the relocations for
3641 the other PLT slots. */
3642 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3643 loc
= (htab
->srelplt2
->contents
+ reloc_index
3644 * sizeof (Elf32_External_Rel
));
3646 rel
.r_offset
= (plt
->output_section
->vma
3647 + plt
->output_offset
3648 + h
->plt
.offset
+ 2),
3649 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3650 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3652 /* Create the R_386_32 relocation referencing the beginning of
3653 the PLT for this GOT entry. */
3654 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3655 + htab
->elf
.sgotplt
->output_offset
3657 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3658 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3659 loc
+ sizeof (Elf32_External_Rel
));
3664 bfd_put_32 (output_bfd
, got_offset
,
3665 resolved_plt
->contents
+ plt_offset
3666 + htab
->plt
.plt_got_offset
);
3669 /* Fill in the entry in the global offset table. Leave the entry
3670 as zero for undefined weak symbol in PIE. No PLT relocation
3671 against undefined weak symbol in PIE. */
3672 if (!local_undefweak
)
3674 if (htab
->plt
.has_plt0
)
3675 bfd_put_32 (output_bfd
,
3676 (plt
->output_section
->vma
3677 + plt
->output_offset
3679 + htab
->lazy_plt
->plt_lazy_offset
),
3680 gotplt
->contents
+ got_offset
);
3682 /* Fill in the entry in the .rel.plt section. */
3683 rel
.r_offset
= (gotplt
->output_section
->vma
3684 + gotplt
->output_offset
3686 if (PLT_LOCAL_IFUNC_P (info
, h
))
3688 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
3689 h
->root
.root
.string
,
3690 h
->root
.u
.def
.section
->owner
);
3692 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3693 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
3694 in the .got.plt section. */
3695 bfd_put_32 (output_bfd
,
3696 (h
->root
.u
.def
.value
3697 + h
->root
.u
.def
.section
->output_section
->vma
3698 + h
->root
.u
.def
.section
->output_offset
),
3699 gotplt
->contents
+ got_offset
);
3700 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3702 if (htab
->params
->report_relative_reloc
)
3703 _bfd_x86_elf_link_report_relative_reloc
3704 (info
, relplt
, h
, sym
, "R_386_IRELATIVE", &rel
);
3706 /* R_386_IRELATIVE comes last. */
3707 plt_index
= htab
->next_irelative_index
--;
3711 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3712 plt_index
= htab
->next_jump_slot_index
++;
3715 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3716 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3718 /* Don't fill the second and third slots in PLT entry for
3719 static executables nor without PLT0. */
3720 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
3722 bfd_put_32 (output_bfd
,
3723 plt_index
* sizeof (Elf32_External_Rel
),
3724 plt
->contents
+ h
->plt
.offset
3725 + htab
->lazy_plt
->plt_reloc_offset
);
3726 bfd_put_32 (output_bfd
,
3728 + htab
->lazy_plt
->plt_plt_offset
+ 4),
3729 (plt
->contents
+ h
->plt
.offset
3730 + htab
->lazy_plt
->plt_plt_offset
));
3734 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
3736 bfd_vma got_offset
, plt_offset
;
3737 asection
*plt
, *got
, *gotplt
;
3738 const bfd_byte
*got_plt_entry
;
3740 /* Set the entry in the GOT procedure linkage table. */
3741 plt
= htab
->plt_got
;
3742 got
= htab
->elf
.sgot
;
3743 gotplt
= htab
->elf
.sgotplt
;
3744 got_offset
= h
->got
.offset
;
3746 if (got_offset
== (bfd_vma
) -1
3752 /* Fill in the entry in the GOT procedure linkage table. */
3753 if (! bfd_link_pic (info
))
3755 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3756 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
3760 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3761 got_offset
+= (got
->output_section
->vma
3762 + got
->output_offset
3763 - gotplt
->output_section
->vma
3764 - gotplt
->output_offset
);
3767 plt_offset
= eh
->plt_got
.offset
;
3768 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
3769 htab
->non_lazy_plt
->plt_entry_size
);
3770 bfd_put_32 (output_bfd
, got_offset
,
3771 (plt
->contents
+ plt_offset
3772 + htab
->non_lazy_plt
->plt_got_offset
));
3775 if (!local_undefweak
3777 && (h
->plt
.offset
!= (bfd_vma
) -1
3778 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
3780 /* Mark the symbol as undefined, rather than as defined in
3781 the .plt section. Leave the value if there were any
3782 relocations where pointer equality matters (this is a clue
3783 for the dynamic linker, to make function pointer
3784 comparisons work between an application and shared
3785 library), otherwise set it to zero. If a function is only
3786 called from a binary, there is no need to slow down
3787 shared libraries because of that. */
3788 sym
->st_shndx
= SHN_UNDEF
;
3789 if (!h
->pointer_equality_needed
)
3793 _bfd_x86_elf_link_fixup_ifunc_symbol (info
, htab
, h
, sym
);
3795 /* Don't generate dynamic GOT relocation against undefined weak
3796 symbol in executable. */
3797 if (h
->got
.offset
!= (bfd_vma
) -1
3798 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h
)->tls_type
)
3799 && (elf_x86_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
3800 && !local_undefweak
)
3802 Elf_Internal_Rela rel
;
3803 asection
*relgot
= htab
->elf
.srelgot
;
3804 const char *relative_reloc_name
= NULL
;
3806 /* This symbol has an entry in the global offset table. Set it
3809 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
3812 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3813 + htab
->elf
.sgot
->output_offset
3814 + (h
->got
.offset
& ~(bfd_vma
) 1));
3816 /* If this is a static link, or it is a -Bsymbolic link and the
3817 symbol is defined locally or was forced to be local because
3818 of a version file, we just want to emit a RELATIVE reloc.
3819 The entry in the global offset table will already have been
3820 initialized in the relocate_section function. */
3822 && h
->type
== STT_GNU_IFUNC
)
3824 if (h
->plt
.offset
== (bfd_vma
) -1)
3826 /* STT_GNU_IFUNC is referenced without PLT. */
3827 if (htab
->elf
.splt
== NULL
)
3829 /* use .rel[a].iplt section to store .got relocations
3830 in static executable. */
3831 relgot
= htab
->elf
.irelplt
;
3833 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3835 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
3836 h
->root
.root
.string
,
3837 h
->root
.u
.def
.section
->owner
);
3839 bfd_put_32 (output_bfd
,
3840 (h
->root
.u
.def
.value
3841 + h
->root
.u
.def
.section
->output_section
->vma
3842 + h
->root
.u
.def
.section
->output_offset
),
3843 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3844 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3845 relative_reloc_name
= "R_386_IRELATIVE";
3850 else if (bfd_link_pic (info
))
3852 /* Generate R_386_GLOB_DAT. */
3860 if (!h
->pointer_equality_needed
)
3863 /* For non-shared object, we can't use .got.plt, which
3864 contains the real function addres if we need pointer
3865 equality. We load the GOT entry with the PLT entry. */
3866 if (htab
->plt_second
!= NULL
)
3868 plt
= htab
->plt_second
;
3869 plt_offset
= eh
->plt_second
.offset
;
3873 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3874 plt_offset
= h
->plt
.offset
;
3876 bfd_put_32 (output_bfd
,
3877 (plt
->output_section
->vma
3878 + plt
->output_offset
+ plt_offset
),
3879 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3883 else if (bfd_link_pic (info
)
3884 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3886 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3887 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3888 relative_reloc_name
= "R_386_RELATIVE";
3892 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3894 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3895 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3896 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3899 if (relative_reloc_name
!= NULL
3900 && htab
->params
->report_relative_reloc
)
3901 _bfd_x86_elf_link_report_relative_reloc
3902 (info
, relgot
, h
, sym
, relative_reloc_name
, &rel
);
3904 elf_append_rel (output_bfd
, relgot
, &rel
);
3909 Elf_Internal_Rela rel
;
3912 /* This symbol needs a copy reloc. Set it up. */
3913 VERIFY_COPY_RELOC (h
, htab
)
3915 rel
.r_offset
= (h
->root
.u
.def
.value
3916 + h
->root
.u
.def
.section
->output_section
->vma
3917 + h
->root
.u
.def
.section
->output_offset
);
3918 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
3919 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
3920 s
= htab
->elf
.sreldynrelro
;
3922 s
= htab
->elf
.srelbss
;
3923 elf_append_rel (output_bfd
, s
, &rel
);
3929 /* Finish up local dynamic symbol handling. We set the contents of
3930 various dynamic sections here. */
3933 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
3935 struct elf_link_hash_entry
*h
3936 = (struct elf_link_hash_entry
*) *slot
;
3937 struct bfd_link_info
*info
3938 = (struct bfd_link_info
*) inf
;
3940 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
3944 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
3945 here since undefined weak symbol may not be dynamic and may not be
3946 called for elf_i386_finish_dynamic_symbol. */
3949 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
3952 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
3953 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3955 if (h
->root
.type
!= bfd_link_hash_undefweak
3956 || h
->dynindx
!= -1)
3959 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
3963 /* Used to decide how to sort relocs in an optimal manner for the
3964 dynamic linker, before writing them out. */
3966 static enum elf_reloc_type_class
3967 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
3968 const asection
*rel_sec ATTRIBUTE_UNUSED
,
3969 const Elf_Internal_Rela
*rela
)
3971 bfd
*abfd
= info
->output_bfd
;
3972 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3973 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3975 if (htab
->dynsym
!= NULL
3976 && htab
->dynsym
->contents
!= NULL
)
3978 /* Check relocation against STT_GNU_IFUNC symbol if there are
3980 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
3981 if (r_symndx
!= STN_UNDEF
)
3983 Elf_Internal_Sym sym
;
3984 if (!bed
->s
->swap_symbol_in (abfd
,
3985 (htab
->dynsym
->contents
3986 + r_symndx
* sizeof (Elf32_External_Sym
)),
3990 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
3991 return reloc_class_ifunc
;
3995 switch (ELF32_R_TYPE (rela
->r_info
))
3997 case R_386_IRELATIVE
:
3998 return reloc_class_ifunc
;
3999 case R_386_RELATIVE
:
4000 return reloc_class_relative
;
4001 case R_386_JUMP_SLOT
:
4002 return reloc_class_plt
;
4004 return reloc_class_copy
;
4006 return reloc_class_normal
;
4010 /* Finish up the dynamic sections. */
4013 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4014 struct bfd_link_info
*info
)
4016 struct elf_x86_link_hash_table
*htab
;
4018 htab
= _bfd_x86_elf_finish_dynamic_sections (output_bfd
, info
);
4022 if (!htab
->elf
.dynamic_sections_created
)
4025 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4027 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4028 really seem like the right value. */
4029 elf_section_data (htab
->elf
.splt
->output_section
)
4030 ->this_hdr
.sh_entsize
= 4;
4032 if (htab
->plt
.has_plt0
)
4034 /* Fill in the special first entry in the procedure linkage
4036 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
4037 htab
->lazy_plt
->plt0_entry_size
);
4038 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
4039 htab
->plt0_pad_byte
,
4040 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
4041 if (!bfd_link_pic (info
))
4043 bfd_put_32 (output_bfd
,
4044 (htab
->elf
.sgotplt
->output_section
->vma
4045 + htab
->elf
.sgotplt
->output_offset
4047 htab
->elf
.splt
->contents
4048 + htab
->lazy_plt
->plt0_got1_offset
);
4049 bfd_put_32 (output_bfd
,
4050 (htab
->elf
.sgotplt
->output_section
->vma
4051 + htab
->elf
.sgotplt
->output_offset
4053 htab
->elf
.splt
->contents
4054 + htab
->lazy_plt
->plt0_got2_offset
);
4056 if (htab
->elf
.target_os
== is_vxworks
)
4058 Elf_Internal_Rela rel
;
4059 int num_plts
= (htab
->elf
.splt
->size
4060 / htab
->plt
.plt_entry_size
) - 1;
4062 asection
*srelplt2
= htab
->srelplt2
;
4064 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4065 + 4. On IA32 we use REL relocations so the
4066 addend goes in the PLT directly. */
4067 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4068 + htab
->elf
.splt
->output_offset
4069 + htab
->lazy_plt
->plt0_got1_offset
);
4070 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4072 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4073 srelplt2
->contents
);
4074 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4076 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4077 + htab
->elf
.splt
->output_offset
4078 + htab
->lazy_plt
->plt0_got2_offset
);
4079 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4081 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4082 srelplt2
->contents
+
4083 sizeof (Elf32_External_Rel
));
4084 /* Correct the .rel.plt.unloaded relocations. */
4085 p
= srelplt2
->contents
;
4086 if (bfd_link_pic (info
))
4087 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4089 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4091 for (; num_plts
; num_plts
--)
4093 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4094 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4096 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4097 p
+= sizeof (Elf32_External_Rel
);
4099 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4100 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
4102 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4103 p
+= sizeof (Elf32_External_Rel
);
4110 /* Fill PLT entries for undefined weak symbols in PIE. */
4111 if (bfd_link_pie (info
))
4112 bfd_hash_traverse (&info
->hash
->table
,
4113 elf_i386_pie_finish_undefweak_symbol
,
4119 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4120 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4121 It has to be done before elf_link_sort_relocs is called so that
4122 dynamic relocations are properly sorted. */
4125 elf_i386_output_arch_local_syms
4126 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4127 struct bfd_link_info
*info
,
4128 void *flaginfo ATTRIBUTE_UNUSED
,
4129 int (*func
) (void *, const char *,
4132 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4134 struct elf_x86_link_hash_table
*htab
4135 = elf_x86_hash_table (info
, I386_ELF_DATA
);
4139 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4140 htab_traverse (htab
->loc_hash_table
,
4141 elf_i386_finish_local_dynamic_symbol
,
4147 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4148 dynamic relocations. */
4151 elf_i386_get_synthetic_symtab (bfd
*abfd
,
4152 long symcount ATTRIBUTE_UNUSED
,
4153 asymbol
**syms ATTRIBUTE_UNUSED
,
4160 bfd_byte
*plt_contents
;
4162 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4163 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4164 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4165 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4168 enum elf_x86_plt_type plt_type
;
4169 struct elf_x86_plt plts
[] =
4171 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4172 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4173 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4174 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4179 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4182 if (dynsymcount
<= 0)
4185 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4189 non_lazy_plt
= NULL
;
4190 /* Silence GCC 6. */
4192 non_lazy_ibt_plt
= NULL
;
4193 lazy_ibt_plt
= NULL
;
4194 switch (get_elf_backend_data (abfd
)->target_os
)
4198 non_lazy_plt
= &elf_i386_non_lazy_plt
;
4199 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4200 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4203 lazy_plt
= &elf_i386_lazy_plt
;
4212 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4214 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4215 if (plt
== NULL
|| plt
->size
== 0)
4218 /* Get the PLT section contents. */
4219 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
4220 if (plt_contents
== NULL
)
4222 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
4223 plt_contents
, 0, plt
->size
))
4225 free (plt_contents
);
4229 /* Check what kind of PLT it is. */
4230 plt_type
= plt_unknown
;
4231 if (plts
[j
].type
== plt_unknown
4232 && (plt
->size
>= (lazy_plt
->plt0_entry_size
4233 + lazy_plt
->plt_entry_size
)))
4235 /* Match lazy PLT first. */
4236 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4237 lazy_plt
->plt0_got1_offset
) == 0)
4239 /* The fist entry in the lazy IBT PLT is the same as the
4241 if (lazy_ibt_plt
!= NULL
4242 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4243 lazy_ibt_plt
->plt_entry
,
4244 lazy_ibt_plt
->plt_got_offset
) == 0))
4245 plt_type
= plt_lazy
| plt_second
;
4247 plt_type
= plt_lazy
;
4249 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
4250 lazy_plt
->plt0_got1_offset
) == 0)
4252 /* The fist entry in the PIC lazy IBT PLT is the same as
4253 the normal PIC lazy PLT. */
4254 if (lazy_ibt_plt
!= NULL
4255 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4256 lazy_ibt_plt
->pic_plt_entry
,
4257 lazy_ibt_plt
->plt_got_offset
) == 0))
4258 plt_type
= plt_lazy
| plt_pic
| plt_second
;
4260 plt_type
= plt_lazy
| plt_pic
;
4264 if (non_lazy_plt
!= NULL
4265 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
4266 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
4268 /* Match non-lazy PLT. */
4269 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
4270 non_lazy_plt
->plt_got_offset
) == 0)
4271 plt_type
= plt_non_lazy
;
4272 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
4273 non_lazy_plt
->plt_got_offset
) == 0)
4277 if ((non_lazy_ibt_plt
!= NULL
)
4278 && (plt_type
== plt_unknown
|| plt_type
== plt_second
)
4279 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
)
4281 if (memcmp (plt_contents
,
4282 non_lazy_ibt_plt
->plt_entry
,
4283 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4285 /* Match IBT PLT. */
4286 plt_type
= plt_second
;
4287 non_lazy_plt
= non_lazy_ibt_plt
;
4289 else if (memcmp (plt_contents
,
4290 non_lazy_ibt_plt
->pic_plt_entry
,
4291 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4293 /* Match PIC IBT PLT. */
4294 plt_type
= plt_second
| plt_pic
;
4295 non_lazy_plt
= non_lazy_ibt_plt
;
4299 if (plt_type
== plt_unknown
)
4301 free (plt_contents
);
4306 plts
[j
].type
= plt_type
;
4308 if ((plt_type
& plt_lazy
))
4310 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
4311 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
4312 /* Skip PLT0 in lazy PLT. */
4317 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
4318 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
4322 /* Skip lazy PLT when the second PLT is used. */
4323 if ((plt_type
& (plt_lazy
| plt_second
))
4324 == (plt_lazy
| plt_second
))
4328 n
= plt
->size
/ plts
[j
].plt_entry_size
;
4333 plts
[j
].contents
= plt_contents
;
4335 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
4336 if ((plt_type
& plt_pic
))
4337 got_addr
= (bfd_vma
) -1;
4340 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
4341 got_addr
, plts
, dynsyms
,
4345 /* Set up i386 GNU properties. Return the first relocatable ELF input
4346 with GNU properties if found. Otherwise, return NULL. */
4349 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
4351 struct elf_x86_init_table init_table
;
4353 switch (get_elf_backend_data (info
->output_bfd
)->target_os
)
4357 init_table
.plt0_pad_byte
= 0x0;
4358 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4359 init_table
.non_lazy_plt
= &elf_i386_non_lazy_plt
;
4360 init_table
.lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4361 init_table
.non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4364 init_table
.plt0_pad_byte
= 0x90;
4365 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4366 init_table
.non_lazy_plt
= NULL
;
4367 init_table
.lazy_ibt_plt
= NULL
;
4368 init_table
.non_lazy_ibt_plt
= NULL
;
4374 init_table
.r_info
= elf32_r_info
;
4375 init_table
.r_sym
= elf32_r_sym
;
4377 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
4380 #define TARGET_LITTLE_SYM i386_elf32_vec
4381 #define TARGET_LITTLE_NAME "elf32-i386"
4382 #define ELF_ARCH bfd_arch_i386
4383 #define ELF_TARGET_ID I386_ELF_DATA
4384 #define ELF_MACHINE_CODE EM_386
4385 #define ELF_MAXPAGESIZE 0x1000
4387 #define elf_backend_can_gc_sections 1
4388 #define elf_backend_can_refcount 1
4389 #define elf_backend_want_got_plt 1
4390 #define elf_backend_plt_readonly 1
4391 #define elf_backend_want_plt_sym 0
4392 #define elf_backend_got_header_size 12
4393 #define elf_backend_plt_alignment 4
4394 #define elf_backend_dtrel_excludes_plt 1
4395 #define elf_backend_extern_protected_data 1
4396 #define elf_backend_caches_rawsize 1
4397 #define elf_backend_want_dynrelro 1
4399 /* Support RELA for objdump of prelink objects. */
4400 #define elf_info_to_howto elf_i386_info_to_howto_rel
4401 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4403 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4404 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4405 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4406 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
4408 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4409 #define elf_backend_check_relocs elf_i386_check_relocs
4410 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
4411 #define elf_backend_fake_sections elf_i386_fake_sections
4412 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4413 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4414 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
4415 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4416 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4417 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4418 #define elf_backend_relocate_section elf_i386_relocate_section
4419 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
4420 #define elf_backend_hide_symbol _bfd_x86_elf_hide_symbol
4422 #define elf_backend_linux_prpsinfo32_ugid16 true
4424 #define elf32_bed elf32_i386_bed
4426 #include "elf32-target.h"
4428 /* FreeBSD support. */
4430 #undef TARGET_LITTLE_SYM
4431 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
4432 #undef TARGET_LITTLE_NAME
4433 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4435 #define ELF_OSABI ELFOSABI_FREEBSD
4437 /* The kernel recognizes executables as valid only if they carry a
4438 "FreeBSD" label in the ELF header. So we put this label on all
4439 executables and (for simplicity) also all other object files. */
4442 elf_i386_fbsd_init_file_header (bfd
*abfd
, struct bfd_link_info
*info
)
4444 if (!_bfd_elf_init_file_header (abfd
, info
))
4447 #ifdef OLD_FREEBSD_ABI_LABEL
4449 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4450 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
4451 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4457 #undef elf_backend_init_file_header
4458 #define elf_backend_init_file_header elf_i386_fbsd_init_file_header
4460 #define elf32_bed elf32_i386_fbsd_bed
4462 #undef elf_backend_add_symbol_hook
4464 #include "elf32-target.h"
4466 #undef elf_backend_init_file_header
4470 #undef TARGET_LITTLE_SYM
4471 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
4472 #undef TARGET_LITTLE_NAME
4473 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
4475 #undef ELF_TARGET_OS
4476 #define ELF_TARGET_OS is_solaris
4478 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4479 objects won't be recognized. */
4483 #define elf32_bed elf32_i386_sol2_bed
4485 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
4487 #undef elf_backend_static_tls_alignment
4488 #define elf_backend_static_tls_alignment 8
4490 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4492 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4494 #undef elf_backend_want_plt_sym
4495 #define elf_backend_want_plt_sym 1
4497 #undef elf_backend_strtab_flags
4498 #define elf_backend_strtab_flags SHF_STRINGS
4500 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
4501 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
4502 FALSE otherwise. ISECTION is the best guess matching section from the
4503 input bfd IBFD, but it might be NULL. */
4506 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
4507 bfd
*obfd ATTRIBUTE_UNUSED
,
4508 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
4509 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
4511 /* PR 19938: FIXME: Need to add code for setting the sh_info
4512 and sh_link fields of Solaris specific section types. */
4515 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
4516 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
4518 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
4520 The following values should be set:
4523 -----------------------------------------------------------------------------
4524 SHT_SUNW_ancillary The section header index of 0
4525 [0x6fffffee] the associated string table.
4527 SHT_SUNW_capinfo The section header index of For a dynamic object, the
4528 [0x6ffffff0] the associated symbol table. section header index of
4530 SHT_SUNW_capchain table,
4533 SHT_SUNW_symsort The section header index of 0
4534 [0x6ffffff1] the associated symbol table.
4536 SHT_SUNW_tlssort The section header index of 0
4537 [0x6ffffff2] the associated symbol table.
4539 SHT_SUNW_LDYNSYM The section header index of One greater than the
4540 [0x6ffffff3] the associated string table. symbol table index of the
4541 This index is the same string last local symbol,
4542 table used by the SHT_DYNSYM STB_LOCAL. Since
4543 section. SHT_SUNW_LDYNSYM only
4544 contains local symbols,
4545 sh_info is equivalent to
4546 the number of symbols in
4549 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
4550 [0x6ffffff5] the section header index of to named strings, the
4551 the associated section header index of
4552 SHT_SUNW_capinfo table, the associated string
4553 otherwise 0. table, otherwise 0.
4555 SHT_SUNW_move The section header index of 0
4556 [0x6ffffffa] the associated symbol table.
4561 SHT_SUNW_syminfo The section header index of The section header index
4562 [0x6ffffffc] the associated symbol table. of the associated
4565 SHT_SUNW_verdef The section header index of The number of version
4566 [0x6ffffffd] the associated string table. definitions within the
4569 SHT_SUNW_verneed The section header index of The number of version
4570 [0x6ffffffe] the associated string table. dependencies within the
4573 SHT_SUNW_versym The section header index of 0
4574 [0x6fffffff] the associated symbol table. */
4577 #undef elf_backend_copy_special_section_fields
4578 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
4580 #include "elf32-target.h"
4582 /* Intel MCU support. */
4585 elf32_iamcu_elf_object_p (bfd
*abfd
)
4587 /* Set the right machine number for an IAMCU elf32 file. */
4588 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
4592 #undef TARGET_LITTLE_SYM
4593 #define TARGET_LITTLE_SYM iamcu_elf32_vec
4594 #undef TARGET_LITTLE_NAME
4595 #define TARGET_LITTLE_NAME "elf32-iamcu"
4597 #define ELF_ARCH bfd_arch_iamcu
4599 #undef ELF_MACHINE_CODE
4600 #define ELF_MACHINE_CODE EM_IAMCU
4602 #undef ELF_TARGET_OS
4606 #define elf32_bed elf32_iamcu_bed
4608 #undef elf_backend_object_p
4609 #define elf_backend_object_p elf32_iamcu_elf_object_p
4611 #undef elf_backend_static_tls_alignment
4613 #undef elf_backend_want_plt_sym
4614 #define elf_backend_want_plt_sym 0
4616 #undef elf_backend_strtab_flags
4617 #undef elf_backend_copy_special_section_fields
4619 #include "elf32-target.h"
4621 /* Restore defaults. */
4623 #define ELF_ARCH bfd_arch_i386
4624 #undef ELF_MACHINE_CODE
4625 #define ELF_MACHINE_CODE EM_386
4626 #undef elf_backend_object_p
4628 /* VxWorks support. */
4630 #undef TARGET_LITTLE_SYM
4631 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
4632 #undef TARGET_LITTLE_NAME
4633 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4635 #undef ELF_MAXPAGESIZE
4636 #define ELF_MAXPAGESIZE 0x1000
4637 #undef elf_backend_plt_alignment
4638 #define elf_backend_plt_alignment 4
4640 #undef ELF_TARGET_OS
4641 #define ELF_TARGET_OS is_vxworks
4643 #undef elf_backend_relocs_compatible
4644 #undef elf_backend_add_symbol_hook
4645 #define elf_backend_add_symbol_hook \
4646 elf_vxworks_add_symbol_hook
4647 #undef elf_backend_link_output_symbol_hook
4648 #define elf_backend_link_output_symbol_hook \
4649 elf_vxworks_link_output_symbol_hook
4650 #undef elf_backend_emit_relocs
4651 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
4652 #undef elf_backend_final_write_processing
4653 #define elf_backend_final_write_processing \
4654 elf_vxworks_final_write_processing
4655 #undef elf_backend_static_tls_alignment
4657 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
4659 #undef elf_backend_want_plt_sym
4660 #define elf_backend_want_plt_sym 1
4663 #define elf32_bed elf32_i386_vxworks_bed
4665 #include "elf32-target.h"