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 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
660 0, 0, 0, 0, /* CIE ID */
662 'z', 'R', 0, /* Augmentation string */
663 1, /* Code alignment factor */
664 0x7c, /* Data alignment factor */
665 8, /* Return address column */
666 1, /* Augmentation size */
667 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
668 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
669 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
670 DW_CFA_nop
, DW_CFA_nop
,
672 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
673 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
674 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
675 0, 0, 0, 0, /* .plt size goes here */
676 0, /* Augmentation size */
677 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
678 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
679 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
680 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
681 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
682 11, /* Block length */
683 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
684 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
685 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
686 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
687 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
690 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
692 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt
[] =
694 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
695 0, 0, 0, 0, /* CIE ID */
697 'z', 'R', 0, /* Augmentation string */
698 1, /* Code alignment factor */
699 0x7c, /* Data alignment factor */
700 8, /* Return address column */
701 1, /* Augmentation size */
702 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
703 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
704 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
705 DW_CFA_nop
, DW_CFA_nop
,
707 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
708 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
709 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
710 0, 0, 0, 0, /* .plt size goes here */
711 0, /* Augmentation size */
712 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
713 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
714 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
715 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
716 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
717 11, /* Block length */
718 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
719 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
720 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
721 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
722 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
725 /* .eh_frame covering the non-lazy .plt section. */
727 static const bfd_byte elf_i386_eh_frame_non_lazy_plt
[] =
729 #define PLT_GOT_FDE_LENGTH 16
730 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
731 0, 0, 0, 0, /* CIE ID */
733 'z', 'R', 0, /* Augmentation string */
734 1, /* Code alignment factor */
735 0x7c, /* Data alignment factor */
736 8, /* Return address column */
737 1, /* Augmentation size */
738 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
739 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
740 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
741 DW_CFA_nop
, DW_CFA_nop
,
743 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
744 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
745 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
746 0, 0, 0, 0, /* non-lazy .plt size goes here */
747 0, /* Augmentation size */
748 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
751 /* These are the standard parameters. */
752 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt
=
754 elf_i386_lazy_plt0_entry
, /* plt0_entry */
755 sizeof (elf_i386_lazy_plt0_entry
), /* plt0_entry_size */
756 elf_i386_lazy_plt_entry
, /* plt_entry */
757 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
758 2, /* plt0_got1_offset */
759 8, /* plt0_got2_offset */
760 0, /* plt0_got2_insn_end */
761 2, /* plt_got_offset */
762 7, /* plt_reloc_offset */
763 12, /* plt_plt_offset */
764 0, /* plt_got_insn_size */
765 0, /* plt_plt_insn_end */
766 6, /* plt_lazy_offset */
767 elf_i386_pic_lazy_plt0_entry
, /* pic_plt0_entry */
768 elf_i386_pic_lazy_plt_entry
, /* pic_plt_entry */
769 elf_i386_eh_frame_lazy_plt
, /* eh_frame_plt */
770 sizeof (elf_i386_eh_frame_lazy_plt
) /* eh_frame_plt_size */
773 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt
=
775 elf_i386_non_lazy_plt_entry
, /* plt_entry */
776 elf_i386_pic_non_lazy_plt_entry
, /* pic_plt_entry */
777 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
778 2, /* plt_got_offset */
779 0, /* plt_got_insn_size */
780 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
781 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
784 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt
=
786 elf_i386_lazy_ibt_plt0_entry
, /* plt0_entry */
787 sizeof (elf_i386_lazy_ibt_plt0_entry
), /* plt0_entry_size */
788 elf_i386_lazy_ibt_plt_entry
, /* plt_entry */
789 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
790 2, /* plt0_got1_offset */
791 8, /* plt0_got2_offset */
792 0, /* plt0_got2_insn_end */
793 4+2, /* plt_got_offset */
794 4+1, /* plt_reloc_offset */
795 4+6, /* plt_plt_offset */
796 0, /* plt_got_insn_size */
797 0, /* plt_plt_insn_end */
798 0, /* plt_lazy_offset */
799 elf_i386_pic_lazy_ibt_plt0_entry
, /* pic_plt0_entry */
800 elf_i386_lazy_ibt_plt_entry
, /* pic_plt_entry */
801 elf_i386_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
802 sizeof (elf_i386_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
805 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt
=
807 elf_i386_non_lazy_ibt_plt_entry
, /* plt_entry */
808 elf_i386_pic_non_lazy_ibt_plt_entry
,/* pic_plt_entry */
809 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
810 4+2, /* plt_got_offset */
811 0, /* plt_got_insn_size */
812 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
813 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
817 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
818 for the PLTResolve stub and then for each PLT entry. */
819 #define PLTRESOLVE_RELOCS_SHLIB 0
820 #define PLTRESOLVE_RELOCS 2
821 #define PLT_NON_JUMP_SLOT_RELOCS 2
823 /* Architecture-specific backend data for i386. */
825 struct elf_i386_backend_data
827 /* Value used to fill the unused bytes of the first PLT entry. */
828 bfd_byte plt0_pad_byte
;
839 #define get_elf_i386_backend_data(abfd) \
840 ((const struct elf_i386_backend_data *) \
841 get_elf_backend_data (abfd)->arch_data)
843 /* These are the standard parameters. */
844 static const struct elf_i386_backend_data elf_i386_arch_bed
=
846 0, /* plt0_pad_byte */
850 #define elf_backend_arch_data &elf_i386_arch_bed
852 /* Return TRUE if the TLS access code sequence support transition
856 elf_i386_check_tls_transition (asection
*sec
,
858 Elf_Internal_Shdr
*symtab_hdr
,
859 struct elf_link_hash_entry
**sym_hashes
,
861 const Elf_Internal_Rela
*rel
,
862 const Elf_Internal_Rela
*relend
)
864 unsigned int val
, type
, reg
;
865 unsigned long r_symndx
;
866 struct elf_link_hash_entry
*h
;
869 bfd_boolean indirect_call
;
871 offset
= rel
->r_offset
;
876 if (offset
< 2 || (rel
+ 1) >= relend
)
879 indirect_call
= FALSE
;
880 call
= contents
+ offset
+ 4;
883 if (r_type
== R_386_TLS_GD
)
885 /* Check transition from GD access model. Only
886 leal foo@tlsgd(,%ebx,1), %eax
887 call ___tls_get_addr@PLT
889 leal foo@tlsgd(%ebx) %eax
890 call ___tls_get_addr@PLT
893 leal foo@tlsgd(%reg), %eax
894 call *___tls_get_addr@GOT(%reg)
895 which may be converted to
896 addr32 call ___tls_get_addr
897 can transit to different access model. */
898 if ((offset
+ 10) > sec
->size
899 || (type
!= 0x8d && type
!= 0x04))
904 /* leal foo@tlsgd(,%ebx,1), %eax
905 call ___tls_get_addr@PLT */
909 if (*(call
- 7) != 0x8d
917 leal foo@tlsgd(%ebx), %eax
918 call ___tls_get_addr@PLT
921 leal foo@tlsgd(%reg), %eax
922 call *___tls_get_addr@GOT(%reg)
923 which may be converted to
924 addr32 call ___tls_get_addr
926 %eax can't be used as the GOT base register since it
927 is used to pass parameter to ___tls_get_addr. */
929 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
932 indirect_call
= call
[0] == 0xff;
933 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
934 && !(call
[0] == 0x67 && call
[1] == 0xe8)
936 && (call
[1] & 0xf8) == 0x90
937 && (call
[1] & 0x7) == reg
))
943 /* Check transition from LD access model. Only
944 leal foo@tlsldm(%ebx), %eax
945 call ___tls_get_addr@PLT
947 leal foo@tlsldm(%reg), %eax
948 call *___tls_get_addr@GOT(%reg)
949 which may be converted to
950 addr32 call ___tls_get_addr
951 can transit to different access model. */
952 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
955 /* %eax can't be used as the GOT base register since it is
956 used to pass parameter to ___tls_get_addr. */
958 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
961 indirect_call
= call
[0] == 0xff;
962 if (!(reg
== 3 && call
[0] == 0xe8)
963 && !(call
[0] == 0x67 && call
[1] == 0xe8)
965 && (call
[1] & 0xf8) == 0x90
966 && (call
[1] & 0x7) == reg
))
970 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
971 if (r_symndx
< symtab_hdr
->sh_info
)
974 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
976 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
978 else if (indirect_call
)
979 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
981 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
982 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
985 /* Check transition from IE access model:
986 movl foo@indntpoff(%rip), %eax
987 movl foo@indntpoff(%rip), %reg
988 addl foo@indntpoff(%rip), %reg
991 if (offset
< 1 || (offset
+ 4) > sec
->size
)
994 /* Check "movl foo@tpoff(%rip), %eax" first. */
995 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1002 /* Check movl|addl foo@tpoff(%rip), %reg. */
1003 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1004 return ((type
== 0x8b || type
== 0x03)
1005 && (val
& 0xc7) == 0x05);
1007 case R_386_TLS_GOTIE
:
1008 case R_386_TLS_IE_32
:
1009 /* Check transition from {IE_32,GOTIE} access model:
1010 subl foo@{tpoff,gontoff}(%reg1), %reg2
1011 movl foo@{tpoff,gontoff}(%reg1), %reg2
1012 addl foo@{tpoff,gontoff}(%reg1), %reg2
1015 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1018 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1019 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1022 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1023 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1025 case R_386_TLS_GOTDESC
:
1026 /* Check transition from GDesc access model:
1027 leal x@tlsdesc(%ebx), %eax
1029 Make sure it's a leal adding ebx to a 32-bit offset
1030 into any register, although it's probably almost always
1033 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1036 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1039 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1040 return (val
& 0xc7) == 0x83;
1042 case R_386_TLS_DESC_CALL
:
1043 /* Check transition from GDesc access model:
1044 call *x@tlsdesc(%eax)
1046 if (offset
+ 2 <= sec
->size
)
1048 /* Make sure that it's a call *x@tlsdesc(%eax). */
1049 call
= contents
+ offset
;
1050 return call
[0] == 0xff && call
[1] == 0x10;
1060 /* Return TRUE if the TLS access transition is OK or no transition
1061 will be performed. Update R_TYPE if there is a transition. */
1064 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1065 asection
*sec
, bfd_byte
*contents
,
1066 Elf_Internal_Shdr
*symtab_hdr
,
1067 struct elf_link_hash_entry
**sym_hashes
,
1068 unsigned int *r_type
, int tls_type
,
1069 const Elf_Internal_Rela
*rel
,
1070 const Elf_Internal_Rela
*relend
,
1071 struct elf_link_hash_entry
*h
,
1072 unsigned long r_symndx
,
1073 bfd_boolean from_relocate_section
)
1075 unsigned int from_type
= *r_type
;
1076 unsigned int to_type
= from_type
;
1077 bfd_boolean check
= TRUE
;
1079 /* Skip TLS transition for functions. */
1081 && (h
->type
== STT_FUNC
1082 || h
->type
== STT_GNU_IFUNC
))
1088 case R_386_TLS_GOTDESC
:
1089 case R_386_TLS_DESC_CALL
:
1090 case R_386_TLS_IE_32
:
1092 case R_386_TLS_GOTIE
:
1093 if (bfd_link_executable (info
))
1096 to_type
= R_386_TLS_LE_32
;
1097 else if (from_type
!= R_386_TLS_IE
1098 && from_type
!= R_386_TLS_GOTIE
)
1099 to_type
= R_386_TLS_IE_32
;
1102 /* When we are called from elf_i386_relocate_section, there may
1103 be additional transitions based on TLS_TYPE. */
1104 if (from_relocate_section
)
1106 unsigned int new_to_type
= to_type
;
1108 if (bfd_link_executable (info
)
1111 && (tls_type
& GOT_TLS_IE
))
1112 new_to_type
= R_386_TLS_LE_32
;
1114 if (to_type
== R_386_TLS_GD
1115 || to_type
== R_386_TLS_GOTDESC
1116 || to_type
== R_386_TLS_DESC_CALL
)
1118 if (tls_type
== GOT_TLS_IE_POS
)
1119 new_to_type
= R_386_TLS_GOTIE
;
1120 else if (tls_type
& GOT_TLS_IE
)
1121 new_to_type
= R_386_TLS_IE_32
;
1124 /* We checked the transition before when we were called from
1125 elf_i386_check_relocs. We only want to check the new
1126 transition which hasn't been checked before. */
1127 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1128 to_type
= new_to_type
;
1134 if (bfd_link_executable (info
))
1135 to_type
= R_386_TLS_LE_32
;
1142 /* Return TRUE if there is no transition. */
1143 if (from_type
== to_type
)
1146 /* Check if the transition can be performed. */
1148 && ! elf_i386_check_tls_transition (sec
, contents
,
1149 symtab_hdr
, sym_hashes
,
1150 from_type
, rel
, relend
))
1152 reloc_howto_type
*from
, *to
;
1155 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1156 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1159 name
= h
->root
.root
.string
;
1162 struct elf_x86_link_hash_table
*htab
;
1164 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1169 Elf_Internal_Sym
*isym
;
1171 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1173 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1178 /* xgettext:c-format */
1179 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1180 "in section `%A' failed"),
1181 abfd
, from
->name
, to
->name
, name
,
1182 rel
->r_offset
, sec
);
1183 bfd_set_error (bfd_error_bad_value
);
1191 /* With the local symbol, foo, we convert
1192 mov foo@GOT[(%reg1)], %reg2
1194 lea foo[@GOTOFF(%reg1)], %reg2
1196 call/jmp *foo@GOT[(%reg)]
1198 nop call foo/jmp foo nop
1199 When PIC is false, convert
1200 test %reg1, foo@GOT[(%reg2)]
1204 binop foo@GOT[(%reg1)], %reg2
1207 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1212 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1214 unsigned int *r_type_p
,
1215 Elf_Internal_Rela
*irel
,
1216 struct elf_link_hash_entry
*h
,
1217 bfd_boolean
*converted
,
1218 struct bfd_link_info
*link_info
)
1220 struct elf_x86_link_hash_table
*htab
;
1221 unsigned int opcode
;
1223 bfd_boolean baseless
;
1224 Elf_Internal_Sym
*isym
;
1225 unsigned int addend
;
1229 bfd_boolean to_reloc_32
;
1230 unsigned int r_type
;
1231 unsigned int r_symndx
;
1232 bfd_vma roff
= irel
->r_offset
;
1233 bfd_boolean local_ref
;
1234 struct elf_x86_link_hash_entry
*eh
;
1239 /* Addend for R_386_GOT32X relocations must be 0. */
1240 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1244 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
1245 is_pic
= bfd_link_pic (link_info
);
1248 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1250 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1251 baseless
= (modrm
& 0xc7) == 0x5;
1253 if (baseless
&& is_pic
)
1255 /* For PIC, disallow R_386_GOT32X without a base register
1256 since we don't know what the GOT base is. */
1261 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1263 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1266 name
= h
->root
.root
.string
;
1269 /* xgettext:c-format */
1270 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1271 " register can not be used when making a shared object"),
1276 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1278 /* Convert to R_386_32 if PIC is false or there is no base
1280 to_reloc_32
= !is_pic
|| baseless
;
1282 eh
= elf_x86_hash_entry (h
);
1284 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1288 if (opcode
== 0x0ff)
1289 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1290 goto convert_branch
;
1292 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1293 "test %reg1, foo@GOT(%reg2)" and
1294 "binop foo@GOT[(%reg1)], %reg2". */
1298 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1299 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1301 /* Undefined weak symbol is only bound locally in executable
1302 and its reference is resolved as 0. */
1303 if (h
->root
.type
== bfd_link_hash_undefweak
1309 /* No direct branch to 0 for PIC. */
1313 goto convert_branch
;
1317 /* We can convert load of address 0 to R_386_32. */
1325 /* We have "call/jmp *foo@GOT[(%reg)]". */
1326 if ((h
->root
.type
== bfd_link_hash_defined
1327 || h
->root
.type
== bfd_link_hash_defweak
)
1330 /* The function is locally defined. */
1332 /* Convert R_386_GOT32X to R_386_PC32. */
1333 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1335 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1338 /* To support TLS optimization, always use addr32 prefix
1339 for "call *___tls_get_addr@GOT(%reg)". */
1340 if (eh
&& eh
->tls_get_addr
)
1343 nop_offset
= irel
->r_offset
- 2;
1347 nop
= link_info
->call_nop_byte
;
1348 if (link_info
->call_nop_as_suffix
)
1350 nop_offset
= roff
+ 3;
1351 irel
->r_offset
-= 1;
1354 nop_offset
= roff
- 2;
1359 /* Convert to "jmp foo nop". */
1362 nop_offset
= roff
+ 3;
1363 irel
->r_offset
-= 1;
1366 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1367 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1368 /* When converting to PC-relative relocation, we
1369 need to adjust addend by -4. */
1370 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1371 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1372 *r_type_p
= R_386_PC32
;
1378 /* We have "mov foo@GOT[(%re1g)], %reg2",
1379 "test %reg1, foo@GOT(%reg2)" and
1380 "binop foo@GOT[(%reg1)], %reg2".
1382 Avoid optimizing _DYNAMIC since ld.so may use its
1383 link-time address. */
1384 if (h
== htab
->elf
.hdynamic
)
1387 /* def_regular is set by an assignment in a linker script in
1388 bfd_elf_record_link_assignment. start_stop is set on
1389 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1393 || h
->root
.type
== bfd_link_hash_defined
1394 || h
->root
.type
== bfd_link_hash_defweak
)
1402 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1403 "mov $foo, %reg2" with R_386_32. */
1405 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1406 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1411 /* Convert "mov foo@GOT(%reg1), %reg2" to
1412 "lea foo@GOTOFF(%reg1), %reg2". */
1413 r_type
= R_386_GOTOFF
;
1419 /* Only R_386_32 is supported. */
1425 /* Convert "test %reg1, foo@GOT(%reg2)" to
1426 "test $foo, %reg1". */
1427 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1432 /* Convert "binop foo@GOT(%reg1), %reg2" to
1433 "binop $foo, %reg2". */
1435 | (modrm
& 0x38) >> 3
1439 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1443 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1444 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1453 /* Rename some of the generic section flags to better document how they
1455 #define check_relocs_failed sec_flg0
1457 /* Look through the relocs for a section during the first phase, and
1458 calculate needed space in the global offset table, procedure linkage
1459 table, and dynamic reloc sections. */
1462 elf_i386_check_relocs (bfd
*abfd
,
1463 struct bfd_link_info
*info
,
1465 const Elf_Internal_Rela
*relocs
)
1467 struct elf_x86_link_hash_table
*htab
;
1468 Elf_Internal_Shdr
*symtab_hdr
;
1469 struct elf_link_hash_entry
**sym_hashes
;
1470 const Elf_Internal_Rela
*rel
;
1471 const Elf_Internal_Rela
*rel_end
;
1474 bfd_boolean converted
;
1476 if (bfd_link_relocatable (info
))
1479 /* Don't do anything special with non-loaded, non-alloced sections.
1480 In particular, any relocs in such sections should not affect GOT
1481 and PLT reference counting (ie. we don't allow them to create GOT
1482 or PLT entries), there's no possibility or desire to optimize TLS
1483 relocs, and there's not much point in propagating relocs to shared
1484 libs that the dynamic linker won't relocate. */
1485 if ((sec
->flags
& SEC_ALLOC
) == 0)
1488 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1491 sec
->check_relocs_failed
= 1;
1495 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1497 /* Get the section contents. */
1498 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1499 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1500 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1502 sec
->check_relocs_failed
= 1;
1506 symtab_hdr
= &elf_symtab_hdr (abfd
);
1507 sym_hashes
= elf_sym_hashes (abfd
);
1513 rel_end
= relocs
+ sec
->reloc_count
;
1514 for (rel
= relocs
; rel
< rel_end
; rel
++)
1516 unsigned int r_type
;
1517 unsigned int r_symndx
;
1518 struct elf_link_hash_entry
*h
;
1519 struct elf_x86_link_hash_entry
*eh
;
1520 Elf_Internal_Sym
*isym
;
1522 bfd_boolean size_reloc
;
1524 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1525 r_type
= ELF32_R_TYPE (rel
->r_info
);
1527 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1529 /* xgettext:c-format */
1530 _bfd_error_handler (_("%B: bad symbol index: %d"),
1535 if (r_symndx
< symtab_hdr
->sh_info
)
1537 /* A local symbol. */
1538 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1543 /* Check relocation against local STT_GNU_IFUNC symbol. */
1544 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1546 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1550 /* Fake a STT_GNU_IFUNC symbol. */
1551 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1553 h
->type
= STT_GNU_IFUNC
;
1556 h
->forced_local
= 1;
1557 h
->root
.type
= bfd_link_hash_defined
;
1565 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1566 while (h
->root
.type
== bfd_link_hash_indirect
1567 || h
->root
.type
== bfd_link_hash_warning
)
1568 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1571 eh
= (struct elf_x86_link_hash_entry
*) h
;
1574 if (r_type
== R_386_GOTOFF
)
1577 /* It is referenced by a non-shared object. */
1579 h
->root
.non_ir_ref_regular
= 1;
1581 if (h
->type
== STT_GNU_IFUNC
)
1582 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1583 |= elf_gnu_symbol_ifunc
;
1586 if (r_type
== R_386_GOT32X
1587 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1589 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
1590 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
1596 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1597 symtab_hdr
, sym_hashes
,
1598 &r_type
, GOT_UNKNOWN
,
1599 rel
, rel_end
, h
, r_symndx
, FALSE
))
1605 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1609 /* This symbol requires a procedure linkage table entry. We
1610 actually build the entry in adjust_dynamic_symbol,
1611 because this might be a case of linking PIC code which is
1612 never referenced by a dynamic object, in which case we
1613 don't need to generate a procedure linkage table entry
1616 /* If this is a local symbol, we resolve it directly without
1617 creating a procedure linkage table entry. */
1621 eh
->has_got_reloc
= 1;
1623 h
->plt
.refcount
+= 1;
1630 case R_386_TLS_IE_32
:
1632 case R_386_TLS_GOTIE
:
1633 if (!bfd_link_executable (info
))
1634 info
->flags
|= DF_STATIC_TLS
;
1640 case R_386_TLS_GOTDESC
:
1641 case R_386_TLS_DESC_CALL
:
1642 /* This symbol requires a global offset table entry. */
1644 int tls_type
, old_tls_type
;
1651 tls_type
= GOT_NORMAL
;
1653 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1654 case R_386_TLS_GOTDESC
:
1655 case R_386_TLS_DESC_CALL
:
1656 tls_type
= GOT_TLS_GDESC
; break;
1657 case R_386_TLS_IE_32
:
1658 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1659 tls_type
= GOT_TLS_IE_NEG
;
1661 /* If this is a GD->IE transition, we may use either of
1662 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1663 tls_type
= GOT_TLS_IE
;
1666 case R_386_TLS_GOTIE
:
1667 tls_type
= GOT_TLS_IE_POS
; break;
1672 h
->got
.refcount
+= 1;
1673 old_tls_type
= elf_x86_hash_entry (h
)->tls_type
;
1677 bfd_signed_vma
*local_got_refcounts
;
1679 /* This is a global offset table entry for a local symbol. */
1680 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1681 if (local_got_refcounts
== NULL
)
1685 size
= symtab_hdr
->sh_info
;
1686 size
*= (sizeof (bfd_signed_vma
)
1687 + sizeof (bfd_vma
) + sizeof(char));
1688 local_got_refcounts
= (bfd_signed_vma
*)
1689 bfd_zalloc (abfd
, size
);
1690 if (local_got_refcounts
== NULL
)
1692 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1693 elf_x86_local_tlsdesc_gotent (abfd
)
1694 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1695 elf_x86_local_got_tls_type (abfd
)
1696 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1698 local_got_refcounts
[r_symndx
] += 1;
1699 old_tls_type
= elf_x86_local_got_tls_type (abfd
) [r_symndx
];
1702 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1703 tls_type
|= old_tls_type
;
1704 /* If a TLS symbol is accessed using IE at least once,
1705 there is no point to use dynamic model for it. */
1706 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1707 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1708 || (tls_type
& GOT_TLS_IE
) == 0))
1710 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1711 tls_type
= old_tls_type
;
1712 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1713 && GOT_TLS_GD_ANY_P (tls_type
))
1714 tls_type
|= old_tls_type
;
1718 name
= h
->root
.root
.string
;
1720 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1723 /* xgettext:c-format */
1724 (_("%B: `%s' accessed both as normal and "
1725 "thread local symbol"),
1727 bfd_set_error (bfd_error_bad_value
);
1732 if (old_tls_type
!= tls_type
)
1735 elf_x86_hash_entry (h
)->tls_type
= tls_type
;
1737 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1745 if (r_type
!= R_386_TLS_IE
)
1748 eh
->has_got_reloc
= 1;
1753 case R_386_TLS_LE_32
:
1756 eh
->has_got_reloc
= 1;
1757 if (bfd_link_executable (info
))
1759 info
->flags
|= DF_STATIC_TLS
;
1764 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
1765 eh
->has_non_got_reloc
= 1;
1767 /* We are called after all symbols have been resolved. Only
1768 relocation against STT_GNU_IFUNC symbol must go through
1771 && (bfd_link_executable (info
)
1772 || h
->type
== STT_GNU_IFUNC
))
1774 /* If this reloc is in a read-only section, we might
1775 need a copy reloc. We can't check reliably at this
1776 stage whether the section is read-only, as input
1777 sections have not yet been mapped to output sections.
1778 Tentatively set the flag for now, and correct in
1779 adjust_dynamic_symbol. */
1782 /* We may need a .plt entry if the symbol is a function
1783 defined in a shared lib or is a STT_GNU_IFUNC function
1784 referenced from the code or read-only section. */
1786 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
1787 h
->plt
.refcount
+= 1;
1789 if (r_type
== R_386_PC32
)
1791 /* Since something like ".long foo - ." may be used
1792 as pointer, make sure that PLT is used if foo is
1793 a function defined in a shared library. */
1794 if ((sec
->flags
& SEC_CODE
) == 0)
1795 h
->pointer_equality_needed
= 1;
1796 else if (h
->type
== STT_GNU_IFUNC
1797 && bfd_link_pic (info
))
1800 /* xgettext:c-format */
1801 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
1802 abfd
, h
->root
.root
.string
);
1803 bfd_set_error (bfd_error_bad_value
);
1809 h
->pointer_equality_needed
= 1;
1810 /* R_386_32 can be resolved at run-time. */
1811 if (r_type
== R_386_32
1812 && (sec
->flags
& SEC_READONLY
) == 0)
1813 eh
->func_pointer_refcount
+= 1;
1819 /* If we are creating a shared library, and this is a reloc
1820 against a global symbol, or a non PC relative reloc
1821 against a local symbol, then we need to copy the reloc
1822 into the shared library. However, if we are linking with
1823 -Bsymbolic, we do not need to copy a reloc against a
1824 global symbol which is defined in an object we are
1825 including in the link (i.e., DEF_REGULAR is set). At
1826 this point we have not seen all the input files, so it is
1827 possible that DEF_REGULAR is not set now but will be set
1828 later (it is never cleared). In case of a weak definition,
1829 DEF_REGULAR may be cleared later by a strong definition in
1830 a shared library. We account for that possibility below by
1831 storing information in the relocs_copied field of the hash
1832 table entry. A similar situation occurs when creating
1833 shared libraries and symbol visibility changes render the
1836 If on the other hand, we are creating an executable, we
1837 may need to keep relocations for symbols satisfied by a
1838 dynamic library if we manage to avoid copy relocs for the
1841 Generate dynamic pointer relocation against STT_GNU_IFUNC
1842 symbol in the non-code section. */
1843 if ((bfd_link_pic (info
)
1844 && (r_type
!= R_386_PC32
1846 && (! (bfd_link_pie (info
)
1847 || SYMBOLIC_BIND (info
, h
))
1848 || h
->root
.type
== bfd_link_hash_defweak
1849 || !h
->def_regular
))))
1851 && h
->type
== STT_GNU_IFUNC
1852 && r_type
== R_386_32
1853 && (sec
->flags
& SEC_CODE
) == 0)
1854 || (ELIMINATE_COPY_RELOCS
1855 && !bfd_link_pic (info
)
1857 && (h
->root
.type
== bfd_link_hash_defweak
1858 || !h
->def_regular
)))
1860 struct elf_dyn_relocs
*p
;
1861 struct elf_dyn_relocs
**head
;
1863 /* We must copy these reloc types into the output file.
1864 Create a reloc section in dynobj and make room for
1868 sreloc
= _bfd_elf_make_dynamic_reloc_section
1869 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1875 /* If this is a global symbol, we count the number of
1876 relocations we need for this symbol. */
1879 head
= &eh
->dyn_relocs
;
1883 /* Track dynamic relocs needed for local syms too.
1884 We really need local syms available to do this
1889 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1894 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1898 vpp
= &elf_section_data (s
)->local_dynrel
;
1899 head
= (struct elf_dyn_relocs
**)vpp
;
1903 if (p
== NULL
|| p
->sec
!= sec
)
1905 bfd_size_type amt
= sizeof *p
;
1906 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1918 /* Count size relocation as PC-relative relocation. */
1919 if (r_type
== R_386_PC32
|| size_reloc
)
1924 /* This relocation describes the C++ object vtable hierarchy.
1925 Reconstruct it for later use during GC. */
1926 case R_386_GNU_VTINHERIT
:
1927 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1931 /* This relocation describes which C++ vtable entries are actually
1932 used. Record for later use during GC. */
1933 case R_386_GNU_VTENTRY
:
1934 BFD_ASSERT (h
!= NULL
);
1936 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1945 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1947 if (!converted
&& !info
->keep_memory
)
1951 /* Cache the section contents for elf_link_input_bfd if any
1952 load is converted or --no-keep-memory isn't used. */
1953 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1957 /* Cache relocations if any load is converted. */
1958 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
1959 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
1964 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1966 sec
->check_relocs_failed
= 1;
1970 /* Set the correct type for an x86 ELF section. We do this by the
1971 section name, which is a hack, but ought to work. */
1974 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1975 Elf_Internal_Shdr
*hdr
,
1980 name
= bfd_get_section_name (abfd
, sec
);
1982 /* This is an ugly, but unfortunately necessary hack that is
1983 needed when producing EFI binaries on x86. It tells
1984 elf.c:elf_fake_sections() not to consider ".reloc" as a section
1985 containing ELF relocation info. We need this hack in order to
1986 be able to generate ELF binaries that can be translated into
1987 EFI applications (which are essentially COFF objects). Those
1988 files contain a COFF ".reloc" section inside an ELFNN object,
1989 which would normally cause BFD to segfault because it would
1990 attempt to interpret this section as containing relocation
1991 entries for section "oc". With this hack enabled, ".reloc"
1992 will be treated as a normal data section, which will avoid the
1993 segfault. However, you won't be able to create an ELFNN binary
1994 with a section named "oc" that needs relocations, but that's
1995 the kind of ugly side-effects you get when detecting section
1996 types based on their names... In practice, this limitation is
1997 unlikely to bite. */
1998 if (strcmp (name
, ".reloc") == 0)
1999 hdr
->sh_type
= SHT_PROGBITS
;
2004 /* Return the relocation value for @tpoff relocation
2005 if STT_TLS virtual address is ADDRESS. */
2008 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2010 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2011 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2012 bfd_vma static_tls_size
;
2014 /* If tls_sec is NULL, we should have signalled an error already. */
2015 if (htab
->tls_sec
== NULL
)
2018 /* Consider special static TLS alignment requirements. */
2019 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2020 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
2023 /* Relocate an i386 ELF section. */
2026 elf_i386_relocate_section (bfd
*output_bfd
,
2027 struct bfd_link_info
*info
,
2029 asection
*input_section
,
2031 Elf_Internal_Rela
*relocs
,
2032 Elf_Internal_Sym
*local_syms
,
2033 asection
**local_sections
)
2035 struct elf_x86_link_hash_table
*htab
;
2036 Elf_Internal_Shdr
*symtab_hdr
;
2037 struct elf_link_hash_entry
**sym_hashes
;
2038 bfd_vma
*local_got_offsets
;
2039 bfd_vma
*local_tlsdesc_gotents
;
2040 Elf_Internal_Rela
*rel
;
2041 Elf_Internal_Rela
*wrel
;
2042 Elf_Internal_Rela
*relend
;
2043 bfd_boolean is_vxworks_tls
;
2044 unsigned plt_entry_size
;
2046 /* Skip if check_relocs failed. */
2047 if (input_section
->check_relocs_failed
)
2050 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2054 BFD_ASSERT (is_x86_elf (input_bfd
, htab
));
2056 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2057 sym_hashes
= elf_sym_hashes (input_bfd
);
2058 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2059 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2060 /* We have to handle relocations in vxworks .tls_vars sections
2061 specially, because the dynamic loader is 'weird'. */
2062 is_vxworks_tls
= (htab
->is_vxworks
2063 && bfd_link_pic (info
)
2064 && !strcmp (input_section
->output_section
->name
,
2067 _bfd_x86_elf_set_tls_module_base (info
);
2069 plt_entry_size
= htab
->plt
.plt_entry_size
;
2071 rel
= wrel
= relocs
;
2072 relend
= relocs
+ input_section
->reloc_count
;
2073 for (; rel
< relend
; wrel
++, rel
++)
2075 unsigned int r_type
, r_type_tls
;
2076 reloc_howto_type
*howto
;
2077 unsigned long r_symndx
;
2078 struct elf_link_hash_entry
*h
;
2079 struct elf_x86_link_hash_entry
*eh
;
2080 Elf_Internal_Sym
*sym
;
2082 bfd_vma off
, offplt
, plt_offset
;
2084 bfd_boolean unresolved_reloc
;
2085 bfd_reloc_status_type r
;
2089 asection
*resolved_plt
;
2090 bfd_boolean resolved_to_zero
;
2091 bfd_boolean relative_reloc
;
2093 r_type
= ELF32_R_TYPE (rel
->r_info
);
2094 if (r_type
== R_386_GNU_VTINHERIT
2095 || r_type
== R_386_GNU_VTENTRY
)
2102 if ((indx
= r_type
) >= R_386_standard
2103 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2104 >= R_386_ext
- R_386_standard
)
2105 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2106 >= R_386_ext2
- R_386_ext
))
2107 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2109 howto
= elf_howto_table
+ indx
;
2111 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2115 unresolved_reloc
= FALSE
;
2116 if (r_symndx
< symtab_hdr
->sh_info
)
2118 sym
= local_syms
+ r_symndx
;
2119 sec
= local_sections
[r_symndx
];
2120 relocation
= (sec
->output_section
->vma
2121 + sec
->output_offset
2123 st_size
= sym
->st_size
;
2125 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2126 && ((sec
->flags
& SEC_MERGE
) != 0
2127 || (bfd_link_relocatable (info
)
2128 && sec
->output_offset
!= 0)))
2131 bfd_byte
*where
= contents
+ rel
->r_offset
;
2133 switch (howto
->size
)
2136 addend
= bfd_get_8 (input_bfd
, where
);
2137 if (howto
->pc_relative
)
2139 addend
= (addend
^ 0x80) - 0x80;
2144 addend
= bfd_get_16 (input_bfd
, where
);
2145 if (howto
->pc_relative
)
2147 addend
= (addend
^ 0x8000) - 0x8000;
2152 addend
= bfd_get_32 (input_bfd
, where
);
2153 if (howto
->pc_relative
)
2155 addend
= (addend
^ 0x80000000) - 0x80000000;
2163 if (bfd_link_relocatable (info
))
2164 addend
+= sec
->output_offset
;
2167 asection
*msec
= sec
;
2168 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2170 addend
-= relocation
;
2171 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2174 switch (howto
->size
)
2177 /* FIXME: overflow checks. */
2178 if (howto
->pc_relative
)
2180 bfd_put_8 (input_bfd
, addend
, where
);
2183 if (howto
->pc_relative
)
2185 bfd_put_16 (input_bfd
, addend
, where
);
2188 if (howto
->pc_relative
)
2190 bfd_put_32 (input_bfd
, addend
, where
);
2194 else if (!bfd_link_relocatable (info
)
2195 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2197 /* Relocate against local STT_GNU_IFUNC symbol. */
2198 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
, rel
,
2203 /* Set STT_GNU_IFUNC symbol value. */
2204 h
->root
.u
.def
.value
= sym
->st_value
;
2205 h
->root
.u
.def
.section
= sec
;
2210 bfd_boolean warned ATTRIBUTE_UNUSED
;
2211 bfd_boolean ignored ATTRIBUTE_UNUSED
;
2213 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2214 r_symndx
, symtab_hdr
, sym_hashes
,
2216 unresolved_reloc
, warned
, ignored
);
2220 if (sec
!= NULL
&& discarded_section (sec
))
2222 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2223 contents
+ rel
->r_offset
);
2224 wrel
->r_offset
= rel
->r_offset
;
2228 /* For ld -r, remove relocations in debug sections against
2229 sections defined in discarded sections. Not done for
2230 eh_frame editing code expects to be present. */
2231 if (bfd_link_relocatable (info
)
2232 && (input_section
->flags
& SEC_DEBUGGING
))
2238 if (bfd_link_relocatable (info
))
2245 eh
= (struct elf_x86_link_hash_entry
*) h
;
2247 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2248 it here if it is defined in a non-shared object. */
2250 && h
->type
== STT_GNU_IFUNC
2253 asection
*gotplt
, *base_got
;
2257 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2259 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2260 sections because such sections are not SEC_ALLOC and
2261 thus ld.so will not process them. */
2262 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2267 /* STT_GNU_IFUNC symbol must go through PLT. */
2268 if (htab
->elf
.splt
!= NULL
)
2270 if (htab
->plt_second
!= NULL
)
2272 resolved_plt
= htab
->plt_second
;
2273 plt_offset
= eh
->plt_second
.offset
;
2277 resolved_plt
= htab
->elf
.splt
;
2278 plt_offset
= h
->plt
.offset
;
2280 gotplt
= htab
->elf
.sgotplt
;
2284 resolved_plt
= htab
->elf
.iplt
;
2285 plt_offset
= h
->plt
.offset
;
2286 gotplt
= htab
->elf
.igotplt
;
2296 base_got
= htab
->elf
.sgot
;
2297 off
= h
->got
.offset
;
2299 if (base_got
== NULL
)
2302 if (off
== (bfd_vma
) -1)
2304 /* We can't use h->got.offset here to save state, or
2305 even just remember the offset, as finish_dynamic_symbol
2306 would use that as offset into .got. */
2308 if (h
->plt
.offset
== (bfd_vma
) -1)
2311 if (htab
->elf
.splt
!= NULL
)
2313 plt_index
= (h
->plt
.offset
/ plt_entry_size
2314 - htab
->plt
.has_plt0
);
2315 off
= (plt_index
+ 3) * 4;
2316 base_got
= htab
->elf
.sgotplt
;
2320 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2321 off
= plt_index
* 4;
2322 base_got
= htab
->elf
.igotplt
;
2325 if (h
->dynindx
== -1
2329 /* This references the local defitionion. We must
2330 initialize this entry in the global offset table.
2331 Since the offset must always be a multiple of 8,
2332 we use the least significant bit to record
2333 whether we have initialized it already.
2335 When doing a dynamic link, we create a .rela.got
2336 relocation entry to initialize the value. This
2337 is done in the finish_dynamic_symbol routine. */
2342 bfd_put_32 (output_bfd
, relocation
,
2343 base_got
->contents
+ off
);
2351 relocation
= (base_got
->output_section
->vma
2352 + base_got
->output_offset
+ off
2353 - gotplt
->output_section
->vma
2354 - gotplt
->output_offset
);
2356 if (rel
->r_offset
> 1
2357 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2358 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2360 if (bfd_link_pic (info
))
2361 goto disallow_got32
;
2363 /* Add the GOT base if there is no base register. */
2364 relocation
+= (gotplt
->output_section
->vma
2365 + gotplt
->output_offset
);
2367 else if (htab
->elf
.splt
== NULL
)
2369 /* Adjust for static executables. */
2370 relocation
+= gotplt
->output_offset
;
2376 if (h
->plt
.offset
== (bfd_vma
) -1)
2378 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2379 if (r_type
== R_386_32
2380 && (input_section
->flags
& SEC_CODE
) == 0)
2381 goto do_ifunc_pointer
;
2382 goto bad_ifunc_reloc
;
2385 relocation
= (resolved_plt
->output_section
->vma
2386 + resolved_plt
->output_offset
+ plt_offset
);
2392 if (h
->root
.root
.string
)
2393 name
= h
->root
.root
.string
;
2395 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2398 /* xgettext:c-format */
2399 (_("%B: relocation %s against STT_GNU_IFUNC "
2400 "symbol `%s' isn't supported"), input_bfd
,
2402 bfd_set_error (bfd_error_bad_value
);
2406 /* Generate dynamic relcoation only when there is a
2407 non-GOT reference in a shared object. */
2408 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2409 || h
->plt
.offset
== (bfd_vma
) -1)
2411 Elf_Internal_Rela outrel
;
2416 /* Need a dynamic relocation to get the real function
2418 offset
= _bfd_elf_section_offset (output_bfd
,
2422 if (offset
== (bfd_vma
) -1
2423 || offset
== (bfd_vma
) -2)
2426 outrel
.r_offset
= (input_section
->output_section
->vma
2427 + input_section
->output_offset
2430 if (h
->dynindx
== -1
2432 || bfd_link_executable (info
))
2434 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
2435 h
->root
.root
.string
,
2436 h
->root
.u
.def
.section
->owner
);
2438 /* This symbol is resolved locally. */
2439 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
2440 bfd_put_32 (output_bfd
,
2441 (h
->root
.u
.def
.value
2442 + h
->root
.u
.def
.section
->output_section
->vma
2443 + h
->root
.u
.def
.section
->output_offset
),
2447 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2449 /* Dynamic relocations are stored in
2450 1. .rel.ifunc section in PIC object.
2451 2. .rel.got section in dynamic executable.
2452 3. .rel.iplt section in static executable. */
2453 if (bfd_link_pic (info
))
2454 sreloc
= htab
->elf
.irelifunc
;
2455 else if (htab
->elf
.splt
!= NULL
)
2456 sreloc
= htab
->elf
.srelgot
;
2458 sreloc
= htab
->elf
.irelplt
;
2459 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2461 /* If this reloc is against an external symbol, we
2462 do not want to fiddle with the addend. Otherwise,
2463 we need to include the symbol value so that it
2464 becomes an addend for the dynamic reloc. For an
2465 internal symbol, we have updated addend. */
2474 relocation
-= (gotplt
->output_section
->vma
2475 + gotplt
->output_offset
);
2480 resolved_to_zero
= (eh
!= NULL
2481 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2486 /* Avoid optimizing _DYNAMIC since ld.so may use its
2487 link-time address. */
2488 if (h
== htab
->elf
.hdynamic
)
2491 if (bfd_link_pic (info
))
2493 /* It is OK to convert mov to lea and convert indirect
2494 branch to direct branch. It is OK to convert adc,
2495 add, and, cmp, or, sbb, sub, test, xor only when PIC
2497 unsigned int opcode
, addend
;
2498 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2501 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2502 if (opcode
!= 0x8b && opcode
!= 0xff)
2506 /* Resolve "mov GOT[(%reg)], %reg",
2507 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
2508 and "binop foo@GOT[(%reg)], %reg". */
2510 || (h
->plt
.offset
== (bfd_vma
) -1
2511 && h
->got
.offset
== (bfd_vma
) -1)
2512 || htab
->elf
.sgotplt
== NULL
)
2515 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
2516 + htab
->elf
.sgotplt
->output_offset
);
2518 /* It is relative to .got.plt section. */
2519 if (h
->got
.offset
!= (bfd_vma
) -1)
2520 /* Use GOT entry. Mask off the least significant bit in
2521 GOT offset which may be set by R_386_GOT32 processing
2523 relocation
= (htab
->elf
.sgot
->output_section
->vma
2524 + htab
->elf
.sgot
->output_offset
2525 + (h
->got
.offset
& ~1) - offplt
);
2527 /* Use GOTPLT entry. */
2528 relocation
= (h
->plt
.offset
/ plt_entry_size
2529 - htab
->plt
.has_plt0
+ 3) * 4;
2531 if (!bfd_link_pic (info
))
2533 /* If not PIC, add the .got.plt section address for
2534 baseless addressing. */
2536 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2537 if ((modrm
& 0xc7) == 0x5)
2538 relocation
+= offplt
;
2541 unresolved_reloc
= FALSE
;
2546 /* Relocation is to the entry for this symbol in the global
2548 if (htab
->elf
.sgot
== NULL
)
2551 relative_reloc
= FALSE
;
2556 off
= h
->got
.offset
;
2557 dyn
= htab
->elf
.dynamic_sections_created
;
2558 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2559 bfd_link_pic (info
),
2561 || (bfd_link_pic (info
)
2562 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
2563 || (ELF_ST_VISIBILITY (h
->other
)
2564 && h
->root
.type
== bfd_link_hash_undefweak
))
2566 /* This is actually a static link, or it is a
2567 -Bsymbolic link and the symbol is defined
2568 locally, or the symbol was forced to be local
2569 because of a version file. We must initialize
2570 this entry in the global offset table. Since the
2571 offset must always be a multiple of 4, we use the
2572 least significant bit to record whether we have
2573 initialized it already.
2575 When doing a dynamic link, we create a .rel.got
2576 relocation entry to initialize the value. This
2577 is done in the finish_dynamic_symbol routine. */
2582 bfd_put_32 (output_bfd
, relocation
,
2583 htab
->elf
.sgot
->contents
+ off
);
2586 if (h
->dynindx
== -1
2588 && h
->root
.type
!= bfd_link_hash_undefweak
2589 && bfd_link_pic (info
))
2591 /* PR ld/21402: If this symbol isn't dynamic
2592 in PIC, generate R_386_RELATIVE here. */
2593 eh
->no_finish_dynamic_symbol
= 1;
2594 relative_reloc
= TRUE
;
2599 unresolved_reloc
= FALSE
;
2603 if (local_got_offsets
== NULL
)
2606 off
= local_got_offsets
[r_symndx
];
2608 /* The offset must always be a multiple of 4. We use
2609 the least significant bit to record whether we have
2610 already generated the necessary reloc. */
2615 bfd_put_32 (output_bfd
, relocation
,
2616 htab
->elf
.sgot
->contents
+ off
);
2617 local_got_offsets
[r_symndx
] |= 1;
2619 if (bfd_link_pic (info
))
2620 relative_reloc
= TRUE
;
2627 Elf_Internal_Rela outrel
;
2629 s
= htab
->elf
.srelgot
;
2633 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
2634 + htab
->elf
.sgot
->output_offset
2636 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2637 elf_append_rel (output_bfd
, s
, &outrel
);
2640 if (off
>= (bfd_vma
) -2)
2643 relocation
= (htab
->elf
.sgot
->output_section
->vma
2644 + htab
->elf
.sgot
->output_offset
+ off
);
2645 if (rel
->r_offset
> 1
2646 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2647 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2649 if (bfd_link_pic (info
))
2651 /* For PIC, disallow R_386_GOT32 without a base
2652 register, except for "lea foo@GOT, %reg", since
2653 we don't know what the GOT base is. */
2657 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
2658 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2661 name
= h
->root
.root
.string
;
2664 /* xgettext:c-format */
2665 (_("%B: direct GOT relocation %s against `%s'"
2666 " without base register can not be used"
2667 " when making a shared object"),
2668 input_bfd
, howto
->name
, name
);
2669 bfd_set_error (bfd_error_bad_value
);
2675 /* Subtract the .got.plt section address only with a base
2677 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
2678 + htab
->elf
.sgotplt
->output_offset
);
2684 /* Relocation is relative to the start of the global offset
2687 /* Check to make sure it isn't a protected function or data
2688 symbol for shared library since it may not be local when
2689 used as function address or with copy relocation. We also
2690 need to make sure that a symbol is referenced locally. */
2691 if (!bfd_link_executable (info
) && h
)
2693 if (!h
->def_regular
)
2697 switch (ELF_ST_VISIBILITY (h
->other
))
2700 v
= _("hidden symbol");
2703 v
= _("internal symbol");
2706 v
= _("protected symbol");
2714 /* xgettext:c-format */
2715 (_("%B: relocation R_386_GOTOFF against undefined %s"
2716 " `%s' can not be used when making a shared object"),
2717 input_bfd
, v
, h
->root
.root
.string
);
2718 bfd_set_error (bfd_error_bad_value
);
2721 else if (!SYMBOL_REFERENCES_LOCAL_P (info
, h
)
2722 && (h
->type
== STT_FUNC
2723 || h
->type
== STT_OBJECT
)
2724 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2727 /* xgettext:c-format */
2728 (_("%B: relocation R_386_GOTOFF against protected %s"
2729 " `%s' can not be used when making a shared object"),
2731 h
->type
== STT_FUNC
? "function" : "data",
2732 h
->root
.root
.string
);
2733 bfd_set_error (bfd_error_bad_value
);
2738 /* Note that sgot is not involved in this
2739 calculation. We always want the start of .got.plt. If we
2740 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2741 permitted by the ABI, we might have to change this
2743 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2744 + htab
->elf
.sgotplt
->output_offset
;
2748 /* Use global offset table as symbol value. */
2749 relocation
= htab
->elf
.sgotplt
->output_section
->vma
2750 + htab
->elf
.sgotplt
->output_offset
;
2751 unresolved_reloc
= FALSE
;
2755 /* Relocation is to the entry for this symbol in the
2756 procedure linkage table. */
2758 /* Resolve a PLT32 reloc against a local symbol directly,
2759 without using the procedure linkage table. */
2763 if ((h
->plt
.offset
== (bfd_vma
) -1
2764 && eh
->plt_got
.offset
== (bfd_vma
) -1)
2765 || htab
->elf
.splt
== NULL
)
2767 /* We didn't make a PLT entry for this symbol. This
2768 happens when statically linking PIC code, or when
2769 using -Bsymbolic. */
2773 if (h
->plt
.offset
!= (bfd_vma
) -1)
2775 if (htab
->plt_second
!= NULL
)
2777 resolved_plt
= htab
->plt_second
;
2778 plt_offset
= eh
->plt_second
.offset
;
2782 resolved_plt
= htab
->elf
.splt
;
2783 plt_offset
= h
->plt
.offset
;
2788 resolved_plt
= htab
->plt_got
;
2789 plt_offset
= eh
->plt_got
.offset
;
2792 relocation
= (resolved_plt
->output_section
->vma
2793 + resolved_plt
->output_offset
2795 unresolved_reloc
= FALSE
;
2799 /* Set to symbol size. */
2800 relocation
= st_size
;
2805 if ((input_section
->flags
& SEC_ALLOC
) == 0
2809 /* Copy dynamic function pointer relocations. Don't generate
2810 dynamic relocations against resolved undefined weak symbols
2811 in PIE, except for R_386_PC32. */
2812 if ((bfd_link_pic (info
)
2814 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2815 && (!resolved_to_zero
2816 || r_type
== R_386_PC32
))
2817 || h
->root
.type
!= bfd_link_hash_undefweak
))
2818 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
2819 || !SYMBOL_CALLS_LOCAL (info
, h
)))
2820 || (ELIMINATE_COPY_RELOCS
2821 && !bfd_link_pic (info
)
2825 || eh
->func_pointer_refcount
> 0
2826 || (h
->root
.type
== bfd_link_hash_undefweak
2827 && !resolved_to_zero
))
2828 && ((h
->def_dynamic
&& !h
->def_regular
)
2829 /* Undefined weak symbol is bound locally when
2831 || h
->root
.type
== bfd_link_hash_undefweak
)))
2833 Elf_Internal_Rela outrel
;
2834 bfd_boolean skip
, relocate
;
2837 /* When generating a shared object, these relocations
2838 are copied into the output file to be resolved at run
2845 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2847 if (outrel
.r_offset
== (bfd_vma
) -1)
2849 else if (outrel
.r_offset
== (bfd_vma
) -2)
2850 skip
= TRUE
, relocate
= TRUE
;
2851 outrel
.r_offset
+= (input_section
->output_section
->vma
2852 + input_section
->output_offset
);
2855 memset (&outrel
, 0, sizeof outrel
);
2858 && (r_type
== R_386_PC32
2859 || !(bfd_link_executable (info
)
2860 || SYMBOLIC_BIND (info
, h
))
2861 || !h
->def_regular
))
2862 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2865 /* This symbol is local, or marked to become local. */
2867 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2870 sreloc
= elf_section_data (input_section
)->sreloc
;
2872 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
2874 r
= bfd_reloc_notsupported
;
2875 goto check_relocation_error
;
2878 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2880 /* If this reloc is against an external symbol, we do
2881 not want to fiddle with the addend. Otherwise, we
2882 need to include the symbol value so that it becomes
2883 an addend for the dynamic reloc. */
2890 if (!bfd_link_executable (info
))
2892 Elf_Internal_Rela outrel
;
2895 outrel
.r_offset
= rel
->r_offset
2896 + input_section
->output_section
->vma
2897 + input_section
->output_offset
;
2898 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2899 sreloc
= elf_section_data (input_section
)->sreloc
;
2902 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2907 case R_386_TLS_GOTDESC
:
2908 case R_386_TLS_DESC_CALL
:
2909 case R_386_TLS_IE_32
:
2910 case R_386_TLS_GOTIE
:
2911 tls_type
= GOT_UNKNOWN
;
2912 if (h
== NULL
&& local_got_offsets
)
2913 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
2915 tls_type
= elf_x86_hash_entry(h
)->tls_type
;
2916 if (tls_type
== GOT_TLS_IE
)
2917 tls_type
= GOT_TLS_IE_NEG
;
2919 r_type_tls
= r_type
;
2920 if (! elf_i386_tls_transition (info
, input_bfd
,
2921 input_section
, contents
,
2922 symtab_hdr
, sym_hashes
,
2923 &r_type_tls
, tls_type
, rel
,
2924 relend
, h
, r_symndx
, TRUE
))
2927 if (r_type_tls
== R_386_TLS_LE_32
)
2929 BFD_ASSERT (! unresolved_reloc
);
2930 if (r_type
== R_386_TLS_GD
)
2935 /* GD->LE transition. */
2936 type
= *(contents
+ rel
->r_offset
- 2);
2940 leal foo@tlsgd(,%ebx,1), %eax
2941 call ___tls_get_addr@PLT
2944 subl $foo@tpoff, %eax
2945 (6 byte form of subl). */
2946 roff
= rel
->r_offset
+ 5;
2951 leal foo@tlsgd(%ebx), %eax
2952 call ___tls_get_addr@PLT
2955 leal foo@tlsgd(%reg), %eax
2956 call *___tls_get_addr@GOT(%reg)
2957 which may be converted to
2958 addr32 call ___tls_get_addr
2960 movl %gs:0, %eax; subl $foo@tpoff, %eax
2961 (6 byte form of subl). */
2962 roff
= rel
->r_offset
+ 6;
2964 memcpy (contents
+ roff
- 8,
2965 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2966 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
2968 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
2973 else if (r_type
== R_386_TLS_GOTDESC
)
2975 /* GDesc -> LE transition.
2976 It's originally something like:
2977 leal x@tlsdesc(%ebx), %eax
2981 Registers other than %eax may be set up here. */
2986 roff
= rel
->r_offset
;
2987 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2989 /* Now modify the instruction as appropriate. */
2990 /* aoliva FIXME: remove the above and xor the byte
2992 bfd_put_8 (output_bfd
, val
^ 0x86,
2993 contents
+ roff
- 1);
2994 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
2998 else if (r_type
== R_386_TLS_DESC_CALL
)
3000 /* GDesc -> LE transition.
3008 roff
= rel
->r_offset
;
3009 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3010 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3013 else if (r_type
== R_386_TLS_IE
)
3017 /* IE->LE transition:
3018 Originally it can be one of:
3026 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3029 /* movl foo, %eax. */
3030 bfd_put_8 (output_bfd
, 0xb8,
3031 contents
+ rel
->r_offset
- 1);
3037 type
= bfd_get_8 (input_bfd
,
3038 contents
+ rel
->r_offset
- 2);
3043 bfd_put_8 (output_bfd
, 0xc7,
3044 contents
+ rel
->r_offset
- 2);
3045 bfd_put_8 (output_bfd
,
3046 0xc0 | ((val
>> 3) & 7),
3047 contents
+ rel
->r_offset
- 1);
3051 bfd_put_8 (output_bfd
, 0x81,
3052 contents
+ rel
->r_offset
- 2);
3053 bfd_put_8 (output_bfd
,
3054 0xc0 | ((val
>> 3) & 7),
3055 contents
+ rel
->r_offset
- 1);
3062 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3063 contents
+ rel
->r_offset
);
3068 unsigned int val
, type
;
3070 /* {IE_32,GOTIE}->LE transition:
3071 Originally it can be one of:
3072 subl foo(%reg1), %reg2
3073 movl foo(%reg1), %reg2
3074 addl foo(%reg1), %reg2
3077 movl $foo, %reg2 (6 byte form)
3078 addl $foo, %reg2. */
3079 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3080 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3084 bfd_put_8 (output_bfd
, 0xc7,
3085 contents
+ rel
->r_offset
- 2);
3086 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3087 contents
+ rel
->r_offset
- 1);
3089 else if (type
== 0x2b)
3092 bfd_put_8 (output_bfd
, 0x81,
3093 contents
+ rel
->r_offset
- 2);
3094 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3095 contents
+ rel
->r_offset
- 1);
3097 else if (type
== 0x03)
3100 bfd_put_8 (output_bfd
, 0x81,
3101 contents
+ rel
->r_offset
- 2);
3102 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3103 contents
+ rel
->r_offset
- 1);
3107 if (r_type
== R_386_TLS_GOTIE
)
3108 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3109 contents
+ rel
->r_offset
);
3111 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3112 contents
+ rel
->r_offset
);
3117 if (htab
->elf
.sgot
== NULL
)
3122 off
= h
->got
.offset
;
3123 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3127 if (local_got_offsets
== NULL
)
3130 off
= local_got_offsets
[r_symndx
];
3131 offplt
= local_tlsdesc_gotents
[r_symndx
];
3138 Elf_Internal_Rela outrel
;
3142 if (htab
->elf
.srelgot
== NULL
)
3145 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3147 if (GOT_TLS_GDESC_P (tls_type
))
3150 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3151 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3152 <= htab
->elf
.sgotplt
->size
);
3153 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3154 + htab
->elf
.sgotplt
->output_offset
3156 + htab
->sgotplt_jump_table_size
);
3157 sreloc
= htab
->elf
.srelplt
;
3158 loc
= sreloc
->contents
;
3159 loc
+= (htab
->next_tls_desc_index
++
3160 * sizeof (Elf32_External_Rel
));
3161 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3162 <= sreloc
->contents
+ sreloc
->size
);
3163 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3166 BFD_ASSERT (! unresolved_reloc
);
3167 bfd_put_32 (output_bfd
,
3168 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3169 htab
->elf
.sgotplt
->contents
+ offplt
3170 + htab
->sgotplt_jump_table_size
+ 4);
3174 bfd_put_32 (output_bfd
, 0,
3175 htab
->elf
.sgotplt
->contents
+ offplt
3176 + htab
->sgotplt_jump_table_size
+ 4);
3180 sreloc
= htab
->elf
.srelgot
;
3182 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3183 + htab
->elf
.sgot
->output_offset
+ off
);
3185 if (GOT_TLS_GD_P (tls_type
))
3186 dr_type
= R_386_TLS_DTPMOD32
;
3187 else if (GOT_TLS_GDESC_P (tls_type
))
3189 else if (tls_type
== GOT_TLS_IE_POS
)
3190 dr_type
= R_386_TLS_TPOFF
;
3192 dr_type
= R_386_TLS_TPOFF32
;
3194 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3195 bfd_put_32 (output_bfd
,
3196 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3197 htab
->elf
.sgot
->contents
+ off
);
3198 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3199 bfd_put_32 (output_bfd
,
3200 _bfd_x86_elf_dtpoff_base (info
) - relocation
,
3201 htab
->elf
.sgot
->contents
+ off
);
3202 else if (dr_type
!= R_386_TLS_DESC
)
3203 bfd_put_32 (output_bfd
, 0,
3204 htab
->elf
.sgot
->contents
+ off
);
3205 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3207 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3209 if (GOT_TLS_GD_P (tls_type
))
3213 BFD_ASSERT (! unresolved_reloc
);
3214 bfd_put_32 (output_bfd
,
3215 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3216 htab
->elf
.sgot
->contents
+ off
+ 4);
3220 bfd_put_32 (output_bfd
, 0,
3221 htab
->elf
.sgot
->contents
+ off
+ 4);
3222 outrel
.r_info
= ELF32_R_INFO (indx
,
3223 R_386_TLS_DTPOFF32
);
3224 outrel
.r_offset
+= 4;
3225 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3228 else if (tls_type
== GOT_TLS_IE_BOTH
)
3230 bfd_put_32 (output_bfd
,
3232 ? relocation
- _bfd_x86_elf_dtpoff_base (info
)
3234 htab
->elf
.sgot
->contents
+ off
+ 4);
3235 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3236 outrel
.r_offset
+= 4;
3237 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3244 local_got_offsets
[r_symndx
] |= 1;
3247 if (off
>= (bfd_vma
) -2
3248 && ! GOT_TLS_GDESC_P (tls_type
))
3250 if (r_type_tls
== R_386_TLS_GOTDESC
3251 || r_type_tls
== R_386_TLS_DESC_CALL
)
3253 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3254 unresolved_reloc
= FALSE
;
3256 else if (r_type_tls
== r_type
)
3258 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3259 + htab
->elf
.sgotplt
->output_offset
;
3260 relocation
= htab
->elf
.sgot
->output_section
->vma
3261 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3262 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3263 && tls_type
== GOT_TLS_IE_BOTH
)
3265 if (r_type
== R_386_TLS_IE
)
3266 relocation
+= g_o_t
;
3267 unresolved_reloc
= FALSE
;
3269 else if (r_type
== R_386_TLS_GD
)
3271 unsigned int val
, type
;
3274 /* GD->IE transition. */
3275 type
= *(contents
+ rel
->r_offset
- 2);
3276 val
= *(contents
+ rel
->r_offset
- 1);
3280 leal foo@tlsgd(,%ebx,1), %eax
3281 call ___tls_get_addr@PLT
3284 subl $foo@gottpoff(%ebx), %eax. */
3286 roff
= rel
->r_offset
- 3;
3291 leal foo@tlsgd(%ebx), %eax
3292 call ___tls_get_addr@PLT
3295 leal foo@tlsgd(%reg), %eax
3296 call *___tls_get_addr@GOT(%reg)
3297 which may be converted to
3298 addr32 call ___tls_get_addr
3301 subl $foo@gottpoff(%reg), %eax. */
3302 roff
= rel
->r_offset
- 2;
3304 memcpy (contents
+ roff
,
3305 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3306 contents
[roff
+ 7] = 0x80 | (val
& 7);
3307 /* If foo is used only with foo@gotntpoff(%reg) and
3308 foo@indntpoff, but not with foo@gottpoff(%reg), change
3309 subl $foo@gottpoff(%reg), %eax
3311 addl $foo@gotntpoff(%reg), %eax. */
3312 if (tls_type
== GOT_TLS_IE_POS
)
3313 contents
[roff
+ 6] = 0x03;
3314 bfd_put_32 (output_bfd
,
3315 htab
->elf
.sgot
->output_section
->vma
3316 + htab
->elf
.sgot
->output_offset
+ off
3317 - htab
->elf
.sgotplt
->output_section
->vma
3318 - htab
->elf
.sgotplt
->output_offset
,
3319 contents
+ roff
+ 8);
3320 /* Skip R_386_PLT32 and R_386_GOT32X. */
3325 else if (r_type
== R_386_TLS_GOTDESC
)
3327 /* GDesc -> IE transition.
3328 It's originally something like:
3329 leal x@tlsdesc(%ebx), %eax
3332 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3334 movl x@gottpoff(%ebx), %eax # before negl %eax
3336 Registers other than %eax may be set up here. */
3340 /* First, make sure it's a leal adding ebx to a 32-bit
3341 offset into any register, although it's probably
3342 almost always going to be eax. */
3343 roff
= rel
->r_offset
;
3345 /* Now modify the instruction as appropriate. */
3346 /* To turn a leal into a movl in the form we use it, it
3347 suffices to change the first byte from 0x8d to 0x8b.
3348 aoliva FIXME: should we decide to keep the leal, all
3349 we have to do is remove the statement below, and
3350 adjust the relaxation of R_386_TLS_DESC_CALL. */
3351 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3353 if (tls_type
== GOT_TLS_IE_BOTH
)
3356 bfd_put_32 (output_bfd
,
3357 htab
->elf
.sgot
->output_section
->vma
3358 + htab
->elf
.sgot
->output_offset
+ off
3359 - htab
->elf
.sgotplt
->output_section
->vma
3360 - htab
->elf
.sgotplt
->output_offset
,
3364 else if (r_type
== R_386_TLS_DESC_CALL
)
3366 /* GDesc -> IE transition.
3374 depending on how we transformed the TLS_GOTDESC above.
3379 roff
= rel
->r_offset
;
3381 /* Now modify the instruction as appropriate. */
3382 if (tls_type
!= GOT_TLS_IE_NEG
)
3385 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3386 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3391 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3392 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3402 if (! elf_i386_tls_transition (info
, input_bfd
,
3403 input_section
, contents
,
3404 symtab_hdr
, sym_hashes
,
3405 &r_type
, GOT_UNKNOWN
, rel
,
3406 relend
, h
, r_symndx
, TRUE
))
3409 if (r_type
!= R_386_TLS_LDM
)
3411 /* LD->LE transition. Change
3412 leal foo@tlsldm(%ebx) %eax
3413 call ___tls_get_addr@PLT
3417 leal 0(%esi,1), %esi
3419 leal foo@tlsldm(%reg) %eax
3420 call *___tls_get_addr@GOT(%reg)
3421 which may be converted to
3422 addr32 call ___tls_get_addr
3425 leal 0(%esi), %esi */
3426 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3427 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
3428 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
3429 memcpy (contents
+ rel
->r_offset
- 2,
3430 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
3432 memcpy (contents
+ rel
->r_offset
- 2,
3433 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3434 /* Skip R_386_PC32/R_386_PLT32. */
3440 if (htab
->elf
.sgot
== NULL
)
3443 off
= htab
->tls_ld_or_ldm_got
.offset
;
3448 Elf_Internal_Rela outrel
;
3450 if (htab
->elf
.srelgot
== NULL
)
3453 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3454 + htab
->elf
.sgot
->output_offset
+ off
);
3456 bfd_put_32 (output_bfd
, 0,
3457 htab
->elf
.sgot
->contents
+ off
);
3458 bfd_put_32 (output_bfd
, 0,
3459 htab
->elf
.sgot
->contents
+ off
+ 4);
3460 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3461 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3462 htab
->tls_ld_or_ldm_got
.offset
|= 1;
3464 relocation
= htab
->elf
.sgot
->output_section
->vma
3465 + htab
->elf
.sgot
->output_offset
+ off
3466 - htab
->elf
.sgotplt
->output_section
->vma
3467 - htab
->elf
.sgotplt
->output_offset
;
3468 unresolved_reloc
= FALSE
;
3471 case R_386_TLS_LDO_32
:
3472 if (!bfd_link_executable (info
)
3473 || (input_section
->flags
& SEC_CODE
) == 0)
3474 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3476 /* When converting LDO to LE, we must negate. */
3477 relocation
= -elf_i386_tpoff (info
, relocation
);
3480 case R_386_TLS_LE_32
:
3482 if (!bfd_link_executable (info
))
3484 Elf_Internal_Rela outrel
;
3487 outrel
.r_offset
= rel
->r_offset
3488 + input_section
->output_section
->vma
3489 + input_section
->output_offset
;
3490 if (h
!= NULL
&& h
->dynindx
!= -1)
3494 if (r_type
== R_386_TLS_LE_32
)
3495 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3497 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3498 sreloc
= elf_section_data (input_section
)->sreloc
;
3501 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3504 else if (r_type
== R_386_TLS_LE_32
)
3505 relocation
= _bfd_x86_elf_dtpoff_base (info
) - relocation
;
3507 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3509 else if (r_type
== R_386_TLS_LE_32
)
3510 relocation
= elf_i386_tpoff (info
, relocation
);
3512 relocation
= -elf_i386_tpoff (info
, relocation
);
3519 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3520 because such sections are not SEC_ALLOC and thus ld.so will
3521 not process them. */
3522 if (unresolved_reloc
3523 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3525 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3526 rel
->r_offset
) != (bfd_vma
) -1)
3529 /* xgettext:c-format */
3530 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
3535 h
->root
.root
.string
);
3540 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3541 contents
, rel
->r_offset
,
3544 check_relocation_error
:
3545 if (r
!= bfd_reloc_ok
)
3550 name
= h
->root
.root
.string
;
3553 name
= bfd_elf_string_from_elf_section (input_bfd
,
3554 symtab_hdr
->sh_link
,
3559 name
= bfd_section_name (input_bfd
, sec
);
3562 if (r
== bfd_reloc_overflow
)
3563 (*info
->callbacks
->reloc_overflow
)
3564 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3565 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3569 /* xgettext:c-format */
3570 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
3571 input_bfd
, input_section
,
3572 rel
->r_offset
, name
, (int) r
);
3583 Elf_Internal_Shdr
*rel_hdr
;
3584 size_t deleted
= rel
- wrel
;
3586 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
3587 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3588 if (rel_hdr
->sh_size
== 0)
3590 /* It is too late to remove an empty reloc section. Leave
3592 ??? What is wrong with an empty section??? */
3593 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
3596 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
3597 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3598 input_section
->reloc_count
-= deleted
;
3604 /* Finish up dynamic symbol handling. We set the contents of various
3605 dynamic sections here. */
3608 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3609 struct bfd_link_info
*info
,
3610 struct elf_link_hash_entry
*h
,
3611 Elf_Internal_Sym
*sym
)
3613 struct elf_x86_link_hash_table
*htab
;
3614 unsigned plt_entry_size
;
3615 struct elf_x86_link_hash_entry
*eh
;
3616 bfd_boolean local_undefweak
;
3617 bfd_boolean use_plt_second
;
3619 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
3623 plt_entry_size
= htab
->plt
.plt_entry_size
;
3625 /* Use the second PLT section only if there is .plt section. */
3626 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
3628 eh
= (struct elf_x86_link_hash_entry
*) h
;
3629 if (eh
->no_finish_dynamic_symbol
)
3632 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
3633 resolved undefined weak symbols in executable so that their
3634 references have value 0 at run-time. */
3635 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
3637 if (h
->plt
.offset
!= (bfd_vma
) -1)
3639 bfd_vma plt_index
, plt_offset
;
3641 Elf_Internal_Rela rel
;
3643 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
3645 /* When building a static executable, use .iplt, .igot.plt and
3646 .rel.iplt sections for STT_GNU_IFUNC symbols. */
3647 if (htab
->elf
.splt
!= NULL
)
3649 plt
= htab
->elf
.splt
;
3650 gotplt
= htab
->elf
.sgotplt
;
3651 relplt
= htab
->elf
.srelplt
;
3655 plt
= htab
->elf
.iplt
;
3656 gotplt
= htab
->elf
.igotplt
;
3657 relplt
= htab
->elf
.irelplt
;
3660 /* This symbol has an entry in the procedure linkage table. Set
3663 if ((h
->dynindx
== -1
3665 && !((h
->forced_local
|| bfd_link_executable (info
))
3667 && h
->type
== STT_GNU_IFUNC
))
3673 /* Get the index in the procedure linkage table which
3674 corresponds to this symbol. This is the index of this symbol
3675 in all the symbols for which we are making plt entries. The
3676 first entry in the procedure linkage table is reserved.
3678 Get the offset into the .got table of the entry that
3679 corresponds to this function. Each .got entry is 4 bytes.
3680 The first three are reserved.
3682 For static executables, we don't reserve anything. */
3684 if (plt
== htab
->elf
.splt
)
3686 got_offset
= (h
->plt
.offset
/ plt_entry_size
3687 - htab
->plt
.has_plt0
);
3688 got_offset
= (got_offset
+ 3) * 4;
3692 got_offset
= h
->plt
.offset
/ plt_entry_size
;
3693 got_offset
= got_offset
* 4;
3696 /* Fill in the entry in the procedure linkage table and update
3698 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
3703 const bfd_byte
*plt_entry
;
3704 if (bfd_link_pic (info
))
3705 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3707 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3708 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
3709 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
3711 resolved_plt
= htab
->plt_second
;
3712 plt_offset
= eh
->plt_second
.offset
;
3717 plt_offset
= h
->plt
.offset
;
3720 if (! bfd_link_pic (info
))
3722 bfd_put_32 (output_bfd
,
3723 (gotplt
->output_section
->vma
3724 + gotplt
->output_offset
3726 resolved_plt
->contents
+ plt_offset
3727 + htab
->plt
.plt_got_offset
);
3729 if (htab
->is_vxworks
)
3731 int s
, k
, reloc_index
;
3733 /* Create the R_386_32 relocation referencing the GOT
3734 for this PLT entry. */
3736 /* S: Current slot number (zero-based). */
3737 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
3738 / htab
->plt
.plt_entry_size
);
3739 /* K: Number of relocations for PLTResolve. */
3740 if (bfd_link_pic (info
))
3741 k
= PLTRESOLVE_RELOCS_SHLIB
;
3743 k
= PLTRESOLVE_RELOCS
;
3744 /* Skip the PLTresolve relocations, and the relocations for
3745 the other PLT slots. */
3746 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3747 loc
= (htab
->srelplt2
->contents
+ reloc_index
3748 * sizeof (Elf32_External_Rel
));
3750 rel
.r_offset
= (plt
->output_section
->vma
3751 + plt
->output_offset
3752 + h
->plt
.offset
+ 2),
3753 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3754 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3756 /* Create the R_386_32 relocation referencing the beginning of
3757 the PLT for this GOT entry. */
3758 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3759 + htab
->elf
.sgotplt
->output_offset
3761 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3762 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3763 loc
+ sizeof (Elf32_External_Rel
));
3768 bfd_put_32 (output_bfd
, got_offset
,
3769 resolved_plt
->contents
+ plt_offset
3770 + htab
->plt
.plt_got_offset
);
3773 /* Fill in the entry in the global offset table. Leave the entry
3774 as zero for undefined weak symbol in PIE. No PLT relocation
3775 against undefined weak symbol in PIE. */
3776 if (!local_undefweak
)
3778 if (htab
->plt
.has_plt0
)
3779 bfd_put_32 (output_bfd
,
3780 (plt
->output_section
->vma
3781 + plt
->output_offset
3783 + htab
->lazy_plt
->plt_lazy_offset
),
3784 gotplt
->contents
+ got_offset
);
3786 /* Fill in the entry in the .rel.plt section. */
3787 rel
.r_offset
= (gotplt
->output_section
->vma
3788 + gotplt
->output_offset
3790 if (h
->dynindx
== -1
3791 || ((bfd_link_executable (info
)
3792 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3794 && h
->type
== STT_GNU_IFUNC
))
3796 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3797 h
->root
.root
.string
,
3798 h
->root
.u
.def
.section
->owner
);
3800 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3801 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
3802 in the .got.plt section. */
3803 bfd_put_32 (output_bfd
,
3804 (h
->root
.u
.def
.value
3805 + h
->root
.u
.def
.section
->output_section
->vma
3806 + h
->root
.u
.def
.section
->output_offset
),
3807 gotplt
->contents
+ got_offset
);
3808 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3809 /* R_386_IRELATIVE comes last. */
3810 plt_index
= htab
->next_irelative_index
--;
3814 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3815 plt_index
= htab
->next_jump_slot_index
++;
3818 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3819 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3821 /* Don't fill the second and third slots in PLT entry for
3822 static executables nor without PLT0. */
3823 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
3825 bfd_put_32 (output_bfd
,
3826 plt_index
* sizeof (Elf32_External_Rel
),
3827 plt
->contents
+ h
->plt
.offset
3828 + htab
->lazy_plt
->plt_reloc_offset
);
3829 bfd_put_32 (output_bfd
,
3831 + htab
->lazy_plt
->plt_plt_offset
+ 4),
3832 (plt
->contents
+ h
->plt
.offset
3833 + htab
->lazy_plt
->plt_plt_offset
));
3837 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
3839 bfd_vma got_offset
, plt_offset
;
3840 asection
*plt
, *got
, *gotplt
;
3841 const bfd_byte
*got_plt_entry
;
3843 /* Set the entry in the GOT procedure linkage table. */
3844 plt
= htab
->plt_got
;
3845 got
= htab
->elf
.sgot
;
3846 gotplt
= htab
->elf
.sgotplt
;
3847 got_offset
= h
->got
.offset
;
3849 if (got_offset
== (bfd_vma
) -1
3855 /* Fill in the entry in the GOT procedure linkage table. */
3856 if (! bfd_link_pic (info
))
3858 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3859 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
3863 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3864 got_offset
+= (got
->output_section
->vma
3865 + got
->output_offset
3866 - gotplt
->output_section
->vma
3867 - gotplt
->output_offset
);
3870 plt_offset
= eh
->plt_got
.offset
;
3871 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
3872 htab
->non_lazy_plt
->plt_entry_size
);
3873 bfd_put_32 (output_bfd
, got_offset
,
3874 (plt
->contents
+ plt_offset
3875 + htab
->non_lazy_plt
->plt_got_offset
));
3878 if (!local_undefweak
3880 && (h
->plt
.offset
!= (bfd_vma
) -1
3881 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
3883 /* Mark the symbol as undefined, rather than as defined in
3884 the .plt section. Leave the value if there were any
3885 relocations where pointer equality matters (this is a clue
3886 for the dynamic linker, to make function pointer
3887 comparisons work between an application and shared
3888 library), otherwise set it to zero. If a function is only
3889 called from a binary, there is no need to slow down
3890 shared libraries because of that. */
3891 sym
->st_shndx
= SHN_UNDEF
;
3892 if (!h
->pointer_equality_needed
)
3896 /* Don't generate dynamic GOT relocation against undefined weak
3897 symbol in executable. */
3898 if (h
->got
.offset
!= (bfd_vma
) -1
3899 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h
)->tls_type
)
3900 && (elf_x86_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
3901 && !local_undefweak
)
3903 Elf_Internal_Rela rel
;
3904 asection
*relgot
= htab
->elf
.srelgot
;
3906 /* This symbol has an entry in the global offset table. Set it
3909 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
3912 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3913 + htab
->elf
.sgot
->output_offset
3914 + (h
->got
.offset
& ~(bfd_vma
) 1));
3916 /* If this is a static link, or it is a -Bsymbolic link and the
3917 symbol is defined locally or was forced to be local because
3918 of a version file, we just want to emit a RELATIVE reloc.
3919 The entry in the global offset table will already have been
3920 initialized in the relocate_section function. */
3922 && h
->type
== STT_GNU_IFUNC
)
3924 if (h
->plt
.offset
== (bfd_vma
) -1)
3926 /* STT_GNU_IFUNC is referenced without PLT. */
3927 if (htab
->elf
.splt
== NULL
)
3929 /* use .rel[a].iplt section to store .got relocations
3930 in static executable. */
3931 relgot
= htab
->elf
.irelplt
;
3933 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3935 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3936 h
->root
.root
.string
,
3937 h
->root
.u
.def
.section
->owner
);
3939 bfd_put_32 (output_bfd
,
3940 (h
->root
.u
.def
.value
3941 + h
->root
.u
.def
.section
->output_section
->vma
3942 + h
->root
.u
.def
.section
->output_offset
),
3943 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3944 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3949 else if (bfd_link_pic (info
))
3951 /* Generate R_386_GLOB_DAT. */
3959 if (!h
->pointer_equality_needed
)
3962 /* For non-shared object, we can't use .got.plt, which
3963 contains the real function addres if we need pointer
3964 equality. We load the GOT entry with the PLT entry. */
3965 if (htab
->plt_second
!= NULL
)
3967 plt
= htab
->plt_second
;
3968 plt_offset
= eh
->plt_second
.offset
;
3972 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3973 plt_offset
= h
->plt
.offset
;
3975 bfd_put_32 (output_bfd
,
3976 (plt
->output_section
->vma
3977 + plt
->output_offset
+ plt_offset
),
3978 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3982 else if (bfd_link_pic (info
)
3983 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3985 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3986 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3990 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3992 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3993 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3994 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3997 elf_append_rel (output_bfd
, relgot
, &rel
);
4002 Elf_Internal_Rela rel
;
4005 /* This symbol needs a copy reloc. Set it up. */
4007 if (h
->dynindx
== -1
4008 || (h
->root
.type
!= bfd_link_hash_defined
4009 && h
->root
.type
!= bfd_link_hash_defweak
)
4010 || htab
->elf
.srelbss
== NULL
4011 || htab
->elf
.sreldynrelro
== NULL
)
4014 rel
.r_offset
= (h
->root
.u
.def
.value
4015 + h
->root
.u
.def
.section
->output_section
->vma
4016 + h
->root
.u
.def
.section
->output_offset
);
4017 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4018 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
4019 s
= htab
->elf
.sreldynrelro
;
4021 s
= htab
->elf
.srelbss
;
4022 elf_append_rel (output_bfd
, s
, &rel
);
4028 /* Finish up local dynamic symbol handling. We set the contents of
4029 various dynamic sections here. */
4032 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4034 struct elf_link_hash_entry
*h
4035 = (struct elf_link_hash_entry
*) *slot
;
4036 struct bfd_link_info
*info
4037 = (struct bfd_link_info
*) inf
;
4039 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4043 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4044 here since undefined weak symbol may not be dynamic and may not be
4045 called for elf_i386_finish_dynamic_symbol. */
4048 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
4051 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
4052 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4054 if (h
->root
.type
!= bfd_link_hash_undefweak
4055 || h
->dynindx
!= -1)
4058 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
4062 /* Used to decide how to sort relocs in an optimal manner for the
4063 dynamic linker, before writing them out. */
4065 static enum elf_reloc_type_class
4066 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
4067 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4068 const Elf_Internal_Rela
*rela
)
4070 bfd
*abfd
= info
->output_bfd
;
4071 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4072 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4074 if (htab
->dynsym
!= NULL
4075 && htab
->dynsym
->contents
!= NULL
)
4077 /* Check relocation against STT_GNU_IFUNC symbol if there are
4079 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
4080 if (r_symndx
!= STN_UNDEF
)
4082 Elf_Internal_Sym sym
;
4083 if (!bed
->s
->swap_symbol_in (abfd
,
4084 (htab
->dynsym
->contents
4085 + r_symndx
* sizeof (Elf32_External_Sym
)),
4089 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
4090 return reloc_class_ifunc
;
4094 switch (ELF32_R_TYPE (rela
->r_info
))
4096 case R_386_IRELATIVE
:
4097 return reloc_class_ifunc
;
4098 case R_386_RELATIVE
:
4099 return reloc_class_relative
;
4100 case R_386_JUMP_SLOT
:
4101 return reloc_class_plt
;
4103 return reloc_class_copy
;
4105 return reloc_class_normal
;
4109 /* Finish up the dynamic sections. */
4112 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4113 struct bfd_link_info
*info
)
4115 struct elf_x86_link_hash_table
*htab
;
4118 const struct elf_i386_backend_data
*abed
;
4120 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
4124 dynobj
= htab
->elf
.dynobj
;
4125 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4126 abed
= get_elf_i386_backend_data (output_bfd
);
4128 if (htab
->elf
.dynamic_sections_created
)
4130 Elf32_External_Dyn
*dyncon
, *dynconend
;
4132 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4135 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4136 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4137 for (; dyncon
< dynconend
; dyncon
++)
4139 Elf_Internal_Dyn dyn
;
4142 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4147 if (htab
->is_vxworks
4148 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4153 s
= htab
->elf
.sgotplt
;
4154 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4158 s
= htab
->elf
.srelplt
;
4159 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4163 s
= htab
->elf
.srelplt
;
4164 dyn
.d_un
.d_val
= s
->size
;
4168 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4171 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4173 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4174 really seem like the right value. */
4175 elf_section_data (htab
->elf
.splt
->output_section
)
4176 ->this_hdr
.sh_entsize
= 4;
4178 if (htab
->plt
.has_plt0
)
4180 /* Fill in the special first entry in the procedure linkage
4182 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
4183 htab
->lazy_plt
->plt0_entry_size
);
4184 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
4185 abed
->plt0_pad_byte
,
4186 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
4187 if (!bfd_link_pic (info
))
4189 bfd_put_32 (output_bfd
,
4190 (htab
->elf
.sgotplt
->output_section
->vma
4191 + htab
->elf
.sgotplt
->output_offset
4193 htab
->elf
.splt
->contents
4194 + htab
->lazy_plt
->plt0_got1_offset
);
4195 bfd_put_32 (output_bfd
,
4196 (htab
->elf
.sgotplt
->output_section
->vma
4197 + htab
->elf
.sgotplt
->output_offset
4199 htab
->elf
.splt
->contents
4200 + htab
->lazy_plt
->plt0_got2_offset
);
4202 if (htab
->is_vxworks
)
4204 Elf_Internal_Rela rel
;
4205 int num_plts
= (htab
->elf
.splt
->size
4206 / htab
->plt
.plt_entry_size
) - 1;
4208 asection
*srelplt2
= htab
->srelplt2
;
4210 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4211 + 4. On IA32 we use REL relocations so the
4212 addend goes in the PLT directly. */
4213 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4214 + htab
->elf
.splt
->output_offset
4215 + htab
->lazy_plt
->plt0_got1_offset
);
4216 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4218 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4219 srelplt2
->contents
);
4220 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4222 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4223 + htab
->elf
.splt
->output_offset
4224 + htab
->lazy_plt
->plt0_got2_offset
);
4225 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4227 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4228 srelplt2
->contents
+
4229 sizeof (Elf32_External_Rel
));
4230 /* Correct the .rel.plt.unloaded relocations. */
4231 p
= srelplt2
->contents
;
4232 if (bfd_link_pic (info
))
4233 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4235 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4237 for (; num_plts
; num_plts
--)
4239 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4240 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4242 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4243 p
+= sizeof (Elf32_External_Rel
);
4245 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4246 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
4248 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4249 p
+= sizeof (Elf32_External_Rel
);
4256 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
4257 elf_section_data (htab
->plt_got
->output_section
)
4258 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4260 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
4261 elf_section_data (htab
->plt_second
->output_section
)
4262 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4265 /* Fill in the first three entries in the global offset table. */
4266 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
4268 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4271 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4275 bfd_put_32 (output_bfd
,
4277 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4278 htab
->elf
.sgotplt
->contents
);
4279 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4280 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4282 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4285 /* Adjust .eh_frame for .plt section. */
4286 if (htab
->plt_eh_frame
!= NULL
4287 && htab
->plt_eh_frame
->contents
!= NULL
)
4289 if (htab
->elf
.splt
!= NULL
4290 && htab
->elf
.splt
->size
!= 0
4291 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4292 && htab
->elf
.splt
->output_section
!= NULL
4293 && htab
->plt_eh_frame
->output_section
!= NULL
)
4295 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4296 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4297 + htab
->plt_eh_frame
->output_offset
4298 + PLT_FDE_START_OFFSET
;
4299 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4300 htab
->plt_eh_frame
->contents
4301 + PLT_FDE_START_OFFSET
);
4303 if (htab
->plt_eh_frame
->sec_info_type
4304 == SEC_INFO_TYPE_EH_FRAME
)
4306 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4308 htab
->plt_eh_frame
->contents
))
4313 /* Adjust .eh_frame for .plt.got section. */
4314 if (htab
->plt_got_eh_frame
!= NULL
4315 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4317 if (htab
->plt_got
!= NULL
4318 && htab
->plt_got
->size
!= 0
4319 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
4320 && htab
->plt_got
->output_section
!= NULL
4321 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
4323 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
4324 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
4325 + htab
->plt_got_eh_frame
->output_offset
4326 + PLT_FDE_START_OFFSET
;
4327 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4328 htab
->plt_got_eh_frame
->contents
4329 + PLT_FDE_START_OFFSET
);
4331 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4333 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4334 htab
->plt_got_eh_frame
,
4335 htab
->plt_got_eh_frame
->contents
))
4340 /* Adjust .eh_frame for the second PLT section. */
4341 if (htab
->plt_second_eh_frame
!= NULL
4342 && htab
->plt_second_eh_frame
->contents
!= NULL
)
4344 if (htab
->plt_second
!= NULL
4345 && htab
->plt_second
->size
!= 0
4346 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
4347 && htab
->plt_second
->output_section
!= NULL
4348 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
4350 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
4351 bfd_vma eh_frame_start
4352 = (htab
->plt_second_eh_frame
->output_section
->vma
4353 + htab
->plt_second_eh_frame
->output_offset
4354 + PLT_FDE_START_OFFSET
);
4355 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4356 htab
->plt_second_eh_frame
->contents
4357 + PLT_FDE_START_OFFSET
);
4359 if (htab
->plt_second_eh_frame
->sec_info_type
4360 == SEC_INFO_TYPE_EH_FRAME
)
4362 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4363 htab
->plt_second_eh_frame
,
4364 htab
->plt_second_eh_frame
->contents
))
4369 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4370 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4372 /* Fill PLT entries for undefined weak symbols in PIE. */
4373 if (bfd_link_pie (info
))
4374 bfd_hash_traverse (&info
->hash
->table
,
4375 elf_i386_pie_finish_undefweak_symbol
,
4381 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4382 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4383 It has to be done before elf_link_sort_relocs is called so that
4384 dynamic relocations are properly sorted. */
4387 elf_i386_output_arch_local_syms
4388 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4389 struct bfd_link_info
*info
,
4390 void *flaginfo ATTRIBUTE_UNUSED
,
4391 int (*func
) (void *, const char *,
4394 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4396 struct elf_x86_link_hash_table
*htab
4397 = elf_x86_hash_table (info
, I386_ELF_DATA
);
4401 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4402 htab_traverse (htab
->loc_hash_table
,
4403 elf_i386_finish_local_dynamic_symbol
,
4409 /* Forward declaration. */
4410 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
;
4412 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4413 dynamic relocations. */
4416 elf_i386_get_synthetic_symtab (bfd
*abfd
,
4417 long symcount ATTRIBUTE_UNUSED
,
4418 asymbol
**syms ATTRIBUTE_UNUSED
,
4425 bfd_byte
*plt_contents
;
4427 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4428 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4429 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4430 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4433 enum elf_x86_plt_type plt_type
;
4434 struct elf_x86_plt plts
[] =
4436 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4437 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4438 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4439 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4444 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4447 if (dynsymcount
<= 0)
4450 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4454 non_lazy_plt
= NULL
;
4455 /* Silence GCC 6. */
4457 non_lazy_ibt_plt
= NULL
;
4458 lazy_ibt_plt
= NULL
;
4459 switch (get_elf_i386_backend_data (abfd
)->os
)
4462 non_lazy_plt
= &elf_i386_non_lazy_plt
;
4463 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4464 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4467 lazy_plt
= &elf_i386_lazy_plt
;
4470 lazy_plt
= &elf_i386_nacl_plt
;
4477 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4479 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4480 if (plt
== NULL
|| plt
->size
== 0)
4483 /* Get the PLT section contents. */
4484 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
4485 if (plt_contents
== NULL
)
4487 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
4488 plt_contents
, 0, plt
->size
))
4490 free (plt_contents
);
4494 /* Check what kind of PLT it is. */
4495 plt_type
= plt_unknown
;
4496 if (plts
[j
].type
== plt_unknown
4497 && (plt
->size
>= (lazy_plt
->plt0_entry_size
4498 + lazy_plt
->plt_entry_size
)))
4500 /* Match lazy PLT first. */
4501 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4502 lazy_plt
->plt0_got1_offset
) == 0)
4504 /* The fist entry in the lazy IBT PLT is the same as the
4506 if (lazy_ibt_plt
!= NULL
4507 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4508 lazy_ibt_plt
->plt_entry
,
4509 lazy_ibt_plt
->plt_got_offset
) == 0))
4510 plt_type
= plt_lazy
| plt_second
;
4512 plt_type
= plt_lazy
;
4514 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
4515 lazy_plt
->plt0_got1_offset
) == 0)
4517 /* The fist entry in the PIC lazy IBT PLT is the same as
4518 the normal PIC lazy PLT. */
4519 if (lazy_ibt_plt
!= NULL
4520 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4521 lazy_ibt_plt
->pic_plt_entry
,
4522 lazy_ibt_plt
->plt_got_offset
) == 0))
4523 plt_type
= plt_lazy
| plt_pic
| plt_second
;
4525 plt_type
= plt_lazy
| plt_pic
;
4529 if (non_lazy_plt
!= NULL
4530 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
4531 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
4533 /* Match non-lazy PLT. */
4534 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
4535 non_lazy_plt
->plt_got_offset
) == 0)
4536 plt_type
= plt_non_lazy
;
4537 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
4538 non_lazy_plt
->plt_got_offset
) == 0)
4542 if ((non_lazy_ibt_plt
!= NULL
)
4543 && (plt_type
== plt_unknown
|| plt_type
== plt_second
)
4544 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
)
4546 if (memcmp (plt_contents
,
4547 non_lazy_ibt_plt
->plt_entry
,
4548 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4550 /* Match IBT PLT. */
4551 plt_type
= plt_second
;
4552 non_lazy_plt
= non_lazy_ibt_plt
;
4554 else if (memcmp (plt_contents
,
4555 non_lazy_ibt_plt
->pic_plt_entry
,
4556 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4558 /* Match PIC IBT PLT. */
4559 plt_type
= plt_second
| plt_pic
;
4560 non_lazy_plt
= non_lazy_ibt_plt
;
4564 if (plt_type
== plt_unknown
)
4566 free (plt_contents
);
4571 plts
[j
].type
= plt_type
;
4573 if ((plt_type
& plt_lazy
))
4575 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
4576 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
4577 /* Skip PLT0 in lazy PLT. */
4582 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
4583 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
4587 /* Skip lazy PLT when the second PLT is used. */
4588 if ((plt_type
& (plt_lazy
| plt_second
))
4589 == (plt_lazy
| plt_second
))
4593 n
= plt
->size
/ plts
[j
].plt_entry_size
;
4598 plts
[j
].contents
= plt_contents
;
4600 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
4601 if ((plt_type
& plt_pic
))
4602 got_addr
= (bfd_vma
) -1;
4605 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
4606 got_addr
, plts
, dynsyms
,
4610 /* Set up i386 GNU properties. Return the first relocatable ELF input
4611 with GNU properties if found. Otherwise, return NULL. */
4614 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
4616 struct elf_x86_init_table init_table
;
4618 init_table
.normal_target
= FALSE
;
4619 init_table
.is_vxworks
= FALSE
;
4620 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
4623 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4624 init_table
.non_lazy_plt
= &elf_i386_non_lazy_plt
;
4625 init_table
.lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4626 init_table
.non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4627 init_table
.normal_target
= TRUE
;
4630 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4631 init_table
.non_lazy_plt
= NULL
;
4632 init_table
.lazy_ibt_plt
= NULL
;
4633 init_table
.non_lazy_ibt_plt
= NULL
;
4634 init_table
.is_vxworks
= TRUE
;
4637 init_table
.lazy_plt
= &elf_i386_nacl_plt
;
4638 init_table
.non_lazy_plt
= NULL
;
4639 init_table
.lazy_ibt_plt
= NULL
;
4640 init_table
.non_lazy_ibt_plt
= NULL
;
4644 init_table
.r_info
= elf32_r_info
;
4645 init_table
.r_sym
= elf32_r_sym
;
4647 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
4650 #define TARGET_LITTLE_SYM i386_elf32_vec
4651 #define TARGET_LITTLE_NAME "elf32-i386"
4652 #define ELF_ARCH bfd_arch_i386
4653 #define ELF_TARGET_ID I386_ELF_DATA
4654 #define ELF_MACHINE_CODE EM_386
4655 #define ELF_MAXPAGESIZE 0x1000
4657 #define elf_backend_can_gc_sections 1
4658 #define elf_backend_can_refcount 1
4659 #define elf_backend_want_got_plt 1
4660 #define elf_backend_plt_readonly 1
4661 #define elf_backend_want_plt_sym 0
4662 #define elf_backend_got_header_size 12
4663 #define elf_backend_plt_alignment 4
4664 #define elf_backend_dtrel_excludes_plt 1
4665 #define elf_backend_extern_protected_data 1
4666 #define elf_backend_caches_rawsize 1
4667 #define elf_backend_want_dynrelro 1
4669 /* Support RELA for objdump of prelink objects. */
4670 #define elf_info_to_howto elf_i386_info_to_howto_rel
4671 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4673 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4674 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4675 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4676 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
4678 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4679 #define elf_backend_check_relocs elf_i386_check_relocs
4680 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
4681 #define elf_backend_fake_sections elf_i386_fake_sections
4682 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4683 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4684 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
4685 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4686 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4687 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4688 #define elf_backend_relocate_section elf_i386_relocate_section
4689 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
4691 #include "elf32-target.h"
4693 /* FreeBSD support. */
4695 #undef TARGET_LITTLE_SYM
4696 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
4697 #undef TARGET_LITTLE_NAME
4698 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4700 #define ELF_OSABI ELFOSABI_FREEBSD
4702 /* The kernel recognizes executables as valid only if they carry a
4703 "FreeBSD" label in the ELF header. So we put this label on all
4704 executables and (for simplicity) also all other object files. */
4707 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4709 _bfd_elf_post_process_headers (abfd
, info
);
4711 #ifdef OLD_FREEBSD_ABI_LABEL
4713 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4714 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
4715 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4720 #undef elf_backend_post_process_headers
4721 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4723 #define elf32_bed elf32_i386_fbsd_bed
4725 #undef elf_backend_add_symbol_hook
4727 #include "elf32-target.h"
4731 #undef TARGET_LITTLE_SYM
4732 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
4733 #undef TARGET_LITTLE_NAME
4734 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
4736 #undef elf_backend_post_process_headers
4738 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4739 objects won't be recognized. */
4743 #define elf32_bed elf32_i386_sol2_bed
4745 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
4747 #undef elf_backend_static_tls_alignment
4748 #define elf_backend_static_tls_alignment 8
4750 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4752 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4754 #undef elf_backend_want_plt_sym
4755 #define elf_backend_want_plt_sym 1
4757 #undef elf_backend_strtab_flags
4758 #define elf_backend_strtab_flags SHF_STRINGS
4760 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
4761 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
4762 FALSE otherwise. ISECTION is the best guess matching section from the
4763 input bfd IBFD, but it might be NULL. */
4766 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
4767 bfd
*obfd ATTRIBUTE_UNUSED
,
4768 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
4769 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
4771 /* PR 19938: FIXME: Need to add code for setting the sh_info
4772 and sh_link fields of Solaris specific section types. */
4775 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
4776 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
4778 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
4780 The following values should be set:
4783 -----------------------------------------------------------------------------
4784 SHT_SUNW_ancillary The section header index of 0
4785 [0x6fffffee] the associated string table.
4787 SHT_SUNW_capinfo The section header index of For a dynamic object, the
4788 [0x6ffffff0] the associated symbol table. section header index of
4790 SHT_SUNW_capchain table,
4793 SHT_SUNW_symsort The section header index of 0
4794 [0x6ffffff1] the associated symbol table.
4796 SHT_SUNW_tlssort The section header index of 0
4797 [0x6ffffff2] the associated symbol table.
4799 SHT_SUNW_LDYNSYM The section header index of One greater than the
4800 [0x6ffffff3] the associated string table. symbol table index of the
4801 This index is the same string last local symbol,
4802 table used by the SHT_DYNSYM STB_LOCAL. Since
4803 section. SHT_SUNW_LDYNSYM only
4804 contains local symbols,
4805 sh_info is equivalent to
4806 the number of symbols in
4809 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
4810 [0x6ffffff5] the section header index of to named strings, the
4811 the associated section header index of
4812 SHT_SUNW_capinfo table, the associated string
4813 otherwise 0. table, otherwise 0.
4815 SHT_SUNW_move The section header index of 0
4816 [0x6ffffffa] the associated symbol table.
4821 SHT_SUNW_syminfo The section header index of The section header index
4822 [0x6ffffffc] the associated symbol table. of the associated
4825 SHT_SUNW_verdef The section header index of The number of version
4826 [0x6ffffffd] the associated string table. definitions within the
4829 SHT_SUNW_verneed The section header index of The number of version
4830 [0x6ffffffe] the associated string table. dependencies within the
4833 SHT_SUNW_versym The section header index of 0
4834 [0x6fffffff] the associated symbol table. */
4837 #undef elf_backend_copy_special_section_fields
4838 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
4840 #include "elf32-target.h"
4842 /* Intel MCU support. */
4845 elf32_iamcu_elf_object_p (bfd
*abfd
)
4847 /* Set the right machine number for an IAMCU elf32 file. */
4848 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
4852 #undef TARGET_LITTLE_SYM
4853 #define TARGET_LITTLE_SYM iamcu_elf32_vec
4854 #undef TARGET_LITTLE_NAME
4855 #define TARGET_LITTLE_NAME "elf32-iamcu"
4857 #define ELF_ARCH bfd_arch_iamcu
4859 #undef ELF_MACHINE_CODE
4860 #define ELF_MACHINE_CODE EM_IAMCU
4865 #define elf32_bed elf32_iamcu_bed
4867 #undef elf_backend_object_p
4868 #define elf_backend_object_p elf32_iamcu_elf_object_p
4870 #undef elf_backend_static_tls_alignment
4872 #undef elf_backend_want_plt_sym
4873 #define elf_backend_want_plt_sym 0
4875 #undef elf_backend_strtab_flags
4876 #undef elf_backend_copy_special_section_fields
4878 #include "elf32-target.h"
4880 /* Restore defaults. */
4882 #define ELF_ARCH bfd_arch_i386
4883 #undef ELF_MACHINE_CODE
4884 #define ELF_MACHINE_CODE EM_386
4886 /* Native Client support. */
4888 #undef TARGET_LITTLE_SYM
4889 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
4890 #undef TARGET_LITTLE_NAME
4891 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
4893 #define elf32_bed elf32_i386_nacl_bed
4895 #undef ELF_MAXPAGESIZE
4896 #define ELF_MAXPAGESIZE 0x10000
4898 /* Restore defaults. */
4900 #undef elf_backend_want_plt_sym
4901 #define elf_backend_want_plt_sym 0
4902 #undef elf_backend_post_process_headers
4903 #undef elf_backend_static_tls_alignment
4905 /* NaCl uses substantially different PLT entries for the same effects. */
4907 #undef elf_backend_plt_alignment
4908 #define elf_backend_plt_alignment 5
4909 #define NACL_PLT_ENTRY_SIZE 64
4910 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
4912 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
4914 0xff, 0x35, /* pushl contents of address */
4915 0, 0, 0, 0, /* replaced with address of .got + 4. */
4916 0x8b, 0x0d, /* movl contents of address, %ecx */
4917 0, 0, 0, 0, /* replaced with address of .got + 8. */
4918 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
4919 0xff, 0xe1 /* jmp *%ecx */
4922 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
4924 0x8b, 0x0d, /* movl contents of address, %ecx */
4925 0, 0, 0, 0, /* replaced with GOT slot address. */
4926 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
4927 0xff, 0xe1, /* jmp *%ecx */
4929 /* Pad to the next 32-byte boundary with nop instructions. */
4931 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4932 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4934 /* Lazy GOT entries point here (32-byte aligned). */
4935 0x68, /* pushl immediate */
4936 0, 0, 0, 0, /* replaced with reloc offset. */
4937 0xe9, /* jmp relative */
4938 0, 0, 0, 0, /* replaced with offset to .plt. */
4940 /* Pad to the next 32-byte boundary with nop instructions. */
4941 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4942 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4946 static const bfd_byte
4947 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
4949 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
4950 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
4951 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
4952 0xff, 0xe1, /* jmp *%ecx */
4954 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
4955 so pad to that size with nop instructions. */
4956 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
4959 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
4961 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
4962 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
4963 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
4964 0xff, 0xe1, /* jmp *%ecx */
4966 /* Pad to the next 32-byte boundary with nop instructions. */
4968 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4969 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4971 /* Lazy GOT entries point here (32-byte aligned). */
4972 0x68, /* pushl immediate */
4973 0, 0, 0, 0, /* replaced with offset into relocation table. */
4974 0xe9, /* jmp relative */
4975 0, 0, 0, 0, /* replaced with offset to start of .plt. */
4977 /* Pad to the next 32-byte boundary with nop instructions. */
4978 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4979 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4983 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
4985 #if (PLT_CIE_LENGTH != 20 \
4986 || PLT_FDE_LENGTH != 36 \
4987 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
4988 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
4989 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
4991 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
4992 0, 0, 0, 0, /* CIE ID */
4993 1, /* CIE version */
4994 'z', 'R', 0, /* Augmentation string */
4995 1, /* Code alignment factor */
4996 0x7c, /* Data alignment factor: -4 */
4997 8, /* Return address column */
4998 1, /* Augmentation size */
4999 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5000 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5001 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5002 DW_CFA_nop
, DW_CFA_nop
,
5004 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5005 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
5006 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5007 0, 0, 0, 0, /* .plt size goes here */
5008 0, /* Augmentation size */
5009 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
5010 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5011 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
5012 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5013 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5014 13, /* Block length */
5015 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
5016 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
5017 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5018 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
5019 DW_CFA_nop
, DW_CFA_nop
5022 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
=
5024 elf_i386_nacl_plt0_entry
, /* plt0_entry */
5025 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
5026 elf_i386_nacl_plt_entry
, /* plt_entry */
5027 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5028 2, /* plt0_got1_offset */
5029 8, /* plt0_got2_offset */
5030 0, /* plt0_got2_insn_end */
5031 2, /* plt_got_offset */
5032 33, /* plt_reloc_offset */
5033 38, /* plt_plt_offset */
5034 0, /* plt_got_insn_size */
5035 0, /* plt_plt_insn_end */
5036 32, /* plt_lazy_offset */
5037 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
5038 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
5039 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
5040 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
5043 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
5045 0x90, /* plt0_pad_byte: nop insn */
5050 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
5052 /* Set the right machine number for a NaCl i386 ELF32 file. */
5053 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
5057 #undef elf_backend_arch_data
5058 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
5060 #undef elf_backend_object_p
5061 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
5062 #undef elf_backend_modify_segment_map
5063 #define elf_backend_modify_segment_map nacl_modify_segment_map
5064 #undef elf_backend_modify_program_headers
5065 #define elf_backend_modify_program_headers nacl_modify_program_headers
5066 #undef elf_backend_final_write_processing
5067 #define elf_backend_final_write_processing nacl_final_write_processing
5069 #include "elf32-target.h"
5071 /* Restore defaults. */
5072 #undef elf_backend_object_p
5073 #undef elf_backend_modify_segment_map
5074 #undef elf_backend_modify_program_headers
5075 #undef elf_backend_final_write_processing
5077 /* VxWorks support. */
5079 #undef TARGET_LITTLE_SYM
5080 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
5081 #undef TARGET_LITTLE_NAME
5082 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
5084 #undef ELF_MAXPAGESIZE
5085 #define ELF_MAXPAGESIZE 0x1000
5086 #undef elf_backend_plt_alignment
5087 #define elf_backend_plt_alignment 4
5089 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
5091 0x90, /* plt0_pad_byte */
5095 #undef elf_backend_arch_data
5096 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
5098 #undef elf_backend_relocs_compatible
5099 #undef elf_backend_add_symbol_hook
5100 #define elf_backend_add_symbol_hook \
5101 elf_vxworks_add_symbol_hook
5102 #undef elf_backend_link_output_symbol_hook
5103 #define elf_backend_link_output_symbol_hook \
5104 elf_vxworks_link_output_symbol_hook
5105 #undef elf_backend_emit_relocs
5106 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5107 #undef elf_backend_final_write_processing
5108 #define elf_backend_final_write_processing \
5109 elf_vxworks_final_write_processing
5110 #undef elf_backend_static_tls_alignment
5112 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5114 #undef elf_backend_want_plt_sym
5115 #define elf_backend_want_plt_sym 1
5118 #define elf32_bed elf32_i386_vxworks_bed
5120 #include "elf32-target.h"