1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #include "elfxx-x86.h"
23 #include "elf-vxworks.h"
25 #include "opcode/i386.h"
27 /* 386 uses REL relocations instead of RELA. */
32 static reloc_howto_type elf_howto_table
[]=
34 HOWTO(R_386_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
35 bfd_elf_generic_reloc
, "R_386_NONE",
36 TRUE
, 0x00000000, 0x00000000, FALSE
),
37 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
38 bfd_elf_generic_reloc
, "R_386_32",
39 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
40 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
41 bfd_elf_generic_reloc
, "R_386_PC32",
42 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
43 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
44 bfd_elf_generic_reloc
, "R_386_GOT32",
45 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
46 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
47 bfd_elf_generic_reloc
, "R_386_PLT32",
48 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
49 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
50 bfd_elf_generic_reloc
, "R_386_COPY",
51 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
52 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
53 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
54 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
55 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
56 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
57 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
58 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
59 bfd_elf_generic_reloc
, "R_386_RELATIVE",
60 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
61 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_386_GOTOFF",
63 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
64 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
65 bfd_elf_generic_reloc
, "R_386_GOTPC",
66 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
68 /* We have a gap in the reloc numbers here.
69 R_386_standard counts the number up to this point, and
70 R_386_ext_offset is the value to subtract from a reloc type of
71 R_386_16 thru R_386_PC8 to form an index into this table. */
72 #define R_386_standard (R_386_GOTPC + 1)
73 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
75 /* These relocs are a GNU extension. */
76 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
78 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
79 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
80 bfd_elf_generic_reloc
, "R_386_TLS_IE",
81 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
82 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
84 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
85 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
86 bfd_elf_generic_reloc
, "R_386_TLS_LE",
87 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
88 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_386_TLS_GD",
90 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
91 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
92 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
93 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
94 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_386_16",
96 TRUE
, 0xffff, 0xffff, FALSE
),
97 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
98 bfd_elf_generic_reloc
, "R_386_PC16",
99 TRUE
, 0xffff, 0xffff, TRUE
),
100 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
101 bfd_elf_generic_reloc
, "R_386_8",
102 TRUE
, 0xff, 0xff, FALSE
),
103 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
104 bfd_elf_generic_reloc
, "R_386_PC8",
105 TRUE
, 0xff, 0xff, TRUE
),
107 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
108 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
109 /* These are common with Solaris TLS implementation. */
110 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
111 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
112 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
113 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
114 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
115 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
116 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
118 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
119 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
121 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
122 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
123 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
124 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
125 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
126 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
127 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
128 HOWTO(R_386_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
129 bfd_elf_generic_reloc
, "R_386_SIZE32",
130 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
131 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
132 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
133 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
135 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
137 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
139 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
140 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
141 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
142 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
143 HOWTO(R_386_GOT32X
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_GOT32X",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
148 #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
149 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
151 /* GNU extension to record C++ vtable hierarchy. */
152 HOWTO (R_386_GNU_VTINHERIT
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_dont
, /* complain_on_overflow */
159 NULL
, /* special_function */
160 "R_386_GNU_VTINHERIT", /* name */
161 FALSE
, /* partial_inplace */
164 FALSE
), /* pcrel_offset */
166 /* GNU extension to record C++ vtable member usage. */
167 HOWTO (R_386_GNU_VTENTRY
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE
, /* pc_relative */
173 complain_overflow_dont
, /* complain_on_overflow */
174 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
175 "R_386_GNU_VTENTRY", /* name */
176 FALSE
, /* partial_inplace */
179 FALSE
) /* pcrel_offset */
181 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
185 #ifdef DEBUG_GEN_RELOC
187 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
192 static reloc_howto_type
*
193 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
194 bfd_reloc_code_real_type code
)
199 TRACE ("BFD_RELOC_NONE");
200 return &elf_howto_table
[R_386_NONE
];
203 TRACE ("BFD_RELOC_32");
204 return &elf_howto_table
[R_386_32
];
207 TRACE ("BFD_RELOC_CTOR");
208 return &elf_howto_table
[R_386_32
];
210 case BFD_RELOC_32_PCREL
:
211 TRACE ("BFD_RELOC_PC32");
212 return &elf_howto_table
[R_386_PC32
];
214 case BFD_RELOC_386_GOT32
:
215 TRACE ("BFD_RELOC_386_GOT32");
216 return &elf_howto_table
[R_386_GOT32
];
218 case BFD_RELOC_386_PLT32
:
219 TRACE ("BFD_RELOC_386_PLT32");
220 return &elf_howto_table
[R_386_PLT32
];
222 case BFD_RELOC_386_COPY
:
223 TRACE ("BFD_RELOC_386_COPY");
224 return &elf_howto_table
[R_386_COPY
];
226 case BFD_RELOC_386_GLOB_DAT
:
227 TRACE ("BFD_RELOC_386_GLOB_DAT");
228 return &elf_howto_table
[R_386_GLOB_DAT
];
230 case BFD_RELOC_386_JUMP_SLOT
:
231 TRACE ("BFD_RELOC_386_JUMP_SLOT");
232 return &elf_howto_table
[R_386_JUMP_SLOT
];
234 case BFD_RELOC_386_RELATIVE
:
235 TRACE ("BFD_RELOC_386_RELATIVE");
236 return &elf_howto_table
[R_386_RELATIVE
];
238 case BFD_RELOC_386_GOTOFF
:
239 TRACE ("BFD_RELOC_386_GOTOFF");
240 return &elf_howto_table
[R_386_GOTOFF
];
242 case BFD_RELOC_386_GOTPC
:
243 TRACE ("BFD_RELOC_386_GOTPC");
244 return &elf_howto_table
[R_386_GOTPC
];
246 /* These relocs are a GNU extension. */
247 case BFD_RELOC_386_TLS_TPOFF
:
248 TRACE ("BFD_RELOC_386_TLS_TPOFF");
249 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
251 case BFD_RELOC_386_TLS_IE
:
252 TRACE ("BFD_RELOC_386_TLS_IE");
253 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
255 case BFD_RELOC_386_TLS_GOTIE
:
256 TRACE ("BFD_RELOC_386_TLS_GOTIE");
257 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
259 case BFD_RELOC_386_TLS_LE
:
260 TRACE ("BFD_RELOC_386_TLS_LE");
261 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
263 case BFD_RELOC_386_TLS_GD
:
264 TRACE ("BFD_RELOC_386_TLS_GD");
265 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
267 case BFD_RELOC_386_TLS_LDM
:
268 TRACE ("BFD_RELOC_386_TLS_LDM");
269 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
272 TRACE ("BFD_RELOC_16");
273 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
275 case BFD_RELOC_16_PCREL
:
276 TRACE ("BFD_RELOC_16_PCREL");
277 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
280 TRACE ("BFD_RELOC_8");
281 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
283 case BFD_RELOC_8_PCREL
:
284 TRACE ("BFD_RELOC_8_PCREL");
285 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
287 /* Common with Sun TLS implementation. */
288 case BFD_RELOC_386_TLS_LDO_32
:
289 TRACE ("BFD_RELOC_386_TLS_LDO_32");
290 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
292 case BFD_RELOC_386_TLS_IE_32
:
293 TRACE ("BFD_RELOC_386_TLS_IE_32");
294 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
296 case BFD_RELOC_386_TLS_LE_32
:
297 TRACE ("BFD_RELOC_386_TLS_LE_32");
298 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
300 case BFD_RELOC_386_TLS_DTPMOD32
:
301 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
302 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
304 case BFD_RELOC_386_TLS_DTPOFF32
:
305 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
306 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
308 case BFD_RELOC_386_TLS_TPOFF32
:
309 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
310 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
312 case BFD_RELOC_SIZE32
:
313 TRACE ("BFD_RELOC_SIZE32");
314 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
316 case BFD_RELOC_386_TLS_GOTDESC
:
317 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
318 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
320 case BFD_RELOC_386_TLS_DESC_CALL
:
321 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
322 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
324 case BFD_RELOC_386_TLS_DESC
:
325 TRACE ("BFD_RELOC_386_TLS_DESC");
326 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
328 case BFD_RELOC_386_IRELATIVE
:
329 TRACE ("BFD_RELOC_386_IRELATIVE");
330 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
332 case BFD_RELOC_386_GOT32X
:
333 TRACE ("BFD_RELOC_386_GOT32X");
334 return &elf_howto_table
[R_386_GOT32X
- R_386_tls_offset
];
336 case BFD_RELOC_VTABLE_INHERIT
:
337 TRACE ("BFD_RELOC_VTABLE_INHERIT");
338 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
340 case BFD_RELOC_VTABLE_ENTRY
:
341 TRACE ("BFD_RELOC_VTABLE_ENTRY");
342 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
352 static reloc_howto_type
*
353 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
358 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
359 if (elf_howto_table
[i
].name
!= NULL
360 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
361 return &elf_howto_table
[i
];
366 static reloc_howto_type
*
367 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
371 if ((indx
= r_type
) >= R_386_standard
372 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
373 >= R_386_ext
- R_386_standard
)
374 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
375 >= R_386_ext2
- R_386_ext
)
376 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
377 >= R_386_vt
- R_386_ext2
))
379 /* xgettext:c-format */
380 _bfd_error_handler (_("%B: invalid relocation type %d"),
384 /* PR 17512: file: 0f67f69d. */
385 if (elf_howto_table
[indx
].type
!= r_type
)
387 return &elf_howto_table
[indx
];
391 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
393 Elf_Internal_Rela
*dst
)
395 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
396 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
399 /* Return whether a symbol name implies a local label. The UnixWare
400 2.1 cc generates temporary symbols that start with .X, so we
401 recognize them here. FIXME: do other SVR4 compilers also use .X?.
402 If so, we should move the .X recognition into
403 _bfd_elf_is_local_label_name. */
406 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
408 if (name
[0] == '.' && name
[1] == 'X')
411 return _bfd_elf_is_local_label_name (abfd
, name
);
414 /* Support for core dump NOTE sections. */
417 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
422 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
424 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
430 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
433 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
437 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
441 switch (note
->descsz
)
446 case 144: /* Linux/i386 */
448 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
451 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
461 /* Make a ".reg/999" section. */
462 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
463 size
, note
->descpos
+ offset
);
467 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
469 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
471 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
476 elf_tdata (abfd
)->core
->program
477 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
478 elf_tdata (abfd
)->core
->command
479 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
483 switch (note
->descsz
)
488 case 124: /* Linux/i386 elf_prpsinfo. */
489 elf_tdata (abfd
)->core
->pid
490 = bfd_get_32 (abfd
, note
->descdata
+ 12);
491 elf_tdata (abfd
)->core
->program
492 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
493 elf_tdata (abfd
)->core
->command
494 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
498 /* Note that for some reason, a spurious space is tacked
499 onto the end of the args in some (at least one anyway)
500 implementations, so strip it off if it exists. */
502 char *command
= elf_tdata (abfd
)->core
->command
;
503 int n
= strlen (command
);
505 if (0 < n
&& command
[n
- 1] == ' ')
506 command
[n
- 1] = '\0';
512 /* Functions for the i386 ELF linker.
514 In order to gain some understanding of code in this file without
515 knowing all the intricate details of the linker, note the
518 Functions named elf_i386_* are called by external routines, other
519 functions are only called locally. elf_i386_* functions appear
520 in this file more or less in the order in which they are called
521 from external routines. eg. elf_i386_check_relocs is called
522 early in the link process, elf_i386_finish_dynamic_sections is
523 one of the last functions. */
525 /* The size in bytes of an entry in the lazy procedure linkage table. */
527 #define LAZY_PLT_ENTRY_SIZE 16
529 /* The size in bytes of an entry in the non-lazy procedure linkage
532 #define NON_LAZY_PLT_ENTRY_SIZE 8
534 /* The first entry in an absolute lazy procedure linkage table looks
535 like this. See the SVR4 ABI i386 supplement to see how this works.
536 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
538 static const bfd_byte elf_i386_lazy_plt0_entry
[12] =
540 0xff, 0x35, /* pushl contents of address */
541 0, 0, 0, 0, /* replaced with address of .got + 4. */
542 0xff, 0x25, /* jmp indirect */
543 0, 0, 0, 0 /* replaced with address of .got + 8. */
546 /* Subsequent entries in an absolute lazy procedure linkage table look
549 static const bfd_byte elf_i386_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
551 0xff, 0x25, /* jmp indirect */
552 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
553 0x68, /* pushl immediate */
554 0, 0, 0, 0, /* replaced with offset into relocation table. */
555 0xe9, /* jmp relative */
556 0, 0, 0, 0 /* replaced with offset to start of .plt. */
559 /* The first entry in a PIC lazy procedure linkage table look like
560 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
561 lazy_plt->plt0_pad_byte. */
563 static const bfd_byte elf_i386_pic_lazy_plt0_entry
[12] =
565 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
566 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
569 /* Subsequent entries in a PIC lazy procedure linkage table look like
572 static const bfd_byte elf_i386_pic_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
574 0xff, 0xa3, /* jmp *offset(%ebx) */
575 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
576 0x68, /* pushl immediate */
577 0, 0, 0, 0, /* replaced with offset into relocation table. */
578 0xe9, /* jmp relative */
579 0, 0, 0, 0 /* replaced with offset to start of .plt. */
582 /* Entries in the non-lazy procedure linkage table look like this. */
584 static const bfd_byte elf_i386_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
586 0xff, 0x25, /* jmp indirect */
587 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
588 0x66, 0x90 /* xchg %ax,%ax */
591 /* Entries in the PIC non-lazy procedure linkage table look like
594 static const bfd_byte elf_i386_pic_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
596 0xff, 0xa3, /* jmp *offset(%ebx) */
597 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
598 0x66, 0x90 /* xchg %ax,%ax */
601 /* The first entry in an absolute IBT-enabled lazy procedure linkage
602 table looks like this. */
604 static const bfd_byte elf_i386_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
606 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
607 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
608 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
611 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
612 table look like this. Subsequent entries for a PIC IBT-enabled lazy
613 procedure linkage table are the same. */
615 static const bfd_byte elf_i386_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
617 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
618 0x68, 0, 0, 0, 0, /* pushl immediate */
619 0xe9, 0, 0, 0, 0, /* jmp relative */
620 0x66, 0x90 /* xchg %ax,%ax */
623 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
626 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
628 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
629 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
630 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
633 /* Entries for branches with IBT-enabled in the absolute non-lazey
634 procedure linkage table look like this. They have the same size
635 as the lazy PLT entry. */
637 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
639 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
640 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
641 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
644 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
645 linkage table look like this. They have the same size as the lazy
648 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
650 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
651 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
652 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
655 /* .eh_frame covering the lazy .plt section. */
657 static const bfd_byte elf_i386_eh_frame_lazy_plt
[] =
659 #define PLT_CIE_LENGTH 20
660 #define PLT_FDE_LENGTH 36
661 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
662 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
663 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
664 0, 0, 0, 0, /* CIE ID */
666 'z', 'R', 0, /* Augmentation string */
667 1, /* Code alignment factor */
668 0x7c, /* Data alignment factor */
669 8, /* Return address column */
670 1, /* Augmentation size */
671 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
672 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
673 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
674 DW_CFA_nop
, DW_CFA_nop
,
676 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
677 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
678 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
679 0, 0, 0, 0, /* .plt size goes here */
680 0, /* Augmentation size */
681 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
682 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
683 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
684 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
685 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
686 11, /* Block length */
687 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
688 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
689 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
690 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
691 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
694 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
696 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt
[] =
698 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
699 0, 0, 0, 0, /* CIE ID */
701 'z', 'R', 0, /* Augmentation string */
702 1, /* Code alignment factor */
703 0x7c, /* Data alignment factor */
704 8, /* Return address column */
705 1, /* Augmentation size */
706 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
707 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
708 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
709 DW_CFA_nop
, DW_CFA_nop
,
711 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
712 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
713 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
714 0, 0, 0, 0, /* .plt size goes here */
715 0, /* Augmentation size */
716 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
717 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
718 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
719 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
720 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
721 11, /* Block length */
722 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
723 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
724 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
725 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
726 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
729 /* .eh_frame covering the non-lazy .plt section. */
731 static const bfd_byte elf_i386_eh_frame_non_lazy_plt
[] =
733 #define PLT_GOT_FDE_LENGTH 16
734 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
735 0, 0, 0, 0, /* CIE ID */
737 'z', 'R', 0, /* Augmentation string */
738 1, /* Code alignment factor */
739 0x7c, /* Data alignment factor */
740 8, /* Return address column */
741 1, /* Augmentation size */
742 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
743 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
744 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
745 DW_CFA_nop
, DW_CFA_nop
,
747 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
748 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
749 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
750 0, 0, 0, 0, /* non-lazy .plt size goes here */
751 0, /* Augmentation size */
752 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
755 /* These are the standard parameters. */
756 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt
=
758 elf_i386_lazy_plt0_entry
, /* plt0_entry */
759 sizeof (elf_i386_lazy_plt0_entry
), /* plt0_entry_size */
760 elf_i386_lazy_plt_entry
, /* plt_entry */
761 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
762 2, /* plt0_got1_offset */
763 8, /* plt0_got2_offset */
764 0, /* plt0_got2_insn_end */
765 2, /* plt_got_offset */
766 7, /* plt_reloc_offset */
767 12, /* plt_plt_offset */
768 0, /* plt_got_insn_size */
769 0, /* plt_plt_insn_end */
770 6, /* plt_lazy_offset */
771 elf_i386_pic_lazy_plt0_entry
, /* pic_plt0_entry */
772 elf_i386_pic_lazy_plt_entry
, /* pic_plt_entry */
773 elf_i386_eh_frame_lazy_plt
, /* eh_frame_plt */
774 sizeof (elf_i386_eh_frame_lazy_plt
) /* eh_frame_plt_size */
777 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt
=
779 elf_i386_non_lazy_plt_entry
, /* plt_entry */
780 elf_i386_pic_non_lazy_plt_entry
, /* pic_plt_entry */
781 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
782 2, /* plt_got_offset */
783 0, /* plt_got_insn_size */
784 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
785 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
788 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt
=
790 elf_i386_lazy_ibt_plt0_entry
, /* plt0_entry */
791 sizeof (elf_i386_lazy_ibt_plt0_entry
), /* plt0_entry_size */
792 elf_i386_lazy_ibt_plt_entry
, /* plt_entry */
793 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
794 2, /* plt0_got1_offset */
795 8, /* plt0_got2_offset */
796 0, /* plt0_got2_insn_end */
797 4+2, /* plt_got_offset */
798 4+1, /* plt_reloc_offset */
799 4+6, /* plt_plt_offset */
800 0, /* plt_got_insn_size */
801 0, /* plt_plt_insn_end */
802 0, /* plt_lazy_offset */
803 elf_i386_pic_lazy_ibt_plt0_entry
, /* pic_plt0_entry */
804 elf_i386_lazy_ibt_plt_entry
, /* pic_plt_entry */
805 elf_i386_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
806 sizeof (elf_i386_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
809 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt
=
811 elf_i386_non_lazy_ibt_plt_entry
, /* plt_entry */
812 elf_i386_pic_non_lazy_ibt_plt_entry
,/* pic_plt_entry */
813 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
814 4+2, /* plt_got_offset */
815 0, /* plt_got_insn_size */
816 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
817 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
821 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
822 for the PLTResolve stub and then for each PLT entry. */
823 #define PLTRESOLVE_RELOCS_SHLIB 0
824 #define PLTRESOLVE_RELOCS 2
825 #define PLT_NON_JUMP_SLOT_RELOCS 2
827 /* Architecture-specific backend data for i386. */
829 struct elf_i386_backend_data
831 /* Value used to fill the unused bytes of the first PLT entry. */
832 bfd_byte plt0_pad_byte
;
843 #define get_elf_i386_backend_data(abfd) \
844 ((const struct elf_i386_backend_data *) \
845 get_elf_backend_data (abfd)->arch_data)
847 /* These are the standard parameters. */
848 static const struct elf_i386_backend_data elf_i386_arch_bed
=
850 0, /* plt0_pad_byte */
854 #define elf_backend_arch_data &elf_i386_arch_bed
856 /* Values in tls_type of x86 ELF linker hash entry. */
858 #define GOT_TLS_IE_POS 5
859 #define GOT_TLS_IE_NEG 6
860 #define GOT_TLS_IE_BOTH 7
861 #define GOT_TLS_GDESC 8
862 #define GOT_TLS_GD_BOTH_P(type) \
863 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
864 #define GOT_TLS_GD_P(type) \
865 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
866 #define GOT_TLS_GDESC_P(type) \
867 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
868 #define GOT_TLS_GD_ANY_P(type) \
869 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
871 #define is_i386_elf(bfd) \
872 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
873 && elf_tdata (bfd) != NULL \
874 && elf_object_id (bfd) == I386_ELF_DATA)
877 elf_i386_mkobject (bfd
*abfd
)
879 return bfd_elf_allocate_object (abfd
,
880 sizeof (struct elf_x86_obj_tdata
),
884 #define elf_i386_compute_jump_table_size(htab) \
885 ((htab)->elf.srelplt->reloc_count * 4)
887 /* Return TRUE if the TLS access code sequence support transition
891 elf_i386_check_tls_transition (asection
*sec
,
893 Elf_Internal_Shdr
*symtab_hdr
,
894 struct elf_link_hash_entry
**sym_hashes
,
896 const Elf_Internal_Rela
*rel
,
897 const Elf_Internal_Rela
*relend
)
899 unsigned int val
, type
, reg
;
900 unsigned long r_symndx
;
901 struct elf_link_hash_entry
*h
;
904 bfd_boolean indirect_call
;
906 offset
= rel
->r_offset
;
911 if (offset
< 2 || (rel
+ 1) >= relend
)
914 indirect_call
= FALSE
;
915 call
= contents
+ offset
+ 4;
918 if (r_type
== R_386_TLS_GD
)
920 /* Check transition from GD access model. Only
921 leal foo@tlsgd(,%ebx,1), %eax
922 call ___tls_get_addr@PLT
924 leal foo@tlsgd(%ebx) %eax
925 call ___tls_get_addr@PLT
928 leal foo@tlsgd(%reg), %eax
929 call *___tls_get_addr@GOT(%reg)
930 which may be converted to
931 addr32 call ___tls_get_addr
932 can transit to different access model. */
933 if ((offset
+ 10) > sec
->size
934 || (type
!= 0x8d && type
!= 0x04))
939 /* leal foo@tlsgd(,%ebx,1), %eax
940 call ___tls_get_addr@PLT */
944 if (*(call
- 7) != 0x8d
952 leal foo@tlsgd(%ebx), %eax
953 call ___tls_get_addr@PLT
956 leal foo@tlsgd(%reg), %eax
957 call *___tls_get_addr@GOT(%reg)
958 which may be converted to
959 addr32 call ___tls_get_addr
961 %eax can't be used as the GOT base register since it
962 is used to pass parameter to ___tls_get_addr. */
964 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
967 indirect_call
= call
[0] == 0xff;
968 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
969 && !(call
[0] == 0x67 && call
[1] == 0xe8)
971 && (call
[1] & 0xf8) == 0x90
972 && (call
[1] & 0x7) == reg
))
978 /* Check transition from LD access model. Only
979 leal foo@tlsldm(%ebx), %eax
980 call ___tls_get_addr@PLT
982 leal foo@tlsldm(%reg), %eax
983 call *___tls_get_addr@GOT(%reg)
984 which may be converted to
985 addr32 call ___tls_get_addr
986 can transit to different access model. */
987 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
990 /* %eax can't be used as the GOT base register since it is
991 used to pass parameter to ___tls_get_addr. */
993 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
996 indirect_call
= call
[0] == 0xff;
997 if (!(reg
== 3 && call
[0] == 0xe8)
998 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1000 && (call
[1] & 0xf8) == 0x90
1001 && (call
[1] & 0x7) == reg
))
1005 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1006 if (r_symndx
< symtab_hdr
->sh_info
)
1009 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1011 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1013 else if (indirect_call
)
1014 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
1016 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1017 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
1020 /* Check transition from IE access model:
1021 movl foo@indntpoff(%rip), %eax
1022 movl foo@indntpoff(%rip), %reg
1023 addl foo@indntpoff(%rip), %reg
1026 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1029 /* Check "movl foo@tpoff(%rip), %eax" first. */
1030 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1037 /* Check movl|addl foo@tpoff(%rip), %reg. */
1038 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1039 return ((type
== 0x8b || type
== 0x03)
1040 && (val
& 0xc7) == 0x05);
1042 case R_386_TLS_GOTIE
:
1043 case R_386_TLS_IE_32
:
1044 /* Check transition from {IE_32,GOTIE} access model:
1045 subl foo@{tpoff,gontoff}(%reg1), %reg2
1046 movl foo@{tpoff,gontoff}(%reg1), %reg2
1047 addl foo@{tpoff,gontoff}(%reg1), %reg2
1050 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1053 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1054 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1057 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1058 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1060 case R_386_TLS_GOTDESC
:
1061 /* Check transition from GDesc access model:
1062 leal x@tlsdesc(%ebx), %eax
1064 Make sure it's a leal adding ebx to a 32-bit offset
1065 into any register, although it's probably almost always
1068 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1071 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1074 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1075 return (val
& 0xc7) == 0x83;
1077 case R_386_TLS_DESC_CALL
:
1078 /* Check transition from GDesc access model:
1079 call *x@tlsdesc(%eax)
1081 if (offset
+ 2 <= sec
->size
)
1083 /* Make sure that it's a call *x@tlsdesc(%eax). */
1084 call
= contents
+ offset
;
1085 return call
[0] == 0xff && call
[1] == 0x10;
1095 /* Return TRUE if the TLS access transition is OK or no transition
1096 will be performed. Update R_TYPE if there is a transition. */
1099 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1100 asection
*sec
, bfd_byte
*contents
,
1101 Elf_Internal_Shdr
*symtab_hdr
,
1102 struct elf_link_hash_entry
**sym_hashes
,
1103 unsigned int *r_type
, int tls_type
,
1104 const Elf_Internal_Rela
*rel
,
1105 const Elf_Internal_Rela
*relend
,
1106 struct elf_link_hash_entry
*h
,
1107 unsigned long r_symndx
,
1108 bfd_boolean from_relocate_section
)
1110 unsigned int from_type
= *r_type
;
1111 unsigned int to_type
= from_type
;
1112 bfd_boolean check
= TRUE
;
1114 /* Skip TLS transition for functions. */
1116 && (h
->type
== STT_FUNC
1117 || h
->type
== STT_GNU_IFUNC
))
1123 case R_386_TLS_GOTDESC
:
1124 case R_386_TLS_DESC_CALL
:
1125 case R_386_TLS_IE_32
:
1127 case R_386_TLS_GOTIE
:
1128 if (bfd_link_executable (info
))
1131 to_type
= R_386_TLS_LE_32
;
1132 else if (from_type
!= R_386_TLS_IE
1133 && from_type
!= R_386_TLS_GOTIE
)
1134 to_type
= R_386_TLS_IE_32
;
1137 /* When we are called from elf_i386_relocate_section, there may
1138 be additional transitions based on TLS_TYPE. */
1139 if (from_relocate_section
)
1141 unsigned int new_to_type
= to_type
;
1143 if (bfd_link_executable (info
)
1146 && (tls_type
& GOT_TLS_IE
))
1147 new_to_type
= R_386_TLS_LE_32
;
1149 if (to_type
== R_386_TLS_GD
1150 || to_type
== R_386_TLS_GOTDESC
1151 || to_type
== R_386_TLS_DESC_CALL
)
1153 if (tls_type
== GOT_TLS_IE_POS
)
1154 new_to_type
= R_386_TLS_GOTIE
;
1155 else if (tls_type
& GOT_TLS_IE
)
1156 new_to_type
= R_386_TLS_IE_32
;
1159 /* We checked the transition before when we were called from
1160 elf_i386_check_relocs. We only want to check the new
1161 transition which hasn't been checked before. */
1162 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1163 to_type
= new_to_type
;
1169 if (bfd_link_executable (info
))
1170 to_type
= R_386_TLS_LE_32
;
1177 /* Return TRUE if there is no transition. */
1178 if (from_type
== to_type
)
1181 /* Check if the transition can be performed. */
1183 && ! elf_i386_check_tls_transition (sec
, contents
,
1184 symtab_hdr
, sym_hashes
,
1185 from_type
, rel
, relend
))
1187 reloc_howto_type
*from
, *to
;
1190 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1191 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1194 name
= h
->root
.root
.string
;
1197 struct elf_x86_link_hash_table
*htab
;
1199 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1204 Elf_Internal_Sym
*isym
;
1206 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1208 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1213 /* xgettext:c-format */
1214 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1215 "in section `%A' failed"),
1216 abfd
, from
->name
, to
->name
, name
,
1217 rel
->r_offset
, sec
);
1218 bfd_set_error (bfd_error_bad_value
);
1226 /* With the local symbol, foo, we convert
1227 mov foo@GOT[(%reg1)], %reg2
1229 lea foo[@GOTOFF(%reg1)], %reg2
1231 call/jmp *foo@GOT[(%reg)]
1233 nop call foo/jmp foo nop
1234 When PIC is false, convert
1235 test %reg1, foo@GOT[(%reg2)]
1239 binop foo@GOT[(%reg1)], %reg2
1242 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1247 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1249 Elf_Internal_Rela
*irel
,
1250 struct elf_link_hash_entry
*h
,
1251 bfd_boolean
*converted
,
1252 struct bfd_link_info
*link_info
)
1254 struct elf_x86_link_hash_table
*htab
;
1255 unsigned int opcode
;
1257 bfd_boolean baseless
;
1258 Elf_Internal_Sym
*isym
;
1259 unsigned int addend
;
1263 bfd_boolean to_reloc_32
;
1264 unsigned int r_type
;
1265 unsigned int r_symndx
;
1266 bfd_vma roff
= irel
->r_offset
;
1271 /* Addend for R_386_GOT32X relocations must be 0. */
1272 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1276 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
1277 is_pic
= bfd_link_pic (link_info
);
1279 r_type
= ELF32_R_TYPE (irel
->r_info
);
1280 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1282 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1283 baseless
= (modrm
& 0xc7) == 0x5;
1285 if (baseless
&& is_pic
)
1287 /* For PIC, disallow R_386_GOT32X without a base register
1288 since we don't know what the GOT base is. */
1293 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1295 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1298 name
= h
->root
.root
.string
;
1301 /* xgettext:c-format */
1302 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1303 " register can not be used when making a shared object"),
1308 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1310 /* Convert to R_386_32 if PIC is false or there is no base
1312 to_reloc_32
= !is_pic
|| baseless
;
1314 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1318 if (opcode
== 0x0ff)
1319 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1320 goto convert_branch
;
1322 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1323 "test %reg1, foo@GOT(%reg2)" and
1324 "binop foo@GOT[(%reg1)], %reg2". */
1328 /* Undefined weak symbol is only bound locally in executable
1329 and its reference is resolved as 0. */
1330 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
, I386_ELF_DATA
, TRUE
,
1331 elf_x86_hash_entry (h
)))
1335 /* No direct branch to 0 for PIC. */
1339 goto convert_branch
;
1343 /* We can convert load of address 0 to R_386_32. */
1351 /* We have "call/jmp *foo@GOT[(%reg)]". */
1352 if ((h
->root
.type
== bfd_link_hash_defined
1353 || h
->root
.type
== bfd_link_hash_defweak
)
1354 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1356 /* The function is locally defined. */
1358 /* Convert R_386_GOT32X to R_386_PC32. */
1359 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1361 struct elf_x86_link_hash_entry
*eh
1362 = (struct elf_x86_link_hash_entry
*) h
;
1364 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1367 /* To support TLS optimization, always use addr32 prefix
1368 for "call *___tls_get_addr@GOT(%reg)". */
1369 if (eh
&& eh
->tls_get_addr
)
1372 nop_offset
= irel
->r_offset
- 2;
1376 nop
= link_info
->call_nop_byte
;
1377 if (link_info
->call_nop_as_suffix
)
1379 nop_offset
= roff
+ 3;
1380 irel
->r_offset
-= 1;
1383 nop_offset
= roff
- 2;
1388 /* Convert to "jmp foo nop". */
1391 nop_offset
= roff
+ 3;
1392 irel
->r_offset
-= 1;
1395 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1396 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1397 /* When converting to PC-relative relocation, we
1398 need to adjust addend by -4. */
1399 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1400 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1407 /* We have "mov foo@GOT[(%re1g)], %reg2",
1408 "test %reg1, foo@GOT(%reg2)" and
1409 "binop foo@GOT[(%reg1)], %reg2".
1411 Avoid optimizing _DYNAMIC since ld.so may use its
1412 link-time address. */
1413 if (h
== htab
->elf
.hdynamic
)
1416 /* def_regular is set by an assignment in a linker script in
1417 bfd_elf_record_link_assignment. start_stop is set on
1418 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1421 || h
->root
.type
== bfd_link_hash_defined
1422 || h
->root
.type
== bfd_link_hash_defweak
)
1423 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)))
1430 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1431 "mov $foo, %reg2" with R_386_32. */
1433 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1434 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1439 /* Convert "mov foo@GOT(%reg1), %reg2" to
1440 "lea foo@GOTOFF(%reg1), %reg2". */
1441 r_type
= R_386_GOTOFF
;
1447 /* Only R_386_32 is supported. */
1453 /* Convert "test %reg1, foo@GOT(%reg2)" to
1454 "test $foo, %reg1". */
1455 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1460 /* Convert "binop foo@GOT(%reg1), %reg2" to
1461 "binop $foo, %reg2". */
1463 | (modrm
& 0x38) >> 3
1467 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1471 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1472 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1481 /* Rename some of the generic section flags to better document how they
1483 #define need_convert_load sec_flg0
1484 #define check_relocs_failed sec_flg1
1486 /* Look through the relocs for a section during the first phase, and
1487 calculate needed space in the global offset table, procedure linkage
1488 table, and dynamic reloc sections. */
1491 elf_i386_check_relocs (bfd
*abfd
,
1492 struct bfd_link_info
*info
,
1494 const Elf_Internal_Rela
*relocs
)
1496 struct elf_x86_link_hash_table
*htab
;
1497 Elf_Internal_Shdr
*symtab_hdr
;
1498 struct elf_link_hash_entry
**sym_hashes
;
1499 const Elf_Internal_Rela
*rel
;
1500 const Elf_Internal_Rela
*rel_end
;
1504 if (bfd_link_relocatable (info
))
1507 /* Don't do anything special with non-loaded, non-alloced sections.
1508 In particular, any relocs in such sections should not affect GOT
1509 and PLT reference counting (ie. we don't allow them to create GOT
1510 or PLT entries), there's no possibility or desire to optimize TLS
1511 relocs, and there's not much point in propagating relocs to shared
1512 libs that the dynamic linker won't relocate. */
1513 if ((sec
->flags
& SEC_ALLOC
) == 0)
1516 BFD_ASSERT (is_i386_elf (abfd
));
1518 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1521 sec
->check_relocs_failed
= 1;
1525 /* Get the section contents. */
1526 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1527 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1528 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1530 sec
->check_relocs_failed
= 1;
1534 symtab_hdr
= &elf_symtab_hdr (abfd
);
1535 sym_hashes
= elf_sym_hashes (abfd
);
1539 rel_end
= relocs
+ sec
->reloc_count
;
1540 for (rel
= relocs
; rel
< rel_end
; rel
++)
1542 unsigned int r_type
;
1543 unsigned int r_symndx
;
1544 struct elf_link_hash_entry
*h
;
1545 struct elf_x86_link_hash_entry
*eh
;
1546 Elf_Internal_Sym
*isym
;
1548 bfd_boolean size_reloc
;
1550 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1551 r_type
= ELF32_R_TYPE (rel
->r_info
);
1553 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1555 /* xgettext:c-format */
1556 _bfd_error_handler (_("%B: bad symbol index: %d"),
1561 if (r_symndx
< symtab_hdr
->sh_info
)
1563 /* A local symbol. */
1564 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1569 /* Check relocation against local STT_GNU_IFUNC symbol. */
1570 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1572 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1576 /* Fake a STT_GNU_IFUNC symbol. */
1577 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1579 h
->type
= STT_GNU_IFUNC
;
1582 h
->forced_local
= 1;
1583 h
->root
.type
= bfd_link_hash_defined
;
1591 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1592 while (h
->root
.type
== bfd_link_hash_indirect
1593 || h
->root
.type
== bfd_link_hash_warning
)
1594 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1597 eh
= (struct elf_x86_link_hash_entry
*) h
;
1600 if (r_type
== R_386_GOTOFF
)
1603 /* It is referenced by a non-shared object. */
1605 h
->root
.non_ir_ref_regular
= 1;
1607 if (h
->type
== STT_GNU_IFUNC
)
1608 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1609 |= elf_gnu_symbol_ifunc
;
1612 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1613 symtab_hdr
, sym_hashes
,
1614 &r_type
, GOT_UNKNOWN
,
1615 rel
, rel_end
, h
, r_symndx
, FALSE
))
1621 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1625 /* This symbol requires a procedure linkage table entry. We
1626 actually build the entry in adjust_dynamic_symbol,
1627 because this might be a case of linking PIC code which is
1628 never referenced by a dynamic object, in which case we
1629 don't need to generate a procedure linkage table entry
1632 /* If this is a local symbol, we resolve it directly without
1633 creating a procedure linkage table entry. */
1637 eh
->has_got_reloc
= 1;
1639 h
->plt
.refcount
+= 1;
1646 case R_386_TLS_IE_32
:
1648 case R_386_TLS_GOTIE
:
1649 if (!bfd_link_executable (info
))
1650 info
->flags
|= DF_STATIC_TLS
;
1656 case R_386_TLS_GOTDESC
:
1657 case R_386_TLS_DESC_CALL
:
1658 /* This symbol requires a global offset table entry. */
1660 int tls_type
, old_tls_type
;
1667 tls_type
= GOT_NORMAL
;
1669 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1670 case R_386_TLS_GOTDESC
:
1671 case R_386_TLS_DESC_CALL
:
1672 tls_type
= GOT_TLS_GDESC
; break;
1673 case R_386_TLS_IE_32
:
1674 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1675 tls_type
= GOT_TLS_IE_NEG
;
1677 /* If this is a GD->IE transition, we may use either of
1678 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1679 tls_type
= GOT_TLS_IE
;
1682 case R_386_TLS_GOTIE
:
1683 tls_type
= GOT_TLS_IE_POS
; break;
1688 h
->got
.refcount
+= 1;
1689 old_tls_type
= elf_x86_hash_entry (h
)->tls_type
;
1693 bfd_signed_vma
*local_got_refcounts
;
1695 /* This is a global offset table entry for a local symbol. */
1696 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1697 if (local_got_refcounts
== NULL
)
1701 size
= symtab_hdr
->sh_info
;
1702 size
*= (sizeof (bfd_signed_vma
)
1703 + sizeof (bfd_vma
) + sizeof(char));
1704 local_got_refcounts
= (bfd_signed_vma
*)
1705 bfd_zalloc (abfd
, size
);
1706 if (local_got_refcounts
== NULL
)
1708 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1709 elf_x86_local_tlsdesc_gotent (abfd
)
1710 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1711 elf_x86_local_got_tls_type (abfd
)
1712 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1714 local_got_refcounts
[r_symndx
] += 1;
1715 old_tls_type
= elf_x86_local_got_tls_type (abfd
) [r_symndx
];
1718 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1719 tls_type
|= old_tls_type
;
1720 /* If a TLS symbol is accessed using IE at least once,
1721 there is no point to use dynamic model for it. */
1722 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1723 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1724 || (tls_type
& GOT_TLS_IE
) == 0))
1726 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1727 tls_type
= old_tls_type
;
1728 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1729 && GOT_TLS_GD_ANY_P (tls_type
))
1730 tls_type
|= old_tls_type
;
1734 name
= h
->root
.root
.string
;
1736 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1739 /* xgettext:c-format */
1740 (_("%B: `%s' accessed both as normal and "
1741 "thread local symbol"),
1743 bfd_set_error (bfd_error_bad_value
);
1748 if (old_tls_type
!= tls_type
)
1751 elf_x86_hash_entry (h
)->tls_type
= tls_type
;
1753 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1761 if (r_type
!= R_386_TLS_IE
)
1764 eh
->has_got_reloc
= 1;
1769 case R_386_TLS_LE_32
:
1772 eh
->has_got_reloc
= 1;
1773 if (bfd_link_executable (info
))
1775 info
->flags
|= DF_STATIC_TLS
;
1780 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
1781 eh
->has_non_got_reloc
= 1;
1783 /* We are called after all symbols have been resolved. Only
1784 relocation against STT_GNU_IFUNC symbol must go through
1787 && (bfd_link_executable (info
)
1788 || h
->type
== STT_GNU_IFUNC
))
1790 /* If this reloc is in a read-only section, we might
1791 need a copy reloc. We can't check reliably at this
1792 stage whether the section is read-only, as input
1793 sections have not yet been mapped to output sections.
1794 Tentatively set the flag for now, and correct in
1795 adjust_dynamic_symbol. */
1798 /* We may need a .plt entry if the symbol is a function
1799 defined in a shared lib or is a STT_GNU_IFUNC function
1800 referenced from the code or read-only section. */
1802 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
1803 h
->plt
.refcount
+= 1;
1805 if (r_type
== R_386_PC32
)
1807 /* Since something like ".long foo - ." may be used
1808 as pointer, make sure that PLT is used if foo is
1809 a function defined in a shared library. */
1810 if ((sec
->flags
& SEC_CODE
) == 0)
1811 h
->pointer_equality_needed
= 1;
1812 else if (h
->type
== STT_GNU_IFUNC
1813 && bfd_link_pic (info
))
1816 /* xgettext:c-format */
1817 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
1818 abfd
, h
->root
.root
.string
);
1819 bfd_set_error (bfd_error_bad_value
);
1825 h
->pointer_equality_needed
= 1;
1826 /* R_386_32 can be resolved at run-time. */
1827 if (r_type
== R_386_32
1828 && (sec
->flags
& SEC_READONLY
) == 0)
1829 eh
->func_pointer_refcount
+= 1;
1835 /* If we are creating a shared library, and this is a reloc
1836 against a global symbol, or a non PC relative reloc
1837 against a local symbol, then we need to copy the reloc
1838 into the shared library. However, if we are linking with
1839 -Bsymbolic, we do not need to copy a reloc against a
1840 global symbol which is defined in an object we are
1841 including in the link (i.e., DEF_REGULAR is set). At
1842 this point we have not seen all the input files, so it is
1843 possible that DEF_REGULAR is not set now but will be set
1844 later (it is never cleared). In case of a weak definition,
1845 DEF_REGULAR may be cleared later by a strong definition in
1846 a shared library. We account for that possibility below by
1847 storing information in the relocs_copied field of the hash
1848 table entry. A similar situation occurs when creating
1849 shared libraries and symbol visibility changes render the
1852 If on the other hand, we are creating an executable, we
1853 may need to keep relocations for symbols satisfied by a
1854 dynamic library if we manage to avoid copy relocs for the
1857 Generate dynamic pointer relocation against STT_GNU_IFUNC
1858 symbol in the non-code section. */
1859 if ((bfd_link_pic (info
)
1860 && (r_type
!= R_386_PC32
1862 && (! (bfd_link_pie (info
)
1863 || SYMBOLIC_BIND (info
, h
))
1864 || h
->root
.type
== bfd_link_hash_defweak
1865 || !h
->def_regular
))))
1867 && h
->type
== STT_GNU_IFUNC
1868 && r_type
== R_386_32
1869 && (sec
->flags
& SEC_CODE
) == 0)
1870 || (ELIMINATE_COPY_RELOCS
1871 && !bfd_link_pic (info
)
1873 && (h
->root
.type
== bfd_link_hash_defweak
1874 || !h
->def_regular
)))
1876 struct elf_dyn_relocs
*p
;
1877 struct elf_dyn_relocs
**head
;
1879 /* We must copy these reloc types into the output file.
1880 Create a reloc section in dynobj and make room for
1884 sreloc
= _bfd_elf_make_dynamic_reloc_section
1885 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1891 /* If this is a global symbol, we count the number of
1892 relocations we need for this symbol. */
1895 head
= &eh
->dyn_relocs
;
1899 /* Track dynamic relocs needed for local syms too.
1900 We really need local syms available to do this
1905 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1910 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1914 vpp
= &elf_section_data (s
)->local_dynrel
;
1915 head
= (struct elf_dyn_relocs
**)vpp
;
1919 if (p
== NULL
|| p
->sec
!= sec
)
1921 bfd_size_type amt
= sizeof *p
;
1922 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1934 /* Count size relocation as PC-relative relocation. */
1935 if (r_type
== R_386_PC32
|| size_reloc
)
1940 /* This relocation describes the C++ object vtable hierarchy.
1941 Reconstruct it for later use during GC. */
1942 case R_386_GNU_VTINHERIT
:
1943 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1947 /* This relocation describes which C++ vtable entries are actually
1948 used. Record for later use during GC. */
1949 case R_386_GNU_VTENTRY
:
1950 BFD_ASSERT (h
!= NULL
);
1952 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1960 if (r_type
== R_386_GOT32X
1961 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1962 sec
->need_convert_load
= 1;
1965 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1967 if (!info
->keep_memory
)
1971 /* Cache the section contents for elf_link_input_bfd. */
1972 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1979 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1981 sec
->check_relocs_failed
= 1;
1985 /* Return the section that should be marked against GC for a given
1989 elf_i386_gc_mark_hook (asection
*sec
,
1990 struct bfd_link_info
*info
,
1991 Elf_Internal_Rela
*rel
,
1992 struct elf_link_hash_entry
*h
,
1993 Elf_Internal_Sym
*sym
)
1996 switch (ELF32_R_TYPE (rel
->r_info
))
1998 case R_386_GNU_VTINHERIT
:
1999 case R_386_GNU_VTENTRY
:
2003 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2006 /* Adjust a symbol defined by a dynamic object and referenced by a
2007 regular object. The current definition is in some section of the
2008 dynamic object, but we're not including those sections. We have to
2009 change the definition to something the rest of the link can
2013 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2014 struct elf_link_hash_entry
*h
)
2016 struct elf_x86_link_hash_table
*htab
;
2018 struct elf_x86_link_hash_entry
*eh
;
2019 struct elf_dyn_relocs
*p
;
2021 /* STT_GNU_IFUNC symbol must go through PLT. */
2022 if (h
->type
== STT_GNU_IFUNC
)
2024 /* All local STT_GNU_IFUNC references must be treate as local
2025 calls via local PLT. */
2027 && SYMBOL_CALLS_LOCAL (info
, h
))
2029 bfd_size_type pc_count
= 0, count
= 0;
2030 struct elf_dyn_relocs
**pp
;
2032 eh
= (struct elf_x86_link_hash_entry
*) h
;
2033 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2035 pc_count
+= p
->pc_count
;
2036 p
->count
-= p
->pc_count
;
2045 if (pc_count
|| count
)
2050 /* Increment PLT reference count only for PC-relative
2053 if (h
->plt
.refcount
<= 0)
2054 h
->plt
.refcount
= 1;
2056 h
->plt
.refcount
+= 1;
2061 if (h
->plt
.refcount
<= 0)
2063 h
->plt
.offset
= (bfd_vma
) -1;
2069 /* If this is a function, put it in the procedure linkage table. We
2070 will fill in the contents of the procedure linkage table later,
2071 when we know the address of the .got section. */
2072 if (h
->type
== STT_FUNC
2075 if (h
->plt
.refcount
<= 0
2076 || SYMBOL_CALLS_LOCAL (info
, h
)
2077 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2078 && h
->root
.type
== bfd_link_hash_undefweak
))
2080 /* This case can occur if we saw a PLT32 reloc in an input
2081 file, but the symbol was never referred to by a dynamic
2082 object, or if all references were garbage collected. In
2083 such a case, we don't actually need to build a procedure
2084 linkage table, and we can just do a PC32 reloc instead. */
2085 h
->plt
.offset
= (bfd_vma
) -1;
2092 /* It's possible that we incorrectly decided a .plt reloc was
2093 needed for an R_386_PC32 reloc to a non-function sym in
2094 check_relocs. We can't decide accurately between function and
2095 non-function syms in check-relocs; Objects loaded later in
2096 the link may change h->type. So fix it now. */
2097 h
->plt
.offset
= (bfd_vma
) -1;
2099 eh
= (struct elf_x86_link_hash_entry
*) h
;
2101 /* If this is a weak symbol, and there is a real definition, the
2102 processor independent code will have arranged for us to see the
2103 real definition first, and we can just use the same value. */
2104 if (h
->u
.weakdef
!= NULL
)
2106 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2107 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2108 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2109 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2110 if (ELIMINATE_COPY_RELOCS
2111 || info
->nocopyreloc
2112 || SYMBOL_NO_COPYRELOC (info
, eh
))
2113 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2117 /* This is a reference to a symbol defined by a dynamic object which
2118 is not a function. */
2120 /* If we are creating a shared library, we must presume that the
2121 only references to the symbol are via the global offset table.
2122 For such cases we need not do anything here; the relocations will
2123 be handled correctly by relocate_section. */
2124 if (!bfd_link_executable (info
))
2127 /* If there are no references to this symbol that do not use the
2128 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2130 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2133 /* If -z nocopyreloc was given, we won't generate them either. */
2134 if (info
->nocopyreloc
|| SYMBOL_NO_COPYRELOC (info
, eh
))
2140 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2144 /* If there aren't any dynamic relocs in read-only sections nor
2145 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2146 avoid the copy reloc. This doesn't work on VxWorks, where we can
2147 not have dynamic relocations (other than copy and jump slot
2148 relocations) in an executable. */
2149 if (ELIMINATE_COPY_RELOCS
2151 && get_elf_i386_backend_data (info
->output_bfd
)->os
!= is_vxworks
)
2153 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2155 s
= p
->sec
->output_section
;
2156 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2167 /* We must allocate the symbol in our .dynbss section, which will
2168 become part of the .bss section of the executable. There will be
2169 an entry for this symbol in the .dynsym section. The dynamic
2170 object will contain position independent code, so all references
2171 from the dynamic object to this symbol will go through the global
2172 offset table. The dynamic linker will use the .dynsym entry to
2173 determine the address it must put in the global offset table, so
2174 both the dynamic object and the regular object will refer to the
2175 same memory location for the variable. */
2177 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2178 copy the initial value out of the dynamic object and into the
2179 runtime process image. */
2180 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2182 s
= htab
->elf
.sdynrelro
;
2183 srel
= htab
->elf
.sreldynrelro
;
2187 s
= htab
->elf
.sdynbss
;
2188 srel
= htab
->elf
.srelbss
;
2190 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2192 srel
->size
+= sizeof (Elf32_External_Rel
);
2196 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2199 /* Allocate space in .plt, .got and associated reloc sections for
2203 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2205 struct bfd_link_info
*info
;
2206 struct elf_x86_link_hash_table
*htab
;
2207 struct elf_x86_link_hash_entry
*eh
;
2208 struct elf_dyn_relocs
*p
;
2209 unsigned plt_entry_size
;
2210 bfd_boolean resolved_to_zero
;
2211 const struct elf_i386_backend_data
*bed
;
2213 if (h
->root
.type
== bfd_link_hash_indirect
)
2216 eh
= (struct elf_x86_link_hash_entry
*) h
;
2218 info
= (struct bfd_link_info
*) inf
;
2219 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2223 bed
= get_elf_i386_backend_data (info
->output_bfd
);
2225 plt_entry_size
= htab
->plt
.plt_entry_size
;
2227 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2232 /* Clear the reference count of function pointer relocations if
2233 symbol isn't a normal function. */
2234 if (h
->type
!= STT_FUNC
)
2235 eh
->func_pointer_refcount
= 0;
2237 /* We can't use the GOT PLT if pointer equality is needed since
2238 finish_dynamic_symbol won't clear symbol value and the dynamic
2239 linker won't update the GOT slot. We will get into an infinite
2240 loop at run-time. */
2241 if (htab
->plt_got
!= NULL
2242 && h
->type
!= STT_GNU_IFUNC
2243 && !h
->pointer_equality_needed
2244 && h
->plt
.refcount
> 0
2245 && h
->got
.refcount
> 0)
2247 /* Don't use the regular PLT if there are both GOT and GOTPLT
2249 h
->plt
.offset
= (bfd_vma
) -1;
2251 /* Use the GOT PLT. */
2252 eh
->plt_got
.refcount
= 1;
2255 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2256 here if it is defined and referenced in a non-shared object. */
2257 if (h
->type
== STT_GNU_IFUNC
2260 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2261 &htab
->readonly_dynrelocs_against_ifunc
,
2267 asection
*s
= htab
->plt_second
;
2268 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
2270 /* Use the second PLT section if it is created. */
2271 eh
->plt_second
.offset
= s
->size
;
2273 /* Make room for this entry in the second PLT section. */
2274 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2282 /* Don't create the PLT entry if there are only function pointer
2283 relocations which can be resolved at run-time. */
2284 else if (htab
->elf
.dynamic_sections_created
2285 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2286 || eh
->plt_got
.refcount
> 0))
2288 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
2290 /* Clear the reference count of function pointer relocations
2292 eh
->func_pointer_refcount
= 0;
2294 /* Make sure this symbol is output as a dynamic symbol.
2295 Undefined weak syms won't yet be marked as dynamic. */
2296 if (h
->dynindx
== -1
2298 && !resolved_to_zero
2299 && h
->root
.type
== bfd_link_hash_undefweak
)
2301 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2305 if (bfd_link_pic (info
)
2306 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2308 asection
*s
= htab
->elf
.splt
;
2309 asection
*second_s
= htab
->plt_second
;
2310 asection
*got_s
= htab
->plt_got
;
2312 /* If this is the first .plt entry, make room for the special
2313 first entry. The .plt section is used by prelink to undo
2314 prelinking for dynamic relocations. */
2316 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
2319 eh
->plt_got
.offset
= got_s
->size
;
2322 h
->plt
.offset
= s
->size
;
2324 eh
->plt_second
.offset
= second_s
->size
;
2327 /* If this symbol is not defined in a regular file, and we are
2328 not generating a shared library, then set the symbol to this
2329 location in the .plt. This is required to make function
2330 pointers compare as equal between the normal executable and
2331 the shared library. */
2332 if (! bfd_link_pic (info
)
2337 /* We need to make a call to the entry of the GOT PLT
2338 instead of regular PLT entry. */
2339 h
->root
.u
.def
.section
= got_s
;
2340 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2346 /* We need to make a call to the entry of the
2347 second PLT instead of regular PLT entry. */
2348 h
->root
.u
.def
.section
= second_s
;
2349 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
2353 h
->root
.u
.def
.section
= s
;
2354 h
->root
.u
.def
.value
= h
->plt
.offset
;
2359 /* Make room for this entry. */
2361 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2364 s
->size
+= plt_entry_size
;
2366 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2368 /* We also need to make an entry in the .got.plt section,
2369 which will be placed in the .got section by the linker
2371 htab
->elf
.sgotplt
->size
+= 4;
2373 /* There should be no PLT relocation against resolved
2374 undefined weak symbol in executable. */
2375 if (!resolved_to_zero
)
2377 /* We also need to make an entry in the .rel.plt
2379 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2380 htab
->elf
.srelplt
->reloc_count
++;
2384 if (bed
->os
== is_vxworks
&& !bfd_link_pic (info
))
2386 /* VxWorks has a second set of relocations for each PLT entry
2387 in executables. They go in a separate relocation section,
2388 which is processed by the kernel loader. */
2390 /* There are two relocations for the initial PLT entry: an
2391 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2392 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2394 asection
*srelplt2
= htab
->srelplt2
;
2395 if (h
->plt
.offset
== plt_entry_size
)
2396 srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2398 /* There are two extra relocations for each subsequent PLT entry:
2399 an R_386_32 relocation for the GOT entry, and an R_386_32
2400 relocation for the PLT entry. */
2402 srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2407 eh
->plt_got
.offset
= (bfd_vma
) -1;
2408 h
->plt
.offset
= (bfd_vma
) -1;
2414 eh
->plt_got
.offset
= (bfd_vma
) -1;
2415 h
->plt
.offset
= (bfd_vma
) -1;
2419 eh
->tlsdesc_got
= (bfd_vma
) -1;
2421 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2422 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2423 if (h
->got
.refcount
> 0
2424 && bfd_link_executable (info
)
2426 && (elf_x86_hash_entry (h
)->tls_type
& GOT_TLS_IE
))
2427 h
->got
.offset
= (bfd_vma
) -1;
2428 else if (h
->got
.refcount
> 0)
2432 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
2434 /* Make sure this symbol is output as a dynamic symbol.
2435 Undefined weak syms won't yet be marked as dynamic. */
2436 if (h
->dynindx
== -1
2438 && !resolved_to_zero
2439 && h
->root
.type
== bfd_link_hash_undefweak
)
2441 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2446 if (GOT_TLS_GDESC_P (tls_type
))
2448 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2449 - elf_i386_compute_jump_table_size (htab
);
2450 htab
->elf
.sgotplt
->size
+= 8;
2451 h
->got
.offset
= (bfd_vma
) -2;
2453 if (! GOT_TLS_GDESC_P (tls_type
)
2454 || GOT_TLS_GD_P (tls_type
))
2456 h
->got
.offset
= s
->size
;
2458 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2459 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2462 dyn
= htab
->elf
.dynamic_sections_created
;
2463 /* R_386_TLS_IE_32 needs one dynamic relocation,
2464 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2465 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2466 need two), R_386_TLS_GD needs one if local symbol and two if
2467 global. No dynamic relocation against resolved undefined weak
2468 symbol in executable. */
2469 if (tls_type
== GOT_TLS_IE_BOTH
)
2470 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2471 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2472 || (tls_type
& GOT_TLS_IE
))
2473 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2474 else if (GOT_TLS_GD_P (tls_type
))
2475 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2476 else if (! GOT_TLS_GDESC_P (tls_type
)
2477 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2478 && !resolved_to_zero
)
2479 || h
->root
.type
!= bfd_link_hash_undefweak
)
2480 && (bfd_link_pic (info
)
2481 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2482 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2483 if (GOT_TLS_GDESC_P (tls_type
))
2484 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2487 h
->got
.offset
= (bfd_vma
) -1;
2489 if (eh
->dyn_relocs
== NULL
)
2492 /* In the shared -Bsymbolic case, discard space allocated for
2493 dynamic pc-relative relocs against symbols which turn out to be
2494 defined in regular objects. For the normal shared case, discard
2495 space for pc-relative relocs that have become local due to symbol
2496 visibility changes. */
2498 if (bfd_link_pic (info
))
2500 /* The only reloc that uses pc_count is R_386_PC32, which will
2501 appear on a call or on something like ".long foo - .". We
2502 want calls to protected symbols to resolve directly to the
2503 function rather than going via the plt. If people want
2504 function pointer comparisons to work as expected then they
2505 should avoid writing assembly like ".long foo - .". */
2506 if (SYMBOL_CALLS_LOCAL (info
, h
))
2508 struct elf_dyn_relocs
**pp
;
2510 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2512 p
->count
-= p
->pc_count
;
2521 if (bed
->os
== is_vxworks
)
2523 struct elf_dyn_relocs
**pp
;
2524 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2526 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2533 /* Also discard relocs on undefined weak syms with non-default
2534 visibility or in PIE. */
2535 if (eh
->dyn_relocs
!= NULL
2536 && h
->root
.type
== bfd_link_hash_undefweak
)
2538 /* Undefined weak symbol is never bound locally in shared
2540 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2541 || resolved_to_zero
)
2545 /* Keep dynamic non-GOT/non-PLT relocation so that we
2546 can branch to 0 without PLT. */
2547 struct elf_dyn_relocs
**pp
;
2549 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2550 if (p
->pc_count
== 0)
2554 /* Remove non-R_386_PC32 relocation. */
2555 p
->count
= p
->pc_count
;
2559 if (eh
->dyn_relocs
!= NULL
)
2561 /* Make sure undefined weak symbols are output
2562 as dynamic symbols in PIEs for dynamic non-GOT
2563 non-PLT reloations. */
2564 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2569 eh
->dyn_relocs
= NULL
;
2571 else if (h
->dynindx
== -1
2572 && !h
->forced_local
)
2574 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2579 else if (ELIMINATE_COPY_RELOCS
)
2581 /* For the non-shared case, discard space for relocs against
2582 symbols which turn out to need copy relocs or are not
2583 dynamic. Keep dynamic relocations for run-time function
2584 pointer initialization. */
2586 if ((!h
->non_got_ref
2587 || eh
->func_pointer_refcount
> 0
2588 || (h
->root
.type
== bfd_link_hash_undefweak
2589 && !resolved_to_zero
))
2592 || (htab
->elf
.dynamic_sections_created
2593 && (h
->root
.type
== bfd_link_hash_undefweak
2594 || h
->root
.type
== bfd_link_hash_undefined
))))
2596 /* Make sure this symbol is output as a dynamic symbol.
2597 Undefined weak syms won't yet be marked as dynamic. */
2598 if (h
->dynindx
== -1
2600 && !resolved_to_zero
2601 && h
->root
.type
== bfd_link_hash_undefweak
)
2603 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2607 /* If that succeeded, we know we'll be keeping all the
2609 if (h
->dynindx
!= -1)
2613 eh
->dyn_relocs
= NULL
;
2614 eh
->func_pointer_refcount
= 0;
2619 /* Finally, allocate space. */
2620 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2624 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2626 BFD_ASSERT (sreloc
!= NULL
);
2627 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2633 /* Allocate space in .plt, .got and associated reloc sections for
2634 local dynamic relocs. */
2637 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2639 struct elf_link_hash_entry
*h
2640 = (struct elf_link_hash_entry
*) *slot
;
2642 if (h
->type
!= STT_GNU_IFUNC
2646 || h
->root
.type
!= bfd_link_hash_defined
)
2649 return elf_i386_allocate_dynrelocs (h
, inf
);
2652 /* Convert load via the GOT slot to load immediate. */
2655 elf_i386_convert_load (bfd
*abfd
, asection
*sec
,
2656 struct bfd_link_info
*link_info
)
2658 struct elf_x86_link_hash_table
*htab
;
2659 Elf_Internal_Shdr
*symtab_hdr
;
2660 Elf_Internal_Rela
*internal_relocs
;
2661 Elf_Internal_Rela
*irel
, *irelend
;
2663 bfd_boolean changed
;
2664 bfd_signed_vma
*local_got_refcounts
;
2666 /* Don't even try to convert non-ELF outputs. */
2667 if (!is_elf_hash_table (link_info
->hash
))
2670 /* Nothing to do if there is no need or no output. */
2671 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
2672 || sec
->need_convert_load
== 0
2673 || bfd_is_abs_section (sec
->output_section
))
2676 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2678 /* Load the relocations for this section. */
2679 internal_relocs
= (_bfd_elf_link_read_relocs
2680 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2681 link_info
->keep_memory
));
2682 if (internal_relocs
== NULL
)
2686 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
2687 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2689 /* Get the section contents. */
2690 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2691 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2694 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2698 irelend
= internal_relocs
+ sec
->reloc_count
;
2699 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2701 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
2702 unsigned int r_symndx
;
2703 struct elf_link_hash_entry
*h
;
2704 bfd_boolean converted
;
2706 /* Don't convert R_386_GOT32 since we can't tell if it is applied
2707 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
2708 if (r_type
!= R_386_GOT32X
)
2711 r_symndx
= ELF32_R_SYM (irel
->r_info
);
2712 if (r_symndx
< symtab_hdr
->sh_info
)
2713 h
= _bfd_elf_x86_get_local_sym_hash (htab
, sec
->owner
,
2714 (const Elf_Internal_Rela
*) irel
,
2718 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
2719 while (h
->root
.type
== bfd_link_hash_indirect
2720 || h
->root
.type
== bfd_link_hash_warning
)
2721 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2724 /* STT_GNU_IFUNC must keep GOT32 relocations. */
2725 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2729 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
2730 irel
, h
, &converted
, link_info
))
2735 changed
= converted
;
2738 if (h
->got
.refcount
> 0)
2739 h
->got
.refcount
-= 1;
2743 if (local_got_refcounts
!= NULL
2744 && local_got_refcounts
[r_symndx
] > 0)
2745 local_got_refcounts
[r_symndx
] -= 1;
2750 if (contents
!= NULL
2751 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2753 if (!changed
&& !link_info
->keep_memory
)
2757 /* Cache the section contents for elf_link_input_bfd. */
2758 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2762 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2765 free (internal_relocs
);
2767 elf_section_data (sec
)->relocs
= internal_relocs
;
2773 if (contents
!= NULL
2774 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2776 if (internal_relocs
!= NULL
2777 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2778 free (internal_relocs
);
2782 /* Set the sizes of the dynamic sections. */
2785 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2787 struct elf_x86_link_hash_table
*htab
;
2793 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2796 dynobj
= htab
->elf
.dynobj
;
2800 /* Set up .got offsets for local syms, and space for local dynamic
2802 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2804 bfd_signed_vma
*local_got
;
2805 bfd_signed_vma
*end_local_got
;
2806 char *local_tls_type
;
2807 bfd_vma
*local_tlsdesc_gotent
;
2808 bfd_size_type locsymcount
;
2809 Elf_Internal_Shdr
*symtab_hdr
;
2812 if (! is_i386_elf (ibfd
))
2815 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2817 struct elf_dyn_relocs
*p
;
2819 if (!elf_i386_convert_load (ibfd
, s
, info
))
2822 for (p
= ((struct elf_dyn_relocs
*)
2823 elf_section_data (s
)->local_dynrel
);
2827 if (!bfd_is_abs_section (p
->sec
)
2828 && bfd_is_abs_section (p
->sec
->output_section
))
2830 /* Input section has been discarded, either because
2831 it is a copy of a linkonce section or due to
2832 linker script /DISCARD/, so we'll be discarding
2835 else if ((get_elf_i386_backend_data (output_bfd
)->os
2837 && strcmp (p
->sec
->output_section
->name
,
2840 /* Relocations in vxworks .tls_vars sections are
2841 handled specially by the loader. */
2843 else if (p
->count
!= 0)
2845 srel
= elf_section_data (p
->sec
)->sreloc
;
2846 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2847 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2848 && (info
->flags
& DF_TEXTREL
) == 0)
2850 info
->flags
|= DF_TEXTREL
;
2851 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
2852 || info
->error_textrel
)
2853 /* xgettext:c-format */
2854 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
2855 p
->sec
->owner
, p
->sec
);
2861 local_got
= elf_local_got_refcounts (ibfd
);
2865 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2866 locsymcount
= symtab_hdr
->sh_info
;
2867 end_local_got
= local_got
+ locsymcount
;
2868 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
2869 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
2871 srel
= htab
->elf
.srelgot
;
2872 for (; local_got
< end_local_got
;
2873 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2875 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2878 if (GOT_TLS_GDESC_P (*local_tls_type
))
2880 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2881 - elf_i386_compute_jump_table_size (htab
);
2882 htab
->elf
.sgotplt
->size
+= 8;
2883 *local_got
= (bfd_vma
) -2;
2885 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2886 || GOT_TLS_GD_P (*local_tls_type
))
2888 *local_got
= s
->size
;
2890 if (GOT_TLS_GD_P (*local_tls_type
)
2891 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2894 if (bfd_link_pic (info
)
2895 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2896 || (*local_tls_type
& GOT_TLS_IE
))
2898 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2899 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2900 else if (GOT_TLS_GD_P (*local_tls_type
)
2901 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2902 srel
->size
+= sizeof (Elf32_External_Rel
);
2903 if (GOT_TLS_GDESC_P (*local_tls_type
))
2904 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2908 *local_got
= (bfd_vma
) -1;
2912 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
2914 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2916 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2917 htab
->elf
.sgot
->size
+= 8;
2918 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2921 htab
->tls_ld_or_ldm_got
.offset
= -1;
2923 /* Allocate global sym .plt and .got entries, and space for global
2924 sym dynamic relocs. */
2925 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2927 /* Allocate .plt and .got entries, and space for local symbols. */
2928 htab_traverse (htab
->loc_hash_table
,
2929 elf_i386_allocate_local_dynrelocs
,
2932 /* For every jump slot reserved in the sgotplt, reloc_count is
2933 incremented. However, when we reserve space for TLS descriptors,
2934 it's not incremented, so in order to compute the space reserved
2935 for them, it suffices to multiply the reloc count by the jump
2938 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2939 so that R_386_IRELATIVE entries come last. */
2940 if (htab
->elf
.srelplt
)
2942 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
2943 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2944 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2946 else if (htab
->elf
.irelplt
)
2947 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2950 if (htab
->elf
.sgotplt
)
2952 /* Don't allocate .got.plt section if there are no GOT nor PLT
2953 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
2954 if ((htab
->elf
.hgot
== NULL
2955 || !htab
->elf
.hgot
->ref_regular_nonweak
)
2956 && (htab
->elf
.sgotplt
->size
2957 == get_elf_backend_data (output_bfd
)->got_header_size
)
2958 && (htab
->elf
.splt
== NULL
2959 || htab
->elf
.splt
->size
== 0)
2960 && (htab
->elf
.sgot
== NULL
2961 || htab
->elf
.sgot
->size
== 0)
2962 && (htab
->elf
.iplt
== NULL
2963 || htab
->elf
.iplt
->size
== 0)
2964 && (htab
->elf
.igotplt
== NULL
2965 || htab
->elf
.igotplt
->size
== 0))
2966 htab
->elf
.sgotplt
->size
= 0;
2969 if (_bfd_elf_eh_frame_present (info
))
2971 if (htab
->plt_eh_frame
!= NULL
2972 && htab
->elf
.splt
!= NULL
2973 && htab
->elf
.splt
->size
!= 0
2974 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
2975 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
2977 if (htab
->plt_got_eh_frame
!= NULL
2978 && htab
->plt_got
!= NULL
2979 && htab
->plt_got
->size
!= 0
2980 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
2981 htab
->plt_got_eh_frame
->size
2982 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2984 /* Unwind info for the second PLT and .plt.got sections are
2986 if (htab
->plt_second_eh_frame
!= NULL
2987 && htab
->plt_second
!= NULL
2988 && htab
->plt_second
->size
!= 0
2989 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
2990 htab
->plt_second_eh_frame
->size
2991 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2994 /* We now have determined the sizes of the various dynamic sections.
2995 Allocate memory for them. */
2997 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2999 bfd_boolean strip_section
= TRUE
;
3001 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3004 if (s
== htab
->elf
.splt
3005 || s
== htab
->elf
.sgot
)
3007 /* Strip this section if we don't need it; see the
3009 /* We'd like to strip these sections if they aren't needed, but if
3010 we've exported dynamic symbols from them we must leave them.
3011 It's too late to tell BFD to get rid of the symbols. */
3013 if (htab
->elf
.hplt
!= NULL
)
3014 strip_section
= FALSE
;
3016 else if (s
== htab
->elf
.sgotplt
3017 || s
== htab
->elf
.iplt
3018 || s
== htab
->elf
.igotplt
3019 || s
== htab
->plt_second
3020 || s
== htab
->plt_got
3021 || s
== htab
->plt_eh_frame
3022 || s
== htab
->plt_got_eh_frame
3023 || s
== htab
->plt_second_eh_frame
3024 || s
== htab
->elf
.sdynbss
3025 || s
== htab
->elf
.sdynrelro
)
3027 /* Strip these too. */
3029 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3032 && s
!= htab
->elf
.srelplt
3033 && s
!= htab
->srelplt2
)
3036 /* We use the reloc_count field as a counter if we need
3037 to copy relocs into the output file. */
3042 /* It's not one of our sections, so don't allocate space. */
3048 /* If we don't need this section, strip it from the
3049 output file. This is mostly to handle .rel.bss and
3050 .rel.plt. We must create both sections in
3051 create_dynamic_sections, because they must be created
3052 before the linker maps input sections to output
3053 sections. The linker does that before
3054 adjust_dynamic_symbol is called, and it is that
3055 function which decides whether anything needs to go
3056 into these sections. */
3058 s
->flags
|= SEC_EXCLUDE
;
3062 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3065 /* Allocate memory for the section contents. We use bfd_zalloc
3066 here in case unused entries are not reclaimed before the
3067 section's contents are written out. This should not happen,
3068 but this way if it does, we get a R_386_NONE reloc instead
3070 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3071 if (s
->contents
== NULL
)
3075 if (htab
->plt_eh_frame
!= NULL
3076 && htab
->plt_eh_frame
->contents
!= NULL
)
3078 memcpy (htab
->plt_eh_frame
->contents
,
3079 htab
->plt
.eh_frame_plt
,
3080 htab
->plt_eh_frame
->size
);
3081 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3082 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3085 if (htab
->plt_got_eh_frame
!= NULL
3086 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3088 memcpy (htab
->plt_got_eh_frame
->contents
,
3089 htab
->non_lazy_plt
->eh_frame_plt
,
3090 htab
->plt_got_eh_frame
->size
);
3091 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3092 (htab
->plt_got_eh_frame
->contents
3093 + PLT_FDE_LEN_OFFSET
));
3096 if (htab
->plt_second_eh_frame
!= NULL
3097 && htab
->plt_second_eh_frame
->contents
!= NULL
)
3099 memcpy (htab
->plt_second_eh_frame
->contents
,
3100 htab
->non_lazy_plt
->eh_frame_plt
,
3101 htab
->plt_second_eh_frame
->size
);
3102 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
3103 (htab
->plt_second_eh_frame
->contents
3104 + PLT_FDE_LEN_OFFSET
));
3107 if (htab
->elf
.dynamic_sections_created
)
3109 /* Add some entries to the .dynamic section. We fill in the
3110 values later, in elf_i386_finish_dynamic_sections, but we
3111 must add the entries now so that we get the correct size for
3112 the .dynamic section. The DT_DEBUG entry is filled in by the
3113 dynamic linker and used by the debugger. */
3114 #define add_dynamic_entry(TAG, VAL) \
3115 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3117 if (bfd_link_executable (info
))
3119 if (!add_dynamic_entry (DT_DEBUG
, 0))
3123 if (htab
->elf
.splt
->size
!= 0)
3125 /* DT_PLTGOT is used by prelink even if there is no PLT
3127 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3131 if (htab
->elf
.srelplt
->size
!= 0)
3133 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3134 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3135 || !add_dynamic_entry (DT_JMPREL
, 0))
3141 if (!add_dynamic_entry (DT_REL
, 0)
3142 || !add_dynamic_entry (DT_RELSZ
, 0)
3143 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3146 /* If any dynamic relocs apply to a read-only section,
3147 then we need a DT_TEXTREL entry. */
3148 if ((info
->flags
& DF_TEXTREL
) == 0)
3149 elf_link_hash_traverse (&htab
->elf
,
3150 _bfd_x86_elf_readonly_dynrelocs
,
3153 if ((info
->flags
& DF_TEXTREL
) != 0)
3155 if (htab
->readonly_dynrelocs_against_ifunc
)
3157 info
->callbacks
->einfo
3158 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3159 bfd_set_error (bfd_error_bad_value
);
3163 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3167 if (get_elf_i386_backend_data (output_bfd
)->os
== is_vxworks
3168 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3171 #undef add_dynamic_entry
3176 /* Set the correct type for an x86 ELF section. We do this by the
3177 section name, which is a hack, but ought to work. */
3180 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3181 Elf_Internal_Shdr
*hdr
,
3186 name
= bfd_get_section_name (abfd
, sec
);
3188 /* This is an ugly, but unfortunately necessary hack that is
3189 needed when producing EFI binaries on x86. It tells
3190 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3191 containing ELF relocation info. We need this hack in order to
3192 be able to generate ELF binaries that can be translated into
3193 EFI applications (which are essentially COFF objects). Those
3194 files contain a COFF ".reloc" section inside an ELFNN object,
3195 which would normally cause BFD to segfault because it would
3196 attempt to interpret this section as containing relocation
3197 entries for section "oc". With this hack enabled, ".reloc"
3198 will be treated as a normal data section, which will avoid the
3199 segfault. However, you won't be able to create an ELFNN binary
3200 with a section named "oc" that needs relocations, but that's
3201 the kind of ugly side-effects you get when detecting section
3202 types based on their names... In practice, this limitation is
3203 unlikely to bite. */
3204 if (strcmp (name
, ".reloc") == 0)
3205 hdr
->sh_type
= SHT_PROGBITS
;
3210 /* Return the relocation value for @tpoff relocation
3211 if STT_TLS virtual address is ADDRESS. */
3214 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3216 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3217 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3218 bfd_vma static_tls_size
;
3220 /* If tls_sec is NULL, we should have signalled an error already. */
3221 if (htab
->tls_sec
== NULL
)
3224 /* Consider special static TLS alignment requirements. */
3225 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3226 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3229 /* Relocate an i386 ELF section. */
3232 elf_i386_relocate_section (bfd
*output_bfd
,
3233 struct bfd_link_info
*info
,
3235 asection
*input_section
,
3237 Elf_Internal_Rela
*relocs
,
3238 Elf_Internal_Sym
*local_syms
,
3239 asection
**local_sections
)
3241 struct elf_x86_link_hash_table
*htab
;
3242 Elf_Internal_Shdr
*symtab_hdr
;
3243 struct elf_link_hash_entry
**sym_hashes
;
3244 bfd_vma
*local_got_offsets
;
3245 bfd_vma
*local_tlsdesc_gotents
;
3246 Elf_Internal_Rela
*rel
;
3247 Elf_Internal_Rela
*wrel
;
3248 Elf_Internal_Rela
*relend
;
3249 bfd_boolean is_vxworks_tls
;
3250 unsigned plt_entry_size
;
3252 BFD_ASSERT (is_i386_elf (input_bfd
));
3254 /* Skip if check_relocs failed. */
3255 if (input_section
->check_relocs_failed
)
3258 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
3261 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3262 sym_hashes
= elf_sym_hashes (input_bfd
);
3263 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3264 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
3265 /* We have to handle relocations in vxworks .tls_vars sections
3266 specially, because the dynamic loader is 'weird'. */
3267 is_vxworks_tls
= ((get_elf_i386_backend_data (output_bfd
)->os
3269 && bfd_link_pic (info
)
3270 && !strcmp (input_section
->output_section
->name
,
3273 _bfd_x86_elf_set_tls_module_base (info
);
3275 plt_entry_size
= htab
->plt
.plt_entry_size
;
3277 rel
= wrel
= relocs
;
3278 relend
= relocs
+ input_section
->reloc_count
;
3279 for (; rel
< relend
; wrel
++, rel
++)
3281 unsigned int r_type
;
3282 reloc_howto_type
*howto
;
3283 unsigned long r_symndx
;
3284 struct elf_link_hash_entry
*h
;
3285 struct elf_x86_link_hash_entry
*eh
;
3286 Elf_Internal_Sym
*sym
;
3288 bfd_vma off
, offplt
, plt_offset
;
3290 bfd_boolean unresolved_reloc
;
3291 bfd_reloc_status_type r
;
3295 asection
*resolved_plt
;
3296 bfd_boolean resolved_to_zero
;
3297 bfd_boolean relative_reloc
;
3299 r_type
= ELF32_R_TYPE (rel
->r_info
);
3300 if (r_type
== R_386_GNU_VTINHERIT
3301 || r_type
== R_386_GNU_VTENTRY
)
3308 if ((indx
= r_type
) >= R_386_standard
3309 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3310 >= R_386_ext
- R_386_standard
)
3311 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3312 >= R_386_ext2
- R_386_ext
))
3313 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
3315 howto
= elf_howto_table
+ indx
;
3317 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3321 unresolved_reloc
= FALSE
;
3322 if (r_symndx
< symtab_hdr
->sh_info
)
3324 sym
= local_syms
+ r_symndx
;
3325 sec
= local_sections
[r_symndx
];
3326 relocation
= (sec
->output_section
->vma
3327 + sec
->output_offset
3329 st_size
= sym
->st_size
;
3331 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3332 && ((sec
->flags
& SEC_MERGE
) != 0
3333 || (bfd_link_relocatable (info
)
3334 && sec
->output_offset
!= 0)))
3337 bfd_byte
*where
= contents
+ rel
->r_offset
;
3339 switch (howto
->size
)
3342 addend
= bfd_get_8 (input_bfd
, where
);
3343 if (howto
->pc_relative
)
3345 addend
= (addend
^ 0x80) - 0x80;
3350 addend
= bfd_get_16 (input_bfd
, where
);
3351 if (howto
->pc_relative
)
3353 addend
= (addend
^ 0x8000) - 0x8000;
3358 addend
= bfd_get_32 (input_bfd
, where
);
3359 if (howto
->pc_relative
)
3361 addend
= (addend
^ 0x80000000) - 0x80000000;
3369 if (bfd_link_relocatable (info
))
3370 addend
+= sec
->output_offset
;
3373 asection
*msec
= sec
;
3374 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3376 addend
-= relocation
;
3377 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3380 switch (howto
->size
)
3383 /* FIXME: overflow checks. */
3384 if (howto
->pc_relative
)
3386 bfd_put_8 (input_bfd
, addend
, where
);
3389 if (howto
->pc_relative
)
3391 bfd_put_16 (input_bfd
, addend
, where
);
3394 if (howto
->pc_relative
)
3396 bfd_put_32 (input_bfd
, addend
, where
);
3400 else if (!bfd_link_relocatable (info
)
3401 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3403 /* Relocate against local STT_GNU_IFUNC symbol. */
3404 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
, rel
,
3409 /* Set STT_GNU_IFUNC symbol value. */
3410 h
->root
.u
.def
.value
= sym
->st_value
;
3411 h
->root
.u
.def
.section
= sec
;
3416 bfd_boolean warned ATTRIBUTE_UNUSED
;
3417 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3419 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3420 r_symndx
, symtab_hdr
, sym_hashes
,
3422 unresolved_reloc
, warned
, ignored
);
3426 if (sec
!= NULL
&& discarded_section (sec
))
3428 _bfd_clear_contents (howto
, input_bfd
, input_section
,
3429 contents
+ rel
->r_offset
);
3430 wrel
->r_offset
= rel
->r_offset
;
3434 /* For ld -r, remove relocations in debug sections against
3435 sections defined in discarded sections. Not done for
3436 eh_frame editing code expects to be present. */
3437 if (bfd_link_relocatable (info
)
3438 && (input_section
->flags
& SEC_DEBUGGING
))
3444 if (bfd_link_relocatable (info
))
3451 eh
= (struct elf_x86_link_hash_entry
*) h
;
3453 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3454 it here if it is defined in a non-shared object. */
3456 && h
->type
== STT_GNU_IFUNC
3459 asection
*gotplt
, *base_got
;
3463 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3465 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3466 sections because such sections are not SEC_ALLOC and
3467 thus ld.so will not process them. */
3468 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
3473 /* STT_GNU_IFUNC symbol must go through PLT. */
3474 if (htab
->elf
.splt
!= NULL
)
3476 if (htab
->plt_second
!= NULL
)
3478 resolved_plt
= htab
->plt_second
;
3479 plt_offset
= eh
->plt_second
.offset
;
3483 resolved_plt
= htab
->elf
.splt
;
3484 plt_offset
= h
->plt
.offset
;
3486 gotplt
= htab
->elf
.sgotplt
;
3490 resolved_plt
= htab
->elf
.iplt
;
3491 plt_offset
= h
->plt
.offset
;
3492 gotplt
= htab
->elf
.igotplt
;
3502 base_got
= htab
->elf
.sgot
;
3503 off
= h
->got
.offset
;
3505 if (base_got
== NULL
)
3508 if (off
== (bfd_vma
) -1)
3510 /* We can't use h->got.offset here to save state, or
3511 even just remember the offset, as finish_dynamic_symbol
3512 would use that as offset into .got. */
3514 if (h
->plt
.offset
== (bfd_vma
) -1)
3517 if (htab
->elf
.splt
!= NULL
)
3519 plt_index
= (h
->plt
.offset
/ plt_entry_size
3520 - htab
->plt
.has_plt0
);
3521 off
= (plt_index
+ 3) * 4;
3522 base_got
= htab
->elf
.sgotplt
;
3526 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3527 off
= plt_index
* 4;
3528 base_got
= htab
->elf
.igotplt
;
3531 if (h
->dynindx
== -1
3535 /* This references the local defitionion. We must
3536 initialize this entry in the global offset table.
3537 Since the offset must always be a multiple of 8,
3538 we use the least significant bit to record
3539 whether we have initialized it already.
3541 When doing a dynamic link, we create a .rela.got
3542 relocation entry to initialize the value. This
3543 is done in the finish_dynamic_symbol routine. */
3548 bfd_put_32 (output_bfd
, relocation
,
3549 base_got
->contents
+ off
);
3557 relocation
= (base_got
->output_section
->vma
3558 + base_got
->output_offset
+ off
3559 - gotplt
->output_section
->vma
3560 - gotplt
->output_offset
);
3562 if (rel
->r_offset
> 1
3563 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
3564 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
3566 if (bfd_link_pic (info
))
3567 goto disallow_got32
;
3569 /* Add the GOT base if there is no base register. */
3570 relocation
+= (gotplt
->output_section
->vma
3571 + gotplt
->output_offset
);
3573 else if (htab
->elf
.splt
== NULL
)
3575 /* Adjust for static executables. */
3576 relocation
+= gotplt
->output_offset
;
3582 if (h
->plt
.offset
== (bfd_vma
) -1)
3584 /* Handle static pointers of STT_GNU_IFUNC symbols. */
3585 if (r_type
== R_386_32
3586 && (input_section
->flags
& SEC_CODE
) == 0)
3587 goto do_ifunc_pointer
;
3588 goto bad_ifunc_reloc
;
3591 relocation
= (resolved_plt
->output_section
->vma
3592 + resolved_plt
->output_offset
+ plt_offset
);
3598 if (h
->root
.root
.string
)
3599 name
= h
->root
.root
.string
;
3601 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3604 /* xgettext:c-format */
3605 (_("%B: relocation %s against STT_GNU_IFUNC "
3606 "symbol `%s' isn't supported"), input_bfd
,
3608 bfd_set_error (bfd_error_bad_value
);
3612 /* Generate dynamic relcoation only when there is a
3613 non-GOT reference in a shared object. */
3614 if ((bfd_link_pic (info
) && h
->non_got_ref
)
3615 || h
->plt
.offset
== (bfd_vma
) -1)
3617 Elf_Internal_Rela outrel
;
3622 /* Need a dynamic relocation to get the real function
3624 offset
= _bfd_elf_section_offset (output_bfd
,
3628 if (offset
== (bfd_vma
) -1
3629 || offset
== (bfd_vma
) -2)
3632 outrel
.r_offset
= (input_section
->output_section
->vma
3633 + input_section
->output_offset
3636 if (h
->dynindx
== -1
3638 || bfd_link_executable (info
))
3640 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3641 h
->root
.root
.string
,
3642 h
->root
.u
.def
.section
->owner
);
3644 /* This symbol is resolved locally. */
3645 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3646 bfd_put_32 (output_bfd
,
3647 (h
->root
.u
.def
.value
3648 + h
->root
.u
.def
.section
->output_section
->vma
3649 + h
->root
.u
.def
.section
->output_offset
),
3653 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3655 /* Dynamic relocations are stored in
3656 1. .rel.ifunc section in PIC object.
3657 2. .rel.got section in dynamic executable.
3658 3. .rel.iplt section in static executable. */
3659 if (bfd_link_pic (info
))
3660 sreloc
= htab
->elf
.irelifunc
;
3661 else if (htab
->elf
.splt
!= NULL
)
3662 sreloc
= htab
->elf
.srelgot
;
3664 sreloc
= htab
->elf
.irelplt
;
3665 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3667 /* If this reloc is against an external symbol, we
3668 do not want to fiddle with the addend. Otherwise,
3669 we need to include the symbol value so that it
3670 becomes an addend for the dynamic reloc. For an
3671 internal symbol, we have updated addend. */
3680 relocation
-= (gotplt
->output_section
->vma
3681 + gotplt
->output_offset
);
3686 resolved_to_zero
= (eh
!= NULL
3687 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3695 /* Avoid optimizing _DYNAMIC since ld.so may use its
3696 link-time address. */
3697 if (h
== htab
->elf
.hdynamic
)
3700 if (bfd_link_pic (info
))
3702 /* It is OK to convert mov to lea and convert indirect
3703 branch to direct branch. It is OK to convert adc,
3704 add, and, cmp, or, sbb, sub, test, xor only when PIC
3706 unsigned int opcode
, addend
;
3707 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3710 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3711 if (opcode
!= 0x8b && opcode
!= 0xff)
3715 /* Resolve "mov GOT[(%reg)], %reg",
3716 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
3717 and "binop foo@GOT[(%reg)], %reg". */
3719 || (h
->plt
.offset
== (bfd_vma
) -1
3720 && h
->got
.offset
== (bfd_vma
) -1)
3721 || htab
->elf
.sgotplt
== NULL
)
3724 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
3725 + htab
->elf
.sgotplt
->output_offset
);
3727 /* It is relative to .got.plt section. */
3728 if (h
->got
.offset
!= (bfd_vma
) -1)
3729 /* Use GOT entry. Mask off the least significant bit in
3730 GOT offset which may be set by R_386_GOT32 processing
3732 relocation
= (htab
->elf
.sgot
->output_section
->vma
3733 + htab
->elf
.sgot
->output_offset
3734 + (h
->got
.offset
& ~1) - offplt
);
3736 /* Use GOTPLT entry. */
3737 relocation
= (h
->plt
.offset
/ plt_entry_size
3738 - htab
->plt
.has_plt0
+ 3) * 4;
3740 if (!bfd_link_pic (info
))
3742 /* If not PIC, add the .got.plt section address for
3743 baseless addressing. */
3745 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3746 if ((modrm
& 0xc7) == 0x5)
3747 relocation
+= offplt
;
3750 unresolved_reloc
= FALSE
;
3755 /* Relocation is to the entry for this symbol in the global
3757 if (htab
->elf
.sgot
== NULL
)
3760 relative_reloc
= FALSE
;
3765 off
= h
->got
.offset
;
3766 dyn
= htab
->elf
.dynamic_sections_created
;
3767 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
3768 bfd_link_pic (info
),
3770 || (bfd_link_pic (info
)
3771 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3772 || (ELF_ST_VISIBILITY (h
->other
)
3773 && h
->root
.type
== bfd_link_hash_undefweak
))
3775 /* This is actually a static link, or it is a
3776 -Bsymbolic link and the symbol is defined
3777 locally, or the symbol was forced to be local
3778 because of a version file. We must initialize
3779 this entry in the global offset table. Since the
3780 offset must always be a multiple of 4, we use the
3781 least significant bit to record whether we have
3782 initialized it already.
3784 When doing a dynamic link, we create a .rel.got
3785 relocation entry to initialize the value. This
3786 is done in the finish_dynamic_symbol routine. */
3791 bfd_put_32 (output_bfd
, relocation
,
3792 htab
->elf
.sgot
->contents
+ off
);
3795 if (h
->dynindx
== -1
3797 && h
->root
.type
!= bfd_link_hash_undefweak
3798 && bfd_link_pic (info
))
3800 /* PR ld/21402: If this symbol isn't dynamic
3801 in PIC, generate R_386_RELATIVE here. */
3802 eh
->no_finish_dynamic_symbol
= 1;
3803 relative_reloc
= TRUE
;
3808 unresolved_reloc
= FALSE
;
3812 if (local_got_offsets
== NULL
)
3815 off
= local_got_offsets
[r_symndx
];
3817 /* The offset must always be a multiple of 4. We use
3818 the least significant bit to record whether we have
3819 already generated the necessary reloc. */
3824 bfd_put_32 (output_bfd
, relocation
,
3825 htab
->elf
.sgot
->contents
+ off
);
3826 local_got_offsets
[r_symndx
] |= 1;
3828 if (bfd_link_pic (info
))
3829 relative_reloc
= TRUE
;
3836 Elf_Internal_Rela outrel
;
3838 s
= htab
->elf
.srelgot
;
3842 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3843 + htab
->elf
.sgot
->output_offset
3845 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3846 elf_append_rel (output_bfd
, s
, &outrel
);
3849 if (off
>= (bfd_vma
) -2)
3852 relocation
= (htab
->elf
.sgot
->output_section
->vma
3853 + htab
->elf
.sgot
->output_offset
+ off
);
3854 if (rel
->r_offset
> 1
3855 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
3856 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
3858 if (bfd_link_pic (info
))
3860 /* For PIC, disallow R_386_GOT32 without a base
3861 register, except for "lea foo@GOT, %reg", since
3862 we don't know what the GOT base is. */
3866 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
3867 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3870 name
= h
->root
.root
.string
;
3873 /* xgettext:c-format */
3874 (_("%B: direct GOT relocation %s against `%s'"
3875 " without base register can not be used"
3876 " when making a shared object"),
3877 input_bfd
, howto
->name
, name
);
3878 bfd_set_error (bfd_error_bad_value
);
3884 /* Subtract the .got.plt section address only with a base
3886 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
3887 + htab
->elf
.sgotplt
->output_offset
);
3893 /* Relocation is relative to the start of the global offset
3896 /* Check to make sure it isn't a protected function or data
3897 symbol for shared library since it may not be local when
3898 used as function address or with copy relocation. We also
3899 need to make sure that a symbol is referenced locally. */
3900 if (!bfd_link_executable (info
) && h
)
3902 if (!h
->def_regular
)
3906 switch (ELF_ST_VISIBILITY (h
->other
))
3909 v
= _("hidden symbol");
3912 v
= _("internal symbol");
3915 v
= _("protected symbol");
3923 /* xgettext:c-format */
3924 (_("%B: relocation R_386_GOTOFF against undefined %s"
3925 " `%s' can not be used when making a shared object"),
3926 input_bfd
, v
, h
->root
.root
.string
);
3927 bfd_set_error (bfd_error_bad_value
);
3930 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
3931 && (h
->type
== STT_FUNC
3932 || h
->type
== STT_OBJECT
)
3933 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3936 /* xgettext:c-format */
3937 (_("%B: relocation R_386_GOTOFF against protected %s"
3938 " `%s' can not be used when making a shared object"),
3940 h
->type
== STT_FUNC
? "function" : "data",
3941 h
->root
.root
.string
);
3942 bfd_set_error (bfd_error_bad_value
);
3947 /* Note that sgot is not involved in this
3948 calculation. We always want the start of .got.plt. If we
3949 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3950 permitted by the ABI, we might have to change this
3952 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3953 + htab
->elf
.sgotplt
->output_offset
;
3957 /* Use global offset table as symbol value. */
3958 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3959 + htab
->elf
.sgotplt
->output_offset
;
3960 unresolved_reloc
= FALSE
;
3964 /* Relocation is to the entry for this symbol in the
3965 procedure linkage table. */
3967 /* Resolve a PLT32 reloc against a local symbol directly,
3968 without using the procedure linkage table. */
3972 if ((h
->plt
.offset
== (bfd_vma
) -1
3973 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3974 || htab
->elf
.splt
== NULL
)
3976 /* We didn't make a PLT entry for this symbol. This
3977 happens when statically linking PIC code, or when
3978 using -Bsymbolic. */
3982 if (h
->plt
.offset
!= (bfd_vma
) -1)
3984 if (htab
->plt_second
!= NULL
)
3986 resolved_plt
= htab
->plt_second
;
3987 plt_offset
= eh
->plt_second
.offset
;
3991 resolved_plt
= htab
->elf
.splt
;
3992 plt_offset
= h
->plt
.offset
;
3997 resolved_plt
= htab
->plt_got
;
3998 plt_offset
= eh
->plt_got
.offset
;
4001 relocation
= (resolved_plt
->output_section
->vma
4002 + resolved_plt
->output_offset
4004 unresolved_reloc
= FALSE
;
4008 /* Set to symbol size. */
4009 relocation
= st_size
;
4014 if ((input_section
->flags
& SEC_ALLOC
) == 0
4018 /* Copy dynamic function pointer relocations. Don't generate
4019 dynamic relocations against resolved undefined weak symbols
4020 in PIE, except for R_386_PC32. */
4021 if ((bfd_link_pic (info
)
4023 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4024 && (!resolved_to_zero
4025 || r_type
== R_386_PC32
))
4026 || h
->root
.type
!= bfd_link_hash_undefweak
))
4027 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
4028 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4029 || (ELIMINATE_COPY_RELOCS
4030 && !bfd_link_pic (info
)
4034 || eh
->func_pointer_refcount
> 0
4035 || (h
->root
.type
== bfd_link_hash_undefweak
4036 && !resolved_to_zero
))
4037 && ((h
->def_dynamic
&& !h
->def_regular
)
4038 /* Undefined weak symbol is bound locally when
4040 || h
->root
.type
== bfd_link_hash_undefweak
)))
4042 Elf_Internal_Rela outrel
;
4043 bfd_boolean skip
, relocate
;
4046 /* When generating a shared object, these relocations
4047 are copied into the output file to be resolved at run
4054 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4056 if (outrel
.r_offset
== (bfd_vma
) -1)
4058 else if (outrel
.r_offset
== (bfd_vma
) -2)
4059 skip
= TRUE
, relocate
= TRUE
;
4060 outrel
.r_offset
+= (input_section
->output_section
->vma
4061 + input_section
->output_offset
);
4064 memset (&outrel
, 0, sizeof outrel
);
4067 && (r_type
== R_386_PC32
4068 || !(bfd_link_executable (info
)
4069 || SYMBOLIC_BIND (info
, h
))
4070 || !h
->def_regular
))
4071 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4074 /* This symbol is local, or marked to become local. */
4076 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4079 sreloc
= elf_section_data (input_section
)->sreloc
;
4081 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4083 r
= bfd_reloc_notsupported
;
4084 goto check_relocation_error
;
4087 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4089 /* If this reloc is against an external symbol, we do
4090 not want to fiddle with the addend. Otherwise, we
4091 need to include the symbol value so that it becomes
4092 an addend for the dynamic reloc. */
4099 if (!bfd_link_executable (info
))
4101 Elf_Internal_Rela outrel
;
4104 outrel
.r_offset
= rel
->r_offset
4105 + input_section
->output_section
->vma
4106 + input_section
->output_offset
;
4107 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4108 sreloc
= elf_section_data (input_section
)->sreloc
;
4111 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4116 case R_386_TLS_GOTDESC
:
4117 case R_386_TLS_DESC_CALL
:
4118 case R_386_TLS_IE_32
:
4119 case R_386_TLS_GOTIE
:
4120 tls_type
= GOT_UNKNOWN
;
4121 if (h
== NULL
&& local_got_offsets
)
4122 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
4124 tls_type
= elf_x86_hash_entry(h
)->tls_type
;
4125 if (tls_type
== GOT_TLS_IE
)
4126 tls_type
= GOT_TLS_IE_NEG
;
4128 if (! elf_i386_tls_transition (info
, input_bfd
,
4129 input_section
, contents
,
4130 symtab_hdr
, sym_hashes
,
4131 &r_type
, tls_type
, rel
,
4132 relend
, h
, r_symndx
, TRUE
))
4135 if (r_type
== R_386_TLS_LE_32
)
4137 BFD_ASSERT (! unresolved_reloc
);
4138 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4143 /* GD->LE transition. */
4144 type
= *(contents
+ rel
->r_offset
- 2);
4148 leal foo@tlsgd(,%ebx,1), %eax
4149 call ___tls_get_addr@PLT
4152 subl $foo@tpoff, %eax
4153 (6 byte form of subl). */
4154 roff
= rel
->r_offset
+ 5;
4159 leal foo@tlsgd(%ebx), %eax
4160 call ___tls_get_addr@PLT
4163 leal foo@tlsgd(%reg), %eax
4164 call *___tls_get_addr@GOT(%reg)
4165 which may be converted to
4166 addr32 call ___tls_get_addr
4168 movl %gs:0, %eax; subl $foo@tpoff, %eax
4169 (6 byte form of subl). */
4170 roff
= rel
->r_offset
+ 6;
4172 memcpy (contents
+ roff
- 8,
4173 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4174 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4176 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4181 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4183 /* GDesc -> LE transition.
4184 It's originally something like:
4185 leal x@tlsdesc(%ebx), %eax
4189 Registers other than %eax may be set up here. */
4194 roff
= rel
->r_offset
;
4195 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4197 /* Now modify the instruction as appropriate. */
4198 /* aoliva FIXME: remove the above and xor the byte
4200 bfd_put_8 (output_bfd
, val
^ 0x86,
4201 contents
+ roff
- 1);
4202 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4206 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4208 /* GDesc -> LE transition.
4216 roff
= rel
->r_offset
;
4217 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4218 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4221 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4225 /* IE->LE transition:
4226 Originally it can be one of:
4234 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4237 /* movl foo, %eax. */
4238 bfd_put_8 (output_bfd
, 0xb8,
4239 contents
+ rel
->r_offset
- 1);
4245 type
= bfd_get_8 (input_bfd
,
4246 contents
+ rel
->r_offset
- 2);
4251 bfd_put_8 (output_bfd
, 0xc7,
4252 contents
+ rel
->r_offset
- 2);
4253 bfd_put_8 (output_bfd
,
4254 0xc0 | ((val
>> 3) & 7),
4255 contents
+ rel
->r_offset
- 1);
4259 bfd_put_8 (output_bfd
, 0x81,
4260 contents
+ rel
->r_offset
- 2);
4261 bfd_put_8 (output_bfd
,
4262 0xc0 | ((val
>> 3) & 7),
4263 contents
+ rel
->r_offset
- 1);
4270 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4271 contents
+ rel
->r_offset
);
4276 unsigned int val
, type
;
4278 /* {IE_32,GOTIE}->LE transition:
4279 Originally it can be one of:
4280 subl foo(%reg1), %reg2
4281 movl foo(%reg1), %reg2
4282 addl foo(%reg1), %reg2
4285 movl $foo, %reg2 (6 byte form)
4286 addl $foo, %reg2. */
4287 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4288 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4292 bfd_put_8 (output_bfd
, 0xc7,
4293 contents
+ rel
->r_offset
- 2);
4294 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4295 contents
+ rel
->r_offset
- 1);
4297 else if (type
== 0x2b)
4300 bfd_put_8 (output_bfd
, 0x81,
4301 contents
+ rel
->r_offset
- 2);
4302 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4303 contents
+ rel
->r_offset
- 1);
4305 else if (type
== 0x03)
4308 bfd_put_8 (output_bfd
, 0x81,
4309 contents
+ rel
->r_offset
- 2);
4310 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4311 contents
+ rel
->r_offset
- 1);
4315 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4316 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4317 contents
+ rel
->r_offset
);
4319 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4320 contents
+ rel
->r_offset
);
4325 if (htab
->elf
.sgot
== NULL
)
4330 off
= h
->got
.offset
;
4331 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
4335 if (local_got_offsets
== NULL
)
4338 off
= local_got_offsets
[r_symndx
];
4339 offplt
= local_tlsdesc_gotents
[r_symndx
];
4346 Elf_Internal_Rela outrel
;
4350 if (htab
->elf
.srelgot
== NULL
)
4353 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4355 if (GOT_TLS_GDESC_P (tls_type
))
4358 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4359 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4360 <= htab
->elf
.sgotplt
->size
);
4361 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4362 + htab
->elf
.sgotplt
->output_offset
4364 + htab
->sgotplt_jump_table_size
);
4365 sreloc
= htab
->elf
.srelplt
;
4366 loc
= sreloc
->contents
;
4367 loc
+= (htab
->next_tls_desc_index
++
4368 * sizeof (Elf32_External_Rel
));
4369 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4370 <= sreloc
->contents
+ sreloc
->size
);
4371 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4374 BFD_ASSERT (! unresolved_reloc
);
4375 bfd_put_32 (output_bfd
,
4376 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4377 htab
->elf
.sgotplt
->contents
+ offplt
4378 + htab
->sgotplt_jump_table_size
+ 4);
4382 bfd_put_32 (output_bfd
, 0,
4383 htab
->elf
.sgotplt
->contents
+ offplt
4384 + htab
->sgotplt_jump_table_size
+ 4);
4388 sreloc
= htab
->elf
.srelgot
;
4390 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4391 + htab
->elf
.sgot
->output_offset
+ off
);
4393 if (GOT_TLS_GD_P (tls_type
))
4394 dr_type
= R_386_TLS_DTPMOD32
;
4395 else if (GOT_TLS_GDESC_P (tls_type
))
4397 else if (tls_type
== GOT_TLS_IE_POS
)
4398 dr_type
= R_386_TLS_TPOFF
;
4400 dr_type
= R_386_TLS_TPOFF32
;
4402 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
4403 bfd_put_32 (output_bfd
,
4404 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4405 htab
->elf
.sgot
->contents
+ off
);
4406 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
4407 bfd_put_32 (output_bfd
,
4408 _bfd_x86_elf_dtpoff_base (info
) - relocation
,
4409 htab
->elf
.sgot
->contents
+ off
);
4410 else if (dr_type
!= R_386_TLS_DESC
)
4411 bfd_put_32 (output_bfd
, 0,
4412 htab
->elf
.sgot
->contents
+ off
);
4413 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
4415 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4417 if (GOT_TLS_GD_P (tls_type
))
4421 BFD_ASSERT (! unresolved_reloc
);
4422 bfd_put_32 (output_bfd
,
4423 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4424 htab
->elf
.sgot
->contents
+ off
+ 4);
4428 bfd_put_32 (output_bfd
, 0,
4429 htab
->elf
.sgot
->contents
+ off
+ 4);
4430 outrel
.r_info
= ELF32_R_INFO (indx
,
4431 R_386_TLS_DTPOFF32
);
4432 outrel
.r_offset
+= 4;
4433 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4436 else if (tls_type
== GOT_TLS_IE_BOTH
)
4438 bfd_put_32 (output_bfd
,
4440 ? relocation
- _bfd_x86_elf_dtpoff_base (info
)
4442 htab
->elf
.sgot
->contents
+ off
+ 4);
4443 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4444 outrel
.r_offset
+= 4;
4445 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4452 local_got_offsets
[r_symndx
] |= 1;
4455 if (off
>= (bfd_vma
) -2
4456 && ! GOT_TLS_GDESC_P (tls_type
))
4458 if (r_type
== R_386_TLS_GOTDESC
4459 || r_type
== R_386_TLS_DESC_CALL
)
4461 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4462 unresolved_reloc
= FALSE
;
4464 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4466 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4467 + htab
->elf
.sgotplt
->output_offset
;
4468 relocation
= htab
->elf
.sgot
->output_section
->vma
4469 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4470 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4471 && tls_type
== GOT_TLS_IE_BOTH
)
4473 if (r_type
== R_386_TLS_IE
)
4474 relocation
+= g_o_t
;
4475 unresolved_reloc
= FALSE
;
4477 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4479 unsigned int val
, type
;
4482 /* GD->IE transition. */
4483 type
= *(contents
+ rel
->r_offset
- 2);
4484 val
= *(contents
+ rel
->r_offset
- 1);
4488 leal foo@tlsgd(,%ebx,1), %eax
4489 call ___tls_get_addr@PLT
4492 subl $foo@gottpoff(%ebx), %eax. */
4494 roff
= rel
->r_offset
- 3;
4499 leal foo@tlsgd(%ebx), %eax
4500 call ___tls_get_addr@PLT
4503 leal foo@tlsgd(%reg), %eax
4504 call *___tls_get_addr@GOT(%reg)
4505 which may be converted to
4506 addr32 call ___tls_get_addr
4509 subl $foo@gottpoff(%reg), %eax. */
4510 roff
= rel
->r_offset
- 2;
4512 memcpy (contents
+ roff
,
4513 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4514 contents
[roff
+ 7] = 0x80 | (val
& 7);
4515 /* If foo is used only with foo@gotntpoff(%reg) and
4516 foo@indntpoff, but not with foo@gottpoff(%reg), change
4517 subl $foo@gottpoff(%reg), %eax
4519 addl $foo@gotntpoff(%reg), %eax. */
4520 if (tls_type
== GOT_TLS_IE_POS
)
4521 contents
[roff
+ 6] = 0x03;
4522 bfd_put_32 (output_bfd
,
4523 htab
->elf
.sgot
->output_section
->vma
4524 + htab
->elf
.sgot
->output_offset
+ off
4525 - htab
->elf
.sgotplt
->output_section
->vma
4526 - htab
->elf
.sgotplt
->output_offset
,
4527 contents
+ roff
+ 8);
4528 /* Skip R_386_PLT32 and R_386_GOT32X. */
4533 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4535 /* GDesc -> IE transition.
4536 It's originally something like:
4537 leal x@tlsdesc(%ebx), %eax
4540 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4542 movl x@gottpoff(%ebx), %eax # before negl %eax
4544 Registers other than %eax may be set up here. */
4548 /* First, make sure it's a leal adding ebx to a 32-bit
4549 offset into any register, although it's probably
4550 almost always going to be eax. */
4551 roff
= rel
->r_offset
;
4553 /* Now modify the instruction as appropriate. */
4554 /* To turn a leal into a movl in the form we use it, it
4555 suffices to change the first byte from 0x8d to 0x8b.
4556 aoliva FIXME: should we decide to keep the leal, all
4557 we have to do is remove the statement below, and
4558 adjust the relaxation of R_386_TLS_DESC_CALL. */
4559 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4561 if (tls_type
== GOT_TLS_IE_BOTH
)
4564 bfd_put_32 (output_bfd
,
4565 htab
->elf
.sgot
->output_section
->vma
4566 + htab
->elf
.sgot
->output_offset
+ off
4567 - htab
->elf
.sgotplt
->output_section
->vma
4568 - htab
->elf
.sgotplt
->output_offset
,
4572 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4574 /* GDesc -> IE transition.
4582 depending on how we transformed the TLS_GOTDESC above.
4587 roff
= rel
->r_offset
;
4589 /* Now modify the instruction as appropriate. */
4590 if (tls_type
!= GOT_TLS_IE_NEG
)
4593 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4594 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4599 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4600 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4610 if (! elf_i386_tls_transition (info
, input_bfd
,
4611 input_section
, contents
,
4612 symtab_hdr
, sym_hashes
,
4613 &r_type
, GOT_UNKNOWN
, rel
,
4614 relend
, h
, r_symndx
, TRUE
))
4617 if (r_type
!= R_386_TLS_LDM
)
4619 /* LD->LE transition. Change
4620 leal foo@tlsldm(%ebx) %eax
4621 call ___tls_get_addr@PLT
4625 leal 0(%esi,1), %esi
4627 leal foo@tlsldm(%reg) %eax
4628 call *___tls_get_addr@GOT(%reg)
4629 which may be converted to
4630 addr32 call ___tls_get_addr
4633 leal 0(%esi), %esi */
4634 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4635 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
4636 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
4637 memcpy (contents
+ rel
->r_offset
- 2,
4638 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
4640 memcpy (contents
+ rel
->r_offset
- 2,
4641 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4642 /* Skip R_386_PC32/R_386_PLT32. */
4648 if (htab
->elf
.sgot
== NULL
)
4651 off
= htab
->tls_ld_or_ldm_got
.offset
;
4656 Elf_Internal_Rela outrel
;
4658 if (htab
->elf
.srelgot
== NULL
)
4661 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4662 + htab
->elf
.sgot
->output_offset
+ off
);
4664 bfd_put_32 (output_bfd
, 0,
4665 htab
->elf
.sgot
->contents
+ off
);
4666 bfd_put_32 (output_bfd
, 0,
4667 htab
->elf
.sgot
->contents
+ off
+ 4);
4668 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4669 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
4670 htab
->tls_ld_or_ldm_got
.offset
|= 1;
4672 relocation
= htab
->elf
.sgot
->output_section
->vma
4673 + htab
->elf
.sgot
->output_offset
+ off
4674 - htab
->elf
.sgotplt
->output_section
->vma
4675 - htab
->elf
.sgotplt
->output_offset
;
4676 unresolved_reloc
= FALSE
;
4679 case R_386_TLS_LDO_32
:
4680 if (!bfd_link_executable (info
)
4681 || (input_section
->flags
& SEC_CODE
) == 0)
4682 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4684 /* When converting LDO to LE, we must negate. */
4685 relocation
= -elf_i386_tpoff (info
, relocation
);
4688 case R_386_TLS_LE_32
:
4690 if (!bfd_link_executable (info
))
4692 Elf_Internal_Rela outrel
;
4695 outrel
.r_offset
= rel
->r_offset
4696 + input_section
->output_section
->vma
4697 + input_section
->output_offset
;
4698 if (h
!= NULL
&& h
->dynindx
!= -1)
4702 if (r_type
== R_386_TLS_LE_32
)
4703 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4705 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4706 sreloc
= elf_section_data (input_section
)->sreloc
;
4709 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4712 else if (r_type
== R_386_TLS_LE_32
)
4713 relocation
= _bfd_x86_elf_dtpoff_base (info
) - relocation
;
4715 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4717 else if (r_type
== R_386_TLS_LE_32
)
4718 relocation
= elf_i386_tpoff (info
, relocation
);
4720 relocation
= -elf_i386_tpoff (info
, relocation
);
4727 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4728 because such sections are not SEC_ALLOC and thus ld.so will
4729 not process them. */
4730 if (unresolved_reloc
4731 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4733 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4734 rel
->r_offset
) != (bfd_vma
) -1)
4737 /* xgettext:c-format */
4738 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
4743 h
->root
.root
.string
);
4748 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4749 contents
, rel
->r_offset
,
4752 check_relocation_error
:
4753 if (r
!= bfd_reloc_ok
)
4758 name
= h
->root
.root
.string
;
4761 name
= bfd_elf_string_from_elf_section (input_bfd
,
4762 symtab_hdr
->sh_link
,
4767 name
= bfd_section_name (input_bfd
, sec
);
4770 if (r
== bfd_reloc_overflow
)
4771 (*info
->callbacks
->reloc_overflow
)
4772 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4773 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4777 /* xgettext:c-format */
4778 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
4779 input_bfd
, input_section
,
4780 rel
->r_offset
, name
, (int) r
);
4791 Elf_Internal_Shdr
*rel_hdr
;
4792 size_t deleted
= rel
- wrel
;
4794 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
4795 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4796 if (rel_hdr
->sh_size
== 0)
4798 /* It is too late to remove an empty reloc section. Leave
4800 ??? What is wrong with an empty section??? */
4801 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
4804 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
4805 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4806 input_section
->reloc_count
-= deleted
;
4812 /* Finish up dynamic symbol handling. We set the contents of various
4813 dynamic sections here. */
4816 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4817 struct bfd_link_info
*info
,
4818 struct elf_link_hash_entry
*h
,
4819 Elf_Internal_Sym
*sym
)
4821 struct elf_x86_link_hash_table
*htab
;
4822 unsigned plt_entry_size
;
4823 const struct elf_i386_backend_data
*abed
;
4824 struct elf_x86_link_hash_entry
*eh
;
4825 bfd_boolean local_undefweak
;
4826 bfd_boolean use_plt_second
;
4828 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
4832 abed
= get_elf_i386_backend_data (output_bfd
);
4833 plt_entry_size
= htab
->plt
.plt_entry_size
;
4835 /* Use the second PLT section only if there is .plt section. */
4836 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
4838 eh
= (struct elf_x86_link_hash_entry
*) h
;
4839 if (eh
->no_finish_dynamic_symbol
)
4842 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4843 resolved undefined weak symbols in executable so that their
4844 references have value 0 at run-time. */
4845 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, I386_ELF_DATA
,
4849 if (h
->plt
.offset
!= (bfd_vma
) -1)
4851 bfd_vma plt_index
, plt_offset
;
4853 Elf_Internal_Rela rel
;
4855 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
4857 /* When building a static executable, use .iplt, .igot.plt and
4858 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4859 if (htab
->elf
.splt
!= NULL
)
4861 plt
= htab
->elf
.splt
;
4862 gotplt
= htab
->elf
.sgotplt
;
4863 relplt
= htab
->elf
.srelplt
;
4867 plt
= htab
->elf
.iplt
;
4868 gotplt
= htab
->elf
.igotplt
;
4869 relplt
= htab
->elf
.irelplt
;
4872 /* This symbol has an entry in the procedure linkage table. Set
4875 if ((h
->dynindx
== -1
4877 && !((h
->forced_local
|| bfd_link_executable (info
))
4879 && h
->type
== STT_GNU_IFUNC
))
4885 /* Get the index in the procedure linkage table which
4886 corresponds to this symbol. This is the index of this symbol
4887 in all the symbols for which we are making plt entries. The
4888 first entry in the procedure linkage table is reserved.
4890 Get the offset into the .got table of the entry that
4891 corresponds to this function. Each .got entry is 4 bytes.
4892 The first three are reserved.
4894 For static executables, we don't reserve anything. */
4896 if (plt
== htab
->elf
.splt
)
4898 got_offset
= (h
->plt
.offset
/ plt_entry_size
4899 - htab
->plt
.has_plt0
);
4900 got_offset
= (got_offset
+ 3) * 4;
4904 got_offset
= h
->plt
.offset
/ plt_entry_size
;
4905 got_offset
= got_offset
* 4;
4908 /* Fill in the entry in the procedure linkage table and update
4910 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
4915 const bfd_byte
*plt_entry
;
4916 if (bfd_link_pic (info
))
4917 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
4919 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
4920 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
4921 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
4923 resolved_plt
= htab
->plt_second
;
4924 plt_offset
= eh
->plt_second
.offset
;
4929 plt_offset
= h
->plt
.offset
;
4932 if (! bfd_link_pic (info
))
4934 bfd_put_32 (output_bfd
,
4935 (gotplt
->output_section
->vma
4936 + gotplt
->output_offset
4938 resolved_plt
->contents
+ plt_offset
4939 + htab
->plt
.plt_got_offset
);
4941 if (abed
->os
== is_vxworks
)
4943 int s
, k
, reloc_index
;
4945 /* Create the R_386_32 relocation referencing the GOT
4946 for this PLT entry. */
4948 /* S: Current slot number (zero-based). */
4949 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
4950 / htab
->plt
.plt_entry_size
);
4951 /* K: Number of relocations for PLTResolve. */
4952 if (bfd_link_pic (info
))
4953 k
= PLTRESOLVE_RELOCS_SHLIB
;
4955 k
= PLTRESOLVE_RELOCS
;
4956 /* Skip the PLTresolve relocations, and the relocations for
4957 the other PLT slots. */
4958 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4959 loc
= (htab
->srelplt2
->contents
+ reloc_index
4960 * sizeof (Elf32_External_Rel
));
4962 rel
.r_offset
= (plt
->output_section
->vma
4963 + plt
->output_offset
4964 + h
->plt
.offset
+ 2),
4965 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4966 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4968 /* Create the R_386_32 relocation referencing the beginning of
4969 the PLT for this GOT entry. */
4970 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4971 + htab
->elf
.sgotplt
->output_offset
4973 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4974 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4975 loc
+ sizeof (Elf32_External_Rel
));
4980 bfd_put_32 (output_bfd
, got_offset
,
4981 resolved_plt
->contents
+ plt_offset
4982 + htab
->plt
.plt_got_offset
);
4985 /* Fill in the entry in the global offset table. Leave the entry
4986 as zero for undefined weak symbol in PIE. No PLT relocation
4987 against undefined weak symbol in PIE. */
4988 if (!local_undefweak
)
4990 if (htab
->plt
.has_plt0
)
4991 bfd_put_32 (output_bfd
,
4992 (plt
->output_section
->vma
4993 + plt
->output_offset
4995 + htab
->lazy_plt
->plt_lazy_offset
),
4996 gotplt
->contents
+ got_offset
);
4998 /* Fill in the entry in the .rel.plt section. */
4999 rel
.r_offset
= (gotplt
->output_section
->vma
5000 + gotplt
->output_offset
5002 if (h
->dynindx
== -1
5003 || ((bfd_link_executable (info
)
5004 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5006 && h
->type
== STT_GNU_IFUNC
))
5008 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5009 h
->root
.root
.string
,
5010 h
->root
.u
.def
.section
->owner
);
5012 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5013 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5014 in the .got.plt section. */
5015 bfd_put_32 (output_bfd
,
5016 (h
->root
.u
.def
.value
5017 + h
->root
.u
.def
.section
->output_section
->vma
5018 + h
->root
.u
.def
.section
->output_offset
),
5019 gotplt
->contents
+ got_offset
);
5020 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5021 /* R_386_IRELATIVE comes last. */
5022 plt_index
= htab
->next_irelative_index
--;
5026 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
5027 plt_index
= htab
->next_jump_slot_index
++;
5030 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5031 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5033 /* Don't fill the second and third slots in PLT entry for
5034 static executables nor without PLT0. */
5035 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
5037 bfd_put_32 (output_bfd
,
5038 plt_index
* sizeof (Elf32_External_Rel
),
5039 plt
->contents
+ h
->plt
.offset
5040 + htab
->lazy_plt
->plt_reloc_offset
);
5041 bfd_put_32 (output_bfd
,
5043 + htab
->lazy_plt
->plt_plt_offset
+ 4),
5044 (plt
->contents
+ h
->plt
.offset
5045 + htab
->lazy_plt
->plt_plt_offset
));
5049 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5051 bfd_vma got_offset
, plt_offset
;
5052 asection
*plt
, *got
, *gotplt
;
5053 const bfd_byte
*got_plt_entry
;
5055 /* Set the entry in the GOT procedure linkage table. */
5056 plt
= htab
->plt_got
;
5057 got
= htab
->elf
.sgot
;
5058 gotplt
= htab
->elf
.sgotplt
;
5059 got_offset
= h
->got
.offset
;
5061 if (got_offset
== (bfd_vma
) -1
5067 /* Fill in the entry in the GOT procedure linkage table. */
5068 if (! bfd_link_pic (info
))
5070 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5071 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
5075 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5076 got_offset
+= (got
->output_section
->vma
5077 + got
->output_offset
5078 - gotplt
->output_section
->vma
5079 - gotplt
->output_offset
);
5082 plt_offset
= eh
->plt_got
.offset
;
5083 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
5084 htab
->non_lazy_plt
->plt_entry_size
);
5085 bfd_put_32 (output_bfd
, got_offset
,
5086 (plt
->contents
+ plt_offset
5087 + htab
->non_lazy_plt
->plt_got_offset
));
5090 if (!local_undefweak
5092 && (h
->plt
.offset
!= (bfd_vma
) -1
5093 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5095 /* Mark the symbol as undefined, rather than as defined in
5096 the .plt section. Leave the value if there were any
5097 relocations where pointer equality matters (this is a clue
5098 for the dynamic linker, to make function pointer
5099 comparisons work between an application and shared
5100 library), otherwise set it to zero. If a function is only
5101 called from a binary, there is no need to slow down
5102 shared libraries because of that. */
5103 sym
->st_shndx
= SHN_UNDEF
;
5104 if (!h
->pointer_equality_needed
)
5108 /* Don't generate dynamic GOT relocation against undefined weak
5109 symbol in executable. */
5110 if (h
->got
.offset
!= (bfd_vma
) -1
5111 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h
)->tls_type
)
5112 && (elf_x86_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
5113 && !local_undefweak
)
5115 Elf_Internal_Rela rel
;
5116 asection
*relgot
= htab
->elf
.srelgot
;
5118 /* This symbol has an entry in the global offset table. Set it
5121 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5124 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5125 + htab
->elf
.sgot
->output_offset
5126 + (h
->got
.offset
& ~(bfd_vma
) 1));
5128 /* If this is a static link, or it is a -Bsymbolic link and the
5129 symbol is defined locally or was forced to be local because
5130 of a version file, we just want to emit a RELATIVE reloc.
5131 The entry in the global offset table will already have been
5132 initialized in the relocate_section function. */
5134 && h
->type
== STT_GNU_IFUNC
)
5136 if (h
->plt
.offset
== (bfd_vma
) -1)
5138 /* STT_GNU_IFUNC is referenced without PLT. */
5139 if (htab
->elf
.splt
== NULL
)
5141 /* use .rel[a].iplt section to store .got relocations
5142 in static executable. */
5143 relgot
= htab
->elf
.irelplt
;
5145 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5147 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5148 h
->root
.root
.string
,
5149 h
->root
.u
.def
.section
->owner
);
5151 bfd_put_32 (output_bfd
,
5152 (h
->root
.u
.def
.value
5153 + h
->root
.u
.def
.section
->output_section
->vma
5154 + h
->root
.u
.def
.section
->output_offset
),
5155 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5156 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5161 else if (bfd_link_pic (info
))
5163 /* Generate R_386_GLOB_DAT. */
5171 if (!h
->pointer_equality_needed
)
5174 /* For non-shared object, we can't use .got.plt, which
5175 contains the real function addres if we need pointer
5176 equality. We load the GOT entry with the PLT entry. */
5177 if (htab
->plt_second
!= NULL
)
5179 plt
= htab
->plt_second
;
5180 plt_offset
= eh
->plt_second
.offset
;
5184 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5185 plt_offset
= h
->plt
.offset
;
5187 bfd_put_32 (output_bfd
,
5188 (plt
->output_section
->vma
5189 + plt
->output_offset
+ plt_offset
),
5190 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5194 else if (bfd_link_pic (info
)
5195 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5197 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5198 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
5202 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5204 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5205 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5206 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
5209 elf_append_rel (output_bfd
, relgot
, &rel
);
5214 Elf_Internal_Rela rel
;
5217 /* This symbol needs a copy reloc. Set it up. */
5219 if (h
->dynindx
== -1
5220 || (h
->root
.type
!= bfd_link_hash_defined
5221 && h
->root
.type
!= bfd_link_hash_defweak
)
5222 || htab
->elf
.srelbss
== NULL
5223 || htab
->elf
.sreldynrelro
== NULL
)
5226 rel
.r_offset
= (h
->root
.u
.def
.value
5227 + h
->root
.u
.def
.section
->output_section
->vma
5228 + h
->root
.u
.def
.section
->output_offset
);
5229 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5230 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5231 s
= htab
->elf
.sreldynrelro
;
5233 s
= htab
->elf
.srelbss
;
5234 elf_append_rel (output_bfd
, s
, &rel
);
5240 /* Finish up local dynamic symbol handling. We set the contents of
5241 various dynamic sections here. */
5244 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5246 struct elf_link_hash_entry
*h
5247 = (struct elf_link_hash_entry
*) *slot
;
5248 struct bfd_link_info
*info
5249 = (struct bfd_link_info
*) inf
;
5251 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5255 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5256 here since undefined weak symbol may not be dynamic and may not be
5257 called for elf_i386_finish_dynamic_symbol. */
5260 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5263 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5264 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5266 if (h
->root
.type
!= bfd_link_hash_undefweak
5267 || h
->dynindx
!= -1)
5270 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5274 /* Used to decide how to sort relocs in an optimal manner for the
5275 dynamic linker, before writing them out. */
5277 static enum elf_reloc_type_class
5278 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5279 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5280 const Elf_Internal_Rela
*rela
)
5282 bfd
*abfd
= info
->output_bfd
;
5283 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5284 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5286 if (htab
->dynsym
!= NULL
5287 && htab
->dynsym
->contents
!= NULL
)
5289 /* Check relocation against STT_GNU_IFUNC symbol if there are
5291 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5292 if (r_symndx
!= STN_UNDEF
)
5294 Elf_Internal_Sym sym
;
5295 if (!bed
->s
->swap_symbol_in (abfd
,
5296 (htab
->dynsym
->contents
5297 + r_symndx
* sizeof (Elf32_External_Sym
)),
5301 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5302 return reloc_class_ifunc
;
5306 switch (ELF32_R_TYPE (rela
->r_info
))
5308 case R_386_IRELATIVE
:
5309 return reloc_class_ifunc
;
5310 case R_386_RELATIVE
:
5311 return reloc_class_relative
;
5312 case R_386_JUMP_SLOT
:
5313 return reloc_class_plt
;
5315 return reloc_class_copy
;
5317 return reloc_class_normal
;
5321 /* Finish up the dynamic sections. */
5324 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5325 struct bfd_link_info
*info
)
5327 struct elf_x86_link_hash_table
*htab
;
5330 const struct elf_i386_backend_data
*abed
;
5332 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
5336 dynobj
= htab
->elf
.dynobj
;
5337 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5338 abed
= get_elf_i386_backend_data (output_bfd
);
5340 if (htab
->elf
.dynamic_sections_created
)
5342 Elf32_External_Dyn
*dyncon
, *dynconend
;
5344 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5347 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5348 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5349 for (; dyncon
< dynconend
; dyncon
++)
5351 Elf_Internal_Dyn dyn
;
5354 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5359 if (abed
->os
== is_vxworks
5360 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5365 s
= htab
->elf
.sgotplt
;
5366 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5370 s
= htab
->elf
.srelplt
;
5371 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5375 s
= htab
->elf
.srelplt
;
5376 dyn
.d_un
.d_val
= s
->size
;
5380 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5383 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5385 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5386 really seem like the right value. */
5387 elf_section_data (htab
->elf
.splt
->output_section
)
5388 ->this_hdr
.sh_entsize
= 4;
5390 if (htab
->plt
.has_plt0
)
5392 /* Fill in the special first entry in the procedure linkage
5394 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
5395 htab
->lazy_plt
->plt0_entry_size
);
5396 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
5397 abed
->plt0_pad_byte
,
5398 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
5399 if (!bfd_link_pic (info
))
5401 bfd_put_32 (output_bfd
,
5402 (htab
->elf
.sgotplt
->output_section
->vma
5403 + htab
->elf
.sgotplt
->output_offset
5405 htab
->elf
.splt
->contents
5406 + htab
->lazy_plt
->plt0_got1_offset
);
5407 bfd_put_32 (output_bfd
,
5408 (htab
->elf
.sgotplt
->output_section
->vma
5409 + htab
->elf
.sgotplt
->output_offset
5411 htab
->elf
.splt
->contents
5412 + htab
->lazy_plt
->plt0_got2_offset
);
5414 if (abed
->os
== is_vxworks
)
5416 Elf_Internal_Rela rel
;
5417 int num_plts
= (htab
->elf
.splt
->size
5418 / htab
->plt
.plt_entry_size
) - 1;
5420 asection
*srelplt2
= htab
->srelplt2
;
5422 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5423 + 4. On IA32 we use REL relocations so the
5424 addend goes in the PLT directly. */
5425 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5426 + htab
->elf
.splt
->output_offset
5427 + htab
->lazy_plt
->plt0_got1_offset
);
5428 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5430 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5431 srelplt2
->contents
);
5432 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5434 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5435 + htab
->elf
.splt
->output_offset
5436 + htab
->lazy_plt
->plt0_got2_offset
);
5437 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5439 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5440 srelplt2
->contents
+
5441 sizeof (Elf32_External_Rel
));
5442 /* Correct the .rel.plt.unloaded relocations. */
5443 p
= srelplt2
->contents
;
5444 if (bfd_link_pic (info
))
5445 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
5447 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
5449 for (; num_plts
; num_plts
--)
5451 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5452 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5454 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5455 p
+= sizeof (Elf32_External_Rel
);
5457 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5458 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
5460 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5461 p
+= sizeof (Elf32_External_Rel
);
5468 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
5469 elf_section_data (htab
->plt_got
->output_section
)
5470 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
5472 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
5473 elf_section_data (htab
->plt_second
->output_section
)
5474 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
5477 /* Fill in the first three entries in the global offset table. */
5478 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
5480 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5483 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5487 bfd_put_32 (output_bfd
,
5489 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
5490 htab
->elf
.sgotplt
->contents
);
5491 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
5492 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
5494 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
5497 /* Adjust .eh_frame for .plt section. */
5498 if (htab
->plt_eh_frame
!= NULL
5499 && htab
->plt_eh_frame
->contents
!= NULL
)
5501 if (htab
->elf
.splt
!= NULL
5502 && htab
->elf
.splt
->size
!= 0
5503 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5504 && htab
->elf
.splt
->output_section
!= NULL
5505 && htab
->plt_eh_frame
->output_section
!= NULL
)
5507 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5508 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5509 + htab
->plt_eh_frame
->output_offset
5510 + PLT_FDE_START_OFFSET
;
5511 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5512 htab
->plt_eh_frame
->contents
5513 + PLT_FDE_START_OFFSET
);
5515 if (htab
->plt_eh_frame
->sec_info_type
5516 == SEC_INFO_TYPE_EH_FRAME
)
5518 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5520 htab
->plt_eh_frame
->contents
))
5525 /* Adjust .eh_frame for .plt.got section. */
5526 if (htab
->plt_got_eh_frame
!= NULL
5527 && htab
->plt_got_eh_frame
->contents
!= NULL
)
5529 if (htab
->plt_got
!= NULL
5530 && htab
->plt_got
->size
!= 0
5531 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
5532 && htab
->plt_got
->output_section
!= NULL
5533 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
5535 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
5536 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
5537 + htab
->plt_got_eh_frame
->output_offset
5538 + PLT_FDE_START_OFFSET
;
5539 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5540 htab
->plt_got_eh_frame
->contents
5541 + PLT_FDE_START_OFFSET
);
5543 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5545 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5546 htab
->plt_got_eh_frame
,
5547 htab
->plt_got_eh_frame
->contents
))
5552 /* Adjust .eh_frame for the second PLT section. */
5553 if (htab
->plt_second_eh_frame
!= NULL
5554 && htab
->plt_second_eh_frame
->contents
!= NULL
)
5556 if (htab
->plt_second
!= NULL
5557 && htab
->plt_second
->size
!= 0
5558 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
5559 && htab
->plt_second
->output_section
!= NULL
5560 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
5562 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
5563 bfd_vma eh_frame_start
5564 = (htab
->plt_second_eh_frame
->output_section
->vma
5565 + htab
->plt_second_eh_frame
->output_offset
5566 + PLT_FDE_START_OFFSET
);
5567 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5568 htab
->plt_second_eh_frame
->contents
5569 + PLT_FDE_START_OFFSET
);
5571 if (htab
->plt_second_eh_frame
->sec_info_type
5572 == SEC_INFO_TYPE_EH_FRAME
)
5574 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5575 htab
->plt_second_eh_frame
,
5576 htab
->plt_second_eh_frame
->contents
))
5581 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5582 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5584 /* Fill PLT entries for undefined weak symbols in PIE. */
5585 if (bfd_link_pie (info
))
5586 bfd_hash_traverse (&info
->hash
->table
,
5587 elf_i386_pie_finish_undefweak_symbol
,
5593 /* Fill PLT/GOT entries and allocate dynamic relocations for local
5594 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
5595 It has to be done before elf_link_sort_relocs is called so that
5596 dynamic relocations are properly sorted. */
5599 elf_i386_output_arch_local_syms
5600 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5601 struct bfd_link_info
*info
,
5602 void *flaginfo ATTRIBUTE_UNUSED
,
5603 int (*func
) (void *, const char *,
5606 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
5608 struct elf_x86_link_hash_table
*htab
5609 = elf_x86_hash_table (info
, I386_ELF_DATA
);
5613 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5614 htab_traverse (htab
->loc_hash_table
,
5615 elf_i386_finish_local_dynamic_symbol
,
5621 /* Forward declaration. */
5622 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
;
5624 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
5625 dynamic relocations. */
5628 elf_i386_get_synthetic_symtab (bfd
*abfd
,
5629 long symcount ATTRIBUTE_UNUSED
,
5630 asymbol
**syms ATTRIBUTE_UNUSED
,
5637 bfd_byte
*plt_contents
;
5639 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
5640 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
5641 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
5642 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
5645 enum elf_x86_plt_type plt_type
;
5646 struct elf_x86_plt plts
[] =
5648 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
5649 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
5650 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
5651 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
5656 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
5659 if (dynsymcount
<= 0)
5662 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
5666 non_lazy_plt
= NULL
;
5667 /* Silence GCC 6. */
5669 non_lazy_ibt_plt
= NULL
;
5670 lazy_ibt_plt
= NULL
;
5671 switch (get_elf_i386_backend_data (abfd
)->os
)
5674 non_lazy_plt
= &elf_i386_non_lazy_plt
;
5675 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
5676 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
5679 lazy_plt
= &elf_i386_lazy_plt
;
5682 lazy_plt
= &elf_i386_nacl_plt
;
5689 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
5691 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
5692 if (plt
== NULL
|| plt
->size
== 0)
5695 /* Get the PLT section contents. */
5696 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
5697 if (plt_contents
== NULL
)
5699 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
5700 plt_contents
, 0, plt
->size
))
5702 free (plt_contents
);
5706 /* Check what kind of PLT it is. */
5707 plt_type
= plt_unknown
;
5708 if (plts
[j
].type
== plt_unknown
5709 && (plt
->size
>= (lazy_plt
->plt0_entry_size
5710 + lazy_plt
->plt_entry_size
)))
5712 /* Match lazy PLT first. */
5713 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
5714 lazy_plt
->plt0_got1_offset
) == 0)
5716 /* The fist entry in the lazy IBT PLT is the same as the
5718 if (lazy_ibt_plt
!= NULL
5719 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
5720 lazy_ibt_plt
->plt_entry
,
5721 lazy_ibt_plt
->plt_got_offset
) == 0))
5722 plt_type
= plt_lazy
| plt_second
;
5724 plt_type
= plt_lazy
;
5726 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
5727 lazy_plt
->plt0_got1_offset
) == 0)
5729 /* The fist entry in the PIC lazy IBT PLT is the same as
5730 the normal PIC lazy PLT. */
5731 if (lazy_ibt_plt
!= NULL
5732 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
5733 lazy_ibt_plt
->pic_plt_entry
,
5734 lazy_ibt_plt
->plt_got_offset
) == 0))
5735 plt_type
= plt_lazy
| plt_pic
| plt_second
;
5737 plt_type
= plt_lazy
| plt_pic
;
5741 if (non_lazy_plt
!= NULL
5742 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
5743 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
5745 /* Match non-lazy PLT. */
5746 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
5747 non_lazy_plt
->plt_got_offset
) == 0)
5748 plt_type
= plt_non_lazy
;
5749 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
5750 non_lazy_plt
->plt_got_offset
) == 0)
5754 if ((non_lazy_ibt_plt
!= NULL
)
5755 && (plt_type
== plt_unknown
|| plt_type
== plt_second
)
5756 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
)
5758 if (memcmp (plt_contents
,
5759 non_lazy_ibt_plt
->plt_entry
,
5760 non_lazy_ibt_plt
->plt_got_offset
) == 0)
5762 /* Match IBT PLT. */
5763 plt_type
= plt_second
;
5764 non_lazy_plt
= non_lazy_ibt_plt
;
5766 else if (memcmp (plt_contents
,
5767 non_lazy_ibt_plt
->pic_plt_entry
,
5768 non_lazy_ibt_plt
->plt_got_offset
) == 0)
5770 /* Match PIC IBT PLT. */
5771 plt_type
= plt_second
| plt_pic
;
5772 non_lazy_plt
= non_lazy_ibt_plt
;
5776 if (plt_type
== plt_unknown
)
5778 free (plt_contents
);
5783 plts
[j
].type
= plt_type
;
5785 if ((plt_type
& plt_lazy
))
5787 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
5788 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
5789 /* Skip PLT0 in lazy PLT. */
5794 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
5795 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
5799 /* Skip lazy PLT when the second PLT is used. */
5800 if ((plt_type
& (plt_lazy
| plt_second
))
5801 == (plt_lazy
| plt_second
))
5805 n
= plt
->size
/ plts
[j
].plt_entry_size
;
5810 plts
[j
].contents
= plt_contents
;
5812 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
5813 if ((plt_type
& plt_pic
))
5814 got_addr
= (bfd_vma
) -1;
5817 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
5818 got_addr
, plts
, dynsyms
,
5822 /* Set up i386 GNU properties. Return the first relocatable ELF input
5823 with GNU properties if found. Otherwise, return NULL. */
5826 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
5828 bfd_boolean normal_target
;
5829 bfd_boolean lazy_plt
;
5830 asection
*sec
, *pltsec
;
5832 bfd_boolean use_ibt_plt
;
5833 unsigned int plt_alignment
, features
;
5834 struct elf_x86_link_hash_table
*htab
;
5841 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
5843 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
5845 /* Find a normal input file with GNU property note. */
5846 for (pbfd
= info
->input_bfds
;
5848 pbfd
= pbfd
->link
.next
)
5849 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
5850 && bfd_count_sections (pbfd
) != 0)
5854 if (elf_properties (pbfd
) != NULL
)
5858 if (ebfd
!= NULL
&& features
)
5860 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
5861 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
5862 prop
= _bfd_elf_get_property (ebfd
,
5863 GNU_PROPERTY_X86_FEATURE_1_AND
,
5865 prop
->u
.number
|= features
;
5866 prop
->pr_kind
= property_number
;
5868 /* Create the GNU property note section if needed. */
5871 sec
= bfd_make_section_with_flags (ebfd
,
5872 NOTE_GNU_PROPERTY_SECTION_NAME
,
5880 info
->callbacks
->einfo (_("%F: failed to create GNU property section\n"));
5882 if (!bfd_set_section_alignment (ebfd
, sec
, 2))
5885 info
->callbacks
->einfo (_("%F%A: failed to align section\n"),
5889 elf_section_type (sec
) = SHT_NOTE
;
5893 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
5895 if (bfd_link_relocatable (info
))
5898 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
5902 use_ibt_plt
= info
->ibtplt
|| info
->ibt
;
5903 if (!use_ibt_plt
&& pbfd
!= NULL
)
5905 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
5906 elf_property_list
*p
;
5908 /* The property list is sorted in order of type. */
5909 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
5911 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
5913 use_ibt_plt
= !!(p
->property
.u
.number
5914 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
5917 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
5922 dynobj
= htab
->elf
.dynobj
;
5924 /* Set htab->elf.dynobj here so that there is no need to check and
5925 set it in check_relocs. */
5930 htab
->elf
.dynobj
= pbfd
;
5937 /* Find a normal input file to hold linker created
5939 for (abfd
= info
->input_bfds
;
5941 abfd
= abfd
->link
.next
)
5942 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
5944 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0)
5946 htab
->elf
.dynobj
= abfd
;
5953 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
5954 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
5955 canonical function address. */
5956 htab
->plt
.has_plt0
= 1;
5957 normal_target
= FALSE
;
5959 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
5964 htab
->lazy_plt
= &elf_i386_lazy_ibt_plt
;
5965 htab
->non_lazy_plt
= &elf_i386_non_lazy_ibt_plt
;
5969 htab
->lazy_plt
= &elf_i386_lazy_plt
;
5970 htab
->non_lazy_plt
= &elf_i386_non_lazy_plt
;
5972 normal_target
= TRUE
;
5975 htab
->lazy_plt
= &elf_i386_lazy_plt
;
5976 htab
->non_lazy_plt
= NULL
;
5977 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
,
5979 info
->callbacks
->einfo (_("%F: failed to create VxWorks dynamic sections\n"));
5982 htab
->lazy_plt
= &elf_i386_nacl_plt
;
5983 htab
->non_lazy_plt
= NULL
;
5987 pltsec
= htab
->elf
.splt
;
5989 /* If the non-lazy PLT is available, use it for all PLT entries if
5990 there are no PLT0 or no .plt section. */
5991 if (htab
->non_lazy_plt
!= NULL
5992 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
5995 if (bfd_link_pic (info
))
5996 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
5998 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->plt_entry
;
5999 htab
->plt
.plt_entry_size
= htab
->non_lazy_plt
->plt_entry_size
;
6000 htab
->plt
.plt_got_offset
= htab
->non_lazy_plt
->plt_got_offset
;
6001 htab
->plt
.eh_frame_plt_size
6002 = htab
->non_lazy_plt
->eh_frame_plt_size
;
6003 htab
->plt
.eh_frame_plt
= htab
->non_lazy_plt
->eh_frame_plt
;
6008 if (bfd_link_pic (info
))
6010 htab
->plt
.plt0_entry
= htab
->lazy_plt
->pic_plt0_entry
;
6011 htab
->plt
.plt_entry
= htab
->lazy_plt
->pic_plt_entry
;
6015 htab
->plt
.plt0_entry
= htab
->lazy_plt
->plt0_entry
;
6016 htab
->plt
.plt_entry
= htab
->lazy_plt
->plt_entry
;
6019 htab
->plt
.plt_entry_size
= htab
->lazy_plt
->plt_entry_size
;
6020 htab
->plt
.plt_got_offset
= htab
->lazy_plt
->plt_got_offset
;
6021 htab
->plt
.eh_frame_plt_size
= htab
->lazy_plt
->eh_frame_plt_size
;
6022 htab
->plt
.eh_frame_plt
= htab
->lazy_plt
->eh_frame_plt
;
6025 /* This is unused for i386. */
6026 htab
->plt
.plt_got_insn_size
= 0;
6028 /* Return if there are no normal input files. */
6032 /* Since create_dynamic_sections isn't always called, but GOT
6033 relocations need GOT sections, create them here so that we
6034 don't need to do it in check_relocs. */
6035 if (htab
->elf
.sgot
== NULL
6036 && !_bfd_elf_create_got_section (dynobj
, info
))
6037 info
->callbacks
->einfo (_("%F: failed to create GOT sections\n"));
6039 /* Create the ifunc sections here so that check_relocs can be
6041 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
6042 info
->callbacks
->einfo (_("%F: failed to create ifunc sections\n"));
6044 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
6048 /* Whe creating executable, set the contents of the .interp
6049 section to the interpreter. */
6050 if (bfd_link_executable (info
) && !info
->nointerp
)
6052 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
6055 s
->size
= htab
->dynamic_interpreter_size
;
6056 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
6060 /* Don't change PLT section alignment for NaCl since it uses
6061 64-byte PLT entry and sets PLT section alignment to 32
6065 const struct elf_backend_data
*bed
6066 = get_elf_backend_data (dynobj
);
6067 flagword pltflags
= (bed
->dynamic_sec_flags
6072 unsigned int non_lazy_plt_alignment
6073 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
6076 if (!bfd_set_section_alignment (sec
->owner
, sec
,
6078 goto error_alignment
;
6080 /* Create the GOT procedure linkage table. */
6081 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6085 info
->callbacks
->einfo (_("%F: failed to create GOT PLT section\n"));
6087 if (!bfd_set_section_alignment (dynobj
, sec
,
6088 non_lazy_plt_alignment
))
6089 goto error_alignment
;
6091 htab
->plt_got
= sec
;
6099 /* Create the second PLT for Intel IBT support. IBT
6100 PLT is supported only for non-NaCl target and is
6101 is needed only for lazy binding. */
6102 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6106 info
->callbacks
->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
6108 if (!bfd_set_section_alignment (dynobj
, sec
,
6110 goto error_alignment
;
6113 htab
->plt_second
= sec
;
6117 if (!info
->no_ld_generated_unwind_info
)
6119 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
6120 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6121 | SEC_LINKER_CREATED
);
6123 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6127 info
->callbacks
->einfo (_("%F: failed to create PLT .eh_frame section\n"));
6129 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
6130 goto error_alignment
;
6132 htab
->plt_eh_frame
= sec
;
6134 if (htab
->plt_got
!= NULL
)
6136 sec
= bfd_make_section_anyway_with_flags (dynobj
,
6140 info
->callbacks
->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
6142 if (!bfd_set_section_alignment (dynobj
, sec
, 2))
6143 goto error_alignment
;
6145 htab
->plt_got_eh_frame
= sec
;
6152 /* The .iplt section is used for IFUNC symbols in static
6154 sec
= htab
->elf
.iplt
;
6156 && !bfd_set_section_alignment (sec
->owner
, sec
,
6158 goto error_alignment
;
6164 #define TARGET_LITTLE_SYM i386_elf32_vec
6165 #define TARGET_LITTLE_NAME "elf32-i386"
6166 #define ELF_ARCH bfd_arch_i386
6167 #define ELF_TARGET_ID I386_ELF_DATA
6168 #define ELF_MACHINE_CODE EM_386
6169 #define ELF_MAXPAGESIZE 0x1000
6171 #define elf_backend_can_gc_sections 1
6172 #define elf_backend_can_refcount 1
6173 #define elf_backend_want_got_plt 1
6174 #define elf_backend_plt_readonly 1
6175 #define elf_backend_want_plt_sym 0
6176 #define elf_backend_got_header_size 12
6177 #define elf_backend_plt_alignment 4
6178 #define elf_backend_dtrel_excludes_plt 1
6179 #define elf_backend_extern_protected_data 1
6180 #define elf_backend_caches_rawsize 1
6181 #define elf_backend_want_dynrelro 1
6183 /* Support RELA for objdump of prelink objects. */
6184 #define elf_info_to_howto elf_i386_info_to_howto_rel
6185 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
6187 #define bfd_elf32_mkobject elf_i386_mkobject
6189 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
6190 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
6191 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
6192 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
6194 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
6195 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
6196 #define elf_backend_check_relocs elf_i386_check_relocs
6197 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
6198 #define elf_backend_fake_sections elf_i386_fake_sections
6199 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
6200 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
6201 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
6202 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
6203 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
6204 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
6205 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
6206 #define elf_backend_relocate_section elf_i386_relocate_section
6207 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
6208 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
6210 #include "elf32-target.h"
6212 /* FreeBSD support. */
6214 #undef TARGET_LITTLE_SYM
6215 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
6216 #undef TARGET_LITTLE_NAME
6217 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
6219 #define ELF_OSABI ELFOSABI_FREEBSD
6221 /* The kernel recognizes executables as valid only if they carry a
6222 "FreeBSD" label in the ELF header. So we put this label on all
6223 executables and (for simplicity) also all other object files. */
6226 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
6228 _bfd_elf_post_process_headers (abfd
, info
);
6230 #ifdef OLD_FREEBSD_ABI_LABEL
6232 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
6233 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
6234 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
6239 #undef elf_backend_post_process_headers
6240 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
6242 #define elf32_bed elf32_i386_fbsd_bed
6244 #undef elf_backend_add_symbol_hook
6246 #include "elf32-target.h"
6250 #undef TARGET_LITTLE_SYM
6251 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
6252 #undef TARGET_LITTLE_NAME
6253 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
6255 #undef elf_backend_post_process_headers
6257 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
6258 objects won't be recognized. */
6262 #define elf32_bed elf32_i386_sol2_bed
6264 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
6266 #undef elf_backend_static_tls_alignment
6267 #define elf_backend_static_tls_alignment 8
6269 /* The Solaris 2 ABI requires a plt symbol on all platforms.
6271 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
6273 #undef elf_backend_want_plt_sym
6274 #define elf_backend_want_plt_sym 1
6276 #undef elf_backend_strtab_flags
6277 #define elf_backend_strtab_flags SHF_STRINGS
6279 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
6280 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
6281 FALSE otherwise. ISECTION is the best guess matching section from the
6282 input bfd IBFD, but it might be NULL. */
6285 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
6286 bfd
*obfd ATTRIBUTE_UNUSED
,
6287 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
6288 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
6290 /* PR 19938: FIXME: Need to add code for setting the sh_info
6291 and sh_link fields of Solaris specific section types. */
6294 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
6295 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
6297 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
6299 The following values should be set:
6302 -----------------------------------------------------------------------------
6303 SHT_SUNW_ancillary The section header index of 0
6304 [0x6fffffee] the associated string table.
6306 SHT_SUNW_capinfo The section header index of For a dynamic object, the
6307 [0x6ffffff0] the associated symbol table. section header index of
6309 SHT_SUNW_capchain table,
6312 SHT_SUNW_symsort The section header index of 0
6313 [0x6ffffff1] the associated symbol table.
6315 SHT_SUNW_tlssort The section header index of 0
6316 [0x6ffffff2] the associated symbol table.
6318 SHT_SUNW_LDYNSYM The section header index of One greater than the
6319 [0x6ffffff3] the associated string table. symbol table index of the
6320 This index is the same string last local symbol,
6321 table used by the SHT_DYNSYM STB_LOCAL. Since
6322 section. SHT_SUNW_LDYNSYM only
6323 contains local symbols,
6324 sh_info is equivalent to
6325 the number of symbols in
6328 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
6329 [0x6ffffff5] the section header index of to named strings, the
6330 the associated section header index of
6331 SHT_SUNW_capinfo table, the associated string
6332 otherwise 0. table, otherwise 0.
6334 SHT_SUNW_move The section header index of 0
6335 [0x6ffffffa] the associated symbol table.
6340 SHT_SUNW_syminfo The section header index of The section header index
6341 [0x6ffffffc] the associated symbol table. of the associated
6344 SHT_SUNW_verdef The section header index of The number of version
6345 [0x6ffffffd] the associated string table. definitions within the
6348 SHT_SUNW_verneed The section header index of The number of version
6349 [0x6ffffffe] the associated string table. dependencies within the
6352 SHT_SUNW_versym The section header index of 0
6353 [0x6fffffff] the associated symbol table. */
6356 #undef elf_backend_copy_special_section_fields
6357 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
6359 #include "elf32-target.h"
6361 /* Intel MCU support. */
6364 elf32_iamcu_elf_object_p (bfd
*abfd
)
6366 /* Set the right machine number for an IAMCU elf32 file. */
6367 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
6371 #undef TARGET_LITTLE_SYM
6372 #define TARGET_LITTLE_SYM iamcu_elf32_vec
6373 #undef TARGET_LITTLE_NAME
6374 #define TARGET_LITTLE_NAME "elf32-iamcu"
6376 #define ELF_ARCH bfd_arch_iamcu
6378 #undef ELF_MACHINE_CODE
6379 #define ELF_MACHINE_CODE EM_IAMCU
6384 #define elf32_bed elf32_iamcu_bed
6386 #undef elf_backend_object_p
6387 #define elf_backend_object_p elf32_iamcu_elf_object_p
6389 #undef elf_backend_static_tls_alignment
6391 #undef elf_backend_want_plt_sym
6392 #define elf_backend_want_plt_sym 0
6394 #undef elf_backend_strtab_flags
6395 #undef elf_backend_copy_special_section_fields
6397 #include "elf32-target.h"
6399 /* Restore defaults. */
6401 #define ELF_ARCH bfd_arch_i386
6402 #undef ELF_MACHINE_CODE
6403 #define ELF_MACHINE_CODE EM_386
6405 /* Native Client support. */
6407 #undef TARGET_LITTLE_SYM
6408 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
6409 #undef TARGET_LITTLE_NAME
6410 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
6412 #define elf32_bed elf32_i386_nacl_bed
6414 #undef ELF_MAXPAGESIZE
6415 #define ELF_MAXPAGESIZE 0x10000
6417 /* Restore defaults. */
6419 #undef elf_backend_want_plt_sym
6420 #define elf_backend_want_plt_sym 0
6421 #undef elf_backend_post_process_headers
6422 #undef elf_backend_static_tls_alignment
6424 /* NaCl uses substantially different PLT entries for the same effects. */
6426 #undef elf_backend_plt_alignment
6427 #define elf_backend_plt_alignment 5
6428 #define NACL_PLT_ENTRY_SIZE 64
6429 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
6431 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
6433 0xff, 0x35, /* pushl contents of address */
6434 0, 0, 0, 0, /* replaced with address of .got + 4. */
6435 0x8b, 0x0d, /* movl contents of address, %ecx */
6436 0, 0, 0, 0, /* replaced with address of .got + 8. */
6437 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6438 0xff, 0xe1 /* jmp *%ecx */
6441 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6443 0x8b, 0x0d, /* movl contents of address, %ecx */
6444 0, 0, 0, 0, /* replaced with GOT slot address. */
6445 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6446 0xff, 0xe1, /* jmp *%ecx */
6448 /* Pad to the next 32-byte boundary with nop instructions. */
6450 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6451 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6453 /* Lazy GOT entries point here (32-byte aligned). */
6454 0x68, /* pushl immediate */
6455 0, 0, 0, 0, /* replaced with reloc offset. */
6456 0xe9, /* jmp relative */
6457 0, 0, 0, 0, /* replaced with offset to .plt. */
6459 /* Pad to the next 32-byte boundary with nop instructions. */
6460 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6461 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6465 static const bfd_byte
6466 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
6468 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
6469 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
6470 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
6471 0xff, 0xe1, /* jmp *%ecx */
6473 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
6474 so pad to that size with nop instructions. */
6475 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
6478 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6480 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
6481 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
6482 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
6483 0xff, 0xe1, /* jmp *%ecx */
6485 /* Pad to the next 32-byte boundary with nop instructions. */
6487 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6488 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6490 /* Lazy GOT entries point here (32-byte aligned). */
6491 0x68, /* pushl immediate */
6492 0, 0, 0, 0, /* replaced with offset into relocation table. */
6493 0xe9, /* jmp relative */
6494 0, 0, 0, 0, /* replaced with offset to start of .plt. */
6496 /* Pad to the next 32-byte boundary with nop instructions. */
6497 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6498 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6502 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
6504 #if (PLT_CIE_LENGTH != 20 \
6505 || PLT_FDE_LENGTH != 36 \
6506 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
6507 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
6508 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
6510 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
6511 0, 0, 0, 0, /* CIE ID */
6512 1, /* CIE version */
6513 'z', 'R', 0, /* Augmentation string */
6514 1, /* Code alignment factor */
6515 0x7c, /* Data alignment factor: -4 */
6516 8, /* Return address column */
6517 1, /* Augmentation size */
6518 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
6519 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
6520 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
6521 DW_CFA_nop
, DW_CFA_nop
,
6523 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
6524 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
6525 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
6526 0, 0, 0, 0, /* .plt size goes here */
6527 0, /* Augmentation size */
6528 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
6529 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
6530 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
6531 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
6532 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
6533 13, /* Block length */
6534 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
6535 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
6536 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
6537 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
6538 DW_CFA_nop
, DW_CFA_nop
6541 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
=
6543 elf_i386_nacl_plt0_entry
, /* plt0_entry */
6544 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
6545 elf_i386_nacl_plt_entry
, /* plt_entry */
6546 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
6547 2, /* plt0_got1_offset */
6548 8, /* plt0_got2_offset */
6549 0, /* plt0_got2_insn_end */
6550 2, /* plt_got_offset */
6551 33, /* plt_reloc_offset */
6552 38, /* plt_plt_offset */
6553 0, /* plt_got_insn_size */
6554 0, /* plt_plt_insn_end */
6555 32, /* plt_lazy_offset */
6556 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
6557 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
6558 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
6559 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
6562 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
6564 0x90, /* plt0_pad_byte: nop insn */
6569 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
6571 /* Set the right machine number for a NaCl i386 ELF32 file. */
6572 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
6576 #undef elf_backend_arch_data
6577 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
6579 #undef elf_backend_object_p
6580 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
6581 #undef elf_backend_modify_segment_map
6582 #define elf_backend_modify_segment_map nacl_modify_segment_map
6583 #undef elf_backend_modify_program_headers
6584 #define elf_backend_modify_program_headers nacl_modify_program_headers
6585 #undef elf_backend_final_write_processing
6586 #define elf_backend_final_write_processing nacl_final_write_processing
6588 #include "elf32-target.h"
6590 /* Restore defaults. */
6591 #undef elf_backend_object_p
6592 #undef elf_backend_modify_segment_map
6593 #undef elf_backend_modify_program_headers
6594 #undef elf_backend_final_write_processing
6596 /* VxWorks support. */
6598 #undef TARGET_LITTLE_SYM
6599 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
6600 #undef TARGET_LITTLE_NAME
6601 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
6603 #undef ELF_MAXPAGESIZE
6604 #define ELF_MAXPAGESIZE 0x1000
6605 #undef elf_backend_plt_alignment
6606 #define elf_backend_plt_alignment 4
6608 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
6610 0x90, /* plt0_pad_byte */
6614 #undef elf_backend_arch_data
6615 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
6617 #undef elf_backend_relocs_compatible
6618 #undef elf_backend_add_symbol_hook
6619 #define elf_backend_add_symbol_hook \
6620 elf_vxworks_add_symbol_hook
6621 #undef elf_backend_link_output_symbol_hook
6622 #define elf_backend_link_output_symbol_hook \
6623 elf_vxworks_link_output_symbol_hook
6624 #undef elf_backend_emit_relocs
6625 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
6626 #undef elf_backend_final_write_processing
6627 #define elf_backend_final_write_processing \
6628 elf_vxworks_final_write_processing
6629 #undef elf_backend_static_tls_alignment
6631 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
6633 #undef elf_backend_want_plt_sym
6634 #define elf_backend_want_plt_sym 1
6637 #define elf32_bed elf32_i386_vxworks_bed
6639 #include "elf32-target.h"