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)
876 #define elf_i386_compute_jump_table_size(htab) \
877 ((htab)->elf.srelplt->reloc_count * 4)
879 /* Return TRUE if the TLS access code sequence support transition
883 elf_i386_check_tls_transition (asection
*sec
,
885 Elf_Internal_Shdr
*symtab_hdr
,
886 struct elf_link_hash_entry
**sym_hashes
,
888 const Elf_Internal_Rela
*rel
,
889 const Elf_Internal_Rela
*relend
)
891 unsigned int val
, type
, reg
;
892 unsigned long r_symndx
;
893 struct elf_link_hash_entry
*h
;
896 bfd_boolean indirect_call
;
898 offset
= rel
->r_offset
;
903 if (offset
< 2 || (rel
+ 1) >= relend
)
906 indirect_call
= FALSE
;
907 call
= contents
+ offset
+ 4;
910 if (r_type
== R_386_TLS_GD
)
912 /* Check transition from GD access model. Only
913 leal foo@tlsgd(,%ebx,1), %eax
914 call ___tls_get_addr@PLT
916 leal foo@tlsgd(%ebx) %eax
917 call ___tls_get_addr@PLT
920 leal foo@tlsgd(%reg), %eax
921 call *___tls_get_addr@GOT(%reg)
922 which may be converted to
923 addr32 call ___tls_get_addr
924 can transit to different access model. */
925 if ((offset
+ 10) > sec
->size
926 || (type
!= 0x8d && type
!= 0x04))
931 /* leal foo@tlsgd(,%ebx,1), %eax
932 call ___tls_get_addr@PLT */
936 if (*(call
- 7) != 0x8d
944 leal foo@tlsgd(%ebx), %eax
945 call ___tls_get_addr@PLT
948 leal foo@tlsgd(%reg), %eax
949 call *___tls_get_addr@GOT(%reg)
950 which may be converted to
951 addr32 call ___tls_get_addr
953 %eax can't be used as the GOT base register since it
954 is used to pass parameter to ___tls_get_addr. */
956 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
959 indirect_call
= call
[0] == 0xff;
960 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
961 && !(call
[0] == 0x67 && call
[1] == 0xe8)
963 && (call
[1] & 0xf8) == 0x90
964 && (call
[1] & 0x7) == reg
))
970 /* Check transition from LD access model. Only
971 leal foo@tlsldm(%ebx), %eax
972 call ___tls_get_addr@PLT
974 leal foo@tlsldm(%reg), %eax
975 call *___tls_get_addr@GOT(%reg)
976 which may be converted to
977 addr32 call ___tls_get_addr
978 can transit to different access model. */
979 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
982 /* %eax can't be used as the GOT base register since it is
983 used to pass parameter to ___tls_get_addr. */
985 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
988 indirect_call
= call
[0] == 0xff;
989 if (!(reg
== 3 && call
[0] == 0xe8)
990 && !(call
[0] == 0x67 && call
[1] == 0xe8)
992 && (call
[1] & 0xf8) == 0x90
993 && (call
[1] & 0x7) == reg
))
997 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
998 if (r_symndx
< symtab_hdr
->sh_info
)
1001 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1003 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1005 else if (indirect_call
)
1006 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
1008 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1009 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
1012 /* Check transition from IE access model:
1013 movl foo@indntpoff(%rip), %eax
1014 movl foo@indntpoff(%rip), %reg
1015 addl foo@indntpoff(%rip), %reg
1018 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1021 /* Check "movl foo@tpoff(%rip), %eax" first. */
1022 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1029 /* Check movl|addl foo@tpoff(%rip), %reg. */
1030 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1031 return ((type
== 0x8b || type
== 0x03)
1032 && (val
& 0xc7) == 0x05);
1034 case R_386_TLS_GOTIE
:
1035 case R_386_TLS_IE_32
:
1036 /* Check transition from {IE_32,GOTIE} access model:
1037 subl foo@{tpoff,gontoff}(%reg1), %reg2
1038 movl foo@{tpoff,gontoff}(%reg1), %reg2
1039 addl foo@{tpoff,gontoff}(%reg1), %reg2
1042 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1045 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1046 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1049 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1050 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1052 case R_386_TLS_GOTDESC
:
1053 /* Check transition from GDesc access model:
1054 leal x@tlsdesc(%ebx), %eax
1056 Make sure it's a leal adding ebx to a 32-bit offset
1057 into any register, although it's probably almost always
1060 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1063 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1066 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1067 return (val
& 0xc7) == 0x83;
1069 case R_386_TLS_DESC_CALL
:
1070 /* Check transition from GDesc access model:
1071 call *x@tlsdesc(%eax)
1073 if (offset
+ 2 <= sec
->size
)
1075 /* Make sure that it's a call *x@tlsdesc(%eax). */
1076 call
= contents
+ offset
;
1077 return call
[0] == 0xff && call
[1] == 0x10;
1087 /* Return TRUE if the TLS access transition is OK or no transition
1088 will be performed. Update R_TYPE if there is a transition. */
1091 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1092 asection
*sec
, bfd_byte
*contents
,
1093 Elf_Internal_Shdr
*symtab_hdr
,
1094 struct elf_link_hash_entry
**sym_hashes
,
1095 unsigned int *r_type
, int tls_type
,
1096 const Elf_Internal_Rela
*rel
,
1097 const Elf_Internal_Rela
*relend
,
1098 struct elf_link_hash_entry
*h
,
1099 unsigned long r_symndx
,
1100 bfd_boolean from_relocate_section
)
1102 unsigned int from_type
= *r_type
;
1103 unsigned int to_type
= from_type
;
1104 bfd_boolean check
= TRUE
;
1106 /* Skip TLS transition for functions. */
1108 && (h
->type
== STT_FUNC
1109 || h
->type
== STT_GNU_IFUNC
))
1115 case R_386_TLS_GOTDESC
:
1116 case R_386_TLS_DESC_CALL
:
1117 case R_386_TLS_IE_32
:
1119 case R_386_TLS_GOTIE
:
1120 if (bfd_link_executable (info
))
1123 to_type
= R_386_TLS_LE_32
;
1124 else if (from_type
!= R_386_TLS_IE
1125 && from_type
!= R_386_TLS_GOTIE
)
1126 to_type
= R_386_TLS_IE_32
;
1129 /* When we are called from elf_i386_relocate_section, there may
1130 be additional transitions based on TLS_TYPE. */
1131 if (from_relocate_section
)
1133 unsigned int new_to_type
= to_type
;
1135 if (bfd_link_executable (info
)
1138 && (tls_type
& GOT_TLS_IE
))
1139 new_to_type
= R_386_TLS_LE_32
;
1141 if (to_type
== R_386_TLS_GD
1142 || to_type
== R_386_TLS_GOTDESC
1143 || to_type
== R_386_TLS_DESC_CALL
)
1145 if (tls_type
== GOT_TLS_IE_POS
)
1146 new_to_type
= R_386_TLS_GOTIE
;
1147 else if (tls_type
& GOT_TLS_IE
)
1148 new_to_type
= R_386_TLS_IE_32
;
1151 /* We checked the transition before when we were called from
1152 elf_i386_check_relocs. We only want to check the new
1153 transition which hasn't been checked before. */
1154 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1155 to_type
= new_to_type
;
1161 if (bfd_link_executable (info
))
1162 to_type
= R_386_TLS_LE_32
;
1169 /* Return TRUE if there is no transition. */
1170 if (from_type
== to_type
)
1173 /* Check if the transition can be performed. */
1175 && ! elf_i386_check_tls_transition (sec
, contents
,
1176 symtab_hdr
, sym_hashes
,
1177 from_type
, rel
, relend
))
1179 reloc_howto_type
*from
, *to
;
1182 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1183 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1186 name
= h
->root
.root
.string
;
1189 struct elf_x86_link_hash_table
*htab
;
1191 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1196 Elf_Internal_Sym
*isym
;
1198 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1200 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1205 /* xgettext:c-format */
1206 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1207 "in section `%A' failed"),
1208 abfd
, from
->name
, to
->name
, name
,
1209 rel
->r_offset
, sec
);
1210 bfd_set_error (bfd_error_bad_value
);
1218 /* With the local symbol, foo, we convert
1219 mov foo@GOT[(%reg1)], %reg2
1221 lea foo[@GOTOFF(%reg1)], %reg2
1223 call/jmp *foo@GOT[(%reg)]
1225 nop call foo/jmp foo nop
1226 When PIC is false, convert
1227 test %reg1, foo@GOT[(%reg2)]
1231 binop foo@GOT[(%reg1)], %reg2
1234 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1239 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1241 Elf_Internal_Rela
*irel
,
1242 struct elf_link_hash_entry
*h
,
1243 bfd_boolean
*converted
,
1244 struct bfd_link_info
*link_info
)
1246 struct elf_x86_link_hash_table
*htab
;
1247 unsigned int opcode
;
1249 bfd_boolean baseless
;
1250 Elf_Internal_Sym
*isym
;
1251 unsigned int addend
;
1255 bfd_boolean to_reloc_32
;
1256 unsigned int r_type
;
1257 unsigned int r_symndx
;
1258 bfd_vma roff
= irel
->r_offset
;
1263 /* Addend for R_386_GOT32X relocations must be 0. */
1264 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1268 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
1269 is_pic
= bfd_link_pic (link_info
);
1271 r_type
= ELF32_R_TYPE (irel
->r_info
);
1272 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1274 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1275 baseless
= (modrm
& 0xc7) == 0x5;
1277 if (baseless
&& is_pic
)
1279 /* For PIC, disallow R_386_GOT32X without a base register
1280 since we don't know what the GOT base is. */
1285 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1287 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1290 name
= h
->root
.root
.string
;
1293 /* xgettext:c-format */
1294 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1295 " register can not be used when making a shared object"),
1300 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1302 /* Convert to R_386_32 if PIC is false or there is no base
1304 to_reloc_32
= !is_pic
|| baseless
;
1306 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1310 if (opcode
== 0x0ff)
1311 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1312 goto convert_branch
;
1314 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1315 "test %reg1, foo@GOT(%reg2)" and
1316 "binop foo@GOT[(%reg1)], %reg2". */
1320 /* Undefined weak symbol is only bound locally in executable
1321 and its reference is resolved as 0. */
1322 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
, I386_ELF_DATA
, TRUE
,
1323 elf_x86_hash_entry (h
)))
1327 /* No direct branch to 0 for PIC. */
1331 goto convert_branch
;
1335 /* We can convert load of address 0 to R_386_32. */
1343 /* We have "call/jmp *foo@GOT[(%reg)]". */
1344 if ((h
->root
.type
== bfd_link_hash_defined
1345 || h
->root
.type
== bfd_link_hash_defweak
)
1346 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1348 /* The function is locally defined. */
1350 /* Convert R_386_GOT32X to R_386_PC32. */
1351 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1353 struct elf_x86_link_hash_entry
*eh
1354 = (struct elf_x86_link_hash_entry
*) h
;
1356 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1359 /* To support TLS optimization, always use addr32 prefix
1360 for "call *___tls_get_addr@GOT(%reg)". */
1361 if (eh
&& eh
->tls_get_addr
)
1364 nop_offset
= irel
->r_offset
- 2;
1368 nop
= link_info
->call_nop_byte
;
1369 if (link_info
->call_nop_as_suffix
)
1371 nop_offset
= roff
+ 3;
1372 irel
->r_offset
-= 1;
1375 nop_offset
= roff
- 2;
1380 /* Convert to "jmp foo nop". */
1383 nop_offset
= roff
+ 3;
1384 irel
->r_offset
-= 1;
1387 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1388 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1389 /* When converting to PC-relative relocation, we
1390 need to adjust addend by -4. */
1391 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1392 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1399 /* We have "mov foo@GOT[(%re1g)], %reg2",
1400 "test %reg1, foo@GOT(%reg2)" and
1401 "binop foo@GOT[(%reg1)], %reg2".
1403 Avoid optimizing _DYNAMIC since ld.so may use its
1404 link-time address. */
1405 if (h
== htab
->elf
.hdynamic
)
1408 /* def_regular is set by an assignment in a linker script in
1409 bfd_elf_record_link_assignment. start_stop is set on
1410 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1413 || h
->root
.type
== bfd_link_hash_defined
1414 || h
->root
.type
== bfd_link_hash_defweak
)
1415 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)))
1422 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1423 "mov $foo, %reg2" with R_386_32. */
1425 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1426 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1431 /* Convert "mov foo@GOT(%reg1), %reg2" to
1432 "lea foo@GOTOFF(%reg1), %reg2". */
1433 r_type
= R_386_GOTOFF
;
1439 /* Only R_386_32 is supported. */
1445 /* Convert "test %reg1, foo@GOT(%reg2)" to
1446 "test $foo, %reg1". */
1447 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1452 /* Convert "binop foo@GOT(%reg1), %reg2" to
1453 "binop $foo, %reg2". */
1455 | (modrm
& 0x38) >> 3
1459 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1463 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1464 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1473 /* Rename some of the generic section flags to better document how they
1475 #define need_convert_load sec_flg0
1476 #define check_relocs_failed sec_flg1
1478 /* Look through the relocs for a section during the first phase, and
1479 calculate needed space in the global offset table, procedure linkage
1480 table, and dynamic reloc sections. */
1483 elf_i386_check_relocs (bfd
*abfd
,
1484 struct bfd_link_info
*info
,
1486 const Elf_Internal_Rela
*relocs
)
1488 struct elf_x86_link_hash_table
*htab
;
1489 Elf_Internal_Shdr
*symtab_hdr
;
1490 struct elf_link_hash_entry
**sym_hashes
;
1491 const Elf_Internal_Rela
*rel
;
1492 const Elf_Internal_Rela
*rel_end
;
1496 if (bfd_link_relocatable (info
))
1499 /* Don't do anything special with non-loaded, non-alloced sections.
1500 In particular, any relocs in such sections should not affect GOT
1501 and PLT reference counting (ie. we don't allow them to create GOT
1502 or PLT entries), there's no possibility or desire to optimize TLS
1503 relocs, and there's not much point in propagating relocs to shared
1504 libs that the dynamic linker won't relocate. */
1505 if ((sec
->flags
& SEC_ALLOC
) == 0)
1508 BFD_ASSERT (is_i386_elf (abfd
));
1510 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1513 sec
->check_relocs_failed
= 1;
1517 /* Get the section contents. */
1518 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1519 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1520 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1522 sec
->check_relocs_failed
= 1;
1526 symtab_hdr
= &elf_symtab_hdr (abfd
);
1527 sym_hashes
= elf_sym_hashes (abfd
);
1531 rel_end
= relocs
+ sec
->reloc_count
;
1532 for (rel
= relocs
; rel
< rel_end
; rel
++)
1534 unsigned int r_type
;
1535 unsigned int r_symndx
;
1536 struct elf_link_hash_entry
*h
;
1537 struct elf_x86_link_hash_entry
*eh
;
1538 Elf_Internal_Sym
*isym
;
1540 bfd_boolean size_reloc
;
1542 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1543 r_type
= ELF32_R_TYPE (rel
->r_info
);
1545 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1547 /* xgettext:c-format */
1548 _bfd_error_handler (_("%B: bad symbol index: %d"),
1553 if (r_symndx
< symtab_hdr
->sh_info
)
1555 /* A local symbol. */
1556 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1561 /* Check relocation against local STT_GNU_IFUNC symbol. */
1562 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1564 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1568 /* Fake a STT_GNU_IFUNC symbol. */
1569 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1571 h
->type
= STT_GNU_IFUNC
;
1574 h
->forced_local
= 1;
1575 h
->root
.type
= bfd_link_hash_defined
;
1583 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1584 while (h
->root
.type
== bfd_link_hash_indirect
1585 || h
->root
.type
== bfd_link_hash_warning
)
1586 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1589 eh
= (struct elf_x86_link_hash_entry
*) h
;
1592 if (r_type
== R_386_GOTOFF
)
1595 /* It is referenced by a non-shared object. */
1597 h
->root
.non_ir_ref_regular
= 1;
1599 if (h
->type
== STT_GNU_IFUNC
)
1600 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1601 |= elf_gnu_symbol_ifunc
;
1604 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1605 symtab_hdr
, sym_hashes
,
1606 &r_type
, GOT_UNKNOWN
,
1607 rel
, rel_end
, h
, r_symndx
, FALSE
))
1613 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1617 /* This symbol requires a procedure linkage table entry. We
1618 actually build the entry in adjust_dynamic_symbol,
1619 because this might be a case of linking PIC code which is
1620 never referenced by a dynamic object, in which case we
1621 don't need to generate a procedure linkage table entry
1624 /* If this is a local symbol, we resolve it directly without
1625 creating a procedure linkage table entry. */
1629 eh
->has_got_reloc
= 1;
1631 h
->plt
.refcount
+= 1;
1638 case R_386_TLS_IE_32
:
1640 case R_386_TLS_GOTIE
:
1641 if (!bfd_link_executable (info
))
1642 info
->flags
|= DF_STATIC_TLS
;
1648 case R_386_TLS_GOTDESC
:
1649 case R_386_TLS_DESC_CALL
:
1650 /* This symbol requires a global offset table entry. */
1652 int tls_type
, old_tls_type
;
1659 tls_type
= GOT_NORMAL
;
1661 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1662 case R_386_TLS_GOTDESC
:
1663 case R_386_TLS_DESC_CALL
:
1664 tls_type
= GOT_TLS_GDESC
; break;
1665 case R_386_TLS_IE_32
:
1666 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1667 tls_type
= GOT_TLS_IE_NEG
;
1669 /* If this is a GD->IE transition, we may use either of
1670 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1671 tls_type
= GOT_TLS_IE
;
1674 case R_386_TLS_GOTIE
:
1675 tls_type
= GOT_TLS_IE_POS
; break;
1680 h
->got
.refcount
+= 1;
1681 old_tls_type
= elf_x86_hash_entry (h
)->tls_type
;
1685 bfd_signed_vma
*local_got_refcounts
;
1687 /* This is a global offset table entry for a local symbol. */
1688 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1689 if (local_got_refcounts
== NULL
)
1693 size
= symtab_hdr
->sh_info
;
1694 size
*= (sizeof (bfd_signed_vma
)
1695 + sizeof (bfd_vma
) + sizeof(char));
1696 local_got_refcounts
= (bfd_signed_vma
*)
1697 bfd_zalloc (abfd
, size
);
1698 if (local_got_refcounts
== NULL
)
1700 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1701 elf_x86_local_tlsdesc_gotent (abfd
)
1702 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1703 elf_x86_local_got_tls_type (abfd
)
1704 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1706 local_got_refcounts
[r_symndx
] += 1;
1707 old_tls_type
= elf_x86_local_got_tls_type (abfd
) [r_symndx
];
1710 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1711 tls_type
|= old_tls_type
;
1712 /* If a TLS symbol is accessed using IE at least once,
1713 there is no point to use dynamic model for it. */
1714 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1715 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1716 || (tls_type
& GOT_TLS_IE
) == 0))
1718 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1719 tls_type
= old_tls_type
;
1720 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1721 && GOT_TLS_GD_ANY_P (tls_type
))
1722 tls_type
|= old_tls_type
;
1726 name
= h
->root
.root
.string
;
1728 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1731 /* xgettext:c-format */
1732 (_("%B: `%s' accessed both as normal and "
1733 "thread local symbol"),
1735 bfd_set_error (bfd_error_bad_value
);
1740 if (old_tls_type
!= tls_type
)
1743 elf_x86_hash_entry (h
)->tls_type
= tls_type
;
1745 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1753 if (r_type
!= R_386_TLS_IE
)
1756 eh
->has_got_reloc
= 1;
1761 case R_386_TLS_LE_32
:
1764 eh
->has_got_reloc
= 1;
1765 if (bfd_link_executable (info
))
1767 info
->flags
|= DF_STATIC_TLS
;
1772 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
1773 eh
->has_non_got_reloc
= 1;
1775 /* We are called after all symbols have been resolved. Only
1776 relocation against STT_GNU_IFUNC symbol must go through
1779 && (bfd_link_executable (info
)
1780 || h
->type
== STT_GNU_IFUNC
))
1782 /* If this reloc is in a read-only section, we might
1783 need a copy reloc. We can't check reliably at this
1784 stage whether the section is read-only, as input
1785 sections have not yet been mapped to output sections.
1786 Tentatively set the flag for now, and correct in
1787 adjust_dynamic_symbol. */
1790 /* We may need a .plt entry if the symbol is a function
1791 defined in a shared lib or is a STT_GNU_IFUNC function
1792 referenced from the code or read-only section. */
1794 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
1795 h
->plt
.refcount
+= 1;
1797 if (r_type
== R_386_PC32
)
1799 /* Since something like ".long foo - ." may be used
1800 as pointer, make sure that PLT is used if foo is
1801 a function defined in a shared library. */
1802 if ((sec
->flags
& SEC_CODE
) == 0)
1803 h
->pointer_equality_needed
= 1;
1804 else if (h
->type
== STT_GNU_IFUNC
1805 && bfd_link_pic (info
))
1808 /* xgettext:c-format */
1809 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
1810 abfd
, h
->root
.root
.string
);
1811 bfd_set_error (bfd_error_bad_value
);
1817 h
->pointer_equality_needed
= 1;
1818 /* R_386_32 can be resolved at run-time. */
1819 if (r_type
== R_386_32
1820 && (sec
->flags
& SEC_READONLY
) == 0)
1821 eh
->func_pointer_refcount
+= 1;
1827 /* If we are creating a shared library, and this is a reloc
1828 against a global symbol, or a non PC relative reloc
1829 against a local symbol, then we need to copy the reloc
1830 into the shared library. However, if we are linking with
1831 -Bsymbolic, we do not need to copy a reloc against a
1832 global symbol which is defined in an object we are
1833 including in the link (i.e., DEF_REGULAR is set). At
1834 this point we have not seen all the input files, so it is
1835 possible that DEF_REGULAR is not set now but will be set
1836 later (it is never cleared). In case of a weak definition,
1837 DEF_REGULAR may be cleared later by a strong definition in
1838 a shared library. We account for that possibility below by
1839 storing information in the relocs_copied field of the hash
1840 table entry. A similar situation occurs when creating
1841 shared libraries and symbol visibility changes render the
1844 If on the other hand, we are creating an executable, we
1845 may need to keep relocations for symbols satisfied by a
1846 dynamic library if we manage to avoid copy relocs for the
1849 Generate dynamic pointer relocation against STT_GNU_IFUNC
1850 symbol in the non-code section. */
1851 if ((bfd_link_pic (info
)
1852 && (r_type
!= R_386_PC32
1854 && (! (bfd_link_pie (info
)
1855 || SYMBOLIC_BIND (info
, h
))
1856 || h
->root
.type
== bfd_link_hash_defweak
1857 || !h
->def_regular
))))
1859 && h
->type
== STT_GNU_IFUNC
1860 && r_type
== R_386_32
1861 && (sec
->flags
& SEC_CODE
) == 0)
1862 || (ELIMINATE_COPY_RELOCS
1863 && !bfd_link_pic (info
)
1865 && (h
->root
.type
== bfd_link_hash_defweak
1866 || !h
->def_regular
)))
1868 struct elf_dyn_relocs
*p
;
1869 struct elf_dyn_relocs
**head
;
1871 /* We must copy these reloc types into the output file.
1872 Create a reloc section in dynobj and make room for
1876 sreloc
= _bfd_elf_make_dynamic_reloc_section
1877 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1883 /* If this is a global symbol, we count the number of
1884 relocations we need for this symbol. */
1887 head
= &eh
->dyn_relocs
;
1891 /* Track dynamic relocs needed for local syms too.
1892 We really need local syms available to do this
1897 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1902 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1906 vpp
= &elf_section_data (s
)->local_dynrel
;
1907 head
= (struct elf_dyn_relocs
**)vpp
;
1911 if (p
== NULL
|| p
->sec
!= sec
)
1913 bfd_size_type amt
= sizeof *p
;
1914 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1926 /* Count size relocation as PC-relative relocation. */
1927 if (r_type
== R_386_PC32
|| size_reloc
)
1932 /* This relocation describes the C++ object vtable hierarchy.
1933 Reconstruct it for later use during GC. */
1934 case R_386_GNU_VTINHERIT
:
1935 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1939 /* This relocation describes which C++ vtable entries are actually
1940 used. Record for later use during GC. */
1941 case R_386_GNU_VTENTRY
:
1942 BFD_ASSERT (h
!= NULL
);
1944 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1952 if (r_type
== R_386_GOT32X
1953 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1954 sec
->need_convert_load
= 1;
1957 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1959 if (!info
->keep_memory
)
1963 /* Cache the section contents for elf_link_input_bfd. */
1964 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1971 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1973 sec
->check_relocs_failed
= 1;
1977 /* Allocate space in .plt, .got and associated reloc sections for
1981 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1983 struct bfd_link_info
*info
;
1984 struct elf_x86_link_hash_table
*htab
;
1985 struct elf_x86_link_hash_entry
*eh
;
1986 struct elf_dyn_relocs
*p
;
1987 unsigned plt_entry_size
;
1988 bfd_boolean resolved_to_zero
;
1989 const struct elf_i386_backend_data
*bed
;
1991 if (h
->root
.type
== bfd_link_hash_indirect
)
1994 eh
= (struct elf_x86_link_hash_entry
*) h
;
1996 info
= (struct bfd_link_info
*) inf
;
1997 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2001 bed
= get_elf_i386_backend_data (info
->output_bfd
);
2003 plt_entry_size
= htab
->plt
.plt_entry_size
;
2005 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2010 /* Clear the reference count of function pointer relocations if
2011 symbol isn't a normal function. */
2012 if (h
->type
!= STT_FUNC
)
2013 eh
->func_pointer_refcount
= 0;
2015 /* We can't use the GOT PLT if pointer equality is needed since
2016 finish_dynamic_symbol won't clear symbol value and the dynamic
2017 linker won't update the GOT slot. We will get into an infinite
2018 loop at run-time. */
2019 if (htab
->plt_got
!= NULL
2020 && h
->type
!= STT_GNU_IFUNC
2021 && !h
->pointer_equality_needed
2022 && h
->plt
.refcount
> 0
2023 && h
->got
.refcount
> 0)
2025 /* Don't use the regular PLT if there are both GOT and GOTPLT
2027 h
->plt
.offset
= (bfd_vma
) -1;
2029 /* Use the GOT PLT. */
2030 eh
->plt_got
.refcount
= 1;
2033 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2034 here if it is defined and referenced in a non-shared object. */
2035 if (h
->type
== STT_GNU_IFUNC
2038 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2039 &htab
->readonly_dynrelocs_against_ifunc
,
2045 asection
*s
= htab
->plt_second
;
2046 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
2048 /* Use the second PLT section if it is created. */
2049 eh
->plt_second
.offset
= s
->size
;
2051 /* Make room for this entry in the second PLT section. */
2052 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2060 /* Don't create the PLT entry if there are only function pointer
2061 relocations which can be resolved at run-time. */
2062 else if (htab
->elf
.dynamic_sections_created
2063 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2064 || eh
->plt_got
.refcount
> 0))
2066 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
2068 /* Clear the reference count of function pointer relocations
2070 eh
->func_pointer_refcount
= 0;
2072 /* Make sure this symbol is output as a dynamic symbol.
2073 Undefined weak syms won't yet be marked as dynamic. */
2074 if (h
->dynindx
== -1
2076 && !resolved_to_zero
2077 && h
->root
.type
== bfd_link_hash_undefweak
)
2079 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2083 if (bfd_link_pic (info
)
2084 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2086 asection
*s
= htab
->elf
.splt
;
2087 asection
*second_s
= htab
->plt_second
;
2088 asection
*got_s
= htab
->plt_got
;
2090 /* If this is the first .plt entry, make room for the special
2091 first entry. The .plt section is used by prelink to undo
2092 prelinking for dynamic relocations. */
2094 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
2097 eh
->plt_got
.offset
= got_s
->size
;
2100 h
->plt
.offset
= s
->size
;
2102 eh
->plt_second
.offset
= second_s
->size
;
2105 /* If this symbol is not defined in a regular file, and we are
2106 not generating a shared library, then set the symbol to this
2107 location in the .plt. This is required to make function
2108 pointers compare as equal between the normal executable and
2109 the shared library. */
2110 if (! bfd_link_pic (info
)
2115 /* We need to make a call to the entry of the GOT PLT
2116 instead of regular PLT entry. */
2117 h
->root
.u
.def
.section
= got_s
;
2118 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2124 /* We need to make a call to the entry of the
2125 second PLT instead of regular PLT entry. */
2126 h
->root
.u
.def
.section
= second_s
;
2127 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
2131 h
->root
.u
.def
.section
= s
;
2132 h
->root
.u
.def
.value
= h
->plt
.offset
;
2137 /* Make room for this entry. */
2139 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2142 s
->size
+= plt_entry_size
;
2144 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2146 /* We also need to make an entry in the .got.plt section,
2147 which will be placed in the .got section by the linker
2149 htab
->elf
.sgotplt
->size
+= 4;
2151 /* There should be no PLT relocation against resolved
2152 undefined weak symbol in executable. */
2153 if (!resolved_to_zero
)
2155 /* We also need to make an entry in the .rel.plt
2157 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2158 htab
->elf
.srelplt
->reloc_count
++;
2162 if (bed
->os
== is_vxworks
&& !bfd_link_pic (info
))
2164 /* VxWorks has a second set of relocations for each PLT entry
2165 in executables. They go in a separate relocation section,
2166 which is processed by the kernel loader. */
2168 /* There are two relocations for the initial PLT entry: an
2169 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2170 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2172 asection
*srelplt2
= htab
->srelplt2
;
2173 if (h
->plt
.offset
== plt_entry_size
)
2174 srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2176 /* There are two extra relocations for each subsequent PLT entry:
2177 an R_386_32 relocation for the GOT entry, and an R_386_32
2178 relocation for the PLT entry. */
2180 srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2185 eh
->plt_got
.offset
= (bfd_vma
) -1;
2186 h
->plt
.offset
= (bfd_vma
) -1;
2192 eh
->plt_got
.offset
= (bfd_vma
) -1;
2193 h
->plt
.offset
= (bfd_vma
) -1;
2197 eh
->tlsdesc_got
= (bfd_vma
) -1;
2199 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2200 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2201 if (h
->got
.refcount
> 0
2202 && bfd_link_executable (info
)
2204 && (elf_x86_hash_entry (h
)->tls_type
& GOT_TLS_IE
))
2205 h
->got
.offset
= (bfd_vma
) -1;
2206 else if (h
->got
.refcount
> 0)
2210 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
2212 /* Make sure this symbol is output as a dynamic symbol.
2213 Undefined weak syms won't yet be marked as dynamic. */
2214 if (h
->dynindx
== -1
2216 && !resolved_to_zero
2217 && h
->root
.type
== bfd_link_hash_undefweak
)
2219 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2224 if (GOT_TLS_GDESC_P (tls_type
))
2226 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2227 - elf_i386_compute_jump_table_size (htab
);
2228 htab
->elf
.sgotplt
->size
+= 8;
2229 h
->got
.offset
= (bfd_vma
) -2;
2231 if (! GOT_TLS_GDESC_P (tls_type
)
2232 || GOT_TLS_GD_P (tls_type
))
2234 h
->got
.offset
= s
->size
;
2236 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2237 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2240 dyn
= htab
->elf
.dynamic_sections_created
;
2241 /* R_386_TLS_IE_32 needs one dynamic relocation,
2242 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2243 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2244 need two), R_386_TLS_GD needs one if local symbol and two if
2245 global. No dynamic relocation against resolved undefined weak
2246 symbol in executable. */
2247 if (tls_type
== GOT_TLS_IE_BOTH
)
2248 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2249 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2250 || (tls_type
& GOT_TLS_IE
))
2251 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2252 else if (GOT_TLS_GD_P (tls_type
))
2253 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2254 else if (! GOT_TLS_GDESC_P (tls_type
)
2255 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2256 && !resolved_to_zero
)
2257 || h
->root
.type
!= bfd_link_hash_undefweak
)
2258 && (bfd_link_pic (info
)
2259 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2260 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2261 if (GOT_TLS_GDESC_P (tls_type
))
2262 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2265 h
->got
.offset
= (bfd_vma
) -1;
2267 if (eh
->dyn_relocs
== NULL
)
2270 /* In the shared -Bsymbolic case, discard space allocated for
2271 dynamic pc-relative relocs against symbols which turn out to be
2272 defined in regular objects. For the normal shared case, discard
2273 space for pc-relative relocs that have become local due to symbol
2274 visibility changes. */
2276 if (bfd_link_pic (info
))
2278 /* The only reloc that uses pc_count is R_386_PC32, which will
2279 appear on a call or on something like ".long foo - .". We
2280 want calls to protected symbols to resolve directly to the
2281 function rather than going via the plt. If people want
2282 function pointer comparisons to work as expected then they
2283 should avoid writing assembly like ".long foo - .". */
2284 if (SYMBOL_CALLS_LOCAL (info
, h
))
2286 struct elf_dyn_relocs
**pp
;
2288 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2290 p
->count
-= p
->pc_count
;
2299 if (bed
->os
== is_vxworks
)
2301 struct elf_dyn_relocs
**pp
;
2302 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2304 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2311 /* Also discard relocs on undefined weak syms with non-default
2312 visibility or in PIE. */
2313 if (eh
->dyn_relocs
!= NULL
2314 && h
->root
.type
== bfd_link_hash_undefweak
)
2316 /* Undefined weak symbol is never bound locally in shared
2318 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2319 || resolved_to_zero
)
2323 /* Keep dynamic non-GOT/non-PLT relocation so that we
2324 can branch to 0 without PLT. */
2325 struct elf_dyn_relocs
**pp
;
2327 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2328 if (p
->pc_count
== 0)
2332 /* Remove non-R_386_PC32 relocation. */
2333 p
->count
= p
->pc_count
;
2337 if (eh
->dyn_relocs
!= NULL
)
2339 /* Make sure undefined weak symbols are output
2340 as dynamic symbols in PIEs for dynamic non-GOT
2341 non-PLT reloations. */
2342 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2347 eh
->dyn_relocs
= NULL
;
2349 else if (h
->dynindx
== -1
2350 && !h
->forced_local
)
2352 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2357 else if (ELIMINATE_COPY_RELOCS
)
2359 /* For the non-shared case, discard space for relocs against
2360 symbols which turn out to need copy relocs or are not
2361 dynamic. Keep dynamic relocations for run-time function
2362 pointer initialization. */
2364 if ((!h
->non_got_ref
2365 || eh
->func_pointer_refcount
> 0
2366 || (h
->root
.type
== bfd_link_hash_undefweak
2367 && !resolved_to_zero
))
2370 || (htab
->elf
.dynamic_sections_created
2371 && (h
->root
.type
== bfd_link_hash_undefweak
2372 || h
->root
.type
== bfd_link_hash_undefined
))))
2374 /* Make sure this symbol is output as a dynamic symbol.
2375 Undefined weak syms won't yet be marked as dynamic. */
2376 if (h
->dynindx
== -1
2378 && !resolved_to_zero
2379 && h
->root
.type
== bfd_link_hash_undefweak
)
2381 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2385 /* If that succeeded, we know we'll be keeping all the
2387 if (h
->dynindx
!= -1)
2391 eh
->dyn_relocs
= NULL
;
2392 eh
->func_pointer_refcount
= 0;
2397 /* Finally, allocate space. */
2398 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2402 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2404 BFD_ASSERT (sreloc
!= NULL
);
2405 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2411 /* Allocate space in .plt, .got and associated reloc sections for
2412 local dynamic relocs. */
2415 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2417 struct elf_link_hash_entry
*h
2418 = (struct elf_link_hash_entry
*) *slot
;
2420 if (h
->type
!= STT_GNU_IFUNC
2424 || h
->root
.type
!= bfd_link_hash_defined
)
2427 return elf_i386_allocate_dynrelocs (h
, inf
);
2430 /* Convert load via the GOT slot to load immediate. */
2433 elf_i386_convert_load (bfd
*abfd
, asection
*sec
,
2434 struct bfd_link_info
*link_info
)
2436 struct elf_x86_link_hash_table
*htab
;
2437 Elf_Internal_Shdr
*symtab_hdr
;
2438 Elf_Internal_Rela
*internal_relocs
;
2439 Elf_Internal_Rela
*irel
, *irelend
;
2441 bfd_boolean changed
;
2442 bfd_signed_vma
*local_got_refcounts
;
2444 /* Don't even try to convert non-ELF outputs. */
2445 if (!is_elf_hash_table (link_info
->hash
))
2448 /* Nothing to do if there is no need or no output. */
2449 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
2450 || sec
->need_convert_load
== 0
2451 || bfd_is_abs_section (sec
->output_section
))
2454 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2456 /* Load the relocations for this section. */
2457 internal_relocs
= (_bfd_elf_link_read_relocs
2458 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2459 link_info
->keep_memory
));
2460 if (internal_relocs
== NULL
)
2464 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
2465 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2467 /* Get the section contents. */
2468 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2469 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2472 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2476 irelend
= internal_relocs
+ sec
->reloc_count
;
2477 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2479 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
2480 unsigned int r_symndx
;
2481 struct elf_link_hash_entry
*h
;
2482 bfd_boolean converted
;
2484 /* Don't convert R_386_GOT32 since we can't tell if it is applied
2485 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
2486 if (r_type
!= R_386_GOT32X
)
2489 r_symndx
= ELF32_R_SYM (irel
->r_info
);
2490 if (r_symndx
< symtab_hdr
->sh_info
)
2491 h
= _bfd_elf_x86_get_local_sym_hash (htab
, sec
->owner
,
2492 (const Elf_Internal_Rela
*) irel
,
2496 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
2497 while (h
->root
.type
== bfd_link_hash_indirect
2498 || h
->root
.type
== bfd_link_hash_warning
)
2499 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2502 /* STT_GNU_IFUNC must keep GOT32 relocations. */
2503 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2507 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
2508 irel
, h
, &converted
, link_info
))
2513 changed
= converted
;
2516 if (h
->got
.refcount
> 0)
2517 h
->got
.refcount
-= 1;
2521 if (local_got_refcounts
!= NULL
2522 && local_got_refcounts
[r_symndx
] > 0)
2523 local_got_refcounts
[r_symndx
] -= 1;
2528 if (contents
!= NULL
2529 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2531 if (!changed
&& !link_info
->keep_memory
)
2535 /* Cache the section contents for elf_link_input_bfd. */
2536 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2540 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2543 free (internal_relocs
);
2545 elf_section_data (sec
)->relocs
= internal_relocs
;
2551 if (contents
!= NULL
2552 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2554 if (internal_relocs
!= NULL
2555 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2556 free (internal_relocs
);
2560 /* Set the sizes of the dynamic sections. */
2563 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2565 struct elf_x86_link_hash_table
*htab
;
2571 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2574 dynobj
= htab
->elf
.dynobj
;
2578 /* Set up .got offsets for local syms, and space for local dynamic
2580 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2582 bfd_signed_vma
*local_got
;
2583 bfd_signed_vma
*end_local_got
;
2584 char *local_tls_type
;
2585 bfd_vma
*local_tlsdesc_gotent
;
2586 bfd_size_type locsymcount
;
2587 Elf_Internal_Shdr
*symtab_hdr
;
2590 if (! is_i386_elf (ibfd
))
2593 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2595 struct elf_dyn_relocs
*p
;
2597 if (!elf_i386_convert_load (ibfd
, s
, info
))
2600 for (p
= ((struct elf_dyn_relocs
*)
2601 elf_section_data (s
)->local_dynrel
);
2605 if (!bfd_is_abs_section (p
->sec
)
2606 && bfd_is_abs_section (p
->sec
->output_section
))
2608 /* Input section has been discarded, either because
2609 it is a copy of a linkonce section or due to
2610 linker script /DISCARD/, so we'll be discarding
2613 else if ((get_elf_i386_backend_data (output_bfd
)->os
2615 && strcmp (p
->sec
->output_section
->name
,
2618 /* Relocations in vxworks .tls_vars sections are
2619 handled specially by the loader. */
2621 else if (p
->count
!= 0)
2623 srel
= elf_section_data (p
->sec
)->sreloc
;
2624 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2625 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2626 && (info
->flags
& DF_TEXTREL
) == 0)
2628 info
->flags
|= DF_TEXTREL
;
2629 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
2630 || info
->error_textrel
)
2631 /* xgettext:c-format */
2632 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
2633 p
->sec
->owner
, p
->sec
);
2639 local_got
= elf_local_got_refcounts (ibfd
);
2643 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2644 locsymcount
= symtab_hdr
->sh_info
;
2645 end_local_got
= local_got
+ locsymcount
;
2646 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
2647 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
2649 srel
= htab
->elf
.srelgot
;
2650 for (; local_got
< end_local_got
;
2651 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2653 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2656 if (GOT_TLS_GDESC_P (*local_tls_type
))
2658 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2659 - elf_i386_compute_jump_table_size (htab
);
2660 htab
->elf
.sgotplt
->size
+= 8;
2661 *local_got
= (bfd_vma
) -2;
2663 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2664 || GOT_TLS_GD_P (*local_tls_type
))
2666 *local_got
= s
->size
;
2668 if (GOT_TLS_GD_P (*local_tls_type
)
2669 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2672 if (bfd_link_pic (info
)
2673 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2674 || (*local_tls_type
& GOT_TLS_IE
))
2676 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2677 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2678 else if (GOT_TLS_GD_P (*local_tls_type
)
2679 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2680 srel
->size
+= sizeof (Elf32_External_Rel
);
2681 if (GOT_TLS_GDESC_P (*local_tls_type
))
2682 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2686 *local_got
= (bfd_vma
) -1;
2690 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
2692 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2694 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2695 htab
->elf
.sgot
->size
+= 8;
2696 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2699 htab
->tls_ld_or_ldm_got
.offset
= -1;
2701 /* Allocate global sym .plt and .got entries, and space for global
2702 sym dynamic relocs. */
2703 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2705 /* Allocate .plt and .got entries, and space for local symbols. */
2706 htab_traverse (htab
->loc_hash_table
,
2707 elf_i386_allocate_local_dynrelocs
,
2710 /* For every jump slot reserved in the sgotplt, reloc_count is
2711 incremented. However, when we reserve space for TLS descriptors,
2712 it's not incremented, so in order to compute the space reserved
2713 for them, it suffices to multiply the reloc count by the jump
2716 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2717 so that R_386_IRELATIVE entries come last. */
2718 if (htab
->elf
.srelplt
)
2720 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
2721 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2722 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2724 else if (htab
->elf
.irelplt
)
2725 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2728 if (htab
->elf
.sgotplt
)
2730 /* Don't allocate .got.plt section if there are no GOT nor PLT
2731 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
2732 if ((htab
->elf
.hgot
== NULL
2733 || !htab
->elf
.hgot
->ref_regular_nonweak
)
2734 && (htab
->elf
.sgotplt
->size
2735 == get_elf_backend_data (output_bfd
)->got_header_size
)
2736 && (htab
->elf
.splt
== NULL
2737 || htab
->elf
.splt
->size
== 0)
2738 && (htab
->elf
.sgot
== NULL
2739 || htab
->elf
.sgot
->size
== 0)
2740 && (htab
->elf
.iplt
== NULL
2741 || htab
->elf
.iplt
->size
== 0)
2742 && (htab
->elf
.igotplt
== NULL
2743 || htab
->elf
.igotplt
->size
== 0))
2744 htab
->elf
.sgotplt
->size
= 0;
2747 if (_bfd_elf_eh_frame_present (info
))
2749 if (htab
->plt_eh_frame
!= NULL
2750 && htab
->elf
.splt
!= NULL
2751 && htab
->elf
.splt
->size
!= 0
2752 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
2753 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
2755 if (htab
->plt_got_eh_frame
!= NULL
2756 && htab
->plt_got
!= NULL
2757 && htab
->plt_got
->size
!= 0
2758 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
2759 htab
->plt_got_eh_frame
->size
2760 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2762 /* Unwind info for the second PLT and .plt.got sections are
2764 if (htab
->plt_second_eh_frame
!= NULL
2765 && htab
->plt_second
!= NULL
2766 && htab
->plt_second
->size
!= 0
2767 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
2768 htab
->plt_second_eh_frame
->size
2769 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2772 /* We now have determined the sizes of the various dynamic sections.
2773 Allocate memory for them. */
2775 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2777 bfd_boolean strip_section
= TRUE
;
2779 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2782 if (s
== htab
->elf
.splt
2783 || s
== htab
->elf
.sgot
)
2785 /* Strip this section if we don't need it; see the
2787 /* We'd like to strip these sections if they aren't needed, but if
2788 we've exported dynamic symbols from them we must leave them.
2789 It's too late to tell BFD to get rid of the symbols. */
2791 if (htab
->elf
.hplt
!= NULL
)
2792 strip_section
= FALSE
;
2794 else if (s
== htab
->elf
.sgotplt
2795 || s
== htab
->elf
.iplt
2796 || s
== htab
->elf
.igotplt
2797 || s
== htab
->plt_second
2798 || s
== htab
->plt_got
2799 || s
== htab
->plt_eh_frame
2800 || s
== htab
->plt_got_eh_frame
2801 || s
== htab
->plt_second_eh_frame
2802 || s
== htab
->elf
.sdynbss
2803 || s
== htab
->elf
.sdynrelro
)
2805 /* Strip these too. */
2807 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2810 && s
!= htab
->elf
.srelplt
2811 && s
!= htab
->srelplt2
)
2814 /* We use the reloc_count field as a counter if we need
2815 to copy relocs into the output file. */
2820 /* It's not one of our sections, so don't allocate space. */
2826 /* If we don't need this section, strip it from the
2827 output file. This is mostly to handle .rel.bss and
2828 .rel.plt. We must create both sections in
2829 create_dynamic_sections, because they must be created
2830 before the linker maps input sections to output
2831 sections. The linker does that before
2832 adjust_dynamic_symbol is called, and it is that
2833 function which decides whether anything needs to go
2834 into these sections. */
2836 s
->flags
|= SEC_EXCLUDE
;
2840 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2843 /* Allocate memory for the section contents. We use bfd_zalloc
2844 here in case unused entries are not reclaimed before the
2845 section's contents are written out. This should not happen,
2846 but this way if it does, we get a R_386_NONE reloc instead
2848 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2849 if (s
->contents
== NULL
)
2853 if (htab
->plt_eh_frame
!= NULL
2854 && htab
->plt_eh_frame
->contents
!= NULL
)
2856 memcpy (htab
->plt_eh_frame
->contents
,
2857 htab
->plt
.eh_frame_plt
,
2858 htab
->plt_eh_frame
->size
);
2859 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2860 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2863 if (htab
->plt_got_eh_frame
!= NULL
2864 && htab
->plt_got_eh_frame
->contents
!= NULL
)
2866 memcpy (htab
->plt_got_eh_frame
->contents
,
2867 htab
->non_lazy_plt
->eh_frame_plt
,
2868 htab
->plt_got_eh_frame
->size
);
2869 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
2870 (htab
->plt_got_eh_frame
->contents
2871 + PLT_FDE_LEN_OFFSET
));
2874 if (htab
->plt_second_eh_frame
!= NULL
2875 && htab
->plt_second_eh_frame
->contents
!= NULL
)
2877 memcpy (htab
->plt_second_eh_frame
->contents
,
2878 htab
->non_lazy_plt
->eh_frame_plt
,
2879 htab
->plt_second_eh_frame
->size
);
2880 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
2881 (htab
->plt_second_eh_frame
->contents
2882 + PLT_FDE_LEN_OFFSET
));
2885 if (htab
->elf
.dynamic_sections_created
)
2887 /* Add some entries to the .dynamic section. We fill in the
2888 values later, in elf_i386_finish_dynamic_sections, but we
2889 must add the entries now so that we get the correct size for
2890 the .dynamic section. The DT_DEBUG entry is filled in by the
2891 dynamic linker and used by the debugger. */
2892 #define add_dynamic_entry(TAG, VAL) \
2893 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2895 if (bfd_link_executable (info
))
2897 if (!add_dynamic_entry (DT_DEBUG
, 0))
2901 if (htab
->elf
.splt
->size
!= 0)
2903 /* DT_PLTGOT is used by prelink even if there is no PLT
2905 if (!add_dynamic_entry (DT_PLTGOT
, 0))
2909 if (htab
->elf
.srelplt
->size
!= 0)
2911 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
2912 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2913 || !add_dynamic_entry (DT_JMPREL
, 0))
2919 if (!add_dynamic_entry (DT_REL
, 0)
2920 || !add_dynamic_entry (DT_RELSZ
, 0)
2921 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2924 /* If any dynamic relocs apply to a read-only section,
2925 then we need a DT_TEXTREL entry. */
2926 if ((info
->flags
& DF_TEXTREL
) == 0)
2927 elf_link_hash_traverse (&htab
->elf
,
2928 _bfd_x86_elf_readonly_dynrelocs
,
2931 if ((info
->flags
& DF_TEXTREL
) != 0)
2933 if (htab
->readonly_dynrelocs_against_ifunc
)
2935 info
->callbacks
->einfo
2936 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
2937 bfd_set_error (bfd_error_bad_value
);
2941 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2945 if (get_elf_i386_backend_data (output_bfd
)->os
== is_vxworks
2946 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2949 #undef add_dynamic_entry
2954 /* Set the correct type for an x86 ELF section. We do this by the
2955 section name, which is a hack, but ought to work. */
2958 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2959 Elf_Internal_Shdr
*hdr
,
2964 name
= bfd_get_section_name (abfd
, sec
);
2966 /* This is an ugly, but unfortunately necessary hack that is
2967 needed when producing EFI binaries on x86. It tells
2968 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2969 containing ELF relocation info. We need this hack in order to
2970 be able to generate ELF binaries that can be translated into
2971 EFI applications (which are essentially COFF objects). Those
2972 files contain a COFF ".reloc" section inside an ELFNN object,
2973 which would normally cause BFD to segfault because it would
2974 attempt to interpret this section as containing relocation
2975 entries for section "oc". With this hack enabled, ".reloc"
2976 will be treated as a normal data section, which will avoid the
2977 segfault. However, you won't be able to create an ELFNN binary
2978 with a section named "oc" that needs relocations, but that's
2979 the kind of ugly side-effects you get when detecting section
2980 types based on their names... In practice, this limitation is
2981 unlikely to bite. */
2982 if (strcmp (name
, ".reloc") == 0)
2983 hdr
->sh_type
= SHT_PROGBITS
;
2988 /* Return the relocation value for @tpoff relocation
2989 if STT_TLS virtual address is ADDRESS. */
2992 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2994 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2995 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2996 bfd_vma static_tls_size
;
2998 /* If tls_sec is NULL, we should have signalled an error already. */
2999 if (htab
->tls_sec
== NULL
)
3002 /* Consider special static TLS alignment requirements. */
3003 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3004 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3007 /* Relocate an i386 ELF section. */
3010 elf_i386_relocate_section (bfd
*output_bfd
,
3011 struct bfd_link_info
*info
,
3013 asection
*input_section
,
3015 Elf_Internal_Rela
*relocs
,
3016 Elf_Internal_Sym
*local_syms
,
3017 asection
**local_sections
)
3019 struct elf_x86_link_hash_table
*htab
;
3020 Elf_Internal_Shdr
*symtab_hdr
;
3021 struct elf_link_hash_entry
**sym_hashes
;
3022 bfd_vma
*local_got_offsets
;
3023 bfd_vma
*local_tlsdesc_gotents
;
3024 Elf_Internal_Rela
*rel
;
3025 Elf_Internal_Rela
*wrel
;
3026 Elf_Internal_Rela
*relend
;
3027 bfd_boolean is_vxworks_tls
;
3028 unsigned plt_entry_size
;
3030 BFD_ASSERT (is_i386_elf (input_bfd
));
3032 /* Skip if check_relocs failed. */
3033 if (input_section
->check_relocs_failed
)
3036 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
3039 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3040 sym_hashes
= elf_sym_hashes (input_bfd
);
3041 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3042 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
3043 /* We have to handle relocations in vxworks .tls_vars sections
3044 specially, because the dynamic loader is 'weird'. */
3045 is_vxworks_tls
= ((get_elf_i386_backend_data (output_bfd
)->os
3047 && bfd_link_pic (info
)
3048 && !strcmp (input_section
->output_section
->name
,
3051 _bfd_x86_elf_set_tls_module_base (info
);
3053 plt_entry_size
= htab
->plt
.plt_entry_size
;
3055 rel
= wrel
= relocs
;
3056 relend
= relocs
+ input_section
->reloc_count
;
3057 for (; rel
< relend
; wrel
++, rel
++)
3059 unsigned int r_type
;
3060 reloc_howto_type
*howto
;
3061 unsigned long r_symndx
;
3062 struct elf_link_hash_entry
*h
;
3063 struct elf_x86_link_hash_entry
*eh
;
3064 Elf_Internal_Sym
*sym
;
3066 bfd_vma off
, offplt
, plt_offset
;
3068 bfd_boolean unresolved_reloc
;
3069 bfd_reloc_status_type r
;
3073 asection
*resolved_plt
;
3074 bfd_boolean resolved_to_zero
;
3075 bfd_boolean relative_reloc
;
3077 r_type
= ELF32_R_TYPE (rel
->r_info
);
3078 if (r_type
== R_386_GNU_VTINHERIT
3079 || r_type
== R_386_GNU_VTENTRY
)
3086 if ((indx
= r_type
) >= R_386_standard
3087 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3088 >= R_386_ext
- R_386_standard
)
3089 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3090 >= R_386_ext2
- R_386_ext
))
3091 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
3093 howto
= elf_howto_table
+ indx
;
3095 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3099 unresolved_reloc
= FALSE
;
3100 if (r_symndx
< symtab_hdr
->sh_info
)
3102 sym
= local_syms
+ r_symndx
;
3103 sec
= local_sections
[r_symndx
];
3104 relocation
= (sec
->output_section
->vma
3105 + sec
->output_offset
3107 st_size
= sym
->st_size
;
3109 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3110 && ((sec
->flags
& SEC_MERGE
) != 0
3111 || (bfd_link_relocatable (info
)
3112 && sec
->output_offset
!= 0)))
3115 bfd_byte
*where
= contents
+ rel
->r_offset
;
3117 switch (howto
->size
)
3120 addend
= bfd_get_8 (input_bfd
, where
);
3121 if (howto
->pc_relative
)
3123 addend
= (addend
^ 0x80) - 0x80;
3128 addend
= bfd_get_16 (input_bfd
, where
);
3129 if (howto
->pc_relative
)
3131 addend
= (addend
^ 0x8000) - 0x8000;
3136 addend
= bfd_get_32 (input_bfd
, where
);
3137 if (howto
->pc_relative
)
3139 addend
= (addend
^ 0x80000000) - 0x80000000;
3147 if (bfd_link_relocatable (info
))
3148 addend
+= sec
->output_offset
;
3151 asection
*msec
= sec
;
3152 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3154 addend
-= relocation
;
3155 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3158 switch (howto
->size
)
3161 /* FIXME: overflow checks. */
3162 if (howto
->pc_relative
)
3164 bfd_put_8 (input_bfd
, addend
, where
);
3167 if (howto
->pc_relative
)
3169 bfd_put_16 (input_bfd
, addend
, where
);
3172 if (howto
->pc_relative
)
3174 bfd_put_32 (input_bfd
, addend
, where
);
3178 else if (!bfd_link_relocatable (info
)
3179 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3181 /* Relocate against local STT_GNU_IFUNC symbol. */
3182 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
, rel
,
3187 /* Set STT_GNU_IFUNC symbol value. */
3188 h
->root
.u
.def
.value
= sym
->st_value
;
3189 h
->root
.u
.def
.section
= sec
;
3194 bfd_boolean warned ATTRIBUTE_UNUSED
;
3195 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3197 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3198 r_symndx
, symtab_hdr
, sym_hashes
,
3200 unresolved_reloc
, warned
, ignored
);
3204 if (sec
!= NULL
&& discarded_section (sec
))
3206 _bfd_clear_contents (howto
, input_bfd
, input_section
,
3207 contents
+ rel
->r_offset
);
3208 wrel
->r_offset
= rel
->r_offset
;
3212 /* For ld -r, remove relocations in debug sections against
3213 sections defined in discarded sections. Not done for
3214 eh_frame editing code expects to be present. */
3215 if (bfd_link_relocatable (info
)
3216 && (input_section
->flags
& SEC_DEBUGGING
))
3222 if (bfd_link_relocatable (info
))
3229 eh
= (struct elf_x86_link_hash_entry
*) h
;
3231 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3232 it here if it is defined in a non-shared object. */
3234 && h
->type
== STT_GNU_IFUNC
3237 asection
*gotplt
, *base_got
;
3241 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3243 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3244 sections because such sections are not SEC_ALLOC and
3245 thus ld.so will not process them. */
3246 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
3251 /* STT_GNU_IFUNC symbol must go through PLT. */
3252 if (htab
->elf
.splt
!= NULL
)
3254 if (htab
->plt_second
!= NULL
)
3256 resolved_plt
= htab
->plt_second
;
3257 plt_offset
= eh
->plt_second
.offset
;
3261 resolved_plt
= htab
->elf
.splt
;
3262 plt_offset
= h
->plt
.offset
;
3264 gotplt
= htab
->elf
.sgotplt
;
3268 resolved_plt
= htab
->elf
.iplt
;
3269 plt_offset
= h
->plt
.offset
;
3270 gotplt
= htab
->elf
.igotplt
;
3280 base_got
= htab
->elf
.sgot
;
3281 off
= h
->got
.offset
;
3283 if (base_got
== NULL
)
3286 if (off
== (bfd_vma
) -1)
3288 /* We can't use h->got.offset here to save state, or
3289 even just remember the offset, as finish_dynamic_symbol
3290 would use that as offset into .got. */
3292 if (h
->plt
.offset
== (bfd_vma
) -1)
3295 if (htab
->elf
.splt
!= NULL
)
3297 plt_index
= (h
->plt
.offset
/ plt_entry_size
3298 - htab
->plt
.has_plt0
);
3299 off
= (plt_index
+ 3) * 4;
3300 base_got
= htab
->elf
.sgotplt
;
3304 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3305 off
= plt_index
* 4;
3306 base_got
= htab
->elf
.igotplt
;
3309 if (h
->dynindx
== -1
3313 /* This references the local defitionion. We must
3314 initialize this entry in the global offset table.
3315 Since the offset must always be a multiple of 8,
3316 we use the least significant bit to record
3317 whether we have initialized it already.
3319 When doing a dynamic link, we create a .rela.got
3320 relocation entry to initialize the value. This
3321 is done in the finish_dynamic_symbol routine. */
3326 bfd_put_32 (output_bfd
, relocation
,
3327 base_got
->contents
+ off
);
3335 relocation
= (base_got
->output_section
->vma
3336 + base_got
->output_offset
+ off
3337 - gotplt
->output_section
->vma
3338 - gotplt
->output_offset
);
3340 if (rel
->r_offset
> 1
3341 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
3342 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
3344 if (bfd_link_pic (info
))
3345 goto disallow_got32
;
3347 /* Add the GOT base if there is no base register. */
3348 relocation
+= (gotplt
->output_section
->vma
3349 + gotplt
->output_offset
);
3351 else if (htab
->elf
.splt
== NULL
)
3353 /* Adjust for static executables. */
3354 relocation
+= gotplt
->output_offset
;
3360 if (h
->plt
.offset
== (bfd_vma
) -1)
3362 /* Handle static pointers of STT_GNU_IFUNC symbols. */
3363 if (r_type
== R_386_32
3364 && (input_section
->flags
& SEC_CODE
) == 0)
3365 goto do_ifunc_pointer
;
3366 goto bad_ifunc_reloc
;
3369 relocation
= (resolved_plt
->output_section
->vma
3370 + resolved_plt
->output_offset
+ plt_offset
);
3376 if (h
->root
.root
.string
)
3377 name
= h
->root
.root
.string
;
3379 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3382 /* xgettext:c-format */
3383 (_("%B: relocation %s against STT_GNU_IFUNC "
3384 "symbol `%s' isn't supported"), input_bfd
,
3386 bfd_set_error (bfd_error_bad_value
);
3390 /* Generate dynamic relcoation only when there is a
3391 non-GOT reference in a shared object. */
3392 if ((bfd_link_pic (info
) && h
->non_got_ref
)
3393 || h
->plt
.offset
== (bfd_vma
) -1)
3395 Elf_Internal_Rela outrel
;
3400 /* Need a dynamic relocation to get the real function
3402 offset
= _bfd_elf_section_offset (output_bfd
,
3406 if (offset
== (bfd_vma
) -1
3407 || offset
== (bfd_vma
) -2)
3410 outrel
.r_offset
= (input_section
->output_section
->vma
3411 + input_section
->output_offset
3414 if (h
->dynindx
== -1
3416 || bfd_link_executable (info
))
3418 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3419 h
->root
.root
.string
,
3420 h
->root
.u
.def
.section
->owner
);
3422 /* This symbol is resolved locally. */
3423 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3424 bfd_put_32 (output_bfd
,
3425 (h
->root
.u
.def
.value
3426 + h
->root
.u
.def
.section
->output_section
->vma
3427 + h
->root
.u
.def
.section
->output_offset
),
3431 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3433 /* Dynamic relocations are stored in
3434 1. .rel.ifunc section in PIC object.
3435 2. .rel.got section in dynamic executable.
3436 3. .rel.iplt section in static executable. */
3437 if (bfd_link_pic (info
))
3438 sreloc
= htab
->elf
.irelifunc
;
3439 else if (htab
->elf
.splt
!= NULL
)
3440 sreloc
= htab
->elf
.srelgot
;
3442 sreloc
= htab
->elf
.irelplt
;
3443 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3445 /* If this reloc is against an external symbol, we
3446 do not want to fiddle with the addend. Otherwise,
3447 we need to include the symbol value so that it
3448 becomes an addend for the dynamic reloc. For an
3449 internal symbol, we have updated addend. */
3458 relocation
-= (gotplt
->output_section
->vma
3459 + gotplt
->output_offset
);
3464 resolved_to_zero
= (eh
!= NULL
3465 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3473 /* Avoid optimizing _DYNAMIC since ld.so may use its
3474 link-time address. */
3475 if (h
== htab
->elf
.hdynamic
)
3478 if (bfd_link_pic (info
))
3480 /* It is OK to convert mov to lea and convert indirect
3481 branch to direct branch. It is OK to convert adc,
3482 add, and, cmp, or, sbb, sub, test, xor only when PIC
3484 unsigned int opcode
, addend
;
3485 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3488 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3489 if (opcode
!= 0x8b && opcode
!= 0xff)
3493 /* Resolve "mov GOT[(%reg)], %reg",
3494 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
3495 and "binop foo@GOT[(%reg)], %reg". */
3497 || (h
->plt
.offset
== (bfd_vma
) -1
3498 && h
->got
.offset
== (bfd_vma
) -1)
3499 || htab
->elf
.sgotplt
== NULL
)
3502 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
3503 + htab
->elf
.sgotplt
->output_offset
);
3505 /* It is relative to .got.plt section. */
3506 if (h
->got
.offset
!= (bfd_vma
) -1)
3507 /* Use GOT entry. Mask off the least significant bit in
3508 GOT offset which may be set by R_386_GOT32 processing
3510 relocation
= (htab
->elf
.sgot
->output_section
->vma
3511 + htab
->elf
.sgot
->output_offset
3512 + (h
->got
.offset
& ~1) - offplt
);
3514 /* Use GOTPLT entry. */
3515 relocation
= (h
->plt
.offset
/ plt_entry_size
3516 - htab
->plt
.has_plt0
+ 3) * 4;
3518 if (!bfd_link_pic (info
))
3520 /* If not PIC, add the .got.plt section address for
3521 baseless addressing. */
3523 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3524 if ((modrm
& 0xc7) == 0x5)
3525 relocation
+= offplt
;
3528 unresolved_reloc
= FALSE
;
3533 /* Relocation is to the entry for this symbol in the global
3535 if (htab
->elf
.sgot
== NULL
)
3538 relative_reloc
= FALSE
;
3543 off
= h
->got
.offset
;
3544 dyn
= htab
->elf
.dynamic_sections_created
;
3545 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
3546 bfd_link_pic (info
),
3548 || (bfd_link_pic (info
)
3549 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3550 || (ELF_ST_VISIBILITY (h
->other
)
3551 && h
->root
.type
== bfd_link_hash_undefweak
))
3553 /* This is actually a static link, or it is a
3554 -Bsymbolic link and the symbol is defined
3555 locally, or the symbol was forced to be local
3556 because of a version file. We must initialize
3557 this entry in the global offset table. Since the
3558 offset must always be a multiple of 4, we use the
3559 least significant bit to record whether we have
3560 initialized it already.
3562 When doing a dynamic link, we create a .rel.got
3563 relocation entry to initialize the value. This
3564 is done in the finish_dynamic_symbol routine. */
3569 bfd_put_32 (output_bfd
, relocation
,
3570 htab
->elf
.sgot
->contents
+ off
);
3573 if (h
->dynindx
== -1
3575 && h
->root
.type
!= bfd_link_hash_undefweak
3576 && bfd_link_pic (info
))
3578 /* PR ld/21402: If this symbol isn't dynamic
3579 in PIC, generate R_386_RELATIVE here. */
3580 eh
->no_finish_dynamic_symbol
= 1;
3581 relative_reloc
= TRUE
;
3586 unresolved_reloc
= FALSE
;
3590 if (local_got_offsets
== NULL
)
3593 off
= local_got_offsets
[r_symndx
];
3595 /* The offset must always be a multiple of 4. We use
3596 the least significant bit to record whether we have
3597 already generated the necessary reloc. */
3602 bfd_put_32 (output_bfd
, relocation
,
3603 htab
->elf
.sgot
->contents
+ off
);
3604 local_got_offsets
[r_symndx
] |= 1;
3606 if (bfd_link_pic (info
))
3607 relative_reloc
= TRUE
;
3614 Elf_Internal_Rela outrel
;
3616 s
= htab
->elf
.srelgot
;
3620 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3621 + htab
->elf
.sgot
->output_offset
3623 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3624 elf_append_rel (output_bfd
, s
, &outrel
);
3627 if (off
>= (bfd_vma
) -2)
3630 relocation
= (htab
->elf
.sgot
->output_section
->vma
3631 + htab
->elf
.sgot
->output_offset
+ off
);
3632 if (rel
->r_offset
> 1
3633 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
3634 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
3636 if (bfd_link_pic (info
))
3638 /* For PIC, disallow R_386_GOT32 without a base
3639 register, except for "lea foo@GOT, %reg", since
3640 we don't know what the GOT base is. */
3644 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
3645 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3648 name
= h
->root
.root
.string
;
3651 /* xgettext:c-format */
3652 (_("%B: direct GOT relocation %s against `%s'"
3653 " without base register can not be used"
3654 " when making a shared object"),
3655 input_bfd
, howto
->name
, name
);
3656 bfd_set_error (bfd_error_bad_value
);
3662 /* Subtract the .got.plt section address only with a base
3664 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
3665 + htab
->elf
.sgotplt
->output_offset
);
3671 /* Relocation is relative to the start of the global offset
3674 /* Check to make sure it isn't a protected function or data
3675 symbol for shared library since it may not be local when
3676 used as function address or with copy relocation. We also
3677 need to make sure that a symbol is referenced locally. */
3678 if (!bfd_link_executable (info
) && h
)
3680 if (!h
->def_regular
)
3684 switch (ELF_ST_VISIBILITY (h
->other
))
3687 v
= _("hidden symbol");
3690 v
= _("internal symbol");
3693 v
= _("protected symbol");
3701 /* xgettext:c-format */
3702 (_("%B: relocation R_386_GOTOFF against undefined %s"
3703 " `%s' can not be used when making a shared object"),
3704 input_bfd
, v
, h
->root
.root
.string
);
3705 bfd_set_error (bfd_error_bad_value
);
3708 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
3709 && (h
->type
== STT_FUNC
3710 || h
->type
== STT_OBJECT
)
3711 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3714 /* xgettext:c-format */
3715 (_("%B: relocation R_386_GOTOFF against protected %s"
3716 " `%s' can not be used when making a shared object"),
3718 h
->type
== STT_FUNC
? "function" : "data",
3719 h
->root
.root
.string
);
3720 bfd_set_error (bfd_error_bad_value
);
3725 /* Note that sgot is not involved in this
3726 calculation. We always want the start of .got.plt. If we
3727 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3728 permitted by the ABI, we might have to change this
3730 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3731 + htab
->elf
.sgotplt
->output_offset
;
3735 /* Use global offset table as symbol value. */
3736 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3737 + htab
->elf
.sgotplt
->output_offset
;
3738 unresolved_reloc
= FALSE
;
3742 /* Relocation is to the entry for this symbol in the
3743 procedure linkage table. */
3745 /* Resolve a PLT32 reloc against a local symbol directly,
3746 without using the procedure linkage table. */
3750 if ((h
->plt
.offset
== (bfd_vma
) -1
3751 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3752 || htab
->elf
.splt
== NULL
)
3754 /* We didn't make a PLT entry for this symbol. This
3755 happens when statically linking PIC code, or when
3756 using -Bsymbolic. */
3760 if (h
->plt
.offset
!= (bfd_vma
) -1)
3762 if (htab
->plt_second
!= NULL
)
3764 resolved_plt
= htab
->plt_second
;
3765 plt_offset
= eh
->plt_second
.offset
;
3769 resolved_plt
= htab
->elf
.splt
;
3770 plt_offset
= h
->plt
.offset
;
3775 resolved_plt
= htab
->plt_got
;
3776 plt_offset
= eh
->plt_got
.offset
;
3779 relocation
= (resolved_plt
->output_section
->vma
3780 + resolved_plt
->output_offset
3782 unresolved_reloc
= FALSE
;
3786 /* Set to symbol size. */
3787 relocation
= st_size
;
3792 if ((input_section
->flags
& SEC_ALLOC
) == 0
3796 /* Copy dynamic function pointer relocations. Don't generate
3797 dynamic relocations against resolved undefined weak symbols
3798 in PIE, except for R_386_PC32. */
3799 if ((bfd_link_pic (info
)
3801 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3802 && (!resolved_to_zero
3803 || r_type
== R_386_PC32
))
3804 || h
->root
.type
!= bfd_link_hash_undefweak
))
3805 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
3806 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3807 || (ELIMINATE_COPY_RELOCS
3808 && !bfd_link_pic (info
)
3812 || eh
->func_pointer_refcount
> 0
3813 || (h
->root
.type
== bfd_link_hash_undefweak
3814 && !resolved_to_zero
))
3815 && ((h
->def_dynamic
&& !h
->def_regular
)
3816 /* Undefined weak symbol is bound locally when
3818 || h
->root
.type
== bfd_link_hash_undefweak
)))
3820 Elf_Internal_Rela outrel
;
3821 bfd_boolean skip
, relocate
;
3824 /* When generating a shared object, these relocations
3825 are copied into the output file to be resolved at run
3832 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3834 if (outrel
.r_offset
== (bfd_vma
) -1)
3836 else if (outrel
.r_offset
== (bfd_vma
) -2)
3837 skip
= TRUE
, relocate
= TRUE
;
3838 outrel
.r_offset
+= (input_section
->output_section
->vma
3839 + input_section
->output_offset
);
3842 memset (&outrel
, 0, sizeof outrel
);
3845 && (r_type
== R_386_PC32
3846 || !(bfd_link_executable (info
)
3847 || SYMBOLIC_BIND (info
, h
))
3848 || !h
->def_regular
))
3849 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3852 /* This symbol is local, or marked to become local. */
3854 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3857 sreloc
= elf_section_data (input_section
)->sreloc
;
3859 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3861 r
= bfd_reloc_notsupported
;
3862 goto check_relocation_error
;
3865 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3867 /* If this reloc is against an external symbol, we do
3868 not want to fiddle with the addend. Otherwise, we
3869 need to include the symbol value so that it becomes
3870 an addend for the dynamic reloc. */
3877 if (!bfd_link_executable (info
))
3879 Elf_Internal_Rela outrel
;
3882 outrel
.r_offset
= rel
->r_offset
3883 + input_section
->output_section
->vma
3884 + input_section
->output_offset
;
3885 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3886 sreloc
= elf_section_data (input_section
)->sreloc
;
3889 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3894 case R_386_TLS_GOTDESC
:
3895 case R_386_TLS_DESC_CALL
:
3896 case R_386_TLS_IE_32
:
3897 case R_386_TLS_GOTIE
:
3898 tls_type
= GOT_UNKNOWN
;
3899 if (h
== NULL
&& local_got_offsets
)
3900 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
3902 tls_type
= elf_x86_hash_entry(h
)->tls_type
;
3903 if (tls_type
== GOT_TLS_IE
)
3904 tls_type
= GOT_TLS_IE_NEG
;
3906 if (! elf_i386_tls_transition (info
, input_bfd
,
3907 input_section
, contents
,
3908 symtab_hdr
, sym_hashes
,
3909 &r_type
, tls_type
, rel
,
3910 relend
, h
, r_symndx
, TRUE
))
3913 if (r_type
== R_386_TLS_LE_32
)
3915 BFD_ASSERT (! unresolved_reloc
);
3916 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3921 /* GD->LE transition. */
3922 type
= *(contents
+ rel
->r_offset
- 2);
3926 leal foo@tlsgd(,%ebx,1), %eax
3927 call ___tls_get_addr@PLT
3930 subl $foo@tpoff, %eax
3931 (6 byte form of subl). */
3932 roff
= rel
->r_offset
+ 5;
3937 leal foo@tlsgd(%ebx), %eax
3938 call ___tls_get_addr@PLT
3941 leal foo@tlsgd(%reg), %eax
3942 call *___tls_get_addr@GOT(%reg)
3943 which may be converted to
3944 addr32 call ___tls_get_addr
3946 movl %gs:0, %eax; subl $foo@tpoff, %eax
3947 (6 byte form of subl). */
3948 roff
= rel
->r_offset
+ 6;
3950 memcpy (contents
+ roff
- 8,
3951 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3952 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3954 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
3959 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3961 /* GDesc -> LE transition.
3962 It's originally something like:
3963 leal x@tlsdesc(%ebx), %eax
3967 Registers other than %eax may be set up here. */
3972 roff
= rel
->r_offset
;
3973 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3975 /* Now modify the instruction as appropriate. */
3976 /* aoliva FIXME: remove the above and xor the byte
3978 bfd_put_8 (output_bfd
, val
^ 0x86,
3979 contents
+ roff
- 1);
3980 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3984 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3986 /* GDesc -> LE transition.
3994 roff
= rel
->r_offset
;
3995 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3996 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3999 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4003 /* IE->LE transition:
4004 Originally it can be one of:
4012 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4015 /* movl foo, %eax. */
4016 bfd_put_8 (output_bfd
, 0xb8,
4017 contents
+ rel
->r_offset
- 1);
4023 type
= bfd_get_8 (input_bfd
,
4024 contents
+ rel
->r_offset
- 2);
4029 bfd_put_8 (output_bfd
, 0xc7,
4030 contents
+ rel
->r_offset
- 2);
4031 bfd_put_8 (output_bfd
,
4032 0xc0 | ((val
>> 3) & 7),
4033 contents
+ rel
->r_offset
- 1);
4037 bfd_put_8 (output_bfd
, 0x81,
4038 contents
+ rel
->r_offset
- 2);
4039 bfd_put_8 (output_bfd
,
4040 0xc0 | ((val
>> 3) & 7),
4041 contents
+ rel
->r_offset
- 1);
4048 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4049 contents
+ rel
->r_offset
);
4054 unsigned int val
, type
;
4056 /* {IE_32,GOTIE}->LE transition:
4057 Originally it can be one of:
4058 subl foo(%reg1), %reg2
4059 movl foo(%reg1), %reg2
4060 addl foo(%reg1), %reg2
4063 movl $foo, %reg2 (6 byte form)
4064 addl $foo, %reg2. */
4065 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4066 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4070 bfd_put_8 (output_bfd
, 0xc7,
4071 contents
+ rel
->r_offset
- 2);
4072 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4073 contents
+ rel
->r_offset
- 1);
4075 else if (type
== 0x2b)
4078 bfd_put_8 (output_bfd
, 0x81,
4079 contents
+ rel
->r_offset
- 2);
4080 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4081 contents
+ rel
->r_offset
- 1);
4083 else if (type
== 0x03)
4086 bfd_put_8 (output_bfd
, 0x81,
4087 contents
+ rel
->r_offset
- 2);
4088 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4089 contents
+ rel
->r_offset
- 1);
4093 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4094 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4095 contents
+ rel
->r_offset
);
4097 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4098 contents
+ rel
->r_offset
);
4103 if (htab
->elf
.sgot
== NULL
)
4108 off
= h
->got
.offset
;
4109 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
4113 if (local_got_offsets
== NULL
)
4116 off
= local_got_offsets
[r_symndx
];
4117 offplt
= local_tlsdesc_gotents
[r_symndx
];
4124 Elf_Internal_Rela outrel
;
4128 if (htab
->elf
.srelgot
== NULL
)
4131 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4133 if (GOT_TLS_GDESC_P (tls_type
))
4136 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4137 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4138 <= htab
->elf
.sgotplt
->size
);
4139 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4140 + htab
->elf
.sgotplt
->output_offset
4142 + htab
->sgotplt_jump_table_size
);
4143 sreloc
= htab
->elf
.srelplt
;
4144 loc
= sreloc
->contents
;
4145 loc
+= (htab
->next_tls_desc_index
++
4146 * sizeof (Elf32_External_Rel
));
4147 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4148 <= sreloc
->contents
+ sreloc
->size
);
4149 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4152 BFD_ASSERT (! unresolved_reloc
);
4153 bfd_put_32 (output_bfd
,
4154 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4155 htab
->elf
.sgotplt
->contents
+ offplt
4156 + htab
->sgotplt_jump_table_size
+ 4);
4160 bfd_put_32 (output_bfd
, 0,
4161 htab
->elf
.sgotplt
->contents
+ offplt
4162 + htab
->sgotplt_jump_table_size
+ 4);
4166 sreloc
= htab
->elf
.srelgot
;
4168 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4169 + htab
->elf
.sgot
->output_offset
+ off
);
4171 if (GOT_TLS_GD_P (tls_type
))
4172 dr_type
= R_386_TLS_DTPMOD32
;
4173 else if (GOT_TLS_GDESC_P (tls_type
))
4175 else if (tls_type
== GOT_TLS_IE_POS
)
4176 dr_type
= R_386_TLS_TPOFF
;
4178 dr_type
= R_386_TLS_TPOFF32
;
4180 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
4181 bfd_put_32 (output_bfd
,
4182 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4183 htab
->elf
.sgot
->contents
+ off
);
4184 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
4185 bfd_put_32 (output_bfd
,
4186 _bfd_x86_elf_dtpoff_base (info
) - relocation
,
4187 htab
->elf
.sgot
->contents
+ off
);
4188 else if (dr_type
!= R_386_TLS_DESC
)
4189 bfd_put_32 (output_bfd
, 0,
4190 htab
->elf
.sgot
->contents
+ off
);
4191 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
4193 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4195 if (GOT_TLS_GD_P (tls_type
))
4199 BFD_ASSERT (! unresolved_reloc
);
4200 bfd_put_32 (output_bfd
,
4201 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4202 htab
->elf
.sgot
->contents
+ off
+ 4);
4206 bfd_put_32 (output_bfd
, 0,
4207 htab
->elf
.sgot
->contents
+ off
+ 4);
4208 outrel
.r_info
= ELF32_R_INFO (indx
,
4209 R_386_TLS_DTPOFF32
);
4210 outrel
.r_offset
+= 4;
4211 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4214 else if (tls_type
== GOT_TLS_IE_BOTH
)
4216 bfd_put_32 (output_bfd
,
4218 ? relocation
- _bfd_x86_elf_dtpoff_base (info
)
4220 htab
->elf
.sgot
->contents
+ off
+ 4);
4221 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4222 outrel
.r_offset
+= 4;
4223 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4230 local_got_offsets
[r_symndx
] |= 1;
4233 if (off
>= (bfd_vma
) -2
4234 && ! GOT_TLS_GDESC_P (tls_type
))
4236 if (r_type
== R_386_TLS_GOTDESC
4237 || r_type
== R_386_TLS_DESC_CALL
)
4239 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4240 unresolved_reloc
= FALSE
;
4242 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4244 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4245 + htab
->elf
.sgotplt
->output_offset
;
4246 relocation
= htab
->elf
.sgot
->output_section
->vma
4247 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4248 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4249 && tls_type
== GOT_TLS_IE_BOTH
)
4251 if (r_type
== R_386_TLS_IE
)
4252 relocation
+= g_o_t
;
4253 unresolved_reloc
= FALSE
;
4255 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4257 unsigned int val
, type
;
4260 /* GD->IE transition. */
4261 type
= *(contents
+ rel
->r_offset
- 2);
4262 val
= *(contents
+ rel
->r_offset
- 1);
4266 leal foo@tlsgd(,%ebx,1), %eax
4267 call ___tls_get_addr@PLT
4270 subl $foo@gottpoff(%ebx), %eax. */
4272 roff
= rel
->r_offset
- 3;
4277 leal foo@tlsgd(%ebx), %eax
4278 call ___tls_get_addr@PLT
4281 leal foo@tlsgd(%reg), %eax
4282 call *___tls_get_addr@GOT(%reg)
4283 which may be converted to
4284 addr32 call ___tls_get_addr
4287 subl $foo@gottpoff(%reg), %eax. */
4288 roff
= rel
->r_offset
- 2;
4290 memcpy (contents
+ roff
,
4291 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4292 contents
[roff
+ 7] = 0x80 | (val
& 7);
4293 /* If foo is used only with foo@gotntpoff(%reg) and
4294 foo@indntpoff, but not with foo@gottpoff(%reg), change
4295 subl $foo@gottpoff(%reg), %eax
4297 addl $foo@gotntpoff(%reg), %eax. */
4298 if (tls_type
== GOT_TLS_IE_POS
)
4299 contents
[roff
+ 6] = 0x03;
4300 bfd_put_32 (output_bfd
,
4301 htab
->elf
.sgot
->output_section
->vma
4302 + htab
->elf
.sgot
->output_offset
+ off
4303 - htab
->elf
.sgotplt
->output_section
->vma
4304 - htab
->elf
.sgotplt
->output_offset
,
4305 contents
+ roff
+ 8);
4306 /* Skip R_386_PLT32 and R_386_GOT32X. */
4311 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4313 /* GDesc -> IE transition.
4314 It's originally something like:
4315 leal x@tlsdesc(%ebx), %eax
4318 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4320 movl x@gottpoff(%ebx), %eax # before negl %eax
4322 Registers other than %eax may be set up here. */
4326 /* First, make sure it's a leal adding ebx to a 32-bit
4327 offset into any register, although it's probably
4328 almost always going to be eax. */
4329 roff
= rel
->r_offset
;
4331 /* Now modify the instruction as appropriate. */
4332 /* To turn a leal into a movl in the form we use it, it
4333 suffices to change the first byte from 0x8d to 0x8b.
4334 aoliva FIXME: should we decide to keep the leal, all
4335 we have to do is remove the statement below, and
4336 adjust the relaxation of R_386_TLS_DESC_CALL. */
4337 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4339 if (tls_type
== GOT_TLS_IE_BOTH
)
4342 bfd_put_32 (output_bfd
,
4343 htab
->elf
.sgot
->output_section
->vma
4344 + htab
->elf
.sgot
->output_offset
+ off
4345 - htab
->elf
.sgotplt
->output_section
->vma
4346 - htab
->elf
.sgotplt
->output_offset
,
4350 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4352 /* GDesc -> IE transition.
4360 depending on how we transformed the TLS_GOTDESC above.
4365 roff
= rel
->r_offset
;
4367 /* Now modify the instruction as appropriate. */
4368 if (tls_type
!= GOT_TLS_IE_NEG
)
4371 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4372 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4377 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4378 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4388 if (! elf_i386_tls_transition (info
, input_bfd
,
4389 input_section
, contents
,
4390 symtab_hdr
, sym_hashes
,
4391 &r_type
, GOT_UNKNOWN
, rel
,
4392 relend
, h
, r_symndx
, TRUE
))
4395 if (r_type
!= R_386_TLS_LDM
)
4397 /* LD->LE transition. Change
4398 leal foo@tlsldm(%ebx) %eax
4399 call ___tls_get_addr@PLT
4403 leal 0(%esi,1), %esi
4405 leal foo@tlsldm(%reg) %eax
4406 call *___tls_get_addr@GOT(%reg)
4407 which may be converted to
4408 addr32 call ___tls_get_addr
4411 leal 0(%esi), %esi */
4412 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4413 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
4414 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
4415 memcpy (contents
+ rel
->r_offset
- 2,
4416 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
4418 memcpy (contents
+ rel
->r_offset
- 2,
4419 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4420 /* Skip R_386_PC32/R_386_PLT32. */
4426 if (htab
->elf
.sgot
== NULL
)
4429 off
= htab
->tls_ld_or_ldm_got
.offset
;
4434 Elf_Internal_Rela outrel
;
4436 if (htab
->elf
.srelgot
== NULL
)
4439 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4440 + htab
->elf
.sgot
->output_offset
+ off
);
4442 bfd_put_32 (output_bfd
, 0,
4443 htab
->elf
.sgot
->contents
+ off
);
4444 bfd_put_32 (output_bfd
, 0,
4445 htab
->elf
.sgot
->contents
+ off
+ 4);
4446 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4447 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
4448 htab
->tls_ld_or_ldm_got
.offset
|= 1;
4450 relocation
= htab
->elf
.sgot
->output_section
->vma
4451 + htab
->elf
.sgot
->output_offset
+ off
4452 - htab
->elf
.sgotplt
->output_section
->vma
4453 - htab
->elf
.sgotplt
->output_offset
;
4454 unresolved_reloc
= FALSE
;
4457 case R_386_TLS_LDO_32
:
4458 if (!bfd_link_executable (info
)
4459 || (input_section
->flags
& SEC_CODE
) == 0)
4460 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4462 /* When converting LDO to LE, we must negate. */
4463 relocation
= -elf_i386_tpoff (info
, relocation
);
4466 case R_386_TLS_LE_32
:
4468 if (!bfd_link_executable (info
))
4470 Elf_Internal_Rela outrel
;
4473 outrel
.r_offset
= rel
->r_offset
4474 + input_section
->output_section
->vma
4475 + input_section
->output_offset
;
4476 if (h
!= NULL
&& h
->dynindx
!= -1)
4480 if (r_type
== R_386_TLS_LE_32
)
4481 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4483 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4484 sreloc
= elf_section_data (input_section
)->sreloc
;
4487 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4490 else if (r_type
== R_386_TLS_LE_32
)
4491 relocation
= _bfd_x86_elf_dtpoff_base (info
) - relocation
;
4493 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4495 else if (r_type
== R_386_TLS_LE_32
)
4496 relocation
= elf_i386_tpoff (info
, relocation
);
4498 relocation
= -elf_i386_tpoff (info
, relocation
);
4505 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4506 because such sections are not SEC_ALLOC and thus ld.so will
4507 not process them. */
4508 if (unresolved_reloc
4509 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4511 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4512 rel
->r_offset
) != (bfd_vma
) -1)
4515 /* xgettext:c-format */
4516 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
4521 h
->root
.root
.string
);
4526 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4527 contents
, rel
->r_offset
,
4530 check_relocation_error
:
4531 if (r
!= bfd_reloc_ok
)
4536 name
= h
->root
.root
.string
;
4539 name
= bfd_elf_string_from_elf_section (input_bfd
,
4540 symtab_hdr
->sh_link
,
4545 name
= bfd_section_name (input_bfd
, sec
);
4548 if (r
== bfd_reloc_overflow
)
4549 (*info
->callbacks
->reloc_overflow
)
4550 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4551 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4555 /* xgettext:c-format */
4556 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
4557 input_bfd
, input_section
,
4558 rel
->r_offset
, name
, (int) r
);
4569 Elf_Internal_Shdr
*rel_hdr
;
4570 size_t deleted
= rel
- wrel
;
4572 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
4573 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4574 if (rel_hdr
->sh_size
== 0)
4576 /* It is too late to remove an empty reloc section. Leave
4578 ??? What is wrong with an empty section??? */
4579 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
4582 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
4583 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4584 input_section
->reloc_count
-= deleted
;
4590 /* Finish up dynamic symbol handling. We set the contents of various
4591 dynamic sections here. */
4594 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4595 struct bfd_link_info
*info
,
4596 struct elf_link_hash_entry
*h
,
4597 Elf_Internal_Sym
*sym
)
4599 struct elf_x86_link_hash_table
*htab
;
4600 unsigned plt_entry_size
;
4601 const struct elf_i386_backend_data
*abed
;
4602 struct elf_x86_link_hash_entry
*eh
;
4603 bfd_boolean local_undefweak
;
4604 bfd_boolean use_plt_second
;
4606 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
4610 abed
= get_elf_i386_backend_data (output_bfd
);
4611 plt_entry_size
= htab
->plt
.plt_entry_size
;
4613 /* Use the second PLT section only if there is .plt section. */
4614 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
4616 eh
= (struct elf_x86_link_hash_entry
*) h
;
4617 if (eh
->no_finish_dynamic_symbol
)
4620 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4621 resolved undefined weak symbols in executable so that their
4622 references have value 0 at run-time. */
4623 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, I386_ELF_DATA
,
4627 if (h
->plt
.offset
!= (bfd_vma
) -1)
4629 bfd_vma plt_index
, plt_offset
;
4631 Elf_Internal_Rela rel
;
4633 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
4635 /* When building a static executable, use .iplt, .igot.plt and
4636 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4637 if (htab
->elf
.splt
!= NULL
)
4639 plt
= htab
->elf
.splt
;
4640 gotplt
= htab
->elf
.sgotplt
;
4641 relplt
= htab
->elf
.srelplt
;
4645 plt
= htab
->elf
.iplt
;
4646 gotplt
= htab
->elf
.igotplt
;
4647 relplt
= htab
->elf
.irelplt
;
4650 /* This symbol has an entry in the procedure linkage table. Set
4653 if ((h
->dynindx
== -1
4655 && !((h
->forced_local
|| bfd_link_executable (info
))
4657 && h
->type
== STT_GNU_IFUNC
))
4663 /* Get the index in the procedure linkage table which
4664 corresponds to this symbol. This is the index of this symbol
4665 in all the symbols for which we are making plt entries. The
4666 first entry in the procedure linkage table is reserved.
4668 Get the offset into the .got table of the entry that
4669 corresponds to this function. Each .got entry is 4 bytes.
4670 The first three are reserved.
4672 For static executables, we don't reserve anything. */
4674 if (plt
== htab
->elf
.splt
)
4676 got_offset
= (h
->plt
.offset
/ plt_entry_size
4677 - htab
->plt
.has_plt0
);
4678 got_offset
= (got_offset
+ 3) * 4;
4682 got_offset
= h
->plt
.offset
/ plt_entry_size
;
4683 got_offset
= got_offset
* 4;
4686 /* Fill in the entry in the procedure linkage table and update
4688 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
4693 const bfd_byte
*plt_entry
;
4694 if (bfd_link_pic (info
))
4695 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
4697 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
4698 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
4699 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
4701 resolved_plt
= htab
->plt_second
;
4702 plt_offset
= eh
->plt_second
.offset
;
4707 plt_offset
= h
->plt
.offset
;
4710 if (! bfd_link_pic (info
))
4712 bfd_put_32 (output_bfd
,
4713 (gotplt
->output_section
->vma
4714 + gotplt
->output_offset
4716 resolved_plt
->contents
+ plt_offset
4717 + htab
->plt
.plt_got_offset
);
4719 if (abed
->os
== is_vxworks
)
4721 int s
, k
, reloc_index
;
4723 /* Create the R_386_32 relocation referencing the GOT
4724 for this PLT entry. */
4726 /* S: Current slot number (zero-based). */
4727 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
4728 / htab
->plt
.plt_entry_size
);
4729 /* K: Number of relocations for PLTResolve. */
4730 if (bfd_link_pic (info
))
4731 k
= PLTRESOLVE_RELOCS_SHLIB
;
4733 k
= PLTRESOLVE_RELOCS
;
4734 /* Skip the PLTresolve relocations, and the relocations for
4735 the other PLT slots. */
4736 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4737 loc
= (htab
->srelplt2
->contents
+ reloc_index
4738 * sizeof (Elf32_External_Rel
));
4740 rel
.r_offset
= (plt
->output_section
->vma
4741 + plt
->output_offset
4742 + h
->plt
.offset
+ 2),
4743 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4744 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4746 /* Create the R_386_32 relocation referencing the beginning of
4747 the PLT for this GOT entry. */
4748 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4749 + htab
->elf
.sgotplt
->output_offset
4751 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4752 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4753 loc
+ sizeof (Elf32_External_Rel
));
4758 bfd_put_32 (output_bfd
, got_offset
,
4759 resolved_plt
->contents
+ plt_offset
4760 + htab
->plt
.plt_got_offset
);
4763 /* Fill in the entry in the global offset table. Leave the entry
4764 as zero for undefined weak symbol in PIE. No PLT relocation
4765 against undefined weak symbol in PIE. */
4766 if (!local_undefweak
)
4768 if (htab
->plt
.has_plt0
)
4769 bfd_put_32 (output_bfd
,
4770 (plt
->output_section
->vma
4771 + plt
->output_offset
4773 + htab
->lazy_plt
->plt_lazy_offset
),
4774 gotplt
->contents
+ got_offset
);
4776 /* Fill in the entry in the .rel.plt section. */
4777 rel
.r_offset
= (gotplt
->output_section
->vma
4778 + gotplt
->output_offset
4780 if (h
->dynindx
== -1
4781 || ((bfd_link_executable (info
)
4782 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4784 && h
->type
== STT_GNU_IFUNC
))
4786 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4787 h
->root
.root
.string
,
4788 h
->root
.u
.def
.section
->owner
);
4790 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4791 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4792 in the .got.plt section. */
4793 bfd_put_32 (output_bfd
,
4794 (h
->root
.u
.def
.value
4795 + h
->root
.u
.def
.section
->output_section
->vma
4796 + h
->root
.u
.def
.section
->output_offset
),
4797 gotplt
->contents
+ got_offset
);
4798 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4799 /* R_386_IRELATIVE comes last. */
4800 plt_index
= htab
->next_irelative_index
--;
4804 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4805 plt_index
= htab
->next_jump_slot_index
++;
4808 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4809 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4811 /* Don't fill the second and third slots in PLT entry for
4812 static executables nor without PLT0. */
4813 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
4815 bfd_put_32 (output_bfd
,
4816 plt_index
* sizeof (Elf32_External_Rel
),
4817 plt
->contents
+ h
->plt
.offset
4818 + htab
->lazy_plt
->plt_reloc_offset
);
4819 bfd_put_32 (output_bfd
,
4821 + htab
->lazy_plt
->plt_plt_offset
+ 4),
4822 (plt
->contents
+ h
->plt
.offset
4823 + htab
->lazy_plt
->plt_plt_offset
));
4827 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4829 bfd_vma got_offset
, plt_offset
;
4830 asection
*plt
, *got
, *gotplt
;
4831 const bfd_byte
*got_plt_entry
;
4833 /* Set the entry in the GOT procedure linkage table. */
4834 plt
= htab
->plt_got
;
4835 got
= htab
->elf
.sgot
;
4836 gotplt
= htab
->elf
.sgotplt
;
4837 got_offset
= h
->got
.offset
;
4839 if (got_offset
== (bfd_vma
) -1
4845 /* Fill in the entry in the GOT procedure linkage table. */
4846 if (! bfd_link_pic (info
))
4848 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
4849 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
4853 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
4854 got_offset
+= (got
->output_section
->vma
4855 + got
->output_offset
4856 - gotplt
->output_section
->vma
4857 - gotplt
->output_offset
);
4860 plt_offset
= eh
->plt_got
.offset
;
4861 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
4862 htab
->non_lazy_plt
->plt_entry_size
);
4863 bfd_put_32 (output_bfd
, got_offset
,
4864 (plt
->contents
+ plt_offset
4865 + htab
->non_lazy_plt
->plt_got_offset
));
4868 if (!local_undefweak
4870 && (h
->plt
.offset
!= (bfd_vma
) -1
4871 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4873 /* Mark the symbol as undefined, rather than as defined in
4874 the .plt section. Leave the value if there were any
4875 relocations where pointer equality matters (this is a clue
4876 for the dynamic linker, to make function pointer
4877 comparisons work between an application and shared
4878 library), otherwise set it to zero. If a function is only
4879 called from a binary, there is no need to slow down
4880 shared libraries because of that. */
4881 sym
->st_shndx
= SHN_UNDEF
;
4882 if (!h
->pointer_equality_needed
)
4886 /* Don't generate dynamic GOT relocation against undefined weak
4887 symbol in executable. */
4888 if (h
->got
.offset
!= (bfd_vma
) -1
4889 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h
)->tls_type
)
4890 && (elf_x86_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
4891 && !local_undefweak
)
4893 Elf_Internal_Rela rel
;
4894 asection
*relgot
= htab
->elf
.srelgot
;
4896 /* This symbol has an entry in the global offset table. Set it
4899 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4902 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4903 + htab
->elf
.sgot
->output_offset
4904 + (h
->got
.offset
& ~(bfd_vma
) 1));
4906 /* If this is a static link, or it is a -Bsymbolic link and the
4907 symbol is defined locally or was forced to be local because
4908 of a version file, we just want to emit a RELATIVE reloc.
4909 The entry in the global offset table will already have been
4910 initialized in the relocate_section function. */
4912 && h
->type
== STT_GNU_IFUNC
)
4914 if (h
->plt
.offset
== (bfd_vma
) -1)
4916 /* STT_GNU_IFUNC is referenced without PLT. */
4917 if (htab
->elf
.splt
== NULL
)
4919 /* use .rel[a].iplt section to store .got relocations
4920 in static executable. */
4921 relgot
= htab
->elf
.irelplt
;
4923 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4925 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4926 h
->root
.root
.string
,
4927 h
->root
.u
.def
.section
->owner
);
4929 bfd_put_32 (output_bfd
,
4930 (h
->root
.u
.def
.value
4931 + h
->root
.u
.def
.section
->output_section
->vma
4932 + h
->root
.u
.def
.section
->output_offset
),
4933 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4934 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4939 else if (bfd_link_pic (info
))
4941 /* Generate R_386_GLOB_DAT. */
4949 if (!h
->pointer_equality_needed
)
4952 /* For non-shared object, we can't use .got.plt, which
4953 contains the real function addres if we need pointer
4954 equality. We load the GOT entry with the PLT entry. */
4955 if (htab
->plt_second
!= NULL
)
4957 plt
= htab
->plt_second
;
4958 plt_offset
= eh
->plt_second
.offset
;
4962 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4963 plt_offset
= h
->plt
.offset
;
4965 bfd_put_32 (output_bfd
,
4966 (plt
->output_section
->vma
4967 + plt
->output_offset
+ plt_offset
),
4968 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4972 else if (bfd_link_pic (info
)
4973 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4975 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4976 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4980 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4982 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4983 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4984 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4987 elf_append_rel (output_bfd
, relgot
, &rel
);
4992 Elf_Internal_Rela rel
;
4995 /* This symbol needs a copy reloc. Set it up. */
4997 if (h
->dynindx
== -1
4998 || (h
->root
.type
!= bfd_link_hash_defined
4999 && h
->root
.type
!= bfd_link_hash_defweak
)
5000 || htab
->elf
.srelbss
== NULL
5001 || htab
->elf
.sreldynrelro
== NULL
)
5004 rel
.r_offset
= (h
->root
.u
.def
.value
5005 + h
->root
.u
.def
.section
->output_section
->vma
5006 + h
->root
.u
.def
.section
->output_offset
);
5007 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5008 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5009 s
= htab
->elf
.sreldynrelro
;
5011 s
= htab
->elf
.srelbss
;
5012 elf_append_rel (output_bfd
, s
, &rel
);
5018 /* Finish up local dynamic symbol handling. We set the contents of
5019 various dynamic sections here. */
5022 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5024 struct elf_link_hash_entry
*h
5025 = (struct elf_link_hash_entry
*) *slot
;
5026 struct bfd_link_info
*info
5027 = (struct bfd_link_info
*) inf
;
5029 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5033 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5034 here since undefined weak symbol may not be dynamic and may not be
5035 called for elf_i386_finish_dynamic_symbol. */
5038 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5041 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5042 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5044 if (h
->root
.type
!= bfd_link_hash_undefweak
5045 || h
->dynindx
!= -1)
5048 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5052 /* Used to decide how to sort relocs in an optimal manner for the
5053 dynamic linker, before writing them out. */
5055 static enum elf_reloc_type_class
5056 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5057 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5058 const Elf_Internal_Rela
*rela
)
5060 bfd
*abfd
= info
->output_bfd
;
5061 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5062 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5064 if (htab
->dynsym
!= NULL
5065 && htab
->dynsym
->contents
!= NULL
)
5067 /* Check relocation against STT_GNU_IFUNC symbol if there are
5069 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5070 if (r_symndx
!= STN_UNDEF
)
5072 Elf_Internal_Sym sym
;
5073 if (!bed
->s
->swap_symbol_in (abfd
,
5074 (htab
->dynsym
->contents
5075 + r_symndx
* sizeof (Elf32_External_Sym
)),
5079 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5080 return reloc_class_ifunc
;
5084 switch (ELF32_R_TYPE (rela
->r_info
))
5086 case R_386_IRELATIVE
:
5087 return reloc_class_ifunc
;
5088 case R_386_RELATIVE
:
5089 return reloc_class_relative
;
5090 case R_386_JUMP_SLOT
:
5091 return reloc_class_plt
;
5093 return reloc_class_copy
;
5095 return reloc_class_normal
;
5099 /* Finish up the dynamic sections. */
5102 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5103 struct bfd_link_info
*info
)
5105 struct elf_x86_link_hash_table
*htab
;
5108 const struct elf_i386_backend_data
*abed
;
5110 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
5114 dynobj
= htab
->elf
.dynobj
;
5115 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5116 abed
= get_elf_i386_backend_data (output_bfd
);
5118 if (htab
->elf
.dynamic_sections_created
)
5120 Elf32_External_Dyn
*dyncon
, *dynconend
;
5122 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5125 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5126 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5127 for (; dyncon
< dynconend
; dyncon
++)
5129 Elf_Internal_Dyn dyn
;
5132 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5137 if (abed
->os
== is_vxworks
5138 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5143 s
= htab
->elf
.sgotplt
;
5144 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5148 s
= htab
->elf
.srelplt
;
5149 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5153 s
= htab
->elf
.srelplt
;
5154 dyn
.d_un
.d_val
= s
->size
;
5158 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5161 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5163 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5164 really seem like the right value. */
5165 elf_section_data (htab
->elf
.splt
->output_section
)
5166 ->this_hdr
.sh_entsize
= 4;
5168 if (htab
->plt
.has_plt0
)
5170 /* Fill in the special first entry in the procedure linkage
5172 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
5173 htab
->lazy_plt
->plt0_entry_size
);
5174 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
5175 abed
->plt0_pad_byte
,
5176 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
5177 if (!bfd_link_pic (info
))
5179 bfd_put_32 (output_bfd
,
5180 (htab
->elf
.sgotplt
->output_section
->vma
5181 + htab
->elf
.sgotplt
->output_offset
5183 htab
->elf
.splt
->contents
5184 + htab
->lazy_plt
->plt0_got1_offset
);
5185 bfd_put_32 (output_bfd
,
5186 (htab
->elf
.sgotplt
->output_section
->vma
5187 + htab
->elf
.sgotplt
->output_offset
5189 htab
->elf
.splt
->contents
5190 + htab
->lazy_plt
->plt0_got2_offset
);
5192 if (abed
->os
== is_vxworks
)
5194 Elf_Internal_Rela rel
;
5195 int num_plts
= (htab
->elf
.splt
->size
5196 / htab
->plt
.plt_entry_size
) - 1;
5198 asection
*srelplt2
= htab
->srelplt2
;
5200 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5201 + 4. On IA32 we use REL relocations so the
5202 addend goes in the PLT directly. */
5203 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5204 + htab
->elf
.splt
->output_offset
5205 + htab
->lazy_plt
->plt0_got1_offset
);
5206 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5208 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5209 srelplt2
->contents
);
5210 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
5212 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5213 + htab
->elf
.splt
->output_offset
5214 + htab
->lazy_plt
->plt0_got2_offset
);
5215 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5217 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5218 srelplt2
->contents
+
5219 sizeof (Elf32_External_Rel
));
5220 /* Correct the .rel.plt.unloaded relocations. */
5221 p
= srelplt2
->contents
;
5222 if (bfd_link_pic (info
))
5223 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
5225 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
5227 for (; num_plts
; num_plts
--)
5229 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5230 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
5232 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5233 p
+= sizeof (Elf32_External_Rel
);
5235 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5236 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
5238 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5239 p
+= sizeof (Elf32_External_Rel
);
5246 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
5247 elf_section_data (htab
->plt_got
->output_section
)
5248 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
5250 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
5251 elf_section_data (htab
->plt_second
->output_section
)
5252 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
5255 /* Fill in the first three entries in the global offset table. */
5256 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
5258 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5261 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5265 bfd_put_32 (output_bfd
,
5267 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
5268 htab
->elf
.sgotplt
->contents
);
5269 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
5270 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
5272 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
5275 /* Adjust .eh_frame for .plt section. */
5276 if (htab
->plt_eh_frame
!= NULL
5277 && htab
->plt_eh_frame
->contents
!= NULL
)
5279 if (htab
->elf
.splt
!= NULL
5280 && htab
->elf
.splt
->size
!= 0
5281 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5282 && htab
->elf
.splt
->output_section
!= NULL
5283 && htab
->plt_eh_frame
->output_section
!= NULL
)
5285 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5286 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5287 + htab
->plt_eh_frame
->output_offset
5288 + PLT_FDE_START_OFFSET
;
5289 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5290 htab
->plt_eh_frame
->contents
5291 + PLT_FDE_START_OFFSET
);
5293 if (htab
->plt_eh_frame
->sec_info_type
5294 == SEC_INFO_TYPE_EH_FRAME
)
5296 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5298 htab
->plt_eh_frame
->contents
))
5303 /* Adjust .eh_frame for .plt.got section. */
5304 if (htab
->plt_got_eh_frame
!= NULL
5305 && htab
->plt_got_eh_frame
->contents
!= NULL
)
5307 if (htab
->plt_got
!= NULL
5308 && htab
->plt_got
->size
!= 0
5309 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
5310 && htab
->plt_got
->output_section
!= NULL
5311 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
5313 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
5314 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
5315 + htab
->plt_got_eh_frame
->output_offset
5316 + PLT_FDE_START_OFFSET
;
5317 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5318 htab
->plt_got_eh_frame
->contents
5319 + PLT_FDE_START_OFFSET
);
5321 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5323 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5324 htab
->plt_got_eh_frame
,
5325 htab
->plt_got_eh_frame
->contents
))
5330 /* Adjust .eh_frame for the second PLT section. */
5331 if (htab
->plt_second_eh_frame
!= NULL
5332 && htab
->plt_second_eh_frame
->contents
!= NULL
)
5334 if (htab
->plt_second
!= NULL
5335 && htab
->plt_second
->size
!= 0
5336 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
5337 && htab
->plt_second
->output_section
!= NULL
5338 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
5340 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
5341 bfd_vma eh_frame_start
5342 = (htab
->plt_second_eh_frame
->output_section
->vma
5343 + htab
->plt_second_eh_frame
->output_offset
5344 + PLT_FDE_START_OFFSET
);
5345 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5346 htab
->plt_second_eh_frame
->contents
5347 + PLT_FDE_START_OFFSET
);
5349 if (htab
->plt_second_eh_frame
->sec_info_type
5350 == SEC_INFO_TYPE_EH_FRAME
)
5352 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5353 htab
->plt_second_eh_frame
,
5354 htab
->plt_second_eh_frame
->contents
))
5359 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5360 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5362 /* Fill PLT entries for undefined weak symbols in PIE. */
5363 if (bfd_link_pie (info
))
5364 bfd_hash_traverse (&info
->hash
->table
,
5365 elf_i386_pie_finish_undefweak_symbol
,
5371 /* Fill PLT/GOT entries and allocate dynamic relocations for local
5372 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
5373 It has to be done before elf_link_sort_relocs is called so that
5374 dynamic relocations are properly sorted. */
5377 elf_i386_output_arch_local_syms
5378 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5379 struct bfd_link_info
*info
,
5380 void *flaginfo ATTRIBUTE_UNUSED
,
5381 int (*func
) (void *, const char *,
5384 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
5386 struct elf_x86_link_hash_table
*htab
5387 = elf_x86_hash_table (info
, I386_ELF_DATA
);
5391 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5392 htab_traverse (htab
->loc_hash_table
,
5393 elf_i386_finish_local_dynamic_symbol
,
5399 /* Forward declaration. */
5400 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
;
5402 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
5403 dynamic relocations. */
5406 elf_i386_get_synthetic_symtab (bfd
*abfd
,
5407 long symcount ATTRIBUTE_UNUSED
,
5408 asymbol
**syms ATTRIBUTE_UNUSED
,
5415 bfd_byte
*plt_contents
;
5417 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
5418 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
5419 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
5420 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
5423 enum elf_x86_plt_type plt_type
;
5424 struct elf_x86_plt plts
[] =
5426 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
5427 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
5428 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
5429 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
5434 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
5437 if (dynsymcount
<= 0)
5440 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
5444 non_lazy_plt
= NULL
;
5445 /* Silence GCC 6. */
5447 non_lazy_ibt_plt
= NULL
;
5448 lazy_ibt_plt
= NULL
;
5449 switch (get_elf_i386_backend_data (abfd
)->os
)
5452 non_lazy_plt
= &elf_i386_non_lazy_plt
;
5453 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
5454 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
5457 lazy_plt
= &elf_i386_lazy_plt
;
5460 lazy_plt
= &elf_i386_nacl_plt
;
5467 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
5469 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
5470 if (plt
== NULL
|| plt
->size
== 0)
5473 /* Get the PLT section contents. */
5474 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
5475 if (plt_contents
== NULL
)
5477 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
5478 plt_contents
, 0, plt
->size
))
5480 free (plt_contents
);
5484 /* Check what kind of PLT it is. */
5485 plt_type
= plt_unknown
;
5486 if (plts
[j
].type
== plt_unknown
5487 && (plt
->size
>= (lazy_plt
->plt0_entry_size
5488 + lazy_plt
->plt_entry_size
)))
5490 /* Match lazy PLT first. */
5491 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
5492 lazy_plt
->plt0_got1_offset
) == 0)
5494 /* The fist entry in the lazy IBT PLT is the same as the
5496 if (lazy_ibt_plt
!= NULL
5497 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
5498 lazy_ibt_plt
->plt_entry
,
5499 lazy_ibt_plt
->plt_got_offset
) == 0))
5500 plt_type
= plt_lazy
| plt_second
;
5502 plt_type
= plt_lazy
;
5504 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
5505 lazy_plt
->plt0_got1_offset
) == 0)
5507 /* The fist entry in the PIC lazy IBT PLT is the same as
5508 the normal PIC lazy PLT. */
5509 if (lazy_ibt_plt
!= NULL
5510 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
5511 lazy_ibt_plt
->pic_plt_entry
,
5512 lazy_ibt_plt
->plt_got_offset
) == 0))
5513 plt_type
= plt_lazy
| plt_pic
| plt_second
;
5515 plt_type
= plt_lazy
| plt_pic
;
5519 if (non_lazy_plt
!= NULL
5520 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
5521 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
5523 /* Match non-lazy PLT. */
5524 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
5525 non_lazy_plt
->plt_got_offset
) == 0)
5526 plt_type
= plt_non_lazy
;
5527 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
5528 non_lazy_plt
->plt_got_offset
) == 0)
5532 if ((non_lazy_ibt_plt
!= NULL
)
5533 && (plt_type
== plt_unknown
|| plt_type
== plt_second
)
5534 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
)
5536 if (memcmp (plt_contents
,
5537 non_lazy_ibt_plt
->plt_entry
,
5538 non_lazy_ibt_plt
->plt_got_offset
) == 0)
5540 /* Match IBT PLT. */
5541 plt_type
= plt_second
;
5542 non_lazy_plt
= non_lazy_ibt_plt
;
5544 else if (memcmp (plt_contents
,
5545 non_lazy_ibt_plt
->pic_plt_entry
,
5546 non_lazy_ibt_plt
->plt_got_offset
) == 0)
5548 /* Match PIC IBT PLT. */
5549 plt_type
= plt_second
| plt_pic
;
5550 non_lazy_plt
= non_lazy_ibt_plt
;
5554 if (plt_type
== plt_unknown
)
5556 free (plt_contents
);
5561 plts
[j
].type
= plt_type
;
5563 if ((plt_type
& plt_lazy
))
5565 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
5566 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
5567 /* Skip PLT0 in lazy PLT. */
5572 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
5573 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
5577 /* Skip lazy PLT when the second PLT is used. */
5578 if ((plt_type
& (plt_lazy
| plt_second
))
5579 == (plt_lazy
| plt_second
))
5583 n
= plt
->size
/ plts
[j
].plt_entry_size
;
5588 plts
[j
].contents
= plt_contents
;
5590 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
5591 if ((plt_type
& plt_pic
))
5592 got_addr
= (bfd_vma
) -1;
5595 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
5596 got_addr
, plts
, dynsyms
,
5600 /* Set up i386 GNU properties. Return the first relocatable ELF input
5601 with GNU properties if found. Otherwise, return NULL. */
5604 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
5606 struct elf_x86_plt_layout_table plt_layout
;
5608 plt_layout
.normal_target
= FALSE
;
5609 plt_layout
.is_vxworks
= FALSE
;
5610 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
5613 plt_layout
.lazy_plt
= &elf_i386_lazy_plt
;
5614 plt_layout
.non_lazy_plt
= &elf_i386_non_lazy_plt
;
5615 plt_layout
.lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
5616 plt_layout
.non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
5617 plt_layout
.normal_target
= TRUE
;
5620 plt_layout
.lazy_plt
= &elf_i386_lazy_plt
;
5621 plt_layout
.non_lazy_plt
= NULL
;
5622 plt_layout
.lazy_ibt_plt
= NULL
;
5623 plt_layout
.non_lazy_ibt_plt
= NULL
;
5624 plt_layout
.is_vxworks
= TRUE
;
5627 plt_layout
.lazy_plt
= &elf_i386_nacl_plt
;
5628 plt_layout
.non_lazy_plt
= NULL
;
5629 plt_layout
.lazy_ibt_plt
= NULL
;
5630 plt_layout
.non_lazy_ibt_plt
= NULL
;
5634 return _bfd_x86_elf_link_setup_gnu_properties (info
, &plt_layout
);
5637 #define TARGET_LITTLE_SYM i386_elf32_vec
5638 #define TARGET_LITTLE_NAME "elf32-i386"
5639 #define ELF_ARCH bfd_arch_i386
5640 #define ELF_TARGET_ID I386_ELF_DATA
5641 #define ELF_MACHINE_CODE EM_386
5642 #define ELF_MAXPAGESIZE 0x1000
5644 #define elf_backend_can_gc_sections 1
5645 #define elf_backend_can_refcount 1
5646 #define elf_backend_want_got_plt 1
5647 #define elf_backend_plt_readonly 1
5648 #define elf_backend_want_plt_sym 0
5649 #define elf_backend_got_header_size 12
5650 #define elf_backend_plt_alignment 4
5651 #define elf_backend_dtrel_excludes_plt 1
5652 #define elf_backend_extern_protected_data 1
5653 #define elf_backend_caches_rawsize 1
5654 #define elf_backend_want_dynrelro 1
5656 /* Support RELA for objdump of prelink objects. */
5657 #define elf_info_to_howto elf_i386_info_to_howto_rel
5658 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
5660 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
5661 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
5662 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
5663 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
5665 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
5666 #define elf_backend_check_relocs elf_i386_check_relocs
5667 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5668 #define elf_backend_fake_sections elf_i386_fake_sections
5669 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
5670 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
5671 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
5672 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
5673 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
5674 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
5675 #define elf_backend_relocate_section elf_i386_relocate_section
5676 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
5677 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
5679 #include "elf32-target.h"
5681 /* FreeBSD support. */
5683 #undef TARGET_LITTLE_SYM
5684 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
5685 #undef TARGET_LITTLE_NAME
5686 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
5688 #define ELF_OSABI ELFOSABI_FREEBSD
5690 /* The kernel recognizes executables as valid only if they carry a
5691 "FreeBSD" label in the ELF header. So we put this label on all
5692 executables and (for simplicity) also all other object files. */
5695 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
5697 _bfd_elf_post_process_headers (abfd
, info
);
5699 #ifdef OLD_FREEBSD_ABI_LABEL
5701 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5702 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
5703 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5708 #undef elf_backend_post_process_headers
5709 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
5711 #define elf32_bed elf32_i386_fbsd_bed
5713 #undef elf_backend_add_symbol_hook
5715 #include "elf32-target.h"
5719 #undef TARGET_LITTLE_SYM
5720 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
5721 #undef TARGET_LITTLE_NAME
5722 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
5724 #undef elf_backend_post_process_headers
5726 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5727 objects won't be recognized. */
5731 #define elf32_bed elf32_i386_sol2_bed
5733 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5735 #undef elf_backend_static_tls_alignment
5736 #define elf_backend_static_tls_alignment 8
5738 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5740 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5742 #undef elf_backend_want_plt_sym
5743 #define elf_backend_want_plt_sym 1
5745 #undef elf_backend_strtab_flags
5746 #define elf_backend_strtab_flags SHF_STRINGS
5748 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
5749 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
5750 FALSE otherwise. ISECTION is the best guess matching section from the
5751 input bfd IBFD, but it might be NULL. */
5754 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
5755 bfd
*obfd ATTRIBUTE_UNUSED
,
5756 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
5757 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
5759 /* PR 19938: FIXME: Need to add code for setting the sh_info
5760 and sh_link fields of Solaris specific section types. */
5763 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
5764 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
5766 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
5768 The following values should be set:
5771 -----------------------------------------------------------------------------
5772 SHT_SUNW_ancillary The section header index of 0
5773 [0x6fffffee] the associated string table.
5775 SHT_SUNW_capinfo The section header index of For a dynamic object, the
5776 [0x6ffffff0] the associated symbol table. section header index of
5778 SHT_SUNW_capchain table,
5781 SHT_SUNW_symsort The section header index of 0
5782 [0x6ffffff1] the associated symbol table.
5784 SHT_SUNW_tlssort The section header index of 0
5785 [0x6ffffff2] the associated symbol table.
5787 SHT_SUNW_LDYNSYM The section header index of One greater than the
5788 [0x6ffffff3] the associated string table. symbol table index of the
5789 This index is the same string last local symbol,
5790 table used by the SHT_DYNSYM STB_LOCAL. Since
5791 section. SHT_SUNW_LDYNSYM only
5792 contains local symbols,
5793 sh_info is equivalent to
5794 the number of symbols in
5797 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
5798 [0x6ffffff5] the section header index of to named strings, the
5799 the associated section header index of
5800 SHT_SUNW_capinfo table, the associated string
5801 otherwise 0. table, otherwise 0.
5803 SHT_SUNW_move The section header index of 0
5804 [0x6ffffffa] the associated symbol table.
5809 SHT_SUNW_syminfo The section header index of The section header index
5810 [0x6ffffffc] the associated symbol table. of the associated
5813 SHT_SUNW_verdef The section header index of The number of version
5814 [0x6ffffffd] the associated string table. definitions within the
5817 SHT_SUNW_verneed The section header index of The number of version
5818 [0x6ffffffe] the associated string table. dependencies within the
5821 SHT_SUNW_versym The section header index of 0
5822 [0x6fffffff] the associated symbol table. */
5825 #undef elf_backend_copy_special_section_fields
5826 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
5828 #include "elf32-target.h"
5830 /* Intel MCU support. */
5833 elf32_iamcu_elf_object_p (bfd
*abfd
)
5835 /* Set the right machine number for an IAMCU elf32 file. */
5836 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
5840 #undef TARGET_LITTLE_SYM
5841 #define TARGET_LITTLE_SYM iamcu_elf32_vec
5842 #undef TARGET_LITTLE_NAME
5843 #define TARGET_LITTLE_NAME "elf32-iamcu"
5845 #define ELF_ARCH bfd_arch_iamcu
5847 #undef ELF_MACHINE_CODE
5848 #define ELF_MACHINE_CODE EM_IAMCU
5853 #define elf32_bed elf32_iamcu_bed
5855 #undef elf_backend_object_p
5856 #define elf_backend_object_p elf32_iamcu_elf_object_p
5858 #undef elf_backend_static_tls_alignment
5860 #undef elf_backend_want_plt_sym
5861 #define elf_backend_want_plt_sym 0
5863 #undef elf_backend_strtab_flags
5864 #undef elf_backend_copy_special_section_fields
5866 #include "elf32-target.h"
5868 /* Restore defaults. */
5870 #define ELF_ARCH bfd_arch_i386
5871 #undef ELF_MACHINE_CODE
5872 #define ELF_MACHINE_CODE EM_386
5874 /* Native Client support. */
5876 #undef TARGET_LITTLE_SYM
5877 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
5878 #undef TARGET_LITTLE_NAME
5879 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
5881 #define elf32_bed elf32_i386_nacl_bed
5883 #undef ELF_MAXPAGESIZE
5884 #define ELF_MAXPAGESIZE 0x10000
5886 /* Restore defaults. */
5888 #undef elf_backend_want_plt_sym
5889 #define elf_backend_want_plt_sym 0
5890 #undef elf_backend_post_process_headers
5891 #undef elf_backend_static_tls_alignment
5893 /* NaCl uses substantially different PLT entries for the same effects. */
5895 #undef elf_backend_plt_alignment
5896 #define elf_backend_plt_alignment 5
5897 #define NACL_PLT_ENTRY_SIZE 64
5898 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5900 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
5902 0xff, 0x35, /* pushl contents of address */
5903 0, 0, 0, 0, /* replaced with address of .got + 4. */
5904 0x8b, 0x0d, /* movl contents of address, %ecx */
5905 0, 0, 0, 0, /* replaced with address of .got + 8. */
5906 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5907 0xff, 0xe1 /* jmp *%ecx */
5910 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5912 0x8b, 0x0d, /* movl contents of address, %ecx */
5913 0, 0, 0, 0, /* replaced with GOT slot address. */
5914 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5915 0xff, 0xe1, /* jmp *%ecx */
5917 /* Pad to the next 32-byte boundary with nop instructions. */
5919 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5920 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5922 /* Lazy GOT entries point here (32-byte aligned). */
5923 0x68, /* pushl immediate */
5924 0, 0, 0, 0, /* replaced with reloc offset. */
5925 0xe9, /* jmp relative */
5926 0, 0, 0, 0, /* replaced with offset to .plt. */
5928 /* Pad to the next 32-byte boundary with nop instructions. */
5929 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5930 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5934 static const bfd_byte
5935 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
5937 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5938 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5939 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5940 0xff, 0xe1, /* jmp *%ecx */
5942 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
5943 so pad to that size with nop instructions. */
5944 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
5947 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5949 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5950 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5951 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5952 0xff, 0xe1, /* jmp *%ecx */
5954 /* Pad to the next 32-byte boundary with nop instructions. */
5956 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5957 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5959 /* Lazy GOT entries point here (32-byte aligned). */
5960 0x68, /* pushl immediate */
5961 0, 0, 0, 0, /* replaced with offset into relocation table. */
5962 0xe9, /* jmp relative */
5963 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5965 /* Pad to the next 32-byte boundary with nop instructions. */
5966 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5967 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5971 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
5973 #if (PLT_CIE_LENGTH != 20 \
5974 || PLT_FDE_LENGTH != 36 \
5975 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5976 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5977 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5979 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5980 0, 0, 0, 0, /* CIE ID */
5981 1, /* CIE version */
5982 'z', 'R', 0, /* Augmentation string */
5983 1, /* Code alignment factor */
5984 0x7c, /* Data alignment factor: -4 */
5985 8, /* Return address column */
5986 1, /* Augmentation size */
5987 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5988 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5989 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5990 DW_CFA_nop
, DW_CFA_nop
,
5992 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5993 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
5994 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5995 0, 0, 0, 0, /* .plt size goes here */
5996 0, /* Augmentation size */
5997 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
5998 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5999 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
6000 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
6001 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
6002 13, /* Block length */
6003 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
6004 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
6005 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
6006 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
6007 DW_CFA_nop
, DW_CFA_nop
6010 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
=
6012 elf_i386_nacl_plt0_entry
, /* plt0_entry */
6013 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
6014 elf_i386_nacl_plt_entry
, /* plt_entry */
6015 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
6016 2, /* plt0_got1_offset */
6017 8, /* plt0_got2_offset */
6018 0, /* plt0_got2_insn_end */
6019 2, /* plt_got_offset */
6020 33, /* plt_reloc_offset */
6021 38, /* plt_plt_offset */
6022 0, /* plt_got_insn_size */
6023 0, /* plt_plt_insn_end */
6024 32, /* plt_lazy_offset */
6025 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
6026 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
6027 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
6028 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
6031 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
6033 0x90, /* plt0_pad_byte: nop insn */
6038 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
6040 /* Set the right machine number for a NaCl i386 ELF32 file. */
6041 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
6045 #undef elf_backend_arch_data
6046 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
6048 #undef elf_backend_object_p
6049 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
6050 #undef elf_backend_modify_segment_map
6051 #define elf_backend_modify_segment_map nacl_modify_segment_map
6052 #undef elf_backend_modify_program_headers
6053 #define elf_backend_modify_program_headers nacl_modify_program_headers
6054 #undef elf_backend_final_write_processing
6055 #define elf_backend_final_write_processing nacl_final_write_processing
6057 #include "elf32-target.h"
6059 /* Restore defaults. */
6060 #undef elf_backend_object_p
6061 #undef elf_backend_modify_segment_map
6062 #undef elf_backend_modify_program_headers
6063 #undef elf_backend_final_write_processing
6065 /* VxWorks support. */
6067 #undef TARGET_LITTLE_SYM
6068 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
6069 #undef TARGET_LITTLE_NAME
6070 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
6072 #undef ELF_MAXPAGESIZE
6073 #define ELF_MAXPAGESIZE 0x1000
6074 #undef elf_backend_plt_alignment
6075 #define elf_backend_plt_alignment 4
6077 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
6079 0x90, /* plt0_pad_byte */
6083 #undef elf_backend_arch_data
6084 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
6086 #undef elf_backend_relocs_compatible
6087 #undef elf_backend_add_symbol_hook
6088 #define elf_backend_add_symbol_hook \
6089 elf_vxworks_add_symbol_hook
6090 #undef elf_backend_link_output_symbol_hook
6091 #define elf_backend_link_output_symbol_hook \
6092 elf_vxworks_link_output_symbol_hook
6093 #undef elf_backend_emit_relocs
6094 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
6095 #undef elf_backend_final_write_processing
6096 #define elf_backend_final_write_processing \
6097 elf_vxworks_final_write_processing
6098 #undef elf_backend_static_tls_alignment
6100 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
6102 #undef elf_backend_want_plt_sym
6103 #define elf_backend_want_plt_sym 1
6106 #define elf32_bed elf32_i386_vxworks_bed
6108 #include "elf32-target.h"