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 0x%lx "
1712 "in section `%A' failed"),
1713 abfd
, from
->name
, to
->name
, name
,
1714 (unsigned long) 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 long 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
))
3944 /* xgettext:c-format */
3945 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3946 input_bfd
, r_type
, input_section
);
3947 bfd_set_error (bfd_error_bad_value
);
3950 howto
= elf_howto_table
+ indx
;
3952 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3956 unresolved_reloc
= FALSE
;
3957 if (r_symndx
< symtab_hdr
->sh_info
)
3959 sym
= local_syms
+ r_symndx
;
3960 sec
= local_sections
[r_symndx
];
3961 relocation
= (sec
->output_section
->vma
3962 + sec
->output_offset
3964 st_size
= sym
->st_size
;
3966 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3967 && ((sec
->flags
& SEC_MERGE
) != 0
3968 || (bfd_link_relocatable (info
)
3969 && sec
->output_offset
!= 0)))
3972 bfd_byte
*where
= contents
+ rel
->r_offset
;
3974 switch (howto
->size
)
3977 addend
= bfd_get_8 (input_bfd
, where
);
3978 if (howto
->pc_relative
)
3980 addend
= (addend
^ 0x80) - 0x80;
3985 addend
= bfd_get_16 (input_bfd
, where
);
3986 if (howto
->pc_relative
)
3988 addend
= (addend
^ 0x8000) - 0x8000;
3993 addend
= bfd_get_32 (input_bfd
, where
);
3994 if (howto
->pc_relative
)
3996 addend
= (addend
^ 0x80000000) - 0x80000000;
4004 if (bfd_link_relocatable (info
))
4005 addend
+= sec
->output_offset
;
4008 asection
*msec
= sec
;
4009 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
4011 addend
-= relocation
;
4012 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4015 switch (howto
->size
)
4018 /* FIXME: overflow checks. */
4019 if (howto
->pc_relative
)
4021 bfd_put_8 (input_bfd
, addend
, where
);
4024 if (howto
->pc_relative
)
4026 bfd_put_16 (input_bfd
, addend
, where
);
4029 if (howto
->pc_relative
)
4031 bfd_put_32 (input_bfd
, addend
, where
);
4035 else if (!bfd_link_relocatable (info
)
4036 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4038 /* Relocate against local STT_GNU_IFUNC symbol. */
4039 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
4044 /* Set STT_GNU_IFUNC symbol value. */
4045 h
->root
.u
.def
.value
= sym
->st_value
;
4046 h
->root
.u
.def
.section
= sec
;
4051 bfd_boolean warned ATTRIBUTE_UNUSED
;
4052 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4054 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4055 r_symndx
, symtab_hdr
, sym_hashes
,
4057 unresolved_reloc
, warned
, ignored
);
4061 if (sec
!= NULL
&& discarded_section (sec
))
4063 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4064 contents
+ rel
->r_offset
);
4065 wrel
->r_offset
= rel
->r_offset
;
4069 /* For ld -r, remove relocations in debug sections against
4070 sections defined in discarded sections. Not done for
4071 eh_frame editing code expects to be present. */
4072 if (bfd_link_relocatable (info
)
4073 && (input_section
->flags
& SEC_DEBUGGING
))
4079 if (bfd_link_relocatable (info
))
4086 eh
= (struct elf_i386_link_hash_entry
*) h
;
4088 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4089 it here if it is defined in a non-shared object. */
4091 && h
->type
== STT_GNU_IFUNC
4094 asection
*gotplt
, *base_got
;
4098 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4100 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4101 sections because such sections are not SEC_ALLOC and
4102 thus ld.so will not process them. */
4103 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4108 /* STT_GNU_IFUNC symbol must go through PLT. */
4109 if (htab
->elf
.splt
!= NULL
)
4111 if (htab
->plt_second
!= NULL
)
4113 resolved_plt
= htab
->plt_second
;
4114 plt_offset
= eh
->plt_second
.offset
;
4118 resolved_plt
= htab
->elf
.splt
;
4119 plt_offset
= h
->plt
.offset
;
4121 gotplt
= htab
->elf
.sgotplt
;
4125 resolved_plt
= htab
->elf
.iplt
;
4126 plt_offset
= h
->plt
.offset
;
4127 gotplt
= htab
->elf
.igotplt
;
4137 base_got
= htab
->elf
.sgot
;
4138 off
= h
->got
.offset
;
4140 if (base_got
== NULL
)
4143 if (off
== (bfd_vma
) -1)
4145 /* We can't use h->got.offset here to save state, or
4146 even just remember the offset, as finish_dynamic_symbol
4147 would use that as offset into .got. */
4149 if (h
->plt
.offset
== (bfd_vma
) -1)
4152 if (htab
->elf
.splt
!= NULL
)
4154 plt_index
= (h
->plt
.offset
/ plt_entry_size
4155 - htab
->plt
.has_plt0
);
4156 off
= (plt_index
+ 3) * 4;
4157 base_got
= htab
->elf
.sgotplt
;
4161 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4162 off
= plt_index
* 4;
4163 base_got
= htab
->elf
.igotplt
;
4166 if (h
->dynindx
== -1
4170 /* This references the local defitionion. We must
4171 initialize this entry in the global offset table.
4172 Since the offset must always be a multiple of 8,
4173 we use the least significant bit to record
4174 whether we have initialized it already.
4176 When doing a dynamic link, we create a .rela.got
4177 relocation entry to initialize the value. This
4178 is done in the finish_dynamic_symbol routine. */
4183 bfd_put_32 (output_bfd
, relocation
,
4184 base_got
->contents
+ off
);
4192 relocation
= (base_got
->output_section
->vma
4193 + base_got
->output_offset
+ off
4194 - gotplt
->output_section
->vma
4195 - gotplt
->output_offset
);
4197 if (rel
->r_offset
> 1
4198 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4199 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4201 if (bfd_link_pic (info
))
4202 goto disallow_got32
;
4204 /* Add the GOT base if there is no base register. */
4205 relocation
+= (gotplt
->output_section
->vma
4206 + gotplt
->output_offset
);
4208 else if (htab
->elf
.splt
== NULL
)
4210 /* Adjust for static executables. */
4211 relocation
+= gotplt
->output_offset
;
4217 if (h
->plt
.offset
== (bfd_vma
) -1)
4219 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4220 if (r_type
== R_386_32
4221 && (input_section
->flags
& SEC_CODE
) == 0)
4222 goto do_ifunc_pointer
;
4223 goto bad_ifunc_reloc
;
4226 relocation
= (resolved_plt
->output_section
->vma
4227 + resolved_plt
->output_offset
+ plt_offset
);
4233 if (h
->root
.root
.string
)
4234 name
= h
->root
.root
.string
;
4236 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4239 /* xgettext:c-format */
4240 (_("%B: relocation %s against STT_GNU_IFUNC "
4241 "symbol `%s' isn't supported"), input_bfd
,
4243 bfd_set_error (bfd_error_bad_value
);
4247 /* Generate dynamic relcoation only when there is a
4248 non-GOT reference in a shared object. */
4249 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4250 || h
->plt
.offset
== (bfd_vma
) -1)
4252 Elf_Internal_Rela outrel
;
4257 /* Need a dynamic relocation to get the real function
4259 offset
= _bfd_elf_section_offset (output_bfd
,
4263 if (offset
== (bfd_vma
) -1
4264 || offset
== (bfd_vma
) -2)
4267 outrel
.r_offset
= (input_section
->output_section
->vma
4268 + input_section
->output_offset
4271 if (h
->dynindx
== -1
4273 || bfd_link_executable (info
))
4275 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4276 h
->root
.root
.string
,
4277 h
->root
.u
.def
.section
->owner
);
4279 /* This symbol is resolved locally. */
4280 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4281 bfd_put_32 (output_bfd
,
4282 (h
->root
.u
.def
.value
4283 + h
->root
.u
.def
.section
->output_section
->vma
4284 + h
->root
.u
.def
.section
->output_offset
),
4288 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4290 /* Dynamic relocations are stored in
4291 1. .rel.ifunc section in PIC object.
4292 2. .rel.got section in dynamic executable.
4293 3. .rel.iplt section in static executable. */
4294 if (bfd_link_pic (info
))
4295 sreloc
= htab
->elf
.irelifunc
;
4296 else if (htab
->elf
.splt
!= NULL
)
4297 sreloc
= htab
->elf
.srelgot
;
4299 sreloc
= htab
->elf
.irelplt
;
4300 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4302 /* If this reloc is against an external symbol, we
4303 do not want to fiddle with the addend. Otherwise,
4304 we need to include the symbol value so that it
4305 becomes an addend for the dynamic reloc. For an
4306 internal symbol, we have updated addend. */
4315 relocation
-= (gotplt
->output_section
->vma
4316 + gotplt
->output_offset
);
4321 resolved_to_zero
= (eh
!= NULL
4322 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4329 /* Avoid optimizing _DYNAMIC since ld.so may use its
4330 link-time address. */
4331 if (h
== htab
->elf
.hdynamic
)
4334 if (bfd_link_pic (info
))
4336 /* It is OK to convert mov to lea and convert indirect
4337 branch to direct branch. It is OK to convert adc,
4338 add, and, cmp, or, sbb, sub, test, xor only when PIC
4340 unsigned int opcode
, addend
;
4341 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4344 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4345 if (opcode
!= 0x8b && opcode
!= 0xff)
4349 /* Resolve "mov GOT[(%reg)], %reg",
4350 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
4351 and "binop foo@GOT[(%reg)], %reg". */
4353 || (h
->plt
.offset
== (bfd_vma
) -1
4354 && h
->got
.offset
== (bfd_vma
) -1)
4355 || htab
->elf
.sgotplt
== NULL
)
4358 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
4359 + htab
->elf
.sgotplt
->output_offset
);
4361 /* It is relative to .got.plt section. */
4362 if (h
->got
.offset
!= (bfd_vma
) -1)
4363 /* Use GOT entry. Mask off the least significant bit in
4364 GOT offset which may be set by R_386_GOT32 processing
4366 relocation
= (htab
->elf
.sgot
->output_section
->vma
4367 + htab
->elf
.sgot
->output_offset
4368 + (h
->got
.offset
& ~1) - offplt
);
4370 /* Use GOTPLT entry. */
4371 relocation
= (h
->plt
.offset
/ plt_entry_size
4372 - htab
->plt
.has_plt0
+ 3) * 4;
4374 if (!bfd_link_pic (info
))
4376 /* If not PIC, add the .got.plt section address for
4377 baseless addressing. */
4379 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4380 if ((modrm
& 0xc7) == 0x5)
4381 relocation
+= offplt
;
4384 unresolved_reloc
= FALSE
;
4389 /* Relocation is to the entry for this symbol in the global
4391 if (htab
->elf
.sgot
== NULL
)
4394 relative_reloc
= FALSE
;
4399 off
= h
->got
.offset
;
4400 dyn
= htab
->elf
.dynamic_sections_created
;
4401 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4402 bfd_link_pic (info
),
4404 || (bfd_link_pic (info
)
4405 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4406 || (ELF_ST_VISIBILITY (h
->other
)
4407 && h
->root
.type
== bfd_link_hash_undefweak
))
4409 /* This is actually a static link, or it is a
4410 -Bsymbolic link and the symbol is defined
4411 locally, or the symbol was forced to be local
4412 because of a version file. We must initialize
4413 this entry in the global offset table. Since the
4414 offset must always be a multiple of 4, we use the
4415 least significant bit to record whether we have
4416 initialized it already.
4418 When doing a dynamic link, we create a .rel.got
4419 relocation entry to initialize the value. This
4420 is done in the finish_dynamic_symbol routine. */
4425 bfd_put_32 (output_bfd
, relocation
,
4426 htab
->elf
.sgot
->contents
+ off
);
4429 if (h
->dynindx
== -1
4431 && h
->root
.type
!= bfd_link_hash_undefweak
4432 && bfd_link_pic (info
))
4434 /* PR ld/21402: If this symbol isn't dynamic
4435 in PIC, generate R_386_RELATIVE here. */
4436 eh
->no_finish_dynamic_symbol
= 1;
4437 relative_reloc
= TRUE
;
4442 unresolved_reloc
= FALSE
;
4446 if (local_got_offsets
== NULL
)
4449 off
= local_got_offsets
[r_symndx
];
4451 /* The offset must always be a multiple of 4. We use
4452 the least significant bit to record whether we have
4453 already generated the necessary reloc. */
4458 bfd_put_32 (output_bfd
, relocation
,
4459 htab
->elf
.sgot
->contents
+ off
);
4460 local_got_offsets
[r_symndx
] |= 1;
4462 if (bfd_link_pic (info
))
4463 relative_reloc
= TRUE
;
4470 Elf_Internal_Rela outrel
;
4472 s
= htab
->elf
.srelgot
;
4476 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4477 + htab
->elf
.sgot
->output_offset
4479 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4480 elf_append_rel (output_bfd
, s
, &outrel
);
4483 if (off
>= (bfd_vma
) -2)
4486 relocation
= (htab
->elf
.sgot
->output_section
->vma
4487 + htab
->elf
.sgot
->output_offset
+ off
);
4488 if (rel
->r_offset
> 1
4489 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4490 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4492 if (bfd_link_pic (info
))
4494 /* For PIC, disallow R_386_GOT32 without a base
4495 register, except for "lea foo@GOT, %reg", since
4496 we don't know what the GOT base is. */
4500 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
4501 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4504 name
= h
->root
.root
.string
;
4507 /* xgettext:c-format */
4508 (_("%B: direct GOT relocation %s against `%s'"
4509 " without base register can not be used"
4510 " when making a shared object"),
4511 input_bfd
, howto
->name
, name
);
4512 bfd_set_error (bfd_error_bad_value
);
4518 /* Subtract the .got.plt section address only with a base
4520 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
4521 + htab
->elf
.sgotplt
->output_offset
);
4527 /* Relocation is relative to the start of the global offset
4530 /* Check to make sure it isn't a protected function or data
4531 symbol for shared library since it may not be local when
4532 used as function address or with copy relocation. We also
4533 need to make sure that a symbol is referenced locally. */
4534 if (!bfd_link_executable (info
) && h
)
4536 if (!h
->def_regular
)
4540 switch (ELF_ST_VISIBILITY (h
->other
))
4543 v
= _("hidden symbol");
4546 v
= _("internal symbol");
4549 v
= _("protected symbol");
4557 /* xgettext:c-format */
4558 (_("%B: relocation R_386_GOTOFF against undefined %s"
4559 " `%s' can not be used when making a shared object"),
4560 input_bfd
, v
, h
->root
.root
.string
);
4561 bfd_set_error (bfd_error_bad_value
);
4564 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
4565 && (h
->type
== STT_FUNC
4566 || h
->type
== STT_OBJECT
)
4567 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4570 /* xgettext:c-format */
4571 (_("%B: relocation R_386_GOTOFF against protected %s"
4572 " `%s' can not be used when making a shared object"),
4574 h
->type
== STT_FUNC
? "function" : "data",
4575 h
->root
.root
.string
);
4576 bfd_set_error (bfd_error_bad_value
);
4581 /* Note that sgot is not involved in this
4582 calculation. We always want the start of .got.plt. If we
4583 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4584 permitted by the ABI, we might have to change this
4586 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4587 + htab
->elf
.sgotplt
->output_offset
;
4591 /* Use global offset table as symbol value. */
4592 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4593 + htab
->elf
.sgotplt
->output_offset
;
4594 unresolved_reloc
= FALSE
;
4598 /* Relocation is to the entry for this symbol in the
4599 procedure linkage table. */
4601 /* Resolve a PLT32 reloc against a local symbol directly,
4602 without using the procedure linkage table. */
4606 if ((h
->plt
.offset
== (bfd_vma
) -1
4607 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4608 || htab
->elf
.splt
== NULL
)
4610 /* We didn't make a PLT entry for this symbol. This
4611 happens when statically linking PIC code, or when
4612 using -Bsymbolic. */
4616 if (h
->plt
.offset
!= (bfd_vma
) -1)
4618 if (htab
->plt_second
!= NULL
)
4620 resolved_plt
= htab
->plt_second
;
4621 plt_offset
= eh
->plt_second
.offset
;
4625 resolved_plt
= htab
->elf
.splt
;
4626 plt_offset
= h
->plt
.offset
;
4631 resolved_plt
= htab
->plt_got
;
4632 plt_offset
= eh
->plt_got
.offset
;
4635 relocation
= (resolved_plt
->output_section
->vma
4636 + resolved_plt
->output_offset
4638 unresolved_reloc
= FALSE
;
4642 /* Set to symbol size. */
4643 relocation
= st_size
;
4648 if ((input_section
->flags
& SEC_ALLOC
) == 0
4652 /* Copy dynamic function pointer relocations. Don't generate
4653 dynamic relocations against resolved undefined weak symbols
4654 in PIE, except for R_386_PC32. */
4655 if ((bfd_link_pic (info
)
4657 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4658 && (!resolved_to_zero
4659 || r_type
== R_386_PC32
))
4660 || h
->root
.type
!= bfd_link_hash_undefweak
))
4661 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
4662 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4663 || (ELIMINATE_COPY_RELOCS
4664 && !bfd_link_pic (info
)
4668 || eh
->func_pointer_refcount
> 0
4669 || (h
->root
.type
== bfd_link_hash_undefweak
4670 && !resolved_to_zero
))
4671 && ((h
->def_dynamic
&& !h
->def_regular
)
4672 /* Undefined weak symbol is bound locally when
4674 || h
->root
.type
== bfd_link_hash_undefweak
)))
4676 Elf_Internal_Rela outrel
;
4677 bfd_boolean skip
, relocate
;
4680 /* When generating a shared object, these relocations
4681 are copied into the output file to be resolved at run
4688 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4690 if (outrel
.r_offset
== (bfd_vma
) -1)
4692 else if (outrel
.r_offset
== (bfd_vma
) -2)
4693 skip
= TRUE
, relocate
= TRUE
;
4694 outrel
.r_offset
+= (input_section
->output_section
->vma
4695 + input_section
->output_offset
);
4698 memset (&outrel
, 0, sizeof outrel
);
4701 && (r_type
== R_386_PC32
4702 || !(bfd_link_executable (info
)
4703 || SYMBOLIC_BIND (info
, h
))
4704 || !h
->def_regular
))
4705 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4708 /* This symbol is local, or marked to become local. */
4710 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4713 sreloc
= elf_section_data (input_section
)->sreloc
;
4715 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4717 r
= bfd_reloc_notsupported
;
4718 goto check_relocation_error
;
4721 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4723 /* If this reloc is against an external symbol, we do
4724 not want to fiddle with the addend. Otherwise, we
4725 need to include the symbol value so that it becomes
4726 an addend for the dynamic reloc. */
4733 if (!bfd_link_executable (info
))
4735 Elf_Internal_Rela outrel
;
4738 outrel
.r_offset
= rel
->r_offset
4739 + input_section
->output_section
->vma
4740 + input_section
->output_offset
;
4741 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4742 sreloc
= elf_section_data (input_section
)->sreloc
;
4745 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4750 case R_386_TLS_GOTDESC
:
4751 case R_386_TLS_DESC_CALL
:
4752 case R_386_TLS_IE_32
:
4753 case R_386_TLS_GOTIE
:
4754 tls_type
= GOT_UNKNOWN
;
4755 if (h
== NULL
&& local_got_offsets
)
4756 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
4758 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
4759 if (tls_type
== GOT_TLS_IE
)
4760 tls_type
= GOT_TLS_IE_NEG
;
4762 if (! elf_i386_tls_transition (info
, input_bfd
,
4763 input_section
, contents
,
4764 symtab_hdr
, sym_hashes
,
4765 &r_type
, tls_type
, rel
,
4766 relend
, h
, r_symndx
, TRUE
))
4769 if (r_type
== R_386_TLS_LE_32
)
4771 BFD_ASSERT (! unresolved_reloc
);
4772 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4777 /* GD->LE transition. */
4778 type
= *(contents
+ rel
->r_offset
- 2);
4782 leal foo@tlsgd(,%ebx,1), %eax
4783 call ___tls_get_addr@PLT
4786 subl $foo@tpoff, %eax
4787 (6 byte form of subl). */
4788 roff
= rel
->r_offset
+ 5;
4793 leal foo@tlsgd(%ebx), %eax
4794 call ___tls_get_addr@PLT
4797 leal foo@tlsgd(%reg), %eax
4798 call *___tls_get_addr@GOT(%reg)
4799 which may be converted to
4800 addr32 call ___tls_get_addr
4802 movl %gs:0, %eax; subl $foo@tpoff, %eax
4803 (6 byte form of subl). */
4804 roff
= rel
->r_offset
+ 6;
4806 memcpy (contents
+ roff
- 8,
4807 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4808 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4810 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4815 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4817 /* GDesc -> LE transition.
4818 It's originally something like:
4819 leal x@tlsdesc(%ebx), %eax
4823 Registers other than %eax may be set up here. */
4828 roff
= rel
->r_offset
;
4829 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4831 /* Now modify the instruction as appropriate. */
4832 /* aoliva FIXME: remove the above and xor the byte
4834 bfd_put_8 (output_bfd
, val
^ 0x86,
4835 contents
+ roff
- 1);
4836 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4840 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4842 /* GDesc -> LE transition.
4850 roff
= rel
->r_offset
;
4851 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4852 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4855 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4859 /* IE->LE transition:
4860 Originally it can be one of:
4868 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4871 /* movl foo, %eax. */
4872 bfd_put_8 (output_bfd
, 0xb8,
4873 contents
+ rel
->r_offset
- 1);
4879 type
= bfd_get_8 (input_bfd
,
4880 contents
+ rel
->r_offset
- 2);
4885 bfd_put_8 (output_bfd
, 0xc7,
4886 contents
+ rel
->r_offset
- 2);
4887 bfd_put_8 (output_bfd
,
4888 0xc0 | ((val
>> 3) & 7),
4889 contents
+ rel
->r_offset
- 1);
4893 bfd_put_8 (output_bfd
, 0x81,
4894 contents
+ rel
->r_offset
- 2);
4895 bfd_put_8 (output_bfd
,
4896 0xc0 | ((val
>> 3) & 7),
4897 contents
+ rel
->r_offset
- 1);
4904 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4905 contents
+ rel
->r_offset
);
4910 unsigned int val
, type
;
4912 /* {IE_32,GOTIE}->LE transition:
4913 Originally it can be one of:
4914 subl foo(%reg1), %reg2
4915 movl foo(%reg1), %reg2
4916 addl foo(%reg1), %reg2
4919 movl $foo, %reg2 (6 byte form)
4920 addl $foo, %reg2. */
4921 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4922 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4926 bfd_put_8 (output_bfd
, 0xc7,
4927 contents
+ rel
->r_offset
- 2);
4928 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4929 contents
+ rel
->r_offset
- 1);
4931 else if (type
== 0x2b)
4934 bfd_put_8 (output_bfd
, 0x81,
4935 contents
+ rel
->r_offset
- 2);
4936 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4937 contents
+ rel
->r_offset
- 1);
4939 else if (type
== 0x03)
4942 bfd_put_8 (output_bfd
, 0x81,
4943 contents
+ rel
->r_offset
- 2);
4944 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4945 contents
+ rel
->r_offset
- 1);
4949 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4950 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4951 contents
+ rel
->r_offset
);
4953 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4954 contents
+ rel
->r_offset
);
4959 if (htab
->elf
.sgot
== NULL
)
4964 off
= h
->got
.offset
;
4965 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
4969 if (local_got_offsets
== NULL
)
4972 off
= local_got_offsets
[r_symndx
];
4973 offplt
= local_tlsdesc_gotents
[r_symndx
];
4980 Elf_Internal_Rela outrel
;
4984 if (htab
->elf
.srelgot
== NULL
)
4987 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4989 if (GOT_TLS_GDESC_P (tls_type
))
4992 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4993 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4994 <= htab
->elf
.sgotplt
->size
);
4995 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4996 + htab
->elf
.sgotplt
->output_offset
4998 + htab
->sgotplt_jump_table_size
);
4999 sreloc
= htab
->elf
.srelplt
;
5000 loc
= sreloc
->contents
;
5001 loc
+= (htab
->next_tls_desc_index
++
5002 * sizeof (Elf32_External_Rel
));
5003 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
5004 <= sreloc
->contents
+ sreloc
->size
);
5005 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
5008 BFD_ASSERT (! unresolved_reloc
);
5009 bfd_put_32 (output_bfd
,
5010 relocation
- elf_i386_dtpoff_base (info
),
5011 htab
->elf
.sgotplt
->contents
+ offplt
5012 + htab
->sgotplt_jump_table_size
+ 4);
5016 bfd_put_32 (output_bfd
, 0,
5017 htab
->elf
.sgotplt
->contents
+ offplt
5018 + htab
->sgotplt_jump_table_size
+ 4);
5022 sreloc
= htab
->elf
.srelgot
;
5024 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5025 + htab
->elf
.sgot
->output_offset
+ off
);
5027 if (GOT_TLS_GD_P (tls_type
))
5028 dr_type
= R_386_TLS_DTPMOD32
;
5029 else if (GOT_TLS_GDESC_P (tls_type
))
5031 else if (tls_type
== GOT_TLS_IE_POS
)
5032 dr_type
= R_386_TLS_TPOFF
;
5034 dr_type
= R_386_TLS_TPOFF32
;
5036 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
5037 bfd_put_32 (output_bfd
,
5038 relocation
- elf_i386_dtpoff_base (info
),
5039 htab
->elf
.sgot
->contents
+ off
);
5040 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
5041 bfd_put_32 (output_bfd
,
5042 elf_i386_dtpoff_base (info
) - relocation
,
5043 htab
->elf
.sgot
->contents
+ off
);
5044 else if (dr_type
!= R_386_TLS_DESC
)
5045 bfd_put_32 (output_bfd
, 0,
5046 htab
->elf
.sgot
->contents
+ off
);
5047 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5049 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5051 if (GOT_TLS_GD_P (tls_type
))
5055 BFD_ASSERT (! unresolved_reloc
);
5056 bfd_put_32 (output_bfd
,
5057 relocation
- elf_i386_dtpoff_base (info
),
5058 htab
->elf
.sgot
->contents
+ off
+ 4);
5062 bfd_put_32 (output_bfd
, 0,
5063 htab
->elf
.sgot
->contents
+ off
+ 4);
5064 outrel
.r_info
= ELF32_R_INFO (indx
,
5065 R_386_TLS_DTPOFF32
);
5066 outrel
.r_offset
+= 4;
5067 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5070 else if (tls_type
== GOT_TLS_IE_BOTH
)
5072 bfd_put_32 (output_bfd
,
5074 ? relocation
- elf_i386_dtpoff_base (info
)
5076 htab
->elf
.sgot
->contents
+ off
+ 4);
5077 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5078 outrel
.r_offset
+= 4;
5079 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5086 local_got_offsets
[r_symndx
] |= 1;
5089 if (off
>= (bfd_vma
) -2
5090 && ! GOT_TLS_GDESC_P (tls_type
))
5092 if (r_type
== R_386_TLS_GOTDESC
5093 || r_type
== R_386_TLS_DESC_CALL
)
5095 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
5096 unresolved_reloc
= FALSE
;
5098 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5100 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
5101 + htab
->elf
.sgotplt
->output_offset
;
5102 relocation
= htab
->elf
.sgot
->output_section
->vma
5103 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
5104 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
5105 && tls_type
== GOT_TLS_IE_BOTH
)
5107 if (r_type
== R_386_TLS_IE
)
5108 relocation
+= g_o_t
;
5109 unresolved_reloc
= FALSE
;
5111 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
5113 unsigned int val
, type
;
5116 /* GD->IE transition. */
5117 type
= *(contents
+ rel
->r_offset
- 2);
5118 val
= *(contents
+ rel
->r_offset
- 1);
5122 leal foo@tlsgd(,%ebx,1), %eax
5123 call ___tls_get_addr@PLT
5126 subl $foo@gottpoff(%ebx), %eax. */
5128 roff
= rel
->r_offset
- 3;
5133 leal foo@tlsgd(%ebx), %eax
5134 call ___tls_get_addr@PLT
5137 leal foo@tlsgd(%reg), %eax
5138 call *___tls_get_addr@GOT(%reg)
5139 which may be converted to
5140 addr32 call ___tls_get_addr
5143 subl $foo@gottpoff(%reg), %eax. */
5144 roff
= rel
->r_offset
- 2;
5146 memcpy (contents
+ roff
,
5147 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
5148 contents
[roff
+ 7] = 0x80 | (val
& 7);
5149 /* If foo is used only with foo@gotntpoff(%reg) and
5150 foo@indntpoff, but not with foo@gottpoff(%reg), change
5151 subl $foo@gottpoff(%reg), %eax
5153 addl $foo@gotntpoff(%reg), %eax. */
5154 if (tls_type
== GOT_TLS_IE_POS
)
5155 contents
[roff
+ 6] = 0x03;
5156 bfd_put_32 (output_bfd
,
5157 htab
->elf
.sgot
->output_section
->vma
5158 + htab
->elf
.sgot
->output_offset
+ off
5159 - htab
->elf
.sgotplt
->output_section
->vma
5160 - htab
->elf
.sgotplt
->output_offset
,
5161 contents
+ roff
+ 8);
5162 /* Skip R_386_PLT32 and R_386_GOT32X. */
5167 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
5169 /* GDesc -> IE transition.
5170 It's originally something like:
5171 leal x@tlsdesc(%ebx), %eax
5174 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
5176 movl x@gottpoff(%ebx), %eax # before negl %eax
5178 Registers other than %eax may be set up here. */
5182 /* First, make sure it's a leal adding ebx to a 32-bit
5183 offset into any register, although it's probably
5184 almost always going to be eax. */
5185 roff
= rel
->r_offset
;
5187 /* Now modify the instruction as appropriate. */
5188 /* To turn a leal into a movl in the form we use it, it
5189 suffices to change the first byte from 0x8d to 0x8b.
5190 aoliva FIXME: should we decide to keep the leal, all
5191 we have to do is remove the statement below, and
5192 adjust the relaxation of R_386_TLS_DESC_CALL. */
5193 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5195 if (tls_type
== GOT_TLS_IE_BOTH
)
5198 bfd_put_32 (output_bfd
,
5199 htab
->elf
.sgot
->output_section
->vma
5200 + htab
->elf
.sgot
->output_offset
+ off
5201 - htab
->elf
.sgotplt
->output_section
->vma
5202 - htab
->elf
.sgotplt
->output_offset
,
5206 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
5208 /* GDesc -> IE transition.
5216 depending on how we transformed the TLS_GOTDESC above.
5221 roff
= rel
->r_offset
;
5223 /* Now modify the instruction as appropriate. */
5224 if (tls_type
!= GOT_TLS_IE_NEG
)
5227 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5228 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5233 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
5234 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
5244 if (! elf_i386_tls_transition (info
, input_bfd
,
5245 input_section
, contents
,
5246 symtab_hdr
, sym_hashes
,
5247 &r_type
, GOT_UNKNOWN
, rel
,
5248 relend
, h
, r_symndx
, TRUE
))
5251 if (r_type
!= R_386_TLS_LDM
)
5253 /* LD->LE transition. Change
5254 leal foo@tlsldm(%ebx) %eax
5255 call ___tls_get_addr@PLT
5259 leal 0(%esi,1), %esi
5261 leal foo@tlsldm(%reg) %eax
5262 call *___tls_get_addr@GOT(%reg)
5263 which may be converted to
5264 addr32 call ___tls_get_addr
5267 leal 0(%esi), %esi */
5268 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
5269 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
5270 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
5271 memcpy (contents
+ rel
->r_offset
- 2,
5272 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
5274 memcpy (contents
+ rel
->r_offset
- 2,
5275 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
5276 /* Skip R_386_PC32/R_386_PLT32. */
5282 if (htab
->elf
.sgot
== NULL
)
5285 off
= htab
->tls_ldm_got
.offset
;
5290 Elf_Internal_Rela outrel
;
5292 if (htab
->elf
.srelgot
== NULL
)
5295 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5296 + htab
->elf
.sgot
->output_offset
+ off
);
5298 bfd_put_32 (output_bfd
, 0,
5299 htab
->elf
.sgot
->contents
+ off
);
5300 bfd_put_32 (output_bfd
, 0,
5301 htab
->elf
.sgot
->contents
+ off
+ 4);
5302 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
5303 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
5304 htab
->tls_ldm_got
.offset
|= 1;
5306 relocation
= htab
->elf
.sgot
->output_section
->vma
5307 + htab
->elf
.sgot
->output_offset
+ off
5308 - htab
->elf
.sgotplt
->output_section
->vma
5309 - htab
->elf
.sgotplt
->output_offset
;
5310 unresolved_reloc
= FALSE
;
5313 case R_386_TLS_LDO_32
:
5314 if (!bfd_link_executable (info
)
5315 || (input_section
->flags
& SEC_CODE
) == 0)
5316 relocation
-= elf_i386_dtpoff_base (info
);
5318 /* When converting LDO to LE, we must negate. */
5319 relocation
= -elf_i386_tpoff (info
, relocation
);
5322 case R_386_TLS_LE_32
:
5324 if (!bfd_link_executable (info
))
5326 Elf_Internal_Rela outrel
;
5329 outrel
.r_offset
= rel
->r_offset
5330 + input_section
->output_section
->vma
5331 + input_section
->output_offset
;
5332 if (h
!= NULL
&& h
->dynindx
!= -1)
5336 if (r_type
== R_386_TLS_LE_32
)
5337 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
5339 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5340 sreloc
= elf_section_data (input_section
)->sreloc
;
5343 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5346 else if (r_type
== R_386_TLS_LE_32
)
5347 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
5349 relocation
-= elf_i386_dtpoff_base (info
);
5351 else if (r_type
== R_386_TLS_LE_32
)
5352 relocation
= elf_i386_tpoff (info
, relocation
);
5354 relocation
= -elf_i386_tpoff (info
, relocation
);
5361 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5362 because such sections are not SEC_ALLOC and thus ld.so will
5363 not process them. */
5364 if (unresolved_reloc
5365 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5367 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5368 rel
->r_offset
) != (bfd_vma
) -1)
5371 /* xgettext:c-format */
5372 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5375 (long) rel
->r_offset
,
5377 h
->root
.root
.string
);
5382 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5383 contents
, rel
->r_offset
,
5386 check_relocation_error
:
5387 if (r
!= bfd_reloc_ok
)
5392 name
= h
->root
.root
.string
;
5395 name
= bfd_elf_string_from_elf_section (input_bfd
,
5396 symtab_hdr
->sh_link
,
5401 name
= bfd_section_name (input_bfd
, sec
);
5404 if (r
== bfd_reloc_overflow
)
5405 (*info
->callbacks
->reloc_overflow
)
5406 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5407 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5411 /* xgettext:c-format */
5412 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5413 input_bfd
, input_section
,
5414 (long) rel
->r_offset
, name
, (int) r
);
5425 Elf_Internal_Shdr
*rel_hdr
;
5426 size_t deleted
= rel
- wrel
;
5428 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5429 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5430 if (rel_hdr
->sh_size
== 0)
5432 /* It is too late to remove an empty reloc section. Leave
5434 ??? What is wrong with an empty section??? */
5435 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5438 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5439 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5440 input_section
->reloc_count
-= deleted
;
5446 /* Finish up dynamic symbol handling. We set the contents of various
5447 dynamic sections here. */
5450 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
5451 struct bfd_link_info
*info
,
5452 struct elf_link_hash_entry
*h
,
5453 Elf_Internal_Sym
*sym
)
5455 struct elf_i386_link_hash_table
*htab
;
5456 unsigned plt_entry_size
;
5457 const struct elf_i386_backend_data
*abed
;
5458 struct elf_i386_link_hash_entry
*eh
;
5459 bfd_boolean local_undefweak
;
5460 bfd_boolean use_plt_second
;
5462 htab
= elf_i386_hash_table (info
);
5466 abed
= get_elf_i386_backend_data (output_bfd
);
5467 plt_entry_size
= htab
->plt
.plt_entry_size
;
5469 /* Use the second PLT section only if there is .plt section. */
5470 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
5472 eh
= (struct elf_i386_link_hash_entry
*) h
;
5473 if (eh
->no_finish_dynamic_symbol
)
5476 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5477 resolved undefined weak symbols in executable so that their
5478 references have value 0 at run-time. */
5479 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5483 if (h
->plt
.offset
!= (bfd_vma
) -1)
5485 bfd_vma plt_index
, plt_offset
;
5487 Elf_Internal_Rela rel
;
5489 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
5491 /* When building a static executable, use .iplt, .igot.plt and
5492 .rel.iplt sections for STT_GNU_IFUNC symbols. */
5493 if (htab
->elf
.splt
!= NULL
)
5495 plt
= htab
->elf
.splt
;
5496 gotplt
= htab
->elf
.sgotplt
;
5497 relplt
= htab
->elf
.srelplt
;
5501 plt
= htab
->elf
.iplt
;
5502 gotplt
= htab
->elf
.igotplt
;
5503 relplt
= htab
->elf
.irelplt
;
5506 /* This symbol has an entry in the procedure linkage table. Set
5509 if ((h
->dynindx
== -1
5511 && !((h
->forced_local
|| bfd_link_executable (info
))
5513 && h
->type
== STT_GNU_IFUNC
))
5519 /* Get the index in the procedure linkage table which
5520 corresponds to this symbol. This is the index of this symbol
5521 in all the symbols for which we are making plt entries. The
5522 first entry in the procedure linkage table is reserved.
5524 Get the offset into the .got table of the entry that
5525 corresponds to this function. Each .got entry is 4 bytes.
5526 The first three are reserved.
5528 For static executables, we don't reserve anything. */
5530 if (plt
== htab
->elf
.splt
)
5532 got_offset
= (h
->plt
.offset
/ plt_entry_size
5533 - htab
->plt
.has_plt0
);
5534 got_offset
= (got_offset
+ 3) * 4;
5538 got_offset
= h
->plt
.offset
/ plt_entry_size
;
5539 got_offset
= got_offset
* 4;
5542 /* Fill in the entry in the procedure linkage table and update
5544 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
5549 const bfd_byte
*plt_entry
;
5550 if (bfd_link_pic (info
))
5551 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5553 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5554 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
5555 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
5557 resolved_plt
= htab
->plt_second
;
5558 plt_offset
= eh
->plt_second
.offset
;
5563 plt_offset
= h
->plt
.offset
;
5566 if (! bfd_link_pic (info
))
5568 bfd_put_32 (output_bfd
,
5569 (gotplt
->output_section
->vma
5570 + gotplt
->output_offset
5572 resolved_plt
->contents
+ plt_offset
5573 + htab
->plt
.plt_got_offset
);
5575 if (abed
->os
== is_vxworks
)
5577 int s
, k
, reloc_index
;
5579 /* Create the R_386_32 relocation referencing the GOT
5580 for this PLT entry. */
5582 /* S: Current slot number (zero-based). */
5583 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
5584 / htab
->plt
.plt_entry_size
);
5585 /* K: Number of relocations for PLTResolve. */
5586 if (bfd_link_pic (info
))
5587 k
= PLTRESOLVE_RELOCS_SHLIB
;
5589 k
= PLTRESOLVE_RELOCS
;
5590 /* Skip the PLTresolve relocations, and the relocations for
5591 the other PLT slots. */
5592 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
5593 loc
= (htab
->srelplt2
->contents
+ reloc_index
5594 * sizeof (Elf32_External_Rel
));
5596 rel
.r_offset
= (plt
->output_section
->vma
5597 + plt
->output_offset
5598 + h
->plt
.offset
+ 2),
5599 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5600 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5602 /* Create the R_386_32 relocation referencing the beginning of
5603 the PLT for this GOT entry. */
5604 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5605 + htab
->elf
.sgotplt
->output_offset
5607 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5608 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5609 loc
+ sizeof (Elf32_External_Rel
));
5614 bfd_put_32 (output_bfd
, got_offset
,
5615 resolved_plt
->contents
+ plt_offset
5616 + htab
->plt
.plt_got_offset
);
5619 /* Fill in the entry in the global offset table. Leave the entry
5620 as zero for undefined weak symbol in PIE. No PLT relocation
5621 against undefined weak symbol in PIE. */
5622 if (!local_undefweak
)
5624 if (htab
->plt
.has_plt0
)
5625 bfd_put_32 (output_bfd
,
5626 (plt
->output_section
->vma
5627 + plt
->output_offset
5629 + htab
->lazy_plt
->plt_lazy_offset
),
5630 gotplt
->contents
+ got_offset
);
5632 /* Fill in the entry in the .rel.plt section. */
5633 rel
.r_offset
= (gotplt
->output_section
->vma
5634 + gotplt
->output_offset
5636 if (h
->dynindx
== -1
5637 || ((bfd_link_executable (info
)
5638 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5640 && h
->type
== STT_GNU_IFUNC
))
5642 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5643 h
->root
.root
.string
,
5644 h
->root
.u
.def
.section
->owner
);
5646 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5647 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5648 in the .got.plt section. */
5649 bfd_put_32 (output_bfd
,
5650 (h
->root
.u
.def
.value
5651 + h
->root
.u
.def
.section
->output_section
->vma
5652 + h
->root
.u
.def
.section
->output_offset
),
5653 gotplt
->contents
+ got_offset
);
5654 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5655 /* R_386_IRELATIVE comes last. */
5656 plt_index
= htab
->next_irelative_index
--;
5660 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
5661 plt_index
= htab
->next_jump_slot_index
++;
5664 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5665 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5667 /* Don't fill the second and third slots in PLT entry for
5668 static executables nor without PLT0. */
5669 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
5671 bfd_put_32 (output_bfd
,
5672 plt_index
* sizeof (Elf32_External_Rel
),
5673 plt
->contents
+ h
->plt
.offset
5674 + htab
->lazy_plt
->plt_reloc_offset
);
5675 bfd_put_32 (output_bfd
,
5677 + htab
->lazy_plt
->plt_plt_offset
+ 4),
5678 (plt
->contents
+ h
->plt
.offset
5679 + htab
->lazy_plt
->plt_plt_offset
));
5683 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5685 bfd_vma got_offset
, plt_offset
;
5686 asection
*plt
, *got
, *gotplt
;
5687 const bfd_byte
*got_plt_entry
;
5689 /* Set the entry in the GOT procedure linkage table. */
5690 plt
= htab
->plt_got
;
5691 got
= htab
->elf
.sgot
;
5692 gotplt
= htab
->elf
.sgotplt
;
5693 got_offset
= h
->got
.offset
;
5695 if (got_offset
== (bfd_vma
) -1
5701 /* Fill in the entry in the GOT procedure linkage table. */
5702 if (! bfd_link_pic (info
))
5704 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5705 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
5709 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5710 got_offset
+= (got
->output_section
->vma
5711 + got
->output_offset
5712 - gotplt
->output_section
->vma
5713 - gotplt
->output_offset
);
5716 plt_offset
= eh
->plt_got
.offset
;
5717 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
5718 htab
->non_lazy_plt
->plt_entry_size
);
5719 bfd_put_32 (output_bfd
, got_offset
,
5720 (plt
->contents
+ plt_offset
5721 + htab
->non_lazy_plt
->plt_got_offset
));
5724 if (!local_undefweak
5726 && (h
->plt
.offset
!= (bfd_vma
) -1
5727 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5729 /* Mark the symbol as undefined, rather than as defined in
5730 the .plt section. Leave the value if there were any
5731 relocations where pointer equality matters (this is a clue
5732 for the dynamic linker, to make function pointer
5733 comparisons work between an application and shared
5734 library), otherwise set it to zero. If a function is only
5735 called from a binary, there is no need to slow down
5736 shared libraries because of that. */
5737 sym
->st_shndx
= SHN_UNDEF
;
5738 if (!h
->pointer_equality_needed
)
5742 /* Don't generate dynamic GOT relocation against undefined weak
5743 symbol in executable. */
5744 if (h
->got
.offset
!= (bfd_vma
) -1
5745 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
5746 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
5747 && !local_undefweak
)
5749 Elf_Internal_Rela rel
;
5750 asection
*relgot
= htab
->elf
.srelgot
;
5752 /* This symbol has an entry in the global offset table. Set it
5755 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5758 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5759 + htab
->elf
.sgot
->output_offset
5760 + (h
->got
.offset
& ~(bfd_vma
) 1));
5762 /* If this is a static link, or it is a -Bsymbolic link and the
5763 symbol is defined locally or was forced to be local because
5764 of a version file, we just want to emit a RELATIVE reloc.
5765 The entry in the global offset table will already have been
5766 initialized in the relocate_section function. */
5768 && h
->type
== STT_GNU_IFUNC
)
5770 if (h
->plt
.offset
== (bfd_vma
) -1)
5772 /* STT_GNU_IFUNC is referenced without PLT. */
5773 if (htab
->elf
.splt
== NULL
)
5775 /* use .rel[a].iplt section to store .got relocations
5776 in static executable. */
5777 relgot
= htab
->elf
.irelplt
;
5779 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5781 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5782 h
->root
.root
.string
,
5783 h
->root
.u
.def
.section
->owner
);
5785 bfd_put_32 (output_bfd
,
5786 (h
->root
.u
.def
.value
5787 + h
->root
.u
.def
.section
->output_section
->vma
5788 + h
->root
.u
.def
.section
->output_offset
),
5789 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5790 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5795 else if (bfd_link_pic (info
))
5797 /* Generate R_386_GLOB_DAT. */
5805 if (!h
->pointer_equality_needed
)
5808 /* For non-shared object, we can't use .got.plt, which
5809 contains the real function addres if we need pointer
5810 equality. We load the GOT entry with the PLT entry. */
5811 if (htab
->plt_second
!= NULL
)
5813 plt
= htab
->plt_second
;
5814 plt_offset
= eh
->plt_second
.offset
;
5818 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5819 plt_offset
= h
->plt
.offset
;
5821 bfd_put_32 (output_bfd
,
5822 (plt
->output_section
->vma
5823 + plt
->output_offset
+ plt_offset
),
5824 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5828 else if (bfd_link_pic (info
)
5829 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5831 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5832 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
5836 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5838 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5839 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5840 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
5843 elf_append_rel (output_bfd
, relgot
, &rel
);
5848 Elf_Internal_Rela rel
;
5851 /* This symbol needs a copy reloc. Set it up. */
5853 if (h
->dynindx
== -1
5854 || (h
->root
.type
!= bfd_link_hash_defined
5855 && h
->root
.type
!= bfd_link_hash_defweak
)
5856 || htab
->elf
.srelbss
== NULL
5857 || htab
->elf
.sreldynrelro
== NULL
)
5860 rel
.r_offset
= (h
->root
.u
.def
.value
5861 + h
->root
.u
.def
.section
->output_section
->vma
5862 + h
->root
.u
.def
.section
->output_offset
);
5863 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5864 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5865 s
= htab
->elf
.sreldynrelro
;
5867 s
= htab
->elf
.srelbss
;
5868 elf_append_rel (output_bfd
, s
, &rel
);
5874 /* Finish up local dynamic symbol handling. We set the contents of
5875 various dynamic sections here. */
5878 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5880 struct elf_link_hash_entry
*h
5881 = (struct elf_link_hash_entry
*) *slot
;
5882 struct bfd_link_info
*info
5883 = (struct bfd_link_info
*) inf
;
5885 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5889 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5890 here since undefined weak symbol may not be dynamic and may not be
5891 called for elf_i386_finish_dynamic_symbol. */
5894 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5897 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5898 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5900 if (h
->root
.type
!= bfd_link_hash_undefweak
5901 || h
->dynindx
!= -1)
5904 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5908 /* Used to decide how to sort relocs in an optimal manner for the
5909 dynamic linker, before writing them out. */
5911 static enum elf_reloc_type_class
5912 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5913 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5914 const Elf_Internal_Rela
*rela
)
5916 bfd
*abfd
= info
->output_bfd
;
5917 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5918 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5920 if (htab
->dynsym
!= NULL
5921 && htab
->dynsym
->contents
!= NULL
)
5923 /* Check relocation against STT_GNU_IFUNC symbol if there are
5925 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5926 if (r_symndx
!= STN_UNDEF
)
5928 Elf_Internal_Sym sym
;
5929 if (!bed
->s
->swap_symbol_in (abfd
,
5930 (htab
->dynsym
->contents
5931 + r_symndx
* sizeof (Elf32_External_Sym
)),
5935 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5936 return reloc_class_ifunc
;
5940 switch (ELF32_R_TYPE (rela
->r_info
))
5942 case R_386_IRELATIVE
:
5943 return reloc_class_ifunc
;
5944 case R_386_RELATIVE
:
5945 return reloc_class_relative
;
5946 case R_386_JUMP_SLOT
:
5947 return reloc_class_plt
;
5949 return reloc_class_copy
;
5951 return reloc_class_normal
;
5955 /* Finish up the dynamic sections. */
5958 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5959 struct bfd_link_info
*info
)
5961 struct elf_i386_link_hash_table
*htab
;
5964 const struct elf_i386_backend_data
*abed
;
5966 htab
= elf_i386_hash_table (info
);
5970 dynobj
= htab
->elf
.dynobj
;
5971 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5972 abed
= get_elf_i386_backend_data (output_bfd
);
5974 if (htab
->elf
.dynamic_sections_created
)
5976 Elf32_External_Dyn
*dyncon
, *dynconend
;
5978 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5981 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5982 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5983 for (; dyncon
< dynconend
; dyncon
++)
5985 Elf_Internal_Dyn dyn
;
5988 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5993 if (abed
->os
== is_vxworks
5994 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5999 s
= htab
->elf
.sgotplt
;
6000 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6004 s
= htab
->elf
.srelplt
;
6005 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6009 s
= htab
->elf
.srelplt
;
6010 dyn
.d_un
.d_val
= s
->size
;
6014 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6017 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6019 /* UnixWare sets the entsize of .plt to 4, although that doesn't
6020 really seem like the right value. */
6021 elf_section_data (htab
->elf
.splt
->output_section
)
6022 ->this_hdr
.sh_entsize
= 4;
6024 if (htab
->plt
.has_plt0
)
6026 /* Fill in the special first entry in the procedure linkage
6028 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
6029 htab
->lazy_plt
->plt0_entry_size
);
6030 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
6031 abed
->plt0_pad_byte
,
6032 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
6033 if (!bfd_link_pic (info
))
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_got1_offset
);
6041 bfd_put_32 (output_bfd
,
6042 (htab
->elf
.sgotplt
->output_section
->vma
6043 + htab
->elf
.sgotplt
->output_offset
6045 htab
->elf
.splt
->contents
6046 + htab
->lazy_plt
->plt0_got2_offset
);
6048 if (abed
->os
== is_vxworks
)
6050 Elf_Internal_Rela rel
;
6051 int num_plts
= (htab
->elf
.splt
->size
6052 / htab
->plt
.plt_entry_size
) - 1;
6055 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6056 + 4. On IA32 we use REL relocations so the
6057 addend goes in the PLT directly. */
6058 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
6059 + htab
->elf
.splt
->output_offset
6060 + htab
->lazy_plt
->plt0_got1_offset
);
6061 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6063 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
6064 htab
->srelplt2
->contents
);
6065 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6067 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
6068 + htab
->elf
.splt
->output_offset
6069 + htab
->lazy_plt
->plt0_got2_offset
);
6070 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6072 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
6073 htab
->srelplt2
->contents
+
6074 sizeof (Elf32_External_Rel
));
6075 /* Correct the .rel.plt.unloaded relocations. */
6076 p
= htab
->srelplt2
->contents
;
6077 if (bfd_link_pic (info
))
6078 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
6080 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
6082 for (; num_plts
; num_plts
--)
6084 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
6085 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6087 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
6088 p
+= sizeof (Elf32_External_Rel
);
6090 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
6091 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
6093 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
6094 p
+= sizeof (Elf32_External_Rel
);
6101 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
6102 elf_section_data (htab
->plt_got
->output_section
)
6103 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6105 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
6106 elf_section_data (htab
->plt_second
->output_section
)
6107 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6110 /* Fill in the first three entries in the global offset table. */
6111 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
6113 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6116 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6120 bfd_put_32 (output_bfd
,
6122 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
6123 htab
->elf
.sgotplt
->contents
);
6124 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
6125 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
6127 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
6130 /* Adjust .eh_frame for .plt section. */
6131 if (htab
->plt_eh_frame
!= NULL
6132 && htab
->plt_eh_frame
->contents
!= NULL
)
6134 if (htab
->elf
.splt
!= NULL
6135 && htab
->elf
.splt
->size
!= 0
6136 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6137 && htab
->elf
.splt
->output_section
!= NULL
6138 && htab
->plt_eh_frame
->output_section
!= NULL
)
6140 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6141 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6142 + htab
->plt_eh_frame
->output_offset
6143 + PLT_FDE_START_OFFSET
;
6144 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6145 htab
->plt_eh_frame
->contents
6146 + PLT_FDE_START_OFFSET
);
6148 if (htab
->plt_eh_frame
->sec_info_type
6149 == SEC_INFO_TYPE_EH_FRAME
)
6151 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6153 htab
->plt_eh_frame
->contents
))
6158 /* Adjust .eh_frame for .plt.got section. */
6159 if (htab
->plt_got_eh_frame
!= NULL
6160 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6162 if (htab
->plt_got
!= NULL
6163 && htab
->plt_got
->size
!= 0
6164 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6165 && htab
->plt_got
->output_section
!= NULL
6166 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6168 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6169 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6170 + htab
->plt_got_eh_frame
->output_offset
6171 + PLT_FDE_START_OFFSET
;
6172 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6173 htab
->plt_got_eh_frame
->contents
6174 + PLT_FDE_START_OFFSET
);
6176 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6178 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6179 htab
->plt_got_eh_frame
,
6180 htab
->plt_got_eh_frame
->contents
))
6185 /* Adjust .eh_frame for the second PLT section. */
6186 if (htab
->plt_second_eh_frame
!= NULL
6187 && htab
->plt_second_eh_frame
->contents
!= NULL
)
6189 if (htab
->plt_second
!= NULL
6190 && htab
->plt_second
->size
!= 0
6191 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
6192 && htab
->plt_second
->output_section
!= NULL
6193 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
6195 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
6196 bfd_vma eh_frame_start
6197 = (htab
->plt_second_eh_frame
->output_section
->vma
6198 + htab
->plt_second_eh_frame
->output_offset
6199 + PLT_FDE_START_OFFSET
);
6200 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6201 htab
->plt_second_eh_frame
->contents
6202 + PLT_FDE_START_OFFSET
);
6204 if (htab
->plt_second_eh_frame
->sec_info_type
6205 == SEC_INFO_TYPE_EH_FRAME
)
6207 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6208 htab
->plt_second_eh_frame
,
6209 htab
->plt_second_eh_frame
->contents
))
6214 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6215 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6217 /* Fill PLT entries for undefined weak symbols in PIE. */
6218 if (bfd_link_pie (info
))
6219 bfd_hash_traverse (&info
->hash
->table
,
6220 elf_i386_pie_finish_undefweak_symbol
,
6226 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6227 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6228 It has to be done before elf_link_sort_relocs is called so that
6229 dynamic relocations are properly sorted. */
6232 elf_i386_output_arch_local_syms
6233 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6234 struct bfd_link_info
*info
,
6235 void *flaginfo ATTRIBUTE_UNUSED
,
6236 int (*func
) (void *, const char *,
6239 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6241 struct elf_i386_link_hash_table
*htab
= elf_i386_hash_table (info
);
6245 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6246 htab_traverse (htab
->loc_hash_table
,
6247 elf_i386_finish_local_dynamic_symbol
,
6253 /* Sort relocs into address order. */
6256 compare_relocs (const void *ap
, const void *bp
)
6258 const arelent
*a
= * (const arelent
**) ap
;
6259 const arelent
*b
= * (const arelent
**) bp
;
6261 if (a
->address
> b
->address
)
6263 else if (a
->address
< b
->address
)
6269 enum elf_i386_plt_type
6274 plt_second
= 1 << 2,
6283 enum elf_i386_plt_type type
;
6284 unsigned int plt_got_offset
;
6285 unsigned int plt_entry_size
;
6289 /* Forward declaration. */
6290 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
;
6292 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
6293 dynamic relocations. */
6296 elf_i386_get_synthetic_symtab (bfd
*abfd
,
6297 long symcount ATTRIBUTE_UNUSED
,
6298 asymbol
**syms ATTRIBUTE_UNUSED
,
6303 long size
, count
, i
, n
;
6305 unsigned int plt_got_offset
, plt_entry_size
;
6307 bfd_byte
*plt_contents
;
6308 long dynrelcount
, relsize
;
6309 arelent
**dynrelbuf
;
6310 const struct elf_i386_lazy_plt_layout
*lazy_plt
;
6311 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt
;
6312 const struct elf_i386_lazy_plt_layout
*lazy_ibt_plt
;
6313 const struct elf_i386_non_lazy_plt_layout
*non_lazy_ibt_plt
;
6317 enum elf_i386_plt_type plt_type
;
6318 struct elf_i386_plt plts
[] =
6320 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0 },
6321 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0 },
6322 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0 },
6323 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0 }
6328 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
6331 if (dynsymcount
<= 0)
6334 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
6338 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
6339 if (dynrelbuf
== NULL
)
6342 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
6345 /* Sort the relocs by address. */
6346 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*), compare_relocs
);
6348 non_lazy_plt
= NULL
;
6349 /* Silence GCC 6. */
6351 non_lazy_ibt_plt
= NULL
;
6352 lazy_ibt_plt
= NULL
;
6353 switch (get_elf_i386_backend_data (abfd
)->os
)
6356 non_lazy_plt
= &elf_i386_non_lazy_plt
;
6357 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
6358 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
6361 lazy_plt
= &elf_i386_lazy_plt
;
6364 lazy_plt
= &elf_i386_nacl_plt
;
6371 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6373 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
6377 /* Get the PLT section contents. */
6378 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6379 if (plt_contents
== NULL
)
6381 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6382 plt_contents
, 0, plt
->size
))
6384 free (plt_contents
);
6388 /* Check what kind of PLT it is. */
6389 plt_type
= plt_unknown
;
6390 if (plts
[j
].type
== plt_unknown
)
6392 /* Match lazy PLT first. */
6393 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
6394 lazy_plt
->plt0_got1_offset
) == 0)
6396 /* The fist entry in the lazy IBT PLT is the same as the
6398 if (lazy_ibt_plt
!= NULL
6399 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
6400 lazy_ibt_plt
->plt_entry
,
6401 lazy_ibt_plt
->plt_got_offset
) == 0))
6402 plt_type
= plt_lazy
| plt_second
;
6404 plt_type
= plt_lazy
;
6406 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
6407 lazy_plt
->plt0_got1_offset
) == 0)
6409 /* The fist entry in the PIC lazy IBT PLT is the same as
6410 the normal PIC lazy PLT. */
6411 if (lazy_ibt_plt
!= NULL
6412 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
6413 lazy_ibt_plt
->pic_plt_entry
,
6414 lazy_ibt_plt
->plt_got_offset
) == 0))
6415 plt_type
= plt_lazy
| plt_pic
| plt_second
;
6417 plt_type
= plt_lazy
| plt_pic
;
6421 if (non_lazy_plt
!= NULL
6422 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
))
6424 /* Match non-lazy PLT. */
6425 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
6426 non_lazy_plt
->plt_got_offset
) == 0)
6427 plt_type
= plt_non_lazy
;
6428 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
6429 non_lazy_plt
->plt_got_offset
) == 0)
6433 if ((non_lazy_ibt_plt
!= NULL
)
6434 && (plt_type
== plt_unknown
|| plt_type
== plt_second
))
6436 if (memcmp (plt_contents
,
6437 non_lazy_ibt_plt
->plt_entry
,
6438 non_lazy_ibt_plt
->plt_got_offset
) == 0)
6440 /* Match IBT PLT. */
6441 plt_type
= plt_second
;
6442 non_lazy_plt
= non_lazy_ibt_plt
;
6444 else if (memcmp (plt_contents
,
6445 non_lazy_ibt_plt
->pic_plt_entry
,
6446 non_lazy_ibt_plt
->plt_got_offset
) == 0)
6448 /* Match PIC IBT PLT. */
6449 plt_type
= plt_second
| plt_pic
;
6450 non_lazy_plt
= non_lazy_ibt_plt
;
6454 if (plt_type
== plt_unknown
)
6458 plts
[j
].type
= plt_type
;
6460 if ((plt_type
& plt_lazy
))
6462 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
6463 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
6464 /* Skip PLT0 in lazy PLT. */
6469 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
6470 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
6474 /* Skip lazy PLT when the second PLT is used. */
6475 if ((plt_type
& (plt_lazy
| plt_second
))
6476 == (plt_lazy
| plt_second
))
6480 n
= plt
->size
/ plts
[j
].plt_entry_size
;
6485 plts
[j
].contents
= plt_contents
;
6487 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
6488 if ((plt_type
& plt_pic
))
6489 got_addr
= (bfd_vma
) -1;
6492 size
= count
* sizeof (asymbol
);
6493 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
6497 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6498 if (plts
[j
].contents
!= NULL
)
6499 free (plts
[j
].contents
);
6506 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
6508 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
6510 got_addr
= sec
->vma
;
6513 sec
= bfd_get_section_by_name (abfd
, ".got");
6515 got_addr
= sec
->vma
;
6518 if (got_addr
== (bfd_vma
) -1)
6522 /* Check for each PLT section. */
6525 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6526 if ((plt_contents
= plts
[j
].contents
) != NULL
)
6531 plt_got_offset
= plts
[j
].plt_got_offset
;
6532 plt_entry_size
= plts
[j
].plt_entry_size
;
6536 if ((plts
[j
].type
& plt_lazy
))
6538 /* Skip PLT0 in lazy PLT. */
6540 offset
= plt_entry_size
;
6548 /* Check each PLT entry against dynamic relocations. */
6549 for (; k
< plts
[j
].count
; k
++)
6556 /* Get the GOT offset, a signed 32-bit integer. */
6557 off
= H_GET_32 (abfd
, (plt_contents
+ offset
6559 got_vma
= got_addr
+ off
;
6561 /* Binary search. */
6565 while ((min
+ 1) < max
)
6569 mid
= (min
+ max
) / 2;
6571 if (got_vma
> r
->address
)
6573 else if (got_vma
< r
->address
)
6582 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6583 if (got_vma
== p
->address
6585 && (p
->howto
->type
== R_386_JUMP_SLOT
6586 || p
->howto
->type
== R_386_GLOB_DAT
6587 || p
->howto
->type
== R_386_IRELATIVE
))
6589 *s
= **p
->sym_ptr_ptr
;
6590 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6591 set. Since we are defining a symbol, ensure one
6593 if ((s
->flags
& BSF_LOCAL
) == 0)
6594 s
->flags
|= BSF_GLOBAL
;
6595 s
->flags
|= BSF_SYNTHETIC
;
6596 /* This is no longer a section symbol. */
6597 s
->flags
&= ~BSF_SECTION_SYM
;
6599 s
->the_bfd
= plt
->owner
;
6601 /* Store relocation for later use. */
6603 /* Add @plt to function name later. */
6604 size
+= strlen (s
->name
) + sizeof ("@plt");
6606 size
+= sizeof ("+0x") - 1 + 8;
6610 offset
+= plt_entry_size
;
6614 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
6620 /* Allocate space for @plt suffixes. */
6621 names
= (char *) bfd_malloc (size
);
6626 for (i
= 0; i
< count
; i
++)
6628 /* Add @plt to function name. */
6629 arelent
*p
= (arelent
*) s
->udata
.p
;
6632 size
= strlen (s
->name
);
6633 memcpy (names
, s
->name
, size
);
6640 memcpy (names
, "+0x", sizeof ("+0x") - 1);
6641 names
+= sizeof ("+0x") - 1;
6642 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
6643 for (a
= buf
; *a
== '0'; ++a
)
6646 memcpy (names
, a
, size
);
6649 memcpy (names
, "@plt", sizeof ("@plt"));
6650 names
+= sizeof ("@plt");
6654 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6655 if (plts
[j
].contents
!= NULL
)
6656 free (plts
[j
].contents
);
6663 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6666 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
6668 if (h
->plt
.offset
!= (bfd_vma
) -1
6670 && !h
->pointer_equality_needed
)
6673 return _bfd_elf_hash_symbol (h
);
6676 /* Parse i386 GNU properties. */
6678 static enum elf_property_kind
6679 elf_i386_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6680 bfd_byte
*ptr
, unsigned int datasz
)
6686 case GNU_PROPERTY_X86_ISA_1_USED
:
6687 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6688 case GNU_PROPERTY_X86_FEATURE_1_AND
:
6692 ((type
== GNU_PROPERTY_X86_ISA_1_USED
6693 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6694 : (type
== GNU_PROPERTY_X86_ISA_1_NEEDED
6695 ? _("error: %B: <corrupt x86 ISA needed size: 0x%x>")
6696 : _("error: %B: <corrupt x86 feature size: 0x%x>"))),
6698 return property_corrupt
;
6700 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
6701 /* Combine properties of the same type. */
6702 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
6703 prop
->pr_kind
= property_number
;
6707 return property_ignored
;
6710 return property_number
;
6713 /* Merge i386 GNU property BPROP with APROP. If APROP isn't NULL,
6714 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6715 should be merged with ABFD. */
6718 elf_i386_merge_gnu_properties (struct bfd_link_info
*info
,
6719 bfd
*abfd ATTRIBUTE_UNUSED
,
6720 elf_property
*aprop
,
6721 elf_property
*bprop
)
6723 unsigned int number
, features
;
6724 bfd_boolean updated
= FALSE
;
6725 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
6729 case GNU_PROPERTY_X86_ISA_1_USED
:
6730 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6731 if (aprop
!= NULL
&& bprop
!= NULL
)
6733 number
= aprop
->u
.number
;
6734 aprop
->u
.number
= number
| bprop
->u
.number
;
6735 updated
= number
!= (unsigned int) aprop
->u
.number
;
6739 /* Return TRUE if APROP is NULL to indicate that BPROP should
6740 be added to ABFD. */
6741 updated
= aprop
== NULL
;
6745 case GNU_PROPERTY_X86_FEATURE_1_AND
:
6746 /* Only one of APROP and BPROP can be NULL:
6747 1. APROP & BPROP when both APROP and BPROP aren't NULL.
6748 2. If APROP is NULL, remove x86 feature.
6749 3. Otherwise, do nothing.
6751 if (aprop
!= NULL
&& bprop
!= NULL
)
6755 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6757 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
6758 number
= aprop
->u
.number
;
6759 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6760 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6761 aprop
->u
.number
= (number
& bprop
->u
.number
) | features
;
6762 updated
= number
!= (unsigned int) aprop
->u
.number
;
6763 /* Remove the property if all feature bits are cleared. */
6764 if (aprop
->u
.number
== 0)
6765 aprop
->pr_kind
= property_remove
;
6771 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6773 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
6776 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6777 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6780 number
= aprop
->u
.number
;
6781 aprop
->u
.number
= number
| features
;
6782 updated
= number
!= (unsigned int) aprop
->u
.number
;
6786 bprop
->u
.number
|= features
;
6790 else if (aprop
!= NULL
)
6792 aprop
->pr_kind
= property_remove
;
6799 /* Never should happen. */
6806 /* Set up i386 GNU properties. Return the first relocatable ELF input
6807 with GNU properties if found. Otherwise, return NULL. */
6810 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
6812 bfd_boolean normal_target
;
6813 bfd_boolean lazy_plt
;
6814 asection
*sec
, *pltsec
;
6816 bfd_boolean use_ibt_plt
;
6817 unsigned int plt_alignment
, features
;
6818 struct elf_i386_link_hash_table
*htab
;
6823 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6825 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
6828 /* Turn on GNU_PROPERTY_X86_FEATURE_1_IBT and
6829 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6833 for (pbfd
= info
->input_bfds
;
6835 pbfd
= pbfd
->link
.next
)
6836 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
6837 && bfd_count_sections (pbfd
) != 0)
6841 if (elf_properties (pbfd
) != NULL
)
6843 /* Find a normal input file with GNU property note. */
6844 prop
= _bfd_elf_get_property (pbfd
,
6845 GNU_PROPERTY_X86_FEATURE_1_AND
,
6847 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
6848 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6849 prop
->u
.number
|= features
;
6850 prop
->pr_kind
= property_number
;
6855 if (pbfd
== NULL
&& ebfd
!= NULL
)
6857 /* Create GNU_PROPERTY_X86_FEATURE_1_IBT if needed. */
6858 prop
= _bfd_elf_get_property (ebfd
,
6859 GNU_PROPERTY_X86_FEATURE_1_AND
,
6861 prop
->u
.number
= features
;
6862 prop
->pr_kind
= property_number
;
6864 sec
= bfd_make_section_with_flags (ebfd
,
6865 NOTE_GNU_PROPERTY_SECTION_NAME
,
6873 info
->callbacks
->einfo (_("%F: failed to create GNU property section\n"));
6875 if (!bfd_set_section_alignment (ebfd
, sec
, 2))
6876 goto error_alignment
;
6878 elf_section_type (sec
) = SHT_NOTE
;
6882 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
6884 if (bfd_link_relocatable (info
))
6887 htab
= elf_i386_hash_table (info
);
6891 use_ibt_plt
= info
->ibtplt
|| info
->ibt
;
6892 if (!use_ibt_plt
&& pbfd
!= NULL
)
6894 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
6895 elf_property_list
*p
;
6897 /* The property list is sorted in order of type. */
6898 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
6900 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
6902 use_ibt_plt
= !!(p
->property
.u
.number
6903 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
6906 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
6911 dynobj
= htab
->elf
.dynobj
;
6913 /* Set htab->elf.dynobj here so that there is no need to check and
6914 set it in check_relocs. */
6919 /* Find a normal input file to hold linker created
6921 for (abfd
= info
->input_bfds
;
6923 abfd
= abfd
->link
.next
)
6925 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0)
6927 htab
->elf
.dynobj
= abfd
;
6933 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
6934 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
6935 canonical function address. */
6936 htab
->plt
.has_plt0
= 1;
6937 normal_target
= FALSE
;
6939 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
6944 htab
->lazy_plt
= &elf_i386_lazy_ibt_plt
;
6945 htab
->non_lazy_plt
= &elf_i386_non_lazy_ibt_plt
;
6949 htab
->lazy_plt
= &elf_i386_lazy_plt
;
6950 htab
->non_lazy_plt
= &elf_i386_non_lazy_plt
;
6952 normal_target
= TRUE
;
6955 htab
->lazy_plt
= &elf_i386_lazy_plt
;
6956 htab
->non_lazy_plt
= NULL
;
6957 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
,
6959 info
->callbacks
->einfo (_("%F: failed to create VxWorks dynamic sections\n"));
6962 htab
->lazy_plt
= &elf_i386_nacl_plt
;
6963 htab
->non_lazy_plt
= NULL
;
6967 pltsec
= htab
->elf
.splt
;
6969 /* If the non-lazy PLT is available, use it for all PLT entries if
6970 there are no PLT0 or no .plt section. */
6971 if (htab
->non_lazy_plt
!= NULL
6972 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
6975 if (bfd_link_pic (info
))
6977 = htab
->non_lazy_plt
->pic_plt_entry
;
6980 = htab
->non_lazy_plt
->plt_entry
;
6981 htab
->plt
.plt_entry_size
6982 = htab
->non_lazy_plt
->plt_entry_size
;
6983 htab
->plt
.plt_got_offset
6984 = htab
->non_lazy_plt
->plt_got_offset
;
6985 htab
->plt
.eh_frame_plt_size
6986 = htab
->non_lazy_plt
->eh_frame_plt_size
;
6987 htab
->plt
.eh_frame_plt
6988 = htab
->non_lazy_plt
->eh_frame_plt
;
6993 if (bfd_link_pic (info
))
6995 htab
->plt
.plt0_entry
6996 = htab
->lazy_plt
->pic_plt0_entry
;
6998 = htab
->lazy_plt
->pic_plt_entry
;
7002 htab
->plt
.plt0_entry
7003 = htab
->lazy_plt
->plt0_entry
;
7005 = htab
->lazy_plt
->plt_entry
;
7007 htab
->plt
.plt_entry_size
7008 = htab
->lazy_plt
->plt_entry_size
;
7009 htab
->plt
.plt_got_offset
7010 = htab
->lazy_plt
->plt_got_offset
;
7011 htab
->plt
.eh_frame_plt_size
7012 = htab
->lazy_plt
->eh_frame_plt_size
;
7013 htab
->plt
.eh_frame_plt
7014 = htab
->lazy_plt
->eh_frame_plt
;
7017 /* Return if there are no normal input files. */
7021 /* Since create_dynamic_sections isn't always called, but GOT
7022 relocations need GOT relocations, create them here so that we
7023 don't need to do it in check_relocs. */
7024 if (htab
->elf
.sgot
== NULL
7025 && !_bfd_elf_create_got_section (dynobj
, info
))
7026 info
->callbacks
->einfo (_("%F: failed to create GOT sections\n"));
7028 /* Create the ifunc sections here so that check_relocs can be
7030 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
7031 info
->callbacks
->einfo (_("%F: failed to create ifunc sections\n"));
7033 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
7037 /* Whe creating executable, set the contents of the .interp
7038 section to the interpreter. */
7039 if (bfd_link_executable (info
) && !info
->nointerp
)
7041 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
7044 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7045 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7049 /* Don't change PLT section alignment for NaCl since it uses
7050 64-byte PLT entry and sets PLT section alignment to 32
7054 const struct elf_backend_data
*bed
7055 = get_elf_backend_data (dynobj
);
7056 flagword pltflags
= (bed
->dynamic_sec_flags
7061 unsigned int non_lazy_plt_alignment
7062 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
7065 if (!bfd_set_section_alignment (sec
->owner
, sec
,
7067 goto error_alignment
;
7069 /* Create the GOT procedure linkage table. */
7070 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7074 info
->callbacks
->einfo (_("%F: failed to create GOT PLT section\n"));
7076 if (!bfd_set_section_alignment (dynobj
, sec
,
7077 non_lazy_plt_alignment
))
7078 goto error_alignment
;
7080 htab
->plt_got
= sec
;
7088 /* Create the second PLT for Intel IBT support. IBT
7089 PLT is supported only for non-NaCl target and is
7090 is needed only for lazy binding. */
7091 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7095 info
->callbacks
->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
7097 if (!bfd_set_section_alignment (dynobj
, sec
,
7099 goto error_alignment
;
7102 htab
->plt_second
= sec
;
7106 if (!info
->no_ld_generated_unwind_info
)
7108 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
7109 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7110 | SEC_LINKER_CREATED
);
7112 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7116 info
->callbacks
->einfo (_("%F: failed to create PLT .eh_frame section\n"));
7118 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
7119 goto error_alignment
;
7121 htab
->plt_eh_frame
= sec
;
7123 if (htab
->plt_got
!= NULL
)
7125 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7129 info
->callbacks
->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
7131 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
7132 goto error_alignment
;
7134 htab
->plt_got_eh_frame
= sec
;
7141 /* The .iplt section is used for IFUNC symbols in static
7143 sec
= htab
->elf
.iplt
;
7145 && !bfd_set_section_alignment (sec
->owner
, sec
,
7149 info
->callbacks
->einfo (_("%F%A: failed to align section\n"),
7157 #define TARGET_LITTLE_SYM i386_elf32_vec
7158 #define TARGET_LITTLE_NAME "elf32-i386"
7159 #define ELF_ARCH bfd_arch_i386
7160 #define ELF_TARGET_ID I386_ELF_DATA
7161 #define ELF_MACHINE_CODE EM_386
7162 #define ELF_MAXPAGESIZE 0x1000
7164 #define elf_backend_can_gc_sections 1
7165 #define elf_backend_can_refcount 1
7166 #define elf_backend_want_got_plt 1
7167 #define elf_backend_plt_readonly 1
7168 #define elf_backend_want_plt_sym 0
7169 #define elf_backend_got_header_size 12
7170 #define elf_backend_plt_alignment 4
7171 #define elf_backend_dtrel_excludes_plt 1
7172 #define elf_backend_extern_protected_data 1
7173 #define elf_backend_caches_rawsize 1
7174 #define elf_backend_want_dynrelro 1
7176 /* Support RELA for objdump of prelink objects. */
7177 #define elf_info_to_howto elf_i386_info_to_howto_rel
7178 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
7180 #define bfd_elf32_mkobject elf_i386_mkobject
7182 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
7183 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
7184 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
7185 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
7186 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
7188 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
7189 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
7190 #define elf_backend_check_relocs elf_i386_check_relocs
7191 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
7192 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
7193 #define elf_backend_fake_sections elf_i386_fake_sections
7194 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
7195 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
7196 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
7197 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
7198 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
7199 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
7200 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
7201 #define elf_backend_relocate_section elf_i386_relocate_section
7202 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
7203 #define elf_backend_always_size_sections elf_i386_always_size_sections
7204 #define elf_backend_omit_section_dynsym \
7205 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7206 #define elf_backend_hash_symbol elf_i386_hash_symbol
7207 #define elf_backend_fixup_symbol elf_i386_fixup_symbol
7208 #define elf_backend_parse_gnu_properties elf_i386_parse_gnu_properties
7209 #define elf_backend_merge_gnu_properties elf_i386_merge_gnu_properties
7210 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
7212 #include "elf32-target.h"
7214 /* FreeBSD support. */
7216 #undef TARGET_LITTLE_SYM
7217 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
7218 #undef TARGET_LITTLE_NAME
7219 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
7221 #define ELF_OSABI ELFOSABI_FREEBSD
7223 /* The kernel recognizes executables as valid only if they carry a
7224 "FreeBSD" label in the ELF header. So we put this label on all
7225 executables and (for simplicity) also all other object files. */
7228 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
7230 _bfd_elf_post_process_headers (abfd
, info
);
7232 #ifdef OLD_FREEBSD_ABI_LABEL
7234 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
7235 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
7236 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
7241 #undef elf_backend_post_process_headers
7242 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
7244 #define elf32_bed elf32_i386_fbsd_bed
7246 #undef elf_backend_add_symbol_hook
7248 #include "elf32-target.h"
7252 #undef TARGET_LITTLE_SYM
7253 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
7254 #undef TARGET_LITTLE_NAME
7255 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
7257 #undef elf_backend_post_process_headers
7259 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7260 objects won't be recognized. */
7264 #define elf32_bed elf32_i386_sol2_bed
7266 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
7268 #undef elf_backend_static_tls_alignment
7269 #define elf_backend_static_tls_alignment 8
7271 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7273 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7275 #undef elf_backend_want_plt_sym
7276 #define elf_backend_want_plt_sym 1
7278 #undef elf_backend_strtab_flags
7279 #define elf_backend_strtab_flags SHF_STRINGS
7281 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
7282 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
7283 FALSE otherwise. ISECTION is the best guess matching section from the
7284 input bfd IBFD, but it might be NULL. */
7287 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7288 bfd
*obfd ATTRIBUTE_UNUSED
,
7289 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7290 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7292 /* PR 19938: FIXME: Need to add code for setting the sh_info
7293 and sh_link fields of Solaris specific section types. */
7296 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
7297 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
7299 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
7301 The following values should be set:
7304 -----------------------------------------------------------------------------
7305 SHT_SUNW_ancillary The section header index of 0
7306 [0x6fffffee] the associated string table.
7308 SHT_SUNW_capinfo The section header index of For a dynamic object, the
7309 [0x6ffffff0] the associated symbol table. section header index of
7311 SHT_SUNW_capchain table,
7314 SHT_SUNW_symsort The section header index of 0
7315 [0x6ffffff1] the associated symbol table.
7317 SHT_SUNW_tlssort The section header index of 0
7318 [0x6ffffff2] the associated symbol table.
7320 SHT_SUNW_LDYNSYM The section header index of One greater than the
7321 [0x6ffffff3] the associated string table. symbol table index of the
7322 This index is the same string last local symbol,
7323 table used by the SHT_DYNSYM STB_LOCAL. Since
7324 section. SHT_SUNW_LDYNSYM only
7325 contains local symbols,
7326 sh_info is equivalent to
7327 the number of symbols in
7330 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
7331 [0x6ffffff5] the section header index of to named strings, the
7332 the associated section header index of
7333 SHT_SUNW_capinfo table, the associated string
7334 otherwise 0. table, otherwise 0.
7336 SHT_SUNW_move The section header index of 0
7337 [0x6ffffffa] the associated symbol table.
7342 SHT_SUNW_syminfo The section header index of The section header index
7343 [0x6ffffffc] the associated symbol table. of the associated
7346 SHT_SUNW_verdef The section header index of The number of version
7347 [0x6ffffffd] the associated string table. definitions within the
7350 SHT_SUNW_verneed The section header index of The number of version
7351 [0x6ffffffe] the associated string table. dependencies within the
7354 SHT_SUNW_versym The section header index of 0
7355 [0x6fffffff] the associated symbol table. */
7358 #undef elf_backend_copy_special_section_fields
7359 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
7361 #include "elf32-target.h"
7363 /* Intel MCU support. */
7366 elf32_iamcu_elf_object_p (bfd
*abfd
)
7368 /* Set the right machine number for an IAMCU elf32 file. */
7369 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
7373 #undef TARGET_LITTLE_SYM
7374 #define TARGET_LITTLE_SYM iamcu_elf32_vec
7375 #undef TARGET_LITTLE_NAME
7376 #define TARGET_LITTLE_NAME "elf32-iamcu"
7378 #define ELF_ARCH bfd_arch_iamcu
7380 #undef ELF_MACHINE_CODE
7381 #define ELF_MACHINE_CODE EM_IAMCU
7386 #define elf32_bed elf32_iamcu_bed
7388 #undef elf_backend_object_p
7389 #define elf_backend_object_p elf32_iamcu_elf_object_p
7391 #undef elf_backend_static_tls_alignment
7393 #undef elf_backend_want_plt_sym
7394 #define elf_backend_want_plt_sym 0
7396 #undef elf_backend_strtab_flags
7397 #undef elf_backend_copy_special_section_fields
7399 #include "elf32-target.h"
7401 /* Restore defaults. */
7403 #define ELF_ARCH bfd_arch_i386
7404 #undef ELF_MACHINE_CODE
7405 #define ELF_MACHINE_CODE EM_386
7407 /* Native Client support. */
7409 #undef TARGET_LITTLE_SYM
7410 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
7411 #undef TARGET_LITTLE_NAME
7412 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
7414 #define elf32_bed elf32_i386_nacl_bed
7416 #undef ELF_MAXPAGESIZE
7417 #define ELF_MAXPAGESIZE 0x10000
7419 /* Restore defaults. */
7421 #undef elf_backend_want_plt_sym
7422 #define elf_backend_want_plt_sym 0
7423 #undef elf_backend_post_process_headers
7424 #undef elf_backend_static_tls_alignment
7426 /* NaCl uses substantially different PLT entries for the same effects. */
7428 #undef elf_backend_plt_alignment
7429 #define elf_backend_plt_alignment 5
7430 #define NACL_PLT_ENTRY_SIZE 64
7431 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7433 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
7435 0xff, 0x35, /* pushl contents of address */
7436 0, 0, 0, 0, /* replaced with address of .got + 4. */
7437 0x8b, 0x0d, /* movl contents of address, %ecx */
7438 0, 0, 0, 0, /* replaced with address of .got + 8. */
7439 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
7440 0xff, 0xe1 /* jmp *%ecx */
7443 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7445 0x8b, 0x0d, /* movl contents of address, %ecx */
7446 0, 0, 0, 0, /* replaced with GOT slot address. */
7447 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
7448 0xff, 0xe1, /* jmp *%ecx */
7450 /* Pad to the next 32-byte boundary with nop instructions. */
7452 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7453 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7455 /* Lazy GOT entries point here (32-byte aligned). */
7456 0x68, /* pushl immediate */
7457 0, 0, 0, 0, /* replaced with reloc offset. */
7458 0xe9, /* jmp relative */
7459 0, 0, 0, 0, /* replaced with offset to .plt. */
7461 /* Pad to the next 32-byte boundary with nop instructions. */
7462 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7463 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7467 static const bfd_byte
7468 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
7470 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
7471 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
7472 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
7473 0xff, 0xe1, /* jmp *%ecx */
7475 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
7476 so pad to that size with nop instructions. */
7477 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
7480 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7482 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
7483 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
7484 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
7485 0xff, 0xe1, /* jmp *%ecx */
7487 /* Pad to the next 32-byte boundary with nop instructions. */
7489 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7490 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7492 /* Lazy GOT entries point here (32-byte aligned). */
7493 0x68, /* pushl immediate */
7494 0, 0, 0, 0, /* replaced with offset into relocation table. */
7495 0xe9, /* jmp relative */
7496 0, 0, 0, 0, /* replaced with offset to start of .plt. */
7498 /* Pad to the next 32-byte boundary with nop instructions. */
7499 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7500 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7504 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
7506 #if (PLT_CIE_LENGTH != 20 \
7507 || PLT_FDE_LENGTH != 36 \
7508 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7509 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7510 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
7512 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7513 0, 0, 0, 0, /* CIE ID */
7514 1, /* CIE version */
7515 'z', 'R', 0, /* Augmentation string */
7516 1, /* Code alignment factor */
7517 0x7c, /* Data alignment factor: -4 */
7518 8, /* Return address column */
7519 1, /* Augmentation size */
7520 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
7521 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
7522 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
7523 DW_CFA_nop
, DW_CFA_nop
,
7525 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
7526 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
7527 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
7528 0, 0, 0, 0, /* .plt size goes here */
7529 0, /* Augmentation size */
7530 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
7531 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7532 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
7533 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7534 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7535 13, /* Block length */
7536 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
7537 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
7538 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7539 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
7540 DW_CFA_nop
, DW_CFA_nop
7543 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
=
7545 elf_i386_nacl_plt0_entry
, /* plt0_entry */
7546 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
7547 2, /* plt0_got1_offset */
7548 8, /* plt0_got2_offset */
7549 elf_i386_nacl_plt_entry
, /* plt_entry */
7550 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7551 2, /* plt_got_offset */
7552 33, /* plt_reloc_offset */
7553 38, /* plt_plt_offset */
7554 32, /* plt_lazy_offset */
7555 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
7556 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
7557 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
7558 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
7561 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
7563 0x90, /* plt0_pad_byte: nop insn */
7568 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
7570 /* Set the right machine number for a NaCl i386 ELF32 file. */
7571 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
7575 #undef elf_backend_arch_data
7576 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
7578 #undef elf_backend_object_p
7579 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
7580 #undef elf_backend_modify_segment_map
7581 #define elf_backend_modify_segment_map nacl_modify_segment_map
7582 #undef elf_backend_modify_program_headers
7583 #define elf_backend_modify_program_headers nacl_modify_program_headers
7584 #undef elf_backend_final_write_processing
7585 #define elf_backend_final_write_processing nacl_final_write_processing
7587 #include "elf32-target.h"
7589 /* Restore defaults. */
7590 #undef elf_backend_object_p
7591 #undef elf_backend_modify_segment_map
7592 #undef elf_backend_modify_program_headers
7593 #undef elf_backend_final_write_processing
7595 /* VxWorks support. */
7597 #undef TARGET_LITTLE_SYM
7598 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
7599 #undef TARGET_LITTLE_NAME
7600 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
7602 #undef ELF_MAXPAGESIZE
7603 #define ELF_MAXPAGESIZE 0x1000
7604 #undef elf_backend_plt_alignment
7605 #define elf_backend_plt_alignment 4
7607 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
7609 0x90, /* plt0_pad_byte */
7613 #undef elf_backend_arch_data
7614 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
7616 #undef elf_backend_relocs_compatible
7617 #undef elf_backend_add_symbol_hook
7618 #define elf_backend_add_symbol_hook \
7619 elf_vxworks_add_symbol_hook
7620 #undef elf_backend_link_output_symbol_hook
7621 #define elf_backend_link_output_symbol_hook \
7622 elf_vxworks_link_output_symbol_hook
7623 #undef elf_backend_emit_relocs
7624 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7625 #undef elf_backend_final_write_processing
7626 #define elf_backend_final_write_processing \
7627 elf_vxworks_final_write_processing
7628 #undef elf_backend_static_tls_alignment
7630 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
7632 #undef elf_backend_want_plt_sym
7633 #define elf_backend_want_plt_sym 1
7636 #define elf32_bed elf32_i386_vxworks_bed
7638 #include "elf32-target.h"