1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #include "elfxx-x86.h"
23 #include "elf-vxworks.h"
25 #include "opcode/i386.h"
27 /* 386 uses REL relocations instead of RELA. */
32 static reloc_howto_type elf_howto_table
[]=
34 HOWTO(R_386_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
35 bfd_elf_generic_reloc
, "R_386_NONE",
36 TRUE
, 0x00000000, 0x00000000, FALSE
),
37 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
38 bfd_elf_generic_reloc
, "R_386_32",
39 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
40 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
41 bfd_elf_generic_reloc
, "R_386_PC32",
42 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
43 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
44 bfd_elf_generic_reloc
, "R_386_GOT32",
45 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
46 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
47 bfd_elf_generic_reloc
, "R_386_PLT32",
48 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
49 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
50 bfd_elf_generic_reloc
, "R_386_COPY",
51 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
52 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
53 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
54 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
55 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
56 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
57 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
58 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
59 bfd_elf_generic_reloc
, "R_386_RELATIVE",
60 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
61 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_386_GOTOFF",
63 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
64 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
65 bfd_elf_generic_reloc
, "R_386_GOTPC",
66 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
68 /* We have a gap in the reloc numbers here.
69 R_386_standard counts the number up to this point, and
70 R_386_ext_offset is the value to subtract from a reloc type of
71 R_386_16 thru R_386_PC8 to form an index into this table. */
72 #define R_386_standard (R_386_GOTPC + 1)
73 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
75 /* These relocs are a GNU extension. */
76 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
78 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
79 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
80 bfd_elf_generic_reloc
, "R_386_TLS_IE",
81 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
82 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
84 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
85 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
86 bfd_elf_generic_reloc
, "R_386_TLS_LE",
87 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
88 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_386_TLS_GD",
90 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
91 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
92 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
93 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
94 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_386_16",
96 TRUE
, 0xffff, 0xffff, FALSE
),
97 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
98 bfd_elf_generic_reloc
, "R_386_PC16",
99 TRUE
, 0xffff, 0xffff, TRUE
),
100 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
101 bfd_elf_generic_reloc
, "R_386_8",
102 TRUE
, 0xff, 0xff, FALSE
),
103 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
104 bfd_elf_generic_reloc
, "R_386_PC8",
105 TRUE
, 0xff, 0xff, TRUE
),
107 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
108 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
109 /* These are common with Solaris TLS implementation. */
110 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
111 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
112 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
113 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
114 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
115 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
116 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
118 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
119 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
121 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
122 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
123 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
124 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
125 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
126 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
127 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
128 HOWTO(R_386_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
129 bfd_elf_generic_reloc
, "R_386_SIZE32",
130 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
131 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
132 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
133 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
135 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
137 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
139 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
140 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
141 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
142 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
143 HOWTO(R_386_GOT32X
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_GOT32X",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
148 #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
149 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
151 /* GNU extension to record C++ vtable hierarchy. */
152 HOWTO (R_386_GNU_VTINHERIT
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_dont
, /* complain_on_overflow */
159 NULL
, /* special_function */
160 "R_386_GNU_VTINHERIT", /* name */
161 FALSE
, /* partial_inplace */
164 FALSE
), /* pcrel_offset */
166 /* GNU extension to record C++ vtable member usage. */
167 HOWTO (R_386_GNU_VTENTRY
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE
, /* pc_relative */
173 complain_overflow_dont
, /* complain_on_overflow */
174 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
175 "R_386_GNU_VTENTRY", /* name */
176 FALSE
, /* partial_inplace */
179 FALSE
) /* pcrel_offset */
181 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
185 #ifdef DEBUG_GEN_RELOC
187 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
192 static reloc_howto_type
*
193 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
194 bfd_reloc_code_real_type code
)
199 TRACE ("BFD_RELOC_NONE");
200 return &elf_howto_table
[R_386_NONE
];
203 TRACE ("BFD_RELOC_32");
204 return &elf_howto_table
[R_386_32
];
207 TRACE ("BFD_RELOC_CTOR");
208 return &elf_howto_table
[R_386_32
];
210 case BFD_RELOC_32_PCREL
:
211 TRACE ("BFD_RELOC_PC32");
212 return &elf_howto_table
[R_386_PC32
];
214 case BFD_RELOC_386_GOT32
:
215 TRACE ("BFD_RELOC_386_GOT32");
216 return &elf_howto_table
[R_386_GOT32
];
218 case BFD_RELOC_386_PLT32
:
219 TRACE ("BFD_RELOC_386_PLT32");
220 return &elf_howto_table
[R_386_PLT32
];
222 case BFD_RELOC_386_COPY
:
223 TRACE ("BFD_RELOC_386_COPY");
224 return &elf_howto_table
[R_386_COPY
];
226 case BFD_RELOC_386_GLOB_DAT
:
227 TRACE ("BFD_RELOC_386_GLOB_DAT");
228 return &elf_howto_table
[R_386_GLOB_DAT
];
230 case BFD_RELOC_386_JUMP_SLOT
:
231 TRACE ("BFD_RELOC_386_JUMP_SLOT");
232 return &elf_howto_table
[R_386_JUMP_SLOT
];
234 case BFD_RELOC_386_RELATIVE
:
235 TRACE ("BFD_RELOC_386_RELATIVE");
236 return &elf_howto_table
[R_386_RELATIVE
];
238 case BFD_RELOC_386_GOTOFF
:
239 TRACE ("BFD_RELOC_386_GOTOFF");
240 return &elf_howto_table
[R_386_GOTOFF
];
242 case BFD_RELOC_386_GOTPC
:
243 TRACE ("BFD_RELOC_386_GOTPC");
244 return &elf_howto_table
[R_386_GOTPC
];
246 /* These relocs are a GNU extension. */
247 case BFD_RELOC_386_TLS_TPOFF
:
248 TRACE ("BFD_RELOC_386_TLS_TPOFF");
249 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
251 case BFD_RELOC_386_TLS_IE
:
252 TRACE ("BFD_RELOC_386_TLS_IE");
253 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
255 case BFD_RELOC_386_TLS_GOTIE
:
256 TRACE ("BFD_RELOC_386_TLS_GOTIE");
257 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
259 case BFD_RELOC_386_TLS_LE
:
260 TRACE ("BFD_RELOC_386_TLS_LE");
261 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
263 case BFD_RELOC_386_TLS_GD
:
264 TRACE ("BFD_RELOC_386_TLS_GD");
265 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
267 case BFD_RELOC_386_TLS_LDM
:
268 TRACE ("BFD_RELOC_386_TLS_LDM");
269 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
272 TRACE ("BFD_RELOC_16");
273 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
275 case BFD_RELOC_16_PCREL
:
276 TRACE ("BFD_RELOC_16_PCREL");
277 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
280 TRACE ("BFD_RELOC_8");
281 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
283 case BFD_RELOC_8_PCREL
:
284 TRACE ("BFD_RELOC_8_PCREL");
285 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
287 /* Common with Sun TLS implementation. */
288 case BFD_RELOC_386_TLS_LDO_32
:
289 TRACE ("BFD_RELOC_386_TLS_LDO_32");
290 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
292 case BFD_RELOC_386_TLS_IE_32
:
293 TRACE ("BFD_RELOC_386_TLS_IE_32");
294 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
296 case BFD_RELOC_386_TLS_LE_32
:
297 TRACE ("BFD_RELOC_386_TLS_LE_32");
298 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
300 case BFD_RELOC_386_TLS_DTPMOD32
:
301 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
302 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
304 case BFD_RELOC_386_TLS_DTPOFF32
:
305 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
306 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
308 case BFD_RELOC_386_TLS_TPOFF32
:
309 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
310 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
312 case BFD_RELOC_SIZE32
:
313 TRACE ("BFD_RELOC_SIZE32");
314 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
316 case BFD_RELOC_386_TLS_GOTDESC
:
317 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
318 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
320 case BFD_RELOC_386_TLS_DESC_CALL
:
321 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
322 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
324 case BFD_RELOC_386_TLS_DESC
:
325 TRACE ("BFD_RELOC_386_TLS_DESC");
326 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
328 case BFD_RELOC_386_IRELATIVE
:
329 TRACE ("BFD_RELOC_386_IRELATIVE");
330 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
332 case BFD_RELOC_386_GOT32X
:
333 TRACE ("BFD_RELOC_386_GOT32X");
334 return &elf_howto_table
[R_386_GOT32X
- R_386_tls_offset
];
336 case BFD_RELOC_VTABLE_INHERIT
:
337 TRACE ("BFD_RELOC_VTABLE_INHERIT");
338 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
340 case BFD_RELOC_VTABLE_ENTRY
:
341 TRACE ("BFD_RELOC_VTABLE_ENTRY");
342 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
352 static reloc_howto_type
*
353 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
358 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
359 if (elf_howto_table
[i
].name
!= NULL
360 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
361 return &elf_howto_table
[i
];
366 static reloc_howto_type
*
367 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
371 if ((indx
= r_type
) >= R_386_standard
372 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
373 >= R_386_ext
- R_386_standard
)
374 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
375 >= R_386_ext2
- R_386_ext
)
376 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
377 >= R_386_vt
- R_386_ext2
))
379 /* xgettext:c-format */
380 _bfd_error_handler (_("%B: invalid relocation type %d"),
384 /* PR 17512: file: 0f67f69d. */
385 if (elf_howto_table
[indx
].type
!= r_type
)
387 return &elf_howto_table
[indx
];
391 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
393 Elf_Internal_Rela
*dst
)
395 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
396 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
399 /* Return whether a symbol name implies a local label. The UnixWare
400 2.1 cc generates temporary symbols that start with .X, so we
401 recognize them here. FIXME: do other SVR4 compilers also use .X?.
402 If so, we should move the .X recognition into
403 _bfd_elf_is_local_label_name. */
406 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
408 if (name
[0] == '.' && name
[1] == 'X')
411 return _bfd_elf_is_local_label_name (abfd
, name
);
414 /* Support for core dump NOTE sections. */
417 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
422 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
424 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
430 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
433 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
437 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
441 switch (note
->descsz
)
446 case 144: /* Linux/i386 */
448 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
451 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
461 /* Make a ".reg/999" section. */
462 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
463 size
, note
->descpos
+ offset
);
467 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
469 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
471 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
476 elf_tdata (abfd
)->core
->program
477 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
478 elf_tdata (abfd
)->core
->command
479 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
483 switch (note
->descsz
)
488 case 124: /* Linux/i386 elf_prpsinfo. */
489 elf_tdata (abfd
)->core
->pid
490 = bfd_get_32 (abfd
, note
->descdata
+ 12);
491 elf_tdata (abfd
)->core
->program
492 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
493 elf_tdata (abfd
)->core
->command
494 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
498 /* Note that for some reason, a spurious space is tacked
499 onto the end of the args in some (at least one anyway)
500 implementations, so strip it off if it exists. */
502 char *command
= elf_tdata (abfd
)->core
->command
;
503 int n
= strlen (command
);
505 if (0 < n
&& command
[n
- 1] == ' ')
506 command
[n
- 1] = '\0';
512 /* Functions for the i386 ELF linker.
514 In order to gain some understanding of code in this file without
515 knowing all the intricate details of the linker, note the
518 Functions named elf_i386_* are called by external routines, other
519 functions are only called locally. elf_i386_* functions appear
520 in this file more or less in the order in which they are called
521 from external routines. eg. elf_i386_check_relocs is called
522 early in the link process, elf_i386_finish_dynamic_sections is
523 one of the last functions. */
526 /* The name of the dynamic interpreter. This is put in the .interp
529 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
531 /* The size in bytes of an entry in the lazy procedure linkage table. */
533 #define LAZY_PLT_ENTRY_SIZE 16
535 /* The size in bytes of an entry in the non-lazy procedure linkage
538 #define NON_LAZY_PLT_ENTRY_SIZE 8
540 /* The first entry in an absolute lazy procedure linkage table looks
541 like this. See the SVR4 ABI i386 supplement to see how this works.
542 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
544 static const bfd_byte elf_i386_lazy_plt0_entry
[12] =
546 0xff, 0x35, /* pushl contents of address */
547 0, 0, 0, 0, /* replaced with address of .got + 4. */
548 0xff, 0x25, /* jmp indirect */
549 0, 0, 0, 0 /* replaced with address of .got + 8. */
552 /* Subsequent entries in an absolute lazy procedure linkage table look
555 static const bfd_byte elf_i386_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
557 0xff, 0x25, /* jmp indirect */
558 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
559 0x68, /* pushl immediate */
560 0, 0, 0, 0, /* replaced with offset into relocation table. */
561 0xe9, /* jmp relative */
562 0, 0, 0, 0 /* replaced with offset to start of .plt. */
565 /* The first entry in a PIC lazy procedure linkage table look like
566 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
567 lazy_plt->plt0_pad_byte. */
569 static const bfd_byte elf_i386_pic_lazy_plt0_entry
[12] =
571 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
572 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
575 /* Subsequent entries in a PIC lazy procedure linkage table look like
578 static const bfd_byte elf_i386_pic_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
580 0xff, 0xa3, /* jmp *offset(%ebx) */
581 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
582 0x68, /* pushl immediate */
583 0, 0, 0, 0, /* replaced with offset into relocation table. */
584 0xe9, /* jmp relative */
585 0, 0, 0, 0 /* replaced with offset to start of .plt. */
588 /* Entries in the non-lazy procedure linkage table look like this. */
590 static const bfd_byte elf_i386_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
592 0xff, 0x25, /* jmp indirect */
593 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
594 0x66, 0x90 /* xchg %ax,%ax */
597 /* Entries in the PIC non-lazy procedure linkage table look like
600 static const bfd_byte elf_i386_pic_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
602 0xff, 0xa3, /* jmp *offset(%ebx) */
603 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
604 0x66, 0x90 /* xchg %ax,%ax */
607 /* The first entry in an absolute IBT-enabled lazy procedure linkage
608 table looks like this. */
610 static const bfd_byte elf_i386_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
612 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
613 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
614 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
617 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
618 table look like this. Subsequent entries for a PIC IBT-enabled lazy
619 procedure linkage table are the same. */
621 static const bfd_byte elf_i386_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
623 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
624 0x68, 0, 0, 0, 0, /* pushl immediate */
625 0xe9, 0, 0, 0, 0, /* jmp relative */
626 0x66, 0x90 /* xchg %ax,%ax */
629 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
632 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
634 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
635 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
636 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
639 /* Entries for branches with IBT-enabled in the absolute non-lazey
640 procedure linkage table look like this. They have the same size
641 as the lazy PLT entry. */
643 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
645 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
646 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
647 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
650 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
651 linkage table look like this. They have the same size as the lazy
654 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
656 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
657 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
658 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
661 /* .eh_frame covering the lazy .plt section. */
663 static const bfd_byte elf_i386_eh_frame_lazy_plt
[] =
665 #define PLT_CIE_LENGTH 20
666 #define PLT_FDE_LENGTH 36
667 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
668 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
669 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
670 0, 0, 0, 0, /* CIE ID */
672 'z', 'R', 0, /* Augmentation string */
673 1, /* Code alignment factor */
674 0x7c, /* Data alignment factor */
675 8, /* Return address column */
676 1, /* Augmentation size */
677 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
678 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
679 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
680 DW_CFA_nop
, DW_CFA_nop
,
682 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
683 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
684 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
685 0, 0, 0, 0, /* .plt size goes here */
686 0, /* Augmentation size */
687 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
688 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
689 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
690 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
691 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
692 11, /* Block length */
693 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
694 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
695 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
696 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
697 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
700 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
702 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt
[] =
704 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
705 0, 0, 0, 0, /* CIE ID */
707 'z', 'R', 0, /* Augmentation string */
708 1, /* Code alignment factor */
709 0x7c, /* Data alignment factor */
710 8, /* Return address column */
711 1, /* Augmentation size */
712 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
713 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
714 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
715 DW_CFA_nop
, DW_CFA_nop
,
717 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
718 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
719 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
720 0, 0, 0, 0, /* .plt size goes here */
721 0, /* Augmentation size */
722 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
723 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
724 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
725 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
726 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
727 11, /* Block length */
728 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
729 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
730 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
731 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
732 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
735 /* .eh_frame covering the non-lazy .plt section. */
737 static const bfd_byte elf_i386_eh_frame_non_lazy_plt
[] =
739 #define PLT_GOT_FDE_LENGTH 16
740 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
741 0, 0, 0, 0, /* CIE ID */
743 'z', 'R', 0, /* Augmentation string */
744 1, /* Code alignment factor */
745 0x7c, /* Data alignment factor */
746 8, /* Return address column */
747 1, /* Augmentation size */
748 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
749 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
750 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
751 DW_CFA_nop
, DW_CFA_nop
,
753 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
754 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
755 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
756 0, 0, 0, 0, /* non-lazy .plt size goes here */
757 0, /* Augmentation size */
758 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
761 struct elf_i386_lazy_plt_layout
763 /* The first entry in an absolute lazy procedure linkage table looks
765 const bfd_byte
*plt0_entry
;
766 unsigned int plt0_entry_size
;
768 /* Offsets into plt0_entry that are to be replaced with GOT[1] and
770 unsigned int plt0_got1_offset
;
771 unsigned int plt0_got2_offset
;
773 /* Later entries in an absolute lazy procedure linkage table look
775 const bfd_byte
*plt_entry
;
776 unsigned int plt_entry_size
;
778 /* Offsets into plt_entry that are to be replaced with... */
779 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
780 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
781 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
783 /* Offset into plt_entry where the initial value of the GOT entry
785 unsigned int plt_lazy_offset
;
787 /* The first entry in a PIC lazy procedure linkage table looks like
789 const bfd_byte
*pic_plt0_entry
;
791 /* Subsequent entries in a PIC lazy procedure linkage table look
793 const bfd_byte
*pic_plt_entry
;
795 /* .eh_frame covering the lazy .plt section. */
796 const bfd_byte
*eh_frame_plt
;
797 unsigned int eh_frame_plt_size
;
800 struct elf_i386_non_lazy_plt_layout
802 /* Entries in an absolute non-lazy procedure linkage table look like
804 const bfd_byte
*plt_entry
;
805 /* Entries in a PIC non-lazy procedure linkage table look like this. */
806 const bfd_byte
*pic_plt_entry
;
808 unsigned int plt_entry_size
;
810 /* Offsets into plt_entry that are to be replaced with... */
811 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
813 /* .eh_frame covering the non-lazy .plt section. */
814 const bfd_byte
*eh_frame_plt
;
815 unsigned int eh_frame_plt_size
;
818 struct elf_i386_plt_layout
820 /* The first entry in a lazy procedure linkage table looks like this. */
821 const bfd_byte
*plt0_entry
;
822 /* Entries in a procedure linkage table look like this. */
823 const bfd_byte
*plt_entry
;
824 unsigned int plt_entry_size
;
827 unsigned int has_plt0
;
829 /* Offsets into plt_entry that are to be replaced with... */
830 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
832 /* .eh_frame covering the .plt section. */
833 const bfd_byte
*eh_frame_plt
;
834 unsigned int eh_frame_plt_size
;
837 /* These are the standard parameters. */
838 static const struct elf_i386_lazy_plt_layout elf_i386_lazy_plt
=
840 elf_i386_lazy_plt0_entry
, /* plt0_entry */
841 sizeof (elf_i386_lazy_plt0_entry
), /* plt0_entry_size */
842 2, /* plt0_got1_offset */
843 8, /* plt0_got2_offset */
844 elf_i386_lazy_plt_entry
, /* plt_entry */
845 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
846 2, /* plt_got_offset */
847 7, /* plt_reloc_offset */
848 12, /* plt_plt_offset */
849 6, /* plt_lazy_offset */
850 elf_i386_pic_lazy_plt0_entry
, /* pic_plt0_entry */
851 elf_i386_pic_lazy_plt_entry
, /* pic_plt_entry */
852 elf_i386_eh_frame_lazy_plt
, /* eh_frame_plt */
853 sizeof (elf_i386_eh_frame_lazy_plt
) /* eh_frame_plt_size */
856 static const struct elf_i386_non_lazy_plt_layout elf_i386_non_lazy_plt
=
858 elf_i386_non_lazy_plt_entry
, /* plt_entry */
859 elf_i386_pic_non_lazy_plt_entry
, /* pic_plt_entry */
860 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
861 2, /* plt_got_offset */
862 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
863 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
866 static const struct elf_i386_lazy_plt_layout elf_i386_lazy_ibt_plt
=
868 elf_i386_lazy_ibt_plt0_entry
, /* plt0_entry */
869 sizeof (elf_i386_lazy_ibt_plt0_entry
), /* plt0_entry_size */
870 2, /* plt0_got1_offset */
871 8, /* plt0_got2_offset */
872 elf_i386_lazy_ibt_plt_entry
, /* plt_entry */
873 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
874 4+2, /* plt_got_offset */
875 4+1, /* plt_reloc_offset */
876 4+6, /* plt_plt_offset */
877 0, /* plt_lazy_offset */
878 elf_i386_pic_lazy_ibt_plt0_entry
, /* pic_plt0_entry */
879 elf_i386_lazy_ibt_plt_entry
, /* pic_plt_entry */
880 elf_i386_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
881 sizeof (elf_i386_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
884 static const struct elf_i386_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt
=
886 elf_i386_non_lazy_ibt_plt_entry
, /* plt_entry */
887 elf_i386_pic_non_lazy_ibt_plt_entry
,/* pic_plt_entry */
888 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
889 4+2, /* plt_got_offset */
890 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
891 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
895 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
896 for the PLTResolve stub and then for each PLT entry. */
897 #define PLTRESOLVE_RELOCS_SHLIB 0
898 #define PLTRESOLVE_RELOCS 2
899 #define PLT_NON_JUMP_SLOT_RELOCS 2
901 /* Architecture-specific backend data for i386. */
903 struct elf_i386_backend_data
905 /* Value used to fill the unused bytes of the first PLT entry. */
906 bfd_byte plt0_pad_byte
;
917 #define get_elf_i386_backend_data(abfd) \
918 ((const struct elf_i386_backend_data *) \
919 get_elf_backend_data (abfd)->arch_data)
921 /* These are the standard parameters. */
922 static const struct elf_i386_backend_data elf_i386_arch_bed
=
924 0, /* plt0_pad_byte */
928 #define elf_backend_arch_data &elf_i386_arch_bed
930 /* Values in tls_type of x86 ELF linker hash entry. */
932 #define GOT_TLS_IE_POS 5
933 #define GOT_TLS_IE_NEG 6
934 #define GOT_TLS_IE_BOTH 7
935 #define GOT_TLS_GDESC 8
936 #define GOT_TLS_GD_BOTH_P(type) \
937 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
938 #define GOT_TLS_GD_P(type) \
939 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
940 #define GOT_TLS_GDESC_P(type) \
941 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
942 #define GOT_TLS_GD_ANY_P(type) \
943 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
945 #define is_i386_elf(bfd) \
946 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
947 && elf_tdata (bfd) != NULL \
948 && elf_object_id (bfd) == I386_ELF_DATA)
951 elf_i386_mkobject (bfd
*abfd
)
953 return bfd_elf_allocate_object (abfd
,
954 sizeof (struct elf_x86_obj_tdata
),
958 /* i386 ELF linker hash table. */
960 struct elf_i386_link_hash_table
962 struct elf_x86_link_hash_table x86
;
964 /* Parameters describing PLT generation, lazy or non-lazy. */
965 struct elf_i386_plt_layout plt
;
967 /* Parameters describing lazy PLT generation. */
968 const struct elf_i386_lazy_plt_layout
*lazy_plt
;
970 /* Parameters describing non-lazy PLT generation. */
971 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt
;
973 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
976 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
977 bfd_vma next_tls_desc_index
;
980 #define elf_i386_next_tls_desc_index(htab) \
981 ((struct elf_i386_link_hash_table *) (htab))->next_tls_desc_index
983 #define elf_i386_srelplt2(htab) \
984 ((struct elf_i386_link_hash_table *) (htab))->srelplt2
986 #define elf_i386_plt(htab) \
987 ((struct elf_i386_link_hash_table *) (htab))->plt
989 #define elf_i386_lazy_plt(htab) \
990 ((struct elf_i386_link_hash_table *) (htab))->lazy_plt
992 #define elf_i386_non_lazy_plt(htab) \
993 ((struct elf_i386_link_hash_table *) (htab))->non_lazy_plt
995 #define elf_i386_compute_jump_table_size(htab) \
996 ((htab)->elf.srelplt->reloc_count * 4)
998 /* Create an i386 ELF linker hash table. */
1000 static struct bfd_link_hash_table
*
1001 elf_i386_link_hash_table_create (bfd
*abfd
)
1003 struct elf_x86_link_hash_table
*ret
;
1004 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
1006 ret
= (struct elf_x86_link_hash_table
*) bfd_zmalloc (amt
);
1010 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1011 _bfd_x86_elf_link_hash_newfunc
,
1012 sizeof (struct elf_x86_link_hash_entry
),
1019 ret
->r_info
= elf32_r_info
;
1020 ret
->r_sym
= elf32_r_sym
;
1021 ret
->pointer_r_type
= R_386_32
;
1022 ret
->dynamic_interpreter_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1023 ret
->dynamic_interpreter
= ELF_DYNAMIC_INTERPRETER
;
1024 ret
->tls_get_addr
= "___tls_get_addr";
1025 ret
->loc_hash_table
= htab_try_create (1024,
1026 _bfd_x86_elf_local_htab_hash
,
1027 _bfd_x86_elf_local_htab_eq
,
1029 ret
->loc_hash_memory
= objalloc_create ();
1030 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1032 _bfd_x86_elf_link_hash_table_free (abfd
);
1035 ret
->elf
.root
.hash_table_free
= _bfd_x86_elf_link_hash_table_free
;
1037 return &ret
->elf
.root
;
1040 /* Return TRUE if the TLS access code sequence support transition
1044 elf_i386_check_tls_transition (asection
*sec
,
1046 Elf_Internal_Shdr
*symtab_hdr
,
1047 struct elf_link_hash_entry
**sym_hashes
,
1048 unsigned int r_type
,
1049 const Elf_Internal_Rela
*rel
,
1050 const Elf_Internal_Rela
*relend
)
1052 unsigned int val
, type
, reg
;
1053 unsigned long r_symndx
;
1054 struct elf_link_hash_entry
*h
;
1057 bfd_boolean indirect_call
;
1059 offset
= rel
->r_offset
;
1064 if (offset
< 2 || (rel
+ 1) >= relend
)
1067 indirect_call
= FALSE
;
1068 call
= contents
+ offset
+ 4;
1071 if (r_type
== R_386_TLS_GD
)
1073 /* Check transition from GD access model. Only
1074 leal foo@tlsgd(,%ebx,1), %eax
1075 call ___tls_get_addr@PLT
1077 leal foo@tlsgd(%ebx) %eax
1078 call ___tls_get_addr@PLT
1081 leal foo@tlsgd(%reg), %eax
1082 call *___tls_get_addr@GOT(%reg)
1083 which may be converted to
1084 addr32 call ___tls_get_addr
1085 can transit to different access model. */
1086 if ((offset
+ 10) > sec
->size
1087 || (type
!= 0x8d && type
!= 0x04))
1092 /* leal foo@tlsgd(,%ebx,1), %eax
1093 call ___tls_get_addr@PLT */
1097 if (*(call
- 7) != 0x8d
1105 leal foo@tlsgd(%ebx), %eax
1106 call ___tls_get_addr@PLT
1109 leal foo@tlsgd(%reg), %eax
1110 call *___tls_get_addr@GOT(%reg)
1111 which may be converted to
1112 addr32 call ___tls_get_addr
1114 %eax can't be used as the GOT base register since it
1115 is used to pass parameter to ___tls_get_addr. */
1117 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1120 indirect_call
= call
[0] == 0xff;
1121 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
1122 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1124 && (call
[1] & 0xf8) == 0x90
1125 && (call
[1] & 0x7) == reg
))
1131 /* Check transition from LD access model. Only
1132 leal foo@tlsldm(%ebx), %eax
1133 call ___tls_get_addr@PLT
1135 leal foo@tlsldm(%reg), %eax
1136 call *___tls_get_addr@GOT(%reg)
1137 which may be converted to
1138 addr32 call ___tls_get_addr
1139 can transit to different access model. */
1140 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1143 /* %eax can't be used as the GOT base register since it is
1144 used to pass parameter to ___tls_get_addr. */
1146 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1149 indirect_call
= call
[0] == 0xff;
1150 if (!(reg
== 3 && call
[0] == 0xe8)
1151 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1153 && (call
[1] & 0xf8) == 0x90
1154 && (call
[1] & 0x7) == reg
))
1158 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1159 if (r_symndx
< symtab_hdr
->sh_info
)
1162 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1164 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1166 else if (indirect_call
)
1167 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
1169 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1170 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
1173 /* Check transition from IE access model:
1174 movl foo@indntpoff(%rip), %eax
1175 movl foo@indntpoff(%rip), %reg
1176 addl foo@indntpoff(%rip), %reg
1179 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1182 /* Check "movl foo@tpoff(%rip), %eax" first. */
1183 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1190 /* Check movl|addl foo@tpoff(%rip), %reg. */
1191 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1192 return ((type
== 0x8b || type
== 0x03)
1193 && (val
& 0xc7) == 0x05);
1195 case R_386_TLS_GOTIE
:
1196 case R_386_TLS_IE_32
:
1197 /* Check transition from {IE_32,GOTIE} access model:
1198 subl foo@{tpoff,gontoff}(%reg1), %reg2
1199 movl foo@{tpoff,gontoff}(%reg1), %reg2
1200 addl foo@{tpoff,gontoff}(%reg1), %reg2
1203 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1206 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1207 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1210 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1211 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1213 case R_386_TLS_GOTDESC
:
1214 /* Check transition from GDesc access model:
1215 leal x@tlsdesc(%ebx), %eax
1217 Make sure it's a leal adding ebx to a 32-bit offset
1218 into any register, although it's probably almost always
1221 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1224 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1227 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1228 return (val
& 0xc7) == 0x83;
1230 case R_386_TLS_DESC_CALL
:
1231 /* Check transition from GDesc access model:
1232 call *x@tlsdesc(%eax)
1234 if (offset
+ 2 <= sec
->size
)
1236 /* Make sure that it's a call *x@tlsdesc(%eax). */
1237 call
= contents
+ offset
;
1238 return call
[0] == 0xff && call
[1] == 0x10;
1248 /* Return TRUE if the TLS access transition is OK or no transition
1249 will be performed. Update R_TYPE if there is a transition. */
1252 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1253 asection
*sec
, bfd_byte
*contents
,
1254 Elf_Internal_Shdr
*symtab_hdr
,
1255 struct elf_link_hash_entry
**sym_hashes
,
1256 unsigned int *r_type
, int tls_type
,
1257 const Elf_Internal_Rela
*rel
,
1258 const Elf_Internal_Rela
*relend
,
1259 struct elf_link_hash_entry
*h
,
1260 unsigned long r_symndx
,
1261 bfd_boolean from_relocate_section
)
1263 unsigned int from_type
= *r_type
;
1264 unsigned int to_type
= from_type
;
1265 bfd_boolean check
= TRUE
;
1267 /* Skip TLS transition for functions. */
1269 && (h
->type
== STT_FUNC
1270 || h
->type
== STT_GNU_IFUNC
))
1276 case R_386_TLS_GOTDESC
:
1277 case R_386_TLS_DESC_CALL
:
1278 case R_386_TLS_IE_32
:
1280 case R_386_TLS_GOTIE
:
1281 if (bfd_link_executable (info
))
1284 to_type
= R_386_TLS_LE_32
;
1285 else if (from_type
!= R_386_TLS_IE
1286 && from_type
!= R_386_TLS_GOTIE
)
1287 to_type
= R_386_TLS_IE_32
;
1290 /* When we are called from elf_i386_relocate_section, there may
1291 be additional transitions based on TLS_TYPE. */
1292 if (from_relocate_section
)
1294 unsigned int new_to_type
= to_type
;
1296 if (bfd_link_executable (info
)
1299 && (tls_type
& GOT_TLS_IE
))
1300 new_to_type
= R_386_TLS_LE_32
;
1302 if (to_type
== R_386_TLS_GD
1303 || to_type
== R_386_TLS_GOTDESC
1304 || to_type
== R_386_TLS_DESC_CALL
)
1306 if (tls_type
== GOT_TLS_IE_POS
)
1307 new_to_type
= R_386_TLS_GOTIE
;
1308 else if (tls_type
& GOT_TLS_IE
)
1309 new_to_type
= R_386_TLS_IE_32
;
1312 /* We checked the transition before when we were called from
1313 elf_i386_check_relocs. We only want to check the new
1314 transition which hasn't been checked before. */
1315 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1316 to_type
= new_to_type
;
1322 if (bfd_link_executable (info
))
1323 to_type
= R_386_TLS_LE_32
;
1330 /* Return TRUE if there is no transition. */
1331 if (from_type
== to_type
)
1334 /* Check if the transition can be performed. */
1336 && ! elf_i386_check_tls_transition (sec
, contents
,
1337 symtab_hdr
, sym_hashes
,
1338 from_type
, rel
, relend
))
1340 reloc_howto_type
*from
, *to
;
1343 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1344 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1347 name
= h
->root
.root
.string
;
1350 struct elf_x86_link_hash_table
*htab
;
1352 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1357 Elf_Internal_Sym
*isym
;
1359 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1361 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1366 /* xgettext:c-format */
1367 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1368 "in section `%A' failed"),
1369 abfd
, from
->name
, to
->name
, name
,
1370 rel
->r_offset
, sec
);
1371 bfd_set_error (bfd_error_bad_value
);
1379 /* With the local symbol, foo, we convert
1380 mov foo@GOT[(%reg1)], %reg2
1382 lea foo[@GOTOFF(%reg1)], %reg2
1384 call/jmp *foo@GOT[(%reg)]
1386 nop call foo/jmp foo nop
1387 When PIC is false, convert
1388 test %reg1, foo@GOT[(%reg2)]
1392 binop foo@GOT[(%reg1)], %reg2
1395 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1400 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1402 Elf_Internal_Rela
*irel
,
1403 struct elf_link_hash_entry
*h
,
1404 bfd_boolean
*converted
,
1405 struct bfd_link_info
*link_info
)
1407 struct elf_x86_link_hash_table
*htab
;
1408 unsigned int opcode
;
1410 bfd_boolean baseless
;
1411 Elf_Internal_Sym
*isym
;
1412 unsigned int addend
;
1416 bfd_boolean to_reloc_32
;
1417 unsigned int r_type
;
1418 unsigned int r_symndx
;
1419 bfd_vma roff
= irel
->r_offset
;
1424 /* Addend for R_386_GOT32X relocations must be 0. */
1425 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1429 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
1430 is_pic
= bfd_link_pic (link_info
);
1432 r_type
= ELF32_R_TYPE (irel
->r_info
);
1433 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1435 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1436 baseless
= (modrm
& 0xc7) == 0x5;
1438 if (baseless
&& is_pic
)
1440 /* For PIC, disallow R_386_GOT32X without a base register
1441 since we don't know what the GOT base is. */
1446 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1448 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1451 name
= h
->root
.root
.string
;
1454 /* xgettext:c-format */
1455 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1456 " register can not be used when making a shared object"),
1461 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1463 /* Convert to R_386_32 if PIC is false or there is no base
1465 to_reloc_32
= !is_pic
|| baseless
;
1467 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1471 if (opcode
== 0x0ff)
1472 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1473 goto convert_branch
;
1475 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1476 "test %reg1, foo@GOT(%reg2)" and
1477 "binop foo@GOT[(%reg1)], %reg2". */
1481 /* Undefined weak symbol is only bound locally in executable
1482 and its reference is resolved as 0. */
1483 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
, I386_ELF_DATA
, TRUE
,
1484 elf_x86_hash_entry (h
)))
1488 /* No direct branch to 0 for PIC. */
1492 goto convert_branch
;
1496 /* We can convert load of address 0 to R_386_32. */
1504 /* We have "call/jmp *foo@GOT[(%reg)]". */
1505 if ((h
->root
.type
== bfd_link_hash_defined
1506 || h
->root
.type
== bfd_link_hash_defweak
)
1507 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1509 /* The function is locally defined. */
1511 /* Convert R_386_GOT32X to R_386_PC32. */
1512 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1514 struct elf_x86_link_hash_entry
*eh
1515 = (struct elf_x86_link_hash_entry
*) h
;
1517 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1520 /* To support TLS optimization, always use addr32 prefix
1521 for "call *___tls_get_addr@GOT(%reg)". */
1522 if (eh
&& eh
->tls_get_addr
)
1525 nop_offset
= irel
->r_offset
- 2;
1529 nop
= link_info
->call_nop_byte
;
1530 if (link_info
->call_nop_as_suffix
)
1532 nop_offset
= roff
+ 3;
1533 irel
->r_offset
-= 1;
1536 nop_offset
= roff
- 2;
1541 /* Convert to "jmp foo nop". */
1544 nop_offset
= roff
+ 3;
1545 irel
->r_offset
-= 1;
1548 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1549 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1550 /* When converting to PC-relative relocation, we
1551 need to adjust addend by -4. */
1552 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1553 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1560 /* We have "mov foo@GOT[(%re1g)], %reg2",
1561 "test %reg1, foo@GOT(%reg2)" and
1562 "binop foo@GOT[(%reg1)], %reg2".
1564 Avoid optimizing _DYNAMIC since ld.so may use its
1565 link-time address. */
1566 if (h
== htab
->elf
.hdynamic
)
1569 /* def_regular is set by an assignment in a linker script in
1570 bfd_elf_record_link_assignment. start_stop is set on
1571 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1574 || h
->root
.type
== bfd_link_hash_defined
1575 || h
->root
.type
== bfd_link_hash_defweak
)
1576 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)))
1583 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1584 "mov $foo, %reg2" with R_386_32. */
1586 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1587 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1592 /* Convert "mov foo@GOT(%reg1), %reg2" to
1593 "lea foo@GOTOFF(%reg1), %reg2". */
1594 r_type
= R_386_GOTOFF
;
1600 /* Only R_386_32 is supported. */
1606 /* Convert "test %reg1, foo@GOT(%reg2)" to
1607 "test $foo, %reg1". */
1608 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1613 /* Convert "binop foo@GOT(%reg1), %reg2" to
1614 "binop $foo, %reg2". */
1616 | (modrm
& 0x38) >> 3
1620 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1624 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1625 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1634 /* Rename some of the generic section flags to better document how they
1636 #define need_convert_load sec_flg0
1637 #define check_relocs_failed sec_flg1
1639 /* Look through the relocs for a section during the first phase, and
1640 calculate needed space in the global offset table, procedure linkage
1641 table, and dynamic reloc sections. */
1644 elf_i386_check_relocs (bfd
*abfd
,
1645 struct bfd_link_info
*info
,
1647 const Elf_Internal_Rela
*relocs
)
1649 struct elf_x86_link_hash_table
*htab
;
1650 Elf_Internal_Shdr
*symtab_hdr
;
1651 struct elf_link_hash_entry
**sym_hashes
;
1652 const Elf_Internal_Rela
*rel
;
1653 const Elf_Internal_Rela
*rel_end
;
1657 if (bfd_link_relocatable (info
))
1660 /* Don't do anything special with non-loaded, non-alloced sections.
1661 In particular, any relocs in such sections should not affect GOT
1662 and PLT reference counting (ie. we don't allow them to create GOT
1663 or PLT entries), there's no possibility or desire to optimize TLS
1664 relocs, and there's not much point in propagating relocs to shared
1665 libs that the dynamic linker won't relocate. */
1666 if ((sec
->flags
& SEC_ALLOC
) == 0)
1669 BFD_ASSERT (is_i386_elf (abfd
));
1671 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1674 sec
->check_relocs_failed
= 1;
1678 /* Get the section contents. */
1679 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1680 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1681 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1683 sec
->check_relocs_failed
= 1;
1687 symtab_hdr
= &elf_symtab_hdr (abfd
);
1688 sym_hashes
= elf_sym_hashes (abfd
);
1692 rel_end
= relocs
+ sec
->reloc_count
;
1693 for (rel
= relocs
; rel
< rel_end
; rel
++)
1695 unsigned int r_type
;
1696 unsigned int r_symndx
;
1697 struct elf_link_hash_entry
*h
;
1698 struct elf_x86_link_hash_entry
*eh
;
1699 Elf_Internal_Sym
*isym
;
1701 bfd_boolean size_reloc
;
1703 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1704 r_type
= ELF32_R_TYPE (rel
->r_info
);
1706 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1708 /* xgettext:c-format */
1709 _bfd_error_handler (_("%B: bad symbol index: %d"),
1714 if (r_symndx
< symtab_hdr
->sh_info
)
1716 /* A local symbol. */
1717 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1722 /* Check relocation against local STT_GNU_IFUNC symbol. */
1723 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1725 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1729 /* Fake a STT_GNU_IFUNC symbol. */
1730 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1732 h
->type
= STT_GNU_IFUNC
;
1735 h
->forced_local
= 1;
1736 h
->root
.type
= bfd_link_hash_defined
;
1744 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1745 while (h
->root
.type
== bfd_link_hash_indirect
1746 || h
->root
.type
== bfd_link_hash_warning
)
1747 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1750 eh
= (struct elf_x86_link_hash_entry
*) h
;
1753 if (r_type
== R_386_GOTOFF
)
1756 /* It is referenced by a non-shared object. */
1758 h
->root
.non_ir_ref_regular
= 1;
1760 if (h
->type
== STT_GNU_IFUNC
)
1761 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1762 |= elf_gnu_symbol_ifunc
;
1765 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1766 symtab_hdr
, sym_hashes
,
1767 &r_type
, GOT_UNKNOWN
,
1768 rel
, rel_end
, h
, r_symndx
, FALSE
))
1774 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1778 /* This symbol requires a procedure linkage table entry. We
1779 actually build the entry in adjust_dynamic_symbol,
1780 because this might be a case of linking PIC code which is
1781 never referenced by a dynamic object, in which case we
1782 don't need to generate a procedure linkage table entry
1785 /* If this is a local symbol, we resolve it directly without
1786 creating a procedure linkage table entry. */
1790 eh
->has_got_reloc
= 1;
1792 h
->plt
.refcount
+= 1;
1799 case R_386_TLS_IE_32
:
1801 case R_386_TLS_GOTIE
:
1802 if (!bfd_link_executable (info
))
1803 info
->flags
|= DF_STATIC_TLS
;
1809 case R_386_TLS_GOTDESC
:
1810 case R_386_TLS_DESC_CALL
:
1811 /* This symbol requires a global offset table entry. */
1813 int tls_type
, old_tls_type
;
1820 tls_type
= GOT_NORMAL
;
1822 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1823 case R_386_TLS_GOTDESC
:
1824 case R_386_TLS_DESC_CALL
:
1825 tls_type
= GOT_TLS_GDESC
; break;
1826 case R_386_TLS_IE_32
:
1827 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1828 tls_type
= GOT_TLS_IE_NEG
;
1830 /* If this is a GD->IE transition, we may use either of
1831 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1832 tls_type
= GOT_TLS_IE
;
1835 case R_386_TLS_GOTIE
:
1836 tls_type
= GOT_TLS_IE_POS
; break;
1841 h
->got
.refcount
+= 1;
1842 old_tls_type
= elf_x86_hash_entry (h
)->tls_type
;
1846 bfd_signed_vma
*local_got_refcounts
;
1848 /* This is a global offset table entry for a local symbol. */
1849 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1850 if (local_got_refcounts
== NULL
)
1854 size
= symtab_hdr
->sh_info
;
1855 size
*= (sizeof (bfd_signed_vma
)
1856 + sizeof (bfd_vma
) + sizeof(char));
1857 local_got_refcounts
= (bfd_signed_vma
*)
1858 bfd_zalloc (abfd
, size
);
1859 if (local_got_refcounts
== NULL
)
1861 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1862 elf_x86_local_tlsdesc_gotent (abfd
)
1863 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1864 elf_x86_local_got_tls_type (abfd
)
1865 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1867 local_got_refcounts
[r_symndx
] += 1;
1868 old_tls_type
= elf_x86_local_got_tls_type (abfd
) [r_symndx
];
1871 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1872 tls_type
|= old_tls_type
;
1873 /* If a TLS symbol is accessed using IE at least once,
1874 there is no point to use dynamic model for it. */
1875 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1876 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1877 || (tls_type
& GOT_TLS_IE
) == 0))
1879 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1880 tls_type
= old_tls_type
;
1881 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1882 && GOT_TLS_GD_ANY_P (tls_type
))
1883 tls_type
|= old_tls_type
;
1887 name
= h
->root
.root
.string
;
1889 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1892 /* xgettext:c-format */
1893 (_("%B: `%s' accessed both as normal and "
1894 "thread local symbol"),
1896 bfd_set_error (bfd_error_bad_value
);
1901 if (old_tls_type
!= tls_type
)
1904 elf_x86_hash_entry (h
)->tls_type
= tls_type
;
1906 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1914 if (r_type
!= R_386_TLS_IE
)
1917 eh
->has_got_reloc
= 1;
1922 case R_386_TLS_LE_32
:
1925 eh
->has_got_reloc
= 1;
1926 if (bfd_link_executable (info
))
1928 info
->flags
|= DF_STATIC_TLS
;
1933 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
1934 eh
->has_non_got_reloc
= 1;
1936 /* We are called after all symbols have been resolved. Only
1937 relocation against STT_GNU_IFUNC symbol must go through
1940 && (bfd_link_executable (info
)
1941 || h
->type
== STT_GNU_IFUNC
))
1943 /* If this reloc is in a read-only section, we might
1944 need a copy reloc. We can't check reliably at this
1945 stage whether the section is read-only, as input
1946 sections have not yet been mapped to output sections.
1947 Tentatively set the flag for now, and correct in
1948 adjust_dynamic_symbol. */
1951 /* We may need a .plt entry if the symbol is a function
1952 defined in a shared lib or is a STT_GNU_IFUNC function
1953 referenced from the code or read-only section. */
1955 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
1956 h
->plt
.refcount
+= 1;
1958 if (r_type
== R_386_PC32
)
1960 /* Since something like ".long foo - ." may be used
1961 as pointer, make sure that PLT is used if foo is
1962 a function defined in a shared library. */
1963 if ((sec
->flags
& SEC_CODE
) == 0)
1964 h
->pointer_equality_needed
= 1;
1965 else if (h
->type
== STT_GNU_IFUNC
1966 && bfd_link_pic (info
))
1969 /* xgettext:c-format */
1970 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
1971 abfd
, h
->root
.root
.string
);
1972 bfd_set_error (bfd_error_bad_value
);
1978 h
->pointer_equality_needed
= 1;
1979 /* R_386_32 can be resolved at run-time. */
1980 if (r_type
== R_386_32
1981 && (sec
->flags
& SEC_READONLY
) == 0)
1982 eh
->func_pointer_refcount
+= 1;
1988 /* If we are creating a shared library, and this is a reloc
1989 against a global symbol, or a non PC relative reloc
1990 against a local symbol, then we need to copy the reloc
1991 into the shared library. However, if we are linking with
1992 -Bsymbolic, we do not need to copy a reloc against a
1993 global symbol which is defined in an object we are
1994 including in the link (i.e., DEF_REGULAR is set). At
1995 this point we have not seen all the input files, so it is
1996 possible that DEF_REGULAR is not set now but will be set
1997 later (it is never cleared). In case of a weak definition,
1998 DEF_REGULAR may be cleared later by a strong definition in
1999 a shared library. We account for that possibility below by
2000 storing information in the relocs_copied field of the hash
2001 table entry. A similar situation occurs when creating
2002 shared libraries and symbol visibility changes render the
2005 If on the other hand, we are creating an executable, we
2006 may need to keep relocations for symbols satisfied by a
2007 dynamic library if we manage to avoid copy relocs for the
2010 Generate dynamic pointer relocation against STT_GNU_IFUNC
2011 symbol in the non-code section. */
2012 if ((bfd_link_pic (info
)
2013 && (r_type
!= R_386_PC32
2015 && (! (bfd_link_pie (info
)
2016 || SYMBOLIC_BIND (info
, h
))
2017 || h
->root
.type
== bfd_link_hash_defweak
2018 || !h
->def_regular
))))
2020 && h
->type
== STT_GNU_IFUNC
2021 && r_type
== R_386_32
2022 && (sec
->flags
& SEC_CODE
) == 0)
2023 || (ELIMINATE_COPY_RELOCS
2024 && !bfd_link_pic (info
)
2026 && (h
->root
.type
== bfd_link_hash_defweak
2027 || !h
->def_regular
)))
2029 struct elf_dyn_relocs
*p
;
2030 struct elf_dyn_relocs
**head
;
2032 /* We must copy these reloc types into the output file.
2033 Create a reloc section in dynobj and make room for
2037 sreloc
= _bfd_elf_make_dynamic_reloc_section
2038 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
2044 /* If this is a global symbol, we count the number of
2045 relocations we need for this symbol. */
2048 head
= &eh
->dyn_relocs
;
2052 /* Track dynamic relocs needed for local syms too.
2053 We really need local syms available to do this
2058 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2063 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2067 vpp
= &elf_section_data (s
)->local_dynrel
;
2068 head
= (struct elf_dyn_relocs
**)vpp
;
2072 if (p
== NULL
|| p
->sec
!= sec
)
2074 bfd_size_type amt
= sizeof *p
;
2075 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
2087 /* Count size relocation as PC-relative relocation. */
2088 if (r_type
== R_386_PC32
|| size_reloc
)
2093 /* This relocation describes the C++ object vtable hierarchy.
2094 Reconstruct it for later use during GC. */
2095 case R_386_GNU_VTINHERIT
:
2096 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2100 /* This relocation describes which C++ vtable entries are actually
2101 used. Record for later use during GC. */
2102 case R_386_GNU_VTENTRY
:
2103 BFD_ASSERT (h
!= NULL
);
2105 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
2113 if (r_type
== R_386_GOT32X
2114 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2115 sec
->need_convert_load
= 1;
2118 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2120 if (!info
->keep_memory
)
2124 /* Cache the section contents for elf_link_input_bfd. */
2125 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2132 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2134 sec
->check_relocs_failed
= 1;
2138 /* Return the section that should be marked against GC for a given
2142 elf_i386_gc_mark_hook (asection
*sec
,
2143 struct bfd_link_info
*info
,
2144 Elf_Internal_Rela
*rel
,
2145 struct elf_link_hash_entry
*h
,
2146 Elf_Internal_Sym
*sym
)
2149 switch (ELF32_R_TYPE (rel
->r_info
))
2151 case R_386_GNU_VTINHERIT
:
2152 case R_386_GNU_VTENTRY
:
2156 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2159 /* Adjust a symbol defined by a dynamic object and referenced by a
2160 regular object. The current definition is in some section of the
2161 dynamic object, but we're not including those sections. We have to
2162 change the definition to something the rest of the link can
2166 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2167 struct elf_link_hash_entry
*h
)
2169 struct elf_x86_link_hash_table
*htab
;
2171 struct elf_x86_link_hash_entry
*eh
;
2172 struct elf_dyn_relocs
*p
;
2174 /* STT_GNU_IFUNC symbol must go through PLT. */
2175 if (h
->type
== STT_GNU_IFUNC
)
2177 /* All local STT_GNU_IFUNC references must be treate as local
2178 calls via local PLT. */
2180 && SYMBOL_CALLS_LOCAL (info
, h
))
2182 bfd_size_type pc_count
= 0, count
= 0;
2183 struct elf_dyn_relocs
**pp
;
2185 eh
= (struct elf_x86_link_hash_entry
*) h
;
2186 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2188 pc_count
+= p
->pc_count
;
2189 p
->count
-= p
->pc_count
;
2198 if (pc_count
|| count
)
2203 /* Increment PLT reference count only for PC-relative
2206 if (h
->plt
.refcount
<= 0)
2207 h
->plt
.refcount
= 1;
2209 h
->plt
.refcount
+= 1;
2214 if (h
->plt
.refcount
<= 0)
2216 h
->plt
.offset
= (bfd_vma
) -1;
2222 /* If this is a function, put it in the procedure linkage table. We
2223 will fill in the contents of the procedure linkage table later,
2224 when we know the address of the .got section. */
2225 if (h
->type
== STT_FUNC
2228 if (h
->plt
.refcount
<= 0
2229 || SYMBOL_CALLS_LOCAL (info
, h
)
2230 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2231 && h
->root
.type
== bfd_link_hash_undefweak
))
2233 /* This case can occur if we saw a PLT32 reloc in an input
2234 file, but the symbol was never referred to by a dynamic
2235 object, or if all references were garbage collected. In
2236 such a case, we don't actually need to build a procedure
2237 linkage table, and we can just do a PC32 reloc instead. */
2238 h
->plt
.offset
= (bfd_vma
) -1;
2245 /* It's possible that we incorrectly decided a .plt reloc was
2246 needed for an R_386_PC32 reloc to a non-function sym in
2247 check_relocs. We can't decide accurately between function and
2248 non-function syms in check-relocs; Objects loaded later in
2249 the link may change h->type. So fix it now. */
2250 h
->plt
.offset
= (bfd_vma
) -1;
2252 eh
= (struct elf_x86_link_hash_entry
*) h
;
2254 /* If this is a weak symbol, and there is a real definition, the
2255 processor independent code will have arranged for us to see the
2256 real definition first, and we can just use the same value. */
2257 if (h
->u
.weakdef
!= NULL
)
2259 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2260 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2261 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2262 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2263 if (ELIMINATE_COPY_RELOCS
2264 || info
->nocopyreloc
2265 || SYMBOL_NO_COPYRELOC (info
, eh
))
2266 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2270 /* This is a reference to a symbol defined by a dynamic object which
2271 is not a function. */
2273 /* If we are creating a shared library, we must presume that the
2274 only references to the symbol are via the global offset table.
2275 For such cases we need not do anything here; the relocations will
2276 be handled correctly by relocate_section. */
2277 if (!bfd_link_executable (info
))
2280 /* If there are no references to this symbol that do not use the
2281 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2283 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2286 /* If -z nocopyreloc was given, we won't generate them either. */
2287 if (info
->nocopyreloc
|| SYMBOL_NO_COPYRELOC (info
, eh
))
2293 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2297 /* If there aren't any dynamic relocs in read-only sections nor
2298 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2299 avoid the copy reloc. This doesn't work on VxWorks, where we can
2300 not have dynamic relocations (other than copy and jump slot
2301 relocations) in an executable. */
2302 if (ELIMINATE_COPY_RELOCS
2304 && get_elf_i386_backend_data (info
->output_bfd
)->os
!= is_vxworks
)
2306 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2308 s
= p
->sec
->output_section
;
2309 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2320 /* We must allocate the symbol in our .dynbss section, which will
2321 become part of the .bss section of the executable. There will be
2322 an entry for this symbol in the .dynsym section. The dynamic
2323 object will contain position independent code, so all references
2324 from the dynamic object to this symbol will go through the global
2325 offset table. The dynamic linker will use the .dynsym entry to
2326 determine the address it must put in the global offset table, so
2327 both the dynamic object and the regular object will refer to the
2328 same memory location for the variable. */
2330 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2331 copy the initial value out of the dynamic object and into the
2332 runtime process image. */
2333 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2335 s
= htab
->elf
.sdynrelro
;
2336 srel
= htab
->elf
.sreldynrelro
;
2340 s
= htab
->elf
.sdynbss
;
2341 srel
= htab
->elf
.srelbss
;
2343 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2345 srel
->size
+= sizeof (Elf32_External_Rel
);
2349 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2352 /* Allocate space in .plt, .got and associated reloc sections for
2356 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2358 struct bfd_link_info
*info
;
2359 struct elf_x86_link_hash_table
*htab
;
2360 struct elf_x86_link_hash_entry
*eh
;
2361 struct elf_dyn_relocs
*p
;
2362 unsigned plt_entry_size
;
2363 bfd_boolean resolved_to_zero
;
2364 const struct elf_i386_backend_data
*bed
;
2365 const struct elf_i386_plt_layout
*plt_layout
;
2366 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt_layout
;
2368 if (h
->root
.type
== bfd_link_hash_indirect
)
2371 eh
= (struct elf_x86_link_hash_entry
*) h
;
2373 info
= (struct bfd_link_info
*) inf
;
2374 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2378 bed
= get_elf_i386_backend_data (info
->output_bfd
);
2380 plt_layout
= &elf_i386_plt (htab
);
2381 non_lazy_plt_layout
= elf_i386_non_lazy_plt (htab
);
2382 plt_entry_size
= plt_layout
->plt_entry_size
;
2384 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2389 /* Clear the reference count of function pointer relocations if
2390 symbol isn't a normal function. */
2391 if (h
->type
!= STT_FUNC
)
2392 eh
->func_pointer_refcount
= 0;
2394 /* We can't use the GOT PLT if pointer equality is needed since
2395 finish_dynamic_symbol won't clear symbol value and the dynamic
2396 linker won't update the GOT slot. We will get into an infinite
2397 loop at run-time. */
2398 if (htab
->plt_got
!= NULL
2399 && h
->type
!= STT_GNU_IFUNC
2400 && !h
->pointer_equality_needed
2401 && h
->plt
.refcount
> 0
2402 && h
->got
.refcount
> 0)
2404 /* Don't use the regular PLT if there are both GOT and GOTPLT
2406 h
->plt
.offset
= (bfd_vma
) -1;
2408 /* Use the GOT PLT. */
2409 eh
->plt_got
.refcount
= 1;
2412 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2413 here if it is defined and referenced in a non-shared object. */
2414 if (h
->type
== STT_GNU_IFUNC
2417 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2418 &htab
->readonly_dynrelocs_against_ifunc
,
2420 (plt_layout
->has_plt0
2424 asection
*s
= htab
->plt_second
;
2425 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
2427 /* Use the second PLT section if it is created. */
2428 eh
->plt_second
.offset
= s
->size
;
2430 /* Make room for this entry in the second PLT section. */
2431 s
->size
+= non_lazy_plt_layout
->plt_entry_size
;
2439 /* Don't create the PLT entry if there are only function pointer
2440 relocations which can be resolved at run-time. */
2441 else if (htab
->elf
.dynamic_sections_created
2442 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2443 || eh
->plt_got
.refcount
> 0))
2445 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
2447 /* Clear the reference count of function pointer relocations
2449 eh
->func_pointer_refcount
= 0;
2451 /* Make sure this symbol is output as a dynamic symbol.
2452 Undefined weak syms won't yet be marked as dynamic. */
2453 if (h
->dynindx
== -1
2455 && !resolved_to_zero
2456 && h
->root
.type
== bfd_link_hash_undefweak
)
2458 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2462 if (bfd_link_pic (info
)
2463 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2465 asection
*s
= htab
->elf
.splt
;
2466 asection
*second_s
= htab
->plt_second
;
2467 asection
*got_s
= htab
->plt_got
;
2469 /* If this is the first .plt entry, make room for the special
2470 first entry. The .plt section is used by prelink to undo
2471 prelinking for dynamic relocations. */
2473 s
->size
= plt_layout
->has_plt0
* plt_entry_size
;
2476 eh
->plt_got
.offset
= got_s
->size
;
2479 h
->plt
.offset
= s
->size
;
2481 eh
->plt_second
.offset
= second_s
->size
;
2484 /* If this symbol is not defined in a regular file, and we are
2485 not generating a shared library, then set the symbol to this
2486 location in the .plt. This is required to make function
2487 pointers compare as equal between the normal executable and
2488 the shared library. */
2489 if (! bfd_link_pic (info
)
2494 /* We need to make a call to the entry of the GOT PLT
2495 instead of regular PLT entry. */
2496 h
->root
.u
.def
.section
= got_s
;
2497 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2503 /* We need to make a call to the entry of the
2504 second PLT instead of regular PLT entry. */
2505 h
->root
.u
.def
.section
= second_s
;
2506 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
2510 h
->root
.u
.def
.section
= s
;
2511 h
->root
.u
.def
.value
= h
->plt
.offset
;
2516 /* Make room for this entry. */
2518 got_s
->size
+= non_lazy_plt_layout
->plt_entry_size
;
2521 s
->size
+= plt_entry_size
;
2523 second_s
->size
+= non_lazy_plt_layout
->plt_entry_size
;
2525 /* We also need to make an entry in the .got.plt section,
2526 which will be placed in the .got section by the linker
2528 htab
->elf
.sgotplt
->size
+= 4;
2530 /* There should be no PLT relocation against resolved
2531 undefined weak symbol in executable. */
2532 if (!resolved_to_zero
)
2534 /* We also need to make an entry in the .rel.plt
2536 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2537 htab
->elf
.srelplt
->reloc_count
++;
2541 if (bed
->os
== is_vxworks
&& !bfd_link_pic (info
))
2543 /* VxWorks has a second set of relocations for each PLT entry
2544 in executables. They go in a separate relocation section,
2545 which is processed by the kernel loader. */
2547 /* There are two relocations for the initial PLT entry: an
2548 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2549 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2551 asection
*srelplt2
= elf_i386_srelplt2 (htab
);
2552 if (h
->plt
.offset
== plt_entry_size
)
2553 srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2555 /* There are two extra relocations for each subsequent PLT entry:
2556 an R_386_32 relocation for the GOT entry, and an R_386_32
2557 relocation for the PLT entry. */
2559 srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2564 eh
->plt_got
.offset
= (bfd_vma
) -1;
2565 h
->plt
.offset
= (bfd_vma
) -1;
2571 eh
->plt_got
.offset
= (bfd_vma
) -1;
2572 h
->plt
.offset
= (bfd_vma
) -1;
2576 eh
->tlsdesc_got
= (bfd_vma
) -1;
2578 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2579 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2580 if (h
->got
.refcount
> 0
2581 && bfd_link_executable (info
)
2583 && (elf_x86_hash_entry (h
)->tls_type
& GOT_TLS_IE
))
2584 h
->got
.offset
= (bfd_vma
) -1;
2585 else if (h
->got
.refcount
> 0)
2589 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
2591 /* Make sure this symbol is output as a dynamic symbol.
2592 Undefined weak syms won't yet be marked as dynamic. */
2593 if (h
->dynindx
== -1
2595 && !resolved_to_zero
2596 && h
->root
.type
== bfd_link_hash_undefweak
)
2598 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2603 if (GOT_TLS_GDESC_P (tls_type
))
2605 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2606 - elf_i386_compute_jump_table_size (htab
);
2607 htab
->elf
.sgotplt
->size
+= 8;
2608 h
->got
.offset
= (bfd_vma
) -2;
2610 if (! GOT_TLS_GDESC_P (tls_type
)
2611 || GOT_TLS_GD_P (tls_type
))
2613 h
->got
.offset
= s
->size
;
2615 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2616 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2619 dyn
= htab
->elf
.dynamic_sections_created
;
2620 /* R_386_TLS_IE_32 needs one dynamic relocation,
2621 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2622 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2623 need two), R_386_TLS_GD needs one if local symbol and two if
2624 global. No dynamic relocation against resolved undefined weak
2625 symbol in executable. */
2626 if (tls_type
== GOT_TLS_IE_BOTH
)
2627 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2628 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2629 || (tls_type
& GOT_TLS_IE
))
2630 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2631 else if (GOT_TLS_GD_P (tls_type
))
2632 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2633 else if (! GOT_TLS_GDESC_P (tls_type
)
2634 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2635 && !resolved_to_zero
)
2636 || h
->root
.type
!= bfd_link_hash_undefweak
)
2637 && (bfd_link_pic (info
)
2638 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2639 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2640 if (GOT_TLS_GDESC_P (tls_type
))
2641 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2644 h
->got
.offset
= (bfd_vma
) -1;
2646 if (eh
->dyn_relocs
== NULL
)
2649 /* In the shared -Bsymbolic case, discard space allocated for
2650 dynamic pc-relative relocs against symbols which turn out to be
2651 defined in regular objects. For the normal shared case, discard
2652 space for pc-relative relocs that have become local due to symbol
2653 visibility changes. */
2655 if (bfd_link_pic (info
))
2657 /* The only reloc that uses pc_count is R_386_PC32, which will
2658 appear on a call or on something like ".long foo - .". We
2659 want calls to protected symbols to resolve directly to the
2660 function rather than going via the plt. If people want
2661 function pointer comparisons to work as expected then they
2662 should avoid writing assembly like ".long foo - .". */
2663 if (SYMBOL_CALLS_LOCAL (info
, h
))
2665 struct elf_dyn_relocs
**pp
;
2667 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2669 p
->count
-= p
->pc_count
;
2678 if (bed
->os
== is_vxworks
)
2680 struct elf_dyn_relocs
**pp
;
2681 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2683 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2690 /* Also discard relocs on undefined weak syms with non-default
2691 visibility or in PIE. */
2692 if (eh
->dyn_relocs
!= NULL
2693 && h
->root
.type
== bfd_link_hash_undefweak
)
2695 /* Undefined weak symbol is never bound locally in shared
2697 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2698 || resolved_to_zero
)
2702 /* Keep dynamic non-GOT/non-PLT relocation so that we
2703 can branch to 0 without PLT. */
2704 struct elf_dyn_relocs
**pp
;
2706 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2707 if (p
->pc_count
== 0)
2711 /* Remove non-R_386_PC32 relocation. */
2712 p
->count
= p
->pc_count
;
2716 if (eh
->dyn_relocs
!= NULL
)
2718 /* Make sure undefined weak symbols are output
2719 as dynamic symbols in PIEs for dynamic non-GOT
2720 non-PLT reloations. */
2721 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2726 eh
->dyn_relocs
= NULL
;
2728 else if (h
->dynindx
== -1
2729 && !h
->forced_local
)
2731 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2736 else if (ELIMINATE_COPY_RELOCS
)
2738 /* For the non-shared case, discard space for relocs against
2739 symbols which turn out to need copy relocs or are not
2740 dynamic. Keep dynamic relocations for run-time function
2741 pointer initialization. */
2743 if ((!h
->non_got_ref
2744 || eh
->func_pointer_refcount
> 0
2745 || (h
->root
.type
== bfd_link_hash_undefweak
2746 && !resolved_to_zero
))
2749 || (htab
->elf
.dynamic_sections_created
2750 && (h
->root
.type
== bfd_link_hash_undefweak
2751 || h
->root
.type
== bfd_link_hash_undefined
))))
2753 /* Make sure this symbol is output as a dynamic symbol.
2754 Undefined weak syms won't yet be marked as dynamic. */
2755 if (h
->dynindx
== -1
2757 && !resolved_to_zero
2758 && h
->root
.type
== bfd_link_hash_undefweak
)
2760 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2764 /* If that succeeded, we know we'll be keeping all the
2766 if (h
->dynindx
!= -1)
2770 eh
->dyn_relocs
= NULL
;
2771 eh
->func_pointer_refcount
= 0;
2776 /* Finally, allocate space. */
2777 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2781 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2783 BFD_ASSERT (sreloc
!= NULL
);
2784 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2790 /* Allocate space in .plt, .got and associated reloc sections for
2791 local dynamic relocs. */
2794 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2796 struct elf_link_hash_entry
*h
2797 = (struct elf_link_hash_entry
*) *slot
;
2799 if (h
->type
!= STT_GNU_IFUNC
2803 || h
->root
.type
!= bfd_link_hash_defined
)
2806 return elf_i386_allocate_dynrelocs (h
, inf
);
2809 /* Convert load via the GOT slot to load immediate. */
2812 elf_i386_convert_load (bfd
*abfd
, asection
*sec
,
2813 struct bfd_link_info
*link_info
)
2815 struct elf_x86_link_hash_table
*htab
;
2816 Elf_Internal_Shdr
*symtab_hdr
;
2817 Elf_Internal_Rela
*internal_relocs
;
2818 Elf_Internal_Rela
*irel
, *irelend
;
2820 bfd_boolean changed
;
2821 bfd_signed_vma
*local_got_refcounts
;
2823 /* Don't even try to convert non-ELF outputs. */
2824 if (!is_elf_hash_table (link_info
->hash
))
2827 /* Nothing to do if there is no need or no output. */
2828 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
2829 || sec
->need_convert_load
== 0
2830 || bfd_is_abs_section (sec
->output_section
))
2833 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2835 /* Load the relocations for this section. */
2836 internal_relocs
= (_bfd_elf_link_read_relocs
2837 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2838 link_info
->keep_memory
));
2839 if (internal_relocs
== NULL
)
2843 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
2844 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2846 /* Get the section contents. */
2847 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2848 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2851 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2855 irelend
= internal_relocs
+ sec
->reloc_count
;
2856 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2858 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
2859 unsigned int r_symndx
;
2860 struct elf_link_hash_entry
*h
;
2861 bfd_boolean converted
;
2863 /* Don't convert R_386_GOT32 since we can't tell if it is applied
2864 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
2865 if (r_type
!= R_386_GOT32X
)
2868 r_symndx
= ELF32_R_SYM (irel
->r_info
);
2869 if (r_symndx
< symtab_hdr
->sh_info
)
2870 h
= _bfd_elf_x86_get_local_sym_hash (htab
, sec
->owner
,
2871 (const Elf_Internal_Rela
*) irel
,
2875 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
2876 while (h
->root
.type
== bfd_link_hash_indirect
2877 || h
->root
.type
== bfd_link_hash_warning
)
2878 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2881 /* STT_GNU_IFUNC must keep GOT32 relocations. */
2882 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2886 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
2887 irel
, h
, &converted
, link_info
))
2892 changed
= converted
;
2895 if (h
->got
.refcount
> 0)
2896 h
->got
.refcount
-= 1;
2900 if (local_got_refcounts
!= NULL
2901 && local_got_refcounts
[r_symndx
] > 0)
2902 local_got_refcounts
[r_symndx
] -= 1;
2907 if (contents
!= NULL
2908 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2910 if (!changed
&& !link_info
->keep_memory
)
2914 /* Cache the section contents for elf_link_input_bfd. */
2915 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2919 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2922 free (internal_relocs
);
2924 elf_section_data (sec
)->relocs
= internal_relocs
;
2930 if (contents
!= NULL
2931 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2933 if (internal_relocs
!= NULL
2934 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2935 free (internal_relocs
);
2939 /* Set the sizes of the dynamic sections. */
2942 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2944 struct elf_x86_link_hash_table
*htab
;
2950 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2953 dynobj
= htab
->elf
.dynobj
;
2957 /* Set up .got offsets for local syms, and space for local dynamic
2959 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2961 bfd_signed_vma
*local_got
;
2962 bfd_signed_vma
*end_local_got
;
2963 char *local_tls_type
;
2964 bfd_vma
*local_tlsdesc_gotent
;
2965 bfd_size_type locsymcount
;
2966 Elf_Internal_Shdr
*symtab_hdr
;
2969 if (! is_i386_elf (ibfd
))
2972 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2974 struct elf_dyn_relocs
*p
;
2976 if (!elf_i386_convert_load (ibfd
, s
, info
))
2979 for (p
= ((struct elf_dyn_relocs
*)
2980 elf_section_data (s
)->local_dynrel
);
2984 if (!bfd_is_abs_section (p
->sec
)
2985 && bfd_is_abs_section (p
->sec
->output_section
))
2987 /* Input section has been discarded, either because
2988 it is a copy of a linkonce section or due to
2989 linker script /DISCARD/, so we'll be discarding
2992 else if ((get_elf_i386_backend_data (output_bfd
)->os
2994 && strcmp (p
->sec
->output_section
->name
,
2997 /* Relocations in vxworks .tls_vars sections are
2998 handled specially by the loader. */
3000 else if (p
->count
!= 0)
3002 srel
= elf_section_data (p
->sec
)->sreloc
;
3003 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3004 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3005 && (info
->flags
& DF_TEXTREL
) == 0)
3007 info
->flags
|= DF_TEXTREL
;
3008 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3009 || info
->error_textrel
)
3010 /* xgettext:c-format */
3011 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3012 p
->sec
->owner
, p
->sec
);
3018 local_got
= elf_local_got_refcounts (ibfd
);
3022 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3023 locsymcount
= symtab_hdr
->sh_info
;
3024 end_local_got
= local_got
+ locsymcount
;
3025 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
3026 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
3028 srel
= htab
->elf
.srelgot
;
3029 for (; local_got
< end_local_got
;
3030 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3032 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3035 if (GOT_TLS_GDESC_P (*local_tls_type
))
3037 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3038 - elf_i386_compute_jump_table_size (htab
);
3039 htab
->elf
.sgotplt
->size
+= 8;
3040 *local_got
= (bfd_vma
) -2;
3042 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3043 || GOT_TLS_GD_P (*local_tls_type
))
3045 *local_got
= s
->size
;
3047 if (GOT_TLS_GD_P (*local_tls_type
)
3048 || *local_tls_type
== GOT_TLS_IE_BOTH
)
3051 if (bfd_link_pic (info
)
3052 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3053 || (*local_tls_type
& GOT_TLS_IE
))
3055 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
3056 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
3057 else if (GOT_TLS_GD_P (*local_tls_type
)
3058 || ! GOT_TLS_GDESC_P (*local_tls_type
))
3059 srel
->size
+= sizeof (Elf32_External_Rel
);
3060 if (GOT_TLS_GDESC_P (*local_tls_type
))
3061 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
3065 *local_got
= (bfd_vma
) -1;
3069 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
3071 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
3073 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
3074 htab
->elf
.sgot
->size
+= 8;
3075 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
3078 htab
->tls_ld_or_ldm_got
.offset
= -1;
3080 /* Allocate global sym .plt and .got entries, and space for global
3081 sym dynamic relocs. */
3082 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
3084 /* Allocate .plt and .got entries, and space for local symbols. */
3085 htab_traverse (htab
->loc_hash_table
,
3086 elf_i386_allocate_local_dynrelocs
,
3089 /* For every jump slot reserved in the sgotplt, reloc_count is
3090 incremented. However, when we reserve space for TLS descriptors,
3091 it's not incremented, so in order to compute the space reserved
3092 for them, it suffices to multiply the reloc count by the jump
3095 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3096 so that R_386_IRELATIVE entries come last. */
3097 if (htab
->elf
.srelplt
)
3099 elf_i386_next_tls_desc_index(htab
)
3100 = htab
->elf
.srelplt
->reloc_count
;
3101 htab
->sgotplt_jump_table_size
3102 = elf_i386_next_tls_desc_index(htab
) * 4;
3103 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3105 else if (htab
->elf
.irelplt
)
3106 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3109 if (htab
->elf
.sgotplt
)
3111 /* Don't allocate .got.plt section if there are no GOT nor PLT
3112 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
3113 if ((htab
->elf
.hgot
== NULL
3114 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3115 && (htab
->elf
.sgotplt
->size
3116 == get_elf_backend_data (output_bfd
)->got_header_size
)
3117 && (htab
->elf
.splt
== NULL
3118 || htab
->elf
.splt
->size
== 0)
3119 && (htab
->elf
.sgot
== NULL
3120 || htab
->elf
.sgot
->size
== 0)
3121 && (htab
->elf
.iplt
== NULL
3122 || htab
->elf
.iplt
->size
== 0)
3123 && (htab
->elf
.igotplt
== NULL
3124 || htab
->elf
.igotplt
->size
== 0))
3125 htab
->elf
.sgotplt
->size
= 0;
3128 if (_bfd_elf_eh_frame_present (info
))
3130 if (htab
->plt_eh_frame
!= NULL
3131 && htab
->elf
.splt
!= NULL
3132 && htab
->elf
.splt
->size
!= 0
3133 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3134 htab
->plt_eh_frame
->size
= elf_i386_plt (htab
).eh_frame_plt_size
;
3136 if (htab
->plt_got_eh_frame
!= NULL
3137 && htab
->plt_got
!= NULL
3138 && htab
->plt_got
->size
!= 0
3139 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3140 htab
->plt_got_eh_frame
->size
3141 = elf_i386_non_lazy_plt (htab
)->eh_frame_plt_size
;
3143 /* Unwind info for the second PLT and .plt.got sections are
3145 if (htab
->plt_second_eh_frame
!= NULL
3146 && htab
->plt_second
!= NULL
3147 && htab
->plt_second
->size
!= 0
3148 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
3149 htab
->plt_second_eh_frame
->size
3150 = elf_i386_non_lazy_plt (htab
)->eh_frame_plt_size
;
3153 /* We now have determined the sizes of the various dynamic sections.
3154 Allocate memory for them. */
3156 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3158 bfd_boolean strip_section
= TRUE
;
3160 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3163 if (s
== htab
->elf
.splt
3164 || s
== htab
->elf
.sgot
)
3166 /* Strip this section if we don't need it; see the
3168 /* We'd like to strip these sections if they aren't needed, but if
3169 we've exported dynamic symbols from them we must leave them.
3170 It's too late to tell BFD to get rid of the symbols. */
3172 if (htab
->elf
.hplt
!= NULL
)
3173 strip_section
= FALSE
;
3175 else if (s
== htab
->elf
.sgotplt
3176 || s
== htab
->elf
.iplt
3177 || s
== htab
->elf
.igotplt
3178 || s
== htab
->plt_second
3179 || s
== htab
->plt_got
3180 || s
== htab
->plt_eh_frame
3181 || s
== htab
->plt_got_eh_frame
3182 || s
== htab
->plt_second_eh_frame
3183 || s
== htab
->elf
.sdynbss
3184 || s
== htab
->elf
.sdynrelro
)
3186 /* Strip these too. */
3188 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3191 && s
!= htab
->elf
.srelplt
3192 && s
!= elf_i386_srelplt2 (htab
))
3195 /* We use the reloc_count field as a counter if we need
3196 to copy relocs into the output file. */
3201 /* It's not one of our sections, so don't allocate space. */
3207 /* If we don't need this section, strip it from the
3208 output file. This is mostly to handle .rel.bss and
3209 .rel.plt. We must create both sections in
3210 create_dynamic_sections, because they must be created
3211 before the linker maps input sections to output
3212 sections. The linker does that before
3213 adjust_dynamic_symbol is called, and it is that
3214 function which decides whether anything needs to go
3215 into these sections. */
3217 s
->flags
|= SEC_EXCLUDE
;
3221 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3224 /* Allocate memory for the section contents. We use bfd_zalloc
3225 here in case unused entries are not reclaimed before the
3226 section's contents are written out. This should not happen,
3227 but this way if it does, we get a R_386_NONE reloc instead
3229 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3230 if (s
->contents
== NULL
)
3234 if (htab
->plt_eh_frame
!= NULL
3235 && htab
->plt_eh_frame
->contents
!= NULL
)
3237 memcpy (htab
->plt_eh_frame
->contents
,
3238 elf_i386_plt (htab
).eh_frame_plt
,
3239 htab
->plt_eh_frame
->size
);
3240 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3241 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3244 if (htab
->plt_got_eh_frame
!= NULL
3245 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3247 memcpy (htab
->plt_got_eh_frame
->contents
,
3248 elf_i386_non_lazy_plt (htab
)->eh_frame_plt
,
3249 htab
->plt_got_eh_frame
->size
);
3250 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3251 (htab
->plt_got_eh_frame
->contents
3252 + PLT_FDE_LEN_OFFSET
));
3255 if (htab
->plt_second_eh_frame
!= NULL
3256 && htab
->plt_second_eh_frame
->contents
!= NULL
)
3258 memcpy (htab
->plt_second_eh_frame
->contents
,
3259 elf_i386_non_lazy_plt (htab
)->eh_frame_plt
,
3260 htab
->plt_second_eh_frame
->size
);
3261 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
3262 (htab
->plt_second_eh_frame
->contents
3263 + PLT_FDE_LEN_OFFSET
));
3266 if (htab
->elf
.dynamic_sections_created
)
3268 /* Add some entries to the .dynamic section. We fill in the
3269 values later, in elf_i386_finish_dynamic_sections, but we
3270 must add the entries now so that we get the correct size for
3271 the .dynamic section. The DT_DEBUG entry is filled in by the
3272 dynamic linker and used by the debugger. */
3273 #define add_dynamic_entry(TAG, VAL) \
3274 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3276 if (bfd_link_executable (info
))
3278 if (!add_dynamic_entry (DT_DEBUG
, 0))
3282 if (htab
->elf
.splt
->size
!= 0)
3284 /* DT_PLTGOT is used by prelink even if there is no PLT
3286 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3290 if (htab
->elf
.srelplt
->size
!= 0)
3292 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3293 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3294 || !add_dynamic_entry (DT_JMPREL
, 0))
3300 if (!add_dynamic_entry (DT_REL
, 0)
3301 || !add_dynamic_entry (DT_RELSZ
, 0)
3302 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3305 /* If any dynamic relocs apply to a read-only section,
3306 then we need a DT_TEXTREL entry. */
3307 if ((info
->flags
& DF_TEXTREL
) == 0)
3308 elf_link_hash_traverse (&htab
->elf
,
3309 _bfd_x86_elf_readonly_dynrelocs
,
3312 if ((info
->flags
& DF_TEXTREL
) != 0)
3314 if (htab
->readonly_dynrelocs_against_ifunc
)
3316 info
->callbacks
->einfo
3317 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3318 bfd_set_error (bfd_error_bad_value
);
3322 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3326 if (get_elf_i386_backend_data (output_bfd
)->os
== is_vxworks
3327 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3330 #undef add_dynamic_entry
3335 /* Set the correct type for an x86 ELF section. We do this by the
3336 section name, which is a hack, but ought to work. */
3339 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3340 Elf_Internal_Shdr
*hdr
,
3345 name
= bfd_get_section_name (abfd
, sec
);
3347 /* This is an ugly, but unfortunately necessary hack that is
3348 needed when producing EFI binaries on x86. It tells
3349 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3350 containing ELF relocation info. We need this hack in order to
3351 be able to generate ELF binaries that can be translated into
3352 EFI applications (which are essentially COFF objects). Those
3353 files contain a COFF ".reloc" section inside an ELFNN object,
3354 which would normally cause BFD to segfault because it would
3355 attempt to interpret this section as containing relocation
3356 entries for section "oc". With this hack enabled, ".reloc"
3357 will be treated as a normal data section, which will avoid the
3358 segfault. However, you won't be able to create an ELFNN binary
3359 with a section named "oc" that needs relocations, but that's
3360 the kind of ugly side-effects you get when detecting section
3361 types based on their names... In practice, this limitation is
3362 unlikely to bite. */
3363 if (strcmp (name
, ".reloc") == 0)
3364 hdr
->sh_type
= SHT_PROGBITS
;
3369 /* Return the relocation value for @tpoff relocation
3370 if STT_TLS virtual address is ADDRESS. */
3373 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3375 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3376 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3377 bfd_vma static_tls_size
;
3379 /* If tls_sec is NULL, we should have signalled an error already. */
3380 if (htab
->tls_sec
== NULL
)
3383 /* Consider special static TLS alignment requirements. */
3384 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3385 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3388 /* Relocate an i386 ELF section. */
3391 elf_i386_relocate_section (bfd
*output_bfd
,
3392 struct bfd_link_info
*info
,
3394 asection
*input_section
,
3396 Elf_Internal_Rela
*relocs
,
3397 Elf_Internal_Sym
*local_syms
,
3398 asection
**local_sections
)
3400 struct elf_x86_link_hash_table
*htab
;
3401 Elf_Internal_Shdr
*symtab_hdr
;
3402 struct elf_link_hash_entry
**sym_hashes
;
3403 bfd_vma
*local_got_offsets
;
3404 bfd_vma
*local_tlsdesc_gotents
;
3405 Elf_Internal_Rela
*rel
;
3406 Elf_Internal_Rela
*wrel
;
3407 Elf_Internal_Rela
*relend
;
3408 bfd_boolean is_vxworks_tls
;
3409 unsigned plt_entry_size
;
3411 BFD_ASSERT (is_i386_elf (input_bfd
));
3413 /* Skip if check_relocs failed. */
3414 if (input_section
->check_relocs_failed
)
3417 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
3420 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3421 sym_hashes
= elf_sym_hashes (input_bfd
);
3422 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3423 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
3424 /* We have to handle relocations in vxworks .tls_vars sections
3425 specially, because the dynamic loader is 'weird'. */
3426 is_vxworks_tls
= ((get_elf_i386_backend_data (output_bfd
)->os
3428 && bfd_link_pic (info
)
3429 && !strcmp (input_section
->output_section
->name
,
3432 _bfd_x86_elf_set_tls_module_base (info
);
3434 plt_entry_size
= elf_i386_plt (htab
).plt_entry_size
;
3436 rel
= wrel
= relocs
;
3437 relend
= relocs
+ input_section
->reloc_count
;
3438 for (; rel
< relend
; wrel
++, rel
++)
3440 unsigned int r_type
;
3441 reloc_howto_type
*howto
;
3442 unsigned long r_symndx
;
3443 struct elf_link_hash_entry
*h
;
3444 struct elf_x86_link_hash_entry
*eh
;
3445 Elf_Internal_Sym
*sym
;
3447 bfd_vma off
, offplt
, plt_offset
;
3449 bfd_boolean unresolved_reloc
;
3450 bfd_reloc_status_type r
;
3454 asection
*resolved_plt
;
3455 bfd_boolean resolved_to_zero
;
3456 bfd_boolean relative_reloc
;
3458 r_type
= ELF32_R_TYPE (rel
->r_info
);
3459 if (r_type
== R_386_GNU_VTINHERIT
3460 || r_type
== R_386_GNU_VTENTRY
)
3467 if ((indx
= r_type
) >= R_386_standard
3468 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3469 >= R_386_ext
- R_386_standard
)
3470 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3471 >= R_386_ext2
- R_386_ext
))
3472 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
3474 howto
= elf_howto_table
+ indx
;
3476 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3480 unresolved_reloc
= FALSE
;
3481 if (r_symndx
< symtab_hdr
->sh_info
)
3483 sym
= local_syms
+ r_symndx
;
3484 sec
= local_sections
[r_symndx
];
3485 relocation
= (sec
->output_section
->vma
3486 + sec
->output_offset
3488 st_size
= sym
->st_size
;
3490 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3491 && ((sec
->flags
& SEC_MERGE
) != 0
3492 || (bfd_link_relocatable (info
)
3493 && sec
->output_offset
!= 0)))
3496 bfd_byte
*where
= contents
+ rel
->r_offset
;
3498 switch (howto
->size
)
3501 addend
= bfd_get_8 (input_bfd
, where
);
3502 if (howto
->pc_relative
)
3504 addend
= (addend
^ 0x80) - 0x80;
3509 addend
= bfd_get_16 (input_bfd
, where
);
3510 if (howto
->pc_relative
)
3512 addend
= (addend
^ 0x8000) - 0x8000;
3517 addend
= bfd_get_32 (input_bfd
, where
);
3518 if (howto
->pc_relative
)
3520 addend
= (addend
^ 0x80000000) - 0x80000000;
3528 if (bfd_link_relocatable (info
))
3529 addend
+= sec
->output_offset
;
3532 asection
*msec
= sec
;
3533 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3535 addend
-= relocation
;
3536 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3539 switch (howto
->size
)
3542 /* FIXME: overflow checks. */
3543 if (howto
->pc_relative
)
3545 bfd_put_8 (input_bfd
, addend
, where
);
3548 if (howto
->pc_relative
)
3550 bfd_put_16 (input_bfd
, addend
, where
);
3553 if (howto
->pc_relative
)
3555 bfd_put_32 (input_bfd
, addend
, where
);
3559 else if (!bfd_link_relocatable (info
)
3560 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3562 /* Relocate against local STT_GNU_IFUNC symbol. */
3563 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
, rel
,
3568 /* Set STT_GNU_IFUNC symbol value. */
3569 h
->root
.u
.def
.value
= sym
->st_value
;
3570 h
->root
.u
.def
.section
= sec
;
3575 bfd_boolean warned ATTRIBUTE_UNUSED
;
3576 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3578 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3579 r_symndx
, symtab_hdr
, sym_hashes
,
3581 unresolved_reloc
, warned
, ignored
);
3585 if (sec
!= NULL
&& discarded_section (sec
))
3587 _bfd_clear_contents (howto
, input_bfd
, input_section
,
3588 contents
+ rel
->r_offset
);
3589 wrel
->r_offset
= rel
->r_offset
;
3593 /* For ld -r, remove relocations in debug sections against
3594 sections defined in discarded sections. Not done for
3595 eh_frame editing code expects to be present. */
3596 if (bfd_link_relocatable (info
)
3597 && (input_section
->flags
& SEC_DEBUGGING
))
3603 if (bfd_link_relocatable (info
))
3610 eh
= (struct elf_x86_link_hash_entry
*) h
;
3612 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3613 it here if it is defined in a non-shared object. */
3615 && h
->type
== STT_GNU_IFUNC
3618 asection
*gotplt
, *base_got
;
3622 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3624 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3625 sections because such sections are not SEC_ALLOC and
3626 thus ld.so will not process them. */
3627 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
3632 /* STT_GNU_IFUNC symbol must go through PLT. */
3633 if (htab
->elf
.splt
!= NULL
)
3635 if (htab
->plt_second
!= NULL
)
3637 resolved_plt
= htab
->plt_second
;
3638 plt_offset
= eh
->plt_second
.offset
;
3642 resolved_plt
= htab
->elf
.splt
;
3643 plt_offset
= h
->plt
.offset
;
3645 gotplt
= htab
->elf
.sgotplt
;
3649 resolved_plt
= htab
->elf
.iplt
;
3650 plt_offset
= h
->plt
.offset
;
3651 gotplt
= htab
->elf
.igotplt
;
3661 base_got
= htab
->elf
.sgot
;
3662 off
= h
->got
.offset
;
3664 if (base_got
== NULL
)
3667 if (off
== (bfd_vma
) -1)
3669 /* We can't use h->got.offset here to save state, or
3670 even just remember the offset, as finish_dynamic_symbol
3671 would use that as offset into .got. */
3673 if (h
->plt
.offset
== (bfd_vma
) -1)
3676 if (htab
->elf
.splt
!= NULL
)
3678 plt_index
= (h
->plt
.offset
/ plt_entry_size
3679 - elf_i386_plt (htab
).has_plt0
);
3680 off
= (plt_index
+ 3) * 4;
3681 base_got
= htab
->elf
.sgotplt
;
3685 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3686 off
= plt_index
* 4;
3687 base_got
= htab
->elf
.igotplt
;
3690 if (h
->dynindx
== -1
3694 /* This references the local defitionion. We must
3695 initialize this entry in the global offset table.
3696 Since the offset must always be a multiple of 8,
3697 we use the least significant bit to record
3698 whether we have initialized it already.
3700 When doing a dynamic link, we create a .rela.got
3701 relocation entry to initialize the value. This
3702 is done in the finish_dynamic_symbol routine. */
3707 bfd_put_32 (output_bfd
, relocation
,
3708 base_got
->contents
+ off
);
3716 relocation
= (base_got
->output_section
->vma
3717 + base_got
->output_offset
+ off
3718 - gotplt
->output_section
->vma
3719 - gotplt
->output_offset
);
3721 if (rel
->r_offset
> 1
3722 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
3723 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
3725 if (bfd_link_pic (info
))
3726 goto disallow_got32
;
3728 /* Add the GOT base if there is no base register. */
3729 relocation
+= (gotplt
->output_section
->vma
3730 + gotplt
->output_offset
);
3732 else if (htab
->elf
.splt
== NULL
)
3734 /* Adjust for static executables. */
3735 relocation
+= gotplt
->output_offset
;
3741 if (h
->plt
.offset
== (bfd_vma
) -1)
3743 /* Handle static pointers of STT_GNU_IFUNC symbols. */
3744 if (r_type
== R_386_32
3745 && (input_section
->flags
& SEC_CODE
) == 0)
3746 goto do_ifunc_pointer
;
3747 goto bad_ifunc_reloc
;
3750 relocation
= (resolved_plt
->output_section
->vma
3751 + resolved_plt
->output_offset
+ plt_offset
);
3757 if (h
->root
.root
.string
)
3758 name
= h
->root
.root
.string
;
3760 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3763 /* xgettext:c-format */
3764 (_("%B: relocation %s against STT_GNU_IFUNC "
3765 "symbol `%s' isn't supported"), input_bfd
,
3767 bfd_set_error (bfd_error_bad_value
);
3771 /* Generate dynamic relcoation only when there is a
3772 non-GOT reference in a shared object. */
3773 if ((bfd_link_pic (info
) && h
->non_got_ref
)
3774 || h
->plt
.offset
== (bfd_vma
) -1)
3776 Elf_Internal_Rela outrel
;
3781 /* Need a dynamic relocation to get the real function
3783 offset
= _bfd_elf_section_offset (output_bfd
,
3787 if (offset
== (bfd_vma
) -1
3788 || offset
== (bfd_vma
) -2)
3791 outrel
.r_offset
= (input_section
->output_section
->vma
3792 + input_section
->output_offset
3795 if (h
->dynindx
== -1
3797 || bfd_link_executable (info
))
3799 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3800 h
->root
.root
.string
,
3801 h
->root
.u
.def
.section
->owner
);
3803 /* This symbol is resolved locally. */
3804 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3805 bfd_put_32 (output_bfd
,
3806 (h
->root
.u
.def
.value
3807 + h
->root
.u
.def
.section
->output_section
->vma
3808 + h
->root
.u
.def
.section
->output_offset
),
3812 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3814 /* Dynamic relocations are stored in
3815 1. .rel.ifunc section in PIC object.
3816 2. .rel.got section in dynamic executable.
3817 3. .rel.iplt section in static executable. */
3818 if (bfd_link_pic (info
))
3819 sreloc
= htab
->elf
.irelifunc
;
3820 else if (htab
->elf
.splt
!= NULL
)
3821 sreloc
= htab
->elf
.srelgot
;
3823 sreloc
= htab
->elf
.irelplt
;
3824 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3826 /* If this reloc is against an external symbol, we
3827 do not want to fiddle with the addend. Otherwise,
3828 we need to include the symbol value so that it
3829 becomes an addend for the dynamic reloc. For an
3830 internal symbol, we have updated addend. */
3839 relocation
-= (gotplt
->output_section
->vma
3840 + gotplt
->output_offset
);
3845 resolved_to_zero
= (eh
!= NULL
3846 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3854 /* Avoid optimizing _DYNAMIC since ld.so may use its
3855 link-time address. */
3856 if (h
== htab
->elf
.hdynamic
)
3859 if (bfd_link_pic (info
))
3861 /* It is OK to convert mov to lea and convert indirect
3862 branch to direct branch. It is OK to convert adc,
3863 add, and, cmp, or, sbb, sub, test, xor only when PIC
3865 unsigned int opcode
, addend
;
3866 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3869 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3870 if (opcode
!= 0x8b && opcode
!= 0xff)
3874 /* Resolve "mov GOT[(%reg)], %reg",
3875 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
3876 and "binop foo@GOT[(%reg)], %reg". */
3878 || (h
->plt
.offset
== (bfd_vma
) -1
3879 && h
->got
.offset
== (bfd_vma
) -1)
3880 || htab
->elf
.sgotplt
== NULL
)
3883 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
3884 + htab
->elf
.sgotplt
->output_offset
);
3886 /* It is relative to .got.plt section. */
3887 if (h
->got
.offset
!= (bfd_vma
) -1)
3888 /* Use GOT entry. Mask off the least significant bit in
3889 GOT offset which may be set by R_386_GOT32 processing
3891 relocation
= (htab
->elf
.sgot
->output_section
->vma
3892 + htab
->elf
.sgot
->output_offset
3893 + (h
->got
.offset
& ~1) - offplt
);
3895 /* Use GOTPLT entry. */
3896 relocation
= (h
->plt
.offset
/ plt_entry_size
3897 - elf_i386_plt (htab
).has_plt0
+ 3) * 4;
3899 if (!bfd_link_pic (info
))
3901 /* If not PIC, add the .got.plt section address for
3902 baseless addressing. */
3904 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3905 if ((modrm
& 0xc7) == 0x5)
3906 relocation
+= offplt
;
3909 unresolved_reloc
= FALSE
;
3914 /* Relocation is to the entry for this symbol in the global
3916 if (htab
->elf
.sgot
== NULL
)
3919 relative_reloc
= FALSE
;
3924 off
= h
->got
.offset
;
3925 dyn
= htab
->elf
.dynamic_sections_created
;
3926 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
3927 bfd_link_pic (info
),
3929 || (bfd_link_pic (info
)
3930 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3931 || (ELF_ST_VISIBILITY (h
->other
)
3932 && h
->root
.type
== bfd_link_hash_undefweak
))
3934 /* This is actually a static link, or it is a
3935 -Bsymbolic link and the symbol is defined
3936 locally, or the symbol was forced to be local
3937 because of a version file. We must initialize
3938 this entry in the global offset table. Since the
3939 offset must always be a multiple of 4, we use the
3940 least significant bit to record whether we have
3941 initialized it already.
3943 When doing a dynamic link, we create a .rel.got
3944 relocation entry to initialize the value. This
3945 is done in the finish_dynamic_symbol routine. */
3950 bfd_put_32 (output_bfd
, relocation
,
3951 htab
->elf
.sgot
->contents
+ off
);
3954 if (h
->dynindx
== -1
3956 && h
->root
.type
!= bfd_link_hash_undefweak
3957 && bfd_link_pic (info
))
3959 /* PR ld/21402: If this symbol isn't dynamic
3960 in PIC, generate R_386_RELATIVE here. */
3961 eh
->no_finish_dynamic_symbol
= 1;
3962 relative_reloc
= TRUE
;
3967 unresolved_reloc
= FALSE
;
3971 if (local_got_offsets
== NULL
)
3974 off
= local_got_offsets
[r_symndx
];
3976 /* The offset must always be a multiple of 4. We use
3977 the least significant bit to record whether we have
3978 already generated the necessary reloc. */
3983 bfd_put_32 (output_bfd
, relocation
,
3984 htab
->elf
.sgot
->contents
+ off
);
3985 local_got_offsets
[r_symndx
] |= 1;
3987 if (bfd_link_pic (info
))
3988 relative_reloc
= TRUE
;
3995 Elf_Internal_Rela outrel
;
3997 s
= htab
->elf
.srelgot
;
4001 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4002 + htab
->elf
.sgot
->output_offset
4004 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4005 elf_append_rel (output_bfd
, s
, &outrel
);
4008 if (off
>= (bfd_vma
) -2)
4011 relocation
= (htab
->elf
.sgot
->output_section
->vma
4012 + htab
->elf
.sgot
->output_offset
+ off
);
4013 if (rel
->r_offset
> 1
4014 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4015 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4017 if (bfd_link_pic (info
))
4019 /* For PIC, disallow R_386_GOT32 without a base
4020 register, except for "lea foo@GOT, %reg", since
4021 we don't know what the GOT base is. */
4025 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
4026 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4029 name
= h
->root
.root
.string
;
4032 /* xgettext:c-format */
4033 (_("%B: direct GOT relocation %s against `%s'"
4034 " without base register can not be used"
4035 " when making a shared object"),
4036 input_bfd
, howto
->name
, name
);
4037 bfd_set_error (bfd_error_bad_value
);
4043 /* Subtract the .got.plt section address only with a base
4045 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
4046 + htab
->elf
.sgotplt
->output_offset
);
4052 /* Relocation is relative to the start of the global offset
4055 /* Check to make sure it isn't a protected function or data
4056 symbol for shared library since it may not be local when
4057 used as function address or with copy relocation. We also
4058 need to make sure that a symbol is referenced locally. */
4059 if (!bfd_link_executable (info
) && h
)
4061 if (!h
->def_regular
)
4065 switch (ELF_ST_VISIBILITY (h
->other
))
4068 v
= _("hidden symbol");
4071 v
= _("internal symbol");
4074 v
= _("protected symbol");
4082 /* xgettext:c-format */
4083 (_("%B: relocation R_386_GOTOFF against undefined %s"
4084 " `%s' can not be used when making a shared object"),
4085 input_bfd
, v
, h
->root
.root
.string
);
4086 bfd_set_error (bfd_error_bad_value
);
4089 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
4090 && (h
->type
== STT_FUNC
4091 || h
->type
== STT_OBJECT
)
4092 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4095 /* xgettext:c-format */
4096 (_("%B: relocation R_386_GOTOFF against protected %s"
4097 " `%s' can not be used when making a shared object"),
4099 h
->type
== STT_FUNC
? "function" : "data",
4100 h
->root
.root
.string
);
4101 bfd_set_error (bfd_error_bad_value
);
4106 /* Note that sgot is not involved in this
4107 calculation. We always want the start of .got.plt. If we
4108 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4109 permitted by the ABI, we might have to change this
4111 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4112 + htab
->elf
.sgotplt
->output_offset
;
4116 /* Use global offset table as symbol value. */
4117 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4118 + htab
->elf
.sgotplt
->output_offset
;
4119 unresolved_reloc
= FALSE
;
4123 /* Relocation is to the entry for this symbol in the
4124 procedure linkage table. */
4126 /* Resolve a PLT32 reloc against a local symbol directly,
4127 without using the procedure linkage table. */
4131 if ((h
->plt
.offset
== (bfd_vma
) -1
4132 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4133 || htab
->elf
.splt
== NULL
)
4135 /* We didn't make a PLT entry for this symbol. This
4136 happens when statically linking PIC code, or when
4137 using -Bsymbolic. */
4141 if (h
->plt
.offset
!= (bfd_vma
) -1)
4143 if (htab
->plt_second
!= NULL
)
4145 resolved_plt
= htab
->plt_second
;
4146 plt_offset
= eh
->plt_second
.offset
;
4150 resolved_plt
= htab
->elf
.splt
;
4151 plt_offset
= h
->plt
.offset
;
4156 resolved_plt
= htab
->plt_got
;
4157 plt_offset
= eh
->plt_got
.offset
;
4160 relocation
= (resolved_plt
->output_section
->vma
4161 + resolved_plt
->output_offset
4163 unresolved_reloc
= FALSE
;
4167 /* Set to symbol size. */
4168 relocation
= st_size
;
4173 if ((input_section
->flags
& SEC_ALLOC
) == 0
4177 /* Copy dynamic function pointer relocations. Don't generate
4178 dynamic relocations against resolved undefined weak symbols
4179 in PIE, except for R_386_PC32. */
4180 if ((bfd_link_pic (info
)
4182 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4183 && (!resolved_to_zero
4184 || r_type
== R_386_PC32
))
4185 || h
->root
.type
!= bfd_link_hash_undefweak
))
4186 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
4187 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4188 || (ELIMINATE_COPY_RELOCS
4189 && !bfd_link_pic (info
)
4193 || eh
->func_pointer_refcount
> 0
4194 || (h
->root
.type
== bfd_link_hash_undefweak
4195 && !resolved_to_zero
))
4196 && ((h
->def_dynamic
&& !h
->def_regular
)
4197 /* Undefined weak symbol is bound locally when
4199 || h
->root
.type
== bfd_link_hash_undefweak
)))
4201 Elf_Internal_Rela outrel
;
4202 bfd_boolean skip
, relocate
;
4205 /* When generating a shared object, these relocations
4206 are copied into the output file to be resolved at run
4213 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4215 if (outrel
.r_offset
== (bfd_vma
) -1)
4217 else if (outrel
.r_offset
== (bfd_vma
) -2)
4218 skip
= TRUE
, relocate
= TRUE
;
4219 outrel
.r_offset
+= (input_section
->output_section
->vma
4220 + input_section
->output_offset
);
4223 memset (&outrel
, 0, sizeof outrel
);
4226 && (r_type
== R_386_PC32
4227 || !(bfd_link_executable (info
)
4228 || SYMBOLIC_BIND (info
, h
))
4229 || !h
->def_regular
))
4230 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4233 /* This symbol is local, or marked to become local. */
4235 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4238 sreloc
= elf_section_data (input_section
)->sreloc
;
4240 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4242 r
= bfd_reloc_notsupported
;
4243 goto check_relocation_error
;
4246 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4248 /* If this reloc is against an external symbol, we do
4249 not want to fiddle with the addend. Otherwise, we
4250 need to include the symbol value so that it becomes
4251 an addend for the dynamic reloc. */
4258 if (!bfd_link_executable (info
))
4260 Elf_Internal_Rela outrel
;
4263 outrel
.r_offset
= rel
->r_offset
4264 + input_section
->output_section
->vma
4265 + input_section
->output_offset
;
4266 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4267 sreloc
= elf_section_data (input_section
)->sreloc
;
4270 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4275 case R_386_TLS_GOTDESC
:
4276 case R_386_TLS_DESC_CALL
:
4277 case R_386_TLS_IE_32
:
4278 case R_386_TLS_GOTIE
:
4279 tls_type
= GOT_UNKNOWN
;
4280 if (h
== NULL
&& local_got_offsets
)
4281 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
4283 tls_type
= elf_x86_hash_entry(h
)->tls_type
;
4284 if (tls_type
== GOT_TLS_IE
)
4285 tls_type
= GOT_TLS_IE_NEG
;
4287 if (! elf_i386_tls_transition (info
, input_bfd
,
4288 input_section
, contents
,
4289 symtab_hdr
, sym_hashes
,
4290 &r_type
, tls_type
, rel
,
4291 relend
, h
, r_symndx
, TRUE
))
4294 if (r_type
== R_386_TLS_LE_32
)
4296 BFD_ASSERT (! unresolved_reloc
);
4297 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4302 /* GD->LE transition. */
4303 type
= *(contents
+ rel
->r_offset
- 2);
4307 leal foo@tlsgd(,%ebx,1), %eax
4308 call ___tls_get_addr@PLT
4311 subl $foo@tpoff, %eax
4312 (6 byte form of subl). */
4313 roff
= rel
->r_offset
+ 5;
4318 leal foo@tlsgd(%ebx), %eax
4319 call ___tls_get_addr@PLT
4322 leal foo@tlsgd(%reg), %eax
4323 call *___tls_get_addr@GOT(%reg)
4324 which may be converted to
4325 addr32 call ___tls_get_addr
4327 movl %gs:0, %eax; subl $foo@tpoff, %eax
4328 (6 byte form of subl). */
4329 roff
= rel
->r_offset
+ 6;
4331 memcpy (contents
+ roff
- 8,
4332 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4333 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4335 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4340 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4342 /* GDesc -> LE transition.
4343 It's originally something like:
4344 leal x@tlsdesc(%ebx), %eax
4348 Registers other than %eax may be set up here. */
4353 roff
= rel
->r_offset
;
4354 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4356 /* Now modify the instruction as appropriate. */
4357 /* aoliva FIXME: remove the above and xor the byte
4359 bfd_put_8 (output_bfd
, val
^ 0x86,
4360 contents
+ roff
- 1);
4361 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4365 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4367 /* GDesc -> LE transition.
4375 roff
= rel
->r_offset
;
4376 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4377 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4380 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4384 /* IE->LE transition:
4385 Originally it can be one of:
4393 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4396 /* movl foo, %eax. */
4397 bfd_put_8 (output_bfd
, 0xb8,
4398 contents
+ rel
->r_offset
- 1);
4404 type
= bfd_get_8 (input_bfd
,
4405 contents
+ rel
->r_offset
- 2);
4410 bfd_put_8 (output_bfd
, 0xc7,
4411 contents
+ rel
->r_offset
- 2);
4412 bfd_put_8 (output_bfd
,
4413 0xc0 | ((val
>> 3) & 7),
4414 contents
+ rel
->r_offset
- 1);
4418 bfd_put_8 (output_bfd
, 0x81,
4419 contents
+ rel
->r_offset
- 2);
4420 bfd_put_8 (output_bfd
,
4421 0xc0 | ((val
>> 3) & 7),
4422 contents
+ rel
->r_offset
- 1);
4429 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4430 contents
+ rel
->r_offset
);
4435 unsigned int val
, type
;
4437 /* {IE_32,GOTIE}->LE transition:
4438 Originally it can be one of:
4439 subl foo(%reg1), %reg2
4440 movl foo(%reg1), %reg2
4441 addl foo(%reg1), %reg2
4444 movl $foo, %reg2 (6 byte form)
4445 addl $foo, %reg2. */
4446 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4447 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4451 bfd_put_8 (output_bfd
, 0xc7,
4452 contents
+ rel
->r_offset
- 2);
4453 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4454 contents
+ rel
->r_offset
- 1);
4456 else if (type
== 0x2b)
4459 bfd_put_8 (output_bfd
, 0x81,
4460 contents
+ rel
->r_offset
- 2);
4461 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4462 contents
+ rel
->r_offset
- 1);
4464 else if (type
== 0x03)
4467 bfd_put_8 (output_bfd
, 0x81,
4468 contents
+ rel
->r_offset
- 2);
4469 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4470 contents
+ rel
->r_offset
- 1);
4474 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4475 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4476 contents
+ rel
->r_offset
);
4478 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4479 contents
+ rel
->r_offset
);
4484 if (htab
->elf
.sgot
== NULL
)
4489 off
= h
->got
.offset
;
4490 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
4494 if (local_got_offsets
== NULL
)
4497 off
= local_got_offsets
[r_symndx
];
4498 offplt
= local_tlsdesc_gotents
[r_symndx
];
4505 Elf_Internal_Rela outrel
;
4509 if (htab
->elf
.srelgot
== NULL
)
4512 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4514 if (GOT_TLS_GDESC_P (tls_type
))
4517 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4518 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4519 <= htab
->elf
.sgotplt
->size
);
4520 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4521 + htab
->elf
.sgotplt
->output_offset
4523 + htab
->sgotplt_jump_table_size
);
4524 sreloc
= htab
->elf
.srelplt
;
4525 loc
= sreloc
->contents
;
4526 loc
+= (elf_i386_next_tls_desc_index (htab
)++
4527 * sizeof (Elf32_External_Rel
));
4528 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4529 <= sreloc
->contents
+ sreloc
->size
);
4530 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4533 BFD_ASSERT (! unresolved_reloc
);
4534 bfd_put_32 (output_bfd
,
4535 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4536 htab
->elf
.sgotplt
->contents
+ offplt
4537 + htab
->sgotplt_jump_table_size
+ 4);
4541 bfd_put_32 (output_bfd
, 0,
4542 htab
->elf
.sgotplt
->contents
+ offplt
4543 + htab
->sgotplt_jump_table_size
+ 4);
4547 sreloc
= htab
->elf
.srelgot
;
4549 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4550 + htab
->elf
.sgot
->output_offset
+ off
);
4552 if (GOT_TLS_GD_P (tls_type
))
4553 dr_type
= R_386_TLS_DTPMOD32
;
4554 else if (GOT_TLS_GDESC_P (tls_type
))
4556 else if (tls_type
== GOT_TLS_IE_POS
)
4557 dr_type
= R_386_TLS_TPOFF
;
4559 dr_type
= R_386_TLS_TPOFF32
;
4561 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
4562 bfd_put_32 (output_bfd
,
4563 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4564 htab
->elf
.sgot
->contents
+ off
);
4565 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
4566 bfd_put_32 (output_bfd
,
4567 _bfd_x86_elf_dtpoff_base (info
) - relocation
,
4568 htab
->elf
.sgot
->contents
+ off
);
4569 else if (dr_type
!= R_386_TLS_DESC
)
4570 bfd_put_32 (output_bfd
, 0,
4571 htab
->elf
.sgot
->contents
+ off
);
4572 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
4574 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4576 if (GOT_TLS_GD_P (tls_type
))
4580 BFD_ASSERT (! unresolved_reloc
);
4581 bfd_put_32 (output_bfd
,
4582 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4583 htab
->elf
.sgot
->contents
+ off
+ 4);
4587 bfd_put_32 (output_bfd
, 0,
4588 htab
->elf
.sgot
->contents
+ off
+ 4);
4589 outrel
.r_info
= ELF32_R_INFO (indx
,
4590 R_386_TLS_DTPOFF32
);
4591 outrel
.r_offset
+= 4;
4592 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4595 else if (tls_type
== GOT_TLS_IE_BOTH
)
4597 bfd_put_32 (output_bfd
,
4599 ? relocation
- _bfd_x86_elf_dtpoff_base (info
)
4601 htab
->elf
.sgot
->contents
+ off
+ 4);
4602 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4603 outrel
.r_offset
+= 4;
4604 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4611 local_got_offsets
[r_symndx
] |= 1;
4614 if (off
>= (bfd_vma
) -2
4615 && ! GOT_TLS_GDESC_P (tls_type
))
4617 if (r_type
== R_386_TLS_GOTDESC
4618 || r_type
== R_386_TLS_DESC_CALL
)
4620 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4621 unresolved_reloc
= FALSE
;
4623 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4625 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4626 + htab
->elf
.sgotplt
->output_offset
;
4627 relocation
= htab
->elf
.sgot
->output_section
->vma
4628 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4629 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4630 && tls_type
== GOT_TLS_IE_BOTH
)
4632 if (r_type
== R_386_TLS_IE
)
4633 relocation
+= g_o_t
;
4634 unresolved_reloc
= FALSE
;
4636 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4638 unsigned int val
, type
;
4641 /* GD->IE transition. */
4642 type
= *(contents
+ rel
->r_offset
- 2);
4643 val
= *(contents
+ rel
->r_offset
- 1);
4647 leal foo@tlsgd(,%ebx,1), %eax
4648 call ___tls_get_addr@PLT
4651 subl $foo@gottpoff(%ebx), %eax. */
4653 roff
= rel
->r_offset
- 3;
4658 leal foo@tlsgd(%ebx), %eax
4659 call ___tls_get_addr@PLT
4662 leal foo@tlsgd(%reg), %eax
4663 call *___tls_get_addr@GOT(%reg)
4664 which may be converted to
4665 addr32 call ___tls_get_addr
4668 subl $foo@gottpoff(%reg), %eax. */
4669 roff
= rel
->r_offset
- 2;
4671 memcpy (contents
+ roff
,
4672 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4673 contents
[roff
+ 7] = 0x80 | (val
& 7);
4674 /* If foo is used only with foo@gotntpoff(%reg) and
4675 foo@indntpoff, but not with foo@gottpoff(%reg), change
4676 subl $foo@gottpoff(%reg), %eax
4678 addl $foo@gotntpoff(%reg), %eax. */
4679 if (tls_type
== GOT_TLS_IE_POS
)
4680 contents
[roff
+ 6] = 0x03;
4681 bfd_put_32 (output_bfd
,
4682 htab
->elf
.sgot
->output_section
->vma
4683 + htab
->elf
.sgot
->output_offset
+ off
4684 - htab
->elf
.sgotplt
->output_section
->vma
4685 - htab
->elf
.sgotplt
->output_offset
,
4686 contents
+ roff
+ 8);
4687 /* Skip R_386_PLT32 and R_386_GOT32X. */
4692 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4694 /* GDesc -> IE transition.
4695 It's originally something like:
4696 leal x@tlsdesc(%ebx), %eax
4699 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4701 movl x@gottpoff(%ebx), %eax # before negl %eax
4703 Registers other than %eax may be set up here. */
4707 /* First, make sure it's a leal adding ebx to a 32-bit
4708 offset into any register, although it's probably
4709 almost always going to be eax. */
4710 roff
= rel
->r_offset
;
4712 /* Now modify the instruction as appropriate. */
4713 /* To turn a leal into a movl in the form we use it, it
4714 suffices to change the first byte from 0x8d to 0x8b.
4715 aoliva FIXME: should we decide to keep the leal, all
4716 we have to do is remove the statement below, and
4717 adjust the relaxation of R_386_TLS_DESC_CALL. */
4718 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4720 if (tls_type
== GOT_TLS_IE_BOTH
)
4723 bfd_put_32 (output_bfd
,
4724 htab
->elf
.sgot
->output_section
->vma
4725 + htab
->elf
.sgot
->output_offset
+ off
4726 - htab
->elf
.sgotplt
->output_section
->vma
4727 - htab
->elf
.sgotplt
->output_offset
,
4731 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4733 /* GDesc -> IE transition.
4741 depending on how we transformed the TLS_GOTDESC above.
4746 roff
= rel
->r_offset
;
4748 /* Now modify the instruction as appropriate. */
4749 if (tls_type
!= GOT_TLS_IE_NEG
)
4752 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4753 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4758 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4759 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4769 if (! elf_i386_tls_transition (info
, input_bfd
,
4770 input_section
, contents
,
4771 symtab_hdr
, sym_hashes
,
4772 &r_type
, GOT_UNKNOWN
, rel
,
4773 relend
, h
, r_symndx
, TRUE
))
4776 if (r_type
!= R_386_TLS_LDM
)
4778 /* LD->LE transition. Change
4779 leal foo@tlsldm(%ebx) %eax
4780 call ___tls_get_addr@PLT
4784 leal 0(%esi,1), %esi
4786 leal foo@tlsldm(%reg) %eax
4787 call *___tls_get_addr@GOT(%reg)
4788 which may be converted to
4789 addr32 call ___tls_get_addr
4792 leal 0(%esi), %esi */
4793 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4794 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
4795 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
4796 memcpy (contents
+ rel
->r_offset
- 2,
4797 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
4799 memcpy (contents
+ rel
->r_offset
- 2,
4800 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4801 /* Skip R_386_PC32/R_386_PLT32. */
4807 if (htab
->elf
.sgot
== NULL
)
4810 off
= htab
->tls_ld_or_ldm_got
.offset
;
4815 Elf_Internal_Rela outrel
;
4817 if (htab
->elf
.srelgot
== NULL
)
4820 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4821 + htab
->elf
.sgot
->output_offset
+ off
);
4823 bfd_put_32 (output_bfd
, 0,
4824 htab
->elf
.sgot
->contents
+ off
);
4825 bfd_put_32 (output_bfd
, 0,
4826 htab
->elf
.sgot
->contents
+ off
+ 4);
4827 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4828 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
4829 htab
->tls_ld_or_ldm_got
.offset
|= 1;
4831 relocation
= htab
->elf
.sgot
->output_section
->vma
4832 + htab
->elf
.sgot
->output_offset
+ off
4833 - htab
->elf
.sgotplt
->output_section
->vma
4834 - htab
->elf
.sgotplt
->output_offset
;
4835 unresolved_reloc
= FALSE
;
4838 case R_386_TLS_LDO_32
:
4839 if (!bfd_link_executable (info
)
4840 || (input_section
->flags
& SEC_CODE
) == 0)
4841 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4843 /* When converting LDO to LE, we must negate. */
4844 relocation
= -elf_i386_tpoff (info
, relocation
);
4847 case R_386_TLS_LE_32
:
4849 if (!bfd_link_executable (info
))
4851 Elf_Internal_Rela outrel
;
4854 outrel
.r_offset
= rel
->r_offset
4855 + input_section
->output_section
->vma
4856 + input_section
->output_offset
;
4857 if (h
!= NULL
&& h
->dynindx
!= -1)
4861 if (r_type
== R_386_TLS_LE_32
)
4862 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4864 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4865 sreloc
= elf_section_data (input_section
)->sreloc
;
4868 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4871 else if (r_type
== R_386_TLS_LE_32
)
4872 relocation
= _bfd_x86_elf_dtpoff_base (info
) - relocation
;
4874 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4876 else if (r_type
== R_386_TLS_LE_32
)
4877 relocation
= elf_i386_tpoff (info
, relocation
);
4879 relocation
= -elf_i386_tpoff (info
, relocation
);
4886 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4887 because such sections are not SEC_ALLOC and thus ld.so will
4888 not process them. */
4889 if (unresolved_reloc
4890 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4892 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4893 rel
->r_offset
) != (bfd_vma
) -1)
4896 /* xgettext:c-format */
4897 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
4902 h
->root
.root
.string
);
4907 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4908 contents
, rel
->r_offset
,
4911 check_relocation_error
:
4912 if (r
!= bfd_reloc_ok
)
4917 name
= h
->root
.root
.string
;
4920 name
= bfd_elf_string_from_elf_section (input_bfd
,
4921 symtab_hdr
->sh_link
,
4926 name
= bfd_section_name (input_bfd
, sec
);
4929 if (r
== bfd_reloc_overflow
)
4930 (*info
->callbacks
->reloc_overflow
)
4931 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4932 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4936 /* xgettext:c-format */
4937 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
4938 input_bfd
, input_section
,
4939 rel
->r_offset
, name
, (int) r
);
4950 Elf_Internal_Shdr
*rel_hdr
;
4951 size_t deleted
= rel
- wrel
;
4953 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
4954 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4955 if (rel_hdr
->sh_size
== 0)
4957 /* It is too late to remove an empty reloc section. Leave
4959 ??? What is wrong with an empty section??? */
4960 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
4963 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
4964 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4965 input_section
->reloc_count
-= deleted
;
4971 /* Finish up dynamic symbol handling. We set the contents of various
4972 dynamic sections here. */
4975 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4976 struct bfd_link_info
*info
,
4977 struct elf_link_hash_entry
*h
,
4978 Elf_Internal_Sym
*sym
)
4980 struct elf_x86_link_hash_table
*htab
;
4981 unsigned plt_entry_size
;
4982 const struct elf_i386_backend_data
*abed
;
4983 struct elf_x86_link_hash_entry
*eh
;
4984 bfd_boolean local_undefweak
;
4985 bfd_boolean use_plt_second
;
4986 const struct elf_i386_plt_layout
*plt_layout
;
4987 const struct elf_i386_lazy_plt_layout
*lazy_plt_layout
;
4988 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt_layout
;
4990 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
4994 abed
= get_elf_i386_backend_data (output_bfd
);
4995 plt_layout
= &elf_i386_plt (htab
);
4996 lazy_plt_layout
= elf_i386_lazy_plt (htab
);
4997 non_lazy_plt_layout
= elf_i386_non_lazy_plt (htab
);
4998 plt_entry_size
= plt_layout
->plt_entry_size
;
5000 /* Use the second PLT section only if there is .plt section. */
5001 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
5003 eh
= (struct elf_x86_link_hash_entry
*) h
;
5004 if (eh
->no_finish_dynamic_symbol
)
5007 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5008 resolved undefined weak symbols in executable so that their
5009 references have value 0 at run-time. */
5010 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, I386_ELF_DATA
,
5014 if (h
->plt
.offset
!= (bfd_vma
) -1)
5016 bfd_vma plt_index
, plt_offset
;
5018 Elf_Internal_Rela rel
;
5020 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
5022 /* When building a static executable, use .iplt, .igot.plt and
5023 .rel.iplt sections for STT_GNU_IFUNC symbols. */
5024 if (htab
->elf
.splt
!= NULL
)
5026 plt
= htab
->elf
.splt
;
5027 gotplt
= htab
->elf
.sgotplt
;
5028 relplt
= htab
->elf
.srelplt
;
5032 plt
= htab
->elf
.iplt
;
5033 gotplt
= htab
->elf
.igotplt
;
5034 relplt
= htab
->elf
.irelplt
;
5037 /* This symbol has an entry in the procedure linkage table. Set
5040 if ((h
->dynindx
== -1
5042 && !((h
->forced_local
|| bfd_link_executable (info
))
5044 && h
->type
== STT_GNU_IFUNC
))
5050 /* Get the index in the procedure linkage table which
5051 corresponds to this symbol. This is the index of this symbol
5052 in all the symbols for which we are making plt entries. The
5053 first entry in the procedure linkage table is reserved.
5055 Get the offset into the .got table of the entry that
5056 corresponds to this function. Each .got entry is 4 bytes.
5057 The first three are reserved.
5059 For static executables, we don't reserve anything. */
5061 if (plt
== htab
->elf
.splt
)
5063 got_offset
= (h
->plt
.offset
/ plt_entry_size
5064 - plt_layout
->has_plt0
);
5065 got_offset
= (got_offset
+ 3) * 4;
5069 got_offset
= h
->plt
.offset
/ plt_entry_size
;
5070 got_offset
= got_offset
* 4;
5073 /* Fill in the entry in the procedure linkage table and update
5075 memcpy (plt
->contents
+ h
->plt
.offset
, plt_layout
->plt_entry
,
5080 const bfd_byte
*plt_entry
;
5081 if (bfd_link_pic (info
))
5082 plt_entry
= non_lazy_plt_layout
->pic_plt_entry
;
5084 plt_entry
= non_lazy_plt_layout
->plt_entry
;
5085 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
5086 plt_entry
, non_lazy_plt_layout
->plt_entry_size
);
5088 resolved_plt
= htab
->plt_second
;
5089 plt_offset
= eh
->plt_second
.offset
;
5094 plt_offset
= h
->plt
.offset
;
5097 if (! bfd_link_pic (info
))
5099 bfd_put_32 (output_bfd
,
5100 (gotplt
->output_section
->vma
5101 + gotplt
->output_offset
5103 resolved_plt
->contents
+ plt_offset
5104 + plt_layout
->plt_got_offset
);
5106 if (abed
->os
== is_vxworks
)
5108 int s
, k
, reloc_index
;
5110 /* Create the R_386_32 relocation referencing the GOT
5111 for this PLT entry. */
5113 /* S: Current slot number (zero-based). */
5114 s
= ((h
->plt
.offset
- plt_layout
->plt_entry_size
)
5115 / plt_layout
->plt_entry_size
);
5116 /* K: Number of relocations for PLTResolve. */
5117 if (bfd_link_pic (info
))
5118 k
= PLTRESOLVE_RELOCS_SHLIB
;
5120 k
= PLTRESOLVE_RELOCS
;
5121 /* Skip the PLTresolve relocations, and the relocations for
5122 the other PLT slots. */
5123 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
5124 loc
= (elf_i386_srelplt2 (htab
)->contents
+ reloc_index
5125 * sizeof (Elf32_External_Rel
));
5127 rel
.r_offset
= (plt
->output_section
->vma
5128 + plt
->output_offset
5129 + h
->plt
.offset
+ 2),
5130 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5131 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5133 /* Create the R_386_32 relocation referencing the beginning of
5134 the PLT for this GOT entry. */
5135 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5136 + htab
->elf
.sgotplt
->output_offset
5138 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5139 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5140 loc
+ sizeof (Elf32_External_Rel
));
5145 bfd_put_32 (output_bfd
, got_offset
,
5146 resolved_plt
->contents
+ plt_offset
5147 + plt_layout
->plt_got_offset
);
5150 /* Fill in the entry in the global offset table. Leave the entry
5151 as zero for undefined weak symbol in PIE. No PLT relocation
5152 against undefined weak symbol in PIE. */
5153 if (!local_undefweak
)
5155 if (plt_layout
->has_plt0
)
5156 bfd_put_32 (output_bfd
,
5157 (plt
->output_section
->vma
5158 + plt
->output_offset
5160 + lazy_plt_layout
->plt_lazy_offset
),
5161 gotplt
->contents
+ got_offset
);
5163 /* Fill in the entry in the .rel.plt section. */
5164 rel
.r_offset
= (gotplt
->output_section
->vma
5165 + gotplt
->output_offset
5167 if (h
->dynindx
== -1
5168 || ((bfd_link_executable (info
)
5169 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5171 && h
->type
== STT_GNU_IFUNC
))
5173 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5174 h
->root
.root
.string
,
5175 h
->root
.u
.def
.section
->owner
);
5177 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5178 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5179 in the .got.plt section. */
5180 bfd_put_32 (output_bfd
,
5181 (h
->root
.u
.def
.value
5182 + h
->root
.u
.def
.section
->output_section
->vma
5183 + h
->root
.u
.def
.section
->output_offset
),
5184 gotplt
->contents
+ got_offset
);
5185 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5186 /* R_386_IRELATIVE comes last. */
5187 plt_index
= htab
->next_irelative_index
--;
5191 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
5192 plt_index
= htab
->next_jump_slot_index
++;
5195 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5196 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5198 /* Don't fill the second and third slots in PLT entry for
5199 static executables nor without PLT0. */
5200 if (plt
== htab
->elf
.splt
&& plt_layout
->has_plt0
)
5202 bfd_put_32 (output_bfd
,
5203 plt_index
* sizeof (Elf32_External_Rel
),
5204 plt
->contents
+ h
->plt
.offset
5205 + lazy_plt_layout
->plt_reloc_offset
);
5206 bfd_put_32 (output_bfd
,
5208 + lazy_plt_layout
->plt_plt_offset
+ 4),
5209 (plt
->contents
+ h
->plt
.offset
5210 + lazy_plt_layout
->plt_plt_offset
));
5214 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5216 bfd_vma got_offset
, plt_offset
;
5217 asection
*plt
, *got
, *gotplt
;
5218 const bfd_byte
*got_plt_entry
;
5220 /* Set the entry in the GOT procedure linkage table. */
5221 plt
= htab
->plt_got
;
5222 got
= htab
->elf
.sgot
;
5223 gotplt
= htab
->elf
.sgotplt
;
5224 got_offset
= h
->got
.offset
;
5226 if (got_offset
== (bfd_vma
) -1
5232 /* Fill in the entry in the GOT procedure linkage table. */
5233 if (! bfd_link_pic (info
))
5235 got_plt_entry
= non_lazy_plt_layout
->plt_entry
;
5236 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
5240 got_plt_entry
= non_lazy_plt_layout
->pic_plt_entry
;
5241 got_offset
+= (got
->output_section
->vma
5242 + got
->output_offset
5243 - gotplt
->output_section
->vma
5244 - gotplt
->output_offset
);
5247 plt_offset
= eh
->plt_got
.offset
;
5248 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
5249 non_lazy_plt_layout
->plt_entry_size
);
5250 bfd_put_32 (output_bfd
, got_offset
,
5251 (plt
->contents
+ plt_offset
5252 + non_lazy_plt_layout
->plt_got_offset
));
5255 if (!local_undefweak
5257 && (h
->plt
.offset
!= (bfd_vma
) -1
5258 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5260 /* Mark the symbol as undefined, rather than as defined in
5261 the .plt section. Leave the value if there were any
5262 relocations where pointer equality matters (this is a clue
5263 for the dynamic linker, to make function pointer
5264 comparisons work between an application and shared
5265 library), otherwise set it to zero. If a function is only
5266 called from a binary, there is no need to slow down
5267 shared libraries because of that. */
5268 sym
->st_shndx
= SHN_UNDEF
;
5269 if (!h
->pointer_equality_needed
)
5273 /* Don't generate dynamic GOT relocation against undefined weak
5274 symbol in executable. */
5275 if (h
->got
.offset
!= (bfd_vma
) -1
5276 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h
)->tls_type
)
5277 && (elf_x86_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
5278 && !local_undefweak
)
5280 Elf_Internal_Rela rel
;
5281 asection
*relgot
= htab
->elf
.srelgot
;
5283 /* This symbol has an entry in the global offset table. Set it
5286 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5289 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5290 + htab
->elf
.sgot
->output_offset
5291 + (h
->got
.offset
& ~(bfd_vma
) 1));
5293 /* If this is a static link, or it is a -Bsymbolic link and the
5294 symbol is defined locally or was forced to be local because
5295 of a version file, we just want to emit a RELATIVE reloc.
5296 The entry in the global offset table will already have been
5297 initialized in the relocate_section function. */
5299 && h
->type
== STT_GNU_IFUNC
)
5301 if (h
->plt
.offset
== (bfd_vma
) -1)
5303 /* STT_GNU_IFUNC is referenced without PLT. */
5304 if (htab
->elf
.splt
== NULL
)
5306 /* use .rel[a].iplt section to store .got relocations
5307 in static executable. */
5308 relgot
= htab
->elf
.irelplt
;
5310 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5312 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5313 h
->root
.root
.string
,
5314 h
->root
.u
.def
.section
->owner
);
5316 bfd_put_32 (output_bfd
,
5317 (h
->root
.u
.def
.value
5318 + h
->root
.u
.def
.section
->output_section
->vma
5319 + h
->root
.u
.def
.section
->output_offset
),
5320 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5321 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5326 else if (bfd_link_pic (info
))
5328 /* Generate R_386_GLOB_DAT. */
5336 if (!h
->pointer_equality_needed
)
5339 /* For non-shared object, we can't use .got.plt, which
5340 contains the real function addres if we need pointer
5341 equality. We load the GOT entry with the PLT entry. */
5342 if (htab
->plt_second
!= NULL
)
5344 plt
= htab
->plt_second
;
5345 plt_offset
= eh
->plt_second
.offset
;
5349 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5350 plt_offset
= h
->plt
.offset
;
5352 bfd_put_32 (output_bfd
,
5353 (plt
->output_section
->vma
5354 + plt
->output_offset
+ plt_offset
),
5355 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5359 else if (bfd_link_pic (info
)
5360 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5362 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5363 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
5367 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5369 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5370 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5371 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
5374 elf_append_rel (output_bfd
, relgot
, &rel
);
5379 Elf_Internal_Rela rel
;
5382 /* This symbol needs a copy reloc. Set it up. */
5384 if (h
->dynindx
== -1
5385 || (h
->root
.type
!= bfd_link_hash_defined
5386 && h
->root
.type
!= bfd_link_hash_defweak
)
5387 || htab
->elf
.srelbss
== NULL
5388 || htab
->elf
.sreldynrelro
== NULL
)
5391 rel
.r_offset
= (h
->root
.u
.def
.value
5392 + h
->root
.u
.def
.section
->output_section
->vma
5393 + h
->root
.u
.def
.section
->output_offset
);
5394 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5395 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5396 s
= htab
->elf
.sreldynrelro
;
5398 s
= htab
->elf
.srelbss
;
5399 elf_append_rel (output_bfd
, s
, &rel
);
5405 /* Finish up local dynamic symbol handling. We set the contents of
5406 various dynamic sections here. */
5409 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5411 struct elf_link_hash_entry
*h
5412 = (struct elf_link_hash_entry
*) *slot
;
5413 struct bfd_link_info
*info
5414 = (struct bfd_link_info
*) inf
;
5416 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5420 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5421 here since undefined weak symbol may not be dynamic and may not be
5422 called for elf_i386_finish_dynamic_symbol. */
5425 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5428 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5429 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5431 if (h
->root
.type
!= bfd_link_hash_undefweak
5432 || h
->dynindx
!= -1)
5435 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5439 /* Used to decide how to sort relocs in an optimal manner for the
5440 dynamic linker, before writing them out. */
5442 static enum elf_reloc_type_class
5443 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5444 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5445 const Elf_Internal_Rela
*rela
)
5447 bfd
*abfd
= info
->output_bfd
;
5448 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5449 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5451 if (htab
->dynsym
!= NULL
5452 && htab
->dynsym
->contents
!= NULL
)
5454 /* Check relocation against STT_GNU_IFUNC symbol if there are
5456 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5457 if (r_symndx
!= STN_UNDEF
)
5459 Elf_Internal_Sym sym
;
5460 if (!bed
->s
->swap_symbol_in (abfd
,
5461 (htab
->dynsym
->contents
5462 + r_symndx
* sizeof (Elf32_External_Sym
)),
5466 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5467 return reloc_class_ifunc
;
5471 switch (ELF32_R_TYPE (rela
->r_info
))
5473 case R_386_IRELATIVE
:
5474 return reloc_class_ifunc
;
5475 case R_386_RELATIVE
:
5476 return reloc_class_relative
;
5477 case R_386_JUMP_SLOT
:
5478 return reloc_class_plt
;
5480 return reloc_class_copy
;
5482 return reloc_class_normal
;
5486 /* Finish up the dynamic sections. */
5489 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5490 struct bfd_link_info
*info
)
5492 struct elf_x86_link_hash_table
*htab
;
5495 const struct elf_i386_backend_data
*abed
;
5497 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
5501 dynobj
= htab
->elf
.dynobj
;
5502 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5503 abed
= get_elf_i386_backend_data (output_bfd
);
5505 if (htab
->elf
.dynamic_sections_created
)
5507 Elf32_External_Dyn
*dyncon
, *dynconend
;
5508 const struct elf_i386_plt_layout
*plt_layout
;
5509 const struct elf_i386_lazy_plt_layout
*lazy_plt_layout
;
5510 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt_layout
;
5512 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5515 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5516 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5517 for (; dyncon
< dynconend
; dyncon
++)
5519 Elf_Internal_Dyn dyn
;
5522 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5527 if (abed
->os
== is_vxworks
5528 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5533 s
= htab
->elf
.sgotplt
;
5534 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5538 s
= htab
->elf
.srelplt
;
5539 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5543 s
= htab
->elf
.srelplt
;
5544 dyn
.d_un
.d_val
= s
->size
;
5548 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5551 plt_layout
= &elf_i386_plt (htab
);
5552 lazy_plt_layout
= elf_i386_lazy_plt (htab
);
5553 non_lazy_plt_layout
= elf_i386_non_lazy_plt (htab
);
5555 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5557 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5558 really seem like the right value. */
5559 elf_section_data (htab
->elf
.splt
->output_section
)
5560 ->this_hdr
.sh_entsize
= 4;
5562 if (plt_layout
->has_plt0
)
5564 /* Fill in the special first entry in the procedure linkage
5566 memcpy (htab
->elf
.splt
->contents
, plt_layout
->plt0_entry
,
5567 lazy_plt_layout
->plt0_entry_size
);
5568 memset (htab
->elf
.splt
->contents
+ lazy_plt_layout
->plt0_entry_size
,
5569 abed
->plt0_pad_byte
,
5570 plt_layout
->plt_entry_size
- lazy_plt_layout
->plt0_entry_size
);
5571 if (!bfd_link_pic (info
))
5573 bfd_put_32 (output_bfd
,
5574 (htab
->elf
.sgotplt
->output_section
->vma
5575 + htab
->elf
.sgotplt
->output_offset
5577 htab
->elf
.splt
->contents
5578 + lazy_plt_layout
->plt0_got1_offset
);
5579 bfd_put_32 (output_bfd
,
5580 (htab
->elf
.sgotplt
->output_section
->vma
5581 + htab
->elf
.sgotplt
->output_offset
5583 htab
->elf
.splt
->contents
5584 + lazy_plt_layout
->plt0_got2_offset
);
5586 if (abed
->os
== is_vxworks
)
5588 Elf_Internal_Rela rel
;
5589 int num_plts
= (htab
->elf
.splt
->size
5590 / plt_layout
->plt_entry_size
) - 1;
5592 asection
*srelplt2
= elf_i386_srelplt2 (htab
);
5594 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5595 + 4. On IA32 we use REL relocations so the
5596 addend goes in the PLT directly. */
5597 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5598 + htab
->elf
.splt
->output_offset
5599 + lazy_plt_layout
->plt0_got1_offset
);
5600 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5602 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5603 srelplt2
->contents
);
5604 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5606 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5607 + htab
->elf
.splt
->output_offset
5608 + lazy_plt_layout
->plt0_got2_offset
);
5609 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5611 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5612 srelplt2
->contents
+
5613 sizeof (Elf32_External_Rel
));
5614 /* Correct the .rel.plt.unloaded relocations. */
5615 p
= srelplt2
->contents
;
5616 if (bfd_link_pic (info
))
5617 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
5619 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
5621 for (; num_plts
; num_plts
--)
5623 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5624 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5626 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5627 p
+= sizeof (Elf32_External_Rel
);
5629 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5630 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
5632 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5633 p
+= sizeof (Elf32_External_Rel
);
5640 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
5641 elf_section_data (htab
->plt_got
->output_section
)
5642 ->this_hdr
.sh_entsize
= non_lazy_plt_layout
->plt_entry_size
;
5644 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
5645 elf_section_data (htab
->plt_second
->output_section
)
5646 ->this_hdr
.sh_entsize
= non_lazy_plt_layout
->plt_entry_size
;
5649 /* Fill in the first three entries in the global offset table. */
5650 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
5652 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5655 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5659 bfd_put_32 (output_bfd
,
5661 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
5662 htab
->elf
.sgotplt
->contents
);
5663 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
5664 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
5666 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
5669 /* Adjust .eh_frame for .plt section. */
5670 if (htab
->plt_eh_frame
!= NULL
5671 && htab
->plt_eh_frame
->contents
!= NULL
)
5673 if (htab
->elf
.splt
!= NULL
5674 && htab
->elf
.splt
->size
!= 0
5675 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5676 && htab
->elf
.splt
->output_section
!= NULL
5677 && htab
->plt_eh_frame
->output_section
!= NULL
)
5679 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5680 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5681 + htab
->plt_eh_frame
->output_offset
5682 + PLT_FDE_START_OFFSET
;
5683 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5684 htab
->plt_eh_frame
->contents
5685 + PLT_FDE_START_OFFSET
);
5687 if (htab
->plt_eh_frame
->sec_info_type
5688 == SEC_INFO_TYPE_EH_FRAME
)
5690 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5692 htab
->plt_eh_frame
->contents
))
5697 /* Adjust .eh_frame for .plt.got section. */
5698 if (htab
->plt_got_eh_frame
!= NULL
5699 && htab
->plt_got_eh_frame
->contents
!= NULL
)
5701 if (htab
->plt_got
!= NULL
5702 && htab
->plt_got
->size
!= 0
5703 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
5704 && htab
->plt_got
->output_section
!= NULL
5705 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
5707 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
5708 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
5709 + htab
->plt_got_eh_frame
->output_offset
5710 + PLT_FDE_START_OFFSET
;
5711 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5712 htab
->plt_got_eh_frame
->contents
5713 + PLT_FDE_START_OFFSET
);
5715 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5717 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5718 htab
->plt_got_eh_frame
,
5719 htab
->plt_got_eh_frame
->contents
))
5724 /* Adjust .eh_frame for the second PLT section. */
5725 if (htab
->plt_second_eh_frame
!= NULL
5726 && htab
->plt_second_eh_frame
->contents
!= NULL
)
5728 if (htab
->plt_second
!= NULL
5729 && htab
->plt_second
->size
!= 0
5730 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
5731 && htab
->plt_second
->output_section
!= NULL
5732 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
5734 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
5735 bfd_vma eh_frame_start
5736 = (htab
->plt_second_eh_frame
->output_section
->vma
5737 + htab
->plt_second_eh_frame
->output_offset
5738 + PLT_FDE_START_OFFSET
);
5739 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5740 htab
->plt_second_eh_frame
->contents
5741 + PLT_FDE_START_OFFSET
);
5743 if (htab
->plt_second_eh_frame
->sec_info_type
5744 == SEC_INFO_TYPE_EH_FRAME
)
5746 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5747 htab
->plt_second_eh_frame
,
5748 htab
->plt_second_eh_frame
->contents
))
5753 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5754 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5756 /* Fill PLT entries for undefined weak symbols in PIE. */
5757 if (bfd_link_pie (info
))
5758 bfd_hash_traverse (&info
->hash
->table
,
5759 elf_i386_pie_finish_undefweak_symbol
,
5765 /* Fill PLT/GOT entries and allocate dynamic relocations for local
5766 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
5767 It has to be done before elf_link_sort_relocs is called so that
5768 dynamic relocations are properly sorted. */
5771 elf_i386_output_arch_local_syms
5772 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5773 struct bfd_link_info
*info
,
5774 void *flaginfo ATTRIBUTE_UNUSED
,
5775 int (*func
) (void *, const char *,
5778 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
5780 struct elf_x86_link_hash_table
*htab
5781 = elf_x86_hash_table (info
, I386_ELF_DATA
);
5785 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5786 htab_traverse (htab
->loc_hash_table
,
5787 elf_i386_finish_local_dynamic_symbol
,
5793 enum elf_i386_plt_type
5798 plt_second
= 1 << 2,
5807 enum elf_i386_plt_type type
;
5808 unsigned int plt_got_offset
;
5809 unsigned int plt_entry_size
;
5813 /* Forward declaration. */
5814 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
;
5816 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
5817 dynamic relocations. */
5820 elf_i386_get_synthetic_symtab (bfd
*abfd
,
5821 long symcount ATTRIBUTE_UNUSED
,
5822 asymbol
**syms ATTRIBUTE_UNUSED
,
5827 long size
, count
, i
, n
, len
;
5829 unsigned int plt_got_offset
, plt_entry_size
;
5831 bfd_byte
*plt_contents
;
5832 long dynrelcount
, relsize
;
5833 arelent
**dynrelbuf
, *p
;
5834 const struct elf_i386_lazy_plt_layout
*lazy_plt
;
5835 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt
;
5836 const struct elf_i386_lazy_plt_layout
*lazy_ibt_plt
;
5837 const struct elf_i386_non_lazy_plt_layout
*non_lazy_ibt_plt
;
5841 enum elf_i386_plt_type plt_type
;
5842 struct elf_i386_plt plts
[] =
5844 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0 },
5845 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0 },
5846 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0 },
5847 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0 }
5852 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
5855 if (dynsymcount
<= 0)
5858 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
5862 non_lazy_plt
= NULL
;
5863 /* Silence GCC 6. */
5865 non_lazy_ibt_plt
= NULL
;
5866 lazy_ibt_plt
= NULL
;
5867 switch (get_elf_i386_backend_data (abfd
)->os
)
5870 non_lazy_plt
= &elf_i386_non_lazy_plt
;
5871 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
5872 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
5875 lazy_plt
= &elf_i386_lazy_plt
;
5878 lazy_plt
= &elf_i386_nacl_plt
;
5885 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
5887 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
5888 if (plt
== NULL
|| plt
->size
== 0)
5891 /* Get the PLT section contents. */
5892 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
5893 if (plt_contents
== NULL
)
5895 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
5896 plt_contents
, 0, plt
->size
))
5898 free (plt_contents
);
5902 /* Check what kind of PLT it is. */
5903 plt_type
= plt_unknown
;
5904 if (plts
[j
].type
== plt_unknown
5905 && (plt
->size
>= (lazy_plt
->plt0_entry_size
5906 + lazy_plt
->plt_entry_size
)))
5908 /* Match lazy PLT first. */
5909 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
5910 lazy_plt
->plt0_got1_offset
) == 0)
5912 /* The fist entry in the lazy IBT PLT is the same as the
5914 if (lazy_ibt_plt
!= NULL
5915 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
5916 lazy_ibt_plt
->plt_entry
,
5917 lazy_ibt_plt
->plt_got_offset
) == 0))
5918 plt_type
= plt_lazy
| plt_second
;
5920 plt_type
= plt_lazy
;
5922 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
5923 lazy_plt
->plt0_got1_offset
) == 0)
5925 /* The fist entry in the PIC lazy IBT PLT is the same as
5926 the normal PIC lazy PLT. */
5927 if (lazy_ibt_plt
!= NULL
5928 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
5929 lazy_ibt_plt
->pic_plt_entry
,
5930 lazy_ibt_plt
->plt_got_offset
) == 0))
5931 plt_type
= plt_lazy
| plt_pic
| plt_second
;
5933 plt_type
= plt_lazy
| plt_pic
;
5937 if (non_lazy_plt
!= NULL
5938 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
5939 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
5941 /* Match non-lazy PLT. */
5942 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
5943 non_lazy_plt
->plt_got_offset
) == 0)
5944 plt_type
= plt_non_lazy
;
5945 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
5946 non_lazy_plt
->plt_got_offset
) == 0)
5950 if ((non_lazy_ibt_plt
!= NULL
)
5951 && (plt_type
== plt_unknown
|| plt_type
== plt_second
)
5952 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
)
5954 if (memcmp (plt_contents
,
5955 non_lazy_ibt_plt
->plt_entry
,
5956 non_lazy_ibt_plt
->plt_got_offset
) == 0)
5958 /* Match IBT PLT. */
5959 plt_type
= plt_second
;
5960 non_lazy_plt
= non_lazy_ibt_plt
;
5962 else if (memcmp (plt_contents
,
5963 non_lazy_ibt_plt
->pic_plt_entry
,
5964 non_lazy_ibt_plt
->plt_got_offset
) == 0)
5966 /* Match PIC IBT PLT. */
5967 plt_type
= plt_second
| plt_pic
;
5968 non_lazy_plt
= non_lazy_ibt_plt
;
5972 if (plt_type
== plt_unknown
)
5974 free (plt_contents
);
5979 plts
[j
].type
= plt_type
;
5981 if ((plt_type
& plt_lazy
))
5983 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
5984 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
5985 /* Skip PLT0 in lazy PLT. */
5990 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
5991 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
5995 /* Skip lazy PLT when the second PLT is used. */
5996 if ((plt_type
& (plt_lazy
| plt_second
))
5997 == (plt_lazy
| plt_second
))
6001 n
= plt
->size
/ plts
[j
].plt_entry_size
;
6006 plts
[j
].contents
= plt_contents
;
6008 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
6009 if ((plt_type
& plt_pic
))
6010 got_addr
= (bfd_vma
) -1;
6016 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
6017 if (dynrelbuf
== NULL
)
6020 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
6023 /* Sort the relocs by address. */
6024 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*),
6025 _bfd_x86_elf_compare_relocs
);
6027 size
= count
* sizeof (asymbol
);
6029 /* Allocate space for @plt suffixes. */
6031 for (i
= 0; i
< dynrelcount
; i
++)
6034 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
6036 size
+= sizeof ("+0x") - 1 + 8;
6039 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
6045 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
6047 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
6049 got_addr
= sec
->vma
;
6052 sec
= bfd_get_section_by_name (abfd
, ".got");
6054 got_addr
= sec
->vma
;
6057 if (got_addr
== (bfd_vma
) -1)
6061 /* Check for each PLT section. */
6062 names
= (char *) (s
+ count
);
6065 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6066 if ((plt_contents
= plts
[j
].contents
) != NULL
)
6071 plt_got_offset
= plts
[j
].plt_got_offset
;
6072 plt_entry_size
= plts
[j
].plt_entry_size
;
6076 if ((plts
[j
].type
& plt_lazy
))
6078 /* Skip PLT0 in lazy PLT. */
6080 offset
= plt_entry_size
;
6088 /* Check each PLT entry against dynamic relocations. */
6089 for (; k
< plts
[j
].count
; k
++)
6095 /* Get the GOT offset, a signed 32-bit integer. */
6096 off
= H_GET_32 (abfd
, (plt_contents
+ offset
6098 got_vma
= got_addr
+ off
;
6100 /* Binary search. */
6104 while ((min
+ 1) < max
)
6108 mid
= (min
+ max
) / 2;
6110 if (got_vma
> r
->address
)
6112 else if (got_vma
< r
->address
)
6121 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6122 if (got_vma
== p
->address
6124 && (p
->howto
->type
== R_386_JUMP_SLOT
6125 || p
->howto
->type
== R_386_GLOB_DAT
6126 || p
->howto
->type
== R_386_IRELATIVE
))
6128 *s
= **p
->sym_ptr_ptr
;
6129 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6130 set. Since we are defining a symbol, ensure one
6132 if ((s
->flags
& BSF_LOCAL
) == 0)
6133 s
->flags
|= BSF_GLOBAL
;
6134 s
->flags
|= BSF_SYNTHETIC
;
6135 /* This is no longer a section symbol. */
6136 s
->flags
&= ~BSF_SECTION_SYM
;
6138 s
->the_bfd
= plt
->owner
;
6142 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
6143 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
6149 memcpy (names
, "+0x", sizeof ("+0x") - 1);
6150 names
+= sizeof ("+0x") - 1;
6151 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
6152 for (a
= buf
; *a
== '0'; ++a
)
6155 memcpy (names
, a
, size
);
6158 memcpy (names
, "@plt", sizeof ("@plt"));
6159 names
+= sizeof ("@plt");
6163 offset
+= plt_entry_size
;
6167 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
6176 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6177 if (plts
[j
].contents
!= NULL
)
6178 free (plts
[j
].contents
);
6185 /* Set up i386 GNU properties. Return the first relocatable ELF input
6186 with GNU properties if found. Otherwise, return NULL. */
6189 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
6191 bfd_boolean normal_target
;
6192 bfd_boolean lazy_plt
;
6193 asection
*sec
, *pltsec
;
6195 bfd_boolean use_ibt_plt
;
6196 unsigned int plt_alignment
, features
;
6197 struct elf_x86_link_hash_table
*htab
;
6201 struct elf_i386_plt_layout
*plt_layout
;
6202 const struct elf_i386_lazy_plt_layout
*lazy_plt_layout
;
6203 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt_layout
;
6207 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6209 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
6211 /* Find a normal input file with GNU property note. */
6212 for (pbfd
= info
->input_bfds
;
6214 pbfd
= pbfd
->link
.next
)
6215 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
6216 && bfd_count_sections (pbfd
) != 0)
6220 if (elf_properties (pbfd
) != NULL
)
6224 if (ebfd
!= NULL
&& features
)
6226 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
6227 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6228 prop
= _bfd_elf_get_property (ebfd
,
6229 GNU_PROPERTY_X86_FEATURE_1_AND
,
6231 prop
->u
.number
|= features
;
6232 prop
->pr_kind
= property_number
;
6234 /* Create the GNU property note section if needed. */
6237 sec
= bfd_make_section_with_flags (ebfd
,
6238 NOTE_GNU_PROPERTY_SECTION_NAME
,
6246 info
->callbacks
->einfo (_("%F: failed to create GNU property section\n"));
6248 if (!bfd_set_section_alignment (ebfd
, sec
, 2))
6251 info
->callbacks
->einfo (_("%F%A: failed to align section\n"),
6255 elf_section_type (sec
) = SHT_NOTE
;
6259 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
6261 if (bfd_link_relocatable (info
))
6264 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
6268 use_ibt_plt
= info
->ibtplt
|| info
->ibt
;
6269 if (!use_ibt_plt
&& pbfd
!= NULL
)
6271 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
6272 elf_property_list
*p
;
6274 /* The property list is sorted in order of type. */
6275 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
6277 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
6279 use_ibt_plt
= !!(p
->property
.u
.number
6280 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
6283 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
6288 dynobj
= htab
->elf
.dynobj
;
6290 /* Set htab->elf.dynobj here so that there is no need to check and
6291 set it in check_relocs. */
6296 htab
->elf
.dynobj
= pbfd
;
6303 /* Find a normal input file to hold linker created
6305 for (abfd
= info
->input_bfds
;
6307 abfd
= abfd
->link
.next
)
6308 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
6310 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0)
6312 htab
->elf
.dynobj
= abfd
;
6319 plt_layout
= &elf_i386_plt (htab
);
6321 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
6322 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
6323 canonical function address. */
6324 plt_layout
->has_plt0
= 1;
6325 normal_target
= FALSE
;
6327 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
6332 elf_i386_lazy_plt (htab
) = &elf_i386_lazy_ibt_plt
;
6333 elf_i386_non_lazy_plt (htab
) = &elf_i386_non_lazy_ibt_plt
;
6337 elf_i386_lazy_plt (htab
) = &elf_i386_lazy_plt
;
6338 elf_i386_non_lazy_plt (htab
) = &elf_i386_non_lazy_plt
;
6340 normal_target
= TRUE
;
6343 elf_i386_lazy_plt (htab
) = &elf_i386_lazy_plt
;
6344 elf_i386_non_lazy_plt (htab
) = NULL
;
6345 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
,
6346 &elf_i386_srelplt2 (htab
)))
6347 info
->callbacks
->einfo (_("%F: failed to create VxWorks dynamic sections\n"));
6350 elf_i386_lazy_plt (htab
) = &elf_i386_nacl_plt
;
6351 elf_i386_non_lazy_plt (htab
) = NULL
;
6355 lazy_plt_layout
= elf_i386_lazy_plt (htab
);
6356 non_lazy_plt_layout
= elf_i386_non_lazy_plt (htab
);
6358 pltsec
= htab
->elf
.splt
;
6360 /* If the non-lazy PLT is available, use it for all PLT entries if
6361 there are no PLT0 or no .plt section. */
6362 if (non_lazy_plt_layout
!= NULL
6363 && (!plt_layout
->has_plt0
|| pltsec
== NULL
))
6366 if (bfd_link_pic (info
))
6367 plt_layout
->plt_entry
6368 = non_lazy_plt_layout
->pic_plt_entry
;
6370 plt_layout
->plt_entry
6371 = non_lazy_plt_layout
->plt_entry
;
6372 plt_layout
->plt_entry_size
6373 = non_lazy_plt_layout
->plt_entry_size
;
6374 plt_layout
->plt_got_offset
6375 = non_lazy_plt_layout
->plt_got_offset
;
6376 plt_layout
->eh_frame_plt_size
6377 = non_lazy_plt_layout
->eh_frame_plt_size
;
6378 plt_layout
->eh_frame_plt
6379 = non_lazy_plt_layout
->eh_frame_plt
;
6384 if (bfd_link_pic (info
))
6386 plt_layout
->plt0_entry
6387 = lazy_plt_layout
->pic_plt0_entry
;
6388 plt_layout
->plt_entry
6389 = lazy_plt_layout
->pic_plt_entry
;
6393 plt_layout
->plt0_entry
6394 = lazy_plt_layout
->plt0_entry
;
6395 plt_layout
->plt_entry
6396 = lazy_plt_layout
->plt_entry
;
6398 plt_layout
->plt_entry_size
6399 = lazy_plt_layout
->plt_entry_size
;
6400 plt_layout
->plt_got_offset
6401 = lazy_plt_layout
->plt_got_offset
;
6402 plt_layout
->eh_frame_plt_size
6403 = lazy_plt_layout
->eh_frame_plt_size
;
6404 plt_layout
->eh_frame_plt
6405 = lazy_plt_layout
->eh_frame_plt
;
6408 /* Return if there are no normal input files. */
6412 /* Since create_dynamic_sections isn't always called, but GOT
6413 relocations need GOT sections, create them here so that we
6414 don't need to do it in check_relocs. */
6415 if (htab
->elf
.sgot
== NULL
6416 && !_bfd_elf_create_got_section (dynobj
, info
))
6417 info
->callbacks
->einfo (_("%F: failed to create GOT sections\n"));
6419 /* Create the ifunc sections here so that check_relocs can be
6421 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
6422 info
->callbacks
->einfo (_("%F: failed to create ifunc sections\n"));
6424 plt_alignment
= bfd_log2 (plt_layout
->plt_entry_size
);
6428 /* Whe creating executable, set the contents of the .interp
6429 section to the interpreter. */
6430 if (bfd_link_executable (info
) && !info
->nointerp
)
6432 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
6435 s
->size
= htab
->dynamic_interpreter_size
;
6436 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
6440 /* Don't change PLT section alignment for NaCl since it uses
6441 64-byte PLT entry and sets PLT section alignment to 32
6445 const struct elf_backend_data
*bed
6446 = get_elf_backend_data (dynobj
);
6447 flagword pltflags
= (bed
->dynamic_sec_flags
6452 unsigned int non_lazy_plt_alignment
6453 = bfd_log2 (non_lazy_plt_layout
->plt_entry_size
);
6456 if (!bfd_set_section_alignment (sec
->owner
, sec
,
6458 goto error_alignment
;
6460 /* Create the GOT procedure linkage table. */
6461 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6465 info
->callbacks
->einfo (_("%F: failed to create GOT PLT section\n"));
6467 if (!bfd_set_section_alignment (dynobj
, sec
,
6468 non_lazy_plt_alignment
))
6469 goto error_alignment
;
6471 htab
->plt_got
= sec
;
6479 /* Create the second PLT for Intel IBT support. IBT
6480 PLT is supported only for non-NaCl target and is
6481 is needed only for lazy binding. */
6482 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6486 info
->callbacks
->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
6488 if (!bfd_set_section_alignment (dynobj
, sec
,
6490 goto error_alignment
;
6493 htab
->plt_second
= sec
;
6497 if (!info
->no_ld_generated_unwind_info
)
6499 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
6500 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6501 | SEC_LINKER_CREATED
);
6503 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6507 info
->callbacks
->einfo (_("%F: failed to create PLT .eh_frame section\n"));
6509 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
6510 goto error_alignment
;
6512 htab
->plt_eh_frame
= sec
;
6514 if (htab
->plt_got
!= NULL
)
6516 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6520 info
->callbacks
->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
6522 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
6523 goto error_alignment
;
6525 htab
->plt_got_eh_frame
= sec
;
6532 /* The .iplt section is used for IFUNC symbols in static
6534 sec
= htab
->elf
.iplt
;
6536 && !bfd_set_section_alignment (sec
->owner
, sec
,
6538 goto error_alignment
;
6544 #define TARGET_LITTLE_SYM i386_elf32_vec
6545 #define TARGET_LITTLE_NAME "elf32-i386"
6546 #define ELF_ARCH bfd_arch_i386
6547 #define ELF_TARGET_ID I386_ELF_DATA
6548 #define ELF_MACHINE_CODE EM_386
6549 #define ELF_MAXPAGESIZE 0x1000
6551 #define elf_backend_can_gc_sections 1
6552 #define elf_backend_can_refcount 1
6553 #define elf_backend_want_got_plt 1
6554 #define elf_backend_plt_readonly 1
6555 #define elf_backend_want_plt_sym 0
6556 #define elf_backend_got_header_size 12
6557 #define elf_backend_plt_alignment 4
6558 #define elf_backend_dtrel_excludes_plt 1
6559 #define elf_backend_extern_protected_data 1
6560 #define elf_backend_caches_rawsize 1
6561 #define elf_backend_want_dynrelro 1
6563 /* Support RELA for objdump of prelink objects. */
6564 #define elf_info_to_howto elf_i386_info_to_howto_rel
6565 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
6567 #define bfd_elf32_mkobject elf_i386_mkobject
6569 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
6570 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
6571 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
6572 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
6573 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
6575 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
6576 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
6577 #define elf_backend_check_relocs elf_i386_check_relocs
6578 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
6579 #define elf_backend_fake_sections elf_i386_fake_sections
6580 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
6581 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
6582 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
6583 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
6584 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
6585 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
6586 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
6587 #define elf_backend_relocate_section elf_i386_relocate_section
6588 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
6589 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
6591 #include "elf32-target.h"
6593 /* FreeBSD support. */
6595 #undef TARGET_LITTLE_SYM
6596 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
6597 #undef TARGET_LITTLE_NAME
6598 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
6600 #define ELF_OSABI ELFOSABI_FREEBSD
6602 /* The kernel recognizes executables as valid only if they carry a
6603 "FreeBSD" label in the ELF header. So we put this label on all
6604 executables and (for simplicity) also all other object files. */
6607 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
6609 _bfd_elf_post_process_headers (abfd
, info
);
6611 #ifdef OLD_FREEBSD_ABI_LABEL
6613 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
6614 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
6615 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
6620 #undef elf_backend_post_process_headers
6621 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
6623 #define elf32_bed elf32_i386_fbsd_bed
6625 #undef elf_backend_add_symbol_hook
6627 #include "elf32-target.h"
6631 #undef TARGET_LITTLE_SYM
6632 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
6633 #undef TARGET_LITTLE_NAME
6634 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
6636 #undef elf_backend_post_process_headers
6638 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
6639 objects won't be recognized. */
6643 #define elf32_bed elf32_i386_sol2_bed
6645 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
6647 #undef elf_backend_static_tls_alignment
6648 #define elf_backend_static_tls_alignment 8
6650 /* The Solaris 2 ABI requires a plt symbol on all platforms.
6652 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
6654 #undef elf_backend_want_plt_sym
6655 #define elf_backend_want_plt_sym 1
6657 #undef elf_backend_strtab_flags
6658 #define elf_backend_strtab_flags SHF_STRINGS
6660 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
6661 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
6662 FALSE otherwise. ISECTION is the best guess matching section from the
6663 input bfd IBFD, but it might be NULL. */
6666 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
6667 bfd
*obfd ATTRIBUTE_UNUSED
,
6668 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
6669 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
6671 /* PR 19938: FIXME: Need to add code for setting the sh_info
6672 and sh_link fields of Solaris specific section types. */
6675 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
6676 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
6678 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
6680 The following values should be set:
6683 -----------------------------------------------------------------------------
6684 SHT_SUNW_ancillary The section header index of 0
6685 [0x6fffffee] the associated string table.
6687 SHT_SUNW_capinfo The section header index of For a dynamic object, the
6688 [0x6ffffff0] the associated symbol table. section header index of
6690 SHT_SUNW_capchain table,
6693 SHT_SUNW_symsort The section header index of 0
6694 [0x6ffffff1] the associated symbol table.
6696 SHT_SUNW_tlssort The section header index of 0
6697 [0x6ffffff2] the associated symbol table.
6699 SHT_SUNW_LDYNSYM The section header index of One greater than the
6700 [0x6ffffff3] the associated string table. symbol table index of the
6701 This index is the same string last local symbol,
6702 table used by the SHT_DYNSYM STB_LOCAL. Since
6703 section. SHT_SUNW_LDYNSYM only
6704 contains local symbols,
6705 sh_info is equivalent to
6706 the number of symbols in
6709 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
6710 [0x6ffffff5] the section header index of to named strings, the
6711 the associated section header index of
6712 SHT_SUNW_capinfo table, the associated string
6713 otherwise 0. table, otherwise 0.
6715 SHT_SUNW_move The section header index of 0
6716 [0x6ffffffa] the associated symbol table.
6721 SHT_SUNW_syminfo The section header index of The section header index
6722 [0x6ffffffc] the associated symbol table. of the associated
6725 SHT_SUNW_verdef The section header index of The number of version
6726 [0x6ffffffd] the associated string table. definitions within the
6729 SHT_SUNW_verneed The section header index of The number of version
6730 [0x6ffffffe] the associated string table. dependencies within the
6733 SHT_SUNW_versym The section header index of 0
6734 [0x6fffffff] the associated symbol table. */
6737 #undef elf_backend_copy_special_section_fields
6738 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
6740 #include "elf32-target.h"
6742 /* Intel MCU support. */
6745 elf32_iamcu_elf_object_p (bfd
*abfd
)
6747 /* Set the right machine number for an IAMCU elf32 file. */
6748 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
6752 #undef TARGET_LITTLE_SYM
6753 #define TARGET_LITTLE_SYM iamcu_elf32_vec
6754 #undef TARGET_LITTLE_NAME
6755 #define TARGET_LITTLE_NAME "elf32-iamcu"
6757 #define ELF_ARCH bfd_arch_iamcu
6759 #undef ELF_MACHINE_CODE
6760 #define ELF_MACHINE_CODE EM_IAMCU
6765 #define elf32_bed elf32_iamcu_bed
6767 #undef elf_backend_object_p
6768 #define elf_backend_object_p elf32_iamcu_elf_object_p
6770 #undef elf_backend_static_tls_alignment
6772 #undef elf_backend_want_plt_sym
6773 #define elf_backend_want_plt_sym 0
6775 #undef elf_backend_strtab_flags
6776 #undef elf_backend_copy_special_section_fields
6778 #include "elf32-target.h"
6780 /* Restore defaults. */
6782 #define ELF_ARCH bfd_arch_i386
6783 #undef ELF_MACHINE_CODE
6784 #define ELF_MACHINE_CODE EM_386
6786 /* Native Client support. */
6788 #undef TARGET_LITTLE_SYM
6789 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
6790 #undef TARGET_LITTLE_NAME
6791 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
6793 #define elf32_bed elf32_i386_nacl_bed
6795 #undef ELF_MAXPAGESIZE
6796 #define ELF_MAXPAGESIZE 0x10000
6798 /* Restore defaults. */
6800 #undef elf_backend_want_plt_sym
6801 #define elf_backend_want_plt_sym 0
6802 #undef elf_backend_post_process_headers
6803 #undef elf_backend_static_tls_alignment
6805 /* NaCl uses substantially different PLT entries for the same effects. */
6807 #undef elf_backend_plt_alignment
6808 #define elf_backend_plt_alignment 5
6809 #define NACL_PLT_ENTRY_SIZE 64
6810 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
6812 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
6814 0xff, 0x35, /* pushl contents of address */
6815 0, 0, 0, 0, /* replaced with address of .got + 4. */
6816 0x8b, 0x0d, /* movl contents of address, %ecx */
6817 0, 0, 0, 0, /* replaced with address of .got + 8. */
6818 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6819 0xff, 0xe1 /* jmp *%ecx */
6822 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6824 0x8b, 0x0d, /* movl contents of address, %ecx */
6825 0, 0, 0, 0, /* replaced with GOT slot address. */
6826 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6827 0xff, 0xe1, /* jmp *%ecx */
6829 /* Pad to the next 32-byte boundary with nop instructions. */
6831 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6832 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6834 /* Lazy GOT entries point here (32-byte aligned). */
6835 0x68, /* pushl immediate */
6836 0, 0, 0, 0, /* replaced with reloc offset. */
6837 0xe9, /* jmp relative */
6838 0, 0, 0, 0, /* replaced with offset to .plt. */
6840 /* Pad to the next 32-byte boundary with nop instructions. */
6841 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6842 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6846 static const bfd_byte
6847 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
6849 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
6850 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
6851 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
6852 0xff, 0xe1, /* jmp *%ecx */
6854 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
6855 so pad to that size with nop instructions. */
6856 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
6859 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6861 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
6862 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
6863 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
6864 0xff, 0xe1, /* jmp *%ecx */
6866 /* Pad to the next 32-byte boundary with nop instructions. */
6868 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6869 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6871 /* Lazy GOT entries point here (32-byte aligned). */
6872 0x68, /* pushl immediate */
6873 0, 0, 0, 0, /* replaced with offset into relocation table. */
6874 0xe9, /* jmp relative */
6875 0, 0, 0, 0, /* replaced with offset to start of .plt. */
6877 /* Pad to the next 32-byte boundary with nop instructions. */
6878 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6879 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6883 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
6885 #if (PLT_CIE_LENGTH != 20 \
6886 || PLT_FDE_LENGTH != 36 \
6887 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
6888 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
6889 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
6891 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
6892 0, 0, 0, 0, /* CIE ID */
6893 1, /* CIE version */
6894 'z', 'R', 0, /* Augmentation string */
6895 1, /* Code alignment factor */
6896 0x7c, /* Data alignment factor: -4 */
6897 8, /* Return address column */
6898 1, /* Augmentation size */
6899 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
6900 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
6901 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
6902 DW_CFA_nop
, DW_CFA_nop
,
6904 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
6905 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
6906 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
6907 0, 0, 0, 0, /* .plt size goes here */
6908 0, /* Augmentation size */
6909 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
6910 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
6911 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
6912 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
6913 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
6914 13, /* Block length */
6915 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
6916 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
6917 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
6918 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
6919 DW_CFA_nop
, DW_CFA_nop
6922 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
=
6924 elf_i386_nacl_plt0_entry
, /* plt0_entry */
6925 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
6926 2, /* plt0_got1_offset */
6927 8, /* plt0_got2_offset */
6928 elf_i386_nacl_plt_entry
, /* plt_entry */
6929 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
6930 2, /* plt_got_offset */
6931 33, /* plt_reloc_offset */
6932 38, /* plt_plt_offset */
6933 32, /* plt_lazy_offset */
6934 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
6935 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
6936 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
6937 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
6940 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
6942 0x90, /* plt0_pad_byte: nop insn */
6947 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
6949 /* Set the right machine number for a NaCl i386 ELF32 file. */
6950 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
6954 #undef elf_backend_arch_data
6955 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
6957 #undef elf_backend_object_p
6958 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
6959 #undef elf_backend_modify_segment_map
6960 #define elf_backend_modify_segment_map nacl_modify_segment_map
6961 #undef elf_backend_modify_program_headers
6962 #define elf_backend_modify_program_headers nacl_modify_program_headers
6963 #undef elf_backend_final_write_processing
6964 #define elf_backend_final_write_processing nacl_final_write_processing
6966 #include "elf32-target.h"
6968 /* Restore defaults. */
6969 #undef elf_backend_object_p
6970 #undef elf_backend_modify_segment_map
6971 #undef elf_backend_modify_program_headers
6972 #undef elf_backend_final_write_processing
6974 /* VxWorks support. */
6976 #undef TARGET_LITTLE_SYM
6977 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
6978 #undef TARGET_LITTLE_NAME
6979 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
6981 #undef ELF_MAXPAGESIZE
6982 #define ELF_MAXPAGESIZE 0x1000
6983 #undef elf_backend_plt_alignment
6984 #define elf_backend_plt_alignment 4
6986 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
6988 0x90, /* plt0_pad_byte */
6992 #undef elf_backend_arch_data
6993 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
6995 #undef elf_backend_relocs_compatible
6996 #undef elf_backend_add_symbol_hook
6997 #define elf_backend_add_symbol_hook \
6998 elf_vxworks_add_symbol_hook
6999 #undef elf_backend_link_output_symbol_hook
7000 #define elf_backend_link_output_symbol_hook \
7001 elf_vxworks_link_output_symbol_hook
7002 #undef elf_backend_emit_relocs
7003 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7004 #undef elf_backend_final_write_processing
7005 #define elf_backend_final_write_processing \
7006 elf_vxworks_final_write_processing
7007 #undef elf_backend_static_tls_alignment
7009 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
7011 #undef elf_backend_want_plt_sym
7012 #define elf_backend_want_plt_sym 1
7015 #define elf32_bed elf32_i386_vxworks_bed
7017 #include "elf32-target.h"