1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
28 #include "bfd_stdint.h"
32 #include "opcode/i386.h"
34 /* 386 uses REL relocations instead of RELA. */
39 static reloc_howto_type elf_howto_table
[]=
41 HOWTO(R_386_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
42 bfd_elf_generic_reloc
, "R_386_NONE",
43 TRUE
, 0x00000000, 0x00000000, FALSE
),
44 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
45 bfd_elf_generic_reloc
, "R_386_32",
46 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
47 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
48 bfd_elf_generic_reloc
, "R_386_PC32",
49 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
50 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
51 bfd_elf_generic_reloc
, "R_386_GOT32",
52 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
53 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
54 bfd_elf_generic_reloc
, "R_386_PLT32",
55 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
56 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
57 bfd_elf_generic_reloc
, "R_386_COPY",
58 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
59 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
60 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
61 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
62 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
64 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
65 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
66 bfd_elf_generic_reloc
, "R_386_RELATIVE",
67 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
68 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
69 bfd_elf_generic_reloc
, "R_386_GOTOFF",
70 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
71 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
72 bfd_elf_generic_reloc
, "R_386_GOTPC",
73 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
75 /* We have a gap in the reloc numbers here.
76 R_386_standard counts the number up to this point, and
77 R_386_ext_offset is the value to subtract from a reloc type of
78 R_386_16 thru R_386_PC8 to form an index into this table. */
79 #define R_386_standard (R_386_GOTPC + 1)
80 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
82 /* These relocs are a GNU extension. */
83 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
84 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
85 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
86 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_386_TLS_IE",
88 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
89 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
90 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
91 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
92 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_386_TLS_LE",
94 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
95 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_386_TLS_GD",
97 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
98 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
100 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
101 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
102 bfd_elf_generic_reloc
, "R_386_16",
103 TRUE
, 0xffff, 0xffff, FALSE
),
104 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
105 bfd_elf_generic_reloc
, "R_386_PC16",
106 TRUE
, 0xffff, 0xffff, TRUE
),
107 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
108 bfd_elf_generic_reloc
, "R_386_8",
109 TRUE
, 0xff, 0xff, FALSE
),
110 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
111 bfd_elf_generic_reloc
, "R_386_PC8",
112 TRUE
, 0xff, 0xff, TRUE
),
114 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
115 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
116 /* These are common with Solaris TLS implementation. */
117 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
118 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
119 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
120 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
121 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
122 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
123 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
124 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
125 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
126 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
128 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
129 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
131 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
132 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
133 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
134 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
135 HOWTO(R_386_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
136 bfd_elf_generic_reloc
, "R_386_SIZE32",
137 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
138 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
139 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
140 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
141 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
142 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
144 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
145 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
146 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
147 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
148 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
149 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
150 HOWTO(R_386_GOT32X
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
151 bfd_elf_generic_reloc
, "R_386_GOT32X",
152 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
155 #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
156 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
158 /* GNU extension to record C++ vtable hierarchy. */
159 HOWTO (R_386_GNU_VTINHERIT
, /* type */
161 2, /* size (0 = byte, 1 = short, 2 = long) */
163 FALSE
, /* pc_relative */
165 complain_overflow_dont
, /* complain_on_overflow */
166 NULL
, /* special_function */
167 "R_386_GNU_VTINHERIT", /* name */
168 FALSE
, /* partial_inplace */
171 FALSE
), /* pcrel_offset */
173 /* GNU extension to record C++ vtable member usage. */
174 HOWTO (R_386_GNU_VTENTRY
, /* type */
176 2, /* size (0 = byte, 1 = short, 2 = long) */
178 FALSE
, /* pc_relative */
180 complain_overflow_dont
, /* complain_on_overflow */
181 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
182 "R_386_GNU_VTENTRY", /* name */
183 FALSE
, /* partial_inplace */
186 FALSE
) /* pcrel_offset */
188 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
192 #ifdef DEBUG_GEN_RELOC
194 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
199 static reloc_howto_type
*
200 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
201 bfd_reloc_code_real_type code
)
206 TRACE ("BFD_RELOC_NONE");
207 return &elf_howto_table
[R_386_NONE
];
210 TRACE ("BFD_RELOC_32");
211 return &elf_howto_table
[R_386_32
];
214 TRACE ("BFD_RELOC_CTOR");
215 return &elf_howto_table
[R_386_32
];
217 case BFD_RELOC_32_PCREL
:
218 TRACE ("BFD_RELOC_PC32");
219 return &elf_howto_table
[R_386_PC32
];
221 case BFD_RELOC_386_GOT32
:
222 TRACE ("BFD_RELOC_386_GOT32");
223 return &elf_howto_table
[R_386_GOT32
];
225 case BFD_RELOC_386_PLT32
:
226 TRACE ("BFD_RELOC_386_PLT32");
227 return &elf_howto_table
[R_386_PLT32
];
229 case BFD_RELOC_386_COPY
:
230 TRACE ("BFD_RELOC_386_COPY");
231 return &elf_howto_table
[R_386_COPY
];
233 case BFD_RELOC_386_GLOB_DAT
:
234 TRACE ("BFD_RELOC_386_GLOB_DAT");
235 return &elf_howto_table
[R_386_GLOB_DAT
];
237 case BFD_RELOC_386_JUMP_SLOT
:
238 TRACE ("BFD_RELOC_386_JUMP_SLOT");
239 return &elf_howto_table
[R_386_JUMP_SLOT
];
241 case BFD_RELOC_386_RELATIVE
:
242 TRACE ("BFD_RELOC_386_RELATIVE");
243 return &elf_howto_table
[R_386_RELATIVE
];
245 case BFD_RELOC_386_GOTOFF
:
246 TRACE ("BFD_RELOC_386_GOTOFF");
247 return &elf_howto_table
[R_386_GOTOFF
];
249 case BFD_RELOC_386_GOTPC
:
250 TRACE ("BFD_RELOC_386_GOTPC");
251 return &elf_howto_table
[R_386_GOTPC
];
253 /* These relocs are a GNU extension. */
254 case BFD_RELOC_386_TLS_TPOFF
:
255 TRACE ("BFD_RELOC_386_TLS_TPOFF");
256 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
258 case BFD_RELOC_386_TLS_IE
:
259 TRACE ("BFD_RELOC_386_TLS_IE");
260 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
262 case BFD_RELOC_386_TLS_GOTIE
:
263 TRACE ("BFD_RELOC_386_TLS_GOTIE");
264 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
266 case BFD_RELOC_386_TLS_LE
:
267 TRACE ("BFD_RELOC_386_TLS_LE");
268 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
270 case BFD_RELOC_386_TLS_GD
:
271 TRACE ("BFD_RELOC_386_TLS_GD");
272 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
274 case BFD_RELOC_386_TLS_LDM
:
275 TRACE ("BFD_RELOC_386_TLS_LDM");
276 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
279 TRACE ("BFD_RELOC_16");
280 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
282 case BFD_RELOC_16_PCREL
:
283 TRACE ("BFD_RELOC_16_PCREL");
284 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
287 TRACE ("BFD_RELOC_8");
288 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
290 case BFD_RELOC_8_PCREL
:
291 TRACE ("BFD_RELOC_8_PCREL");
292 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
294 /* Common with Sun TLS implementation. */
295 case BFD_RELOC_386_TLS_LDO_32
:
296 TRACE ("BFD_RELOC_386_TLS_LDO_32");
297 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
299 case BFD_RELOC_386_TLS_IE_32
:
300 TRACE ("BFD_RELOC_386_TLS_IE_32");
301 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
303 case BFD_RELOC_386_TLS_LE_32
:
304 TRACE ("BFD_RELOC_386_TLS_LE_32");
305 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
307 case BFD_RELOC_386_TLS_DTPMOD32
:
308 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
309 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
311 case BFD_RELOC_386_TLS_DTPOFF32
:
312 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
313 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
315 case BFD_RELOC_386_TLS_TPOFF32
:
316 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
317 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
319 case BFD_RELOC_SIZE32
:
320 TRACE ("BFD_RELOC_SIZE32");
321 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
323 case BFD_RELOC_386_TLS_GOTDESC
:
324 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
325 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
327 case BFD_RELOC_386_TLS_DESC_CALL
:
328 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
329 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
331 case BFD_RELOC_386_TLS_DESC
:
332 TRACE ("BFD_RELOC_386_TLS_DESC");
333 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
335 case BFD_RELOC_386_IRELATIVE
:
336 TRACE ("BFD_RELOC_386_IRELATIVE");
337 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
339 case BFD_RELOC_386_GOT32X
:
340 TRACE ("BFD_RELOC_386_GOT32X");
341 return &elf_howto_table
[R_386_GOT32X
- R_386_tls_offset
];
343 case BFD_RELOC_VTABLE_INHERIT
:
344 TRACE ("BFD_RELOC_VTABLE_INHERIT");
345 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
347 case BFD_RELOC_VTABLE_ENTRY
:
348 TRACE ("BFD_RELOC_VTABLE_ENTRY");
349 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
359 static reloc_howto_type
*
360 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
365 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
366 if (elf_howto_table
[i
].name
!= NULL
367 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
368 return &elf_howto_table
[i
];
373 static reloc_howto_type
*
374 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
378 if ((indx
= r_type
) >= R_386_standard
379 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
380 >= R_386_ext
- R_386_standard
)
381 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
382 >= R_386_ext2
- R_386_ext
)
383 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
384 >= R_386_vt
- R_386_ext2
))
386 /* xgettext:c-format */
387 _bfd_error_handler (_("%B: invalid relocation type %d"),
391 /* PR 17512: file: 0f67f69d. */
392 if (elf_howto_table
[indx
].type
!= r_type
)
394 return &elf_howto_table
[indx
];
398 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
400 Elf_Internal_Rela
*dst
)
402 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
403 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
406 /* Return whether a symbol name implies a local label. The UnixWare
407 2.1 cc generates temporary symbols that start with .X, so we
408 recognize them here. FIXME: do other SVR4 compilers also use .X?.
409 If so, we should move the .X recognition into
410 _bfd_elf_is_local_label_name. */
413 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
415 if (name
[0] == '.' && name
[1] == 'X')
418 return _bfd_elf_is_local_label_name (abfd
, name
);
421 /* Support for core dump NOTE sections. */
424 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
429 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
431 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
437 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
440 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
444 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
448 switch (note
->descsz
)
453 case 144: /* Linux/i386 */
455 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
458 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
468 /* Make a ".reg/999" section. */
469 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
470 size
, note
->descpos
+ offset
);
474 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
476 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
478 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
483 elf_tdata (abfd
)->core
->program
484 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
485 elf_tdata (abfd
)->core
->command
486 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
490 switch (note
->descsz
)
495 case 124: /* Linux/i386 elf_prpsinfo. */
496 elf_tdata (abfd
)->core
->pid
497 = bfd_get_32 (abfd
, note
->descdata
+ 12);
498 elf_tdata (abfd
)->core
->program
499 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
500 elf_tdata (abfd
)->core
->command
501 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
505 /* Note that for some reason, a spurious space is tacked
506 onto the end of the args in some (at least one anyway)
507 implementations, so strip it off if it exists. */
509 char *command
= elf_tdata (abfd
)->core
->command
;
510 int n
= strlen (command
);
512 if (0 < n
&& command
[n
- 1] == ' ')
513 command
[n
- 1] = '\0';
519 /* Functions for the i386 ELF linker.
521 In order to gain some understanding of code in this file without
522 knowing all the intricate details of the linker, note the
525 Functions named elf_i386_* are called by external routines, other
526 functions are only called locally. elf_i386_* functions appear
527 in this file more or less in the order in which they are called
528 from external routines. eg. elf_i386_check_relocs is called
529 early in the link process, elf_i386_finish_dynamic_sections is
530 one of the last functions. */
533 /* The name of the dynamic interpreter. This is put in the .interp
536 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
538 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
539 copying dynamic variables from a shared lib into an app's dynbss
540 section, and instead use a dynamic relocation to point into the
542 #define ELIMINATE_COPY_RELOCS 1
544 /* The size in bytes of an entry in the lazy procedure linkage table. */
546 #define LAZY_PLT_ENTRY_SIZE 16
548 /* The size in bytes of an entry in the non-lazy procedure linkage
551 #define NON_LAZY_PLT_ENTRY_SIZE 8
553 /* The first entry in an absolute lazy procedure linkage table looks
554 like this. See the SVR4 ABI i386 supplement to see how this works.
555 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
557 static const bfd_byte elf_i386_lazy_plt0_entry
[12] =
559 0xff, 0x35, /* pushl contents of address */
560 0, 0, 0, 0, /* replaced with address of .got + 4. */
561 0xff, 0x25, /* jmp indirect */
562 0, 0, 0, 0 /* replaced with address of .got + 8. */
565 /* Subsequent entries in an absolute lazy procedure linkage table look
568 static const bfd_byte elf_i386_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
570 0xff, 0x25, /* jmp indirect */
571 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
572 0x68, /* pushl immediate */
573 0, 0, 0, 0, /* replaced with offset into relocation table. */
574 0xe9, /* jmp relative */
575 0, 0, 0, 0 /* replaced with offset to start of .plt. */
578 /* The first entry in a PIC lazy procedure linkage table look like
579 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
580 lazy_plt->plt0_pad_byte. */
582 static const bfd_byte elf_i386_pic_lazy_plt0_entry
[12] =
584 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
585 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
588 /* Subsequent entries in a PIC lazy procedure linkage table look like
591 static const bfd_byte elf_i386_pic_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
593 0xff, 0xa3, /* jmp *offset(%ebx) */
594 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
595 0x68, /* pushl immediate */
596 0, 0, 0, 0, /* replaced with offset into relocation table. */
597 0xe9, /* jmp relative */
598 0, 0, 0, 0 /* replaced with offset to start of .plt. */
601 /* Entries in the non-lazy procedure linkage table look like this. */
603 static const bfd_byte elf_i386_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
605 0xff, 0x25, /* jmp indirect */
606 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
607 0x66, 0x90 /* xchg %ax,%ax */
610 /* Entries in the PIC non-lazy procedure linkage table look like
613 static const bfd_byte elf_i386_pic_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
615 0xff, 0xa3, /* jmp *offset(%ebx) */
616 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
617 0x66, 0x90 /* xchg %ax,%ax */
620 /* The first entry in an absolute IBT-enabled lazy procedure linkage
621 table looks like this. */
623 static const bfd_byte elf_i386_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
625 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
626 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
627 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
630 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
631 table look like this. Subsequent entries for a PIC IBT-enabled lazy
632 procedure linkage table are the same. */
634 static const bfd_byte elf_i386_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
636 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
637 0x68, 0, 0, 0, 0, /* pushl immediate */
638 0xe9, 0, 0, 0, 0, /* jmp relative */
639 0x66, 0x90 /* xchg %ax,%ax */
642 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
645 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
647 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
648 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
649 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
652 /* Entries for branches with IBT-enabled in the absolute non-lazey
653 procedure linkage table look like this. They have the same size
654 as the lazy PLT entry. */
656 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
658 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
659 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
660 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
663 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
664 linkage table look like this. They have the same size as the lazy
667 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
669 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
670 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
671 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
674 /* .eh_frame covering the lazy .plt section. */
676 static const bfd_byte elf_i386_eh_frame_lazy_plt
[] =
678 #define PLT_CIE_LENGTH 20
679 #define PLT_FDE_LENGTH 36
680 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
681 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
682 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
683 0, 0, 0, 0, /* CIE ID */
685 'z', 'R', 0, /* Augmentation string */
686 1, /* Code alignment factor */
687 0x7c, /* Data alignment factor */
688 8, /* Return address column */
689 1, /* Augmentation size */
690 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
691 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
692 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
693 DW_CFA_nop
, DW_CFA_nop
,
695 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
696 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
697 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
698 0, 0, 0, 0, /* .plt size goes here */
699 0, /* Augmentation size */
700 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
701 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
702 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
703 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
704 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
705 11, /* Block length */
706 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
707 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
708 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
709 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
710 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
713 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
715 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt
[] =
717 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
718 0, 0, 0, 0, /* CIE ID */
720 'z', 'R', 0, /* Augmentation string */
721 1, /* Code alignment factor */
722 0x7c, /* Data alignment factor */
723 8, /* Return address column */
724 1, /* Augmentation size */
725 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
726 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
727 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
728 DW_CFA_nop
, DW_CFA_nop
,
730 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
731 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
732 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
733 0, 0, 0, 0, /* .plt size goes here */
734 0, /* Augmentation size */
735 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
736 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
737 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
738 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
739 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
740 11, /* Block length */
741 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
742 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
743 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
744 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
745 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
748 /* .eh_frame covering the non-lazy .plt section. */
750 static const bfd_byte elf_i386_eh_frame_non_lazy_plt
[] =
752 #define PLT_GOT_FDE_LENGTH 16
753 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
754 0, 0, 0, 0, /* CIE ID */
756 'z', 'R', 0, /* Augmentation string */
757 1, /* Code alignment factor */
758 0x7c, /* Data alignment factor */
759 8, /* Return address column */
760 1, /* Augmentation size */
761 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
762 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
763 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
764 DW_CFA_nop
, DW_CFA_nop
,
766 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
767 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
768 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
769 0, 0, 0, 0, /* non-lazy .plt size goes here */
770 0, /* Augmentation size */
771 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
774 struct elf_i386_lazy_plt_layout
776 /* The first entry in an absolute lazy procedure linkage table looks
778 const bfd_byte
*plt0_entry
;
779 unsigned int plt0_entry_size
;
781 /* Offsets into plt0_entry that are to be replaced with GOT[1] and
783 unsigned int plt0_got1_offset
;
784 unsigned int plt0_got2_offset
;
786 /* Later entries in an absolute lazy procedure linkage table look
788 const bfd_byte
*plt_entry
;
789 unsigned int plt_entry_size
;
791 /* Offsets into plt_entry that are to be replaced with... */
792 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
793 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
794 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
796 /* Offset into plt_entry where the initial value of the GOT entry
798 unsigned int plt_lazy_offset
;
800 /* The first entry in a PIC lazy procedure linkage table looks like
802 const bfd_byte
*pic_plt0_entry
;
804 /* Subsequent entries in a PIC lazy procedure linkage table look
806 const bfd_byte
*pic_plt_entry
;
808 /* .eh_frame covering the lazy .plt section. */
809 const bfd_byte
*eh_frame_plt
;
810 unsigned int eh_frame_plt_size
;
813 struct elf_i386_non_lazy_plt_layout
815 /* Entries in an absolute non-lazy procedure linkage table look like
817 const bfd_byte
*plt_entry
;
818 /* Entries in a PIC non-lazy procedure linkage table look like this. */
819 const bfd_byte
*pic_plt_entry
;
821 unsigned int plt_entry_size
;
823 /* Offsets into plt_entry that are to be replaced with... */
824 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
826 /* .eh_frame covering the non-lazy .plt section. */
827 const bfd_byte
*eh_frame_plt
;
828 unsigned int eh_frame_plt_size
;
831 struct elf_i386_plt_layout
833 /* The first entry in a lazy procedure linkage table looks like this. */
834 const bfd_byte
*plt0_entry
;
835 /* Entries in a procedure linkage table look like this. */
836 const bfd_byte
*plt_entry
;
837 unsigned int plt_entry_size
;
840 unsigned int has_plt0
;
842 /* Offsets into plt_entry that are to be replaced with... */
843 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
845 /* .eh_frame covering the .plt section. */
846 const bfd_byte
*eh_frame_plt
;
847 unsigned int eh_frame_plt_size
;
850 /* These are the standard parameters. */
851 static const struct elf_i386_lazy_plt_layout elf_i386_lazy_plt
=
853 elf_i386_lazy_plt0_entry
, /* plt0_entry */
854 sizeof (elf_i386_lazy_plt0_entry
), /* plt0_entry_size */
855 2, /* plt0_got1_offset */
856 8, /* plt0_got2_offset */
857 elf_i386_lazy_plt_entry
, /* plt_entry */
858 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
859 2, /* plt_got_offset */
860 7, /* plt_reloc_offset */
861 12, /* plt_plt_offset */
862 6, /* plt_lazy_offset */
863 elf_i386_pic_lazy_plt0_entry
, /* pic_plt0_entry */
864 elf_i386_pic_lazy_plt_entry
, /* pic_plt_entry */
865 elf_i386_eh_frame_lazy_plt
, /* eh_frame_plt */
866 sizeof (elf_i386_eh_frame_lazy_plt
) /* eh_frame_plt_size */
869 static const struct elf_i386_non_lazy_plt_layout elf_i386_non_lazy_plt
=
871 elf_i386_non_lazy_plt_entry
, /* plt_entry */
872 elf_i386_pic_non_lazy_plt_entry
, /* pic_plt_entry */
873 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
874 2, /* plt_got_offset */
875 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
876 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
879 static const struct elf_i386_lazy_plt_layout elf_i386_lazy_ibt_plt
=
881 elf_i386_lazy_ibt_plt0_entry
, /* plt0_entry */
882 sizeof (elf_i386_lazy_ibt_plt0_entry
), /* plt0_entry_size */
883 2, /* plt0_got1_offset */
884 8, /* plt0_got2_offset */
885 elf_i386_lazy_ibt_plt_entry
, /* plt_entry */
886 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
887 4+2, /* plt_got_offset */
888 4+1, /* plt_reloc_offset */
889 4+6, /* plt_plt_offset */
890 0, /* plt_lazy_offset */
891 elf_i386_pic_lazy_ibt_plt0_entry
, /* pic_plt0_entry */
892 elf_i386_lazy_ibt_plt_entry
, /* pic_plt_entry */
893 elf_i386_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
894 sizeof (elf_i386_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
897 static const struct elf_i386_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt
=
899 elf_i386_non_lazy_ibt_plt_entry
, /* plt_entry */
900 elf_i386_pic_non_lazy_ibt_plt_entry
,/* pic_plt_entry */
901 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
902 4+2, /* plt_got_offset */
903 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
904 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
908 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
909 for the PLTResolve stub and then for each PLT entry. */
910 #define PLTRESOLVE_RELOCS_SHLIB 0
911 #define PLTRESOLVE_RELOCS 2
912 #define PLT_NON_JUMP_SLOT_RELOCS 2
914 /* Architecture-specific backend data for i386. */
916 struct elf_i386_backend_data
918 /* Value used to fill the unused bytes of the first PLT entry. */
919 bfd_byte plt0_pad_byte
;
930 #define get_elf_i386_backend_data(abfd) \
931 ((const struct elf_i386_backend_data *) \
932 get_elf_backend_data (abfd)->arch_data)
934 /* These are the standard parameters. */
935 static const struct elf_i386_backend_data elf_i386_arch_bed
=
937 0, /* plt0_pad_byte */
941 #define elf_backend_arch_data &elf_i386_arch_bed
943 /* Is a undefined weak symbol which is resolved to 0. Reference to an
944 undefined weak symbol is resolved to 0 when building executable if
946 1. Has non-GOT/non-PLT relocations in text section. Or
947 2. Has no GOT/PLT relocation.
948 Local undefined weak symbol is always resolved to 0.
950 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
951 ((EH)->elf.root.type == bfd_link_hash_undefweak \
952 && ((EH)->elf.forced_local \
953 || (bfd_link_executable (INFO) \
954 && (elf_i386_hash_table (INFO)->interp == NULL \
956 || (EH)->has_non_got_reloc \
957 || !(INFO)->dynamic_undefined_weak))))
959 /* i386 ELF linker hash entry. */
961 struct elf_i386_link_hash_entry
963 struct elf_link_hash_entry elf
;
965 /* Track dynamic relocs copied for this symbol. */
966 struct elf_dyn_relocs
*dyn_relocs
;
968 #define GOT_UNKNOWN 0
972 #define GOT_TLS_IE_POS 5
973 #define GOT_TLS_IE_NEG 6
974 #define GOT_TLS_IE_BOTH 7
975 #define GOT_TLS_GDESC 8
976 #define GOT_TLS_GD_BOTH_P(type) \
977 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
978 #define GOT_TLS_GD_P(type) \
979 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
980 #define GOT_TLS_GDESC_P(type) \
981 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
982 #define GOT_TLS_GD_ANY_P(type) \
983 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
984 unsigned char tls_type
;
986 /* Symbol is referenced by R_386_GOTOFF relocation. */
987 unsigned int gotoff_ref
: 1;
989 /* Symbol has GOT or PLT relocations. */
990 unsigned int has_got_reloc
: 1;
992 /* Symbol has non-GOT/non-PLT relocations in text sections. */
993 unsigned int has_non_got_reloc
: 1;
995 /* Don't call finish_dynamic_symbol on this symbol. */
996 unsigned int no_finish_dynamic_symbol
: 1;
998 /* 0: symbol isn't ___tls_get_addr.
999 1: symbol is ___tls_get_addr.
1000 2: symbol is unknown. */
1001 unsigned int tls_get_addr
: 2;
1003 /* Reference count of C/C++ function pointer relocations in read-write
1004 section which can be resolved at run-time. */
1005 bfd_signed_vma func_pointer_refcount
;
1007 /* Information about the GOT PLT entry. Filled when there are both
1008 GOT and PLT relocations against the same function. */
1009 union gotplt_union plt_got
;
1011 /* Information about the second PLT entry. */
1012 union gotplt_union plt_second
;
1014 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
1015 starting at the end of the jump table. */
1016 bfd_vma tlsdesc_got
;
1019 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
1021 struct elf_i386_obj_tdata
1023 struct elf_obj_tdata root
;
1025 /* tls_type for each local got entry. */
1026 char *local_got_tls_type
;
1028 /* GOTPLT entries for TLS descriptors. */
1029 bfd_vma
*local_tlsdesc_gotent
;
1032 #define elf_i386_tdata(abfd) \
1033 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
1035 #define elf_i386_local_got_tls_type(abfd) \
1036 (elf_i386_tdata (abfd)->local_got_tls_type)
1038 #define elf_i386_local_tlsdesc_gotent(abfd) \
1039 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
1041 #define is_i386_elf(bfd) \
1042 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1043 && elf_tdata (bfd) != NULL \
1044 && elf_object_id (bfd) == I386_ELF_DATA)
1047 elf_i386_mkobject (bfd
*abfd
)
1049 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
1053 /* i386 ELF linker hash table. */
1055 struct elf_i386_link_hash_table
1057 struct elf_link_hash_table elf
;
1059 /* Short-cuts to get to dynamic linker sections. */
1061 asection
*plt_eh_frame
;
1062 asection
*plt_second
;
1063 asection
*plt_second_eh_frame
;
1065 asection
*plt_got_eh_frame
;
1067 /* Parameters describing PLT generation. */
1068 struct elf_i386_plt_layout plt
;
1070 /* Parameters describing lazy PLT generation. */
1071 const struct elf_i386_lazy_plt_layout
*lazy_plt
;
1073 /* Parameters describing non-lazy PLT generation. */
1074 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt
;
1078 bfd_signed_vma refcount
;
1082 /* The amount of space used by the reserved portion of the sgotplt
1083 section, plus whatever space is used by the jump slots. */
1084 bfd_vma sgotplt_jump_table_size
;
1086 /* Small local sym cache. */
1087 struct sym_cache sym_cache
;
1089 /* _TLS_MODULE_BASE_ symbol. */
1090 struct bfd_link_hash_entry
*tls_module_base
;
1092 /* Used by local STT_GNU_IFUNC symbols. */
1093 htab_t loc_hash_table
;
1094 void * loc_hash_memory
;
1096 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
1099 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
1100 bfd_vma next_tls_desc_index
;
1102 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
1103 bfd_vma next_jump_slot_index
;
1105 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
1106 bfd_vma next_irelative_index
;
1108 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
1109 to read-only sections. */
1110 bfd_boolean readonly_dynrelocs_against_ifunc
;
1113 /* Get the i386 ELF linker hash table from a link_info structure. */
1115 #define elf_i386_hash_table(p) \
1116 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
1117 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
1119 #define elf_i386_compute_jump_table_size(htab) \
1120 ((htab)->elf.srelplt->reloc_count * 4)
1122 /* Create an entry in an i386 ELF linker hash table. */
1124 static struct bfd_hash_entry
*
1125 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1126 struct bfd_hash_table
*table
,
1129 /* Allocate the structure if it has not already been allocated by a
1133 entry
= (struct bfd_hash_entry
*)
1134 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
1139 /* Call the allocation method of the superclass. */
1140 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1143 struct elf_i386_link_hash_entry
*eh
;
1145 eh
= (struct elf_i386_link_hash_entry
*) entry
;
1146 eh
->dyn_relocs
= NULL
;
1147 eh
->tls_type
= GOT_UNKNOWN
;
1149 eh
->has_got_reloc
= 0;
1150 eh
->has_non_got_reloc
= 0;
1151 eh
->no_finish_dynamic_symbol
= 0;
1152 eh
->tls_get_addr
= 2;
1153 eh
->func_pointer_refcount
= 0;
1154 eh
->plt_got
.offset
= (bfd_vma
) -1;
1155 eh
->tlsdesc_got
= (bfd_vma
) -1;
1161 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1162 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1163 as global symbol. We reuse indx and dynstr_index for local symbol
1164 hash since they aren't used by global symbols in this backend. */
1167 elf_i386_local_htab_hash (const void *ptr
)
1169 struct elf_link_hash_entry
*h
1170 = (struct elf_link_hash_entry
*) ptr
;
1171 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
1174 /* Compare local hash entries. */
1177 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
1179 struct elf_link_hash_entry
*h1
1180 = (struct elf_link_hash_entry
*) ptr1
;
1181 struct elf_link_hash_entry
*h2
1182 = (struct elf_link_hash_entry
*) ptr2
;
1184 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1187 /* Find and/or create a hash entry for local symbol. */
1189 static struct elf_link_hash_entry
*
1190 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
1191 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1194 struct elf_i386_link_hash_entry e
, *ret
;
1195 asection
*sec
= abfd
->sections
;
1196 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1197 ELF32_R_SYM (rel
->r_info
));
1200 e
.elf
.indx
= sec
->id
;
1201 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1202 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1203 create
? INSERT
: NO_INSERT
);
1210 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
1214 ret
= (struct elf_i386_link_hash_entry
*)
1215 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1216 sizeof (struct elf_i386_link_hash_entry
));
1219 memset (ret
, 0, sizeof (*ret
));
1220 ret
->elf
.indx
= sec
->id
;
1221 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1222 ret
->elf
.dynindx
= -1;
1223 ret
->func_pointer_refcount
= 0;
1224 ret
->plt_got
.offset
= (bfd_vma
) -1;
1230 /* Destroy an i386 ELF linker hash table. */
1233 elf_i386_link_hash_table_free (bfd
*obfd
)
1235 struct elf_i386_link_hash_table
*htab
1236 = (struct elf_i386_link_hash_table
*) obfd
->link
.hash
;
1238 if (htab
->loc_hash_table
)
1239 htab_delete (htab
->loc_hash_table
);
1240 if (htab
->loc_hash_memory
)
1241 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1242 _bfd_elf_link_hash_table_free (obfd
);
1245 /* Create an i386 ELF linker hash table. */
1247 static struct bfd_link_hash_table
*
1248 elf_i386_link_hash_table_create (bfd
*abfd
)
1250 struct elf_i386_link_hash_table
*ret
;
1251 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
1253 ret
= (struct elf_i386_link_hash_table
*) bfd_zmalloc (amt
);
1257 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1258 elf_i386_link_hash_newfunc
,
1259 sizeof (struct elf_i386_link_hash_entry
),
1266 ret
->loc_hash_table
= htab_try_create (1024,
1267 elf_i386_local_htab_hash
,
1268 elf_i386_local_htab_eq
,
1270 ret
->loc_hash_memory
= objalloc_create ();
1271 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1273 elf_i386_link_hash_table_free (abfd
);
1276 ret
->elf
.root
.hash_table_free
= elf_i386_link_hash_table_free
;
1278 return &ret
->elf
.root
;
1281 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1284 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1285 struct elf_link_hash_entry
*dir
,
1286 struct elf_link_hash_entry
*ind
)
1288 struct elf_i386_link_hash_entry
*edir
, *eind
;
1290 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1291 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1293 if (eind
->dyn_relocs
!= NULL
)
1295 if (edir
->dyn_relocs
!= NULL
)
1297 struct elf_dyn_relocs
**pp
;
1298 struct elf_dyn_relocs
*p
;
1300 /* Add reloc counts against the indirect sym to the direct sym
1301 list. Merge any entries against the same section. */
1302 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1304 struct elf_dyn_relocs
*q
;
1306 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1307 if (q
->sec
== p
->sec
)
1309 q
->pc_count
+= p
->pc_count
;
1310 q
->count
+= p
->count
;
1317 *pp
= edir
->dyn_relocs
;
1320 edir
->dyn_relocs
= eind
->dyn_relocs
;
1321 eind
->dyn_relocs
= NULL
;
1324 if (ind
->root
.type
== bfd_link_hash_indirect
1325 && dir
->got
.refcount
<= 0)
1327 edir
->tls_type
= eind
->tls_type
;
1328 eind
->tls_type
= GOT_UNKNOWN
;
1331 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1332 generate a R_386_COPY reloc. */
1333 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1335 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1336 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1338 if (ELIMINATE_COPY_RELOCS
1339 && ind
->root
.type
!= bfd_link_hash_indirect
1340 && dir
->dynamic_adjusted
)
1342 /* If called to transfer flags for a weakdef during processing
1343 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1344 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1345 if (dir
->versioned
!= versioned_hidden
)
1346 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1347 dir
->ref_regular
|= ind
->ref_regular
;
1348 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1349 dir
->needs_plt
|= ind
->needs_plt
;
1350 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1354 if (eind
->func_pointer_refcount
> 0)
1356 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1357 eind
->func_pointer_refcount
= 0;
1360 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1364 /* Return TRUE if the TLS access code sequence support transition
1368 elf_i386_check_tls_transition (asection
*sec
,
1370 Elf_Internal_Shdr
*symtab_hdr
,
1371 struct elf_link_hash_entry
**sym_hashes
,
1372 unsigned int r_type
,
1373 const Elf_Internal_Rela
*rel
,
1374 const Elf_Internal_Rela
*relend
)
1376 unsigned int val
, type
, reg
;
1377 unsigned long r_symndx
;
1378 struct elf_link_hash_entry
*h
;
1381 bfd_boolean indirect_call
, tls_get_addr
;
1383 offset
= rel
->r_offset
;
1388 if (offset
< 2 || (rel
+ 1) >= relend
)
1391 indirect_call
= FALSE
;
1392 call
= contents
+ offset
+ 4;
1395 if (r_type
== R_386_TLS_GD
)
1397 /* Check transition from GD access model. Only
1398 leal foo@tlsgd(,%ebx,1), %eax
1399 call ___tls_get_addr@PLT
1401 leal foo@tlsgd(%ebx) %eax
1402 call ___tls_get_addr@PLT
1405 leal foo@tlsgd(%reg), %eax
1406 call *___tls_get_addr@GOT(%reg)
1407 which may be converted to
1408 addr32 call ___tls_get_addr
1409 can transit to different access model. */
1410 if ((offset
+ 10) > sec
->size
1411 || (type
!= 0x8d && type
!= 0x04))
1416 /* leal foo@tlsgd(,%ebx,1), %eax
1417 call ___tls_get_addr@PLT */
1421 if (*(call
- 7) != 0x8d
1429 leal foo@tlsgd(%ebx), %eax
1430 call ___tls_get_addr@PLT
1433 leal foo@tlsgd(%reg), %eax
1434 call *___tls_get_addr@GOT(%reg)
1435 which may be converted to
1436 addr32 call ___tls_get_addr
1438 %eax can't be used as the GOT base register since it
1439 is used to pass parameter to ___tls_get_addr. */
1441 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1444 indirect_call
= call
[0] == 0xff;
1445 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
1446 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1448 && (call
[1] & 0xf8) == 0x90
1449 && (call
[1] & 0x7) == reg
))
1455 /* Check transition from LD access model. Only
1456 leal foo@tlsldm(%ebx), %eax
1457 call ___tls_get_addr@PLT
1459 leal foo@tlsldm(%reg), %eax
1460 call *___tls_get_addr@GOT(%reg)
1461 which may be converted to
1462 addr32 call ___tls_get_addr
1463 can transit to different access model. */
1464 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1467 /* %eax can't be used as the GOT base register since it is
1468 used to pass parameter to ___tls_get_addr. */
1470 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1473 indirect_call
= call
[0] == 0xff;
1474 if (!(reg
== 3 && call
[0] == 0xe8)
1475 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1477 && (call
[1] & 0xf8) == 0x90
1478 && (call
[1] & 0x7) == reg
))
1482 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1483 if (r_symndx
< symtab_hdr
->sh_info
)
1486 tls_get_addr
= FALSE
;
1487 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1488 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1490 struct elf_i386_link_hash_entry
*eh
1491 = (struct elf_i386_link_hash_entry
*) h
;
1492 tls_get_addr
= eh
->tls_get_addr
== 1;
1493 if (eh
->tls_get_addr
> 1)
1495 /* Use strncmp to check ___tls_get_addr since
1496 ___tls_get_addr may be versioned. */
1497 if (strncmp (h
->root
.root
.string
, "___tls_get_addr", 15)
1500 eh
->tls_get_addr
= 1;
1501 tls_get_addr
= TRUE
;
1504 eh
->tls_get_addr
= 0;
1510 else if (indirect_call
)
1511 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
1513 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1514 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
1517 /* Check transition from IE access model:
1518 movl foo@indntpoff(%rip), %eax
1519 movl foo@indntpoff(%rip), %reg
1520 addl foo@indntpoff(%rip), %reg
1523 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1526 /* Check "movl foo@tpoff(%rip), %eax" first. */
1527 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1534 /* Check movl|addl foo@tpoff(%rip), %reg. */
1535 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1536 return ((type
== 0x8b || type
== 0x03)
1537 && (val
& 0xc7) == 0x05);
1539 case R_386_TLS_GOTIE
:
1540 case R_386_TLS_IE_32
:
1541 /* Check transition from {IE_32,GOTIE} access model:
1542 subl foo@{tpoff,gontoff}(%reg1), %reg2
1543 movl foo@{tpoff,gontoff}(%reg1), %reg2
1544 addl foo@{tpoff,gontoff}(%reg1), %reg2
1547 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1550 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1551 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1554 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1555 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1557 case R_386_TLS_GOTDESC
:
1558 /* Check transition from GDesc access model:
1559 leal x@tlsdesc(%ebx), %eax
1561 Make sure it's a leal adding ebx to a 32-bit offset
1562 into any register, although it's probably almost always
1565 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1568 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1571 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1572 return (val
& 0xc7) == 0x83;
1574 case R_386_TLS_DESC_CALL
:
1575 /* Check transition from GDesc access model:
1576 call *x@tlsdesc(%eax)
1578 if (offset
+ 2 <= sec
->size
)
1580 /* Make sure that it's a call *x@tlsdesc(%eax). */
1581 call
= contents
+ offset
;
1582 return call
[0] == 0xff && call
[1] == 0x10;
1592 /* Return TRUE if the TLS access transition is OK or no transition
1593 will be performed. Update R_TYPE if there is a transition. */
1596 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1597 asection
*sec
, bfd_byte
*contents
,
1598 Elf_Internal_Shdr
*symtab_hdr
,
1599 struct elf_link_hash_entry
**sym_hashes
,
1600 unsigned int *r_type
, int tls_type
,
1601 const Elf_Internal_Rela
*rel
,
1602 const Elf_Internal_Rela
*relend
,
1603 struct elf_link_hash_entry
*h
,
1604 unsigned long r_symndx
,
1605 bfd_boolean from_relocate_section
)
1607 unsigned int from_type
= *r_type
;
1608 unsigned int to_type
= from_type
;
1609 bfd_boolean check
= TRUE
;
1611 /* Skip TLS transition for functions. */
1613 && (h
->type
== STT_FUNC
1614 || h
->type
== STT_GNU_IFUNC
))
1620 case R_386_TLS_GOTDESC
:
1621 case R_386_TLS_DESC_CALL
:
1622 case R_386_TLS_IE_32
:
1624 case R_386_TLS_GOTIE
:
1625 if (bfd_link_executable (info
))
1628 to_type
= R_386_TLS_LE_32
;
1629 else if (from_type
!= R_386_TLS_IE
1630 && from_type
!= R_386_TLS_GOTIE
)
1631 to_type
= R_386_TLS_IE_32
;
1634 /* When we are called from elf_i386_relocate_section, there may
1635 be additional transitions based on TLS_TYPE. */
1636 if (from_relocate_section
)
1638 unsigned int new_to_type
= to_type
;
1640 if (bfd_link_executable (info
)
1643 && (tls_type
& GOT_TLS_IE
))
1644 new_to_type
= R_386_TLS_LE_32
;
1646 if (to_type
== R_386_TLS_GD
1647 || to_type
== R_386_TLS_GOTDESC
1648 || to_type
== R_386_TLS_DESC_CALL
)
1650 if (tls_type
== GOT_TLS_IE_POS
)
1651 new_to_type
= R_386_TLS_GOTIE
;
1652 else if (tls_type
& GOT_TLS_IE
)
1653 new_to_type
= R_386_TLS_IE_32
;
1656 /* We checked the transition before when we were called from
1657 elf_i386_check_relocs. We only want to check the new
1658 transition which hasn't been checked before. */
1659 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1660 to_type
= new_to_type
;
1666 if (bfd_link_executable (info
))
1667 to_type
= R_386_TLS_LE_32
;
1674 /* Return TRUE if there is no transition. */
1675 if (from_type
== to_type
)
1678 /* Check if the transition can be performed. */
1680 && ! elf_i386_check_tls_transition (sec
, contents
,
1681 symtab_hdr
, sym_hashes
,
1682 from_type
, rel
, relend
))
1684 reloc_howto_type
*from
, *to
;
1687 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1688 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1691 name
= h
->root
.root
.string
;
1694 struct elf_i386_link_hash_table
*htab
;
1696 htab
= elf_i386_hash_table (info
);
1701 Elf_Internal_Sym
*isym
;
1703 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1705 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1710 /* xgettext:c-format */
1711 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1712 "in section `%A' failed"),
1713 abfd
, from
->name
, to
->name
, name
,
1714 rel
->r_offset
, sec
);
1715 bfd_set_error (bfd_error_bad_value
);
1723 /* With the local symbol, foo, we convert
1724 mov foo@GOT[(%reg1)], %reg2
1726 lea foo[@GOTOFF(%reg1)], %reg2
1728 call/jmp *foo@GOT[(%reg)]
1730 nop call foo/jmp foo nop
1731 When PIC is false, convert
1732 test %reg1, foo@GOT[(%reg2)]
1736 binop foo@GOT[(%reg1)], %reg2
1739 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1744 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1746 Elf_Internal_Rela
*irel
,
1747 struct elf_link_hash_entry
*h
,
1748 bfd_boolean
*converted
,
1749 struct bfd_link_info
*link_info
)
1751 struct elf_i386_link_hash_table
*htab
;
1752 unsigned int opcode
;
1754 bfd_boolean baseless
;
1755 Elf_Internal_Sym
*isym
;
1756 unsigned int addend
;
1760 bfd_boolean to_reloc_32
;
1761 unsigned int r_type
;
1762 unsigned int r_symndx
;
1763 bfd_vma roff
= irel
->r_offset
;
1768 /* Addend for R_386_GOT32X relocations must be 0. */
1769 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1773 htab
= elf_i386_hash_table (link_info
);
1774 is_pic
= bfd_link_pic (link_info
);
1776 r_type
= ELF32_R_TYPE (irel
->r_info
);
1777 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1779 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1780 baseless
= (modrm
& 0xc7) == 0x5;
1782 if (baseless
&& is_pic
)
1784 /* For PIC, disallow R_386_GOT32X without a base register
1785 since we don't know what the GOT base is. */
1790 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1792 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1795 name
= h
->root
.root
.string
;
1798 /* xgettext:c-format */
1799 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1800 " register can not be used when making a shared object"),
1805 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1807 /* Convert to R_386_32 if PIC is false or there is no base
1809 to_reloc_32
= !is_pic
|| baseless
;
1811 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1815 if (opcode
== 0x0ff)
1816 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1817 goto convert_branch
;
1819 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1820 "test %reg1, foo@GOT(%reg2)" and
1821 "binop foo@GOT[(%reg1)], %reg2". */
1825 /* Undefined weak symbol is only bound locally in executable
1826 and its reference is resolved as 0. */
1827 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
, TRUE
,
1828 elf_i386_hash_entry (h
)))
1832 /* No direct branch to 0 for PIC. */
1836 goto convert_branch
;
1840 /* We can convert load of address 0 to R_386_32. */
1848 /* We have "call/jmp *foo@GOT[(%reg)]". */
1849 if ((h
->root
.type
== bfd_link_hash_defined
1850 || h
->root
.type
== bfd_link_hash_defweak
)
1851 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1853 /* The function is locally defined. */
1855 /* Convert R_386_GOT32X to R_386_PC32. */
1856 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1858 struct elf_i386_link_hash_entry
*eh
1859 = (struct elf_i386_link_hash_entry
*) h
;
1861 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1864 /* To support TLS optimization, always use addr32 prefix
1865 for "call *___tls_get_addr@GOT(%reg)". */
1866 if (eh
&& eh
->tls_get_addr
== 1)
1869 nop_offset
= irel
->r_offset
- 2;
1873 nop
= link_info
->call_nop_byte
;
1874 if (link_info
->call_nop_as_suffix
)
1876 nop_offset
= roff
+ 3;
1877 irel
->r_offset
-= 1;
1880 nop_offset
= roff
- 2;
1885 /* Convert to "jmp foo nop". */
1888 nop_offset
= roff
+ 3;
1889 irel
->r_offset
-= 1;
1892 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1893 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1894 /* When converting to PC-relative relocation, we
1895 need to adjust addend by -4. */
1896 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1897 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1904 /* We have "mov foo@GOT[(%re1g)], %reg2",
1905 "test %reg1, foo@GOT(%reg2)" and
1906 "binop foo@GOT[(%reg1)], %reg2".
1908 Avoid optimizing _DYNAMIC since ld.so may use its
1909 link-time address. */
1910 if (h
== htab
->elf
.hdynamic
)
1913 /* def_regular is set by an assignment in a linker script in
1914 bfd_elf_record_link_assignment. start_stop is set on
1915 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1918 || h
->root
.type
== bfd_link_hash_defined
1919 || h
->root
.type
== bfd_link_hash_defweak
)
1920 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)))
1927 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1928 "mov $foo, %reg2" with R_386_32. */
1930 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1931 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1936 /* Convert "mov foo@GOT(%reg1), %reg2" to
1937 "lea foo@GOTOFF(%reg1), %reg2". */
1938 r_type
= R_386_GOTOFF
;
1944 /* Only R_386_32 is supported. */
1950 /* Convert "test %reg1, foo@GOT(%reg2)" to
1951 "test $foo, %reg1". */
1952 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1957 /* Convert "binop foo@GOT(%reg1), %reg2" to
1958 "binop $foo, %reg2". */
1960 | (modrm
& 0x38) >> 3
1964 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1968 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1969 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1978 /* Rename some of the generic section flags to better document how they
1980 #define need_convert_load sec_flg0
1981 #define check_relocs_failed sec_flg1
1983 /* Look through the relocs for a section during the first phase, and
1984 calculate needed space in the global offset table, procedure linkage
1985 table, and dynamic reloc sections. */
1988 elf_i386_check_relocs (bfd
*abfd
,
1989 struct bfd_link_info
*info
,
1991 const Elf_Internal_Rela
*relocs
)
1993 struct elf_i386_link_hash_table
*htab
;
1994 Elf_Internal_Shdr
*symtab_hdr
;
1995 struct elf_link_hash_entry
**sym_hashes
;
1996 const Elf_Internal_Rela
*rel
;
1997 const Elf_Internal_Rela
*rel_end
;
2001 if (bfd_link_relocatable (info
))
2004 /* Don't do anything special with non-loaded, non-alloced sections.
2005 In particular, any relocs in such sections should not affect GOT
2006 and PLT reference counting (ie. we don't allow them to create GOT
2007 or PLT entries), there's no possibility or desire to optimize TLS
2008 relocs, and there's not much point in propagating relocs to shared
2009 libs that the dynamic linker won't relocate. */
2010 if ((sec
->flags
& SEC_ALLOC
) == 0)
2013 BFD_ASSERT (is_i386_elf (abfd
));
2015 htab
= elf_i386_hash_table (info
);
2018 sec
->check_relocs_failed
= 1;
2022 /* Get the section contents. */
2023 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2024 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2025 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2027 sec
->check_relocs_failed
= 1;
2031 symtab_hdr
= &elf_symtab_hdr (abfd
);
2032 sym_hashes
= elf_sym_hashes (abfd
);
2036 rel_end
= relocs
+ sec
->reloc_count
;
2037 for (rel
= relocs
; rel
< rel_end
; rel
++)
2039 unsigned int r_type
;
2040 unsigned int r_symndx
;
2041 struct elf_link_hash_entry
*h
;
2042 struct elf_i386_link_hash_entry
*eh
;
2043 Elf_Internal_Sym
*isym
;
2045 bfd_boolean size_reloc
;
2047 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2048 r_type
= ELF32_R_TYPE (rel
->r_info
);
2050 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2052 /* xgettext:c-format */
2053 _bfd_error_handler (_("%B: bad symbol index: %d"),
2058 if (r_symndx
< symtab_hdr
->sh_info
)
2060 /* A local symbol. */
2061 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2066 /* Check relocation against local STT_GNU_IFUNC symbol. */
2067 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2069 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
2073 /* Fake a STT_GNU_IFUNC symbol. */
2074 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2076 h
->type
= STT_GNU_IFUNC
;
2079 h
->forced_local
= 1;
2080 h
->root
.type
= bfd_link_hash_defined
;
2088 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2089 while (h
->root
.type
== bfd_link_hash_indirect
2090 || h
->root
.type
== bfd_link_hash_warning
)
2091 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2094 eh
= (struct elf_i386_link_hash_entry
*) h
;
2097 if (r_type
== R_386_GOTOFF
)
2100 /* It is referenced by a non-shared object. */
2102 h
->root
.non_ir_ref_regular
= 1;
2104 if (h
->type
== STT_GNU_IFUNC
)
2105 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2106 |= elf_gnu_symbol_ifunc
;
2109 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
2110 symtab_hdr
, sym_hashes
,
2111 &r_type
, GOT_UNKNOWN
,
2112 rel
, rel_end
, h
, r_symndx
, FALSE
))
2118 htab
->tls_ldm_got
.refcount
+= 1;
2122 /* This symbol requires a procedure linkage table entry. We
2123 actually build the entry in adjust_dynamic_symbol,
2124 because this might be a case of linking PIC code which is
2125 never referenced by a dynamic object, in which case we
2126 don't need to generate a procedure linkage table entry
2129 /* If this is a local symbol, we resolve it directly without
2130 creating a procedure linkage table entry. */
2134 eh
->has_got_reloc
= 1;
2136 h
->plt
.refcount
+= 1;
2143 case R_386_TLS_IE_32
:
2145 case R_386_TLS_GOTIE
:
2146 if (!bfd_link_executable (info
))
2147 info
->flags
|= DF_STATIC_TLS
;
2153 case R_386_TLS_GOTDESC
:
2154 case R_386_TLS_DESC_CALL
:
2155 /* This symbol requires a global offset table entry. */
2157 int tls_type
, old_tls_type
;
2164 tls_type
= GOT_NORMAL
;
2166 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
2167 case R_386_TLS_GOTDESC
:
2168 case R_386_TLS_DESC_CALL
:
2169 tls_type
= GOT_TLS_GDESC
; break;
2170 case R_386_TLS_IE_32
:
2171 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
2172 tls_type
= GOT_TLS_IE_NEG
;
2174 /* If this is a GD->IE transition, we may use either of
2175 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
2176 tls_type
= GOT_TLS_IE
;
2179 case R_386_TLS_GOTIE
:
2180 tls_type
= GOT_TLS_IE_POS
; break;
2185 h
->got
.refcount
+= 1;
2186 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2190 bfd_signed_vma
*local_got_refcounts
;
2192 /* This is a global offset table entry for a local symbol. */
2193 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2194 if (local_got_refcounts
== NULL
)
2198 size
= symtab_hdr
->sh_info
;
2199 size
*= (sizeof (bfd_signed_vma
)
2200 + sizeof (bfd_vma
) + sizeof(char));
2201 local_got_refcounts
= (bfd_signed_vma
*)
2202 bfd_zalloc (abfd
, size
);
2203 if (local_got_refcounts
== NULL
)
2205 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2206 elf_i386_local_tlsdesc_gotent (abfd
)
2207 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2208 elf_i386_local_got_tls_type (abfd
)
2209 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2211 local_got_refcounts
[r_symndx
] += 1;
2212 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
2215 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
2216 tls_type
|= old_tls_type
;
2217 /* If a TLS symbol is accessed using IE at least once,
2218 there is no point to use dynamic model for it. */
2219 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2220 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2221 || (tls_type
& GOT_TLS_IE
) == 0))
2223 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
2224 tls_type
= old_tls_type
;
2225 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2226 && GOT_TLS_GD_ANY_P (tls_type
))
2227 tls_type
|= old_tls_type
;
2231 name
= h
->root
.root
.string
;
2233 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2236 /* xgettext:c-format */
2237 (_("%B: `%s' accessed both as normal and "
2238 "thread local symbol"),
2240 bfd_set_error (bfd_error_bad_value
);
2245 if (old_tls_type
!= tls_type
)
2248 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
2250 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2258 if (r_type
!= R_386_TLS_IE
)
2261 eh
->has_got_reloc
= 1;
2266 case R_386_TLS_LE_32
:
2269 eh
->has_got_reloc
= 1;
2270 if (bfd_link_executable (info
))
2272 info
->flags
|= DF_STATIC_TLS
;
2277 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2278 eh
->has_non_got_reloc
= 1;
2280 /* We are called after all symbols have been resolved. Only
2281 relocation against STT_GNU_IFUNC symbol must go through
2284 && (bfd_link_executable (info
)
2285 || h
->type
== STT_GNU_IFUNC
))
2287 /* If this reloc is in a read-only section, we might
2288 need a copy reloc. We can't check reliably at this
2289 stage whether the section is read-only, as input
2290 sections have not yet been mapped to output sections.
2291 Tentatively set the flag for now, and correct in
2292 adjust_dynamic_symbol. */
2295 /* We may need a .plt entry if the symbol is a function
2296 defined in a shared lib or is a STT_GNU_IFUNC function
2297 referenced from the code or read-only section. */
2299 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2300 h
->plt
.refcount
+= 1;
2302 if (r_type
== R_386_PC32
)
2304 /* Since something like ".long foo - ." may be used
2305 as pointer, make sure that PLT is used if foo is
2306 a function defined in a shared library. */
2307 if ((sec
->flags
& SEC_CODE
) == 0)
2308 h
->pointer_equality_needed
= 1;
2309 else if (h
->type
== STT_GNU_IFUNC
2310 && bfd_link_pic (info
))
2313 /* xgettext:c-format */
2314 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
2315 abfd
, h
->root
.root
.string
);
2316 bfd_set_error (bfd_error_bad_value
);
2322 h
->pointer_equality_needed
= 1;
2323 /* R_386_32 can be resolved at run-time. */
2324 if (r_type
== R_386_32
2325 && (sec
->flags
& SEC_READONLY
) == 0)
2326 eh
->func_pointer_refcount
+= 1;
2332 /* If we are creating a shared library, and this is a reloc
2333 against a global symbol, or a non PC relative reloc
2334 against a local symbol, then we need to copy the reloc
2335 into the shared library. However, if we are linking with
2336 -Bsymbolic, we do not need to copy a reloc against a
2337 global symbol which is defined in an object we are
2338 including in the link (i.e., DEF_REGULAR is set). At
2339 this point we have not seen all the input files, so it is
2340 possible that DEF_REGULAR is not set now but will be set
2341 later (it is never cleared). In case of a weak definition,
2342 DEF_REGULAR may be cleared later by a strong definition in
2343 a shared library. We account for that possibility below by
2344 storing information in the relocs_copied field of the hash
2345 table entry. A similar situation occurs when creating
2346 shared libraries and symbol visibility changes render the
2349 If on the other hand, we are creating an executable, we
2350 may need to keep relocations for symbols satisfied by a
2351 dynamic library if we manage to avoid copy relocs for the
2354 Generate dynamic pointer relocation against STT_GNU_IFUNC
2355 symbol in the non-code section. */
2356 if ((bfd_link_pic (info
)
2357 && (r_type
!= R_386_PC32
2359 && (! (bfd_link_pie (info
)
2360 || SYMBOLIC_BIND (info
, h
))
2361 || h
->root
.type
== bfd_link_hash_defweak
2362 || !h
->def_regular
))))
2364 && h
->type
== STT_GNU_IFUNC
2365 && r_type
== R_386_32
2366 && (sec
->flags
& SEC_CODE
) == 0)
2367 || (ELIMINATE_COPY_RELOCS
2368 && !bfd_link_pic (info
)
2370 && (h
->root
.type
== bfd_link_hash_defweak
2371 || !h
->def_regular
)))
2373 struct elf_dyn_relocs
*p
;
2374 struct elf_dyn_relocs
**head
;
2376 /* We must copy these reloc types into the output file.
2377 Create a reloc section in dynobj and make room for
2381 sreloc
= _bfd_elf_make_dynamic_reloc_section
2382 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
2388 /* If this is a global symbol, we count the number of
2389 relocations we need for this symbol. */
2392 head
= &eh
->dyn_relocs
;
2396 /* Track dynamic relocs needed for local syms too.
2397 We really need local syms available to do this
2402 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2407 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2411 vpp
= &elf_section_data (s
)->local_dynrel
;
2412 head
= (struct elf_dyn_relocs
**)vpp
;
2416 if (p
== NULL
|| p
->sec
!= sec
)
2418 bfd_size_type amt
= sizeof *p
;
2419 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
2431 /* Count size relocation as PC-relative relocation. */
2432 if (r_type
== R_386_PC32
|| size_reloc
)
2437 /* This relocation describes the C++ object vtable hierarchy.
2438 Reconstruct it for later use during GC. */
2439 case R_386_GNU_VTINHERIT
:
2440 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2444 /* This relocation describes which C++ vtable entries are actually
2445 used. Record for later use during GC. */
2446 case R_386_GNU_VTENTRY
:
2447 BFD_ASSERT (h
!= NULL
);
2449 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
2457 if (r_type
== R_386_GOT32X
2458 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2459 sec
->need_convert_load
= 1;
2462 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2464 if (!info
->keep_memory
)
2468 /* Cache the section contents for elf_link_input_bfd. */
2469 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2476 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2478 sec
->check_relocs_failed
= 1;
2482 /* Return the section that should be marked against GC for a given
2486 elf_i386_gc_mark_hook (asection
*sec
,
2487 struct bfd_link_info
*info
,
2488 Elf_Internal_Rela
*rel
,
2489 struct elf_link_hash_entry
*h
,
2490 Elf_Internal_Sym
*sym
)
2493 switch (ELF32_R_TYPE (rel
->r_info
))
2495 case R_386_GNU_VTINHERIT
:
2496 case R_386_GNU_VTENTRY
:
2500 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2503 /* Remove undefined weak symbol from the dynamic symbol table if it
2504 is resolved to 0. */
2507 elf_i386_fixup_symbol (struct bfd_link_info
*info
,
2508 struct elf_link_hash_entry
*h
)
2510 if (h
->dynindx
!= -1
2511 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2512 elf_i386_hash_entry (h
)->has_got_reloc
,
2513 elf_i386_hash_entry (h
)))
2516 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2522 /* Adjust a symbol defined by a dynamic object and referenced by a
2523 regular object. The current definition is in some section of the
2524 dynamic object, but we're not including those sections. We have to
2525 change the definition to something the rest of the link can
2529 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2530 struct elf_link_hash_entry
*h
)
2532 struct elf_i386_link_hash_table
*htab
;
2534 struct elf_i386_link_hash_entry
*eh
;
2535 struct elf_dyn_relocs
*p
;
2537 /* STT_GNU_IFUNC symbol must go through PLT. */
2538 if (h
->type
== STT_GNU_IFUNC
)
2540 /* All local STT_GNU_IFUNC references must be treate as local
2541 calls via local PLT. */
2543 && SYMBOL_CALLS_LOCAL (info
, h
))
2545 bfd_size_type pc_count
= 0, count
= 0;
2546 struct elf_dyn_relocs
**pp
;
2548 eh
= (struct elf_i386_link_hash_entry
*) h
;
2549 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2551 pc_count
+= p
->pc_count
;
2552 p
->count
-= p
->pc_count
;
2561 if (pc_count
|| count
)
2566 /* Increment PLT reference count only for PC-relative
2569 if (h
->plt
.refcount
<= 0)
2570 h
->plt
.refcount
= 1;
2572 h
->plt
.refcount
+= 1;
2577 if (h
->plt
.refcount
<= 0)
2579 h
->plt
.offset
= (bfd_vma
) -1;
2585 /* If this is a function, put it in the procedure linkage table. We
2586 will fill in the contents of the procedure linkage table later,
2587 when we know the address of the .got section. */
2588 if (h
->type
== STT_FUNC
2591 if (h
->plt
.refcount
<= 0
2592 || SYMBOL_CALLS_LOCAL (info
, h
)
2593 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2594 && h
->root
.type
== bfd_link_hash_undefweak
))
2596 /* This case can occur if we saw a PLT32 reloc in an input
2597 file, but the symbol was never referred to by a dynamic
2598 object, or if all references were garbage collected. In
2599 such a case, we don't actually need to build a procedure
2600 linkage table, and we can just do a PC32 reloc instead. */
2601 h
->plt
.offset
= (bfd_vma
) -1;
2608 /* It's possible that we incorrectly decided a .plt reloc was
2609 needed for an R_386_PC32 reloc to a non-function sym in
2610 check_relocs. We can't decide accurately between function and
2611 non-function syms in check-relocs; Objects loaded later in
2612 the link may change h->type. So fix it now. */
2613 h
->plt
.offset
= (bfd_vma
) -1;
2615 /* If this is a weak symbol, and there is a real definition, the
2616 processor independent code will have arranged for us to see the
2617 real definition first, and we can just use the same value. */
2618 if (h
->u
.weakdef
!= NULL
)
2620 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2621 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2622 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2623 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2624 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2625 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2629 /* This is a reference to a symbol defined by a dynamic object which
2630 is not a function. */
2632 /* If we are creating a shared library, we must presume that the
2633 only references to the symbol are via the global offset table.
2634 For such cases we need not do anything here; the relocations will
2635 be handled correctly by relocate_section. */
2636 if (!bfd_link_executable (info
))
2639 /* If there are no references to this symbol that do not use the
2640 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2642 eh
= (struct elf_i386_link_hash_entry
*) h
;
2643 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2646 /* If -z nocopyreloc was given, we won't generate them either. */
2647 if (info
->nocopyreloc
)
2653 htab
= elf_i386_hash_table (info
);
2657 /* If there aren't any dynamic relocs in read-only sections nor
2658 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2659 avoid the copy reloc. This doesn't work on VxWorks, where we can
2660 not have dynamic relocations (other than copy and jump slot
2661 relocations) in an executable. */
2662 if (ELIMINATE_COPY_RELOCS
2664 && get_elf_i386_backend_data (info
->output_bfd
)->os
!= is_vxworks
)
2666 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2668 s
= p
->sec
->output_section
;
2669 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2680 /* We must allocate the symbol in our .dynbss section, which will
2681 become part of the .bss section of the executable. There will be
2682 an entry for this symbol in the .dynsym section. The dynamic
2683 object will contain position independent code, so all references
2684 from the dynamic object to this symbol will go through the global
2685 offset table. The dynamic linker will use the .dynsym entry to
2686 determine the address it must put in the global offset table, so
2687 both the dynamic object and the regular object will refer to the
2688 same memory location for the variable. */
2690 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2691 copy the initial value out of the dynamic object and into the
2692 runtime process image. */
2693 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2695 s
= htab
->elf
.sdynrelro
;
2696 srel
= htab
->elf
.sreldynrelro
;
2700 s
= htab
->elf
.sdynbss
;
2701 srel
= htab
->elf
.srelbss
;
2703 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2705 srel
->size
+= sizeof (Elf32_External_Rel
);
2709 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2712 /* Allocate space in .plt, .got and associated reloc sections for
2716 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2718 struct bfd_link_info
*info
;
2719 struct elf_i386_link_hash_table
*htab
;
2720 struct elf_i386_link_hash_entry
*eh
;
2721 struct elf_dyn_relocs
*p
;
2722 unsigned plt_entry_size
;
2723 bfd_boolean resolved_to_zero
;
2724 const struct elf_i386_backend_data
*bed
;
2726 if (h
->root
.type
== bfd_link_hash_indirect
)
2729 eh
= (struct elf_i386_link_hash_entry
*) h
;
2731 info
= (struct bfd_link_info
*) inf
;
2732 htab
= elf_i386_hash_table (info
);
2736 bed
= get_elf_i386_backend_data (info
->output_bfd
);
2738 plt_entry_size
= htab
->plt
.plt_entry_size
;
2740 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2744 /* Clear the reference count of function pointer relocations if
2745 symbol isn't a normal function. */
2746 if (h
->type
!= STT_FUNC
)
2747 eh
->func_pointer_refcount
= 0;
2749 /* We can't use the GOT PLT if pointer equality is needed since
2750 finish_dynamic_symbol won't clear symbol value and the dynamic
2751 linker won't update the GOT slot. We will get into an infinite
2752 loop at run-time. */
2753 if (htab
->plt_got
!= NULL
2754 && h
->type
!= STT_GNU_IFUNC
2755 && !h
->pointer_equality_needed
2756 && h
->plt
.refcount
> 0
2757 && h
->got
.refcount
> 0)
2759 /* Don't use the regular PLT if there are both GOT and GOTPLT
2761 h
->plt
.offset
= (bfd_vma
) -1;
2763 /* Use the GOT PLT. */
2764 eh
->plt_got
.refcount
= 1;
2767 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2768 here if it is defined and referenced in a non-shared object. */
2769 if (h
->type
== STT_GNU_IFUNC
2772 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2773 &htab
->readonly_dynrelocs_against_ifunc
,
2775 (htab
->plt
.has_plt0
*
2779 asection
*s
= htab
->plt_second
;
2780 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
2782 /* Use the second PLT section if it is created. */
2783 eh
->plt_second
.offset
= s
->size
;
2785 /* Make room for this entry in the second PLT section. */
2786 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2794 /* Don't create the PLT entry if there are only function pointer
2795 relocations which can be resolved at run-time. */
2796 else if (htab
->elf
.dynamic_sections_created
2797 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2798 || eh
->plt_got
.refcount
> 0))
2800 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
2802 /* Clear the reference count of function pointer relocations
2804 eh
->func_pointer_refcount
= 0;
2806 /* Make sure this symbol is output as a dynamic symbol.
2807 Undefined weak syms won't yet be marked as dynamic. */
2808 if (h
->dynindx
== -1
2810 && !resolved_to_zero
2811 && h
->root
.type
== bfd_link_hash_undefweak
)
2813 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2817 if (bfd_link_pic (info
)
2818 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2820 asection
*s
= htab
->elf
.splt
;
2821 asection
*second_s
= htab
->plt_second
;
2822 asection
*got_s
= htab
->plt_got
;
2824 /* If this is the first .plt entry, make room for the special
2825 first entry. The .plt section is used by prelink to undo
2826 prelinking for dynamic relocations. */
2828 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
2831 eh
->plt_got
.offset
= got_s
->size
;
2834 h
->plt
.offset
= s
->size
;
2836 eh
->plt_second
.offset
= second_s
->size
;
2839 /* If this symbol is not defined in a regular file, and we are
2840 not generating a shared library, then set the symbol to this
2841 location in the .plt. This is required to make function
2842 pointers compare as equal between the normal executable and
2843 the shared library. */
2844 if (! bfd_link_pic (info
)
2849 /* We need to make a call to the entry of the GOT PLT
2850 instead of regular PLT entry. */
2851 h
->root
.u
.def
.section
= got_s
;
2852 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2858 /* We need to make a call to the entry of the
2859 second PLT instead of regular PLT entry. */
2860 h
->root
.u
.def
.section
= second_s
;
2861 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
2865 h
->root
.u
.def
.section
= s
;
2866 h
->root
.u
.def
.value
= h
->plt
.offset
;
2871 /* Make room for this entry. */
2873 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2876 s
->size
+= plt_entry_size
;
2878 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2880 /* We also need to make an entry in the .got.plt section,
2881 which will be placed in the .got section by the linker
2883 htab
->elf
.sgotplt
->size
+= 4;
2885 /* There should be no PLT relocation against resolved
2886 undefined weak symbol in executable. */
2887 if (!resolved_to_zero
)
2889 /* We also need to make an entry in the .rel.plt
2891 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2892 htab
->elf
.srelplt
->reloc_count
++;
2896 if (bed
->os
== is_vxworks
&& !bfd_link_pic (info
))
2898 /* VxWorks has a second set of relocations for each PLT entry
2899 in executables. They go in a separate relocation section,
2900 which is processed by the kernel loader. */
2902 /* There are two relocations for the initial PLT entry: an
2903 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2904 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2906 if (h
->plt
.offset
== plt_entry_size
)
2907 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2909 /* There are two extra relocations for each subsequent PLT entry:
2910 an R_386_32 relocation for the GOT entry, and an R_386_32
2911 relocation for the PLT entry. */
2913 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2918 eh
->plt_got
.offset
= (bfd_vma
) -1;
2919 h
->plt
.offset
= (bfd_vma
) -1;
2925 eh
->plt_got
.offset
= (bfd_vma
) -1;
2926 h
->plt
.offset
= (bfd_vma
) -1;
2930 eh
->tlsdesc_got
= (bfd_vma
) -1;
2932 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2933 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2934 if (h
->got
.refcount
> 0
2935 && bfd_link_executable (info
)
2937 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2938 h
->got
.offset
= (bfd_vma
) -1;
2939 else if (h
->got
.refcount
> 0)
2943 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2945 /* Make sure this symbol is output as a dynamic symbol.
2946 Undefined weak syms won't yet be marked as dynamic. */
2947 if (h
->dynindx
== -1
2949 && !resolved_to_zero
2950 && h
->root
.type
== bfd_link_hash_undefweak
)
2952 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2957 if (GOT_TLS_GDESC_P (tls_type
))
2959 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2960 - elf_i386_compute_jump_table_size (htab
);
2961 htab
->elf
.sgotplt
->size
+= 8;
2962 h
->got
.offset
= (bfd_vma
) -2;
2964 if (! GOT_TLS_GDESC_P (tls_type
)
2965 || GOT_TLS_GD_P (tls_type
))
2967 h
->got
.offset
= s
->size
;
2969 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2970 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2973 dyn
= htab
->elf
.dynamic_sections_created
;
2974 /* R_386_TLS_IE_32 needs one dynamic relocation,
2975 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2976 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2977 need two), R_386_TLS_GD needs one if local symbol and two if
2978 global. No dynamic relocation against resolved undefined weak
2979 symbol in executable. */
2980 if (tls_type
== GOT_TLS_IE_BOTH
)
2981 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2982 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2983 || (tls_type
& GOT_TLS_IE
))
2984 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2985 else if (GOT_TLS_GD_P (tls_type
))
2986 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2987 else if (! GOT_TLS_GDESC_P (tls_type
)
2988 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2989 && !resolved_to_zero
)
2990 || h
->root
.type
!= bfd_link_hash_undefweak
)
2991 && (bfd_link_pic (info
)
2992 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2993 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2994 if (GOT_TLS_GDESC_P (tls_type
))
2995 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2998 h
->got
.offset
= (bfd_vma
) -1;
3000 if (eh
->dyn_relocs
== NULL
)
3003 /* In the shared -Bsymbolic case, discard space allocated for
3004 dynamic pc-relative relocs against symbols which turn out to be
3005 defined in regular objects. For the normal shared case, discard
3006 space for pc-relative relocs that have become local due to symbol
3007 visibility changes. */
3009 if (bfd_link_pic (info
))
3011 /* The only reloc that uses pc_count is R_386_PC32, which will
3012 appear on a call or on something like ".long foo - .". We
3013 want calls to protected symbols to resolve directly to the
3014 function rather than going via the plt. If people want
3015 function pointer comparisons to work as expected then they
3016 should avoid writing assembly like ".long foo - .". */
3017 if (SYMBOL_CALLS_LOCAL (info
, h
))
3019 struct elf_dyn_relocs
**pp
;
3021 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3023 p
->count
-= p
->pc_count
;
3032 if (bed
->os
== is_vxworks
)
3034 struct elf_dyn_relocs
**pp
;
3035 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3037 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
3044 /* Also discard relocs on undefined weak syms with non-default
3045 visibility or in PIE. */
3046 if (eh
->dyn_relocs
!= NULL
3047 && h
->root
.type
== bfd_link_hash_undefweak
)
3049 /* Undefined weak symbol is never bound locally in shared
3051 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3052 || resolved_to_zero
)
3056 /* Keep dynamic non-GOT/non-PLT relocation so that we
3057 can branch to 0 without PLT. */
3058 struct elf_dyn_relocs
**pp
;
3060 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3061 if (p
->pc_count
== 0)
3065 /* Remove non-R_386_PC32 relocation. */
3066 p
->count
= p
->pc_count
;
3070 if (eh
->dyn_relocs
!= NULL
)
3072 /* Make sure undefined weak symbols are output
3073 as dynamic symbols in PIEs for dynamic non-GOT
3074 non-PLT reloations. */
3075 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3080 eh
->dyn_relocs
= NULL
;
3082 else if (h
->dynindx
== -1
3083 && !h
->forced_local
)
3085 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3090 else if (ELIMINATE_COPY_RELOCS
)
3092 /* For the non-shared case, discard space for relocs against
3093 symbols which turn out to need copy relocs or are not
3094 dynamic. Keep dynamic relocations for run-time function
3095 pointer initialization. */
3097 if ((!h
->non_got_ref
3098 || eh
->func_pointer_refcount
> 0
3099 || (h
->root
.type
== bfd_link_hash_undefweak
3100 && !resolved_to_zero
))
3103 || (htab
->elf
.dynamic_sections_created
3104 && (h
->root
.type
== bfd_link_hash_undefweak
3105 || h
->root
.type
== bfd_link_hash_undefined
))))
3107 /* Make sure this symbol is output as a dynamic symbol.
3108 Undefined weak syms won't yet be marked as dynamic. */
3109 if (h
->dynindx
== -1
3111 && !resolved_to_zero
3112 && h
->root
.type
== bfd_link_hash_undefweak
)
3114 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3118 /* If that succeeded, we know we'll be keeping all the
3120 if (h
->dynindx
!= -1)
3124 eh
->dyn_relocs
= NULL
;
3125 eh
->func_pointer_refcount
= 0;
3130 /* Finally, allocate space. */
3131 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3135 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3137 BFD_ASSERT (sreloc
!= NULL
);
3138 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3144 /* Allocate space in .plt, .got and associated reloc sections for
3145 local dynamic relocs. */
3148 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
3150 struct elf_link_hash_entry
*h
3151 = (struct elf_link_hash_entry
*) *slot
;
3153 if (h
->type
!= STT_GNU_IFUNC
3157 || h
->root
.type
!= bfd_link_hash_defined
)
3160 return elf_i386_allocate_dynrelocs (h
, inf
);
3163 /* Find any dynamic relocs that apply to read-only sections. */
3166 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3168 struct elf_i386_link_hash_entry
*eh
;
3169 struct elf_dyn_relocs
*p
;
3171 /* Skip local IFUNC symbols. */
3172 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3175 eh
= (struct elf_i386_link_hash_entry
*) h
;
3176 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3178 asection
*s
= p
->sec
->output_section
;
3180 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3182 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3184 info
->flags
|= DF_TEXTREL
;
3186 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3187 || info
->error_textrel
)
3188 /* xgettext:c-format */
3189 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3190 p
->sec
->owner
, h
->root
.root
.string
,
3193 /* Not an error, just cut short the traversal. */
3200 /* Convert load via the GOT slot to load immediate. */
3203 elf_i386_convert_load (bfd
*abfd
, asection
*sec
,
3204 struct bfd_link_info
*link_info
)
3206 struct elf_i386_link_hash_table
*htab
;
3207 Elf_Internal_Shdr
*symtab_hdr
;
3208 Elf_Internal_Rela
*internal_relocs
;
3209 Elf_Internal_Rela
*irel
, *irelend
;
3211 bfd_boolean changed
;
3212 bfd_signed_vma
*local_got_refcounts
;
3214 /* Don't even try to convert non-ELF outputs. */
3215 if (!is_elf_hash_table (link_info
->hash
))
3218 /* Nothing to do if there is no need or no output. */
3219 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3220 || sec
->need_convert_load
== 0
3221 || bfd_is_abs_section (sec
->output_section
))
3224 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3226 /* Load the relocations for this section. */
3227 internal_relocs
= (_bfd_elf_link_read_relocs
3228 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3229 link_info
->keep_memory
));
3230 if (internal_relocs
== NULL
)
3234 htab
= elf_i386_hash_table (link_info
);
3235 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3237 /* Get the section contents. */
3238 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3239 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3242 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3246 irelend
= internal_relocs
+ sec
->reloc_count
;
3247 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3249 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3250 unsigned int r_symndx
;
3251 struct elf_link_hash_entry
*h
;
3252 bfd_boolean converted
;
3254 /* Don't convert R_386_GOT32 since we can't tell if it is applied
3255 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
3256 if (r_type
!= R_386_GOT32X
)
3259 r_symndx
= ELF32_R_SYM (irel
->r_info
);
3260 if (r_symndx
< symtab_hdr
->sh_info
)
3261 h
= elf_i386_get_local_sym_hash (htab
, sec
->owner
,
3262 (const Elf_Internal_Rela
*) irel
,
3266 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3267 while (h
->root
.type
== bfd_link_hash_indirect
3268 || h
->root
.type
== bfd_link_hash_warning
)
3269 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3272 /* STT_GNU_IFUNC must keep GOT32 relocations. */
3273 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3277 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
3278 irel
, h
, &converted
, link_info
))
3283 changed
= converted
;
3286 if (h
->got
.refcount
> 0)
3287 h
->got
.refcount
-= 1;
3291 if (local_got_refcounts
!= NULL
3292 && local_got_refcounts
[r_symndx
] > 0)
3293 local_got_refcounts
[r_symndx
] -= 1;
3298 if (contents
!= NULL
3299 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3301 if (!changed
&& !link_info
->keep_memory
)
3305 /* Cache the section contents for elf_link_input_bfd. */
3306 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3310 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3313 free (internal_relocs
);
3315 elf_section_data (sec
)->relocs
= internal_relocs
;
3321 if (contents
!= NULL
3322 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3324 if (internal_relocs
!= NULL
3325 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3326 free (internal_relocs
);
3330 /* Set the sizes of the dynamic sections. */
3333 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3335 struct elf_i386_link_hash_table
*htab
;
3341 htab
= elf_i386_hash_table (info
);
3344 dynobj
= htab
->elf
.dynobj
;
3348 /* Set up .got offsets for local syms, and space for local dynamic
3350 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3352 bfd_signed_vma
*local_got
;
3353 bfd_signed_vma
*end_local_got
;
3354 char *local_tls_type
;
3355 bfd_vma
*local_tlsdesc_gotent
;
3356 bfd_size_type locsymcount
;
3357 Elf_Internal_Shdr
*symtab_hdr
;
3360 if (! is_i386_elf (ibfd
))
3363 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3365 struct elf_dyn_relocs
*p
;
3367 if (!elf_i386_convert_load (ibfd
, s
, info
))
3370 for (p
= ((struct elf_dyn_relocs
*)
3371 elf_section_data (s
)->local_dynrel
);
3375 if (!bfd_is_abs_section (p
->sec
)
3376 && bfd_is_abs_section (p
->sec
->output_section
))
3378 /* Input section has been discarded, either because
3379 it is a copy of a linkonce section or due to
3380 linker script /DISCARD/, so we'll be discarding
3383 else if ((get_elf_i386_backend_data (output_bfd
)->os
3385 && strcmp (p
->sec
->output_section
->name
,
3388 /* Relocations in vxworks .tls_vars sections are
3389 handled specially by the loader. */
3391 else if (p
->count
!= 0)
3393 srel
= elf_section_data (p
->sec
)->sreloc
;
3394 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3395 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3396 && (info
->flags
& DF_TEXTREL
) == 0)
3398 info
->flags
|= DF_TEXTREL
;
3399 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3400 || info
->error_textrel
)
3401 /* xgettext:c-format */
3402 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3403 p
->sec
->owner
, p
->sec
);
3409 local_got
= elf_local_got_refcounts (ibfd
);
3413 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3414 locsymcount
= symtab_hdr
->sh_info
;
3415 end_local_got
= local_got
+ locsymcount
;
3416 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
3417 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
3419 srel
= htab
->elf
.srelgot
;
3420 for (; local_got
< end_local_got
;
3421 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3423 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3426 if (GOT_TLS_GDESC_P (*local_tls_type
))
3428 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3429 - elf_i386_compute_jump_table_size (htab
);
3430 htab
->elf
.sgotplt
->size
+= 8;
3431 *local_got
= (bfd_vma
) -2;
3433 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3434 || GOT_TLS_GD_P (*local_tls_type
))
3436 *local_got
= s
->size
;
3438 if (GOT_TLS_GD_P (*local_tls_type
)
3439 || *local_tls_type
== GOT_TLS_IE_BOTH
)
3442 if (bfd_link_pic (info
)
3443 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3444 || (*local_tls_type
& GOT_TLS_IE
))
3446 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
3447 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
3448 else if (GOT_TLS_GD_P (*local_tls_type
)
3449 || ! GOT_TLS_GDESC_P (*local_tls_type
))
3450 srel
->size
+= sizeof (Elf32_External_Rel
);
3451 if (GOT_TLS_GDESC_P (*local_tls_type
))
3452 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
3456 *local_got
= (bfd_vma
) -1;
3460 if (htab
->tls_ldm_got
.refcount
> 0)
3462 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
3464 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
3465 htab
->elf
.sgot
->size
+= 8;
3466 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
3469 htab
->tls_ldm_got
.offset
= -1;
3471 /* Allocate global sym .plt and .got entries, and space for global
3472 sym dynamic relocs. */
3473 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
3475 /* Allocate .plt and .got entries, and space for local symbols. */
3476 htab_traverse (htab
->loc_hash_table
,
3477 elf_i386_allocate_local_dynrelocs
,
3480 /* For every jump slot reserved in the sgotplt, reloc_count is
3481 incremented. However, when we reserve space for TLS descriptors,
3482 it's not incremented, so in order to compute the space reserved
3483 for them, it suffices to multiply the reloc count by the jump
3486 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3487 so that R_386_IRELATIVE entries come last. */
3488 if (htab
->elf
.srelplt
)
3490 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
3491 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
3492 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3494 else if (htab
->elf
.irelplt
)
3495 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3498 if (htab
->elf
.sgotplt
)
3500 /* Don't allocate .got.plt section if there are no GOT nor PLT
3501 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
3502 if ((htab
->elf
.hgot
== NULL
3503 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3504 && (htab
->elf
.sgotplt
->size
3505 == get_elf_backend_data (output_bfd
)->got_header_size
)
3506 && (htab
->elf
.splt
== NULL
3507 || htab
->elf
.splt
->size
== 0)
3508 && (htab
->elf
.sgot
== NULL
3509 || htab
->elf
.sgot
->size
== 0)
3510 && (htab
->elf
.iplt
== NULL
3511 || htab
->elf
.iplt
->size
== 0)
3512 && (htab
->elf
.igotplt
== NULL
3513 || htab
->elf
.igotplt
->size
== 0))
3514 htab
->elf
.sgotplt
->size
= 0;
3517 if (_bfd_elf_eh_frame_present (info
))
3519 if (htab
->plt_eh_frame
!= NULL
3520 && htab
->elf
.splt
!= NULL
3521 && htab
->elf
.splt
->size
!= 0
3522 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3523 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
3525 if (htab
->plt_got_eh_frame
!= NULL
3526 && htab
->plt_got
!= NULL
3527 && htab
->plt_got
->size
!= 0
3528 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3529 htab
->plt_got_eh_frame
->size
3530 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3532 /* Unwind info for the second PLT and .plt.got sections are
3534 if (htab
->plt_second_eh_frame
!= NULL
3535 && htab
->plt_second
!= NULL
3536 && htab
->plt_second
->size
!= 0
3537 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
3538 htab
->plt_second_eh_frame
->size
3539 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3542 /* We now have determined the sizes of the various dynamic sections.
3543 Allocate memory for them. */
3545 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3547 bfd_boolean strip_section
= TRUE
;
3549 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3552 if (s
== htab
->elf
.splt
3553 || s
== htab
->elf
.sgot
)
3555 /* Strip this section if we don't need it; see the
3557 /* We'd like to strip these sections if they aren't needed, but if
3558 we've exported dynamic symbols from them we must leave them.
3559 It's too late to tell BFD to get rid of the symbols. */
3561 if (htab
->elf
.hplt
!= NULL
)
3562 strip_section
= FALSE
;
3564 else if (s
== htab
->elf
.sgotplt
3565 || s
== htab
->elf
.iplt
3566 || s
== htab
->elf
.igotplt
3567 || s
== htab
->plt_second
3568 || s
== htab
->plt_got
3569 || s
== htab
->plt_eh_frame
3570 || s
== htab
->plt_got_eh_frame
3571 || s
== htab
->plt_second_eh_frame
3572 || s
== htab
->elf
.sdynbss
3573 || s
== htab
->elf
.sdynrelro
)
3575 /* Strip these too. */
3577 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3580 && s
!= htab
->elf
.srelplt
3581 && s
!= htab
->srelplt2
)
3584 /* We use the reloc_count field as a counter if we need
3585 to copy relocs into the output file. */
3590 /* It's not one of our sections, so don't allocate space. */
3596 /* If we don't need this section, strip it from the
3597 output file. This is mostly to handle .rel.bss and
3598 .rel.plt. We must create both sections in
3599 create_dynamic_sections, because they must be created
3600 before the linker maps input sections to output
3601 sections. The linker does that before
3602 adjust_dynamic_symbol is called, and it is that
3603 function which decides whether anything needs to go
3604 into these sections. */
3606 s
->flags
|= SEC_EXCLUDE
;
3610 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3613 /* Allocate memory for the section contents. We use bfd_zalloc
3614 here in case unused entries are not reclaimed before the
3615 section's contents are written out. This should not happen,
3616 but this way if it does, we get a R_386_NONE reloc instead
3618 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3619 if (s
->contents
== NULL
)
3623 if (htab
->plt_eh_frame
!= NULL
3624 && htab
->plt_eh_frame
->contents
!= NULL
)
3626 memcpy (htab
->plt_eh_frame
->contents
,
3627 htab
->plt
.eh_frame_plt
,
3628 htab
->plt_eh_frame
->size
);
3629 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3630 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3633 if (htab
->plt_got_eh_frame
!= NULL
3634 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3636 memcpy (htab
->plt_got_eh_frame
->contents
,
3637 htab
->non_lazy_plt
->eh_frame_plt
,
3638 htab
->plt_got_eh_frame
->size
);
3639 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3640 (htab
->plt_got_eh_frame
->contents
3641 + PLT_FDE_LEN_OFFSET
));
3644 if (htab
->plt_second_eh_frame
!= NULL
3645 && htab
->plt_second_eh_frame
->contents
!= NULL
)
3647 memcpy (htab
->plt_second_eh_frame
->contents
,
3648 htab
->non_lazy_plt
->eh_frame_plt
,
3649 htab
->plt_second_eh_frame
->size
);
3650 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
3651 (htab
->plt_second_eh_frame
->contents
3652 + PLT_FDE_LEN_OFFSET
));
3655 if (htab
->elf
.dynamic_sections_created
)
3657 /* Add some entries to the .dynamic section. We fill in the
3658 values later, in elf_i386_finish_dynamic_sections, but we
3659 must add the entries now so that we get the correct size for
3660 the .dynamic section. The DT_DEBUG entry is filled in by the
3661 dynamic linker and used by the debugger. */
3662 #define add_dynamic_entry(TAG, VAL) \
3663 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3665 if (bfd_link_executable (info
))
3667 if (!add_dynamic_entry (DT_DEBUG
, 0))
3671 if (htab
->elf
.splt
->size
!= 0)
3673 /* DT_PLTGOT is used by prelink even if there is no PLT
3675 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3679 if (htab
->elf
.srelplt
->size
!= 0)
3681 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3682 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3683 || !add_dynamic_entry (DT_JMPREL
, 0))
3689 if (!add_dynamic_entry (DT_REL
, 0)
3690 || !add_dynamic_entry (DT_RELSZ
, 0)
3691 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3694 /* If any dynamic relocs apply to a read-only section,
3695 then we need a DT_TEXTREL entry. */
3696 if ((info
->flags
& DF_TEXTREL
) == 0)
3697 elf_link_hash_traverse (&htab
->elf
,
3698 elf_i386_readonly_dynrelocs
, info
);
3700 if ((info
->flags
& DF_TEXTREL
) != 0)
3702 if (htab
->readonly_dynrelocs_against_ifunc
)
3704 info
->callbacks
->einfo
3705 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3706 bfd_set_error (bfd_error_bad_value
);
3710 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3714 if (get_elf_i386_backend_data (output_bfd
)->os
== is_vxworks
3715 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3718 #undef add_dynamic_entry
3724 elf_i386_always_size_sections (bfd
*output_bfd
,
3725 struct bfd_link_info
*info
)
3727 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3731 struct elf_link_hash_entry
*tlsbase
;
3733 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3734 "_TLS_MODULE_BASE_",
3735 FALSE
, FALSE
, FALSE
);
3737 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3739 struct elf_i386_link_hash_table
*htab
;
3740 struct bfd_link_hash_entry
*bh
= NULL
;
3741 const struct elf_backend_data
*bed
3742 = get_elf_backend_data (output_bfd
);
3744 htab
= elf_i386_hash_table (info
);
3748 if (!(_bfd_generic_link_add_one_symbol
3749 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3750 tls_sec
, 0, NULL
, FALSE
,
3751 bed
->collect
, &bh
)))
3754 htab
->tls_module_base
= bh
;
3756 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3757 tlsbase
->def_regular
= 1;
3758 tlsbase
->other
= STV_HIDDEN
;
3759 tlsbase
->root
.linker_def
= 1;
3760 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
3767 /* Set the correct type for an x86 ELF section. We do this by the
3768 section name, which is a hack, but ought to work. */
3771 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3772 Elf_Internal_Shdr
*hdr
,
3777 name
= bfd_get_section_name (abfd
, sec
);
3779 /* This is an ugly, but unfortunately necessary hack that is
3780 needed when producing EFI binaries on x86. It tells
3781 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3782 containing ELF relocation info. We need this hack in order to
3783 be able to generate ELF binaries that can be translated into
3784 EFI applications (which are essentially COFF objects). Those
3785 files contain a COFF ".reloc" section inside an ELFNN object,
3786 which would normally cause BFD to segfault because it would
3787 attempt to interpret this section as containing relocation
3788 entries for section "oc". With this hack enabled, ".reloc"
3789 will be treated as a normal data section, which will avoid the
3790 segfault. However, you won't be able to create an ELFNN binary
3791 with a section named "oc" that needs relocations, but that's
3792 the kind of ugly side-effects you get when detecting section
3793 types based on their names... In practice, this limitation is
3794 unlikely to bite. */
3795 if (strcmp (name
, ".reloc") == 0)
3796 hdr
->sh_type
= SHT_PROGBITS
;
3801 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3802 executables. Rather than setting it to the beginning of the TLS
3803 section, we have to set it to the end. This function may be called
3804 multiple times, it is idempotent. */
3807 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
3809 struct elf_i386_link_hash_table
*htab
;
3810 struct bfd_link_hash_entry
*base
;
3812 if (!bfd_link_executable (info
))
3815 htab
= elf_i386_hash_table (info
);
3819 base
= htab
->tls_module_base
;
3823 base
->u
.def
.value
= htab
->elf
.tls_size
;
3826 /* Return the base VMA address which should be subtracted from real addresses
3827 when resolving @dtpoff relocation.
3828 This is PT_TLS segment p_vaddr. */
3831 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
3833 /* If tls_sec is NULL, we should have signalled an error already. */
3834 if (elf_hash_table (info
)->tls_sec
== NULL
)
3836 return elf_hash_table (info
)->tls_sec
->vma
;
3839 /* Return the relocation value for @tpoff relocation
3840 if STT_TLS virtual address is ADDRESS. */
3843 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3845 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3846 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3847 bfd_vma static_tls_size
;
3849 /* If tls_sec is NULL, we should have signalled an error already. */
3850 if (htab
->tls_sec
== NULL
)
3853 /* Consider special static TLS alignment requirements. */
3854 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3855 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3858 /* Relocate an i386 ELF section. */
3861 elf_i386_relocate_section (bfd
*output_bfd
,
3862 struct bfd_link_info
*info
,
3864 asection
*input_section
,
3866 Elf_Internal_Rela
*relocs
,
3867 Elf_Internal_Sym
*local_syms
,
3868 asection
**local_sections
)
3870 struct elf_i386_link_hash_table
*htab
;
3871 Elf_Internal_Shdr
*symtab_hdr
;
3872 struct elf_link_hash_entry
**sym_hashes
;
3873 bfd_vma
*local_got_offsets
;
3874 bfd_vma
*local_tlsdesc_gotents
;
3875 Elf_Internal_Rela
*rel
;
3876 Elf_Internal_Rela
*wrel
;
3877 Elf_Internal_Rela
*relend
;
3878 bfd_boolean is_vxworks_tls
;
3879 unsigned plt_entry_size
;
3881 BFD_ASSERT (is_i386_elf (input_bfd
));
3883 /* Skip if check_relocs failed. */
3884 if (input_section
->check_relocs_failed
)
3887 htab
= elf_i386_hash_table (info
);
3890 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3891 sym_hashes
= elf_sym_hashes (input_bfd
);
3892 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3893 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3894 /* We have to handle relocations in vxworks .tls_vars sections
3895 specially, because the dynamic loader is 'weird'. */
3896 is_vxworks_tls
= ((get_elf_i386_backend_data (output_bfd
)->os
3898 && bfd_link_pic (info
)
3899 && !strcmp (input_section
->output_section
->name
,
3902 elf_i386_set_tls_module_base (info
);
3904 plt_entry_size
= htab
->plt
.plt_entry_size
;
3906 rel
= wrel
= relocs
;
3907 relend
= relocs
+ input_section
->reloc_count
;
3908 for (; rel
< relend
; wrel
++, rel
++)
3910 unsigned int r_type
;
3911 reloc_howto_type
*howto
;
3912 unsigned long r_symndx
;
3913 struct elf_link_hash_entry
*h
;
3914 struct elf_i386_link_hash_entry
*eh
;
3915 Elf_Internal_Sym
*sym
;
3917 bfd_vma off
, offplt
, plt_offset
;
3919 bfd_boolean unresolved_reloc
;
3920 bfd_reloc_status_type r
;
3924 asection
*resolved_plt
;
3925 bfd_boolean resolved_to_zero
;
3926 bfd_boolean relative_reloc
;
3928 r_type
= ELF32_R_TYPE (rel
->r_info
);
3929 if (r_type
== R_386_GNU_VTINHERIT
3930 || r_type
== R_386_GNU_VTENTRY
)
3937 if ((indx
= r_type
) >= R_386_standard
3938 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3939 >= R_386_ext
- R_386_standard
)
3940 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3941 >= R_386_ext2
- R_386_ext
))
3942 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
3944 howto
= elf_howto_table
+ indx
;
3946 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3950 unresolved_reloc
= FALSE
;
3951 if (r_symndx
< symtab_hdr
->sh_info
)
3953 sym
= local_syms
+ r_symndx
;
3954 sec
= local_sections
[r_symndx
];
3955 relocation
= (sec
->output_section
->vma
3956 + sec
->output_offset
3958 st_size
= sym
->st_size
;
3960 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3961 && ((sec
->flags
& SEC_MERGE
) != 0
3962 || (bfd_link_relocatable (info
)
3963 && sec
->output_offset
!= 0)))
3966 bfd_byte
*where
= contents
+ rel
->r_offset
;
3968 switch (howto
->size
)
3971 addend
= bfd_get_8 (input_bfd
, where
);
3972 if (howto
->pc_relative
)
3974 addend
= (addend
^ 0x80) - 0x80;
3979 addend
= bfd_get_16 (input_bfd
, where
);
3980 if (howto
->pc_relative
)
3982 addend
= (addend
^ 0x8000) - 0x8000;
3987 addend
= bfd_get_32 (input_bfd
, where
);
3988 if (howto
->pc_relative
)
3990 addend
= (addend
^ 0x80000000) - 0x80000000;
3998 if (bfd_link_relocatable (info
))
3999 addend
+= sec
->output_offset
;
4002 asection
*msec
= sec
;
4003 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
4005 addend
-= relocation
;
4006 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4009 switch (howto
->size
)
4012 /* FIXME: overflow checks. */
4013 if (howto
->pc_relative
)
4015 bfd_put_8 (input_bfd
, addend
, where
);
4018 if (howto
->pc_relative
)
4020 bfd_put_16 (input_bfd
, addend
, where
);
4023 if (howto
->pc_relative
)
4025 bfd_put_32 (input_bfd
, addend
, where
);
4029 else if (!bfd_link_relocatable (info
)
4030 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4032 /* Relocate against local STT_GNU_IFUNC symbol. */
4033 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
4038 /* Set STT_GNU_IFUNC symbol value. */
4039 h
->root
.u
.def
.value
= sym
->st_value
;
4040 h
->root
.u
.def
.section
= sec
;
4045 bfd_boolean warned ATTRIBUTE_UNUSED
;
4046 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4048 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4049 r_symndx
, symtab_hdr
, sym_hashes
,
4051 unresolved_reloc
, warned
, ignored
);
4055 if (sec
!= NULL
&& discarded_section (sec
))
4057 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4058 contents
+ rel
->r_offset
);
4059 wrel
->r_offset
= rel
->r_offset
;
4063 /* For ld -r, remove relocations in debug sections against
4064 sections defined in discarded sections. Not done for
4065 eh_frame editing code expects to be present. */
4066 if (bfd_link_relocatable (info
)
4067 && (input_section
->flags
& SEC_DEBUGGING
))
4073 if (bfd_link_relocatable (info
))
4080 eh
= (struct elf_i386_link_hash_entry
*) h
;
4082 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4083 it here if it is defined in a non-shared object. */
4085 && h
->type
== STT_GNU_IFUNC
4088 asection
*gotplt
, *base_got
;
4092 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4094 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4095 sections because such sections are not SEC_ALLOC and
4096 thus ld.so will not process them. */
4097 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4102 /* STT_GNU_IFUNC symbol must go through PLT. */
4103 if (htab
->elf
.splt
!= NULL
)
4105 if (htab
->plt_second
!= NULL
)
4107 resolved_plt
= htab
->plt_second
;
4108 plt_offset
= eh
->plt_second
.offset
;
4112 resolved_plt
= htab
->elf
.splt
;
4113 plt_offset
= h
->plt
.offset
;
4115 gotplt
= htab
->elf
.sgotplt
;
4119 resolved_plt
= htab
->elf
.iplt
;
4120 plt_offset
= h
->plt
.offset
;
4121 gotplt
= htab
->elf
.igotplt
;
4131 base_got
= htab
->elf
.sgot
;
4132 off
= h
->got
.offset
;
4134 if (base_got
== NULL
)
4137 if (off
== (bfd_vma
) -1)
4139 /* We can't use h->got.offset here to save state, or
4140 even just remember the offset, as finish_dynamic_symbol
4141 would use that as offset into .got. */
4143 if (h
->plt
.offset
== (bfd_vma
) -1)
4146 if (htab
->elf
.splt
!= NULL
)
4148 plt_index
= (h
->plt
.offset
/ plt_entry_size
4149 - htab
->plt
.has_plt0
);
4150 off
= (plt_index
+ 3) * 4;
4151 base_got
= htab
->elf
.sgotplt
;
4155 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4156 off
= plt_index
* 4;
4157 base_got
= htab
->elf
.igotplt
;
4160 if (h
->dynindx
== -1
4164 /* This references the local defitionion. We must
4165 initialize this entry in the global offset table.
4166 Since the offset must always be a multiple of 8,
4167 we use the least significant bit to record
4168 whether we have initialized it already.
4170 When doing a dynamic link, we create a .rela.got
4171 relocation entry to initialize the value. This
4172 is done in the finish_dynamic_symbol routine. */
4177 bfd_put_32 (output_bfd
, relocation
,
4178 base_got
->contents
+ off
);
4186 relocation
= (base_got
->output_section
->vma
4187 + base_got
->output_offset
+ off
4188 - gotplt
->output_section
->vma
4189 - gotplt
->output_offset
);
4191 if (rel
->r_offset
> 1
4192 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4193 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4195 if (bfd_link_pic (info
))
4196 goto disallow_got32
;
4198 /* Add the GOT base if there is no base register. */
4199 relocation
+= (gotplt
->output_section
->vma
4200 + gotplt
->output_offset
);
4202 else if (htab
->elf
.splt
== NULL
)
4204 /* Adjust for static executables. */
4205 relocation
+= gotplt
->output_offset
;
4211 if (h
->plt
.offset
== (bfd_vma
) -1)
4213 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4214 if (r_type
== R_386_32
4215 && (input_section
->flags
& SEC_CODE
) == 0)
4216 goto do_ifunc_pointer
;
4217 goto bad_ifunc_reloc
;
4220 relocation
= (resolved_plt
->output_section
->vma
4221 + resolved_plt
->output_offset
+ plt_offset
);
4227 if (h
->root
.root
.string
)
4228 name
= h
->root
.root
.string
;
4230 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4233 /* xgettext:c-format */
4234 (_("%B: relocation %s against STT_GNU_IFUNC "
4235 "symbol `%s' isn't supported"), input_bfd
,
4237 bfd_set_error (bfd_error_bad_value
);
4241 /* Generate dynamic relcoation only when there is a
4242 non-GOT reference in a shared object. */
4243 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4244 || h
->plt
.offset
== (bfd_vma
) -1)
4246 Elf_Internal_Rela outrel
;
4251 /* Need a dynamic relocation to get the real function
4253 offset
= _bfd_elf_section_offset (output_bfd
,
4257 if (offset
== (bfd_vma
) -1
4258 || offset
== (bfd_vma
) -2)
4261 outrel
.r_offset
= (input_section
->output_section
->vma
4262 + input_section
->output_offset
4265 if (h
->dynindx
== -1
4267 || bfd_link_executable (info
))
4269 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4270 h
->root
.root
.string
,
4271 h
->root
.u
.def
.section
->owner
);
4273 /* This symbol is resolved locally. */
4274 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4275 bfd_put_32 (output_bfd
,
4276 (h
->root
.u
.def
.value
4277 + h
->root
.u
.def
.section
->output_section
->vma
4278 + h
->root
.u
.def
.section
->output_offset
),
4282 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4284 /* Dynamic relocations are stored in
4285 1. .rel.ifunc section in PIC object.
4286 2. .rel.got section in dynamic executable.
4287 3. .rel.iplt section in static executable. */
4288 if (bfd_link_pic (info
))
4289 sreloc
= htab
->elf
.irelifunc
;
4290 else if (htab
->elf
.splt
!= NULL
)
4291 sreloc
= htab
->elf
.srelgot
;
4293 sreloc
= htab
->elf
.irelplt
;
4294 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4296 /* If this reloc is against an external symbol, we
4297 do not want to fiddle with the addend. Otherwise,
4298 we need to include the symbol value so that it
4299 becomes an addend for the dynamic reloc. For an
4300 internal symbol, we have updated addend. */
4309 relocation
-= (gotplt
->output_section
->vma
4310 + gotplt
->output_offset
);
4315 resolved_to_zero
= (eh
!= NULL
4316 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4323 /* Avoid optimizing _DYNAMIC since ld.so may use its
4324 link-time address. */
4325 if (h
== htab
->elf
.hdynamic
)
4328 if (bfd_link_pic (info
))
4330 /* It is OK to convert mov to lea and convert indirect
4331 branch to direct branch. It is OK to convert adc,
4332 add, and, cmp, or, sbb, sub, test, xor only when PIC
4334 unsigned int opcode
, addend
;
4335 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4338 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4339 if (opcode
!= 0x8b && opcode
!= 0xff)
4343 /* Resolve "mov GOT[(%reg)], %reg",
4344 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
4345 and "binop foo@GOT[(%reg)], %reg". */
4347 || (h
->plt
.offset
== (bfd_vma
) -1
4348 && h
->got
.offset
== (bfd_vma
) -1)
4349 || htab
->elf
.sgotplt
== NULL
)
4352 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
4353 + htab
->elf
.sgotplt
->output_offset
);
4355 /* It is relative to .got.plt section. */
4356 if (h
->got
.offset
!= (bfd_vma
) -1)
4357 /* Use GOT entry. Mask off the least significant bit in
4358 GOT offset which may be set by R_386_GOT32 processing
4360 relocation
= (htab
->elf
.sgot
->output_section
->vma
4361 + htab
->elf
.sgot
->output_offset
4362 + (h
->got
.offset
& ~1) - offplt
);
4364 /* Use GOTPLT entry. */
4365 relocation
= (h
->plt
.offset
/ plt_entry_size
4366 - htab
->plt
.has_plt0
+ 3) * 4;
4368 if (!bfd_link_pic (info
))
4370 /* If not PIC, add the .got.plt section address for
4371 baseless addressing. */
4373 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4374 if ((modrm
& 0xc7) == 0x5)
4375 relocation
+= offplt
;
4378 unresolved_reloc
= FALSE
;
4383 /* Relocation is to the entry for this symbol in the global
4385 if (htab
->elf
.sgot
== NULL
)
4388 relative_reloc
= FALSE
;
4393 off
= h
->got
.offset
;
4394 dyn
= htab
->elf
.dynamic_sections_created
;
4395 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4396 bfd_link_pic (info
),
4398 || (bfd_link_pic (info
)
4399 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4400 || (ELF_ST_VISIBILITY (h
->other
)
4401 && h
->root
.type
== bfd_link_hash_undefweak
))
4403 /* This is actually a static link, or it is a
4404 -Bsymbolic link and the symbol is defined
4405 locally, or the symbol was forced to be local
4406 because of a version file. We must initialize
4407 this entry in the global offset table. Since the
4408 offset must always be a multiple of 4, we use the
4409 least significant bit to record whether we have
4410 initialized it already.
4412 When doing a dynamic link, we create a .rel.got
4413 relocation entry to initialize the value. This
4414 is done in the finish_dynamic_symbol routine. */
4419 bfd_put_32 (output_bfd
, relocation
,
4420 htab
->elf
.sgot
->contents
+ off
);
4423 if (h
->dynindx
== -1
4425 && h
->root
.type
!= bfd_link_hash_undefweak
4426 && bfd_link_pic (info
))
4428 /* PR ld/21402: If this symbol isn't dynamic
4429 in PIC, generate R_386_RELATIVE here. */
4430 eh
->no_finish_dynamic_symbol
= 1;
4431 relative_reloc
= TRUE
;
4436 unresolved_reloc
= FALSE
;
4440 if (local_got_offsets
== NULL
)
4443 off
= local_got_offsets
[r_symndx
];
4445 /* The offset must always be a multiple of 4. We use
4446 the least significant bit to record whether we have
4447 already generated the necessary reloc. */
4452 bfd_put_32 (output_bfd
, relocation
,
4453 htab
->elf
.sgot
->contents
+ off
);
4454 local_got_offsets
[r_symndx
] |= 1;
4456 if (bfd_link_pic (info
))
4457 relative_reloc
= TRUE
;
4464 Elf_Internal_Rela outrel
;
4466 s
= htab
->elf
.srelgot
;
4470 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4471 + htab
->elf
.sgot
->output_offset
4473 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4474 elf_append_rel (output_bfd
, s
, &outrel
);
4477 if (off
>= (bfd_vma
) -2)
4480 relocation
= (htab
->elf
.sgot
->output_section
->vma
4481 + htab
->elf
.sgot
->output_offset
+ off
);
4482 if (rel
->r_offset
> 1
4483 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4484 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4486 if (bfd_link_pic (info
))
4488 /* For PIC, disallow R_386_GOT32 without a base
4489 register, except for "lea foo@GOT, %reg", since
4490 we don't know what the GOT base is. */
4494 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
4495 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4498 name
= h
->root
.root
.string
;
4501 /* xgettext:c-format */
4502 (_("%B: direct GOT relocation %s against `%s'"
4503 " without base register can not be used"
4504 " when making a shared object"),
4505 input_bfd
, howto
->name
, name
);
4506 bfd_set_error (bfd_error_bad_value
);
4512 /* Subtract the .got.plt section address only with a base
4514 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
4515 + htab
->elf
.sgotplt
->output_offset
);
4521 /* Relocation is relative to the start of the global offset
4524 /* Check to make sure it isn't a protected function or data
4525 symbol for shared library since it may not be local when
4526 used as function address or with copy relocation. We also
4527 need to make sure that a symbol is referenced locally. */
4528 if (!bfd_link_executable (info
) && h
)
4530 if (!h
->def_regular
)
4534 switch (ELF_ST_VISIBILITY (h
->other
))
4537 v
= _("hidden symbol");
4540 v
= _("internal symbol");
4543 v
= _("protected symbol");
4551 /* xgettext:c-format */
4552 (_("%B: relocation R_386_GOTOFF against undefined %s"
4553 " `%s' can not be used when making a shared object"),
4554 input_bfd
, v
, h
->root
.root
.string
);
4555 bfd_set_error (bfd_error_bad_value
);
4558 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
4559 && (h
->type
== STT_FUNC
4560 || h
->type
== STT_OBJECT
)
4561 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4564 /* xgettext:c-format */
4565 (_("%B: relocation R_386_GOTOFF against protected %s"
4566 " `%s' can not be used when making a shared object"),
4568 h
->type
== STT_FUNC
? "function" : "data",
4569 h
->root
.root
.string
);
4570 bfd_set_error (bfd_error_bad_value
);
4575 /* Note that sgot is not involved in this
4576 calculation. We always want the start of .got.plt. If we
4577 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4578 permitted by the ABI, we might have to change this
4580 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4581 + htab
->elf
.sgotplt
->output_offset
;
4585 /* Use global offset table as symbol value. */
4586 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4587 + htab
->elf
.sgotplt
->output_offset
;
4588 unresolved_reloc
= FALSE
;
4592 /* Relocation is to the entry for this symbol in the
4593 procedure linkage table. */
4595 /* Resolve a PLT32 reloc against a local symbol directly,
4596 without using the procedure linkage table. */
4600 if ((h
->plt
.offset
== (bfd_vma
) -1
4601 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4602 || htab
->elf
.splt
== NULL
)
4604 /* We didn't make a PLT entry for this symbol. This
4605 happens when statically linking PIC code, or when
4606 using -Bsymbolic. */
4610 if (h
->plt
.offset
!= (bfd_vma
) -1)
4612 if (htab
->plt_second
!= NULL
)
4614 resolved_plt
= htab
->plt_second
;
4615 plt_offset
= eh
->plt_second
.offset
;
4619 resolved_plt
= htab
->elf
.splt
;
4620 plt_offset
= h
->plt
.offset
;
4625 resolved_plt
= htab
->plt_got
;
4626 plt_offset
= eh
->plt_got
.offset
;
4629 relocation
= (resolved_plt
->output_section
->vma
4630 + resolved_plt
->output_offset
4632 unresolved_reloc
= FALSE
;
4636 /* Set to symbol size. */
4637 relocation
= st_size
;
4642 if ((input_section
->flags
& SEC_ALLOC
) == 0
4646 /* Copy dynamic function pointer relocations. Don't generate
4647 dynamic relocations against resolved undefined weak symbols
4648 in PIE, except for R_386_PC32. */
4649 if ((bfd_link_pic (info
)
4651 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4652 && (!resolved_to_zero
4653 || r_type
== R_386_PC32
))
4654 || h
->root
.type
!= bfd_link_hash_undefweak
))
4655 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
4656 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4657 || (ELIMINATE_COPY_RELOCS
4658 && !bfd_link_pic (info
)
4662 || eh
->func_pointer_refcount
> 0
4663 || (h
->root
.type
== bfd_link_hash_undefweak
4664 && !resolved_to_zero
))
4665 && ((h
->def_dynamic
&& !h
->def_regular
)
4666 /* Undefined weak symbol is bound locally when
4668 || h
->root
.type
== bfd_link_hash_undefweak
)))
4670 Elf_Internal_Rela outrel
;
4671 bfd_boolean skip
, relocate
;
4674 /* When generating a shared object, these relocations
4675 are copied into the output file to be resolved at run
4682 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4684 if (outrel
.r_offset
== (bfd_vma
) -1)
4686 else if (outrel
.r_offset
== (bfd_vma
) -2)
4687 skip
= TRUE
, relocate
= TRUE
;
4688 outrel
.r_offset
+= (input_section
->output_section
->vma
4689 + input_section
->output_offset
);
4692 memset (&outrel
, 0, sizeof outrel
);
4695 && (r_type
== R_386_PC32
4696 || !(bfd_link_executable (info
)
4697 || SYMBOLIC_BIND (info
, h
))
4698 || !h
->def_regular
))
4699 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4702 /* This symbol is local, or marked to become local. */
4704 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4707 sreloc
= elf_section_data (input_section
)->sreloc
;
4709 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4711 r
= bfd_reloc_notsupported
;
4712 goto check_relocation_error
;
4715 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4717 /* If this reloc is against an external symbol, we do
4718 not want to fiddle with the addend. Otherwise, we
4719 need to include the symbol value so that it becomes
4720 an addend for the dynamic reloc. */
4727 if (!bfd_link_executable (info
))
4729 Elf_Internal_Rela outrel
;
4732 outrel
.r_offset
= rel
->r_offset
4733 + input_section
->output_section
->vma
4734 + input_section
->output_offset
;
4735 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4736 sreloc
= elf_section_data (input_section
)->sreloc
;
4739 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4744 case R_386_TLS_GOTDESC
:
4745 case R_386_TLS_DESC_CALL
:
4746 case R_386_TLS_IE_32
:
4747 case R_386_TLS_GOTIE
:
4748 tls_type
= GOT_UNKNOWN
;
4749 if (h
== NULL
&& local_got_offsets
)
4750 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
4752 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
4753 if (tls_type
== GOT_TLS_IE
)
4754 tls_type
= GOT_TLS_IE_NEG
;
4756 if (! elf_i386_tls_transition (info
, input_bfd
,
4757 input_section
, contents
,
4758 symtab_hdr
, sym_hashes
,
4759 &r_type
, tls_type
, rel
,
4760 relend
, h
, r_symndx
, TRUE
))
4763 if (r_type
== R_386_TLS_LE_32
)
4765 BFD_ASSERT (! unresolved_reloc
);
4766 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4771 /* GD->LE transition. */
4772 type
= *(contents
+ rel
->r_offset
- 2);
4776 leal foo@tlsgd(,%ebx,1), %eax
4777 call ___tls_get_addr@PLT
4780 subl $foo@tpoff, %eax
4781 (6 byte form of subl). */
4782 roff
= rel
->r_offset
+ 5;
4787 leal foo@tlsgd(%ebx), %eax
4788 call ___tls_get_addr@PLT
4791 leal foo@tlsgd(%reg), %eax
4792 call *___tls_get_addr@GOT(%reg)
4793 which may be converted to
4794 addr32 call ___tls_get_addr
4796 movl %gs:0, %eax; subl $foo@tpoff, %eax
4797 (6 byte form of subl). */
4798 roff
= rel
->r_offset
+ 6;
4800 memcpy (contents
+ roff
- 8,
4801 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4802 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4804 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4809 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4811 /* GDesc -> LE transition.
4812 It's originally something like:
4813 leal x@tlsdesc(%ebx), %eax
4817 Registers other than %eax may be set up here. */
4822 roff
= rel
->r_offset
;
4823 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4825 /* Now modify the instruction as appropriate. */
4826 /* aoliva FIXME: remove the above and xor the byte
4828 bfd_put_8 (output_bfd
, val
^ 0x86,
4829 contents
+ roff
- 1);
4830 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4834 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4836 /* GDesc -> LE transition.
4844 roff
= rel
->r_offset
;
4845 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4846 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4849 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4853 /* IE->LE transition:
4854 Originally it can be one of:
4862 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4865 /* movl foo, %eax. */
4866 bfd_put_8 (output_bfd
, 0xb8,
4867 contents
+ rel
->r_offset
- 1);
4873 type
= bfd_get_8 (input_bfd
,
4874 contents
+ rel
->r_offset
- 2);
4879 bfd_put_8 (output_bfd
, 0xc7,
4880 contents
+ rel
->r_offset
- 2);
4881 bfd_put_8 (output_bfd
,
4882 0xc0 | ((val
>> 3) & 7),
4883 contents
+ rel
->r_offset
- 1);
4887 bfd_put_8 (output_bfd
, 0x81,
4888 contents
+ rel
->r_offset
- 2);
4889 bfd_put_8 (output_bfd
,
4890 0xc0 | ((val
>> 3) & 7),
4891 contents
+ rel
->r_offset
- 1);
4898 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4899 contents
+ rel
->r_offset
);
4904 unsigned int val
, type
;
4906 /* {IE_32,GOTIE}->LE transition:
4907 Originally it can be one of:
4908 subl foo(%reg1), %reg2
4909 movl foo(%reg1), %reg2
4910 addl foo(%reg1), %reg2
4913 movl $foo, %reg2 (6 byte form)
4914 addl $foo, %reg2. */
4915 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4916 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4920 bfd_put_8 (output_bfd
, 0xc7,
4921 contents
+ rel
->r_offset
- 2);
4922 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4923 contents
+ rel
->r_offset
- 1);
4925 else if (type
== 0x2b)
4928 bfd_put_8 (output_bfd
, 0x81,
4929 contents
+ rel
->r_offset
- 2);
4930 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4931 contents
+ rel
->r_offset
- 1);
4933 else if (type
== 0x03)
4936 bfd_put_8 (output_bfd
, 0x81,
4937 contents
+ rel
->r_offset
- 2);
4938 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4939 contents
+ rel
->r_offset
- 1);
4943 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4944 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4945 contents
+ rel
->r_offset
);
4947 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4948 contents
+ rel
->r_offset
);
4953 if (htab
->elf
.sgot
== NULL
)
4958 off
= h
->got
.offset
;
4959 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
4963 if (local_got_offsets
== NULL
)
4966 off
= local_got_offsets
[r_symndx
];
4967 offplt
= local_tlsdesc_gotents
[r_symndx
];
4974 Elf_Internal_Rela outrel
;
4978 if (htab
->elf
.srelgot
== NULL
)
4981 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4983 if (GOT_TLS_GDESC_P (tls_type
))
4986 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4987 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4988 <= htab
->elf
.sgotplt
->size
);
4989 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4990 + htab
->elf
.sgotplt
->output_offset
4992 + htab
->sgotplt_jump_table_size
);
4993 sreloc
= htab
->elf
.srelplt
;
4994 loc
= sreloc
->contents
;
4995 loc
+= (htab
->next_tls_desc_index
++
4996 * sizeof (Elf32_External_Rel
));
4997 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4998 <= sreloc
->contents
+ sreloc
->size
);
4999 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
5002 BFD_ASSERT (! unresolved_reloc
);
5003 bfd_put_32 (output_bfd
,
5004 relocation
- elf_i386_dtpoff_base (info
),
5005 htab
->elf
.sgotplt
->contents
+ offplt
5006 + htab
->sgotplt_jump_table_size
+ 4);
5010 bfd_put_32 (output_bfd
, 0,
5011 htab
->elf
.sgotplt
->contents
+ offplt
5012 + htab
->sgotplt_jump_table_size
+ 4);
5016 sreloc
= htab
->elf
.srelgot
;
5018 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5019 + htab
->elf
.sgot
->output_offset
+ off
);
5021 if (GOT_TLS_GD_P (tls_type
))
5022 dr_type
= R_386_TLS_DTPMOD32
;
5023 else if (GOT_TLS_GDESC_P (tls_type
))
5025 else if (tls_type
== GOT_TLS_IE_POS
)
5026 dr_type
= R_386_TLS_TPOFF
;
5028 dr_type
= R_386_TLS_TPOFF32
;
5030 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
5031 bfd_put_32 (output_bfd
,
5032 relocation
- elf_i386_dtpoff_base (info
),
5033 htab
->elf
.sgot
->contents
+ off
);
5034 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
5035 bfd_put_32 (output_bfd
,
5036 elf_i386_dtpoff_base (info
) - relocation
,
5037 htab
->elf
.sgot
->contents
+ off
);
5038 else if (dr_type
!= R_386_TLS_DESC
)
5039 bfd_put_32 (output_bfd
, 0,
5040 htab
->elf
.sgot
->contents
+ off
);
5041 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5043 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5045 if (GOT_TLS_GD_P (tls_type
))
5049 BFD_ASSERT (! unresolved_reloc
);
5050 bfd_put_32 (output_bfd
,
5051 relocation
- elf_i386_dtpoff_base (info
),
5052 htab
->elf
.sgot
->contents
+ off
+ 4);
5056 bfd_put_32 (output_bfd
, 0,
5057 htab
->elf
.sgot
->contents
+ off
+ 4);
5058 outrel
.r_info
= ELF32_R_INFO (indx
,
5059 R_386_TLS_DTPOFF32
);
5060 outrel
.r_offset
+= 4;
5061 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5064 else if (tls_type
== GOT_TLS_IE_BOTH
)
5066 bfd_put_32 (output_bfd
,
5068 ? relocation
- elf_i386_dtpoff_base (info
)
5070 htab
->elf
.sgot
->contents
+ off
+ 4);
5071 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5072 outrel
.r_offset
+= 4;
5073 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5080 local_got_offsets
[r_symndx
] |= 1;
5083 if (off
>= (bfd_vma
) -2
5084 && ! GOT_TLS_GDESC_P (tls_type
))
5086 if (r_type
== R_386_TLS_GOTDESC
5087 || r_type
== R_386_TLS_DESC_CALL
)
5089 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
5090 unresolved_reloc
= FALSE
;
5092 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5094 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
5095 + htab
->elf
.sgotplt
->output_offset
;
5096 relocation
= htab
->elf
.sgot
->output_section
->vma
5097 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
5098 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
5099 && tls_type
== GOT_TLS_IE_BOTH
)
5101 if (r_type
== R_386_TLS_IE
)
5102 relocation
+= g_o_t
;
5103 unresolved_reloc
= FALSE
;
5105 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
5107 unsigned int val
, type
;
5110 /* GD->IE transition. */
5111 type
= *(contents
+ rel
->r_offset
- 2);
5112 val
= *(contents
+ rel
->r_offset
- 1);
5116 leal foo@tlsgd(,%ebx,1), %eax
5117 call ___tls_get_addr@PLT
5120 subl $foo@gottpoff(%ebx), %eax. */
5122 roff
= rel
->r_offset
- 3;
5127 leal foo@tlsgd(%ebx), %eax
5128 call ___tls_get_addr@PLT
5131 leal foo@tlsgd(%reg), %eax
5132 call *___tls_get_addr@GOT(%reg)
5133 which may be converted to
5134 addr32 call ___tls_get_addr
5137 subl $foo@gottpoff(%reg), %eax. */
5138 roff
= rel
->r_offset
- 2;
5140 memcpy (contents
+ roff
,
5141 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
5142 contents
[roff
+ 7] = 0x80 | (val
& 7);
5143 /* If foo is used only with foo@gotntpoff(%reg) and
5144 foo@indntpoff, but not with foo@gottpoff(%reg), change
5145 subl $foo@gottpoff(%reg), %eax
5147 addl $foo@gotntpoff(%reg), %eax. */
5148 if (tls_type
== GOT_TLS_IE_POS
)
5149 contents
[roff
+ 6] = 0x03;
5150 bfd_put_32 (output_bfd
,
5151 htab
->elf
.sgot
->output_section
->vma
5152 + htab
->elf
.sgot
->output_offset
+ off
5153 - htab
->elf
.sgotplt
->output_section
->vma
5154 - htab
->elf
.sgotplt
->output_offset
,
5155 contents
+ roff
+ 8);
5156 /* Skip R_386_PLT32 and R_386_GOT32X. */
5161 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
5163 /* GDesc -> IE transition.
5164 It's originally something like:
5165 leal x@tlsdesc(%ebx), %eax
5168 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
5170 movl x@gottpoff(%ebx), %eax # before negl %eax
5172 Registers other than %eax may be set up here. */
5176 /* First, make sure it's a leal adding ebx to a 32-bit
5177 offset into any register, although it's probably
5178 almost always going to be eax. */
5179 roff
= rel
->r_offset
;
5181 /* Now modify the instruction as appropriate. */
5182 /* To turn a leal into a movl in the form we use it, it
5183 suffices to change the first byte from 0x8d to 0x8b.
5184 aoliva FIXME: should we decide to keep the leal, all
5185 we have to do is remove the statement below, and
5186 adjust the relaxation of R_386_TLS_DESC_CALL. */
5187 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5189 if (tls_type
== GOT_TLS_IE_BOTH
)
5192 bfd_put_32 (output_bfd
,
5193 htab
->elf
.sgot
->output_section
->vma
5194 + htab
->elf
.sgot
->output_offset
+ off
5195 - htab
->elf
.sgotplt
->output_section
->vma
5196 - htab
->elf
.sgotplt
->output_offset
,
5200 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
5202 /* GDesc -> IE transition.
5210 depending on how we transformed the TLS_GOTDESC above.
5215 roff
= rel
->r_offset
;
5217 /* Now modify the instruction as appropriate. */
5218 if (tls_type
!= GOT_TLS_IE_NEG
)
5221 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5222 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5227 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
5228 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
5238 if (! elf_i386_tls_transition (info
, input_bfd
,
5239 input_section
, contents
,
5240 symtab_hdr
, sym_hashes
,
5241 &r_type
, GOT_UNKNOWN
, rel
,
5242 relend
, h
, r_symndx
, TRUE
))
5245 if (r_type
!= R_386_TLS_LDM
)
5247 /* LD->LE transition. Change
5248 leal foo@tlsldm(%ebx) %eax
5249 call ___tls_get_addr@PLT
5253 leal 0(%esi,1), %esi
5255 leal foo@tlsldm(%reg) %eax
5256 call *___tls_get_addr@GOT(%reg)
5257 which may be converted to
5258 addr32 call ___tls_get_addr
5261 leal 0(%esi), %esi */
5262 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
5263 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
5264 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
5265 memcpy (contents
+ rel
->r_offset
- 2,
5266 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
5268 memcpy (contents
+ rel
->r_offset
- 2,
5269 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
5270 /* Skip R_386_PC32/R_386_PLT32. */
5276 if (htab
->elf
.sgot
== NULL
)
5279 off
= htab
->tls_ldm_got
.offset
;
5284 Elf_Internal_Rela outrel
;
5286 if (htab
->elf
.srelgot
== NULL
)
5289 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5290 + htab
->elf
.sgot
->output_offset
+ off
);
5292 bfd_put_32 (output_bfd
, 0,
5293 htab
->elf
.sgot
->contents
+ off
);
5294 bfd_put_32 (output_bfd
, 0,
5295 htab
->elf
.sgot
->contents
+ off
+ 4);
5296 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
5297 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
5298 htab
->tls_ldm_got
.offset
|= 1;
5300 relocation
= htab
->elf
.sgot
->output_section
->vma
5301 + htab
->elf
.sgot
->output_offset
+ off
5302 - htab
->elf
.sgotplt
->output_section
->vma
5303 - htab
->elf
.sgotplt
->output_offset
;
5304 unresolved_reloc
= FALSE
;
5307 case R_386_TLS_LDO_32
:
5308 if (!bfd_link_executable (info
)
5309 || (input_section
->flags
& SEC_CODE
) == 0)
5310 relocation
-= elf_i386_dtpoff_base (info
);
5312 /* When converting LDO to LE, we must negate. */
5313 relocation
= -elf_i386_tpoff (info
, relocation
);
5316 case R_386_TLS_LE_32
:
5318 if (!bfd_link_executable (info
))
5320 Elf_Internal_Rela outrel
;
5323 outrel
.r_offset
= rel
->r_offset
5324 + input_section
->output_section
->vma
5325 + input_section
->output_offset
;
5326 if (h
!= NULL
&& h
->dynindx
!= -1)
5330 if (r_type
== R_386_TLS_LE_32
)
5331 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
5333 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5334 sreloc
= elf_section_data (input_section
)->sreloc
;
5337 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5340 else if (r_type
== R_386_TLS_LE_32
)
5341 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
5343 relocation
-= elf_i386_dtpoff_base (info
);
5345 else if (r_type
== R_386_TLS_LE_32
)
5346 relocation
= elf_i386_tpoff (info
, relocation
);
5348 relocation
= -elf_i386_tpoff (info
, relocation
);
5355 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5356 because such sections are not SEC_ALLOC and thus ld.so will
5357 not process them. */
5358 if (unresolved_reloc
5359 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5361 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5362 rel
->r_offset
) != (bfd_vma
) -1)
5365 /* xgettext:c-format */
5366 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
5371 h
->root
.root
.string
);
5376 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5377 contents
, rel
->r_offset
,
5380 check_relocation_error
:
5381 if (r
!= bfd_reloc_ok
)
5386 name
= h
->root
.root
.string
;
5389 name
= bfd_elf_string_from_elf_section (input_bfd
,
5390 symtab_hdr
->sh_link
,
5395 name
= bfd_section_name (input_bfd
, sec
);
5398 if (r
== bfd_reloc_overflow
)
5399 (*info
->callbacks
->reloc_overflow
)
5400 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5401 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5405 /* xgettext:c-format */
5406 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
5407 input_bfd
, input_section
,
5408 rel
->r_offset
, name
, (int) r
);
5419 Elf_Internal_Shdr
*rel_hdr
;
5420 size_t deleted
= rel
- wrel
;
5422 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5423 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5424 if (rel_hdr
->sh_size
== 0)
5426 /* It is too late to remove an empty reloc section. Leave
5428 ??? What is wrong with an empty section??? */
5429 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5432 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5433 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5434 input_section
->reloc_count
-= deleted
;
5440 /* Finish up dynamic symbol handling. We set the contents of various
5441 dynamic sections here. */
5444 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
5445 struct bfd_link_info
*info
,
5446 struct elf_link_hash_entry
*h
,
5447 Elf_Internal_Sym
*sym
)
5449 struct elf_i386_link_hash_table
*htab
;
5450 unsigned plt_entry_size
;
5451 const struct elf_i386_backend_data
*abed
;
5452 struct elf_i386_link_hash_entry
*eh
;
5453 bfd_boolean local_undefweak
;
5454 bfd_boolean use_plt_second
;
5456 htab
= elf_i386_hash_table (info
);
5460 abed
= get_elf_i386_backend_data (output_bfd
);
5461 plt_entry_size
= htab
->plt
.plt_entry_size
;
5463 /* Use the second PLT section only if there is .plt section. */
5464 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
5466 eh
= (struct elf_i386_link_hash_entry
*) h
;
5467 if (eh
->no_finish_dynamic_symbol
)
5470 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5471 resolved undefined weak symbols in executable so that their
5472 references have value 0 at run-time. */
5473 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5477 if (h
->plt
.offset
!= (bfd_vma
) -1)
5479 bfd_vma plt_index
, plt_offset
;
5481 Elf_Internal_Rela rel
;
5483 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
5485 /* When building a static executable, use .iplt, .igot.plt and
5486 .rel.iplt sections for STT_GNU_IFUNC symbols. */
5487 if (htab
->elf
.splt
!= NULL
)
5489 plt
= htab
->elf
.splt
;
5490 gotplt
= htab
->elf
.sgotplt
;
5491 relplt
= htab
->elf
.srelplt
;
5495 plt
= htab
->elf
.iplt
;
5496 gotplt
= htab
->elf
.igotplt
;
5497 relplt
= htab
->elf
.irelplt
;
5500 /* This symbol has an entry in the procedure linkage table. Set
5503 if ((h
->dynindx
== -1
5505 && !((h
->forced_local
|| bfd_link_executable (info
))
5507 && h
->type
== STT_GNU_IFUNC
))
5513 /* Get the index in the procedure linkage table which
5514 corresponds to this symbol. This is the index of this symbol
5515 in all the symbols for which we are making plt entries. The
5516 first entry in the procedure linkage table is reserved.
5518 Get the offset into the .got table of the entry that
5519 corresponds to this function. Each .got entry is 4 bytes.
5520 The first three are reserved.
5522 For static executables, we don't reserve anything. */
5524 if (plt
== htab
->elf
.splt
)
5526 got_offset
= (h
->plt
.offset
/ plt_entry_size
5527 - htab
->plt
.has_plt0
);
5528 got_offset
= (got_offset
+ 3) * 4;
5532 got_offset
= h
->plt
.offset
/ plt_entry_size
;
5533 got_offset
= got_offset
* 4;
5536 /* Fill in the entry in the procedure linkage table and update
5538 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
5543 const bfd_byte
*plt_entry
;
5544 if (bfd_link_pic (info
))
5545 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5547 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5548 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
5549 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
5551 resolved_plt
= htab
->plt_second
;
5552 plt_offset
= eh
->plt_second
.offset
;
5557 plt_offset
= h
->plt
.offset
;
5560 if (! bfd_link_pic (info
))
5562 bfd_put_32 (output_bfd
,
5563 (gotplt
->output_section
->vma
5564 + gotplt
->output_offset
5566 resolved_plt
->contents
+ plt_offset
5567 + htab
->plt
.plt_got_offset
);
5569 if (abed
->os
== is_vxworks
)
5571 int s
, k
, reloc_index
;
5573 /* Create the R_386_32 relocation referencing the GOT
5574 for this PLT entry. */
5576 /* S: Current slot number (zero-based). */
5577 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
5578 / htab
->plt
.plt_entry_size
);
5579 /* K: Number of relocations for PLTResolve. */
5580 if (bfd_link_pic (info
))
5581 k
= PLTRESOLVE_RELOCS_SHLIB
;
5583 k
= PLTRESOLVE_RELOCS
;
5584 /* Skip the PLTresolve relocations, and the relocations for
5585 the other PLT slots. */
5586 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
5587 loc
= (htab
->srelplt2
->contents
+ reloc_index
5588 * sizeof (Elf32_External_Rel
));
5590 rel
.r_offset
= (plt
->output_section
->vma
5591 + plt
->output_offset
5592 + h
->plt
.offset
+ 2),
5593 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5594 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5596 /* Create the R_386_32 relocation referencing the beginning of
5597 the PLT for this GOT entry. */
5598 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5599 + htab
->elf
.sgotplt
->output_offset
5601 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5602 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5603 loc
+ sizeof (Elf32_External_Rel
));
5608 bfd_put_32 (output_bfd
, got_offset
,
5609 resolved_plt
->contents
+ plt_offset
5610 + htab
->plt
.plt_got_offset
);
5613 /* Fill in the entry in the global offset table. Leave the entry
5614 as zero for undefined weak symbol in PIE. No PLT relocation
5615 against undefined weak symbol in PIE. */
5616 if (!local_undefweak
)
5618 if (htab
->plt
.has_plt0
)
5619 bfd_put_32 (output_bfd
,
5620 (plt
->output_section
->vma
5621 + plt
->output_offset
5623 + htab
->lazy_plt
->plt_lazy_offset
),
5624 gotplt
->contents
+ got_offset
);
5626 /* Fill in the entry in the .rel.plt section. */
5627 rel
.r_offset
= (gotplt
->output_section
->vma
5628 + gotplt
->output_offset
5630 if (h
->dynindx
== -1
5631 || ((bfd_link_executable (info
)
5632 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5634 && h
->type
== STT_GNU_IFUNC
))
5636 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5637 h
->root
.root
.string
,
5638 h
->root
.u
.def
.section
->owner
);
5640 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5641 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5642 in the .got.plt section. */
5643 bfd_put_32 (output_bfd
,
5644 (h
->root
.u
.def
.value
5645 + h
->root
.u
.def
.section
->output_section
->vma
5646 + h
->root
.u
.def
.section
->output_offset
),
5647 gotplt
->contents
+ got_offset
);
5648 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5649 /* R_386_IRELATIVE comes last. */
5650 plt_index
= htab
->next_irelative_index
--;
5654 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
5655 plt_index
= htab
->next_jump_slot_index
++;
5658 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5659 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5661 /* Don't fill the second and third slots in PLT entry for
5662 static executables nor without PLT0. */
5663 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
5665 bfd_put_32 (output_bfd
,
5666 plt_index
* sizeof (Elf32_External_Rel
),
5667 plt
->contents
+ h
->plt
.offset
5668 + htab
->lazy_plt
->plt_reloc_offset
);
5669 bfd_put_32 (output_bfd
,
5671 + htab
->lazy_plt
->plt_plt_offset
+ 4),
5672 (plt
->contents
+ h
->plt
.offset
5673 + htab
->lazy_plt
->plt_plt_offset
));
5677 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5679 bfd_vma got_offset
, plt_offset
;
5680 asection
*plt
, *got
, *gotplt
;
5681 const bfd_byte
*got_plt_entry
;
5683 /* Set the entry in the GOT procedure linkage table. */
5684 plt
= htab
->plt_got
;
5685 got
= htab
->elf
.sgot
;
5686 gotplt
= htab
->elf
.sgotplt
;
5687 got_offset
= h
->got
.offset
;
5689 if (got_offset
== (bfd_vma
) -1
5695 /* Fill in the entry in the GOT procedure linkage table. */
5696 if (! bfd_link_pic (info
))
5698 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5699 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
5703 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5704 got_offset
+= (got
->output_section
->vma
5705 + got
->output_offset
5706 - gotplt
->output_section
->vma
5707 - gotplt
->output_offset
);
5710 plt_offset
= eh
->plt_got
.offset
;
5711 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
5712 htab
->non_lazy_plt
->plt_entry_size
);
5713 bfd_put_32 (output_bfd
, got_offset
,
5714 (plt
->contents
+ plt_offset
5715 + htab
->non_lazy_plt
->plt_got_offset
));
5718 if (!local_undefweak
5720 && (h
->plt
.offset
!= (bfd_vma
) -1
5721 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5723 /* Mark the symbol as undefined, rather than as defined in
5724 the .plt section. Leave the value if there were any
5725 relocations where pointer equality matters (this is a clue
5726 for the dynamic linker, to make function pointer
5727 comparisons work between an application and shared
5728 library), otherwise set it to zero. If a function is only
5729 called from a binary, there is no need to slow down
5730 shared libraries because of that. */
5731 sym
->st_shndx
= SHN_UNDEF
;
5732 if (!h
->pointer_equality_needed
)
5736 /* Don't generate dynamic GOT relocation against undefined weak
5737 symbol in executable. */
5738 if (h
->got
.offset
!= (bfd_vma
) -1
5739 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
5740 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
5741 && !local_undefweak
)
5743 Elf_Internal_Rela rel
;
5744 asection
*relgot
= htab
->elf
.srelgot
;
5746 /* This symbol has an entry in the global offset table. Set it
5749 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5752 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5753 + htab
->elf
.sgot
->output_offset
5754 + (h
->got
.offset
& ~(bfd_vma
) 1));
5756 /* If this is a static link, or it is a -Bsymbolic link and the
5757 symbol is defined locally or was forced to be local because
5758 of a version file, we just want to emit a RELATIVE reloc.
5759 The entry in the global offset table will already have been
5760 initialized in the relocate_section function. */
5762 && h
->type
== STT_GNU_IFUNC
)
5764 if (h
->plt
.offset
== (bfd_vma
) -1)
5766 /* STT_GNU_IFUNC is referenced without PLT. */
5767 if (htab
->elf
.splt
== NULL
)
5769 /* use .rel[a].iplt section to store .got relocations
5770 in static executable. */
5771 relgot
= htab
->elf
.irelplt
;
5773 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5775 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5776 h
->root
.root
.string
,
5777 h
->root
.u
.def
.section
->owner
);
5779 bfd_put_32 (output_bfd
,
5780 (h
->root
.u
.def
.value
5781 + h
->root
.u
.def
.section
->output_section
->vma
5782 + h
->root
.u
.def
.section
->output_offset
),
5783 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5784 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5789 else if (bfd_link_pic (info
))
5791 /* Generate R_386_GLOB_DAT. */
5799 if (!h
->pointer_equality_needed
)
5802 /* For non-shared object, we can't use .got.plt, which
5803 contains the real function addres if we need pointer
5804 equality. We load the GOT entry with the PLT entry. */
5805 if (htab
->plt_second
!= NULL
)
5807 plt
= htab
->plt_second
;
5808 plt_offset
= eh
->plt_second
.offset
;
5812 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5813 plt_offset
= h
->plt
.offset
;
5815 bfd_put_32 (output_bfd
,
5816 (plt
->output_section
->vma
5817 + plt
->output_offset
+ plt_offset
),
5818 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5822 else if (bfd_link_pic (info
)
5823 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5825 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5826 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
5830 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5832 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5833 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5834 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
5837 elf_append_rel (output_bfd
, relgot
, &rel
);
5842 Elf_Internal_Rela rel
;
5845 /* This symbol needs a copy reloc. Set it up. */
5847 if (h
->dynindx
== -1
5848 || (h
->root
.type
!= bfd_link_hash_defined
5849 && h
->root
.type
!= bfd_link_hash_defweak
)
5850 || htab
->elf
.srelbss
== NULL
5851 || htab
->elf
.sreldynrelro
== NULL
)
5854 rel
.r_offset
= (h
->root
.u
.def
.value
5855 + h
->root
.u
.def
.section
->output_section
->vma
5856 + h
->root
.u
.def
.section
->output_offset
);
5857 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5858 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5859 s
= htab
->elf
.sreldynrelro
;
5861 s
= htab
->elf
.srelbss
;
5862 elf_append_rel (output_bfd
, s
, &rel
);
5868 /* Finish up local dynamic symbol handling. We set the contents of
5869 various dynamic sections here. */
5872 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5874 struct elf_link_hash_entry
*h
5875 = (struct elf_link_hash_entry
*) *slot
;
5876 struct bfd_link_info
*info
5877 = (struct bfd_link_info
*) inf
;
5879 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5883 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5884 here since undefined weak symbol may not be dynamic and may not be
5885 called for elf_i386_finish_dynamic_symbol. */
5888 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5891 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5892 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5894 if (h
->root
.type
!= bfd_link_hash_undefweak
5895 || h
->dynindx
!= -1)
5898 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5902 /* Used to decide how to sort relocs in an optimal manner for the
5903 dynamic linker, before writing them out. */
5905 static enum elf_reloc_type_class
5906 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5907 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5908 const Elf_Internal_Rela
*rela
)
5910 bfd
*abfd
= info
->output_bfd
;
5911 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5912 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5914 if (htab
->dynsym
!= NULL
5915 && htab
->dynsym
->contents
!= NULL
)
5917 /* Check relocation against STT_GNU_IFUNC symbol if there are
5919 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5920 if (r_symndx
!= STN_UNDEF
)
5922 Elf_Internal_Sym sym
;
5923 if (!bed
->s
->swap_symbol_in (abfd
,
5924 (htab
->dynsym
->contents
5925 + r_symndx
* sizeof (Elf32_External_Sym
)),
5929 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5930 return reloc_class_ifunc
;
5934 switch (ELF32_R_TYPE (rela
->r_info
))
5936 case R_386_IRELATIVE
:
5937 return reloc_class_ifunc
;
5938 case R_386_RELATIVE
:
5939 return reloc_class_relative
;
5940 case R_386_JUMP_SLOT
:
5941 return reloc_class_plt
;
5943 return reloc_class_copy
;
5945 return reloc_class_normal
;
5949 /* Finish up the dynamic sections. */
5952 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5953 struct bfd_link_info
*info
)
5955 struct elf_i386_link_hash_table
*htab
;
5958 const struct elf_i386_backend_data
*abed
;
5960 htab
= elf_i386_hash_table (info
);
5964 dynobj
= htab
->elf
.dynobj
;
5965 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5966 abed
= get_elf_i386_backend_data (output_bfd
);
5968 if (htab
->elf
.dynamic_sections_created
)
5970 Elf32_External_Dyn
*dyncon
, *dynconend
;
5972 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5975 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5976 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5977 for (; dyncon
< dynconend
; dyncon
++)
5979 Elf_Internal_Dyn dyn
;
5982 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5987 if (abed
->os
== is_vxworks
5988 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5993 s
= htab
->elf
.sgotplt
;
5994 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5998 s
= htab
->elf
.srelplt
;
5999 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6003 s
= htab
->elf
.srelplt
;
6004 dyn
.d_un
.d_val
= s
->size
;
6008 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6011 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6013 /* UnixWare sets the entsize of .plt to 4, although that doesn't
6014 really seem like the right value. */
6015 elf_section_data (htab
->elf
.splt
->output_section
)
6016 ->this_hdr
.sh_entsize
= 4;
6018 if (htab
->plt
.has_plt0
)
6020 /* Fill in the special first entry in the procedure linkage
6022 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
6023 htab
->lazy_plt
->plt0_entry_size
);
6024 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
6025 abed
->plt0_pad_byte
,
6026 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
6027 if (!bfd_link_pic (info
))
6029 bfd_put_32 (output_bfd
,
6030 (htab
->elf
.sgotplt
->output_section
->vma
6031 + htab
->elf
.sgotplt
->output_offset
6033 htab
->elf
.splt
->contents
6034 + htab
->lazy_plt
->plt0_got1_offset
);
6035 bfd_put_32 (output_bfd
,
6036 (htab
->elf
.sgotplt
->output_section
->vma
6037 + htab
->elf
.sgotplt
->output_offset
6039 htab
->elf
.splt
->contents
6040 + htab
->lazy_plt
->plt0_got2_offset
);
6042 if (abed
->os
== is_vxworks
)
6044 Elf_Internal_Rela rel
;
6045 int num_plts
= (htab
->elf
.splt
->size
6046 / htab
->plt
.plt_entry_size
) - 1;
6049 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6050 + 4. On IA32 we use REL relocations so the
6051 addend goes in the PLT directly. */
6052 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
6053 + htab
->elf
.splt
->output_offset
6054 + htab
->lazy_plt
->plt0_got1_offset
);
6055 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6057 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
6058 htab
->srelplt2
->contents
);
6059 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6061 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
6062 + htab
->elf
.splt
->output_offset
6063 + htab
->lazy_plt
->plt0_got2_offset
);
6064 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6066 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
6067 htab
->srelplt2
->contents
+
6068 sizeof (Elf32_External_Rel
));
6069 /* Correct the .rel.plt.unloaded relocations. */
6070 p
= htab
->srelplt2
->contents
;
6071 if (bfd_link_pic (info
))
6072 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
6074 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
6076 for (; num_plts
; num_plts
--)
6078 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
6079 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6081 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
6082 p
+= sizeof (Elf32_External_Rel
);
6084 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
6085 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
6087 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
6088 p
+= sizeof (Elf32_External_Rel
);
6095 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
6096 elf_section_data (htab
->plt_got
->output_section
)
6097 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6099 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
6100 elf_section_data (htab
->plt_second
->output_section
)
6101 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6104 /* Fill in the first three entries in the global offset table. */
6105 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
6107 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6110 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6114 bfd_put_32 (output_bfd
,
6116 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
6117 htab
->elf
.sgotplt
->contents
);
6118 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
6119 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
6121 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
6124 /* Adjust .eh_frame for .plt section. */
6125 if (htab
->plt_eh_frame
!= NULL
6126 && htab
->plt_eh_frame
->contents
!= NULL
)
6128 if (htab
->elf
.splt
!= NULL
6129 && htab
->elf
.splt
->size
!= 0
6130 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6131 && htab
->elf
.splt
->output_section
!= NULL
6132 && htab
->plt_eh_frame
->output_section
!= NULL
)
6134 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6135 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6136 + htab
->plt_eh_frame
->output_offset
6137 + PLT_FDE_START_OFFSET
;
6138 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6139 htab
->plt_eh_frame
->contents
6140 + PLT_FDE_START_OFFSET
);
6142 if (htab
->plt_eh_frame
->sec_info_type
6143 == SEC_INFO_TYPE_EH_FRAME
)
6145 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6147 htab
->plt_eh_frame
->contents
))
6152 /* Adjust .eh_frame for .plt.got section. */
6153 if (htab
->plt_got_eh_frame
!= NULL
6154 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6156 if (htab
->plt_got
!= NULL
6157 && htab
->plt_got
->size
!= 0
6158 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6159 && htab
->plt_got
->output_section
!= NULL
6160 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6162 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6163 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6164 + htab
->plt_got_eh_frame
->output_offset
6165 + PLT_FDE_START_OFFSET
;
6166 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6167 htab
->plt_got_eh_frame
->contents
6168 + PLT_FDE_START_OFFSET
);
6170 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6172 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6173 htab
->plt_got_eh_frame
,
6174 htab
->plt_got_eh_frame
->contents
))
6179 /* Adjust .eh_frame for the second PLT section. */
6180 if (htab
->plt_second_eh_frame
!= NULL
6181 && htab
->plt_second_eh_frame
->contents
!= NULL
)
6183 if (htab
->plt_second
!= NULL
6184 && htab
->plt_second
->size
!= 0
6185 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
6186 && htab
->plt_second
->output_section
!= NULL
6187 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
6189 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
6190 bfd_vma eh_frame_start
6191 = (htab
->plt_second_eh_frame
->output_section
->vma
6192 + htab
->plt_second_eh_frame
->output_offset
6193 + PLT_FDE_START_OFFSET
);
6194 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6195 htab
->plt_second_eh_frame
->contents
6196 + PLT_FDE_START_OFFSET
);
6198 if (htab
->plt_second_eh_frame
->sec_info_type
6199 == SEC_INFO_TYPE_EH_FRAME
)
6201 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6202 htab
->plt_second_eh_frame
,
6203 htab
->plt_second_eh_frame
->contents
))
6208 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6209 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6211 /* Fill PLT entries for undefined weak symbols in PIE. */
6212 if (bfd_link_pie (info
))
6213 bfd_hash_traverse (&info
->hash
->table
,
6214 elf_i386_pie_finish_undefweak_symbol
,
6220 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6221 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6222 It has to be done before elf_link_sort_relocs is called so that
6223 dynamic relocations are properly sorted. */
6226 elf_i386_output_arch_local_syms
6227 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6228 struct bfd_link_info
*info
,
6229 void *flaginfo ATTRIBUTE_UNUSED
,
6230 int (*func
) (void *, const char *,
6233 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6235 struct elf_i386_link_hash_table
*htab
= elf_i386_hash_table (info
);
6239 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6240 htab_traverse (htab
->loc_hash_table
,
6241 elf_i386_finish_local_dynamic_symbol
,
6247 /* Sort relocs into address order. */
6250 compare_relocs (const void *ap
, const void *bp
)
6252 const arelent
*a
= * (const arelent
**) ap
;
6253 const arelent
*b
= * (const arelent
**) bp
;
6255 if (a
->address
> b
->address
)
6257 else if (a
->address
< b
->address
)
6263 enum elf_i386_plt_type
6268 plt_second
= 1 << 2,
6277 enum elf_i386_plt_type type
;
6278 unsigned int plt_got_offset
;
6279 unsigned int plt_entry_size
;
6283 /* Forward declaration. */
6284 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
;
6286 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
6287 dynamic relocations. */
6290 elf_i386_get_synthetic_symtab (bfd
*abfd
,
6291 long symcount ATTRIBUTE_UNUSED
,
6292 asymbol
**syms ATTRIBUTE_UNUSED
,
6297 long size
, count
, i
, n
;
6299 unsigned int plt_got_offset
, plt_entry_size
;
6301 bfd_byte
*plt_contents
;
6302 long dynrelcount
, relsize
;
6303 arelent
**dynrelbuf
;
6304 const struct elf_i386_lazy_plt_layout
*lazy_plt
;
6305 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt
;
6306 const struct elf_i386_lazy_plt_layout
*lazy_ibt_plt
;
6307 const struct elf_i386_non_lazy_plt_layout
*non_lazy_ibt_plt
;
6311 enum elf_i386_plt_type plt_type
;
6312 struct elf_i386_plt plts
[] =
6314 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0 },
6315 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0 },
6316 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0 },
6317 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0 }
6322 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
6325 if (dynsymcount
<= 0)
6328 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
6332 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
6333 if (dynrelbuf
== NULL
)
6336 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
6339 /* Sort the relocs by address. */
6340 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*), compare_relocs
);
6342 non_lazy_plt
= NULL
;
6343 /* Silence GCC 6. */
6345 non_lazy_ibt_plt
= NULL
;
6346 lazy_ibt_plt
= NULL
;
6347 switch (get_elf_i386_backend_data (abfd
)->os
)
6350 non_lazy_plt
= &elf_i386_non_lazy_plt
;
6351 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
6352 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
6355 lazy_plt
= &elf_i386_lazy_plt
;
6358 lazy_plt
= &elf_i386_nacl_plt
;
6365 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6367 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
6371 /* Get the PLT section contents. */
6372 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6373 if (plt_contents
== NULL
)
6375 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6376 plt_contents
, 0, plt
->size
))
6378 free (plt_contents
);
6382 /* Check what kind of PLT it is. */
6383 plt_type
= plt_unknown
;
6384 if (plts
[j
].type
== plt_unknown
)
6386 /* Match lazy PLT first. */
6387 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
6388 lazy_plt
->plt0_got1_offset
) == 0)
6390 /* The fist entry in the lazy IBT PLT is the same as the
6392 if (lazy_ibt_plt
!= NULL
6393 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
6394 lazy_ibt_plt
->plt_entry
,
6395 lazy_ibt_plt
->plt_got_offset
) == 0))
6396 plt_type
= plt_lazy
| plt_second
;
6398 plt_type
= plt_lazy
;
6400 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
6401 lazy_plt
->plt0_got1_offset
) == 0)
6403 /* The fist entry in the PIC lazy IBT PLT is the same as
6404 the normal PIC lazy PLT. */
6405 if (lazy_ibt_plt
!= NULL
6406 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
6407 lazy_ibt_plt
->pic_plt_entry
,
6408 lazy_ibt_plt
->plt_got_offset
) == 0))
6409 plt_type
= plt_lazy
| plt_pic
| plt_second
;
6411 plt_type
= plt_lazy
| plt_pic
;
6415 if (non_lazy_plt
!= NULL
6416 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
))
6418 /* Match non-lazy PLT. */
6419 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
6420 non_lazy_plt
->plt_got_offset
) == 0)
6421 plt_type
= plt_non_lazy
;
6422 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
6423 non_lazy_plt
->plt_got_offset
) == 0)
6427 if ((non_lazy_ibt_plt
!= NULL
)
6428 && (plt_type
== plt_unknown
|| plt_type
== plt_second
))
6430 if (memcmp (plt_contents
,
6431 non_lazy_ibt_plt
->plt_entry
,
6432 non_lazy_ibt_plt
->plt_got_offset
) == 0)
6434 /* Match IBT PLT. */
6435 plt_type
= plt_second
;
6436 non_lazy_plt
= non_lazy_ibt_plt
;
6438 else if (memcmp (plt_contents
,
6439 non_lazy_ibt_plt
->pic_plt_entry
,
6440 non_lazy_ibt_plt
->plt_got_offset
) == 0)
6442 /* Match PIC IBT PLT. */
6443 plt_type
= plt_second
| plt_pic
;
6444 non_lazy_plt
= non_lazy_ibt_plt
;
6448 if (plt_type
== plt_unknown
)
6452 plts
[j
].type
= plt_type
;
6454 if ((plt_type
& plt_lazy
))
6456 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
6457 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
6458 /* Skip PLT0 in lazy PLT. */
6463 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
6464 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
6468 /* Skip lazy PLT when the second PLT is used. */
6469 if ((plt_type
& (plt_lazy
| plt_second
))
6470 == (plt_lazy
| plt_second
))
6474 n
= plt
->size
/ plts
[j
].plt_entry_size
;
6479 plts
[j
].contents
= plt_contents
;
6481 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
6482 if ((plt_type
& plt_pic
))
6483 got_addr
= (bfd_vma
) -1;
6486 size
= count
* sizeof (asymbol
);
6487 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
6491 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6492 if (plts
[j
].contents
!= NULL
)
6493 free (plts
[j
].contents
);
6500 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
6502 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
6504 got_addr
= sec
->vma
;
6507 sec
= bfd_get_section_by_name (abfd
, ".got");
6509 got_addr
= sec
->vma
;
6512 if (got_addr
== (bfd_vma
) -1)
6516 /* Check for each PLT section. */
6519 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6520 if ((plt_contents
= plts
[j
].contents
) != NULL
)
6525 plt_got_offset
= plts
[j
].plt_got_offset
;
6526 plt_entry_size
= plts
[j
].plt_entry_size
;
6530 if ((plts
[j
].type
& plt_lazy
))
6532 /* Skip PLT0 in lazy PLT. */
6534 offset
= plt_entry_size
;
6542 /* Check each PLT entry against dynamic relocations. */
6543 for (; k
< plts
[j
].count
; k
++)
6550 /* Get the GOT offset, a signed 32-bit integer. */
6551 off
= H_GET_32 (abfd
, (plt_contents
+ offset
6553 got_vma
= got_addr
+ off
;
6555 /* Binary search. */
6559 while ((min
+ 1) < max
)
6563 mid
= (min
+ max
) / 2;
6565 if (got_vma
> r
->address
)
6567 else if (got_vma
< r
->address
)
6576 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6577 if (got_vma
== p
->address
6579 && (p
->howto
->type
== R_386_JUMP_SLOT
6580 || p
->howto
->type
== R_386_GLOB_DAT
6581 || p
->howto
->type
== R_386_IRELATIVE
))
6583 *s
= **p
->sym_ptr_ptr
;
6584 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6585 set. Since we are defining a symbol, ensure one
6587 if ((s
->flags
& BSF_LOCAL
) == 0)
6588 s
->flags
|= BSF_GLOBAL
;
6589 s
->flags
|= BSF_SYNTHETIC
;
6590 /* This is no longer a section symbol. */
6591 s
->flags
&= ~BSF_SECTION_SYM
;
6593 s
->the_bfd
= plt
->owner
;
6595 /* Store relocation for later use. */
6597 /* Add @plt to function name later. */
6598 size
+= strlen (s
->name
) + sizeof ("@plt");
6600 size
+= sizeof ("+0x") - 1 + 8;
6604 offset
+= plt_entry_size
;
6608 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
6614 /* Allocate space for @plt suffixes. */
6615 names
= (char *) bfd_malloc (size
);
6620 for (i
= 0; i
< count
; i
++)
6622 /* Add @plt to function name. */
6623 arelent
*p
= (arelent
*) s
->udata
.p
;
6626 size
= strlen (s
->name
);
6627 memcpy (names
, s
->name
, size
);
6634 memcpy (names
, "+0x", sizeof ("+0x") - 1);
6635 names
+= sizeof ("+0x") - 1;
6636 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
6637 for (a
= buf
; *a
== '0'; ++a
)
6640 memcpy (names
, a
, size
);
6643 memcpy (names
, "@plt", sizeof ("@plt"));
6644 names
+= sizeof ("@plt");
6648 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6649 if (plts
[j
].contents
!= NULL
)
6650 free (plts
[j
].contents
);
6657 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6660 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
6662 if (h
->plt
.offset
!= (bfd_vma
) -1
6664 && !h
->pointer_equality_needed
)
6667 return _bfd_elf_hash_symbol (h
);
6670 /* Parse i386 GNU properties. */
6672 static enum elf_property_kind
6673 elf_i386_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6674 bfd_byte
*ptr
, unsigned int datasz
)
6680 case GNU_PROPERTY_X86_ISA_1_USED
:
6681 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6682 case GNU_PROPERTY_X86_FEATURE_1_AND
:
6686 ((type
== GNU_PROPERTY_X86_ISA_1_USED
6687 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6688 : (type
== GNU_PROPERTY_X86_ISA_1_NEEDED
6689 ? _("error: %B: <corrupt x86 ISA needed size: 0x%x>")
6690 : _("error: %B: <corrupt x86 feature size: 0x%x>"))),
6692 return property_corrupt
;
6694 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
6695 /* Combine properties of the same type. */
6696 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
6697 prop
->pr_kind
= property_number
;
6701 return property_ignored
;
6704 return property_number
;
6707 /* Merge i386 GNU property BPROP with APROP. If APROP isn't NULL,
6708 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6709 should be merged with ABFD. */
6712 elf_i386_merge_gnu_properties (struct bfd_link_info
*info
,
6713 bfd
*abfd ATTRIBUTE_UNUSED
,
6714 elf_property
*aprop
,
6715 elf_property
*bprop
)
6717 unsigned int number
, features
;
6718 bfd_boolean updated
= FALSE
;
6719 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
6723 case GNU_PROPERTY_X86_ISA_1_USED
:
6724 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6725 if (aprop
!= NULL
&& bprop
!= NULL
)
6727 number
= aprop
->u
.number
;
6728 aprop
->u
.number
= number
| bprop
->u
.number
;
6729 updated
= number
!= (unsigned int) aprop
->u
.number
;
6733 /* Return TRUE if APROP is NULL to indicate that BPROP should
6734 be added to ABFD. */
6735 updated
= aprop
== NULL
;
6739 case GNU_PROPERTY_X86_FEATURE_1_AND
:
6740 /* Only one of APROP and BPROP can be NULL:
6741 1. APROP & BPROP when both APROP and BPROP aren't NULL.
6742 2. If APROP is NULL, remove x86 feature.
6743 3. Otherwise, do nothing.
6745 if (aprop
!= NULL
&& bprop
!= NULL
)
6749 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6751 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
6752 number
= aprop
->u
.number
;
6753 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6754 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6755 aprop
->u
.number
= (number
& bprop
->u
.number
) | features
;
6756 updated
= number
!= (unsigned int) aprop
->u
.number
;
6757 /* Remove the property if all feature bits are cleared. */
6758 if (aprop
->u
.number
== 0)
6759 aprop
->pr_kind
= property_remove
;
6765 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6767 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
6770 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6771 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6774 number
= aprop
->u
.number
;
6775 aprop
->u
.number
= number
| features
;
6776 updated
= number
!= (unsigned int) aprop
->u
.number
;
6780 bprop
->u
.number
|= features
;
6784 else if (aprop
!= NULL
)
6786 aprop
->pr_kind
= property_remove
;
6793 /* Never should happen. */
6800 /* Set up i386 GNU properties. Return the first relocatable ELF input
6801 with GNU properties if found. Otherwise, return NULL. */
6804 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
6806 bfd_boolean normal_target
;
6807 bfd_boolean lazy_plt
;
6808 asection
*sec
, *pltsec
;
6810 bfd_boolean use_ibt_plt
;
6811 unsigned int plt_alignment
, features
;
6812 struct elf_i386_link_hash_table
*htab
;
6817 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6819 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
6822 /* Turn on GNU_PROPERTY_X86_FEATURE_1_IBT and
6823 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6827 for (pbfd
= info
->input_bfds
;
6829 pbfd
= pbfd
->link
.next
)
6830 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
6831 && bfd_count_sections (pbfd
) != 0)
6835 if (elf_properties (pbfd
) != NULL
)
6837 /* Find a normal input file with GNU property note. */
6838 prop
= _bfd_elf_get_property (pbfd
,
6839 GNU_PROPERTY_X86_FEATURE_1_AND
,
6841 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6842 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6843 prop
->u
.number
|= features
;
6844 prop
->pr_kind
= property_number
;
6849 if (pbfd
== NULL
&& ebfd
!= NULL
)
6851 /* Create GNU_PROPERTY_X86_FEATURE_1_IBT if needed. */
6852 prop
= _bfd_elf_get_property (ebfd
,
6853 GNU_PROPERTY_X86_FEATURE_1_AND
,
6855 prop
->u
.number
= features
;
6856 prop
->pr_kind
= property_number
;
6858 sec
= bfd_make_section_with_flags (ebfd
,
6859 NOTE_GNU_PROPERTY_SECTION_NAME
,
6867 info
->callbacks
->einfo (_("%F: failed to create GNU property section\n"));
6869 if (!bfd_set_section_alignment (ebfd
, sec
, 2))
6870 goto error_alignment
;
6872 elf_section_type (sec
) = SHT_NOTE
;
6876 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
6878 if (bfd_link_relocatable (info
))
6881 htab
= elf_i386_hash_table (info
);
6885 use_ibt_plt
= info
->ibtplt
|| info
->ibt
;
6886 if (!use_ibt_plt
&& pbfd
!= NULL
)
6888 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
6889 elf_property_list
*p
;
6891 /* The property list is sorted in order of type. */
6892 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
6894 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
6896 use_ibt_plt
= !!(p
->property
.u
.number
6897 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
6900 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
6905 dynobj
= htab
->elf
.dynobj
;
6907 /* Set htab->elf.dynobj here so that there is no need to check and
6908 set it in check_relocs. */
6913 /* Find a normal input file to hold linker created
6915 for (abfd
= info
->input_bfds
;
6917 abfd
= abfd
->link
.next
)
6919 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0)
6921 htab
->elf
.dynobj
= abfd
;
6927 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
6928 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
6929 canonical function address. */
6930 htab
->plt
.has_plt0
= 1;
6931 normal_target
= FALSE
;
6933 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
6938 htab
->lazy_plt
= &elf_i386_lazy_ibt_plt
;
6939 htab
->non_lazy_plt
= &elf_i386_non_lazy_ibt_plt
;
6943 htab
->lazy_plt
= &elf_i386_lazy_plt
;
6944 htab
->non_lazy_plt
= &elf_i386_non_lazy_plt
;
6946 normal_target
= TRUE
;
6949 htab
->lazy_plt
= &elf_i386_lazy_plt
;
6950 htab
->non_lazy_plt
= NULL
;
6951 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
,
6953 info
->callbacks
->einfo (_("%F: failed to create VxWorks dynamic sections\n"));
6956 htab
->lazy_plt
= &elf_i386_nacl_plt
;
6957 htab
->non_lazy_plt
= NULL
;
6961 pltsec
= htab
->elf
.splt
;
6963 /* If the non-lazy PLT is available, use it for all PLT entries if
6964 there are no PLT0 or no .plt section. */
6965 if (htab
->non_lazy_plt
!= NULL
6966 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
6969 if (bfd_link_pic (info
))
6971 = htab
->non_lazy_plt
->pic_plt_entry
;
6974 = htab
->non_lazy_plt
->plt_entry
;
6975 htab
->plt
.plt_entry_size
6976 = htab
->non_lazy_plt
->plt_entry_size
;
6977 htab
->plt
.plt_got_offset
6978 = htab
->non_lazy_plt
->plt_got_offset
;
6979 htab
->plt
.eh_frame_plt_size
6980 = htab
->non_lazy_plt
->eh_frame_plt_size
;
6981 htab
->plt
.eh_frame_plt
6982 = htab
->non_lazy_plt
->eh_frame_plt
;
6987 if (bfd_link_pic (info
))
6989 htab
->plt
.plt0_entry
6990 = htab
->lazy_plt
->pic_plt0_entry
;
6992 = htab
->lazy_plt
->pic_plt_entry
;
6996 htab
->plt
.plt0_entry
6997 = htab
->lazy_plt
->plt0_entry
;
6999 = htab
->lazy_plt
->plt_entry
;
7001 htab
->plt
.plt_entry_size
7002 = htab
->lazy_plt
->plt_entry_size
;
7003 htab
->plt
.plt_got_offset
7004 = htab
->lazy_plt
->plt_got_offset
;
7005 htab
->plt
.eh_frame_plt_size
7006 = htab
->lazy_plt
->eh_frame_plt_size
;
7007 htab
->plt
.eh_frame_plt
7008 = htab
->lazy_plt
->eh_frame_plt
;
7011 /* Return if there are no normal input files. */
7015 /* Since create_dynamic_sections isn't always called, but GOT
7016 relocations need GOT relocations, create them here so that we
7017 don't need to do it in check_relocs. */
7018 if (htab
->elf
.sgot
== NULL
7019 && !_bfd_elf_create_got_section (dynobj
, info
))
7020 info
->callbacks
->einfo (_("%F: failed to create GOT sections\n"));
7022 /* Create the ifunc sections here so that check_relocs can be
7024 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
7025 info
->callbacks
->einfo (_("%F: failed to create ifunc sections\n"));
7027 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
7031 /* Whe creating executable, set the contents of the .interp
7032 section to the interpreter. */
7033 if (bfd_link_executable (info
) && !info
->nointerp
)
7035 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
7038 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7039 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7043 /* Don't change PLT section alignment for NaCl since it uses
7044 64-byte PLT entry and sets PLT section alignment to 32
7048 const struct elf_backend_data
*bed
7049 = get_elf_backend_data (dynobj
);
7050 flagword pltflags
= (bed
->dynamic_sec_flags
7055 unsigned int non_lazy_plt_alignment
7056 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
7059 if (!bfd_set_section_alignment (sec
->owner
, sec
,
7061 goto error_alignment
;
7063 /* Create the GOT procedure linkage table. */
7064 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7068 info
->callbacks
->einfo (_("%F: failed to create GOT PLT section\n"));
7070 if (!bfd_set_section_alignment (dynobj
, sec
,
7071 non_lazy_plt_alignment
))
7072 goto error_alignment
;
7074 htab
->plt_got
= sec
;
7082 /* Create the second PLT for Intel IBT support. IBT
7083 PLT is supported only for non-NaCl target and is
7084 is needed only for lazy binding. */
7085 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7089 info
->callbacks
->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
7091 if (!bfd_set_section_alignment (dynobj
, sec
,
7093 goto error_alignment
;
7096 htab
->plt_second
= sec
;
7100 if (!info
->no_ld_generated_unwind_info
)
7102 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
7103 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7104 | SEC_LINKER_CREATED
);
7106 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7110 info
->callbacks
->einfo (_("%F: failed to create PLT .eh_frame section\n"));
7112 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
7113 goto error_alignment
;
7115 htab
->plt_eh_frame
= sec
;
7117 if (htab
->plt_got
!= NULL
)
7119 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7123 info
->callbacks
->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
7125 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
7126 goto error_alignment
;
7128 htab
->plt_got_eh_frame
= sec
;
7135 /* The .iplt section is used for IFUNC symbols in static
7137 sec
= htab
->elf
.iplt
;
7139 && !bfd_set_section_alignment (sec
->owner
, sec
,
7143 info
->callbacks
->einfo (_("%F%A: failed to align section\n"),
7151 #define TARGET_LITTLE_SYM i386_elf32_vec
7152 #define TARGET_LITTLE_NAME "elf32-i386"
7153 #define ELF_ARCH bfd_arch_i386
7154 #define ELF_TARGET_ID I386_ELF_DATA
7155 #define ELF_MACHINE_CODE EM_386
7156 #define ELF_MAXPAGESIZE 0x1000
7158 #define elf_backend_can_gc_sections 1
7159 #define elf_backend_can_refcount 1
7160 #define elf_backend_want_got_plt 1
7161 #define elf_backend_plt_readonly 1
7162 #define elf_backend_want_plt_sym 0
7163 #define elf_backend_got_header_size 12
7164 #define elf_backend_plt_alignment 4
7165 #define elf_backend_dtrel_excludes_plt 1
7166 #define elf_backend_extern_protected_data 1
7167 #define elf_backend_caches_rawsize 1
7168 #define elf_backend_want_dynrelro 1
7170 /* Support RELA for objdump of prelink objects. */
7171 #define elf_info_to_howto elf_i386_info_to_howto_rel
7172 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
7174 #define bfd_elf32_mkobject elf_i386_mkobject
7176 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
7177 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
7178 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
7179 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
7180 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
7182 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
7183 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
7184 #define elf_backend_check_relocs elf_i386_check_relocs
7185 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
7186 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
7187 #define elf_backend_fake_sections elf_i386_fake_sections
7188 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
7189 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
7190 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
7191 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
7192 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
7193 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
7194 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
7195 #define elf_backend_relocate_section elf_i386_relocate_section
7196 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
7197 #define elf_backend_always_size_sections elf_i386_always_size_sections
7198 #define elf_backend_omit_section_dynsym \
7199 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7200 #define elf_backend_hash_symbol elf_i386_hash_symbol
7201 #define elf_backend_fixup_symbol elf_i386_fixup_symbol
7202 #define elf_backend_parse_gnu_properties elf_i386_parse_gnu_properties
7203 #define elf_backend_merge_gnu_properties elf_i386_merge_gnu_properties
7204 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
7206 #include "elf32-target.h"
7208 /* FreeBSD support. */
7210 #undef TARGET_LITTLE_SYM
7211 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
7212 #undef TARGET_LITTLE_NAME
7213 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
7215 #define ELF_OSABI ELFOSABI_FREEBSD
7217 /* The kernel recognizes executables as valid only if they carry a
7218 "FreeBSD" label in the ELF header. So we put this label on all
7219 executables and (for simplicity) also all other object files. */
7222 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
7224 _bfd_elf_post_process_headers (abfd
, info
);
7226 #ifdef OLD_FREEBSD_ABI_LABEL
7228 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
7229 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
7230 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
7235 #undef elf_backend_post_process_headers
7236 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
7238 #define elf32_bed elf32_i386_fbsd_bed
7240 #undef elf_backend_add_symbol_hook
7242 #include "elf32-target.h"
7246 #undef TARGET_LITTLE_SYM
7247 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
7248 #undef TARGET_LITTLE_NAME
7249 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
7251 #undef elf_backend_post_process_headers
7253 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7254 objects won't be recognized. */
7258 #define elf32_bed elf32_i386_sol2_bed
7260 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
7262 #undef elf_backend_static_tls_alignment
7263 #define elf_backend_static_tls_alignment 8
7265 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7267 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7269 #undef elf_backend_want_plt_sym
7270 #define elf_backend_want_plt_sym 1
7272 #undef elf_backend_strtab_flags
7273 #define elf_backend_strtab_flags SHF_STRINGS
7275 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
7276 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
7277 FALSE otherwise. ISECTION is the best guess matching section from the
7278 input bfd IBFD, but it might be NULL. */
7281 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7282 bfd
*obfd ATTRIBUTE_UNUSED
,
7283 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7284 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7286 /* PR 19938: FIXME: Need to add code for setting the sh_info
7287 and sh_link fields of Solaris specific section types. */
7290 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
7291 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
7293 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
7295 The following values should be set:
7298 -----------------------------------------------------------------------------
7299 SHT_SUNW_ancillary The section header index of 0
7300 [0x6fffffee] the associated string table.
7302 SHT_SUNW_capinfo The section header index of For a dynamic object, the
7303 [0x6ffffff0] the associated symbol table. section header index of
7305 SHT_SUNW_capchain table,
7308 SHT_SUNW_symsort The section header index of 0
7309 [0x6ffffff1] the associated symbol table.
7311 SHT_SUNW_tlssort The section header index of 0
7312 [0x6ffffff2] the associated symbol table.
7314 SHT_SUNW_LDYNSYM The section header index of One greater than the
7315 [0x6ffffff3] the associated string table. symbol table index of the
7316 This index is the same string last local symbol,
7317 table used by the SHT_DYNSYM STB_LOCAL. Since
7318 section. SHT_SUNW_LDYNSYM only
7319 contains local symbols,
7320 sh_info is equivalent to
7321 the number of symbols in
7324 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
7325 [0x6ffffff5] the section header index of to named strings, the
7326 the associated section header index of
7327 SHT_SUNW_capinfo table, the associated string
7328 otherwise 0. table, otherwise 0.
7330 SHT_SUNW_move The section header index of 0
7331 [0x6ffffffa] the associated symbol table.
7336 SHT_SUNW_syminfo The section header index of The section header index
7337 [0x6ffffffc] the associated symbol table. of the associated
7340 SHT_SUNW_verdef The section header index of The number of version
7341 [0x6ffffffd] the associated string table. definitions within the
7344 SHT_SUNW_verneed The section header index of The number of version
7345 [0x6ffffffe] the associated string table. dependencies within the
7348 SHT_SUNW_versym The section header index of 0
7349 [0x6fffffff] the associated symbol table. */
7352 #undef elf_backend_copy_special_section_fields
7353 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
7355 #include "elf32-target.h"
7357 /* Intel MCU support. */
7360 elf32_iamcu_elf_object_p (bfd
*abfd
)
7362 /* Set the right machine number for an IAMCU elf32 file. */
7363 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
7367 #undef TARGET_LITTLE_SYM
7368 #define TARGET_LITTLE_SYM iamcu_elf32_vec
7369 #undef TARGET_LITTLE_NAME
7370 #define TARGET_LITTLE_NAME "elf32-iamcu"
7372 #define ELF_ARCH bfd_arch_iamcu
7374 #undef ELF_MACHINE_CODE
7375 #define ELF_MACHINE_CODE EM_IAMCU
7380 #define elf32_bed elf32_iamcu_bed
7382 #undef elf_backend_object_p
7383 #define elf_backend_object_p elf32_iamcu_elf_object_p
7385 #undef elf_backend_static_tls_alignment
7387 #undef elf_backend_want_plt_sym
7388 #define elf_backend_want_plt_sym 0
7390 #undef elf_backend_strtab_flags
7391 #undef elf_backend_copy_special_section_fields
7393 #include "elf32-target.h"
7395 /* Restore defaults. */
7397 #define ELF_ARCH bfd_arch_i386
7398 #undef ELF_MACHINE_CODE
7399 #define ELF_MACHINE_CODE EM_386
7401 /* Native Client support. */
7403 #undef TARGET_LITTLE_SYM
7404 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
7405 #undef TARGET_LITTLE_NAME
7406 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
7408 #define elf32_bed elf32_i386_nacl_bed
7410 #undef ELF_MAXPAGESIZE
7411 #define ELF_MAXPAGESIZE 0x10000
7413 /* Restore defaults. */
7415 #undef elf_backend_want_plt_sym
7416 #define elf_backend_want_plt_sym 0
7417 #undef elf_backend_post_process_headers
7418 #undef elf_backend_static_tls_alignment
7420 /* NaCl uses substantially different PLT entries for the same effects. */
7422 #undef elf_backend_plt_alignment
7423 #define elf_backend_plt_alignment 5
7424 #define NACL_PLT_ENTRY_SIZE 64
7425 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7427 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
7429 0xff, 0x35, /* pushl contents of address */
7430 0, 0, 0, 0, /* replaced with address of .got + 4. */
7431 0x8b, 0x0d, /* movl contents of address, %ecx */
7432 0, 0, 0, 0, /* replaced with address of .got + 8. */
7433 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
7434 0xff, 0xe1 /* jmp *%ecx */
7437 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7439 0x8b, 0x0d, /* movl contents of address, %ecx */
7440 0, 0, 0, 0, /* replaced with GOT slot address. */
7441 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
7442 0xff, 0xe1, /* jmp *%ecx */
7444 /* Pad to the next 32-byte boundary with nop instructions. */
7446 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7447 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7449 /* Lazy GOT entries point here (32-byte aligned). */
7450 0x68, /* pushl immediate */
7451 0, 0, 0, 0, /* replaced with reloc offset. */
7452 0xe9, /* jmp relative */
7453 0, 0, 0, 0, /* replaced with offset to .plt. */
7455 /* Pad to the next 32-byte boundary with nop instructions. */
7456 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7457 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7461 static const bfd_byte
7462 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
7464 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
7465 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
7466 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
7467 0xff, 0xe1, /* jmp *%ecx */
7469 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
7470 so pad to that size with nop instructions. */
7471 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
7474 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7476 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
7477 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
7478 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
7479 0xff, 0xe1, /* jmp *%ecx */
7481 /* Pad to the next 32-byte boundary with nop instructions. */
7483 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7484 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7486 /* Lazy GOT entries point here (32-byte aligned). */
7487 0x68, /* pushl immediate */
7488 0, 0, 0, 0, /* replaced with offset into relocation table. */
7489 0xe9, /* jmp relative */
7490 0, 0, 0, 0, /* replaced with offset to start of .plt. */
7492 /* Pad to the next 32-byte boundary with nop instructions. */
7493 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7494 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7498 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
7500 #if (PLT_CIE_LENGTH != 20 \
7501 || PLT_FDE_LENGTH != 36 \
7502 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7503 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7504 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
7506 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7507 0, 0, 0, 0, /* CIE ID */
7508 1, /* CIE version */
7509 'z', 'R', 0, /* Augmentation string */
7510 1, /* Code alignment factor */
7511 0x7c, /* Data alignment factor: -4 */
7512 8, /* Return address column */
7513 1, /* Augmentation size */
7514 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
7515 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
7516 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
7517 DW_CFA_nop
, DW_CFA_nop
,
7519 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
7520 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
7521 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
7522 0, 0, 0, 0, /* .plt size goes here */
7523 0, /* Augmentation size */
7524 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
7525 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7526 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
7527 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7528 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7529 13, /* Block length */
7530 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
7531 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
7532 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7533 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
7534 DW_CFA_nop
, DW_CFA_nop
7537 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
=
7539 elf_i386_nacl_plt0_entry
, /* plt0_entry */
7540 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
7541 2, /* plt0_got1_offset */
7542 8, /* plt0_got2_offset */
7543 elf_i386_nacl_plt_entry
, /* plt_entry */
7544 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7545 2, /* plt_got_offset */
7546 33, /* plt_reloc_offset */
7547 38, /* plt_plt_offset */
7548 32, /* plt_lazy_offset */
7549 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
7550 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
7551 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
7552 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
7555 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
7557 0x90, /* plt0_pad_byte: nop insn */
7562 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
7564 /* Set the right machine number for a NaCl i386 ELF32 file. */
7565 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
7569 #undef elf_backend_arch_data
7570 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
7572 #undef elf_backend_object_p
7573 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
7574 #undef elf_backend_modify_segment_map
7575 #define elf_backend_modify_segment_map nacl_modify_segment_map
7576 #undef elf_backend_modify_program_headers
7577 #define elf_backend_modify_program_headers nacl_modify_program_headers
7578 #undef elf_backend_final_write_processing
7579 #define elf_backend_final_write_processing nacl_final_write_processing
7581 #include "elf32-target.h"
7583 /* Restore defaults. */
7584 #undef elf_backend_object_p
7585 #undef elf_backend_modify_segment_map
7586 #undef elf_backend_modify_program_headers
7587 #undef elf_backend_final_write_processing
7589 /* VxWorks support. */
7591 #undef TARGET_LITTLE_SYM
7592 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
7593 #undef TARGET_LITTLE_NAME
7594 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
7596 #undef ELF_MAXPAGESIZE
7597 #define ELF_MAXPAGESIZE 0x1000
7598 #undef elf_backend_plt_alignment
7599 #define elf_backend_plt_alignment 4
7601 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
7603 0x90, /* plt0_pad_byte */
7607 #undef elf_backend_arch_data
7608 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
7610 #undef elf_backend_relocs_compatible
7611 #undef elf_backend_add_symbol_hook
7612 #define elf_backend_add_symbol_hook \
7613 elf_vxworks_add_symbol_hook
7614 #undef elf_backend_link_output_symbol_hook
7615 #define elf_backend_link_output_symbol_hook \
7616 elf_vxworks_link_output_symbol_hook
7617 #undef elf_backend_emit_relocs
7618 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7619 #undef elf_backend_final_write_processing
7620 #define elf_backend_final_write_processing \
7621 elf_vxworks_final_write_processing
7622 #undef elf_backend_static_tls_alignment
7624 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
7626 #undef elf_backend_want_plt_sym
7627 #define elf_backend_want_plt_sym 1
7630 #define elf32_bed elf32_i386_vxworks_bed
7632 #include "elf32-target.h"