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.
949 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
950 ((EH)->elf.root.type == bfd_link_hash_undefweak \
951 && bfd_link_executable (INFO) \
952 && (elf_i386_hash_table (INFO)->interp == NULL \
954 || (EH)->has_non_got_reloc \
955 || !(INFO)->dynamic_undefined_weak))
957 /* i386 ELF linker hash entry. */
959 struct elf_i386_link_hash_entry
961 struct elf_link_hash_entry elf
;
963 /* Track dynamic relocs copied for this symbol. */
964 struct elf_dyn_relocs
*dyn_relocs
;
966 #define GOT_UNKNOWN 0
970 #define GOT_TLS_IE_POS 5
971 #define GOT_TLS_IE_NEG 6
972 #define GOT_TLS_IE_BOTH 7
973 #define GOT_TLS_GDESC 8
974 #define GOT_TLS_GD_BOTH_P(type) \
975 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
976 #define GOT_TLS_GD_P(type) \
977 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
978 #define GOT_TLS_GDESC_P(type) \
979 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
980 #define GOT_TLS_GD_ANY_P(type) \
981 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
982 unsigned char tls_type
;
984 /* Symbol is referenced by R_386_GOTOFF relocation. */
985 unsigned int gotoff_ref
: 1;
987 /* Symbol has GOT or PLT relocations. */
988 unsigned int has_got_reloc
: 1;
990 /* Symbol has non-GOT/non-PLT relocations in text sections. */
991 unsigned int has_non_got_reloc
: 1;
993 /* Don't call finish_dynamic_symbol on this symbol. */
994 unsigned int no_finish_dynamic_symbol
: 1;
996 /* 0: symbol isn't ___tls_get_addr.
997 1: symbol is ___tls_get_addr.
998 2: symbol is unknown. */
999 unsigned int tls_get_addr
: 2;
1001 /* Reference count of C/C++ function pointer relocations in read-write
1002 section which can be resolved at run-time. */
1003 bfd_signed_vma func_pointer_refcount
;
1005 /* Information about the GOT PLT entry. Filled when there are both
1006 GOT and PLT relocations against the same function. */
1007 union gotplt_union plt_got
;
1009 /* Information about the second PLT entry. */
1010 union gotplt_union plt_second
;
1012 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
1013 starting at the end of the jump table. */
1014 bfd_vma tlsdesc_got
;
1017 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
1019 struct elf_i386_obj_tdata
1021 struct elf_obj_tdata root
;
1023 /* tls_type for each local got entry. */
1024 char *local_got_tls_type
;
1026 /* GOTPLT entries for TLS descriptors. */
1027 bfd_vma
*local_tlsdesc_gotent
;
1030 #define elf_i386_tdata(abfd) \
1031 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
1033 #define elf_i386_local_got_tls_type(abfd) \
1034 (elf_i386_tdata (abfd)->local_got_tls_type)
1036 #define elf_i386_local_tlsdesc_gotent(abfd) \
1037 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
1039 #define is_i386_elf(bfd) \
1040 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1041 && elf_tdata (bfd) != NULL \
1042 && elf_object_id (bfd) == I386_ELF_DATA)
1045 elf_i386_mkobject (bfd
*abfd
)
1047 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
1051 /* i386 ELF linker hash table. */
1053 struct elf_i386_link_hash_table
1055 struct elf_link_hash_table elf
;
1057 /* Short-cuts to get to dynamic linker sections. */
1059 asection
*plt_eh_frame
;
1060 asection
*plt_second
;
1061 asection
*plt_second_eh_frame
;
1063 asection
*plt_got_eh_frame
;
1065 /* Parameters describing PLT generation. */
1066 struct elf_i386_plt_layout plt
;
1068 /* Parameters describing lazy PLT generation. */
1069 const struct elf_i386_lazy_plt_layout
*lazy_plt
;
1071 /* Parameters describing non-lazy PLT generation. */
1072 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt
;
1076 bfd_signed_vma refcount
;
1080 /* The amount of space used by the reserved portion of the sgotplt
1081 section, plus whatever space is used by the jump slots. */
1082 bfd_vma sgotplt_jump_table_size
;
1084 /* Small local sym cache. */
1085 struct sym_cache sym_cache
;
1087 /* _TLS_MODULE_BASE_ symbol. */
1088 struct bfd_link_hash_entry
*tls_module_base
;
1090 /* Used by local STT_GNU_IFUNC symbols. */
1091 htab_t loc_hash_table
;
1092 void * loc_hash_memory
;
1094 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
1097 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
1098 bfd_vma next_tls_desc_index
;
1100 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
1101 bfd_vma next_jump_slot_index
;
1103 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
1104 bfd_vma next_irelative_index
;
1106 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
1107 to read-only sections. */
1108 bfd_boolean readonly_dynrelocs_against_ifunc
;
1111 /* Get the i386 ELF linker hash table from a link_info structure. */
1113 #define elf_i386_hash_table(p) \
1114 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
1115 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
1117 #define elf_i386_compute_jump_table_size(htab) \
1118 ((htab)->elf.srelplt->reloc_count * 4)
1120 /* Create an entry in an i386 ELF linker hash table. */
1122 static struct bfd_hash_entry
*
1123 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1124 struct bfd_hash_table
*table
,
1127 /* Allocate the structure if it has not already been allocated by a
1131 entry
= (struct bfd_hash_entry
*)
1132 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
1137 /* Call the allocation method of the superclass. */
1138 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1141 struct elf_i386_link_hash_entry
*eh
;
1143 eh
= (struct elf_i386_link_hash_entry
*) entry
;
1144 eh
->dyn_relocs
= NULL
;
1145 eh
->tls_type
= GOT_UNKNOWN
;
1147 eh
->has_got_reloc
= 0;
1148 eh
->has_non_got_reloc
= 0;
1149 eh
->no_finish_dynamic_symbol
= 0;
1150 eh
->tls_get_addr
= 2;
1151 eh
->func_pointer_refcount
= 0;
1152 eh
->plt_got
.offset
= (bfd_vma
) -1;
1153 eh
->tlsdesc_got
= (bfd_vma
) -1;
1159 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1160 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1161 as global symbol. We reuse indx and dynstr_index for local symbol
1162 hash since they aren't used by global symbols in this backend. */
1165 elf_i386_local_htab_hash (const void *ptr
)
1167 struct elf_link_hash_entry
*h
1168 = (struct elf_link_hash_entry
*) ptr
;
1169 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
1172 /* Compare local hash entries. */
1175 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
1177 struct elf_link_hash_entry
*h1
1178 = (struct elf_link_hash_entry
*) ptr1
;
1179 struct elf_link_hash_entry
*h2
1180 = (struct elf_link_hash_entry
*) ptr2
;
1182 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1185 /* Find and/or create a hash entry for local symbol. */
1187 static struct elf_link_hash_entry
*
1188 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
1189 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1192 struct elf_i386_link_hash_entry e
, *ret
;
1193 asection
*sec
= abfd
->sections
;
1194 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1195 ELF32_R_SYM (rel
->r_info
));
1198 e
.elf
.indx
= sec
->id
;
1199 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1200 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1201 create
? INSERT
: NO_INSERT
);
1208 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
1212 ret
= (struct elf_i386_link_hash_entry
*)
1213 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1214 sizeof (struct elf_i386_link_hash_entry
));
1217 memset (ret
, 0, sizeof (*ret
));
1218 ret
->elf
.indx
= sec
->id
;
1219 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1220 ret
->elf
.dynindx
= -1;
1221 ret
->func_pointer_refcount
= 0;
1222 ret
->plt_got
.offset
= (bfd_vma
) -1;
1228 /* Destroy an i386 ELF linker hash table. */
1231 elf_i386_link_hash_table_free (bfd
*obfd
)
1233 struct elf_i386_link_hash_table
*htab
1234 = (struct elf_i386_link_hash_table
*) obfd
->link
.hash
;
1236 if (htab
->loc_hash_table
)
1237 htab_delete (htab
->loc_hash_table
);
1238 if (htab
->loc_hash_memory
)
1239 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1240 _bfd_elf_link_hash_table_free (obfd
);
1243 /* Create an i386 ELF linker hash table. */
1245 static struct bfd_link_hash_table
*
1246 elf_i386_link_hash_table_create (bfd
*abfd
)
1248 struct elf_i386_link_hash_table
*ret
;
1249 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
1251 ret
= (struct elf_i386_link_hash_table
*) bfd_zmalloc (amt
);
1255 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1256 elf_i386_link_hash_newfunc
,
1257 sizeof (struct elf_i386_link_hash_entry
),
1264 ret
->loc_hash_table
= htab_try_create (1024,
1265 elf_i386_local_htab_hash
,
1266 elf_i386_local_htab_eq
,
1268 ret
->loc_hash_memory
= objalloc_create ();
1269 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1271 elf_i386_link_hash_table_free (abfd
);
1274 ret
->elf
.root
.hash_table_free
= elf_i386_link_hash_table_free
;
1276 return &ret
->elf
.root
;
1279 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1282 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1283 struct elf_link_hash_entry
*dir
,
1284 struct elf_link_hash_entry
*ind
)
1286 struct elf_i386_link_hash_entry
*edir
, *eind
;
1288 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1289 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1291 if (eind
->dyn_relocs
!= NULL
)
1293 if (edir
->dyn_relocs
!= NULL
)
1295 struct elf_dyn_relocs
**pp
;
1296 struct elf_dyn_relocs
*p
;
1298 /* Add reloc counts against the indirect sym to the direct sym
1299 list. Merge any entries against the same section. */
1300 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1302 struct elf_dyn_relocs
*q
;
1304 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1305 if (q
->sec
== p
->sec
)
1307 q
->pc_count
+= p
->pc_count
;
1308 q
->count
+= p
->count
;
1315 *pp
= edir
->dyn_relocs
;
1318 edir
->dyn_relocs
= eind
->dyn_relocs
;
1319 eind
->dyn_relocs
= NULL
;
1322 if (ind
->root
.type
== bfd_link_hash_indirect
1323 && dir
->got
.refcount
<= 0)
1325 edir
->tls_type
= eind
->tls_type
;
1326 eind
->tls_type
= GOT_UNKNOWN
;
1329 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1330 generate a R_386_COPY reloc. */
1331 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1333 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1334 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1336 if (ELIMINATE_COPY_RELOCS
1337 && ind
->root
.type
!= bfd_link_hash_indirect
1338 && dir
->dynamic_adjusted
)
1340 /* If called to transfer flags for a weakdef during processing
1341 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1342 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1343 if (dir
->versioned
!= versioned_hidden
)
1344 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1345 dir
->ref_regular
|= ind
->ref_regular
;
1346 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1347 dir
->needs_plt
|= ind
->needs_plt
;
1348 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1352 if (eind
->func_pointer_refcount
> 0)
1354 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1355 eind
->func_pointer_refcount
= 0;
1358 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1362 /* Return TRUE if the TLS access code sequence support transition
1366 elf_i386_check_tls_transition (asection
*sec
,
1368 Elf_Internal_Shdr
*symtab_hdr
,
1369 struct elf_link_hash_entry
**sym_hashes
,
1370 unsigned int r_type
,
1371 const Elf_Internal_Rela
*rel
,
1372 const Elf_Internal_Rela
*relend
)
1374 unsigned int val
, type
, reg
;
1375 unsigned long r_symndx
;
1376 struct elf_link_hash_entry
*h
;
1379 bfd_boolean indirect_call
, tls_get_addr
;
1381 offset
= rel
->r_offset
;
1386 if (offset
< 2 || (rel
+ 1) >= relend
)
1389 indirect_call
= FALSE
;
1390 call
= contents
+ offset
+ 4;
1393 if (r_type
== R_386_TLS_GD
)
1395 /* Check transition from GD access model. Only
1396 leal foo@tlsgd(,%ebx,1), %eax
1397 call ___tls_get_addr@PLT
1399 leal foo@tlsgd(%ebx) %eax
1400 call ___tls_get_addr@PLT
1403 leal foo@tlsgd(%reg), %eax
1404 call *___tls_get_addr@GOT(%reg)
1405 which may be converted to
1406 addr32 call ___tls_get_addr
1407 can transit to different access model. */
1408 if ((offset
+ 10) > sec
->size
1409 || (type
!= 0x8d && type
!= 0x04))
1414 /* leal foo@tlsgd(,%ebx,1), %eax
1415 call ___tls_get_addr@PLT */
1419 if (*(call
- 7) != 0x8d
1427 leal foo@tlsgd(%ebx), %eax
1428 call ___tls_get_addr@PLT
1431 leal foo@tlsgd(%reg), %eax
1432 call *___tls_get_addr@GOT(%reg)
1433 which may be converted to
1434 addr32 call ___tls_get_addr
1436 %eax can't be used as the GOT base register since it
1437 is used to pass parameter to ___tls_get_addr. */
1439 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1442 indirect_call
= call
[0] == 0xff;
1443 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
1444 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1446 && (call
[1] & 0xf8) == 0x90
1447 && (call
[1] & 0x7) == reg
))
1453 /* Check transition from LD access model. Only
1454 leal foo@tlsldm(%ebx), %eax
1455 call ___tls_get_addr@PLT
1457 leal foo@tlsldm(%reg), %eax
1458 call *___tls_get_addr@GOT(%reg)
1459 which may be converted to
1460 addr32 call ___tls_get_addr
1461 can transit to different access model. */
1462 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1465 /* %eax can't be used as the GOT base register since it is
1466 used to pass parameter to ___tls_get_addr. */
1468 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1471 indirect_call
= call
[0] == 0xff;
1472 if (!(reg
== 3 && call
[0] == 0xe8)
1473 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1475 && (call
[1] & 0xf8) == 0x90
1476 && (call
[1] & 0x7) == reg
))
1480 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1481 if (r_symndx
< symtab_hdr
->sh_info
)
1484 tls_get_addr
= FALSE
;
1485 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1486 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1488 struct elf_i386_link_hash_entry
*eh
1489 = (struct elf_i386_link_hash_entry
*) h
;
1490 tls_get_addr
= eh
->tls_get_addr
== 1;
1491 if (eh
->tls_get_addr
> 1)
1493 /* Use strncmp to check ___tls_get_addr since
1494 ___tls_get_addr may be versioned. */
1495 if (strncmp (h
->root
.root
.string
, "___tls_get_addr", 15)
1498 eh
->tls_get_addr
= 1;
1499 tls_get_addr
= TRUE
;
1502 eh
->tls_get_addr
= 0;
1508 else if (indirect_call
)
1509 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
1511 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1512 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
1515 /* Check transition from IE access model:
1516 movl foo@indntpoff(%rip), %eax
1517 movl foo@indntpoff(%rip), %reg
1518 addl foo@indntpoff(%rip), %reg
1521 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1524 /* Check "movl foo@tpoff(%rip), %eax" first. */
1525 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1532 /* Check movl|addl foo@tpoff(%rip), %reg. */
1533 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1534 return ((type
== 0x8b || type
== 0x03)
1535 && (val
& 0xc7) == 0x05);
1537 case R_386_TLS_GOTIE
:
1538 case R_386_TLS_IE_32
:
1539 /* Check transition from {IE_32,GOTIE} access model:
1540 subl foo@{tpoff,gontoff}(%reg1), %reg2
1541 movl foo@{tpoff,gontoff}(%reg1), %reg2
1542 addl foo@{tpoff,gontoff}(%reg1), %reg2
1545 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1548 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1549 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1552 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1553 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1555 case R_386_TLS_GOTDESC
:
1556 /* Check transition from GDesc access model:
1557 leal x@tlsdesc(%ebx), %eax
1559 Make sure it's a leal adding ebx to a 32-bit offset
1560 into any register, although it's probably almost always
1563 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1566 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1569 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1570 return (val
& 0xc7) == 0x83;
1572 case R_386_TLS_DESC_CALL
:
1573 /* Check transition from GDesc access model:
1574 call *x@tlsdesc(%eax)
1576 if (offset
+ 2 <= sec
->size
)
1578 /* Make sure that it's a call *x@tlsdesc(%eax). */
1579 call
= contents
+ offset
;
1580 return call
[0] == 0xff && call
[1] == 0x10;
1590 /* Return TRUE if the TLS access transition is OK or no transition
1591 will be performed. Update R_TYPE if there is a transition. */
1594 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1595 asection
*sec
, bfd_byte
*contents
,
1596 Elf_Internal_Shdr
*symtab_hdr
,
1597 struct elf_link_hash_entry
**sym_hashes
,
1598 unsigned int *r_type
, int tls_type
,
1599 const Elf_Internal_Rela
*rel
,
1600 const Elf_Internal_Rela
*relend
,
1601 struct elf_link_hash_entry
*h
,
1602 unsigned long r_symndx
,
1603 bfd_boolean from_relocate_section
)
1605 unsigned int from_type
= *r_type
;
1606 unsigned int to_type
= from_type
;
1607 bfd_boolean check
= TRUE
;
1609 /* Skip TLS transition for functions. */
1611 && (h
->type
== STT_FUNC
1612 || h
->type
== STT_GNU_IFUNC
))
1618 case R_386_TLS_GOTDESC
:
1619 case R_386_TLS_DESC_CALL
:
1620 case R_386_TLS_IE_32
:
1622 case R_386_TLS_GOTIE
:
1623 if (bfd_link_executable (info
))
1626 to_type
= R_386_TLS_LE_32
;
1627 else if (from_type
!= R_386_TLS_IE
1628 && from_type
!= R_386_TLS_GOTIE
)
1629 to_type
= R_386_TLS_IE_32
;
1632 /* When we are called from elf_i386_relocate_section, there may
1633 be additional transitions based on TLS_TYPE. */
1634 if (from_relocate_section
)
1636 unsigned int new_to_type
= to_type
;
1638 if (bfd_link_executable (info
)
1641 && (tls_type
& GOT_TLS_IE
))
1642 new_to_type
= R_386_TLS_LE_32
;
1644 if (to_type
== R_386_TLS_GD
1645 || to_type
== R_386_TLS_GOTDESC
1646 || to_type
== R_386_TLS_DESC_CALL
)
1648 if (tls_type
== GOT_TLS_IE_POS
)
1649 new_to_type
= R_386_TLS_GOTIE
;
1650 else if (tls_type
& GOT_TLS_IE
)
1651 new_to_type
= R_386_TLS_IE_32
;
1654 /* We checked the transition before when we were called from
1655 elf_i386_check_relocs. We only want to check the new
1656 transition which hasn't been checked before. */
1657 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1658 to_type
= new_to_type
;
1664 if (bfd_link_executable (info
))
1665 to_type
= R_386_TLS_LE_32
;
1672 /* Return TRUE if there is no transition. */
1673 if (from_type
== to_type
)
1676 /* Check if the transition can be performed. */
1678 && ! elf_i386_check_tls_transition (sec
, contents
,
1679 symtab_hdr
, sym_hashes
,
1680 from_type
, rel
, relend
))
1682 reloc_howto_type
*from
, *to
;
1685 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1686 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1689 name
= h
->root
.root
.string
;
1692 struct elf_i386_link_hash_table
*htab
;
1694 htab
= elf_i386_hash_table (info
);
1699 Elf_Internal_Sym
*isym
;
1701 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1703 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1708 /* xgettext:c-format */
1709 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1710 "in section `%A' failed"),
1711 abfd
, from
->name
, to
->name
, name
,
1712 (unsigned long) rel
->r_offset
, sec
);
1713 bfd_set_error (bfd_error_bad_value
);
1721 /* With the local symbol, foo, we convert
1722 mov foo@GOT[(%reg1)], %reg2
1724 lea foo[@GOTOFF(%reg1)], %reg2
1726 call/jmp *foo@GOT[(%reg)]
1728 nop call foo/jmp foo nop
1729 When PIC is false, convert
1730 test %reg1, foo@GOT[(%reg2)]
1734 binop foo@GOT[(%reg1)], %reg2
1737 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1742 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1744 Elf_Internal_Rela
*irel
,
1745 struct elf_link_hash_entry
*h
,
1746 bfd_boolean
*converted
,
1747 struct bfd_link_info
*link_info
)
1749 struct elf_i386_link_hash_table
*htab
;
1750 unsigned int opcode
;
1752 bfd_boolean baseless
;
1753 Elf_Internal_Sym
*isym
;
1754 unsigned int addend
;
1758 bfd_boolean to_reloc_32
;
1759 unsigned int r_type
;
1760 unsigned int r_symndx
;
1761 bfd_vma roff
= irel
->r_offset
;
1766 /* Addend for R_386_GOT32X relocations must be 0. */
1767 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1771 htab
= elf_i386_hash_table (link_info
);
1772 is_pic
= bfd_link_pic (link_info
);
1774 r_type
= ELF32_R_TYPE (irel
->r_info
);
1775 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1777 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1778 baseless
= (modrm
& 0xc7) == 0x5;
1780 if (baseless
&& is_pic
)
1782 /* For PIC, disallow R_386_GOT32X without a base register
1783 since we don't know what the GOT base is. */
1788 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1790 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1793 name
= h
->root
.root
.string
;
1796 /* xgettext:c-format */
1797 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1798 " register can not be used when making a shared object"),
1803 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1805 /* Convert to R_386_32 if PIC is false or there is no base
1807 to_reloc_32
= !is_pic
|| baseless
;
1809 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1813 if (opcode
== 0x0ff)
1814 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1815 goto convert_branch
;
1817 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1818 "test %reg1, foo@GOT(%reg2)" and
1819 "binop foo@GOT[(%reg1)], %reg2". */
1823 /* Undefined weak symbol is only bound locally in executable
1824 and its reference is resolved as 0. */
1825 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
, TRUE
,
1826 elf_i386_hash_entry (h
)))
1830 /* No direct branch to 0 for PIC. */
1834 goto convert_branch
;
1838 /* We can convert load of address 0 to R_386_32. */
1846 /* We have "call/jmp *foo@GOT[(%reg)]". */
1847 if ((h
->root
.type
== bfd_link_hash_defined
1848 || h
->root
.type
== bfd_link_hash_defweak
)
1849 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1851 /* The function is locally defined. */
1853 /* Convert R_386_GOT32X to R_386_PC32. */
1854 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1856 struct elf_i386_link_hash_entry
*eh
1857 = (struct elf_i386_link_hash_entry
*) h
;
1859 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1862 /* To support TLS optimization, always use addr32 prefix
1863 for "call *___tls_get_addr@GOT(%reg)". */
1864 if (eh
&& eh
->tls_get_addr
== 1)
1867 nop_offset
= irel
->r_offset
- 2;
1871 nop
= link_info
->call_nop_byte
;
1872 if (link_info
->call_nop_as_suffix
)
1874 nop_offset
= roff
+ 3;
1875 irel
->r_offset
-= 1;
1878 nop_offset
= roff
- 2;
1883 /* Convert to "jmp foo nop". */
1886 nop_offset
= roff
+ 3;
1887 irel
->r_offset
-= 1;
1890 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1891 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1892 /* When converting to PC-relative relocation, we
1893 need to adjust addend by -4. */
1894 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1895 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1902 /* We have "mov foo@GOT[(%re1g)], %reg2",
1903 "test %reg1, foo@GOT(%reg2)" and
1904 "binop foo@GOT[(%reg1)], %reg2".
1906 Avoid optimizing _DYNAMIC since ld.so may use its
1907 link-time address. */
1908 if (h
== htab
->elf
.hdynamic
)
1911 /* def_regular is set by an assignment in a linker script in
1912 bfd_elf_record_link_assignment. start_stop is set on
1913 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1916 || h
->root
.type
== bfd_link_hash_defined
1917 || h
->root
.type
== bfd_link_hash_defweak
)
1918 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)))
1925 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1926 "mov $foo, %reg2" with R_386_32. */
1928 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1929 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1934 /* Convert "mov foo@GOT(%reg1), %reg2" to
1935 "lea foo@GOTOFF(%reg1), %reg2". */
1936 r_type
= R_386_GOTOFF
;
1942 /* Only R_386_32 is supported. */
1948 /* Convert "test %reg1, foo@GOT(%reg2)" to
1949 "test $foo, %reg1". */
1950 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1955 /* Convert "binop foo@GOT(%reg1), %reg2" to
1956 "binop $foo, %reg2". */
1958 | (modrm
& 0x38) >> 3
1962 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1966 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1967 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1976 /* Rename some of the generic section flags to better document how they
1978 #define need_convert_load sec_flg0
1979 #define check_relocs_failed sec_flg1
1981 /* Look through the relocs for a section during the first phase, and
1982 calculate needed space in the global offset table, procedure linkage
1983 table, and dynamic reloc sections. */
1986 elf_i386_check_relocs (bfd
*abfd
,
1987 struct bfd_link_info
*info
,
1989 const Elf_Internal_Rela
*relocs
)
1991 struct elf_i386_link_hash_table
*htab
;
1992 Elf_Internal_Shdr
*symtab_hdr
;
1993 struct elf_link_hash_entry
**sym_hashes
;
1994 const Elf_Internal_Rela
*rel
;
1995 const Elf_Internal_Rela
*rel_end
;
1999 if (bfd_link_relocatable (info
))
2002 /* Don't do anything special with non-loaded, non-alloced sections.
2003 In particular, any relocs in such sections should not affect GOT
2004 and PLT reference counting (ie. we don't allow them to create GOT
2005 or PLT entries), there's no possibility or desire to optimize TLS
2006 relocs, and there's not much point in propagating relocs to shared
2007 libs that the dynamic linker won't relocate. */
2008 if ((sec
->flags
& SEC_ALLOC
) == 0)
2011 BFD_ASSERT (is_i386_elf (abfd
));
2013 htab
= elf_i386_hash_table (info
);
2016 sec
->check_relocs_failed
= 1;
2020 /* Get the section contents. */
2021 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2022 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2023 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2025 sec
->check_relocs_failed
= 1;
2029 symtab_hdr
= &elf_symtab_hdr (abfd
);
2030 sym_hashes
= elf_sym_hashes (abfd
);
2034 rel_end
= relocs
+ sec
->reloc_count
;
2035 for (rel
= relocs
; rel
< rel_end
; rel
++)
2037 unsigned int r_type
;
2038 unsigned long r_symndx
;
2039 struct elf_link_hash_entry
*h
;
2040 struct elf_i386_link_hash_entry
*eh
;
2041 Elf_Internal_Sym
*isym
;
2043 bfd_boolean size_reloc
;
2045 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2046 r_type
= ELF32_R_TYPE (rel
->r_info
);
2048 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2050 /* xgettext:c-format */
2051 _bfd_error_handler (_("%B: bad symbol index: %d"),
2056 if (r_symndx
< symtab_hdr
->sh_info
)
2058 /* A local symbol. */
2059 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2064 /* Check relocation against local STT_GNU_IFUNC symbol. */
2065 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2067 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
2071 /* Fake a STT_GNU_IFUNC symbol. */
2072 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2074 h
->type
= STT_GNU_IFUNC
;
2077 h
->forced_local
= 1;
2078 h
->root
.type
= bfd_link_hash_defined
;
2086 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2087 while (h
->root
.type
== bfd_link_hash_indirect
2088 || h
->root
.type
== bfd_link_hash_warning
)
2089 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2092 eh
= (struct elf_i386_link_hash_entry
*) h
;
2095 if (r_type
== R_386_GOTOFF
)
2098 /* It is referenced by a non-shared object. */
2100 h
->root
.non_ir_ref_regular
= 1;
2102 if (h
->type
== STT_GNU_IFUNC
)
2103 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2104 |= elf_gnu_symbol_ifunc
;
2107 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
2108 symtab_hdr
, sym_hashes
,
2109 &r_type
, GOT_UNKNOWN
,
2110 rel
, rel_end
, h
, r_symndx
, FALSE
))
2116 htab
->tls_ldm_got
.refcount
+= 1;
2120 /* This symbol requires a procedure linkage table entry. We
2121 actually build the entry in adjust_dynamic_symbol,
2122 because this might be a case of linking PIC code which is
2123 never referenced by a dynamic object, in which case we
2124 don't need to generate a procedure linkage table entry
2127 /* If this is a local symbol, we resolve it directly without
2128 creating a procedure linkage table entry. */
2132 eh
->has_got_reloc
= 1;
2134 h
->plt
.refcount
+= 1;
2141 case R_386_TLS_IE_32
:
2143 case R_386_TLS_GOTIE
:
2144 if (!bfd_link_executable (info
))
2145 info
->flags
|= DF_STATIC_TLS
;
2151 case R_386_TLS_GOTDESC
:
2152 case R_386_TLS_DESC_CALL
:
2153 /* This symbol requires a global offset table entry. */
2155 int tls_type
, old_tls_type
;
2162 tls_type
= GOT_NORMAL
;
2164 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
2165 case R_386_TLS_GOTDESC
:
2166 case R_386_TLS_DESC_CALL
:
2167 tls_type
= GOT_TLS_GDESC
; break;
2168 case R_386_TLS_IE_32
:
2169 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
2170 tls_type
= GOT_TLS_IE_NEG
;
2172 /* If this is a GD->IE transition, we may use either of
2173 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
2174 tls_type
= GOT_TLS_IE
;
2177 case R_386_TLS_GOTIE
:
2178 tls_type
= GOT_TLS_IE_POS
; break;
2183 h
->got
.refcount
+= 1;
2184 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2188 bfd_signed_vma
*local_got_refcounts
;
2190 /* This is a global offset table entry for a local symbol. */
2191 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2192 if (local_got_refcounts
== NULL
)
2196 size
= symtab_hdr
->sh_info
;
2197 size
*= (sizeof (bfd_signed_vma
)
2198 + sizeof (bfd_vma
) + sizeof(char));
2199 local_got_refcounts
= (bfd_signed_vma
*)
2200 bfd_zalloc (abfd
, size
);
2201 if (local_got_refcounts
== NULL
)
2203 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2204 elf_i386_local_tlsdesc_gotent (abfd
)
2205 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2206 elf_i386_local_got_tls_type (abfd
)
2207 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2209 local_got_refcounts
[r_symndx
] += 1;
2210 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
2213 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
2214 tls_type
|= old_tls_type
;
2215 /* If a TLS symbol is accessed using IE at least once,
2216 there is no point to use dynamic model for it. */
2217 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2218 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2219 || (tls_type
& GOT_TLS_IE
) == 0))
2221 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
2222 tls_type
= old_tls_type
;
2223 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2224 && GOT_TLS_GD_ANY_P (tls_type
))
2225 tls_type
|= old_tls_type
;
2229 name
= h
->root
.root
.string
;
2231 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2234 /* xgettext:c-format */
2235 (_("%B: `%s' accessed both as normal and "
2236 "thread local symbol"),
2238 bfd_set_error (bfd_error_bad_value
);
2243 if (old_tls_type
!= tls_type
)
2246 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
2248 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2256 if (r_type
!= R_386_TLS_IE
)
2259 eh
->has_got_reloc
= 1;
2264 case R_386_TLS_LE_32
:
2267 eh
->has_got_reloc
= 1;
2268 if (bfd_link_executable (info
))
2270 info
->flags
|= DF_STATIC_TLS
;
2275 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2276 eh
->has_non_got_reloc
= 1;
2278 /* We are called after all symbols have been resolved. Only
2279 relocation against STT_GNU_IFUNC symbol must go through
2282 && (bfd_link_executable (info
)
2283 || h
->type
== STT_GNU_IFUNC
))
2285 /* If this reloc is in a read-only section, we might
2286 need a copy reloc. We can't check reliably at this
2287 stage whether the section is read-only, as input
2288 sections have not yet been mapped to output sections.
2289 Tentatively set the flag for now, and correct in
2290 adjust_dynamic_symbol. */
2293 /* We may need a .plt entry if the symbol is a function
2294 defined in a shared lib or is a STT_GNU_IFUNC function
2295 referenced from the code or read-only section. */
2297 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2298 h
->plt
.refcount
+= 1;
2300 if (r_type
== R_386_PC32
)
2302 /* Since something like ".long foo - ." may be used
2303 as pointer, make sure that PLT is used if foo is
2304 a function defined in a shared library. */
2305 if ((sec
->flags
& SEC_CODE
) == 0)
2306 h
->pointer_equality_needed
= 1;
2307 else if (h
->type
== STT_GNU_IFUNC
2308 && bfd_link_pic (info
))
2311 /* xgettext:c-format */
2312 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
2313 abfd
, h
->root
.root
.string
);
2314 bfd_set_error (bfd_error_bad_value
);
2320 h
->pointer_equality_needed
= 1;
2321 /* R_386_32 can be resolved at run-time. */
2322 if (r_type
== R_386_32
2323 && (sec
->flags
& SEC_READONLY
) == 0)
2324 eh
->func_pointer_refcount
+= 1;
2330 /* If we are creating a shared library, and this is a reloc
2331 against a global symbol, or a non PC relative reloc
2332 against a local symbol, then we need to copy the reloc
2333 into the shared library. However, if we are linking with
2334 -Bsymbolic, we do not need to copy a reloc against a
2335 global symbol which is defined in an object we are
2336 including in the link (i.e., DEF_REGULAR is set). At
2337 this point we have not seen all the input files, so it is
2338 possible that DEF_REGULAR is not set now but will be set
2339 later (it is never cleared). In case of a weak definition,
2340 DEF_REGULAR may be cleared later by a strong definition in
2341 a shared library. We account for that possibility below by
2342 storing information in the relocs_copied field of the hash
2343 table entry. A similar situation occurs when creating
2344 shared libraries and symbol visibility changes render the
2347 If on the other hand, we are creating an executable, we
2348 may need to keep relocations for symbols satisfied by a
2349 dynamic library if we manage to avoid copy relocs for the
2352 Generate dynamic pointer relocation against STT_GNU_IFUNC
2353 symbol in the non-code section. */
2354 if ((bfd_link_pic (info
)
2355 && (r_type
!= R_386_PC32
2357 && (! (bfd_link_pie (info
)
2358 || SYMBOLIC_BIND (info
, h
))
2359 || h
->root
.type
== bfd_link_hash_defweak
2360 || !h
->def_regular
))))
2362 && h
->type
== STT_GNU_IFUNC
2363 && r_type
== R_386_32
2364 && (sec
->flags
& SEC_CODE
) == 0)
2365 || (ELIMINATE_COPY_RELOCS
2366 && !bfd_link_pic (info
)
2368 && (h
->root
.type
== bfd_link_hash_defweak
2369 || !h
->def_regular
)))
2371 struct elf_dyn_relocs
*p
;
2372 struct elf_dyn_relocs
**head
;
2374 /* We must copy these reloc types into the output file.
2375 Create a reloc section in dynobj and make room for
2379 sreloc
= _bfd_elf_make_dynamic_reloc_section
2380 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
2386 /* If this is a global symbol, we count the number of
2387 relocations we need for this symbol. */
2390 head
= &eh
->dyn_relocs
;
2394 /* Track dynamic relocs needed for local syms too.
2395 We really need local syms available to do this
2400 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2405 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2409 vpp
= &elf_section_data (s
)->local_dynrel
;
2410 head
= (struct elf_dyn_relocs
**)vpp
;
2414 if (p
== NULL
|| p
->sec
!= sec
)
2416 bfd_size_type amt
= sizeof *p
;
2417 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
2429 /* Count size relocation as PC-relative relocation. */
2430 if (r_type
== R_386_PC32
|| size_reloc
)
2435 /* This relocation describes the C++ object vtable hierarchy.
2436 Reconstruct it for later use during GC. */
2437 case R_386_GNU_VTINHERIT
:
2438 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2442 /* This relocation describes which C++ vtable entries are actually
2443 used. Record for later use during GC. */
2444 case R_386_GNU_VTENTRY
:
2445 BFD_ASSERT (h
!= NULL
);
2447 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
2455 if (r_type
== R_386_GOT32X
2456 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2457 sec
->need_convert_load
= 1;
2460 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2462 if (!info
->keep_memory
)
2466 /* Cache the section contents for elf_link_input_bfd. */
2467 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2474 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2476 sec
->check_relocs_failed
= 1;
2480 /* Return the section that should be marked against GC for a given
2484 elf_i386_gc_mark_hook (asection
*sec
,
2485 struct bfd_link_info
*info
,
2486 Elf_Internal_Rela
*rel
,
2487 struct elf_link_hash_entry
*h
,
2488 Elf_Internal_Sym
*sym
)
2491 switch (ELF32_R_TYPE (rel
->r_info
))
2493 case R_386_GNU_VTINHERIT
:
2494 case R_386_GNU_VTENTRY
:
2498 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2501 /* Remove undefined weak symbol from the dynamic symbol table if it
2502 is resolved to 0. */
2505 elf_i386_fixup_symbol (struct bfd_link_info
*info
,
2506 struct elf_link_hash_entry
*h
)
2508 if (h
->dynindx
!= -1
2509 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2510 elf_i386_hash_entry (h
)->has_got_reloc
,
2511 elf_i386_hash_entry (h
)))
2514 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2520 /* Adjust a symbol defined by a dynamic object and referenced by a
2521 regular object. The current definition is in some section of the
2522 dynamic object, but we're not including those sections. We have to
2523 change the definition to something the rest of the link can
2527 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2528 struct elf_link_hash_entry
*h
)
2530 struct elf_i386_link_hash_table
*htab
;
2532 struct elf_i386_link_hash_entry
*eh
;
2533 struct elf_dyn_relocs
*p
;
2535 /* STT_GNU_IFUNC symbol must go through PLT. */
2536 if (h
->type
== STT_GNU_IFUNC
)
2538 /* All local STT_GNU_IFUNC references must be treate as local
2539 calls via local PLT. */
2541 && SYMBOL_CALLS_LOCAL (info
, h
))
2543 bfd_size_type pc_count
= 0, count
= 0;
2544 struct elf_dyn_relocs
**pp
;
2546 eh
= (struct elf_i386_link_hash_entry
*) h
;
2547 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2549 pc_count
+= p
->pc_count
;
2550 p
->count
-= p
->pc_count
;
2559 if (pc_count
|| count
)
2564 /* Increment PLT reference count only for PC-relative
2567 if (h
->plt
.refcount
<= 0)
2568 h
->plt
.refcount
= 1;
2570 h
->plt
.refcount
+= 1;
2575 if (h
->plt
.refcount
<= 0)
2577 h
->plt
.offset
= (bfd_vma
) -1;
2583 /* If this is a function, put it in the procedure linkage table. We
2584 will fill in the contents of the procedure linkage table later,
2585 when we know the address of the .got section. */
2586 if (h
->type
== STT_FUNC
2589 if (h
->plt
.refcount
<= 0
2590 || SYMBOL_CALLS_LOCAL (info
, h
)
2591 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2592 && h
->root
.type
== bfd_link_hash_undefweak
))
2594 /* This case can occur if we saw a PLT32 reloc in an input
2595 file, but the symbol was never referred to by a dynamic
2596 object, or if all references were garbage collected. In
2597 such a case, we don't actually need to build a procedure
2598 linkage table, and we can just do a PC32 reloc instead. */
2599 h
->plt
.offset
= (bfd_vma
) -1;
2606 /* It's possible that we incorrectly decided a .plt reloc was
2607 needed for an R_386_PC32 reloc to a non-function sym in
2608 check_relocs. We can't decide accurately between function and
2609 non-function syms in check-relocs; Objects loaded later in
2610 the link may change h->type. So fix it now. */
2611 h
->plt
.offset
= (bfd_vma
) -1;
2613 /* If this is a weak symbol, and there is a real definition, the
2614 processor independent code will have arranged for us to see the
2615 real definition first, and we can just use the same value. */
2616 if (h
->u
.weakdef
!= NULL
)
2618 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2619 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2620 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2621 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2622 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2623 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2627 /* This is a reference to a symbol defined by a dynamic object which
2628 is not a function. */
2630 /* If we are creating a shared library, we must presume that the
2631 only references to the symbol are via the global offset table.
2632 For such cases we need not do anything here; the relocations will
2633 be handled correctly by relocate_section. */
2634 if (!bfd_link_executable (info
))
2637 /* If there are no references to this symbol that do not use the
2638 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2640 eh
= (struct elf_i386_link_hash_entry
*) h
;
2641 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2644 /* If -z nocopyreloc was given, we won't generate them either. */
2645 if (info
->nocopyreloc
)
2651 htab
= elf_i386_hash_table (info
);
2655 /* If there aren't any dynamic relocs in read-only sections nor
2656 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2657 avoid the copy reloc. This doesn't work on VxWorks, where we can
2658 not have dynamic relocations (other than copy and jump slot
2659 relocations) in an executable. */
2660 if (ELIMINATE_COPY_RELOCS
2662 && get_elf_i386_backend_data (info
->output_bfd
)->os
!= is_vxworks
)
2664 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2666 s
= p
->sec
->output_section
;
2667 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2678 /* We must allocate the symbol in our .dynbss section, which will
2679 become part of the .bss section of the executable. There will be
2680 an entry for this symbol in the .dynsym section. The dynamic
2681 object will contain position independent code, so all references
2682 from the dynamic object to this symbol will go through the global
2683 offset table. The dynamic linker will use the .dynsym entry to
2684 determine the address it must put in the global offset table, so
2685 both the dynamic object and the regular object will refer to the
2686 same memory location for the variable. */
2688 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2689 copy the initial value out of the dynamic object and into the
2690 runtime process image. */
2691 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2693 s
= htab
->elf
.sdynrelro
;
2694 srel
= htab
->elf
.sreldynrelro
;
2698 s
= htab
->elf
.sdynbss
;
2699 srel
= htab
->elf
.srelbss
;
2701 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2703 srel
->size
+= sizeof (Elf32_External_Rel
);
2707 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2710 /* Allocate space in .plt, .got and associated reloc sections for
2714 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2716 struct bfd_link_info
*info
;
2717 struct elf_i386_link_hash_table
*htab
;
2718 struct elf_i386_link_hash_entry
*eh
;
2719 struct elf_dyn_relocs
*p
;
2720 unsigned plt_entry_size
;
2721 bfd_boolean resolved_to_zero
;
2722 const struct elf_i386_backend_data
*bed
;
2724 if (h
->root
.type
== bfd_link_hash_indirect
)
2727 eh
= (struct elf_i386_link_hash_entry
*) h
;
2729 info
= (struct bfd_link_info
*) inf
;
2730 htab
= elf_i386_hash_table (info
);
2734 bed
= get_elf_i386_backend_data (info
->output_bfd
);
2736 plt_entry_size
= htab
->plt
.plt_entry_size
;
2738 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2742 /* Clear the reference count of function pointer relocations if
2743 symbol isn't a normal function. */
2744 if (h
->type
!= STT_FUNC
)
2745 eh
->func_pointer_refcount
= 0;
2747 /* We can't use the GOT PLT if pointer equality is needed since
2748 finish_dynamic_symbol won't clear symbol value and the dynamic
2749 linker won't update the GOT slot. We will get into an infinite
2750 loop at run-time. */
2751 if (htab
->plt_got
!= NULL
2752 && h
->type
!= STT_GNU_IFUNC
2753 && !h
->pointer_equality_needed
2754 && h
->plt
.refcount
> 0
2755 && h
->got
.refcount
> 0)
2757 /* Don't use the regular PLT if there are both GOT and GOTPLT
2759 h
->plt
.offset
= (bfd_vma
) -1;
2761 /* Use the GOT PLT. */
2762 eh
->plt_got
.refcount
= 1;
2765 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2766 here if it is defined and referenced in a non-shared object. */
2767 if (h
->type
== STT_GNU_IFUNC
2770 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2771 &htab
->readonly_dynrelocs_against_ifunc
,
2773 (htab
->plt
.has_plt0
*
2777 asection
*s
= htab
->plt_second
;
2778 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
2780 /* Use the second PLT section if it is created. */
2781 eh
->plt_second
.offset
= s
->size
;
2783 /* Make room for this entry in the second PLT section. */
2784 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2792 /* Don't create the PLT entry if there are only function pointer
2793 relocations which can be resolved at run-time. */
2794 else if (htab
->elf
.dynamic_sections_created
2795 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2796 || eh
->plt_got
.refcount
> 0))
2798 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
2800 /* Clear the reference count of function pointer relocations
2802 eh
->func_pointer_refcount
= 0;
2804 /* Make sure this symbol is output as a dynamic symbol.
2805 Undefined weak syms won't yet be marked as dynamic. */
2806 if (h
->dynindx
== -1
2808 && !resolved_to_zero
2809 && h
->root
.type
== bfd_link_hash_undefweak
)
2811 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2815 if (bfd_link_pic (info
)
2816 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2818 asection
*s
= htab
->elf
.splt
;
2819 asection
*second_s
= htab
->plt_second
;
2820 asection
*got_s
= htab
->plt_got
;
2822 /* If this is the first .plt entry, make room for the special
2823 first entry. The .plt section is used by prelink to undo
2824 prelinking for dynamic relocations. */
2826 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
2829 eh
->plt_got
.offset
= got_s
->size
;
2832 h
->plt
.offset
= s
->size
;
2834 eh
->plt_second
.offset
= second_s
->size
;
2837 /* If this symbol is not defined in a regular file, and we are
2838 not generating a shared library, then set the symbol to this
2839 location in the .plt. This is required to make function
2840 pointers compare as equal between the normal executable and
2841 the shared library. */
2842 if (! bfd_link_pic (info
)
2847 /* We need to make a call to the entry of the GOT PLT
2848 instead of regular PLT entry. */
2849 h
->root
.u
.def
.section
= got_s
;
2850 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2856 /* We need to make a call to the entry of the
2857 second PLT instead of regular PLT entry. */
2858 h
->root
.u
.def
.section
= second_s
;
2859 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
2863 h
->root
.u
.def
.section
= s
;
2864 h
->root
.u
.def
.value
= h
->plt
.offset
;
2869 /* Make room for this entry. */
2871 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2874 s
->size
+= plt_entry_size
;
2876 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2878 /* We also need to make an entry in the .got.plt section,
2879 which will be placed in the .got section by the linker
2881 htab
->elf
.sgotplt
->size
+= 4;
2883 /* There should be no PLT relocation against resolved
2884 undefined weak symbol in executable. */
2885 if (!resolved_to_zero
)
2887 /* We also need to make an entry in the .rel.plt
2889 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2890 htab
->elf
.srelplt
->reloc_count
++;
2894 if (bed
->os
== is_vxworks
&& !bfd_link_pic (info
))
2896 /* VxWorks has a second set of relocations for each PLT entry
2897 in executables. They go in a separate relocation section,
2898 which is processed by the kernel loader. */
2900 /* There are two relocations for the initial PLT entry: an
2901 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2902 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2904 if (h
->plt
.offset
== plt_entry_size
)
2905 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2907 /* There are two extra relocations for each subsequent PLT entry:
2908 an R_386_32 relocation for the GOT entry, and an R_386_32
2909 relocation for the PLT entry. */
2911 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2916 eh
->plt_got
.offset
= (bfd_vma
) -1;
2917 h
->plt
.offset
= (bfd_vma
) -1;
2923 eh
->plt_got
.offset
= (bfd_vma
) -1;
2924 h
->plt
.offset
= (bfd_vma
) -1;
2928 eh
->tlsdesc_got
= (bfd_vma
) -1;
2930 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2931 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2932 if (h
->got
.refcount
> 0
2933 && bfd_link_executable (info
)
2935 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2936 h
->got
.offset
= (bfd_vma
) -1;
2937 else if (h
->got
.refcount
> 0)
2941 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2943 /* Make sure this symbol is output as a dynamic symbol.
2944 Undefined weak syms won't yet be marked as dynamic. */
2945 if (h
->dynindx
== -1
2947 && !resolved_to_zero
2948 && h
->root
.type
== bfd_link_hash_undefweak
)
2950 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2955 if (GOT_TLS_GDESC_P (tls_type
))
2957 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2958 - elf_i386_compute_jump_table_size (htab
);
2959 htab
->elf
.sgotplt
->size
+= 8;
2960 h
->got
.offset
= (bfd_vma
) -2;
2962 if (! GOT_TLS_GDESC_P (tls_type
)
2963 || GOT_TLS_GD_P (tls_type
))
2965 h
->got
.offset
= s
->size
;
2967 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2968 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2971 dyn
= htab
->elf
.dynamic_sections_created
;
2972 /* R_386_TLS_IE_32 needs one dynamic relocation,
2973 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2974 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2975 need two), R_386_TLS_GD needs one if local symbol and two if
2976 global. No dynamic relocation against resolved undefined weak
2977 symbol in executable. */
2978 if (tls_type
== GOT_TLS_IE_BOTH
)
2979 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2980 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2981 || (tls_type
& GOT_TLS_IE
))
2982 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2983 else if (GOT_TLS_GD_P (tls_type
))
2984 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2985 else if (! GOT_TLS_GDESC_P (tls_type
)
2986 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2987 && !resolved_to_zero
)
2988 || h
->root
.type
!= bfd_link_hash_undefweak
)
2989 && (bfd_link_pic (info
)
2990 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2991 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2992 if (GOT_TLS_GDESC_P (tls_type
))
2993 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2996 h
->got
.offset
= (bfd_vma
) -1;
2998 if (eh
->dyn_relocs
== NULL
)
3001 /* In the shared -Bsymbolic case, discard space allocated for
3002 dynamic pc-relative relocs against symbols which turn out to be
3003 defined in regular objects. For the normal shared case, discard
3004 space for pc-relative relocs that have become local due to symbol
3005 visibility changes. */
3007 if (bfd_link_pic (info
))
3009 /* The only reloc that uses pc_count is R_386_PC32, which will
3010 appear on a call or on something like ".long foo - .". We
3011 want calls to protected symbols to resolve directly to the
3012 function rather than going via the plt. If people want
3013 function pointer comparisons to work as expected then they
3014 should avoid writing assembly like ".long foo - .". */
3015 if (SYMBOL_CALLS_LOCAL (info
, h
))
3017 struct elf_dyn_relocs
**pp
;
3019 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3021 p
->count
-= p
->pc_count
;
3030 if (bed
->os
== is_vxworks
)
3032 struct elf_dyn_relocs
**pp
;
3033 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3035 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
3042 /* Also discard relocs on undefined weak syms with non-default
3043 visibility or in PIE. */
3044 if (eh
->dyn_relocs
!= NULL
3045 && h
->root
.type
== bfd_link_hash_undefweak
)
3047 /* Undefined weak symbol is never bound locally in shared
3049 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3050 || resolved_to_zero
)
3054 /* Keep dynamic non-GOT/non-PLT relocation so that we
3055 can branch to 0 without PLT. */
3056 struct elf_dyn_relocs
**pp
;
3058 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3059 if (p
->pc_count
== 0)
3063 /* Remove non-R_386_PC32 relocation. */
3064 p
->count
= p
->pc_count
;
3068 if (eh
->dyn_relocs
!= NULL
)
3070 /* Make sure undefined weak symbols are output
3071 as dynamic symbols in PIEs for dynamic non-GOT
3072 non-PLT reloations. */
3073 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3078 eh
->dyn_relocs
= NULL
;
3080 else if (h
->dynindx
== -1
3081 && !h
->forced_local
)
3083 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3088 else if (ELIMINATE_COPY_RELOCS
)
3090 /* For the non-shared case, discard space for relocs against
3091 symbols which turn out to need copy relocs or are not
3092 dynamic. Keep dynamic relocations for run-time function
3093 pointer initialization. */
3095 if ((!h
->non_got_ref
3096 || eh
->func_pointer_refcount
> 0
3097 || (h
->root
.type
== bfd_link_hash_undefweak
3098 && !resolved_to_zero
))
3101 || (htab
->elf
.dynamic_sections_created
3102 && (h
->root
.type
== bfd_link_hash_undefweak
3103 || h
->root
.type
== bfd_link_hash_undefined
))))
3105 /* Make sure this symbol is output as a dynamic symbol.
3106 Undefined weak syms won't yet be marked as dynamic. */
3107 if (h
->dynindx
== -1
3109 && !resolved_to_zero
3110 && h
->root
.type
== bfd_link_hash_undefweak
)
3112 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3116 /* If that succeeded, we know we'll be keeping all the
3118 if (h
->dynindx
!= -1)
3122 eh
->dyn_relocs
= NULL
;
3123 eh
->func_pointer_refcount
= 0;
3128 /* Finally, allocate space. */
3129 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3133 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3135 BFD_ASSERT (sreloc
!= NULL
);
3136 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3142 /* Allocate space in .plt, .got and associated reloc sections for
3143 local dynamic relocs. */
3146 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
3148 struct elf_link_hash_entry
*h
3149 = (struct elf_link_hash_entry
*) *slot
;
3151 if (h
->type
!= STT_GNU_IFUNC
3155 || h
->root
.type
!= bfd_link_hash_defined
)
3158 return elf_i386_allocate_dynrelocs (h
, inf
);
3161 /* Find any dynamic relocs that apply to read-only sections. */
3164 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3166 struct elf_i386_link_hash_entry
*eh
;
3167 struct elf_dyn_relocs
*p
;
3169 /* Skip local IFUNC symbols. */
3170 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3173 eh
= (struct elf_i386_link_hash_entry
*) h
;
3174 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3176 asection
*s
= p
->sec
->output_section
;
3178 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3180 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3182 info
->flags
|= DF_TEXTREL
;
3184 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3185 || info
->error_textrel
)
3186 /* xgettext:c-format */
3187 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3188 p
->sec
->owner
, h
->root
.root
.string
,
3191 /* Not an error, just cut short the traversal. */
3198 /* Convert load via the GOT slot to load immediate. */
3201 elf_i386_convert_load (bfd
*abfd
, asection
*sec
,
3202 struct bfd_link_info
*link_info
)
3204 struct elf_i386_link_hash_table
*htab
;
3205 Elf_Internal_Shdr
*symtab_hdr
;
3206 Elf_Internal_Rela
*internal_relocs
;
3207 Elf_Internal_Rela
*irel
, *irelend
;
3209 bfd_boolean changed
;
3210 bfd_signed_vma
*local_got_refcounts
;
3212 /* Don't even try to convert non-ELF outputs. */
3213 if (!is_elf_hash_table (link_info
->hash
))
3216 /* Nothing to do if there is no need or no output. */
3217 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3218 || sec
->need_convert_load
== 0
3219 || bfd_is_abs_section (sec
->output_section
))
3222 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3224 /* Load the relocations for this section. */
3225 internal_relocs
= (_bfd_elf_link_read_relocs
3226 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3227 link_info
->keep_memory
));
3228 if (internal_relocs
== NULL
)
3232 htab
= elf_i386_hash_table (link_info
);
3233 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3235 /* Get the section contents. */
3236 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3237 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3240 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3244 irelend
= internal_relocs
+ sec
->reloc_count
;
3245 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3247 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3248 unsigned int r_symndx
;
3249 struct elf_link_hash_entry
*h
;
3250 bfd_boolean converted
;
3252 /* Don't convert R_386_GOT32 since we can't tell if it is applied
3253 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
3254 if (r_type
!= R_386_GOT32X
)
3257 r_symndx
= ELF32_R_SYM (irel
->r_info
);
3258 if (r_symndx
< symtab_hdr
->sh_info
)
3259 h
= elf_i386_get_local_sym_hash (htab
, sec
->owner
,
3260 (const Elf_Internal_Rela
*) irel
,
3264 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3265 while (h
->root
.type
== bfd_link_hash_indirect
3266 || h
->root
.type
== bfd_link_hash_warning
)
3267 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3270 /* STT_GNU_IFUNC must keep GOT32 relocations. */
3271 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3275 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
3276 irel
, h
, &converted
, link_info
))
3281 changed
= converted
;
3284 if (h
->got
.refcount
> 0)
3285 h
->got
.refcount
-= 1;
3289 if (local_got_refcounts
!= NULL
3290 && local_got_refcounts
[r_symndx
] > 0)
3291 local_got_refcounts
[r_symndx
] -= 1;
3296 if (contents
!= NULL
3297 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3299 if (!changed
&& !link_info
->keep_memory
)
3303 /* Cache the section contents for elf_link_input_bfd. */
3304 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3308 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3311 free (internal_relocs
);
3313 elf_section_data (sec
)->relocs
= internal_relocs
;
3319 if (contents
!= NULL
3320 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3322 if (internal_relocs
!= NULL
3323 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3324 free (internal_relocs
);
3328 /* Set the sizes of the dynamic sections. */
3331 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3333 struct elf_i386_link_hash_table
*htab
;
3339 htab
= elf_i386_hash_table (info
);
3342 dynobj
= htab
->elf
.dynobj
;
3346 /* Set up .got offsets for local syms, and space for local dynamic
3348 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3350 bfd_signed_vma
*local_got
;
3351 bfd_signed_vma
*end_local_got
;
3352 char *local_tls_type
;
3353 bfd_vma
*local_tlsdesc_gotent
;
3354 bfd_size_type locsymcount
;
3355 Elf_Internal_Shdr
*symtab_hdr
;
3358 if (! is_i386_elf (ibfd
))
3361 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3363 struct elf_dyn_relocs
*p
;
3365 if (!elf_i386_convert_load (ibfd
, s
, info
))
3368 for (p
= ((struct elf_dyn_relocs
*)
3369 elf_section_data (s
)->local_dynrel
);
3373 if (!bfd_is_abs_section (p
->sec
)
3374 && bfd_is_abs_section (p
->sec
->output_section
))
3376 /* Input section has been discarded, either because
3377 it is a copy of a linkonce section or due to
3378 linker script /DISCARD/, so we'll be discarding
3381 else if ((get_elf_i386_backend_data (output_bfd
)->os
3383 && strcmp (p
->sec
->output_section
->name
,
3386 /* Relocations in vxworks .tls_vars sections are
3387 handled specially by the loader. */
3389 else if (p
->count
!= 0)
3391 srel
= elf_section_data (p
->sec
)->sreloc
;
3392 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3393 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3394 && (info
->flags
& DF_TEXTREL
) == 0)
3396 info
->flags
|= DF_TEXTREL
;
3397 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3398 || info
->error_textrel
)
3399 /* xgettext:c-format */
3400 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3401 p
->sec
->owner
, p
->sec
);
3407 local_got
= elf_local_got_refcounts (ibfd
);
3411 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3412 locsymcount
= symtab_hdr
->sh_info
;
3413 end_local_got
= local_got
+ locsymcount
;
3414 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
3415 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
3417 srel
= htab
->elf
.srelgot
;
3418 for (; local_got
< end_local_got
;
3419 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3421 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3424 if (GOT_TLS_GDESC_P (*local_tls_type
))
3426 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3427 - elf_i386_compute_jump_table_size (htab
);
3428 htab
->elf
.sgotplt
->size
+= 8;
3429 *local_got
= (bfd_vma
) -2;
3431 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3432 || GOT_TLS_GD_P (*local_tls_type
))
3434 *local_got
= s
->size
;
3436 if (GOT_TLS_GD_P (*local_tls_type
)
3437 || *local_tls_type
== GOT_TLS_IE_BOTH
)
3440 if (bfd_link_pic (info
)
3441 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3442 || (*local_tls_type
& GOT_TLS_IE
))
3444 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
3445 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
3446 else if (GOT_TLS_GD_P (*local_tls_type
)
3447 || ! GOT_TLS_GDESC_P (*local_tls_type
))
3448 srel
->size
+= sizeof (Elf32_External_Rel
);
3449 if (GOT_TLS_GDESC_P (*local_tls_type
))
3450 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
3454 *local_got
= (bfd_vma
) -1;
3458 if (htab
->tls_ldm_got
.refcount
> 0)
3460 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
3462 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
3463 htab
->elf
.sgot
->size
+= 8;
3464 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
3467 htab
->tls_ldm_got
.offset
= -1;
3469 /* Allocate global sym .plt and .got entries, and space for global
3470 sym dynamic relocs. */
3471 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
3473 /* Allocate .plt and .got entries, and space for local symbols. */
3474 htab_traverse (htab
->loc_hash_table
,
3475 elf_i386_allocate_local_dynrelocs
,
3478 /* For every jump slot reserved in the sgotplt, reloc_count is
3479 incremented. However, when we reserve space for TLS descriptors,
3480 it's not incremented, so in order to compute the space reserved
3481 for them, it suffices to multiply the reloc count by the jump
3484 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3485 so that R_386_IRELATIVE entries come last. */
3486 if (htab
->elf
.srelplt
)
3488 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
3489 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
3490 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3492 else if (htab
->elf
.irelplt
)
3493 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3496 if (htab
->elf
.sgotplt
)
3498 /* Don't allocate .got.plt section if there are no GOT nor PLT
3499 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
3500 if ((htab
->elf
.hgot
== NULL
3501 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3502 && (htab
->elf
.sgotplt
->size
3503 == get_elf_backend_data (output_bfd
)->got_header_size
)
3504 && (htab
->elf
.splt
== NULL
3505 || htab
->elf
.splt
->size
== 0)
3506 && (htab
->elf
.sgot
== NULL
3507 || htab
->elf
.sgot
->size
== 0)
3508 && (htab
->elf
.iplt
== NULL
3509 || htab
->elf
.iplt
->size
== 0)
3510 && (htab
->elf
.igotplt
== NULL
3511 || htab
->elf
.igotplt
->size
== 0))
3512 htab
->elf
.sgotplt
->size
= 0;
3515 if (_bfd_elf_eh_frame_present (info
))
3517 if (htab
->plt_eh_frame
!= NULL
3518 && htab
->elf
.splt
!= NULL
3519 && htab
->elf
.splt
->size
!= 0
3520 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3521 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
3523 if (htab
->plt_got_eh_frame
!= NULL
3524 && htab
->plt_got
!= NULL
3525 && htab
->plt_got
->size
!= 0
3526 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3527 htab
->plt_got_eh_frame
->size
3528 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3530 /* Unwind info for the second PLT and .plt.got sections are
3532 if (htab
->plt_second_eh_frame
!= NULL
3533 && htab
->plt_second
!= NULL
3534 && htab
->plt_second
->size
!= 0
3535 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
3536 htab
->plt_second_eh_frame
->size
3537 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3540 /* We now have determined the sizes of the various dynamic sections.
3541 Allocate memory for them. */
3543 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3545 bfd_boolean strip_section
= TRUE
;
3547 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3550 if (s
== htab
->elf
.splt
3551 || s
== htab
->elf
.sgot
)
3553 /* Strip this section if we don't need it; see the
3555 /* We'd like to strip these sections if they aren't needed, but if
3556 we've exported dynamic symbols from them we must leave them.
3557 It's too late to tell BFD to get rid of the symbols. */
3559 if (htab
->elf
.hplt
!= NULL
)
3560 strip_section
= FALSE
;
3562 else if (s
== htab
->elf
.sgotplt
3563 || s
== htab
->elf
.iplt
3564 || s
== htab
->elf
.igotplt
3565 || s
== htab
->plt_second
3566 || s
== htab
->plt_got
3567 || s
== htab
->plt_eh_frame
3568 || s
== htab
->plt_got_eh_frame
3569 || s
== htab
->plt_second_eh_frame
3570 || s
== htab
->elf
.sdynbss
3571 || s
== htab
->elf
.sdynrelro
)
3573 /* Strip these too. */
3575 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3578 && s
!= htab
->elf
.srelplt
3579 && s
!= htab
->srelplt2
)
3582 /* We use the reloc_count field as a counter if we need
3583 to copy relocs into the output file. */
3588 /* It's not one of our sections, so don't allocate space. */
3594 /* If we don't need this section, strip it from the
3595 output file. This is mostly to handle .rel.bss and
3596 .rel.plt. We must create both sections in
3597 create_dynamic_sections, because they must be created
3598 before the linker maps input sections to output
3599 sections. The linker does that before
3600 adjust_dynamic_symbol is called, and it is that
3601 function which decides whether anything needs to go
3602 into these sections. */
3604 s
->flags
|= SEC_EXCLUDE
;
3608 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3611 /* Allocate memory for the section contents. We use bfd_zalloc
3612 here in case unused entries are not reclaimed before the
3613 section's contents are written out. This should not happen,
3614 but this way if it does, we get a R_386_NONE reloc instead
3616 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3617 if (s
->contents
== NULL
)
3621 if (htab
->plt_eh_frame
!= NULL
3622 && htab
->plt_eh_frame
->contents
!= NULL
)
3624 memcpy (htab
->plt_eh_frame
->contents
,
3625 htab
->plt
.eh_frame_plt
,
3626 htab
->plt_eh_frame
->size
);
3627 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3628 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3631 if (htab
->plt_got_eh_frame
!= NULL
3632 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3634 memcpy (htab
->plt_got_eh_frame
->contents
,
3635 htab
->non_lazy_plt
->eh_frame_plt
,
3636 htab
->plt_got_eh_frame
->size
);
3637 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3638 (htab
->plt_got_eh_frame
->contents
3639 + PLT_FDE_LEN_OFFSET
));
3642 if (htab
->plt_second_eh_frame
!= NULL
3643 && htab
->plt_second_eh_frame
->contents
!= NULL
)
3645 memcpy (htab
->plt_second_eh_frame
->contents
,
3646 htab
->non_lazy_plt
->eh_frame_plt
,
3647 htab
->plt_second_eh_frame
->size
);
3648 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
3649 (htab
->plt_second_eh_frame
->contents
3650 + PLT_FDE_LEN_OFFSET
));
3653 if (htab
->elf
.dynamic_sections_created
)
3655 /* Add some entries to the .dynamic section. We fill in the
3656 values later, in elf_i386_finish_dynamic_sections, but we
3657 must add the entries now so that we get the correct size for
3658 the .dynamic section. The DT_DEBUG entry is filled in by the
3659 dynamic linker and used by the debugger. */
3660 #define add_dynamic_entry(TAG, VAL) \
3661 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3663 if (bfd_link_executable (info
))
3665 if (!add_dynamic_entry (DT_DEBUG
, 0))
3669 if (htab
->elf
.splt
->size
!= 0)
3671 /* DT_PLTGOT is used by prelink even if there is no PLT
3673 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3677 if (htab
->elf
.srelplt
->size
!= 0)
3679 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3680 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3681 || !add_dynamic_entry (DT_JMPREL
, 0))
3687 if (!add_dynamic_entry (DT_REL
, 0)
3688 || !add_dynamic_entry (DT_RELSZ
, 0)
3689 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3692 /* If any dynamic relocs apply to a read-only section,
3693 then we need a DT_TEXTREL entry. */
3694 if ((info
->flags
& DF_TEXTREL
) == 0)
3695 elf_link_hash_traverse (&htab
->elf
,
3696 elf_i386_readonly_dynrelocs
, info
);
3698 if ((info
->flags
& DF_TEXTREL
) != 0)
3700 if (htab
->readonly_dynrelocs_against_ifunc
)
3702 info
->callbacks
->einfo
3703 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3704 bfd_set_error (bfd_error_bad_value
);
3708 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3712 if (get_elf_i386_backend_data (output_bfd
)->os
== is_vxworks
3713 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3716 #undef add_dynamic_entry
3722 elf_i386_always_size_sections (bfd
*output_bfd
,
3723 struct bfd_link_info
*info
)
3725 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3729 struct elf_link_hash_entry
*tlsbase
;
3731 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3732 "_TLS_MODULE_BASE_",
3733 FALSE
, FALSE
, FALSE
);
3735 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3737 struct elf_i386_link_hash_table
*htab
;
3738 struct bfd_link_hash_entry
*bh
= NULL
;
3739 const struct elf_backend_data
*bed
3740 = get_elf_backend_data (output_bfd
);
3742 htab
= elf_i386_hash_table (info
);
3746 if (!(_bfd_generic_link_add_one_symbol
3747 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3748 tls_sec
, 0, NULL
, FALSE
,
3749 bed
->collect
, &bh
)))
3752 htab
->tls_module_base
= bh
;
3754 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3755 tlsbase
->def_regular
= 1;
3756 tlsbase
->other
= STV_HIDDEN
;
3757 tlsbase
->root
.linker_def
= 1;
3758 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
3765 /* Set the correct type for an x86 ELF section. We do this by the
3766 section name, which is a hack, but ought to work. */
3769 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3770 Elf_Internal_Shdr
*hdr
,
3775 name
= bfd_get_section_name (abfd
, sec
);
3777 /* This is an ugly, but unfortunately necessary hack that is
3778 needed when producing EFI binaries on x86. It tells
3779 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3780 containing ELF relocation info. We need this hack in order to
3781 be able to generate ELF binaries that can be translated into
3782 EFI applications (which are essentially COFF objects). Those
3783 files contain a COFF ".reloc" section inside an ELFNN object,
3784 which would normally cause BFD to segfault because it would
3785 attempt to interpret this section as containing relocation
3786 entries for section "oc". With this hack enabled, ".reloc"
3787 will be treated as a normal data section, which will avoid the
3788 segfault. However, you won't be able to create an ELFNN binary
3789 with a section named "oc" that needs relocations, but that's
3790 the kind of ugly side-effects you get when detecting section
3791 types based on their names... In practice, this limitation is
3792 unlikely to bite. */
3793 if (strcmp (name
, ".reloc") == 0)
3794 hdr
->sh_type
= SHT_PROGBITS
;
3799 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3800 executables. Rather than setting it to the beginning of the TLS
3801 section, we have to set it to the end. This function may be called
3802 multiple times, it is idempotent. */
3805 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
3807 struct elf_i386_link_hash_table
*htab
;
3808 struct bfd_link_hash_entry
*base
;
3810 if (!bfd_link_executable (info
))
3813 htab
= elf_i386_hash_table (info
);
3817 base
= htab
->tls_module_base
;
3821 base
->u
.def
.value
= htab
->elf
.tls_size
;
3824 /* Return the base VMA address which should be subtracted from real addresses
3825 when resolving @dtpoff relocation.
3826 This is PT_TLS segment p_vaddr. */
3829 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
3831 /* If tls_sec is NULL, we should have signalled an error already. */
3832 if (elf_hash_table (info
)->tls_sec
== NULL
)
3834 return elf_hash_table (info
)->tls_sec
->vma
;
3837 /* Return the relocation value for @tpoff relocation
3838 if STT_TLS virtual address is ADDRESS. */
3841 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3843 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3844 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3845 bfd_vma static_tls_size
;
3847 /* If tls_sec is NULL, we should have signalled an error already. */
3848 if (htab
->tls_sec
== NULL
)
3851 /* Consider special static TLS alignment requirements. */
3852 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3853 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3856 /* Relocate an i386 ELF section. */
3859 elf_i386_relocate_section (bfd
*output_bfd
,
3860 struct bfd_link_info
*info
,
3862 asection
*input_section
,
3864 Elf_Internal_Rela
*relocs
,
3865 Elf_Internal_Sym
*local_syms
,
3866 asection
**local_sections
)
3868 struct elf_i386_link_hash_table
*htab
;
3869 Elf_Internal_Shdr
*symtab_hdr
;
3870 struct elf_link_hash_entry
**sym_hashes
;
3871 bfd_vma
*local_got_offsets
;
3872 bfd_vma
*local_tlsdesc_gotents
;
3873 Elf_Internal_Rela
*rel
;
3874 Elf_Internal_Rela
*wrel
;
3875 Elf_Internal_Rela
*relend
;
3876 bfd_boolean is_vxworks_tls
;
3877 unsigned plt_entry_size
;
3879 BFD_ASSERT (is_i386_elf (input_bfd
));
3881 /* Skip if check_relocs failed. */
3882 if (input_section
->check_relocs_failed
)
3885 htab
= elf_i386_hash_table (info
);
3888 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3889 sym_hashes
= elf_sym_hashes (input_bfd
);
3890 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3891 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3892 /* We have to handle relocations in vxworks .tls_vars sections
3893 specially, because the dynamic loader is 'weird'. */
3894 is_vxworks_tls
= ((get_elf_i386_backend_data (output_bfd
)->os
3896 && bfd_link_pic (info
)
3897 && !strcmp (input_section
->output_section
->name
,
3900 elf_i386_set_tls_module_base (info
);
3902 plt_entry_size
= htab
->plt
.plt_entry_size
;
3904 rel
= wrel
= relocs
;
3905 relend
= relocs
+ input_section
->reloc_count
;
3906 for (; rel
< relend
; wrel
++, rel
++)
3908 unsigned int r_type
;
3909 reloc_howto_type
*howto
;
3910 unsigned long r_symndx
;
3911 struct elf_link_hash_entry
*h
;
3912 struct elf_i386_link_hash_entry
*eh
;
3913 Elf_Internal_Sym
*sym
;
3915 bfd_vma off
, offplt
, plt_offset
;
3917 bfd_boolean unresolved_reloc
;
3918 bfd_reloc_status_type r
;
3922 asection
*resolved_plt
;
3923 bfd_boolean resolved_to_zero
;
3924 bfd_boolean relative_reloc
;
3926 r_type
= ELF32_R_TYPE (rel
->r_info
);
3927 if (r_type
== R_386_GNU_VTINHERIT
3928 || r_type
== R_386_GNU_VTENTRY
)
3935 if ((indx
= r_type
) >= R_386_standard
3936 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3937 >= R_386_ext
- R_386_standard
)
3938 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3939 >= R_386_ext2
- R_386_ext
))
3942 /* xgettext:c-format */
3943 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3944 input_bfd
, r_type
, input_section
);
3945 bfd_set_error (bfd_error_bad_value
);
3948 howto
= elf_howto_table
+ indx
;
3950 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3954 unresolved_reloc
= FALSE
;
3955 if (r_symndx
< symtab_hdr
->sh_info
)
3957 sym
= local_syms
+ r_symndx
;
3958 sec
= local_sections
[r_symndx
];
3959 relocation
= (sec
->output_section
->vma
3960 + sec
->output_offset
3962 st_size
= sym
->st_size
;
3964 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3965 && ((sec
->flags
& SEC_MERGE
) != 0
3966 || (bfd_link_relocatable (info
)
3967 && sec
->output_offset
!= 0)))
3970 bfd_byte
*where
= contents
+ rel
->r_offset
;
3972 switch (howto
->size
)
3975 addend
= bfd_get_8 (input_bfd
, where
);
3976 if (howto
->pc_relative
)
3978 addend
= (addend
^ 0x80) - 0x80;
3983 addend
= bfd_get_16 (input_bfd
, where
);
3984 if (howto
->pc_relative
)
3986 addend
= (addend
^ 0x8000) - 0x8000;
3991 addend
= bfd_get_32 (input_bfd
, where
);
3992 if (howto
->pc_relative
)
3994 addend
= (addend
^ 0x80000000) - 0x80000000;
4002 if (bfd_link_relocatable (info
))
4003 addend
+= sec
->output_offset
;
4006 asection
*msec
= sec
;
4007 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
4009 addend
-= relocation
;
4010 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4013 switch (howto
->size
)
4016 /* FIXME: overflow checks. */
4017 if (howto
->pc_relative
)
4019 bfd_put_8 (input_bfd
, addend
, where
);
4022 if (howto
->pc_relative
)
4024 bfd_put_16 (input_bfd
, addend
, where
);
4027 if (howto
->pc_relative
)
4029 bfd_put_32 (input_bfd
, addend
, where
);
4033 else if (!bfd_link_relocatable (info
)
4034 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4036 /* Relocate against local STT_GNU_IFUNC symbol. */
4037 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
4042 /* Set STT_GNU_IFUNC symbol value. */
4043 h
->root
.u
.def
.value
= sym
->st_value
;
4044 h
->root
.u
.def
.section
= sec
;
4049 bfd_boolean warned ATTRIBUTE_UNUSED
;
4050 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4052 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4053 r_symndx
, symtab_hdr
, sym_hashes
,
4055 unresolved_reloc
, warned
, ignored
);
4059 if (sec
!= NULL
&& discarded_section (sec
))
4061 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4062 contents
+ rel
->r_offset
);
4063 wrel
->r_offset
= rel
->r_offset
;
4067 /* For ld -r, remove relocations in debug sections against
4068 sections defined in discarded sections. Not done for
4069 eh_frame editing code expects to be present. */
4070 if (bfd_link_relocatable (info
)
4071 && (input_section
->flags
& SEC_DEBUGGING
))
4077 if (bfd_link_relocatable (info
))
4084 eh
= (struct elf_i386_link_hash_entry
*) h
;
4086 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4087 it here if it is defined in a non-shared object. */
4089 && h
->type
== STT_GNU_IFUNC
4092 asection
*gotplt
, *base_got
;
4096 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4098 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4099 sections because such sections are not SEC_ALLOC and
4100 thus ld.so will not process them. */
4101 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4106 /* STT_GNU_IFUNC symbol must go through PLT. */
4107 if (htab
->elf
.splt
!= NULL
)
4109 if (htab
->plt_second
!= NULL
)
4111 resolved_plt
= htab
->plt_second
;
4112 plt_offset
= eh
->plt_second
.offset
;
4116 resolved_plt
= htab
->elf
.splt
;
4117 plt_offset
= h
->plt
.offset
;
4119 gotplt
= htab
->elf
.sgotplt
;
4123 resolved_plt
= htab
->elf
.iplt
;
4124 plt_offset
= h
->plt
.offset
;
4125 gotplt
= htab
->elf
.igotplt
;
4135 base_got
= htab
->elf
.sgot
;
4136 off
= h
->got
.offset
;
4138 if (base_got
== NULL
)
4141 if (off
== (bfd_vma
) -1)
4143 /* We can't use h->got.offset here to save state, or
4144 even just remember the offset, as finish_dynamic_symbol
4145 would use that as offset into .got. */
4147 if (h
->plt
.offset
== (bfd_vma
) -1)
4150 if (htab
->elf
.splt
!= NULL
)
4152 plt_index
= (h
->plt
.offset
/ plt_entry_size
4153 - htab
->plt
.has_plt0
);
4154 off
= (plt_index
+ 3) * 4;
4155 base_got
= htab
->elf
.sgotplt
;
4159 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4160 off
= plt_index
* 4;
4161 base_got
= htab
->elf
.igotplt
;
4164 if (h
->dynindx
== -1
4168 /* This references the local defitionion. We must
4169 initialize this entry in the global offset table.
4170 Since the offset must always be a multiple of 8,
4171 we use the least significant bit to record
4172 whether we have initialized it already.
4174 When doing a dynamic link, we create a .rela.got
4175 relocation entry to initialize the value. This
4176 is done in the finish_dynamic_symbol routine. */
4181 bfd_put_32 (output_bfd
, relocation
,
4182 base_got
->contents
+ off
);
4190 relocation
= (base_got
->output_section
->vma
4191 + base_got
->output_offset
+ off
4192 - gotplt
->output_section
->vma
4193 - gotplt
->output_offset
);
4195 if (rel
->r_offset
> 1
4196 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4197 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4199 if (bfd_link_pic (info
))
4200 goto disallow_got32
;
4202 /* Add the GOT base if there is no base register. */
4203 relocation
+= (gotplt
->output_section
->vma
4204 + gotplt
->output_offset
);
4206 else if (htab
->elf
.splt
== NULL
)
4208 /* Adjust for static executables. */
4209 relocation
+= gotplt
->output_offset
;
4215 if (h
->plt
.offset
== (bfd_vma
) -1)
4217 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4218 if (r_type
== R_386_32
4219 && (input_section
->flags
& SEC_CODE
) == 0)
4220 goto do_ifunc_pointer
;
4221 goto bad_ifunc_reloc
;
4224 relocation
= (resolved_plt
->output_section
->vma
4225 + resolved_plt
->output_offset
+ plt_offset
);
4231 if (h
->root
.root
.string
)
4232 name
= h
->root
.root
.string
;
4234 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4237 /* xgettext:c-format */
4238 (_("%B: relocation %s against STT_GNU_IFUNC "
4239 "symbol `%s' isn't supported"), input_bfd
,
4241 bfd_set_error (bfd_error_bad_value
);
4245 /* Generate dynamic relcoation only when there is a
4246 non-GOT reference in a shared object. */
4247 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4248 || h
->plt
.offset
== (bfd_vma
) -1)
4250 Elf_Internal_Rela outrel
;
4255 /* Need a dynamic relocation to get the real function
4257 offset
= _bfd_elf_section_offset (output_bfd
,
4261 if (offset
== (bfd_vma
) -1
4262 || offset
== (bfd_vma
) -2)
4265 outrel
.r_offset
= (input_section
->output_section
->vma
4266 + input_section
->output_offset
4269 if (h
->dynindx
== -1
4271 || bfd_link_executable (info
))
4273 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4274 h
->root
.root
.string
,
4275 h
->root
.u
.def
.section
->owner
);
4277 /* This symbol is resolved locally. */
4278 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4279 bfd_put_32 (output_bfd
,
4280 (h
->root
.u
.def
.value
4281 + h
->root
.u
.def
.section
->output_section
->vma
4282 + h
->root
.u
.def
.section
->output_offset
),
4286 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4288 /* Dynamic relocations are stored in
4289 1. .rel.ifunc section in PIC object.
4290 2. .rel.got section in dynamic executable.
4291 3. .rel.iplt section in static executable. */
4292 if (bfd_link_pic (info
))
4293 sreloc
= htab
->elf
.irelifunc
;
4294 else if (htab
->elf
.splt
!= NULL
)
4295 sreloc
= htab
->elf
.srelgot
;
4297 sreloc
= htab
->elf
.irelplt
;
4298 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4300 /* If this reloc is against an external symbol, we
4301 do not want to fiddle with the addend. Otherwise,
4302 we need to include the symbol value so that it
4303 becomes an addend for the dynamic reloc. For an
4304 internal symbol, we have updated addend. */
4313 relocation
-= (gotplt
->output_section
->vma
4314 + gotplt
->output_offset
);
4319 resolved_to_zero
= (eh
!= NULL
4320 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4327 /* Avoid optimizing _DYNAMIC since ld.so may use its
4328 link-time address. */
4329 if (h
== htab
->elf
.hdynamic
)
4332 if (bfd_link_pic (info
))
4334 /* It is OK to convert mov to lea and convert indirect
4335 branch to direct branch. It is OK to convert adc,
4336 add, and, cmp, or, sbb, sub, test, xor only when PIC
4338 unsigned int opcode
, addend
;
4339 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4342 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4343 if (opcode
!= 0x8b && opcode
!= 0xff)
4347 /* Resolve "mov GOT[(%reg)], %reg",
4348 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
4349 and "binop foo@GOT[(%reg)], %reg". */
4351 || (h
->plt
.offset
== (bfd_vma
) -1
4352 && h
->got
.offset
== (bfd_vma
) -1)
4353 || htab
->elf
.sgotplt
== NULL
)
4356 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
4357 + htab
->elf
.sgotplt
->output_offset
);
4359 /* It is relative to .got.plt section. */
4360 if (h
->got
.offset
!= (bfd_vma
) -1)
4361 /* Use GOT entry. Mask off the least significant bit in
4362 GOT offset which may be set by R_386_GOT32 processing
4364 relocation
= (htab
->elf
.sgot
->output_section
->vma
4365 + htab
->elf
.sgot
->output_offset
4366 + (h
->got
.offset
& ~1) - offplt
);
4368 /* Use GOTPLT entry. */
4369 relocation
= (h
->plt
.offset
/ plt_entry_size
4370 - htab
->plt
.has_plt0
+ 3) * 4;
4372 if (!bfd_link_pic (info
))
4374 /* If not PIC, add the .got.plt section address for
4375 baseless addressing. */
4377 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4378 if ((modrm
& 0xc7) == 0x5)
4379 relocation
+= offplt
;
4382 unresolved_reloc
= FALSE
;
4387 /* Relocation is to the entry for this symbol in the global
4389 if (htab
->elf
.sgot
== NULL
)
4392 relative_reloc
= FALSE
;
4397 off
= h
->got
.offset
;
4398 dyn
= htab
->elf
.dynamic_sections_created
;
4399 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4400 bfd_link_pic (info
),
4402 || (bfd_link_pic (info
)
4403 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4404 || (ELF_ST_VISIBILITY (h
->other
)
4405 && h
->root
.type
== bfd_link_hash_undefweak
))
4407 /* This is actually a static link, or it is a
4408 -Bsymbolic link and the symbol is defined
4409 locally, or the symbol was forced to be local
4410 because of a version file. We must initialize
4411 this entry in the global offset table. Since the
4412 offset must always be a multiple of 4, we use the
4413 least significant bit to record whether we have
4414 initialized it already.
4416 When doing a dynamic link, we create a .rel.got
4417 relocation entry to initialize the value. This
4418 is done in the finish_dynamic_symbol routine. */
4423 bfd_put_32 (output_bfd
, relocation
,
4424 htab
->elf
.sgot
->contents
+ off
);
4427 if (h
->dynindx
== -1
4429 && h
->root
.type
!= bfd_link_hash_undefweak
4430 && bfd_link_pic (info
))
4432 /* PR ld/21402: If this symbol isn't dynamic
4433 in PIC, generate R_386_RELATIVE here. */
4434 eh
->no_finish_dynamic_symbol
= 1;
4435 relative_reloc
= TRUE
;
4440 unresolved_reloc
= FALSE
;
4444 if (local_got_offsets
== NULL
)
4447 off
= local_got_offsets
[r_symndx
];
4449 /* The offset must always be a multiple of 4. We use
4450 the least significant bit to record whether we have
4451 already generated the necessary reloc. */
4456 bfd_put_32 (output_bfd
, relocation
,
4457 htab
->elf
.sgot
->contents
+ off
);
4458 local_got_offsets
[r_symndx
] |= 1;
4460 if (bfd_link_pic (info
))
4461 relative_reloc
= TRUE
;
4468 Elf_Internal_Rela outrel
;
4470 s
= htab
->elf
.srelgot
;
4474 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4475 + htab
->elf
.sgot
->output_offset
4477 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4478 elf_append_rel (output_bfd
, s
, &outrel
);
4481 if (off
>= (bfd_vma
) -2)
4484 relocation
= (htab
->elf
.sgot
->output_section
->vma
4485 + htab
->elf
.sgot
->output_offset
+ off
);
4486 if (rel
->r_offset
> 1
4487 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4488 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4490 if (bfd_link_pic (info
))
4492 /* For PIC, disallow R_386_GOT32 without a base
4493 register, except for "lea foo@GOT, %reg", since
4494 we don't know what the GOT base is. */
4498 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
4499 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4502 name
= h
->root
.root
.string
;
4505 /* xgettext:c-format */
4506 (_("%B: direct GOT relocation %s against `%s'"
4507 " without base register can not be used"
4508 " when making a shared object"),
4509 input_bfd
, howto
->name
, name
);
4510 bfd_set_error (bfd_error_bad_value
);
4516 /* Subtract the .got.plt section address only with a base
4518 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
4519 + htab
->elf
.sgotplt
->output_offset
);
4525 /* Relocation is relative to the start of the global offset
4528 /* Check to make sure it isn't a protected function or data
4529 symbol for shared library since it may not be local when
4530 used as function address or with copy relocation. We also
4531 need to make sure that a symbol is referenced locally. */
4532 if (!bfd_link_executable (info
) && h
)
4534 if (!h
->def_regular
)
4538 switch (ELF_ST_VISIBILITY (h
->other
))
4541 v
= _("hidden symbol");
4544 v
= _("internal symbol");
4547 v
= _("protected symbol");
4555 /* xgettext:c-format */
4556 (_("%B: relocation R_386_GOTOFF against undefined %s"
4557 " `%s' can not be used when making a shared object"),
4558 input_bfd
, v
, h
->root
.root
.string
);
4559 bfd_set_error (bfd_error_bad_value
);
4562 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
4563 && (h
->type
== STT_FUNC
4564 || h
->type
== STT_OBJECT
)
4565 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4568 /* xgettext:c-format */
4569 (_("%B: relocation R_386_GOTOFF against protected %s"
4570 " `%s' can not be used when making a shared object"),
4572 h
->type
== STT_FUNC
? "function" : "data",
4573 h
->root
.root
.string
);
4574 bfd_set_error (bfd_error_bad_value
);
4579 /* Note that sgot is not involved in this
4580 calculation. We always want the start of .got.plt. If we
4581 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4582 permitted by the ABI, we might have to change this
4584 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4585 + htab
->elf
.sgotplt
->output_offset
;
4589 /* Use global offset table as symbol value. */
4590 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4591 + htab
->elf
.sgotplt
->output_offset
;
4592 unresolved_reloc
= FALSE
;
4596 /* Relocation is to the entry for this symbol in the
4597 procedure linkage table. */
4599 /* Resolve a PLT32 reloc against a local symbol directly,
4600 without using the procedure linkage table. */
4604 if ((h
->plt
.offset
== (bfd_vma
) -1
4605 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4606 || htab
->elf
.splt
== NULL
)
4608 /* We didn't make a PLT entry for this symbol. This
4609 happens when statically linking PIC code, or when
4610 using -Bsymbolic. */
4614 if (h
->plt
.offset
!= (bfd_vma
) -1)
4616 if (htab
->plt_second
!= NULL
)
4618 resolved_plt
= htab
->plt_second
;
4619 plt_offset
= eh
->plt_second
.offset
;
4623 resolved_plt
= htab
->elf
.splt
;
4624 plt_offset
= h
->plt
.offset
;
4629 resolved_plt
= htab
->plt_got
;
4630 plt_offset
= eh
->plt_got
.offset
;
4633 relocation
= (resolved_plt
->output_section
->vma
4634 + resolved_plt
->output_offset
4636 unresolved_reloc
= FALSE
;
4640 /* Set to symbol size. */
4641 relocation
= st_size
;
4646 if ((input_section
->flags
& SEC_ALLOC
) == 0
4650 /* Copy dynamic function pointer relocations. Don't generate
4651 dynamic relocations against resolved undefined weak symbols
4652 in PIE, except for R_386_PC32. */
4653 if ((bfd_link_pic (info
)
4655 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4656 && (!resolved_to_zero
4657 || r_type
== R_386_PC32
))
4658 || h
->root
.type
!= bfd_link_hash_undefweak
))
4659 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
4660 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4661 || (ELIMINATE_COPY_RELOCS
4662 && !bfd_link_pic (info
)
4666 || eh
->func_pointer_refcount
> 0
4667 || (h
->root
.type
== bfd_link_hash_undefweak
4668 && !resolved_to_zero
))
4669 && ((h
->def_dynamic
&& !h
->def_regular
)
4670 /* Undefined weak symbol is bound locally when
4672 || h
->root
.type
== bfd_link_hash_undefweak
)))
4674 Elf_Internal_Rela outrel
;
4675 bfd_boolean skip
, relocate
;
4678 /* When generating a shared object, these relocations
4679 are copied into the output file to be resolved at run
4686 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4688 if (outrel
.r_offset
== (bfd_vma
) -1)
4690 else if (outrel
.r_offset
== (bfd_vma
) -2)
4691 skip
= TRUE
, relocate
= TRUE
;
4692 outrel
.r_offset
+= (input_section
->output_section
->vma
4693 + input_section
->output_offset
);
4696 memset (&outrel
, 0, sizeof outrel
);
4699 && (r_type
== R_386_PC32
4700 || !(bfd_link_executable (info
)
4701 || SYMBOLIC_BIND (info
, h
))
4702 || !h
->def_regular
))
4703 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4706 /* This symbol is local, or marked to become local. */
4708 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4711 sreloc
= elf_section_data (input_section
)->sreloc
;
4713 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4715 r
= bfd_reloc_notsupported
;
4716 goto check_relocation_error
;
4719 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4721 /* If this reloc is against an external symbol, we do
4722 not want to fiddle with the addend. Otherwise, we
4723 need to include the symbol value so that it becomes
4724 an addend for the dynamic reloc. */
4731 if (!bfd_link_executable (info
))
4733 Elf_Internal_Rela outrel
;
4736 outrel
.r_offset
= rel
->r_offset
4737 + input_section
->output_section
->vma
4738 + input_section
->output_offset
;
4739 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4740 sreloc
= elf_section_data (input_section
)->sreloc
;
4743 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4748 case R_386_TLS_GOTDESC
:
4749 case R_386_TLS_DESC_CALL
:
4750 case R_386_TLS_IE_32
:
4751 case R_386_TLS_GOTIE
:
4752 tls_type
= GOT_UNKNOWN
;
4753 if (h
== NULL
&& local_got_offsets
)
4754 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
4756 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
4757 if (tls_type
== GOT_TLS_IE
)
4758 tls_type
= GOT_TLS_IE_NEG
;
4760 if (! elf_i386_tls_transition (info
, input_bfd
,
4761 input_section
, contents
,
4762 symtab_hdr
, sym_hashes
,
4763 &r_type
, tls_type
, rel
,
4764 relend
, h
, r_symndx
, TRUE
))
4767 if (r_type
== R_386_TLS_LE_32
)
4769 BFD_ASSERT (! unresolved_reloc
);
4770 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4775 /* GD->LE transition. */
4776 type
= *(contents
+ rel
->r_offset
- 2);
4780 leal foo@tlsgd(,%ebx,1), %eax
4781 call ___tls_get_addr@PLT
4784 subl $foo@tpoff, %eax
4785 (6 byte form of subl). */
4786 roff
= rel
->r_offset
+ 5;
4791 leal foo@tlsgd(%ebx), %eax
4792 call ___tls_get_addr@PLT
4795 leal foo@tlsgd(%reg), %eax
4796 call *___tls_get_addr@GOT(%reg)
4797 which may be converted to
4798 addr32 call ___tls_get_addr
4800 movl %gs:0, %eax; subl $foo@tpoff, %eax
4801 (6 byte form of subl). */
4802 roff
= rel
->r_offset
+ 6;
4804 memcpy (contents
+ roff
- 8,
4805 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4806 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4808 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4813 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4815 /* GDesc -> LE transition.
4816 It's originally something like:
4817 leal x@tlsdesc(%ebx), %eax
4821 Registers other than %eax may be set up here. */
4826 roff
= rel
->r_offset
;
4827 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4829 /* Now modify the instruction as appropriate. */
4830 /* aoliva FIXME: remove the above and xor the byte
4832 bfd_put_8 (output_bfd
, val
^ 0x86,
4833 contents
+ roff
- 1);
4834 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4838 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4840 /* GDesc -> LE transition.
4848 roff
= rel
->r_offset
;
4849 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4850 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4853 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4857 /* IE->LE transition:
4858 Originally it can be one of:
4866 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4869 /* movl foo, %eax. */
4870 bfd_put_8 (output_bfd
, 0xb8,
4871 contents
+ rel
->r_offset
- 1);
4877 type
= bfd_get_8 (input_bfd
,
4878 contents
+ rel
->r_offset
- 2);
4883 bfd_put_8 (output_bfd
, 0xc7,
4884 contents
+ rel
->r_offset
- 2);
4885 bfd_put_8 (output_bfd
,
4886 0xc0 | ((val
>> 3) & 7),
4887 contents
+ rel
->r_offset
- 1);
4891 bfd_put_8 (output_bfd
, 0x81,
4892 contents
+ rel
->r_offset
- 2);
4893 bfd_put_8 (output_bfd
,
4894 0xc0 | ((val
>> 3) & 7),
4895 contents
+ rel
->r_offset
- 1);
4902 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4903 contents
+ rel
->r_offset
);
4908 unsigned int val
, type
;
4910 /* {IE_32,GOTIE}->LE transition:
4911 Originally it can be one of:
4912 subl foo(%reg1), %reg2
4913 movl foo(%reg1), %reg2
4914 addl foo(%reg1), %reg2
4917 movl $foo, %reg2 (6 byte form)
4918 addl $foo, %reg2. */
4919 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4920 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4924 bfd_put_8 (output_bfd
, 0xc7,
4925 contents
+ rel
->r_offset
- 2);
4926 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4927 contents
+ rel
->r_offset
- 1);
4929 else if (type
== 0x2b)
4932 bfd_put_8 (output_bfd
, 0x81,
4933 contents
+ rel
->r_offset
- 2);
4934 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4935 contents
+ rel
->r_offset
- 1);
4937 else if (type
== 0x03)
4940 bfd_put_8 (output_bfd
, 0x81,
4941 contents
+ rel
->r_offset
- 2);
4942 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4943 contents
+ rel
->r_offset
- 1);
4947 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4948 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4949 contents
+ rel
->r_offset
);
4951 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4952 contents
+ rel
->r_offset
);
4957 if (htab
->elf
.sgot
== NULL
)
4962 off
= h
->got
.offset
;
4963 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
4967 if (local_got_offsets
== NULL
)
4970 off
= local_got_offsets
[r_symndx
];
4971 offplt
= local_tlsdesc_gotents
[r_symndx
];
4978 Elf_Internal_Rela outrel
;
4982 if (htab
->elf
.srelgot
== NULL
)
4985 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4987 if (GOT_TLS_GDESC_P (tls_type
))
4990 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4991 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4992 <= htab
->elf
.sgotplt
->size
);
4993 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4994 + htab
->elf
.sgotplt
->output_offset
4996 + htab
->sgotplt_jump_table_size
);
4997 sreloc
= htab
->elf
.srelplt
;
4998 loc
= sreloc
->contents
;
4999 loc
+= (htab
->next_tls_desc_index
++
5000 * sizeof (Elf32_External_Rel
));
5001 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
5002 <= sreloc
->contents
+ sreloc
->size
);
5003 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
5006 BFD_ASSERT (! unresolved_reloc
);
5007 bfd_put_32 (output_bfd
,
5008 relocation
- elf_i386_dtpoff_base (info
),
5009 htab
->elf
.sgotplt
->contents
+ offplt
5010 + htab
->sgotplt_jump_table_size
+ 4);
5014 bfd_put_32 (output_bfd
, 0,
5015 htab
->elf
.sgotplt
->contents
+ offplt
5016 + htab
->sgotplt_jump_table_size
+ 4);
5020 sreloc
= htab
->elf
.srelgot
;
5022 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5023 + htab
->elf
.sgot
->output_offset
+ off
);
5025 if (GOT_TLS_GD_P (tls_type
))
5026 dr_type
= R_386_TLS_DTPMOD32
;
5027 else if (GOT_TLS_GDESC_P (tls_type
))
5029 else if (tls_type
== GOT_TLS_IE_POS
)
5030 dr_type
= R_386_TLS_TPOFF
;
5032 dr_type
= R_386_TLS_TPOFF32
;
5034 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
5035 bfd_put_32 (output_bfd
,
5036 relocation
- elf_i386_dtpoff_base (info
),
5037 htab
->elf
.sgot
->contents
+ off
);
5038 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
5039 bfd_put_32 (output_bfd
,
5040 elf_i386_dtpoff_base (info
) - relocation
,
5041 htab
->elf
.sgot
->contents
+ off
);
5042 else if (dr_type
!= R_386_TLS_DESC
)
5043 bfd_put_32 (output_bfd
, 0,
5044 htab
->elf
.sgot
->contents
+ off
);
5045 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5047 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5049 if (GOT_TLS_GD_P (tls_type
))
5053 BFD_ASSERT (! unresolved_reloc
);
5054 bfd_put_32 (output_bfd
,
5055 relocation
- elf_i386_dtpoff_base (info
),
5056 htab
->elf
.sgot
->contents
+ off
+ 4);
5060 bfd_put_32 (output_bfd
, 0,
5061 htab
->elf
.sgot
->contents
+ off
+ 4);
5062 outrel
.r_info
= ELF32_R_INFO (indx
,
5063 R_386_TLS_DTPOFF32
);
5064 outrel
.r_offset
+= 4;
5065 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5068 else if (tls_type
== GOT_TLS_IE_BOTH
)
5070 bfd_put_32 (output_bfd
,
5072 ? relocation
- elf_i386_dtpoff_base (info
)
5074 htab
->elf
.sgot
->contents
+ off
+ 4);
5075 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5076 outrel
.r_offset
+= 4;
5077 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5084 local_got_offsets
[r_symndx
] |= 1;
5087 if (off
>= (bfd_vma
) -2
5088 && ! GOT_TLS_GDESC_P (tls_type
))
5090 if (r_type
== R_386_TLS_GOTDESC
5091 || r_type
== R_386_TLS_DESC_CALL
)
5093 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
5094 unresolved_reloc
= FALSE
;
5096 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5098 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
5099 + htab
->elf
.sgotplt
->output_offset
;
5100 relocation
= htab
->elf
.sgot
->output_section
->vma
5101 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
5102 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
5103 && tls_type
== GOT_TLS_IE_BOTH
)
5105 if (r_type
== R_386_TLS_IE
)
5106 relocation
+= g_o_t
;
5107 unresolved_reloc
= FALSE
;
5109 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
5111 unsigned int val
, type
;
5114 /* GD->IE transition. */
5115 type
= *(contents
+ rel
->r_offset
- 2);
5116 val
= *(contents
+ rel
->r_offset
- 1);
5120 leal foo@tlsgd(,%ebx,1), %eax
5121 call ___tls_get_addr@PLT
5124 subl $foo@gottpoff(%ebx), %eax. */
5126 roff
= rel
->r_offset
- 3;
5131 leal foo@tlsgd(%ebx), %eax
5132 call ___tls_get_addr@PLT
5135 leal foo@tlsgd(%reg), %eax
5136 call *___tls_get_addr@GOT(%reg)
5137 which may be converted to
5138 addr32 call ___tls_get_addr
5141 subl $foo@gottpoff(%reg), %eax. */
5142 roff
= rel
->r_offset
- 2;
5144 memcpy (contents
+ roff
,
5145 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
5146 contents
[roff
+ 7] = 0x80 | (val
& 7);
5147 /* If foo is used only with foo@gotntpoff(%reg) and
5148 foo@indntpoff, but not with foo@gottpoff(%reg), change
5149 subl $foo@gottpoff(%reg), %eax
5151 addl $foo@gotntpoff(%reg), %eax. */
5152 if (tls_type
== GOT_TLS_IE_POS
)
5153 contents
[roff
+ 6] = 0x03;
5154 bfd_put_32 (output_bfd
,
5155 htab
->elf
.sgot
->output_section
->vma
5156 + htab
->elf
.sgot
->output_offset
+ off
5157 - htab
->elf
.sgotplt
->output_section
->vma
5158 - htab
->elf
.sgotplt
->output_offset
,
5159 contents
+ roff
+ 8);
5160 /* Skip R_386_PLT32 and R_386_GOT32X. */
5165 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
5167 /* GDesc -> IE transition.
5168 It's originally something like:
5169 leal x@tlsdesc(%ebx), %eax
5172 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
5174 movl x@gottpoff(%ebx), %eax # before negl %eax
5176 Registers other than %eax may be set up here. */
5180 /* First, make sure it's a leal adding ebx to a 32-bit
5181 offset into any register, although it's probably
5182 almost always going to be eax. */
5183 roff
= rel
->r_offset
;
5185 /* Now modify the instruction as appropriate. */
5186 /* To turn a leal into a movl in the form we use it, it
5187 suffices to change the first byte from 0x8d to 0x8b.
5188 aoliva FIXME: should we decide to keep the leal, all
5189 we have to do is remove the statement below, and
5190 adjust the relaxation of R_386_TLS_DESC_CALL. */
5191 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5193 if (tls_type
== GOT_TLS_IE_BOTH
)
5196 bfd_put_32 (output_bfd
,
5197 htab
->elf
.sgot
->output_section
->vma
5198 + htab
->elf
.sgot
->output_offset
+ off
5199 - htab
->elf
.sgotplt
->output_section
->vma
5200 - htab
->elf
.sgotplt
->output_offset
,
5204 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
5206 /* GDesc -> IE transition.
5214 depending on how we transformed the TLS_GOTDESC above.
5219 roff
= rel
->r_offset
;
5221 /* Now modify the instruction as appropriate. */
5222 if (tls_type
!= GOT_TLS_IE_NEG
)
5225 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5226 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5231 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
5232 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
5242 if (! elf_i386_tls_transition (info
, input_bfd
,
5243 input_section
, contents
,
5244 symtab_hdr
, sym_hashes
,
5245 &r_type
, GOT_UNKNOWN
, rel
,
5246 relend
, h
, r_symndx
, TRUE
))
5249 if (r_type
!= R_386_TLS_LDM
)
5251 /* LD->LE transition. Change
5252 leal foo@tlsldm(%ebx) %eax
5253 call ___tls_get_addr@PLT
5257 leal 0(%esi,1), %esi
5259 leal foo@tlsldm(%reg) %eax
5260 call *___tls_get_addr@GOT(%reg)
5261 which may be converted to
5262 addr32 call ___tls_get_addr
5265 leal 0(%esi), %esi */
5266 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
5267 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
5268 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
5269 memcpy (contents
+ rel
->r_offset
- 2,
5270 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
5272 memcpy (contents
+ rel
->r_offset
- 2,
5273 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
5274 /* Skip R_386_PC32/R_386_PLT32. */
5280 if (htab
->elf
.sgot
== NULL
)
5283 off
= htab
->tls_ldm_got
.offset
;
5288 Elf_Internal_Rela outrel
;
5290 if (htab
->elf
.srelgot
== NULL
)
5293 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5294 + htab
->elf
.sgot
->output_offset
+ off
);
5296 bfd_put_32 (output_bfd
, 0,
5297 htab
->elf
.sgot
->contents
+ off
);
5298 bfd_put_32 (output_bfd
, 0,
5299 htab
->elf
.sgot
->contents
+ off
+ 4);
5300 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
5301 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
5302 htab
->tls_ldm_got
.offset
|= 1;
5304 relocation
= htab
->elf
.sgot
->output_section
->vma
5305 + htab
->elf
.sgot
->output_offset
+ off
5306 - htab
->elf
.sgotplt
->output_section
->vma
5307 - htab
->elf
.sgotplt
->output_offset
;
5308 unresolved_reloc
= FALSE
;
5311 case R_386_TLS_LDO_32
:
5312 if (!bfd_link_executable (info
)
5313 || (input_section
->flags
& SEC_CODE
) == 0)
5314 relocation
-= elf_i386_dtpoff_base (info
);
5316 /* When converting LDO to LE, we must negate. */
5317 relocation
= -elf_i386_tpoff (info
, relocation
);
5320 case R_386_TLS_LE_32
:
5322 if (!bfd_link_executable (info
))
5324 Elf_Internal_Rela outrel
;
5327 outrel
.r_offset
= rel
->r_offset
5328 + input_section
->output_section
->vma
5329 + input_section
->output_offset
;
5330 if (h
!= NULL
&& h
->dynindx
!= -1)
5334 if (r_type
== R_386_TLS_LE_32
)
5335 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
5337 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5338 sreloc
= elf_section_data (input_section
)->sreloc
;
5341 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5344 else if (r_type
== R_386_TLS_LE_32
)
5345 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
5347 relocation
-= elf_i386_dtpoff_base (info
);
5349 else if (r_type
== R_386_TLS_LE_32
)
5350 relocation
= elf_i386_tpoff (info
, relocation
);
5352 relocation
= -elf_i386_tpoff (info
, relocation
);
5359 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5360 because such sections are not SEC_ALLOC and thus ld.so will
5361 not process them. */
5362 if (unresolved_reloc
5363 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5365 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5366 rel
->r_offset
) != (bfd_vma
) -1)
5369 /* xgettext:c-format */
5370 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5373 (long) rel
->r_offset
,
5375 h
->root
.root
.string
);
5380 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5381 contents
, rel
->r_offset
,
5384 check_relocation_error
:
5385 if (r
!= bfd_reloc_ok
)
5390 name
= h
->root
.root
.string
;
5393 name
= bfd_elf_string_from_elf_section (input_bfd
,
5394 symtab_hdr
->sh_link
,
5399 name
= bfd_section_name (input_bfd
, sec
);
5402 if (r
== bfd_reloc_overflow
)
5403 (*info
->callbacks
->reloc_overflow
)
5404 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5405 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5409 /* xgettext:c-format */
5410 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5411 input_bfd
, input_section
,
5412 (long) rel
->r_offset
, name
, (int) r
);
5423 Elf_Internal_Shdr
*rel_hdr
;
5424 size_t deleted
= rel
- wrel
;
5426 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5427 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5428 if (rel_hdr
->sh_size
== 0)
5430 /* It is too late to remove an empty reloc section. Leave
5432 ??? What is wrong with an empty section??? */
5433 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5436 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5437 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5438 input_section
->reloc_count
-= deleted
;
5444 /* Finish up dynamic symbol handling. We set the contents of various
5445 dynamic sections here. */
5448 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
5449 struct bfd_link_info
*info
,
5450 struct elf_link_hash_entry
*h
,
5451 Elf_Internal_Sym
*sym
)
5453 struct elf_i386_link_hash_table
*htab
;
5454 unsigned plt_entry_size
;
5455 const struct elf_i386_backend_data
*abed
;
5456 struct elf_i386_link_hash_entry
*eh
;
5457 bfd_boolean local_undefweak
;
5458 bfd_boolean use_plt_second
;
5460 htab
= elf_i386_hash_table (info
);
5464 abed
= get_elf_i386_backend_data (output_bfd
);
5465 plt_entry_size
= htab
->plt
.plt_entry_size
;
5467 /* Use the second PLT section only if there is .plt section. */
5468 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
5470 eh
= (struct elf_i386_link_hash_entry
*) h
;
5471 if (eh
->no_finish_dynamic_symbol
)
5474 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5475 resolved undefined weak symbols in executable so that their
5476 references have value 0 at run-time. */
5477 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5481 if (h
->plt
.offset
!= (bfd_vma
) -1)
5483 bfd_vma plt_index
, plt_offset
;
5485 Elf_Internal_Rela rel
;
5487 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
5489 /* When building a static executable, use .iplt, .igot.plt and
5490 .rel.iplt sections for STT_GNU_IFUNC symbols. */
5491 if (htab
->elf
.splt
!= NULL
)
5493 plt
= htab
->elf
.splt
;
5494 gotplt
= htab
->elf
.sgotplt
;
5495 relplt
= htab
->elf
.srelplt
;
5499 plt
= htab
->elf
.iplt
;
5500 gotplt
= htab
->elf
.igotplt
;
5501 relplt
= htab
->elf
.irelplt
;
5504 /* This symbol has an entry in the procedure linkage table. Set
5507 if ((h
->dynindx
== -1
5509 && !((h
->forced_local
|| bfd_link_executable (info
))
5511 && h
->type
== STT_GNU_IFUNC
))
5517 /* Get the index in the procedure linkage table which
5518 corresponds to this symbol. This is the index of this symbol
5519 in all the symbols for which we are making plt entries. The
5520 first entry in the procedure linkage table is reserved.
5522 Get the offset into the .got table of the entry that
5523 corresponds to this function. Each .got entry is 4 bytes.
5524 The first three are reserved.
5526 For static executables, we don't reserve anything. */
5528 if (plt
== htab
->elf
.splt
)
5530 got_offset
= (h
->plt
.offset
/ plt_entry_size
5531 - htab
->plt
.has_plt0
);
5532 got_offset
= (got_offset
+ 3) * 4;
5536 got_offset
= h
->plt
.offset
/ plt_entry_size
;
5537 got_offset
= got_offset
* 4;
5540 /* Fill in the entry in the procedure linkage table and update
5542 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
5547 const bfd_byte
*plt_entry
;
5548 if (bfd_link_pic (info
))
5549 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5551 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5552 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
5553 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
5555 resolved_plt
= htab
->plt_second
;
5556 plt_offset
= eh
->plt_second
.offset
;
5561 plt_offset
= h
->plt
.offset
;
5564 if (! bfd_link_pic (info
))
5566 bfd_put_32 (output_bfd
,
5567 (gotplt
->output_section
->vma
5568 + gotplt
->output_offset
5570 resolved_plt
->contents
+ plt_offset
5571 + htab
->plt
.plt_got_offset
);
5573 if (abed
->os
== is_vxworks
)
5575 int s
, k
, reloc_index
;
5577 /* Create the R_386_32 relocation referencing the GOT
5578 for this PLT entry. */
5580 /* S: Current slot number (zero-based). */
5581 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
5582 / htab
->plt
.plt_entry_size
);
5583 /* K: Number of relocations for PLTResolve. */
5584 if (bfd_link_pic (info
))
5585 k
= PLTRESOLVE_RELOCS_SHLIB
;
5587 k
= PLTRESOLVE_RELOCS
;
5588 /* Skip the PLTresolve relocations, and the relocations for
5589 the other PLT slots. */
5590 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
5591 loc
= (htab
->srelplt2
->contents
+ reloc_index
5592 * sizeof (Elf32_External_Rel
));
5594 rel
.r_offset
= (plt
->output_section
->vma
5595 + plt
->output_offset
5596 + h
->plt
.offset
+ 2),
5597 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5598 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5600 /* Create the R_386_32 relocation referencing the beginning of
5601 the PLT for this GOT entry. */
5602 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5603 + htab
->elf
.sgotplt
->output_offset
5605 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5606 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5607 loc
+ sizeof (Elf32_External_Rel
));
5612 bfd_put_32 (output_bfd
, got_offset
,
5613 resolved_plt
->contents
+ plt_offset
5614 + htab
->plt
.plt_got_offset
);
5617 /* Fill in the entry in the global offset table. Leave the entry
5618 as zero for undefined weak symbol in PIE. No PLT relocation
5619 against undefined weak symbol in PIE. */
5620 if (!local_undefweak
)
5622 if (htab
->plt
.has_plt0
)
5623 bfd_put_32 (output_bfd
,
5624 (plt
->output_section
->vma
5625 + plt
->output_offset
5627 + htab
->lazy_plt
->plt_lazy_offset
),
5628 gotplt
->contents
+ got_offset
);
5630 /* Fill in the entry in the .rel.plt section. */
5631 rel
.r_offset
= (gotplt
->output_section
->vma
5632 + gotplt
->output_offset
5634 if (h
->dynindx
== -1
5635 || ((bfd_link_executable (info
)
5636 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5638 && h
->type
== STT_GNU_IFUNC
))
5640 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5641 h
->root
.root
.string
,
5642 h
->root
.u
.def
.section
->owner
);
5644 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5645 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5646 in the .got.plt section. */
5647 bfd_put_32 (output_bfd
,
5648 (h
->root
.u
.def
.value
5649 + h
->root
.u
.def
.section
->output_section
->vma
5650 + h
->root
.u
.def
.section
->output_offset
),
5651 gotplt
->contents
+ got_offset
);
5652 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5653 /* R_386_IRELATIVE comes last. */
5654 plt_index
= htab
->next_irelative_index
--;
5658 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
5659 plt_index
= htab
->next_jump_slot_index
++;
5662 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5663 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5665 /* Don't fill the second and third slots in PLT entry for
5666 static executables nor without PLT0. */
5667 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
5669 bfd_put_32 (output_bfd
,
5670 plt_index
* sizeof (Elf32_External_Rel
),
5671 plt
->contents
+ h
->plt
.offset
5672 + htab
->lazy_plt
->plt_reloc_offset
);
5673 bfd_put_32 (output_bfd
,
5675 + htab
->lazy_plt
->plt_plt_offset
+ 4),
5676 (plt
->contents
+ h
->plt
.offset
5677 + htab
->lazy_plt
->plt_plt_offset
));
5681 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5683 bfd_vma got_offset
, plt_offset
;
5684 asection
*plt
, *got
, *gotplt
;
5685 const bfd_byte
*got_plt_entry
;
5687 /* Set the entry in the GOT procedure linkage table. */
5688 plt
= htab
->plt_got
;
5689 got
= htab
->elf
.sgot
;
5690 gotplt
= htab
->elf
.sgotplt
;
5691 got_offset
= h
->got
.offset
;
5693 if (got_offset
== (bfd_vma
) -1
5699 /* Fill in the entry in the GOT procedure linkage table. */
5700 if (! bfd_link_pic (info
))
5702 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5703 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
5707 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5708 got_offset
+= (got
->output_section
->vma
5709 + got
->output_offset
5710 - gotplt
->output_section
->vma
5711 - gotplt
->output_offset
);
5714 plt_offset
= eh
->plt_got
.offset
;
5715 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
5716 htab
->non_lazy_plt
->plt_entry_size
);
5717 bfd_put_32 (output_bfd
, got_offset
,
5718 (plt
->contents
+ plt_offset
5719 + htab
->non_lazy_plt
->plt_got_offset
));
5722 if (!local_undefweak
5724 && (h
->plt
.offset
!= (bfd_vma
) -1
5725 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5727 /* Mark the symbol as undefined, rather than as defined in
5728 the .plt section. Leave the value if there were any
5729 relocations where pointer equality matters (this is a clue
5730 for the dynamic linker, to make function pointer
5731 comparisons work between an application and shared
5732 library), otherwise set it to zero. If a function is only
5733 called from a binary, there is no need to slow down
5734 shared libraries because of that. */
5735 sym
->st_shndx
= SHN_UNDEF
;
5736 if (!h
->pointer_equality_needed
)
5740 /* Don't generate dynamic GOT relocation against undefined weak
5741 symbol in executable. */
5742 if (h
->got
.offset
!= (bfd_vma
) -1
5743 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
5744 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
5745 && !local_undefweak
)
5747 Elf_Internal_Rela rel
;
5748 asection
*relgot
= htab
->elf
.srelgot
;
5750 /* This symbol has an entry in the global offset table. Set it
5753 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5756 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5757 + htab
->elf
.sgot
->output_offset
5758 + (h
->got
.offset
& ~(bfd_vma
) 1));
5760 /* If this is a static link, or it is a -Bsymbolic link and the
5761 symbol is defined locally or was forced to be local because
5762 of a version file, we just want to emit a RELATIVE reloc.
5763 The entry in the global offset table will already have been
5764 initialized in the relocate_section function. */
5766 && h
->type
== STT_GNU_IFUNC
)
5768 if (h
->plt
.offset
== (bfd_vma
) -1)
5770 /* STT_GNU_IFUNC is referenced without PLT. */
5771 if (htab
->elf
.splt
== NULL
)
5773 /* use .rel[a].iplt section to store .got relocations
5774 in static executable. */
5775 relgot
= htab
->elf
.irelplt
;
5777 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5779 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5780 h
->root
.root
.string
,
5781 h
->root
.u
.def
.section
->owner
);
5783 bfd_put_32 (output_bfd
,
5784 (h
->root
.u
.def
.value
5785 + h
->root
.u
.def
.section
->output_section
->vma
5786 + h
->root
.u
.def
.section
->output_offset
),
5787 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5788 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5793 else if (bfd_link_pic (info
))
5795 /* Generate R_386_GLOB_DAT. */
5803 if (!h
->pointer_equality_needed
)
5806 /* For non-shared object, we can't use .got.plt, which
5807 contains the real function addres if we need pointer
5808 equality. We load the GOT entry with the PLT entry. */
5809 if (htab
->plt_second
!= NULL
)
5811 plt
= htab
->plt_second
;
5812 plt_offset
= eh
->plt_second
.offset
;
5816 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5817 plt_offset
= h
->plt
.offset
;
5819 bfd_put_32 (output_bfd
,
5820 (plt
->output_section
->vma
5821 + plt
->output_offset
+ plt_offset
),
5822 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5826 else if (bfd_link_pic (info
)
5827 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5829 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5830 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
5834 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5836 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5837 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5838 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
5841 elf_append_rel (output_bfd
, relgot
, &rel
);
5846 Elf_Internal_Rela rel
;
5849 /* This symbol needs a copy reloc. Set it up. */
5851 if (h
->dynindx
== -1
5852 || (h
->root
.type
!= bfd_link_hash_defined
5853 && h
->root
.type
!= bfd_link_hash_defweak
)
5854 || htab
->elf
.srelbss
== NULL
5855 || htab
->elf
.sreldynrelro
== NULL
)
5858 rel
.r_offset
= (h
->root
.u
.def
.value
5859 + h
->root
.u
.def
.section
->output_section
->vma
5860 + h
->root
.u
.def
.section
->output_offset
);
5861 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5862 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5863 s
= htab
->elf
.sreldynrelro
;
5865 s
= htab
->elf
.srelbss
;
5866 elf_append_rel (output_bfd
, s
, &rel
);
5872 /* Finish up local dynamic symbol handling. We set the contents of
5873 various dynamic sections here. */
5876 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5878 struct elf_link_hash_entry
*h
5879 = (struct elf_link_hash_entry
*) *slot
;
5880 struct bfd_link_info
*info
5881 = (struct bfd_link_info
*) inf
;
5883 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5887 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5888 here since undefined weak symbol may not be dynamic and may not be
5889 called for elf_i386_finish_dynamic_symbol. */
5892 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5895 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5896 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5898 if (h
->root
.type
!= bfd_link_hash_undefweak
5899 || h
->dynindx
!= -1)
5902 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5906 /* Used to decide how to sort relocs in an optimal manner for the
5907 dynamic linker, before writing them out. */
5909 static enum elf_reloc_type_class
5910 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5911 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5912 const Elf_Internal_Rela
*rela
)
5914 bfd
*abfd
= info
->output_bfd
;
5915 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5916 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5918 if (htab
->dynsym
!= NULL
5919 && htab
->dynsym
->contents
!= NULL
)
5921 /* Check relocation against STT_GNU_IFUNC symbol if there are
5923 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5924 if (r_symndx
!= STN_UNDEF
)
5926 Elf_Internal_Sym sym
;
5927 if (!bed
->s
->swap_symbol_in (abfd
,
5928 (htab
->dynsym
->contents
5929 + r_symndx
* sizeof (Elf32_External_Sym
)),
5933 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5934 return reloc_class_ifunc
;
5938 switch (ELF32_R_TYPE (rela
->r_info
))
5940 case R_386_IRELATIVE
:
5941 return reloc_class_ifunc
;
5942 case R_386_RELATIVE
:
5943 return reloc_class_relative
;
5944 case R_386_JUMP_SLOT
:
5945 return reloc_class_plt
;
5947 return reloc_class_copy
;
5949 return reloc_class_normal
;
5953 /* Finish up the dynamic sections. */
5956 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5957 struct bfd_link_info
*info
)
5959 struct elf_i386_link_hash_table
*htab
;
5962 const struct elf_i386_backend_data
*abed
;
5964 htab
= elf_i386_hash_table (info
);
5968 dynobj
= htab
->elf
.dynobj
;
5969 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5970 abed
= get_elf_i386_backend_data (output_bfd
);
5972 if (htab
->elf
.dynamic_sections_created
)
5974 Elf32_External_Dyn
*dyncon
, *dynconend
;
5976 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5979 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5980 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5981 for (; dyncon
< dynconend
; dyncon
++)
5983 Elf_Internal_Dyn dyn
;
5986 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5991 if (abed
->os
== is_vxworks
5992 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5997 s
= htab
->elf
.sgotplt
;
5998 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6002 s
= htab
->elf
.srelplt
;
6003 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6007 s
= htab
->elf
.srelplt
;
6008 dyn
.d_un
.d_val
= s
->size
;
6012 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6015 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6017 /* UnixWare sets the entsize of .plt to 4, although that doesn't
6018 really seem like the right value. */
6019 elf_section_data (htab
->elf
.splt
->output_section
)
6020 ->this_hdr
.sh_entsize
= 4;
6022 if (htab
->plt
.has_plt0
)
6024 /* Fill in the special first entry in the procedure linkage
6026 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
6027 htab
->lazy_plt
->plt0_entry_size
);
6028 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
6029 abed
->plt0_pad_byte
,
6030 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
6031 if (!bfd_link_pic (info
))
6033 bfd_put_32 (output_bfd
,
6034 (htab
->elf
.sgotplt
->output_section
->vma
6035 + htab
->elf
.sgotplt
->output_offset
6037 htab
->elf
.splt
->contents
6038 + htab
->lazy_plt
->plt0_got1_offset
);
6039 bfd_put_32 (output_bfd
,
6040 (htab
->elf
.sgotplt
->output_section
->vma
6041 + htab
->elf
.sgotplt
->output_offset
6043 htab
->elf
.splt
->contents
6044 + htab
->lazy_plt
->plt0_got2_offset
);
6046 if (abed
->os
== is_vxworks
)
6048 Elf_Internal_Rela rel
;
6049 int num_plts
= (htab
->elf
.splt
->size
6050 / htab
->plt
.plt_entry_size
) - 1;
6053 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6054 + 4. On IA32 we use REL relocations so the
6055 addend goes in the PLT directly. */
6056 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
6057 + htab
->elf
.splt
->output_offset
6058 + htab
->lazy_plt
->plt0_got1_offset
);
6059 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6061 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
6062 htab
->srelplt2
->contents
);
6063 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
6065 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
6066 + htab
->elf
.splt
->output_offset
6067 + htab
->lazy_plt
->plt0_got2_offset
);
6068 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6070 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
6071 htab
->srelplt2
->contents
+
6072 sizeof (Elf32_External_Rel
));
6073 /* Correct the .rel.plt.unloaded relocations. */
6074 p
= htab
->srelplt2
->contents
;
6075 if (bfd_link_pic (info
))
6076 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
6078 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
6080 for (; num_plts
; num_plts
--)
6082 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
6083 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
6085 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
6086 p
+= sizeof (Elf32_External_Rel
);
6088 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
6089 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
6091 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
6092 p
+= sizeof (Elf32_External_Rel
);
6099 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
6100 elf_section_data (htab
->plt_got
->output_section
)
6101 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6103 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
6104 elf_section_data (htab
->plt_second
->output_section
)
6105 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6108 /* Fill in the first three entries in the global offset table. */
6109 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
6111 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6114 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6118 bfd_put_32 (output_bfd
,
6120 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
6121 htab
->elf
.sgotplt
->contents
);
6122 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
6123 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
6125 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
6128 /* Adjust .eh_frame for .plt section. */
6129 if (htab
->plt_eh_frame
!= NULL
6130 && htab
->plt_eh_frame
->contents
!= NULL
)
6132 if (htab
->elf
.splt
!= NULL
6133 && htab
->elf
.splt
->size
!= 0
6134 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6135 && htab
->elf
.splt
->output_section
!= NULL
6136 && htab
->plt_eh_frame
->output_section
!= NULL
)
6138 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6139 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6140 + htab
->plt_eh_frame
->output_offset
6141 + PLT_FDE_START_OFFSET
;
6142 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6143 htab
->plt_eh_frame
->contents
6144 + PLT_FDE_START_OFFSET
);
6146 if (htab
->plt_eh_frame
->sec_info_type
6147 == SEC_INFO_TYPE_EH_FRAME
)
6149 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6151 htab
->plt_eh_frame
->contents
))
6156 /* Adjust .eh_frame for .plt.got section. */
6157 if (htab
->plt_got_eh_frame
!= NULL
6158 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6160 if (htab
->plt_got
!= NULL
6161 && htab
->plt_got
->size
!= 0
6162 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6163 && htab
->plt_got
->output_section
!= NULL
6164 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6166 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6167 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6168 + htab
->plt_got_eh_frame
->output_offset
6169 + PLT_FDE_START_OFFSET
;
6170 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6171 htab
->plt_got_eh_frame
->contents
6172 + PLT_FDE_START_OFFSET
);
6174 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6176 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6177 htab
->plt_got_eh_frame
,
6178 htab
->plt_got_eh_frame
->contents
))
6183 /* Adjust .eh_frame for the second PLT section. */
6184 if (htab
->plt_second_eh_frame
!= NULL
6185 && htab
->plt_second_eh_frame
->contents
!= NULL
)
6187 if (htab
->plt_second
!= NULL
6188 && htab
->plt_second
->size
!= 0
6189 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
6190 && htab
->plt_second
->output_section
!= NULL
6191 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
6193 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
6194 bfd_vma eh_frame_start
6195 = (htab
->plt_second_eh_frame
->output_section
->vma
6196 + htab
->plt_second_eh_frame
->output_offset
6197 + PLT_FDE_START_OFFSET
);
6198 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6199 htab
->plt_second_eh_frame
->contents
6200 + PLT_FDE_START_OFFSET
);
6202 if (htab
->plt_second_eh_frame
->sec_info_type
6203 == SEC_INFO_TYPE_EH_FRAME
)
6205 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6206 htab
->plt_second_eh_frame
,
6207 htab
->plt_second_eh_frame
->contents
))
6212 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6213 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6215 /* Fill PLT entries for undefined weak symbols in PIE. */
6216 if (bfd_link_pie (info
))
6217 bfd_hash_traverse (&info
->hash
->table
,
6218 elf_i386_pie_finish_undefweak_symbol
,
6224 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6225 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6226 It has to be done before elf_link_sort_relocs is called so that
6227 dynamic relocations are properly sorted. */
6230 elf_i386_output_arch_local_syms
6231 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6232 struct bfd_link_info
*info
,
6233 void *flaginfo ATTRIBUTE_UNUSED
,
6234 int (*func
) (void *, const char *,
6237 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6239 struct elf_i386_link_hash_table
*htab
= elf_i386_hash_table (info
);
6243 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6244 htab_traverse (htab
->loc_hash_table
,
6245 elf_i386_finish_local_dynamic_symbol
,
6251 /* Sort relocs into address order. */
6254 compare_relocs (const void *ap
, const void *bp
)
6256 const arelent
*a
= * (const arelent
**) ap
;
6257 const arelent
*b
= * (const arelent
**) bp
;
6259 if (a
->address
> b
->address
)
6261 else if (a
->address
< b
->address
)
6267 enum elf_i386_plt_type
6272 plt_second
= 1 << 2,
6281 enum elf_i386_plt_type type
;
6282 unsigned int plt_got_offset
;
6283 unsigned int plt_entry_size
;
6287 /* Forward declaration. */
6288 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
;
6290 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
6291 dynamic relocations. */
6294 elf_i386_get_synthetic_symtab (bfd
*abfd
,
6295 long symcount ATTRIBUTE_UNUSED
,
6296 asymbol
**syms ATTRIBUTE_UNUSED
,
6301 long size
, count
, i
, n
;
6303 unsigned int plt_got_offset
, plt_entry_size
;
6305 bfd_byte
*plt_contents
;
6306 long dynrelcount
, relsize
;
6307 arelent
**dynrelbuf
;
6308 const struct elf_i386_lazy_plt_layout
*lazy_plt
;
6309 const struct elf_i386_non_lazy_plt_layout
*non_lazy_plt
;
6310 const struct elf_i386_lazy_plt_layout
*lazy_ibt_plt
;
6311 const struct elf_i386_non_lazy_plt_layout
*non_lazy_ibt_plt
;
6315 enum elf_i386_plt_type plt_type
;
6316 struct elf_i386_plt plts
[] =
6318 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0 },
6319 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0 },
6320 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0 },
6321 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0 }
6326 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
6329 if (dynsymcount
<= 0)
6332 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
6336 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
6337 if (dynrelbuf
== NULL
)
6340 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
6343 /* Sort the relocs by address. */
6344 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*), compare_relocs
);
6346 non_lazy_plt
= NULL
;
6347 /* Silence GCC 6. */
6349 non_lazy_ibt_plt
= NULL
;
6350 lazy_ibt_plt
= NULL
;
6351 switch (get_elf_i386_backend_data (abfd
)->os
)
6354 non_lazy_plt
= &elf_i386_non_lazy_plt
;
6355 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
6356 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
6359 lazy_plt
= &elf_i386_lazy_plt
;
6362 lazy_plt
= &elf_i386_nacl_plt
;
6369 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6371 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
6375 /* Get the PLT section contents. */
6376 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6377 if (plt_contents
== NULL
)
6379 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6380 plt_contents
, 0, plt
->size
))
6382 free (plt_contents
);
6386 /* Check what kind of PLT it is. */
6387 plt_type
= plt_unknown
;
6388 if (plts
[j
].type
== plt_unknown
)
6390 /* Match lazy PLT first. */
6391 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
6392 lazy_plt
->plt0_got1_offset
) == 0)
6394 /* The fist entry in the lazy IBT PLT is the same as the
6396 if (lazy_ibt_plt
!= NULL
6397 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
6398 lazy_ibt_plt
->plt_entry
,
6399 lazy_ibt_plt
->plt_got_offset
) == 0))
6400 plt_type
= plt_lazy
| plt_second
;
6402 plt_type
= plt_lazy
;
6404 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
6405 lazy_plt
->plt0_got1_offset
) == 0)
6407 /* The fist entry in the PIC lazy IBT PLT is the same as
6408 the normal PIC lazy PLT. */
6409 if (lazy_ibt_plt
!= NULL
6410 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
6411 lazy_ibt_plt
->pic_plt_entry
,
6412 lazy_ibt_plt
->plt_got_offset
) == 0))
6413 plt_type
= plt_lazy
| plt_pic
| plt_second
;
6415 plt_type
= plt_lazy
| plt_pic
;
6419 if (non_lazy_plt
!= NULL
6420 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
))
6422 /* Match non-lazy PLT. */
6423 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
6424 non_lazy_plt
->plt_got_offset
) == 0)
6425 plt_type
= plt_non_lazy
;
6426 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
6427 non_lazy_plt
->plt_got_offset
) == 0)
6431 if ((non_lazy_ibt_plt
!= NULL
)
6432 && (plt_type
== plt_unknown
|| plt_type
== plt_second
))
6434 if (memcmp (plt_contents
,
6435 non_lazy_ibt_plt
->plt_entry
,
6436 non_lazy_ibt_plt
->plt_got_offset
) == 0)
6438 /* Match IBT PLT. */
6439 plt_type
= plt_second
;
6440 non_lazy_plt
= non_lazy_ibt_plt
;
6442 else if (memcmp (plt_contents
,
6443 non_lazy_ibt_plt
->pic_plt_entry
,
6444 non_lazy_ibt_plt
->plt_got_offset
) == 0)
6446 /* Match PIC IBT PLT. */
6447 plt_type
= plt_second
| plt_pic
;
6448 non_lazy_plt
= non_lazy_ibt_plt
;
6452 if (plt_type
== plt_unknown
)
6456 plts
[j
].type
= plt_type
;
6458 if ((plt_type
& plt_lazy
))
6460 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
6461 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
6462 /* Skip PLT0 in lazy PLT. */
6467 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
6468 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
6472 /* Skip lazy PLT when the second PLT is used. */
6473 if ((plt_type
& (plt_lazy
| plt_second
))
6474 == (plt_lazy
| plt_second
))
6478 n
= plt
->size
/ plts
[j
].plt_entry_size
;
6483 plts
[j
].contents
= plt_contents
;
6485 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
6486 if ((plt_type
& plt_pic
))
6487 got_addr
= (bfd_vma
) -1;
6490 size
= count
* sizeof (asymbol
);
6491 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
6495 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6496 if (plts
[j
].contents
!= NULL
)
6497 free (plts
[j
].contents
);
6504 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
6506 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
6508 got_addr
= sec
->vma
;
6511 sec
= bfd_get_section_by_name (abfd
, ".got");
6513 got_addr
= sec
->vma
;
6516 if (got_addr
== (bfd_vma
) -1)
6520 /* Check for each PLT section. */
6523 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6524 if ((plt_contents
= plts
[j
].contents
) != NULL
)
6529 plt_got_offset
= plts
[j
].plt_got_offset
;
6530 plt_entry_size
= plts
[j
].plt_entry_size
;
6534 if ((plts
[j
].type
& plt_lazy
))
6536 /* Skip PLT0 in lazy PLT. */
6538 offset
= plt_entry_size
;
6546 /* Check each PLT entry against dynamic relocations. */
6547 for (; k
< plts
[j
].count
; k
++)
6554 /* Get the GOT offset, a signed 32-bit integer. */
6555 off
= H_GET_32 (abfd
, (plt_contents
+ offset
6557 got_vma
= got_addr
+ off
;
6559 /* Binary search. */
6563 while ((min
+ 1) < max
)
6567 mid
= (min
+ max
) / 2;
6569 if (got_vma
> r
->address
)
6571 else if (got_vma
< r
->address
)
6580 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6581 if (got_vma
== p
->address
6583 && (p
->howto
->type
== R_386_JUMP_SLOT
6584 || p
->howto
->type
== R_386_GLOB_DAT
6585 || p
->howto
->type
== R_386_IRELATIVE
))
6587 *s
= **p
->sym_ptr_ptr
;
6588 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6589 set. Since we are defining a symbol, ensure one
6591 if ((s
->flags
& BSF_LOCAL
) == 0)
6592 s
->flags
|= BSF_GLOBAL
;
6593 s
->flags
|= BSF_SYNTHETIC
;
6594 /* This is no longer a section symbol. */
6595 s
->flags
&= ~BSF_SECTION_SYM
;
6597 s
->the_bfd
= plt
->owner
;
6599 /* Store relocation for later use. */
6601 /* Add @plt to function name later. */
6602 size
+= strlen (s
->name
) + sizeof ("@plt");
6604 size
+= sizeof ("+0x") - 1 + 8;
6608 offset
+= plt_entry_size
;
6612 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
6618 /* Allocate space for @plt suffixes. */
6619 names
= (char *) bfd_malloc (size
);
6624 for (i
= 0; i
< count
; i
++)
6626 /* Add @plt to function name. */
6627 arelent
*p
= (arelent
*) s
->udata
.p
;
6630 size
= strlen (s
->name
);
6631 memcpy (names
, s
->name
, size
);
6638 memcpy (names
, "+0x", sizeof ("+0x") - 1);
6639 names
+= sizeof ("+0x") - 1;
6640 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
6641 for (a
= buf
; *a
== '0'; ++a
)
6644 memcpy (names
, a
, size
);
6647 memcpy (names
, "@plt", sizeof ("@plt"));
6648 names
+= sizeof ("@plt");
6652 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6653 if (plts
[j
].contents
!= NULL
)
6654 free (plts
[j
].contents
);
6661 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6664 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
6666 if (h
->plt
.offset
!= (bfd_vma
) -1
6668 && !h
->pointer_equality_needed
)
6671 return _bfd_elf_hash_symbol (h
);
6674 /* Parse i386 GNU properties. */
6676 static enum elf_property_kind
6677 elf_i386_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6678 bfd_byte
*ptr
, unsigned int datasz
)
6684 case GNU_PROPERTY_X86_ISA_1_USED
:
6685 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6686 case GNU_PROPERTY_X86_FEATURE_1_AND
:
6690 ((type
== GNU_PROPERTY_X86_ISA_1_USED
6691 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6692 : (type
== GNU_PROPERTY_X86_ISA_1_NEEDED
6693 ? _("error: %B: <corrupt x86 ISA needed size: 0x%x>")
6694 : _("error: %B: <corrupt x86 feature size: 0x%x>"))),
6696 return property_corrupt
;
6698 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
6699 /* Combine properties of the same type. */
6700 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
6701 prop
->pr_kind
= property_number
;
6705 return property_ignored
;
6708 return property_number
;
6711 /* Merge i386 GNU property BPROP with APROP. If APROP isn't NULL,
6712 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6713 should be merged with ABFD. */
6716 elf_i386_merge_gnu_properties (struct bfd_link_info
*info
,
6717 bfd
*abfd ATTRIBUTE_UNUSED
,
6718 elf_property
*aprop
,
6719 elf_property
*bprop
)
6721 unsigned int number
, features
;
6722 bfd_boolean updated
= FALSE
;
6723 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
6727 case GNU_PROPERTY_X86_ISA_1_USED
:
6728 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6729 if (aprop
!= NULL
&& bprop
!= NULL
)
6731 number
= aprop
->u
.number
;
6732 aprop
->u
.number
= number
| bprop
->u
.number
;
6733 updated
= number
!= (unsigned int) aprop
->u
.number
;
6737 /* Return TRUE if APROP is NULL to indicate that BPROP should
6738 be added to ABFD. */
6739 updated
= aprop
== NULL
;
6743 case GNU_PROPERTY_X86_FEATURE_1_AND
:
6744 /* Only one of APROP and BPROP can be NULL:
6745 1. APROP & BPROP when both APROP and BPROP aren't NULL.
6746 2. If APROP is NULL, remove x86 feature.
6747 3. Otherwise, do nothing.
6749 if (aprop
!= NULL
&& bprop
!= NULL
)
6753 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6754 number
= aprop
->u
.number
;
6755 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT. */
6756 aprop
->u
.number
= (number
& bprop
->u
.number
) | features
;
6757 updated
= number
!= (unsigned int) aprop
->u
.number
;
6758 /* Remove the property if all feature bits are cleared. */
6759 if (aprop
->u
.number
== 0)
6760 aprop
->pr_kind
= property_remove
;
6766 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6769 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT. */
6772 number
= aprop
->u
.number
;
6773 aprop
->u
.number
= number
| features
;
6774 updated
= number
!= (unsigned int) aprop
->u
.number
;
6778 bprop
->u
.number
|= features
;
6782 else if (aprop
!= NULL
)
6784 aprop
->pr_kind
= property_remove
;
6791 /* Never should happen. */
6798 /* Set up i386 GNU properties. Return the first relocatable ELF input
6799 with GNU properties if found. Otherwise, return NULL. */
6802 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
6804 bfd_boolean normal_target
;
6805 bfd_boolean lazy_plt
;
6806 asection
*sec
, *pltsec
;
6808 bfd_boolean use_ibt_plt
;
6809 unsigned int plt_alignment
, features
;
6810 struct elf_i386_link_hash_table
*htab
;
6815 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
6818 /* Turn on GNU_PROPERTY_X86_FEATURE_1_IBT. */
6822 for (pbfd
= info
->input_bfds
;
6824 pbfd
= pbfd
->link
.next
)
6825 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
6826 && bfd_count_sections (pbfd
) != 0)
6830 if (elf_properties (pbfd
) != NULL
)
6832 /* Find a normal input file with GNU property note. */
6833 prop
= _bfd_elf_get_property (pbfd
,
6834 GNU_PROPERTY_X86_FEATURE_1_AND
,
6836 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT. */
6837 prop
->u
.number
|= features
;
6838 prop
->pr_kind
= property_number
;
6843 if (pbfd
== NULL
&& ebfd
!= NULL
)
6845 /* Create GNU_PROPERTY_X86_FEATURE_1_IBT if needed. */
6846 prop
= _bfd_elf_get_property (ebfd
,
6847 GNU_PROPERTY_X86_FEATURE_1_AND
,
6849 prop
->u
.number
= features
;
6850 prop
->pr_kind
= property_number
;
6852 sec
= bfd_make_section_with_flags (ebfd
,
6853 NOTE_GNU_PROPERTY_SECTION_NAME
,
6861 info
->callbacks
->einfo (_("%F: failed to create GNU property section\n"));
6863 if (!bfd_set_section_alignment (ebfd
, sec
, 2))
6864 goto error_alignment
;
6866 elf_section_type (sec
) = SHT_NOTE
;
6870 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
6872 if (bfd_link_relocatable (info
))
6875 htab
= elf_i386_hash_table (info
);
6879 use_ibt_plt
= info
->ibtplt
|| info
->ibt
;
6880 if (!use_ibt_plt
&& pbfd
!= NULL
)
6882 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
6883 elf_property_list
*p
;
6885 /* The property list is sorted in order of type. */
6886 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
6888 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
6890 use_ibt_plt
= !!(p
->property
.u
.number
6891 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
6894 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
6899 dynobj
= htab
->elf
.dynobj
;
6901 /* Set htab->elf.dynobj here so that there is no need to check and
6902 set it in check_relocs. */
6907 /* Find a normal input file to hold linker created
6909 for (abfd
= info
->input_bfds
;
6911 abfd
= abfd
->link
.next
)
6913 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0)
6915 htab
->elf
.dynobj
= abfd
;
6921 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
6922 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
6923 canonical function address. */
6924 htab
->plt
.has_plt0
= 1;
6925 normal_target
= FALSE
;
6927 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
6932 htab
->lazy_plt
= &elf_i386_lazy_ibt_plt
;
6933 htab
->non_lazy_plt
= &elf_i386_non_lazy_ibt_plt
;
6937 htab
->lazy_plt
= &elf_i386_lazy_plt
;
6938 htab
->non_lazy_plt
= &elf_i386_non_lazy_plt
;
6940 normal_target
= TRUE
;
6943 htab
->lazy_plt
= &elf_i386_lazy_plt
;
6944 htab
->non_lazy_plt
= NULL
;
6945 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
,
6947 info
->callbacks
->einfo (_("%F: failed to create VxWorks dynamic sections\n"));
6950 htab
->lazy_plt
= &elf_i386_nacl_plt
;
6951 htab
->non_lazy_plt
= NULL
;
6955 pltsec
= htab
->elf
.splt
;
6957 /* If the non-lazy PLT is available, use it for all PLT entries if
6958 there are no PLT0 or no .plt section. */
6959 if (htab
->non_lazy_plt
!= NULL
6960 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
6963 if (bfd_link_pic (info
))
6965 = htab
->non_lazy_plt
->pic_plt_entry
;
6968 = htab
->non_lazy_plt
->plt_entry
;
6969 htab
->plt
.plt_entry_size
6970 = htab
->non_lazy_plt
->plt_entry_size
;
6971 htab
->plt
.plt_got_offset
6972 = htab
->non_lazy_plt
->plt_got_offset
;
6973 htab
->plt
.eh_frame_plt_size
6974 = htab
->non_lazy_plt
->eh_frame_plt_size
;
6975 htab
->plt
.eh_frame_plt
6976 = htab
->non_lazy_plt
->eh_frame_plt
;
6981 if (bfd_link_pic (info
))
6983 htab
->plt
.plt0_entry
6984 = htab
->lazy_plt
->pic_plt0_entry
;
6986 = htab
->lazy_plt
->pic_plt_entry
;
6990 htab
->plt
.plt0_entry
6991 = htab
->lazy_plt
->plt0_entry
;
6993 = htab
->lazy_plt
->plt_entry
;
6995 htab
->plt
.plt_entry_size
6996 = htab
->lazy_plt
->plt_entry_size
;
6997 htab
->plt
.plt_got_offset
6998 = htab
->lazy_plt
->plt_got_offset
;
6999 htab
->plt
.eh_frame_plt_size
7000 = htab
->lazy_plt
->eh_frame_plt_size
;
7001 htab
->plt
.eh_frame_plt
7002 = htab
->lazy_plt
->eh_frame_plt
;
7005 /* Return if there are no normal input files. */
7009 /* Since create_dynamic_sections isn't always called, but GOT
7010 relocations need GOT relocations, create them here so that we
7011 don't need to do it in check_relocs. */
7012 if (htab
->elf
.sgot
== NULL
7013 && !_bfd_elf_create_got_section (dynobj
, info
))
7014 info
->callbacks
->einfo (_("%F: failed to create GOT sections\n"));
7016 /* Create the ifunc sections here so that check_relocs can be
7018 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
7019 info
->callbacks
->einfo (_("%F: failed to create ifunc sections\n"));
7021 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
7025 /* Whe creating executable, set the contents of the .interp
7026 section to the interpreter. */
7027 if (bfd_link_executable (info
) && !info
->nointerp
)
7029 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
7032 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7033 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7037 /* Don't change PLT section alignment for NaCl since it uses
7038 64-byte PLT entry and sets PLT section alignment to 32
7042 const struct elf_backend_data
*bed
7043 = get_elf_backend_data (dynobj
);
7044 flagword pltflags
= (bed
->dynamic_sec_flags
7049 unsigned int non_lazy_plt_alignment
7050 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
7053 if (!bfd_set_section_alignment (sec
->owner
, sec
,
7055 goto error_alignment
;
7057 /* Create the GOT procedure linkage table. */
7058 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7062 info
->callbacks
->einfo (_("%F: failed to create GOT PLT section\n"));
7064 if (!bfd_set_section_alignment (dynobj
, sec
,
7065 non_lazy_plt_alignment
))
7066 goto error_alignment
;
7068 htab
->plt_got
= sec
;
7076 /* Create the second PLT for Intel IBT support. IBT
7077 PLT is supported only for non-NaCl target and is
7078 is needed only for lazy binding. */
7079 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7083 info
->callbacks
->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
7085 if (!bfd_set_section_alignment (dynobj
, sec
,
7087 goto error_alignment
;
7090 htab
->plt_second
= sec
;
7094 if (!info
->no_ld_generated_unwind_info
)
7096 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
7097 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7098 | SEC_LINKER_CREATED
);
7100 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7104 info
->callbacks
->einfo (_("%F: failed to create PLT .eh_frame section\n"));
7106 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
7107 goto error_alignment
;
7109 htab
->plt_eh_frame
= sec
;
7111 if (htab
->plt_got
!= NULL
)
7113 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7117 info
->callbacks
->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
7119 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
7120 goto error_alignment
;
7122 htab
->plt_got_eh_frame
= sec
;
7129 /* The .iplt section is used for IFUNC symbols in static
7131 sec
= htab
->elf
.iplt
;
7133 && !bfd_set_section_alignment (sec
->owner
, sec
,
7137 info
->callbacks
->einfo (_("%F%A: failed to align section\n"),
7145 #define TARGET_LITTLE_SYM i386_elf32_vec
7146 #define TARGET_LITTLE_NAME "elf32-i386"
7147 #define ELF_ARCH bfd_arch_i386
7148 #define ELF_TARGET_ID I386_ELF_DATA
7149 #define ELF_MACHINE_CODE EM_386
7150 #define ELF_MAXPAGESIZE 0x1000
7152 #define elf_backend_can_gc_sections 1
7153 #define elf_backend_can_refcount 1
7154 #define elf_backend_want_got_plt 1
7155 #define elf_backend_plt_readonly 1
7156 #define elf_backend_want_plt_sym 0
7157 #define elf_backend_got_header_size 12
7158 #define elf_backend_plt_alignment 4
7159 #define elf_backend_dtrel_excludes_plt 1
7160 #define elf_backend_extern_protected_data 1
7161 #define elf_backend_caches_rawsize 1
7162 #define elf_backend_want_dynrelro 1
7164 /* Support RELA for objdump of prelink objects. */
7165 #define elf_info_to_howto elf_i386_info_to_howto_rel
7166 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
7168 #define bfd_elf32_mkobject elf_i386_mkobject
7170 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
7171 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
7172 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
7173 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
7174 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
7176 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
7177 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
7178 #define elf_backend_check_relocs elf_i386_check_relocs
7179 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
7180 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
7181 #define elf_backend_fake_sections elf_i386_fake_sections
7182 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
7183 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
7184 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
7185 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
7186 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
7187 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
7188 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
7189 #define elf_backend_relocate_section elf_i386_relocate_section
7190 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
7191 #define elf_backend_always_size_sections elf_i386_always_size_sections
7192 #define elf_backend_omit_section_dynsym \
7193 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7194 #define elf_backend_hash_symbol elf_i386_hash_symbol
7195 #define elf_backend_fixup_symbol elf_i386_fixup_symbol
7196 #define elf_backend_parse_gnu_properties elf_i386_parse_gnu_properties
7197 #define elf_backend_merge_gnu_properties elf_i386_merge_gnu_properties
7198 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
7200 #include "elf32-target.h"
7202 /* FreeBSD support. */
7204 #undef TARGET_LITTLE_SYM
7205 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
7206 #undef TARGET_LITTLE_NAME
7207 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
7209 #define ELF_OSABI ELFOSABI_FREEBSD
7211 /* The kernel recognizes executables as valid only if they carry a
7212 "FreeBSD" label in the ELF header. So we put this label on all
7213 executables and (for simplicity) also all other object files. */
7216 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
7218 _bfd_elf_post_process_headers (abfd
, info
);
7220 #ifdef OLD_FREEBSD_ABI_LABEL
7222 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
7223 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
7224 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
7229 #undef elf_backend_post_process_headers
7230 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
7232 #define elf32_bed elf32_i386_fbsd_bed
7234 #undef elf_backend_add_symbol_hook
7236 #include "elf32-target.h"
7240 #undef TARGET_LITTLE_SYM
7241 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
7242 #undef TARGET_LITTLE_NAME
7243 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
7245 #undef elf_backend_post_process_headers
7247 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7248 objects won't be recognized. */
7252 #define elf32_bed elf32_i386_sol2_bed
7254 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
7256 #undef elf_backend_static_tls_alignment
7257 #define elf_backend_static_tls_alignment 8
7259 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7261 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7263 #undef elf_backend_want_plt_sym
7264 #define elf_backend_want_plt_sym 1
7266 #undef elf_backend_strtab_flags
7267 #define elf_backend_strtab_flags SHF_STRINGS
7269 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
7270 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
7271 FALSE otherwise. ISECTION is the best guess matching section from the
7272 input bfd IBFD, but it might be NULL. */
7275 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7276 bfd
*obfd ATTRIBUTE_UNUSED
,
7277 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7278 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7280 /* PR 19938: FIXME: Need to add code for setting the sh_info
7281 and sh_link fields of Solaris specific section types. */
7284 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
7285 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
7287 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
7289 The following values should be set:
7292 -----------------------------------------------------------------------------
7293 SHT_SUNW_ancillary The section header index of 0
7294 [0x6fffffee] the associated string table.
7296 SHT_SUNW_capinfo The section header index of For a dynamic object, the
7297 [0x6ffffff0] the associated symbol table. section header index of
7299 SHT_SUNW_capchain table,
7302 SHT_SUNW_symsort The section header index of 0
7303 [0x6ffffff1] the associated symbol table.
7305 SHT_SUNW_tlssort The section header index of 0
7306 [0x6ffffff2] the associated symbol table.
7308 SHT_SUNW_LDYNSYM The section header index of One greater than the
7309 [0x6ffffff3] the associated string table. symbol table index of the
7310 This index is the same string last local symbol,
7311 table used by the SHT_DYNSYM STB_LOCAL. Since
7312 section. SHT_SUNW_LDYNSYM only
7313 contains local symbols,
7314 sh_info is equivalent to
7315 the number of symbols in
7318 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
7319 [0x6ffffff5] the section header index of to named strings, the
7320 the associated section header index of
7321 SHT_SUNW_capinfo table, the associated string
7322 otherwise 0. table, otherwise 0.
7324 SHT_SUNW_move The section header index of 0
7325 [0x6ffffffa] the associated symbol table.
7330 SHT_SUNW_syminfo The section header index of The section header index
7331 [0x6ffffffc] the associated symbol table. of the associated
7334 SHT_SUNW_verdef The section header index of The number of version
7335 [0x6ffffffd] the associated string table. definitions within the
7338 SHT_SUNW_verneed The section header index of The number of version
7339 [0x6ffffffe] the associated string table. dependencies within the
7342 SHT_SUNW_versym The section header index of 0
7343 [0x6fffffff] the associated symbol table. */
7346 #undef elf_backend_copy_special_section_fields
7347 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
7349 #include "elf32-target.h"
7351 /* Intel MCU support. */
7354 elf32_iamcu_elf_object_p (bfd
*abfd
)
7356 /* Set the right machine number for an IAMCU elf32 file. */
7357 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
7361 #undef TARGET_LITTLE_SYM
7362 #define TARGET_LITTLE_SYM iamcu_elf32_vec
7363 #undef TARGET_LITTLE_NAME
7364 #define TARGET_LITTLE_NAME "elf32-iamcu"
7366 #define ELF_ARCH bfd_arch_iamcu
7368 #undef ELF_MACHINE_CODE
7369 #define ELF_MACHINE_CODE EM_IAMCU
7374 #define elf32_bed elf32_iamcu_bed
7376 #undef elf_backend_object_p
7377 #define elf_backend_object_p elf32_iamcu_elf_object_p
7379 #undef elf_backend_static_tls_alignment
7381 #undef elf_backend_want_plt_sym
7382 #define elf_backend_want_plt_sym 0
7384 #undef elf_backend_strtab_flags
7385 #undef elf_backend_copy_special_section_fields
7387 #include "elf32-target.h"
7389 /* Restore defaults. */
7391 #define ELF_ARCH bfd_arch_i386
7392 #undef ELF_MACHINE_CODE
7393 #define ELF_MACHINE_CODE EM_386
7395 /* Native Client support. */
7397 #undef TARGET_LITTLE_SYM
7398 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
7399 #undef TARGET_LITTLE_NAME
7400 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
7402 #define elf32_bed elf32_i386_nacl_bed
7404 #undef ELF_MAXPAGESIZE
7405 #define ELF_MAXPAGESIZE 0x10000
7407 /* Restore defaults. */
7409 #undef elf_backend_want_plt_sym
7410 #define elf_backend_want_plt_sym 0
7411 #undef elf_backend_post_process_headers
7412 #undef elf_backend_static_tls_alignment
7414 /* NaCl uses substantially different PLT entries for the same effects. */
7416 #undef elf_backend_plt_alignment
7417 #define elf_backend_plt_alignment 5
7418 #define NACL_PLT_ENTRY_SIZE 64
7419 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7421 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
7423 0xff, 0x35, /* pushl contents of address */
7424 0, 0, 0, 0, /* replaced with address of .got + 4. */
7425 0x8b, 0x0d, /* movl contents of address, %ecx */
7426 0, 0, 0, 0, /* replaced with address of .got + 8. */
7427 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
7428 0xff, 0xe1 /* jmp *%ecx */
7431 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7433 0x8b, 0x0d, /* movl contents of address, %ecx */
7434 0, 0, 0, 0, /* replaced with GOT slot address. */
7435 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
7436 0xff, 0xe1, /* jmp *%ecx */
7438 /* Pad to the next 32-byte boundary with nop instructions. */
7440 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7441 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7443 /* Lazy GOT entries point here (32-byte aligned). */
7444 0x68, /* pushl immediate */
7445 0, 0, 0, 0, /* replaced with reloc offset. */
7446 0xe9, /* jmp relative */
7447 0, 0, 0, 0, /* replaced with offset to .plt. */
7449 /* Pad to the next 32-byte boundary with nop instructions. */
7450 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7451 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7455 static const bfd_byte
7456 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
7458 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
7459 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
7460 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
7461 0xff, 0xe1, /* jmp *%ecx */
7463 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
7464 so pad to that size with nop instructions. */
7465 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
7468 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7470 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
7471 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
7472 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
7473 0xff, 0xe1, /* jmp *%ecx */
7475 /* Pad to the next 32-byte boundary with nop instructions. */
7477 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7478 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7480 /* Lazy GOT entries point here (32-byte aligned). */
7481 0x68, /* pushl immediate */
7482 0, 0, 0, 0, /* replaced with offset into relocation table. */
7483 0xe9, /* jmp relative */
7484 0, 0, 0, 0, /* replaced with offset to start of .plt. */
7486 /* Pad to the next 32-byte boundary with nop instructions. */
7487 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7488 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
7492 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
7494 #if (PLT_CIE_LENGTH != 20 \
7495 || PLT_FDE_LENGTH != 36 \
7496 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7497 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7498 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
7500 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7501 0, 0, 0, 0, /* CIE ID */
7502 1, /* CIE version */
7503 'z', 'R', 0, /* Augmentation string */
7504 1, /* Code alignment factor */
7505 0x7c, /* Data alignment factor: -4 */
7506 8, /* Return address column */
7507 1, /* Augmentation size */
7508 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
7509 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
7510 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
7511 DW_CFA_nop
, DW_CFA_nop
,
7513 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
7514 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
7515 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
7516 0, 0, 0, 0, /* .plt size goes here */
7517 0, /* Augmentation size */
7518 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
7519 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7520 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
7521 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7522 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7523 13, /* Block length */
7524 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
7525 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
7526 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7527 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
7528 DW_CFA_nop
, DW_CFA_nop
7531 static const struct elf_i386_lazy_plt_layout elf_i386_nacl_plt
=
7533 elf_i386_nacl_plt0_entry
, /* plt0_entry */
7534 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
7535 2, /* plt0_got1_offset */
7536 8, /* plt0_got2_offset */
7537 elf_i386_nacl_plt_entry
, /* plt_entry */
7538 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7539 2, /* plt_got_offset */
7540 33, /* plt_reloc_offset */
7541 38, /* plt_plt_offset */
7542 32, /* plt_lazy_offset */
7543 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
7544 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
7545 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
7546 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
7549 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
7551 0x90, /* plt0_pad_byte: nop insn */
7556 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
7558 /* Set the right machine number for a NaCl i386 ELF32 file. */
7559 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
7563 #undef elf_backend_arch_data
7564 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
7566 #undef elf_backend_object_p
7567 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
7568 #undef elf_backend_modify_segment_map
7569 #define elf_backend_modify_segment_map nacl_modify_segment_map
7570 #undef elf_backend_modify_program_headers
7571 #define elf_backend_modify_program_headers nacl_modify_program_headers
7572 #undef elf_backend_final_write_processing
7573 #define elf_backend_final_write_processing nacl_final_write_processing
7575 #include "elf32-target.h"
7577 /* Restore defaults. */
7578 #undef elf_backend_object_p
7579 #undef elf_backend_modify_segment_map
7580 #undef elf_backend_modify_program_headers
7581 #undef elf_backend_final_write_processing
7583 /* VxWorks support. */
7585 #undef TARGET_LITTLE_SYM
7586 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
7587 #undef TARGET_LITTLE_NAME
7588 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
7590 #undef ELF_MAXPAGESIZE
7591 #define ELF_MAXPAGESIZE 0x1000
7592 #undef elf_backend_plt_alignment
7593 #define elf_backend_plt_alignment 4
7595 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
7597 0x90, /* plt0_pad_byte */
7601 #undef elf_backend_arch_data
7602 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
7604 #undef elf_backend_relocs_compatible
7605 #undef elf_backend_add_symbol_hook
7606 #define elf_backend_add_symbol_hook \
7607 elf_vxworks_add_symbol_hook
7608 #undef elf_backend_link_output_symbol_hook
7609 #define elf_backend_link_output_symbol_hook \
7610 elf_vxworks_link_output_symbol_hook
7611 #undef elf_backend_emit_relocs
7612 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7613 #undef elf_backend_final_write_processing
7614 #define elf_backend_final_write_processing \
7615 elf_vxworks_final_write_processing
7616 #undef elf_backend_static_tls_alignment
7618 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
7620 #undef elf_backend_want_plt_sym
7621 #define elf_backend_want_plt_sym 1
7624 #define elf32_bed elf32_i386_vxworks_bed
7626 #include "elf32-target.h"