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 #define X86_PCREL_TYPE_P(TYPE) ((TYPE) == R_386_PC32)
187 #define X86_SIZE_TYPE_P(TYPE) ((TYPE) == R_386_SIZE32)
189 #ifdef DEBUG_GEN_RELOC
191 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
196 static reloc_howto_type
*
197 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
198 bfd_reloc_code_real_type code
)
203 TRACE ("BFD_RELOC_NONE");
204 return &elf_howto_table
[R_386_NONE
];
207 TRACE ("BFD_RELOC_32");
208 return &elf_howto_table
[R_386_32
];
211 TRACE ("BFD_RELOC_CTOR");
212 return &elf_howto_table
[R_386_32
];
214 case BFD_RELOC_32_PCREL
:
215 TRACE ("BFD_RELOC_PC32");
216 return &elf_howto_table
[R_386_PC32
];
218 case BFD_RELOC_386_GOT32
:
219 TRACE ("BFD_RELOC_386_GOT32");
220 return &elf_howto_table
[R_386_GOT32
];
222 case BFD_RELOC_386_PLT32
:
223 TRACE ("BFD_RELOC_386_PLT32");
224 return &elf_howto_table
[R_386_PLT32
];
226 case BFD_RELOC_386_COPY
:
227 TRACE ("BFD_RELOC_386_COPY");
228 return &elf_howto_table
[R_386_COPY
];
230 case BFD_RELOC_386_GLOB_DAT
:
231 TRACE ("BFD_RELOC_386_GLOB_DAT");
232 return &elf_howto_table
[R_386_GLOB_DAT
];
234 case BFD_RELOC_386_JUMP_SLOT
:
235 TRACE ("BFD_RELOC_386_JUMP_SLOT");
236 return &elf_howto_table
[R_386_JUMP_SLOT
];
238 case BFD_RELOC_386_RELATIVE
:
239 TRACE ("BFD_RELOC_386_RELATIVE");
240 return &elf_howto_table
[R_386_RELATIVE
];
242 case BFD_RELOC_386_GOTOFF
:
243 TRACE ("BFD_RELOC_386_GOTOFF");
244 return &elf_howto_table
[R_386_GOTOFF
];
246 case BFD_RELOC_386_GOTPC
:
247 TRACE ("BFD_RELOC_386_GOTPC");
248 return &elf_howto_table
[R_386_GOTPC
];
250 /* These relocs are a GNU extension. */
251 case BFD_RELOC_386_TLS_TPOFF
:
252 TRACE ("BFD_RELOC_386_TLS_TPOFF");
253 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
255 case BFD_RELOC_386_TLS_IE
:
256 TRACE ("BFD_RELOC_386_TLS_IE");
257 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
259 case BFD_RELOC_386_TLS_GOTIE
:
260 TRACE ("BFD_RELOC_386_TLS_GOTIE");
261 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
263 case BFD_RELOC_386_TLS_LE
:
264 TRACE ("BFD_RELOC_386_TLS_LE");
265 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
267 case BFD_RELOC_386_TLS_GD
:
268 TRACE ("BFD_RELOC_386_TLS_GD");
269 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
271 case BFD_RELOC_386_TLS_LDM
:
272 TRACE ("BFD_RELOC_386_TLS_LDM");
273 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
276 TRACE ("BFD_RELOC_16");
277 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
279 case BFD_RELOC_16_PCREL
:
280 TRACE ("BFD_RELOC_16_PCREL");
281 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
284 TRACE ("BFD_RELOC_8");
285 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
287 case BFD_RELOC_8_PCREL
:
288 TRACE ("BFD_RELOC_8_PCREL");
289 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
291 /* Common with Sun TLS implementation. */
292 case BFD_RELOC_386_TLS_LDO_32
:
293 TRACE ("BFD_RELOC_386_TLS_LDO_32");
294 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
296 case BFD_RELOC_386_TLS_IE_32
:
297 TRACE ("BFD_RELOC_386_TLS_IE_32");
298 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
300 case BFD_RELOC_386_TLS_LE_32
:
301 TRACE ("BFD_RELOC_386_TLS_LE_32");
302 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
304 case BFD_RELOC_386_TLS_DTPMOD32
:
305 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
306 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
308 case BFD_RELOC_386_TLS_DTPOFF32
:
309 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
310 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
312 case BFD_RELOC_386_TLS_TPOFF32
:
313 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
314 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
316 case BFD_RELOC_SIZE32
:
317 TRACE ("BFD_RELOC_SIZE32");
318 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
320 case BFD_RELOC_386_TLS_GOTDESC
:
321 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
322 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
324 case BFD_RELOC_386_TLS_DESC_CALL
:
325 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
326 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
328 case BFD_RELOC_386_TLS_DESC
:
329 TRACE ("BFD_RELOC_386_TLS_DESC");
330 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
332 case BFD_RELOC_386_IRELATIVE
:
333 TRACE ("BFD_RELOC_386_IRELATIVE");
334 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
336 case BFD_RELOC_386_GOT32X
:
337 TRACE ("BFD_RELOC_386_GOT32X");
338 return &elf_howto_table
[R_386_GOT32X
- R_386_tls_offset
];
340 case BFD_RELOC_VTABLE_INHERIT
:
341 TRACE ("BFD_RELOC_VTABLE_INHERIT");
342 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
344 case BFD_RELOC_VTABLE_ENTRY
:
345 TRACE ("BFD_RELOC_VTABLE_ENTRY");
346 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
356 static reloc_howto_type
*
357 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
362 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
363 if (elf_howto_table
[i
].name
!= NULL
364 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
365 return &elf_howto_table
[i
];
370 static reloc_howto_type
*
371 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
375 if ((indx
= r_type
) >= R_386_standard
376 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
377 >= R_386_ext
- R_386_standard
)
378 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
379 >= R_386_ext2
- R_386_ext
)
380 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
381 >= R_386_vt
- R_386_ext2
))
383 /* xgettext:c-format */
384 _bfd_error_handler (_("%B: invalid relocation type %d"),
388 /* PR 17512: file: 0f67f69d. */
389 if (elf_howto_table
[indx
].type
!= r_type
)
391 return &elf_howto_table
[indx
];
395 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
397 Elf_Internal_Rela
*dst
)
399 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
400 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
403 /* Return whether a symbol name implies a local label. The UnixWare
404 2.1 cc generates temporary symbols that start with .X, so we
405 recognize them here. FIXME: do other SVR4 compilers also use .X?.
406 If so, we should move the .X recognition into
407 _bfd_elf_is_local_label_name. */
410 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
412 if (name
[0] == '.' && name
[1] == 'X')
415 return _bfd_elf_is_local_label_name (abfd
, name
);
418 /* Support for core dump NOTE sections. */
421 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
426 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
428 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
434 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
437 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
441 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
445 switch (note
->descsz
)
450 case 144: /* Linux/i386 */
452 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
455 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
465 /* Make a ".reg/999" section. */
466 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
467 size
, note
->descpos
+ offset
);
471 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
473 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
475 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
480 elf_tdata (abfd
)->core
->program
481 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
482 elf_tdata (abfd
)->core
->command
483 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
487 switch (note
->descsz
)
492 case 124: /* Linux/i386 elf_prpsinfo. */
493 elf_tdata (abfd
)->core
->pid
494 = bfd_get_32 (abfd
, note
->descdata
+ 12);
495 elf_tdata (abfd
)->core
->program
496 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
497 elf_tdata (abfd
)->core
->command
498 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
502 /* Note that for some reason, a spurious space is tacked
503 onto the end of the args in some (at least one anyway)
504 implementations, so strip it off if it exists. */
506 char *command
= elf_tdata (abfd
)->core
->command
;
507 int n
= strlen (command
);
509 if (0 < n
&& command
[n
- 1] == ' ')
510 command
[n
- 1] = '\0';
516 /* Functions for the i386 ELF linker.
518 In order to gain some understanding of code in this file without
519 knowing all the intricate details of the linker, note the
522 Functions named elf_i386_* are called by external routines, other
523 functions are only called locally. elf_i386_* functions appear
524 in this file more or less in the order in which they are called
525 from external routines. eg. elf_i386_check_relocs is called
526 early in the link process, elf_i386_finish_dynamic_sections is
527 one of the last functions. */
529 /* The size in bytes of an entry in the lazy procedure linkage table. */
531 #define LAZY_PLT_ENTRY_SIZE 16
533 /* The size in bytes of an entry in the non-lazy procedure linkage
536 #define NON_LAZY_PLT_ENTRY_SIZE 8
538 /* The first entry in an absolute lazy procedure linkage table looks
539 like this. See the SVR4 ABI i386 supplement to see how this works.
540 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
542 static const bfd_byte elf_i386_lazy_plt0_entry
[12] =
544 0xff, 0x35, /* pushl contents of address */
545 0, 0, 0, 0, /* replaced with address of .got + 4. */
546 0xff, 0x25, /* jmp indirect */
547 0, 0, 0, 0 /* replaced with address of .got + 8. */
550 /* Subsequent entries in an absolute lazy procedure linkage table look
553 static const bfd_byte elf_i386_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
555 0xff, 0x25, /* jmp indirect */
556 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
557 0x68, /* pushl immediate */
558 0, 0, 0, 0, /* replaced with offset into relocation table. */
559 0xe9, /* jmp relative */
560 0, 0, 0, 0 /* replaced with offset to start of .plt. */
563 /* The first entry in a PIC lazy procedure linkage table look like
564 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
565 lazy_plt->plt0_pad_byte. */
567 static const bfd_byte elf_i386_pic_lazy_plt0_entry
[12] =
569 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
570 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
573 /* Subsequent entries in a PIC lazy procedure linkage table look like
576 static const bfd_byte elf_i386_pic_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
578 0xff, 0xa3, /* jmp *offset(%ebx) */
579 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
580 0x68, /* pushl immediate */
581 0, 0, 0, 0, /* replaced with offset into relocation table. */
582 0xe9, /* jmp relative */
583 0, 0, 0, 0 /* replaced with offset to start of .plt. */
586 /* Entries in the non-lazy procedure linkage table look like this. */
588 static const bfd_byte elf_i386_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
590 0xff, 0x25, /* jmp indirect */
591 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
592 0x66, 0x90 /* xchg %ax,%ax */
595 /* Entries in the PIC non-lazy procedure linkage table look like
598 static const bfd_byte elf_i386_pic_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
600 0xff, 0xa3, /* jmp *offset(%ebx) */
601 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
602 0x66, 0x90 /* xchg %ax,%ax */
605 /* The first entry in an absolute IBT-enabled lazy procedure linkage
606 table looks like this. */
608 static const bfd_byte elf_i386_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
610 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
611 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
612 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
615 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
616 table look like this. Subsequent entries for a PIC IBT-enabled lazy
617 procedure linkage table are the same. */
619 static const bfd_byte elf_i386_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
621 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
622 0x68, 0, 0, 0, 0, /* pushl immediate */
623 0xe9, 0, 0, 0, 0, /* jmp relative */
624 0x66, 0x90 /* xchg %ax,%ax */
627 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
630 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
632 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
633 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
634 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
637 /* Entries for branches with IBT-enabled in the absolute non-lazey
638 procedure linkage table look like this. They have the same size
639 as the lazy PLT entry. */
641 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
643 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
644 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
645 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
648 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
649 linkage table look like this. They have the same size as the lazy
652 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
654 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
655 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
656 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
659 /* .eh_frame covering the lazy .plt section. */
661 static const bfd_byte elf_i386_eh_frame_lazy_plt
[] =
663 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
664 0, 0, 0, 0, /* CIE ID */
666 'z', 'R', 0, /* Augmentation string */
667 1, /* Code alignment factor */
668 0x7c, /* Data alignment factor */
669 8, /* Return address column */
670 1, /* Augmentation size */
671 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
672 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
673 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
674 DW_CFA_nop
, DW_CFA_nop
,
676 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
677 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
678 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
679 0, 0, 0, 0, /* .plt size goes here */
680 0, /* Augmentation size */
681 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
682 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
683 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
684 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
685 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
686 11, /* Block length */
687 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
688 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
689 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
690 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
691 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
694 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
696 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt
[] =
698 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
699 0, 0, 0, 0, /* CIE ID */
701 'z', 'R', 0, /* Augmentation string */
702 1, /* Code alignment factor */
703 0x7c, /* Data alignment factor */
704 8, /* Return address column */
705 1, /* Augmentation size */
706 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
707 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
708 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
709 DW_CFA_nop
, DW_CFA_nop
,
711 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
712 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
713 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
714 0, 0, 0, 0, /* .plt size goes here */
715 0, /* Augmentation size */
716 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
717 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
718 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
719 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
720 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
721 11, /* Block length */
722 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
723 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
724 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
725 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
726 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
729 /* .eh_frame covering the non-lazy .plt section. */
731 static const bfd_byte elf_i386_eh_frame_non_lazy_plt
[] =
733 #define PLT_GOT_FDE_LENGTH 16
734 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
735 0, 0, 0, 0, /* CIE ID */
737 'z', 'R', 0, /* Augmentation string */
738 1, /* Code alignment factor */
739 0x7c, /* Data alignment factor */
740 8, /* Return address column */
741 1, /* Augmentation size */
742 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
743 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
744 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
745 DW_CFA_nop
, DW_CFA_nop
,
747 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
748 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
749 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
750 0, 0, 0, 0, /* non-lazy .plt size goes here */
751 0, /* Augmentation size */
752 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
755 /* These are the standard parameters. */
756 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt
=
758 elf_i386_lazy_plt0_entry
, /* plt0_entry */
759 sizeof (elf_i386_lazy_plt0_entry
), /* plt0_entry_size */
760 elf_i386_lazy_plt_entry
, /* plt_entry */
761 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
762 2, /* plt0_got1_offset */
763 8, /* plt0_got2_offset */
764 0, /* plt0_got2_insn_end */
765 2, /* plt_got_offset */
766 7, /* plt_reloc_offset */
767 12, /* plt_plt_offset */
768 0, /* plt_got_insn_size */
769 0, /* plt_plt_insn_end */
770 6, /* plt_lazy_offset */
771 elf_i386_pic_lazy_plt0_entry
, /* pic_plt0_entry */
772 elf_i386_pic_lazy_plt_entry
, /* pic_plt_entry */
773 elf_i386_eh_frame_lazy_plt
, /* eh_frame_plt */
774 sizeof (elf_i386_eh_frame_lazy_plt
) /* eh_frame_plt_size */
777 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt
=
779 elf_i386_non_lazy_plt_entry
, /* plt_entry */
780 elf_i386_pic_non_lazy_plt_entry
, /* pic_plt_entry */
781 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
782 2, /* plt_got_offset */
783 0, /* plt_got_insn_size */
784 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
785 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
788 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt
=
790 elf_i386_lazy_ibt_plt0_entry
, /* plt0_entry */
791 sizeof (elf_i386_lazy_ibt_plt0_entry
), /* plt0_entry_size */
792 elf_i386_lazy_ibt_plt_entry
, /* plt_entry */
793 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
794 2, /* plt0_got1_offset */
795 8, /* plt0_got2_offset */
796 0, /* plt0_got2_insn_end */
797 4+2, /* plt_got_offset */
798 4+1, /* plt_reloc_offset */
799 4+6, /* plt_plt_offset */
800 0, /* plt_got_insn_size */
801 0, /* plt_plt_insn_end */
802 0, /* plt_lazy_offset */
803 elf_i386_pic_lazy_ibt_plt0_entry
, /* pic_plt0_entry */
804 elf_i386_lazy_ibt_plt_entry
, /* pic_plt_entry */
805 elf_i386_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
806 sizeof (elf_i386_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
809 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt
=
811 elf_i386_non_lazy_ibt_plt_entry
, /* plt_entry */
812 elf_i386_pic_non_lazy_ibt_plt_entry
,/* pic_plt_entry */
813 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
814 4+2, /* plt_got_offset */
815 0, /* plt_got_insn_size */
816 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
817 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
821 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
822 for the PLTResolve stub and then for each PLT entry. */
823 #define PLTRESOLVE_RELOCS_SHLIB 0
824 #define PLTRESOLVE_RELOCS 2
825 #define PLT_NON_JUMP_SLOT_RELOCS 2
827 /* Architecture-specific backend data for i386. */
829 struct elf_i386_backend_data
831 /* Value used to fill the unused bytes of the first PLT entry. */
832 bfd_byte plt0_pad_byte
;
843 #define get_elf_i386_backend_data(abfd) \
844 ((const struct elf_i386_backend_data *) \
845 get_elf_backend_data (abfd)->arch_data)
847 /* These are the standard parameters. */
848 static const struct elf_i386_backend_data elf_i386_arch_bed
=
850 0, /* plt0_pad_byte */
854 #define elf_backend_arch_data &elf_i386_arch_bed
856 /* Return TRUE if the TLS access code sequence support transition
860 elf_i386_check_tls_transition (asection
*sec
,
862 Elf_Internal_Shdr
*symtab_hdr
,
863 struct elf_link_hash_entry
**sym_hashes
,
865 const Elf_Internal_Rela
*rel
,
866 const Elf_Internal_Rela
*relend
)
868 unsigned int val
, type
, reg
;
869 unsigned long r_symndx
;
870 struct elf_link_hash_entry
*h
;
873 bfd_boolean indirect_call
;
875 offset
= rel
->r_offset
;
880 if (offset
< 2 || (rel
+ 1) >= relend
)
883 indirect_call
= FALSE
;
884 call
= contents
+ offset
+ 4;
887 if (r_type
== R_386_TLS_GD
)
889 /* Check transition from GD access model. Only
890 leal foo@tlsgd(,%ebx,1), %eax
891 call ___tls_get_addr@PLT
893 leal foo@tlsgd(%ebx) %eax
894 call ___tls_get_addr@PLT
897 leal foo@tlsgd(%reg), %eax
898 call *___tls_get_addr@GOT(%reg)
899 which may be converted to
900 addr32 call ___tls_get_addr
901 can transit to different access model. */
902 if ((offset
+ 10) > sec
->size
903 || (type
!= 0x8d && type
!= 0x04))
908 /* leal foo@tlsgd(,%ebx,1), %eax
909 call ___tls_get_addr@PLT */
913 if (*(call
- 7) != 0x8d
921 leal foo@tlsgd(%ebx), %eax
922 call ___tls_get_addr@PLT
925 leal foo@tlsgd(%reg), %eax
926 call *___tls_get_addr@GOT(%reg)
927 which may be converted to
928 addr32 call ___tls_get_addr
930 %eax can't be used as the GOT base register since it
931 is used to pass parameter to ___tls_get_addr. */
933 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
936 indirect_call
= call
[0] == 0xff;
937 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
938 && !(call
[0] == 0x67 && call
[1] == 0xe8)
940 && (call
[1] & 0xf8) == 0x90
941 && (call
[1] & 0x7) == reg
))
947 /* Check transition from LD access model. Only
948 leal foo@tlsldm(%ebx), %eax
949 call ___tls_get_addr@PLT
951 leal foo@tlsldm(%reg), %eax
952 call *___tls_get_addr@GOT(%reg)
953 which may be converted to
954 addr32 call ___tls_get_addr
955 can transit to different access model. */
956 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
959 /* %eax can't be used as the GOT base register since it is
960 used to pass parameter to ___tls_get_addr. */
962 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
965 indirect_call
= call
[0] == 0xff;
966 if (!(reg
== 3 && call
[0] == 0xe8)
967 && !(call
[0] == 0x67 && call
[1] == 0xe8)
969 && (call
[1] & 0xf8) == 0x90
970 && (call
[1] & 0x7) == reg
))
974 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
975 if (r_symndx
< symtab_hdr
->sh_info
)
978 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
980 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
982 else if (indirect_call
)
983 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
985 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
986 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
989 /* Check transition from IE access model:
990 movl foo@indntpoff(%rip), %eax
991 movl foo@indntpoff(%rip), %reg
992 addl foo@indntpoff(%rip), %reg
995 if (offset
< 1 || (offset
+ 4) > sec
->size
)
998 /* Check "movl foo@tpoff(%rip), %eax" first. */
999 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1006 /* Check movl|addl foo@tpoff(%rip), %reg. */
1007 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1008 return ((type
== 0x8b || type
== 0x03)
1009 && (val
& 0xc7) == 0x05);
1011 case R_386_TLS_GOTIE
:
1012 case R_386_TLS_IE_32
:
1013 /* Check transition from {IE_32,GOTIE} access model:
1014 subl foo@{tpoff,gontoff}(%reg1), %reg2
1015 movl foo@{tpoff,gontoff}(%reg1), %reg2
1016 addl foo@{tpoff,gontoff}(%reg1), %reg2
1019 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1022 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1023 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1026 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1027 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1029 case R_386_TLS_GOTDESC
:
1030 /* Check transition from GDesc access model:
1031 leal x@tlsdesc(%ebx), %eax
1033 Make sure it's a leal adding ebx to a 32-bit offset
1034 into any register, although it's probably almost always
1037 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1040 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1043 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1044 return (val
& 0xc7) == 0x83;
1046 case R_386_TLS_DESC_CALL
:
1047 /* Check transition from GDesc access model:
1048 call *x@tlsdesc(%eax)
1050 if (offset
+ 2 <= sec
->size
)
1052 /* Make sure that it's a call *x@tlsdesc(%eax). */
1053 call
= contents
+ offset
;
1054 return call
[0] == 0xff && call
[1] == 0x10;
1064 /* Return TRUE if the TLS access transition is OK or no transition
1065 will be performed. Update R_TYPE if there is a transition. */
1068 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1069 asection
*sec
, bfd_byte
*contents
,
1070 Elf_Internal_Shdr
*symtab_hdr
,
1071 struct elf_link_hash_entry
**sym_hashes
,
1072 unsigned int *r_type
, int tls_type
,
1073 const Elf_Internal_Rela
*rel
,
1074 const Elf_Internal_Rela
*relend
,
1075 struct elf_link_hash_entry
*h
,
1076 unsigned long r_symndx
,
1077 bfd_boolean from_relocate_section
)
1079 unsigned int from_type
= *r_type
;
1080 unsigned int to_type
= from_type
;
1081 bfd_boolean check
= TRUE
;
1083 /* Skip TLS transition for functions. */
1085 && (h
->type
== STT_FUNC
1086 || h
->type
== STT_GNU_IFUNC
))
1092 case R_386_TLS_GOTDESC
:
1093 case R_386_TLS_DESC_CALL
:
1094 case R_386_TLS_IE_32
:
1096 case R_386_TLS_GOTIE
:
1097 if (bfd_link_executable (info
))
1100 to_type
= R_386_TLS_LE_32
;
1101 else if (from_type
!= R_386_TLS_IE
1102 && from_type
!= R_386_TLS_GOTIE
)
1103 to_type
= R_386_TLS_IE_32
;
1106 /* When we are called from elf_i386_relocate_section, there may
1107 be additional transitions based on TLS_TYPE. */
1108 if (from_relocate_section
)
1110 unsigned int new_to_type
= to_type
;
1112 if (TLS_TRANSITION_IE_TO_LE_P (info
, h
, tls_type
))
1113 new_to_type
= R_386_TLS_LE_32
;
1115 if (to_type
== R_386_TLS_GD
1116 || to_type
== R_386_TLS_GOTDESC
1117 || to_type
== R_386_TLS_DESC_CALL
)
1119 if (tls_type
== GOT_TLS_IE_POS
)
1120 new_to_type
= R_386_TLS_GOTIE
;
1121 else if (tls_type
& GOT_TLS_IE
)
1122 new_to_type
= R_386_TLS_IE_32
;
1125 /* We checked the transition before when we were called from
1126 elf_i386_check_relocs. We only want to check the new
1127 transition which hasn't been checked before. */
1128 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1129 to_type
= new_to_type
;
1135 if (bfd_link_executable (info
))
1136 to_type
= R_386_TLS_LE_32
;
1143 /* Return TRUE if there is no transition. */
1144 if (from_type
== to_type
)
1147 /* Check if the transition can be performed. */
1149 && ! elf_i386_check_tls_transition (sec
, contents
,
1150 symtab_hdr
, sym_hashes
,
1151 from_type
, rel
, relend
))
1153 reloc_howto_type
*from
, *to
;
1156 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1157 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1160 name
= h
->root
.root
.string
;
1163 struct elf_x86_link_hash_table
*htab
;
1165 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1170 Elf_Internal_Sym
*isym
;
1172 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1174 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1179 /* xgettext:c-format */
1180 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1181 "in section `%A' failed"),
1182 abfd
, from
->name
, to
->name
, name
,
1183 rel
->r_offset
, sec
);
1184 bfd_set_error (bfd_error_bad_value
);
1192 /* With the local symbol, foo, we convert
1193 mov foo@GOT[(%reg1)], %reg2
1195 lea foo[@GOTOFF(%reg1)], %reg2
1197 call/jmp *foo@GOT[(%reg)]
1199 nop call foo/jmp foo nop
1200 When PIC is false, convert
1201 test %reg1, foo@GOT[(%reg2)]
1205 binop foo@GOT[(%reg1)], %reg2
1208 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1213 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1215 unsigned int *r_type_p
,
1216 Elf_Internal_Rela
*irel
,
1217 struct elf_link_hash_entry
*h
,
1218 bfd_boolean
*converted
,
1219 struct bfd_link_info
*link_info
)
1221 struct elf_x86_link_hash_table
*htab
;
1222 unsigned int opcode
;
1224 bfd_boolean baseless
;
1225 Elf_Internal_Sym
*isym
;
1226 unsigned int addend
;
1230 bfd_boolean to_reloc_32
;
1231 unsigned int r_type
;
1232 unsigned int r_symndx
;
1233 bfd_vma roff
= irel
->r_offset
;
1234 bfd_boolean local_ref
;
1235 struct elf_x86_link_hash_entry
*eh
;
1240 /* Addend for R_386_GOT32X relocations must be 0. */
1241 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1245 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
1246 is_pic
= bfd_link_pic (link_info
);
1249 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1251 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1252 baseless
= (modrm
& 0xc7) == 0x5;
1254 if (baseless
&& is_pic
)
1256 /* For PIC, disallow R_386_GOT32X without a base register
1257 since we don't know what the GOT base is. */
1262 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1264 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1267 name
= h
->root
.root
.string
;
1270 /* xgettext:c-format */
1271 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1272 " register can not be used when making a shared object"),
1277 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1279 /* Convert to R_386_32 if PIC is false or there is no base
1281 to_reloc_32
= !is_pic
|| baseless
;
1283 eh
= elf_x86_hash_entry (h
);
1285 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1289 if (opcode
== 0x0ff)
1290 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1291 goto convert_branch
;
1293 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1294 "test %reg1, foo@GOT(%reg2)" and
1295 "binop foo@GOT[(%reg1)], %reg2". */
1299 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1300 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1302 /* Undefined weak symbol is only bound locally in executable
1303 and its reference is resolved as 0. */
1304 if (h
->root
.type
== bfd_link_hash_undefweak
1310 /* No direct branch to 0 for PIC. */
1314 goto convert_branch
;
1318 /* We can convert load of address 0 to R_386_32. */
1326 /* We have "call/jmp *foo@GOT[(%reg)]". */
1327 if ((h
->root
.type
== bfd_link_hash_defined
1328 || h
->root
.type
== bfd_link_hash_defweak
)
1331 /* The function is locally defined. */
1333 /* Convert R_386_GOT32X to R_386_PC32. */
1334 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1336 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1339 /* To support TLS optimization, always use addr32 prefix
1340 for "call *___tls_get_addr@GOT(%reg)". */
1341 if (eh
&& eh
->tls_get_addr
)
1344 nop_offset
= irel
->r_offset
- 2;
1348 nop
= link_info
->call_nop_byte
;
1349 if (link_info
->call_nop_as_suffix
)
1351 nop_offset
= roff
+ 3;
1352 irel
->r_offset
-= 1;
1355 nop_offset
= roff
- 2;
1360 /* Convert to "jmp foo nop". */
1363 nop_offset
= roff
+ 3;
1364 irel
->r_offset
-= 1;
1367 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1368 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1369 /* When converting to PC-relative relocation, we
1370 need to adjust addend by -4. */
1371 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1372 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1373 *r_type_p
= R_386_PC32
;
1379 /* We have "mov foo@GOT[(%re1g)], %reg2",
1380 "test %reg1, foo@GOT(%reg2)" and
1381 "binop foo@GOT[(%reg1)], %reg2".
1383 Avoid optimizing _DYNAMIC since ld.so may use its
1384 link-time address. */
1385 if (h
== htab
->elf
.hdynamic
)
1388 /* def_regular is set by an assignment in a linker script in
1389 bfd_elf_record_link_assignment. start_stop is set on
1390 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1394 || h
->root
.type
== bfd_link_hash_defined
1395 || h
->root
.type
== bfd_link_hash_defweak
)
1403 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1404 "mov $foo, %reg2" with R_386_32. */
1406 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1407 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1412 /* Convert "mov foo@GOT(%reg1), %reg2" to
1413 "lea foo@GOTOFF(%reg1), %reg2". */
1414 r_type
= R_386_GOTOFF
;
1420 /* Only R_386_32 is supported. */
1426 /* Convert "test %reg1, foo@GOT(%reg2)" to
1427 "test $foo, %reg1". */
1428 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1433 /* Convert "binop foo@GOT(%reg1), %reg2" to
1434 "binop $foo, %reg2". */
1436 | (modrm
& 0x38) >> 3
1440 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1444 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1445 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1454 /* Rename some of the generic section flags to better document how they
1456 #define check_relocs_failed sec_flg0
1458 /* Look through the relocs for a section during the first phase, and
1459 calculate needed space in the global offset table, procedure linkage
1460 table, and dynamic reloc sections. */
1463 elf_i386_check_relocs (bfd
*abfd
,
1464 struct bfd_link_info
*info
,
1466 const Elf_Internal_Rela
*relocs
)
1468 struct elf_x86_link_hash_table
*htab
;
1469 Elf_Internal_Shdr
*symtab_hdr
;
1470 struct elf_link_hash_entry
**sym_hashes
;
1471 const Elf_Internal_Rela
*rel
;
1472 const Elf_Internal_Rela
*rel_end
;
1475 bfd_boolean converted
;
1477 if (bfd_link_relocatable (info
))
1480 /* Don't do anything special with non-loaded, non-alloced sections.
1481 In particular, any relocs in such sections should not affect GOT
1482 and PLT reference counting (ie. we don't allow them to create GOT
1483 or PLT entries), there's no possibility or desire to optimize TLS
1484 relocs, and there's not much point in propagating relocs to shared
1485 libs that the dynamic linker won't relocate. */
1486 if ((sec
->flags
& SEC_ALLOC
) == 0)
1489 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1492 sec
->check_relocs_failed
= 1;
1496 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1498 /* Get the section contents. */
1499 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1500 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1501 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1503 sec
->check_relocs_failed
= 1;
1507 symtab_hdr
= &elf_symtab_hdr (abfd
);
1508 sym_hashes
= elf_sym_hashes (abfd
);
1514 rel_end
= relocs
+ sec
->reloc_count
;
1515 for (rel
= relocs
; rel
< rel_end
; rel
++)
1517 unsigned int r_type
;
1518 unsigned int r_symndx
;
1519 struct elf_link_hash_entry
*h
;
1520 struct elf_x86_link_hash_entry
*eh
;
1521 Elf_Internal_Sym
*isym
;
1523 bfd_boolean size_reloc
;
1525 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1526 r_type
= ELF32_R_TYPE (rel
->r_info
);
1528 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1530 /* xgettext:c-format */
1531 _bfd_error_handler (_("%B: bad symbol index: %d"),
1536 if (r_symndx
< symtab_hdr
->sh_info
)
1538 /* A local symbol. */
1539 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1544 /* Check relocation against local STT_GNU_IFUNC symbol. */
1545 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1547 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1551 /* Fake a STT_GNU_IFUNC symbol. */
1552 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1554 h
->type
= STT_GNU_IFUNC
;
1557 h
->forced_local
= 1;
1558 h
->root
.type
= bfd_link_hash_defined
;
1566 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1567 while (h
->root
.type
== bfd_link_hash_indirect
1568 || h
->root
.type
== bfd_link_hash_warning
)
1569 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1572 eh
= (struct elf_x86_link_hash_entry
*) h
;
1575 if (r_type
== R_386_GOTOFF
)
1578 /* It is referenced by a non-shared object. */
1580 h
->root
.non_ir_ref_regular
= 1;
1582 if (h
->type
== STT_GNU_IFUNC
)
1583 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1584 |= elf_gnu_symbol_ifunc
;
1587 if (r_type
== R_386_GOT32X
1588 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1590 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
1591 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
1597 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1598 symtab_hdr
, sym_hashes
,
1599 &r_type
, GOT_UNKNOWN
,
1600 rel
, rel_end
, h
, r_symndx
, FALSE
))
1606 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1610 /* This symbol requires a procedure linkage table entry. We
1611 actually build the entry in adjust_dynamic_symbol,
1612 because this might be a case of linking PIC code which is
1613 never referenced by a dynamic object, in which case we
1614 don't need to generate a procedure linkage table entry
1617 /* If this is a local symbol, we resolve it directly without
1618 creating a procedure linkage table entry. */
1622 eh
->has_got_reloc
= 1;
1624 h
->plt
.refcount
+= 1;
1631 case R_386_TLS_IE_32
:
1633 case R_386_TLS_GOTIE
:
1634 if (!bfd_link_executable (info
))
1635 info
->flags
|= DF_STATIC_TLS
;
1641 case R_386_TLS_GOTDESC
:
1642 case R_386_TLS_DESC_CALL
:
1643 /* This symbol requires a global offset table entry. */
1645 int tls_type
, old_tls_type
;
1652 tls_type
= GOT_NORMAL
;
1654 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1655 case R_386_TLS_GOTDESC
:
1656 case R_386_TLS_DESC_CALL
:
1657 tls_type
= GOT_TLS_GDESC
; break;
1658 case R_386_TLS_IE_32
:
1659 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1660 tls_type
= GOT_TLS_IE_NEG
;
1662 /* If this is a GD->IE transition, we may use either of
1663 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1664 tls_type
= GOT_TLS_IE
;
1667 case R_386_TLS_GOTIE
:
1668 tls_type
= GOT_TLS_IE_POS
; break;
1673 h
->got
.refcount
+= 1;
1674 old_tls_type
= elf_x86_hash_entry (h
)->tls_type
;
1678 bfd_signed_vma
*local_got_refcounts
;
1680 /* This is a global offset table entry for a local symbol. */
1681 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1682 if (local_got_refcounts
== NULL
)
1686 size
= symtab_hdr
->sh_info
;
1687 size
*= (sizeof (bfd_signed_vma
)
1688 + sizeof (bfd_vma
) + sizeof(char));
1689 local_got_refcounts
= (bfd_signed_vma
*)
1690 bfd_zalloc (abfd
, size
);
1691 if (local_got_refcounts
== NULL
)
1693 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1694 elf_x86_local_tlsdesc_gotent (abfd
)
1695 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1696 elf_x86_local_got_tls_type (abfd
)
1697 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1699 local_got_refcounts
[r_symndx
] += 1;
1700 old_tls_type
= elf_x86_local_got_tls_type (abfd
) [r_symndx
];
1703 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1704 tls_type
|= old_tls_type
;
1705 /* If a TLS symbol is accessed using IE at least once,
1706 there is no point to use dynamic model for it. */
1707 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1708 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1709 || (tls_type
& GOT_TLS_IE
) == 0))
1711 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1712 tls_type
= old_tls_type
;
1713 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1714 && GOT_TLS_GD_ANY_P (tls_type
))
1715 tls_type
|= old_tls_type
;
1719 name
= h
->root
.root
.string
;
1721 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1724 /* xgettext:c-format */
1725 (_("%B: `%s' accessed both as normal and "
1726 "thread local symbol"),
1728 bfd_set_error (bfd_error_bad_value
);
1733 if (old_tls_type
!= tls_type
)
1736 elf_x86_hash_entry (h
)->tls_type
= tls_type
;
1738 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1746 if (r_type
!= R_386_TLS_IE
)
1749 eh
->has_got_reloc
= 1;
1754 case R_386_TLS_LE_32
:
1757 eh
->has_got_reloc
= 1;
1758 if (bfd_link_executable (info
))
1760 info
->flags
|= DF_STATIC_TLS
;
1765 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
1766 eh
->has_non_got_reloc
= 1;
1768 /* We are called after all symbols have been resolved. Only
1769 relocation against STT_GNU_IFUNC symbol must go through
1772 && (bfd_link_executable (info
)
1773 || h
->type
== STT_GNU_IFUNC
))
1775 /* If this reloc is in a read-only section, we might
1776 need a copy reloc. We can't check reliably at this
1777 stage whether the section is read-only, as input
1778 sections have not yet been mapped to output sections.
1779 Tentatively set the flag for now, and correct in
1780 adjust_dynamic_symbol. */
1783 /* We may need a .plt entry if the symbol is a function
1784 defined in a shared lib or is a STT_GNU_IFUNC function
1785 referenced from the code or read-only section. */
1787 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
1788 h
->plt
.refcount
+= 1;
1790 if (r_type
== R_386_PC32
)
1792 /* Since something like ".long foo - ." may be used
1793 as pointer, make sure that PLT is used if foo is
1794 a function defined in a shared library. */
1795 if ((sec
->flags
& SEC_CODE
) == 0)
1796 h
->pointer_equality_needed
= 1;
1797 else if (h
->type
== STT_GNU_IFUNC
1798 && bfd_link_pic (info
))
1801 /* xgettext:c-format */
1802 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
1803 abfd
, h
->root
.root
.string
);
1804 bfd_set_error (bfd_error_bad_value
);
1810 h
->pointer_equality_needed
= 1;
1811 /* R_386_32 can be resolved at run-time. */
1812 if (r_type
== R_386_32
1813 && (sec
->flags
& SEC_READONLY
) == 0)
1814 eh
->func_pointer_refcount
+= 1;
1820 if (NEED_DYNAMIC_RELOCATION_P (info
, h
, sec
, r_type
,
1823 struct elf_dyn_relocs
*p
;
1824 struct elf_dyn_relocs
**head
;
1826 /* We must copy these reloc types into the output file.
1827 Create a reloc section in dynobj and make room for
1831 sreloc
= _bfd_elf_make_dynamic_reloc_section
1832 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1838 /* If this is a global symbol, we count the number of
1839 relocations we need for this symbol. */
1842 head
= &eh
->dyn_relocs
;
1846 /* Track dynamic relocs needed for local syms too.
1847 We really need local syms available to do this
1852 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1857 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1861 vpp
= &elf_section_data (s
)->local_dynrel
;
1862 head
= (struct elf_dyn_relocs
**)vpp
;
1866 if (p
== NULL
|| p
->sec
!= sec
)
1868 bfd_size_type amt
= sizeof *p
;
1869 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1881 /* Count size relocation as PC-relative relocation. */
1882 if (r_type
== R_386_PC32
|| size_reloc
)
1887 /* This relocation describes the C++ object vtable hierarchy.
1888 Reconstruct it for later use during GC. */
1889 case R_386_GNU_VTINHERIT
:
1890 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1894 /* This relocation describes which C++ vtable entries are actually
1895 used. Record for later use during GC. */
1896 case R_386_GNU_VTENTRY
:
1897 BFD_ASSERT (h
!= NULL
);
1899 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1908 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1910 if (!converted
&& !info
->keep_memory
)
1914 /* Cache the section contents for elf_link_input_bfd if any
1915 load is converted or --no-keep-memory isn't used. */
1916 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1920 /* Cache relocations if any load is converted. */
1921 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
1922 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
1927 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1929 sec
->check_relocs_failed
= 1;
1933 /* Set the correct type for an x86 ELF section. We do this by the
1934 section name, which is a hack, but ought to work. */
1937 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1938 Elf_Internal_Shdr
*hdr
,
1943 name
= bfd_get_section_name (abfd
, sec
);
1945 /* This is an ugly, but unfortunately necessary hack that is
1946 needed when producing EFI binaries on x86. It tells
1947 elf.c:elf_fake_sections() not to consider ".reloc" as a section
1948 containing ELF relocation info. We need this hack in order to
1949 be able to generate ELF binaries that can be translated into
1950 EFI applications (which are essentially COFF objects). Those
1951 files contain a COFF ".reloc" section inside an ELFNN object,
1952 which would normally cause BFD to segfault because it would
1953 attempt to interpret this section as containing relocation
1954 entries for section "oc". With this hack enabled, ".reloc"
1955 will be treated as a normal data section, which will avoid the
1956 segfault. However, you won't be able to create an ELFNN binary
1957 with a section named "oc" that needs relocations, but that's
1958 the kind of ugly side-effects you get when detecting section
1959 types based on their names... In practice, this limitation is
1960 unlikely to bite. */
1961 if (strcmp (name
, ".reloc") == 0)
1962 hdr
->sh_type
= SHT_PROGBITS
;
1967 /* Return the relocation value for @tpoff relocation
1968 if STT_TLS virtual address is ADDRESS. */
1971 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
1973 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1974 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
1975 bfd_vma static_tls_size
;
1977 /* If tls_sec is NULL, we should have signalled an error already. */
1978 if (htab
->tls_sec
== NULL
)
1981 /* Consider special static TLS alignment requirements. */
1982 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
1983 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
1986 /* Relocate an i386 ELF section. */
1989 elf_i386_relocate_section (bfd
*output_bfd
,
1990 struct bfd_link_info
*info
,
1992 asection
*input_section
,
1994 Elf_Internal_Rela
*relocs
,
1995 Elf_Internal_Sym
*local_syms
,
1996 asection
**local_sections
)
1998 struct elf_x86_link_hash_table
*htab
;
1999 Elf_Internal_Shdr
*symtab_hdr
;
2000 struct elf_link_hash_entry
**sym_hashes
;
2001 bfd_vma
*local_got_offsets
;
2002 bfd_vma
*local_tlsdesc_gotents
;
2003 Elf_Internal_Rela
*rel
;
2004 Elf_Internal_Rela
*wrel
;
2005 Elf_Internal_Rela
*relend
;
2006 bfd_boolean is_vxworks_tls
;
2007 unsigned plt_entry_size
;
2009 /* Skip if check_relocs failed. */
2010 if (input_section
->check_relocs_failed
)
2013 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2017 BFD_ASSERT (is_x86_elf (input_bfd
, htab
));
2019 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2020 sym_hashes
= elf_sym_hashes (input_bfd
);
2021 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2022 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2023 /* We have to handle relocations in vxworks .tls_vars sections
2024 specially, because the dynamic loader is 'weird'. */
2025 is_vxworks_tls
= (htab
->is_vxworks
2026 && bfd_link_pic (info
)
2027 && !strcmp (input_section
->output_section
->name
,
2030 _bfd_x86_elf_set_tls_module_base (info
);
2032 plt_entry_size
= htab
->plt
.plt_entry_size
;
2034 rel
= wrel
= relocs
;
2035 relend
= relocs
+ input_section
->reloc_count
;
2036 for (; rel
< relend
; wrel
++, rel
++)
2038 unsigned int r_type
, r_type_tls
;
2039 reloc_howto_type
*howto
;
2040 unsigned long r_symndx
;
2041 struct elf_link_hash_entry
*h
;
2042 struct elf_x86_link_hash_entry
*eh
;
2043 Elf_Internal_Sym
*sym
;
2045 bfd_vma off
, offplt
, plt_offset
;
2047 bfd_boolean unresolved_reloc
;
2048 bfd_reloc_status_type r
;
2052 asection
*resolved_plt
;
2053 bfd_boolean resolved_to_zero
;
2054 bfd_boolean relative_reloc
;
2056 r_type
= ELF32_R_TYPE (rel
->r_info
);
2057 if (r_type
== R_386_GNU_VTINHERIT
2058 || r_type
== R_386_GNU_VTENTRY
)
2065 if ((indx
= r_type
) >= R_386_standard
2066 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2067 >= R_386_ext
- R_386_standard
)
2068 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2069 >= R_386_ext2
- R_386_ext
))
2070 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2072 howto
= elf_howto_table
+ indx
;
2074 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2078 unresolved_reloc
= FALSE
;
2079 if (r_symndx
< symtab_hdr
->sh_info
)
2081 sym
= local_syms
+ r_symndx
;
2082 sec
= local_sections
[r_symndx
];
2083 relocation
= (sec
->output_section
->vma
2084 + sec
->output_offset
2086 st_size
= sym
->st_size
;
2088 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2089 && ((sec
->flags
& SEC_MERGE
) != 0
2090 || (bfd_link_relocatable (info
)
2091 && sec
->output_offset
!= 0)))
2094 bfd_byte
*where
= contents
+ rel
->r_offset
;
2096 switch (howto
->size
)
2099 addend
= bfd_get_8 (input_bfd
, where
);
2100 if (howto
->pc_relative
)
2102 addend
= (addend
^ 0x80) - 0x80;
2107 addend
= bfd_get_16 (input_bfd
, where
);
2108 if (howto
->pc_relative
)
2110 addend
= (addend
^ 0x8000) - 0x8000;
2115 addend
= bfd_get_32 (input_bfd
, where
);
2116 if (howto
->pc_relative
)
2118 addend
= (addend
^ 0x80000000) - 0x80000000;
2126 if (bfd_link_relocatable (info
))
2127 addend
+= sec
->output_offset
;
2130 asection
*msec
= sec
;
2131 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2133 addend
-= relocation
;
2134 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2137 switch (howto
->size
)
2140 /* FIXME: overflow checks. */
2141 if (howto
->pc_relative
)
2143 bfd_put_8 (input_bfd
, addend
, where
);
2146 if (howto
->pc_relative
)
2148 bfd_put_16 (input_bfd
, addend
, where
);
2151 if (howto
->pc_relative
)
2153 bfd_put_32 (input_bfd
, addend
, where
);
2157 else if (!bfd_link_relocatable (info
)
2158 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2160 /* Relocate against local STT_GNU_IFUNC symbol. */
2161 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
, rel
,
2166 /* Set STT_GNU_IFUNC symbol value. */
2167 h
->root
.u
.def
.value
= sym
->st_value
;
2168 h
->root
.u
.def
.section
= sec
;
2173 bfd_boolean warned ATTRIBUTE_UNUSED
;
2174 bfd_boolean ignored ATTRIBUTE_UNUSED
;
2176 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2177 r_symndx
, symtab_hdr
, sym_hashes
,
2179 unresolved_reloc
, warned
, ignored
);
2183 if (sec
!= NULL
&& discarded_section (sec
))
2185 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2186 contents
+ rel
->r_offset
);
2187 wrel
->r_offset
= rel
->r_offset
;
2191 /* For ld -r, remove relocations in debug sections against
2192 sections defined in discarded sections. Not done for
2193 eh_frame editing code expects to be present. */
2194 if (bfd_link_relocatable (info
)
2195 && (input_section
->flags
& SEC_DEBUGGING
))
2201 if (bfd_link_relocatable (info
))
2208 eh
= (struct elf_x86_link_hash_entry
*) h
;
2210 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2211 it here if it is defined in a non-shared object. */
2213 && h
->type
== STT_GNU_IFUNC
2216 asection
*gotplt
, *base_got
;
2220 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2222 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2223 sections because such sections are not SEC_ALLOC and
2224 thus ld.so will not process them. */
2225 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2230 /* STT_GNU_IFUNC symbol must go through PLT. */
2231 if (htab
->elf
.splt
!= NULL
)
2233 if (htab
->plt_second
!= NULL
)
2235 resolved_plt
= htab
->plt_second
;
2236 plt_offset
= eh
->plt_second
.offset
;
2240 resolved_plt
= htab
->elf
.splt
;
2241 plt_offset
= h
->plt
.offset
;
2243 gotplt
= htab
->elf
.sgotplt
;
2247 resolved_plt
= htab
->elf
.iplt
;
2248 plt_offset
= h
->plt
.offset
;
2249 gotplt
= htab
->elf
.igotplt
;
2259 base_got
= htab
->elf
.sgot
;
2260 off
= h
->got
.offset
;
2262 if (base_got
== NULL
)
2265 if (off
== (bfd_vma
) -1)
2267 /* We can't use h->got.offset here to save state, or
2268 even just remember the offset, as finish_dynamic_symbol
2269 would use that as offset into .got. */
2271 if (h
->plt
.offset
== (bfd_vma
) -1)
2274 if (htab
->elf
.splt
!= NULL
)
2276 plt_index
= (h
->plt
.offset
/ plt_entry_size
2277 - htab
->plt
.has_plt0
);
2278 off
= (plt_index
+ 3) * 4;
2279 base_got
= htab
->elf
.sgotplt
;
2283 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2284 off
= plt_index
* 4;
2285 base_got
= htab
->elf
.igotplt
;
2288 if (h
->dynindx
== -1
2292 /* This references the local defitionion. We must
2293 initialize this entry in the global offset table.
2294 Since the offset must always be a multiple of 8,
2295 we use the least significant bit to record
2296 whether we have initialized it already.
2298 When doing a dynamic link, we create a .rela.got
2299 relocation entry to initialize the value. This
2300 is done in the finish_dynamic_symbol routine. */
2305 bfd_put_32 (output_bfd
, relocation
,
2306 base_got
->contents
+ off
);
2314 relocation
= (base_got
->output_section
->vma
2315 + base_got
->output_offset
+ off
2316 - gotplt
->output_section
->vma
2317 - gotplt
->output_offset
);
2319 if (rel
->r_offset
> 1
2320 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2321 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2323 if (bfd_link_pic (info
))
2324 goto disallow_got32
;
2326 /* Add the GOT base if there is no base register. */
2327 relocation
+= (gotplt
->output_section
->vma
2328 + gotplt
->output_offset
);
2330 else if (htab
->elf
.splt
== NULL
)
2332 /* Adjust for static executables. */
2333 relocation
+= gotplt
->output_offset
;
2339 if (h
->plt
.offset
== (bfd_vma
) -1)
2341 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2342 if (r_type
== R_386_32
2343 && (input_section
->flags
& SEC_CODE
) == 0)
2344 goto do_ifunc_pointer
;
2345 goto bad_ifunc_reloc
;
2348 relocation
= (resolved_plt
->output_section
->vma
2349 + resolved_plt
->output_offset
+ plt_offset
);
2355 if (h
->root
.root
.string
)
2356 name
= h
->root
.root
.string
;
2358 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2361 /* xgettext:c-format */
2362 (_("%B: relocation %s against STT_GNU_IFUNC "
2363 "symbol `%s' isn't supported"), input_bfd
,
2365 bfd_set_error (bfd_error_bad_value
);
2369 /* Generate dynamic relcoation only when there is a
2370 non-GOT reference in a shared object. */
2371 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2372 || h
->plt
.offset
== (bfd_vma
) -1)
2374 Elf_Internal_Rela outrel
;
2379 /* Need a dynamic relocation to get the real function
2381 offset
= _bfd_elf_section_offset (output_bfd
,
2385 if (offset
== (bfd_vma
) -1
2386 || offset
== (bfd_vma
) -2)
2389 outrel
.r_offset
= (input_section
->output_section
->vma
2390 + input_section
->output_offset
2393 if (POINTER_LOCAL_IFUNC_P (info
, h
))
2395 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
2396 h
->root
.root
.string
,
2397 h
->root
.u
.def
.section
->owner
);
2399 /* This symbol is resolved locally. */
2400 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
2401 bfd_put_32 (output_bfd
,
2402 (h
->root
.u
.def
.value
2403 + h
->root
.u
.def
.section
->output_section
->vma
2404 + h
->root
.u
.def
.section
->output_offset
),
2408 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2410 /* Dynamic relocations are stored in
2411 1. .rel.ifunc section in PIC object.
2412 2. .rel.got section in dynamic executable.
2413 3. .rel.iplt section in static executable. */
2414 if (bfd_link_pic (info
))
2415 sreloc
= htab
->elf
.irelifunc
;
2416 else if (htab
->elf
.splt
!= NULL
)
2417 sreloc
= htab
->elf
.srelgot
;
2419 sreloc
= htab
->elf
.irelplt
;
2420 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2422 /* If this reloc is against an external symbol, we
2423 do not want to fiddle with the addend. Otherwise,
2424 we need to include the symbol value so that it
2425 becomes an addend for the dynamic reloc. For an
2426 internal symbol, we have updated addend. */
2435 relocation
-= (gotplt
->output_section
->vma
2436 + gotplt
->output_offset
);
2441 resolved_to_zero
= (eh
!= NULL
2442 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2447 /* Avoid optimizing _DYNAMIC since ld.so may use its
2448 link-time address. */
2449 if (h
== htab
->elf
.hdynamic
)
2452 if (bfd_link_pic (info
))
2454 /* It is OK to convert mov to lea and convert indirect
2455 branch to direct branch. It is OK to convert adc,
2456 add, and, cmp, or, sbb, sub, test, xor only when PIC
2458 unsigned int opcode
, addend
;
2459 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2462 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2463 if (opcode
!= 0x8b && opcode
!= 0xff)
2467 /* Resolve "mov GOT[(%reg)], %reg",
2468 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
2469 and "binop foo@GOT[(%reg)], %reg". */
2471 || (h
->plt
.offset
== (bfd_vma
) -1
2472 && h
->got
.offset
== (bfd_vma
) -1)
2473 || htab
->elf
.sgotplt
== NULL
)
2476 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
2477 + htab
->elf
.sgotplt
->output_offset
);
2479 /* It is relative to .got.plt section. */
2480 if (h
->got
.offset
!= (bfd_vma
) -1)
2481 /* Use GOT entry. Mask off the least significant bit in
2482 GOT offset which may be set by R_386_GOT32 processing
2484 relocation
= (htab
->elf
.sgot
->output_section
->vma
2485 + htab
->elf
.sgot
->output_offset
2486 + (h
->got
.offset
& ~1) - offplt
);
2488 /* Use GOTPLT entry. */
2489 relocation
= (h
->plt
.offset
/ plt_entry_size
2490 - htab
->plt
.has_plt0
+ 3) * 4;
2492 if (!bfd_link_pic (info
))
2494 /* If not PIC, add the .got.plt section address for
2495 baseless addressing. */
2497 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2498 if ((modrm
& 0xc7) == 0x5)
2499 relocation
+= offplt
;
2502 unresolved_reloc
= FALSE
;
2507 /* Relocation is to the entry for this symbol in the global
2509 if (htab
->elf
.sgot
== NULL
)
2512 relative_reloc
= FALSE
;
2515 off
= h
->got
.offset
;
2516 if (RESOLVED_LOCALLY_P (info
, h
, htab
))
2518 /* We must initialize this entry in the global offset
2519 table. Since the offset must always be a multiple
2520 of 4, we use the least significant bit to record
2521 whether we have initialized it already.
2523 When doing a dynamic link, we create a .rel.got
2524 relocation entry to initialize the value. This
2525 is done in the finish_dynamic_symbol routine. */
2530 bfd_put_32 (output_bfd
, relocation
,
2531 htab
->elf
.sgot
->contents
+ off
);
2534 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
2536 /* PR ld/21402: If this symbol isn't dynamic
2537 in PIC, generate R_386_RELATIVE here. */
2538 eh
->no_finish_dynamic_symbol
= 1;
2539 relative_reloc
= TRUE
;
2544 unresolved_reloc
= FALSE
;
2548 if (local_got_offsets
== NULL
)
2551 off
= local_got_offsets
[r_symndx
];
2553 /* The offset must always be a multiple of 4. We use
2554 the least significant bit to record whether we have
2555 already generated the necessary reloc. */
2560 bfd_put_32 (output_bfd
, relocation
,
2561 htab
->elf
.sgot
->contents
+ off
);
2562 local_got_offsets
[r_symndx
] |= 1;
2564 if (bfd_link_pic (info
))
2565 relative_reloc
= TRUE
;
2572 Elf_Internal_Rela outrel
;
2574 s
= htab
->elf
.srelgot
;
2578 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
2579 + htab
->elf
.sgot
->output_offset
2581 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2582 elf_append_rel (output_bfd
, s
, &outrel
);
2585 if (off
>= (bfd_vma
) -2)
2588 relocation
= (htab
->elf
.sgot
->output_section
->vma
2589 + htab
->elf
.sgot
->output_offset
+ off
);
2590 if (rel
->r_offset
> 1
2591 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2592 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2594 if (bfd_link_pic (info
))
2596 /* For PIC, disallow R_386_GOT32 without a base
2597 register, except for "lea foo@GOT, %reg", since
2598 we don't know what the GOT base is. */
2602 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
2603 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2606 name
= h
->root
.root
.string
;
2609 /* xgettext:c-format */
2610 (_("%B: direct GOT relocation %s against `%s'"
2611 " without base register can not be used"
2612 " when making a shared object"),
2613 input_bfd
, howto
->name
, name
);
2614 bfd_set_error (bfd_error_bad_value
);
2620 /* Subtract the .got.plt section address only with a base
2622 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
2623 + htab
->elf
.sgotplt
->output_offset
);
2629 /* Relocation is relative to the start of the global offset
2632 /* Check to make sure it isn't a protected function or data
2633 symbol for shared library since it may not be local when
2634 used as function address or with copy relocation. We also
2635 need to make sure that a symbol is referenced locally. */
2636 if (!bfd_link_executable (info
) && h
)
2638 if (!h
->def_regular
)
2642 switch (ELF_ST_VISIBILITY (h
->other
))
2645 v
= _("hidden symbol");
2648 v
= _("internal symbol");
2651 v
= _("protected symbol");
2659 /* xgettext:c-format */
2660 (_("%B: relocation R_386_GOTOFF against undefined %s"
2661 " `%s' can not be used when making a shared object"),
2662 input_bfd
, v
, h
->root
.root
.string
);
2663 bfd_set_error (bfd_error_bad_value
);
2666 else if (!SYMBOL_REFERENCES_LOCAL_P (info
, h
)
2667 && (h
->type
== STT_FUNC
2668 || h
->type
== STT_OBJECT
)
2669 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2672 /* xgettext:c-format */
2673 (_("%B: relocation R_386_GOTOFF against protected %s"
2674 " `%s' can not be used when making a shared object"),
2676 h
->type
== STT_FUNC
? "function" : "data",
2677 h
->root
.root
.string
);
2678 bfd_set_error (bfd_error_bad_value
);
2683 /* Note that sgot is not involved in this
2684 calculation. We always want the start of .got.plt. If we
2685 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2686 permitted by the ABI, we might have to change this
2688 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2689 + htab
->elf
.sgotplt
->output_offset
;
2693 /* Use global offset table as symbol value. */
2694 relocation
= htab
->elf
.sgotplt
->output_section
->vma
2695 + htab
->elf
.sgotplt
->output_offset
;
2696 unresolved_reloc
= FALSE
;
2700 /* Relocation is to the entry for this symbol in the
2701 procedure linkage table. */
2703 /* Resolve a PLT32 reloc against a local symbol directly,
2704 without using the procedure linkage table. */
2708 if ((h
->plt
.offset
== (bfd_vma
) -1
2709 && eh
->plt_got
.offset
== (bfd_vma
) -1)
2710 || htab
->elf
.splt
== NULL
)
2712 /* We didn't make a PLT entry for this symbol. This
2713 happens when statically linking PIC code, or when
2714 using -Bsymbolic. */
2718 if (h
->plt
.offset
!= (bfd_vma
) -1)
2720 if (htab
->plt_second
!= NULL
)
2722 resolved_plt
= htab
->plt_second
;
2723 plt_offset
= eh
->plt_second
.offset
;
2727 resolved_plt
= htab
->elf
.splt
;
2728 plt_offset
= h
->plt
.offset
;
2733 resolved_plt
= htab
->plt_got
;
2734 plt_offset
= eh
->plt_got
.offset
;
2737 relocation
= (resolved_plt
->output_section
->vma
2738 + resolved_plt
->output_offset
2740 unresolved_reloc
= FALSE
;
2744 /* Set to symbol size. */
2745 relocation
= st_size
;
2750 if ((input_section
->flags
& SEC_ALLOC
) == 0
2754 if (GENERATE_DYNAMIC_RELOCATION_P (info
, eh
, r_type
,
2755 FALSE
, resolved_to_zero
,
2756 (r_type
== R_386_PC32
)))
2758 Elf_Internal_Rela outrel
;
2759 bfd_boolean skip
, relocate
;
2762 /* When generating a shared object, these relocations
2763 are copied into the output file to be resolved at run
2770 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2772 if (outrel
.r_offset
== (bfd_vma
) -1)
2774 else if (outrel
.r_offset
== (bfd_vma
) -2)
2775 skip
= TRUE
, relocate
= TRUE
;
2776 outrel
.r_offset
+= (input_section
->output_section
->vma
2777 + input_section
->output_offset
);
2780 memset (&outrel
, 0, sizeof outrel
);
2781 else if (COPY_INPUT_RELOC_P (info
, h
, r_type
))
2782 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2785 /* This symbol is local, or marked to become local. */
2787 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2790 sreloc
= elf_section_data (input_section
)->sreloc
;
2792 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
2794 r
= bfd_reloc_notsupported
;
2795 goto check_relocation_error
;
2798 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2800 /* If this reloc is against an external symbol, we do
2801 not want to fiddle with the addend. Otherwise, we
2802 need to include the symbol value so that it becomes
2803 an addend for the dynamic reloc. */
2810 if (!bfd_link_executable (info
))
2812 Elf_Internal_Rela outrel
;
2815 outrel
.r_offset
= rel
->r_offset
2816 + input_section
->output_section
->vma
2817 + input_section
->output_offset
;
2818 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2819 sreloc
= elf_section_data (input_section
)->sreloc
;
2822 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2827 case R_386_TLS_GOTDESC
:
2828 case R_386_TLS_DESC_CALL
:
2829 case R_386_TLS_IE_32
:
2830 case R_386_TLS_GOTIE
:
2831 tls_type
= GOT_UNKNOWN
;
2832 if (h
== NULL
&& local_got_offsets
)
2833 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
2835 tls_type
= elf_x86_hash_entry(h
)->tls_type
;
2836 if (tls_type
== GOT_TLS_IE
)
2837 tls_type
= GOT_TLS_IE_NEG
;
2839 r_type_tls
= r_type
;
2840 if (! elf_i386_tls_transition (info
, input_bfd
,
2841 input_section
, contents
,
2842 symtab_hdr
, sym_hashes
,
2843 &r_type_tls
, tls_type
, rel
,
2844 relend
, h
, r_symndx
, TRUE
))
2847 if (r_type_tls
== R_386_TLS_LE_32
)
2849 BFD_ASSERT (! unresolved_reloc
);
2850 if (r_type
== R_386_TLS_GD
)
2855 /* GD->LE transition. */
2856 type
= *(contents
+ rel
->r_offset
- 2);
2860 leal foo@tlsgd(,%ebx,1), %eax
2861 call ___tls_get_addr@PLT
2864 subl $foo@tpoff, %eax
2865 (6 byte form of subl). */
2866 roff
= rel
->r_offset
+ 5;
2871 leal foo@tlsgd(%ebx), %eax
2872 call ___tls_get_addr@PLT
2875 leal foo@tlsgd(%reg), %eax
2876 call *___tls_get_addr@GOT(%reg)
2877 which may be converted to
2878 addr32 call ___tls_get_addr
2880 movl %gs:0, %eax; subl $foo@tpoff, %eax
2881 (6 byte form of subl). */
2882 roff
= rel
->r_offset
+ 6;
2884 memcpy (contents
+ roff
- 8,
2885 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2886 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
2888 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
2893 else if (r_type
== R_386_TLS_GOTDESC
)
2895 /* GDesc -> LE transition.
2896 It's originally something like:
2897 leal x@tlsdesc(%ebx), %eax
2901 Registers other than %eax may be set up here. */
2906 roff
= rel
->r_offset
;
2907 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2909 /* Now modify the instruction as appropriate. */
2910 /* aoliva FIXME: remove the above and xor the byte
2912 bfd_put_8 (output_bfd
, val
^ 0x86,
2913 contents
+ roff
- 1);
2914 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
2918 else if (r_type
== R_386_TLS_DESC_CALL
)
2920 /* GDesc -> LE transition.
2928 roff
= rel
->r_offset
;
2929 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
2930 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
2933 else if (r_type
== R_386_TLS_IE
)
2937 /* IE->LE transition:
2938 Originally it can be one of:
2946 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2949 /* movl foo, %eax. */
2950 bfd_put_8 (output_bfd
, 0xb8,
2951 contents
+ rel
->r_offset
- 1);
2957 type
= bfd_get_8 (input_bfd
,
2958 contents
+ rel
->r_offset
- 2);
2963 bfd_put_8 (output_bfd
, 0xc7,
2964 contents
+ rel
->r_offset
- 2);
2965 bfd_put_8 (output_bfd
,
2966 0xc0 | ((val
>> 3) & 7),
2967 contents
+ rel
->r_offset
- 1);
2971 bfd_put_8 (output_bfd
, 0x81,
2972 contents
+ rel
->r_offset
- 2);
2973 bfd_put_8 (output_bfd
,
2974 0xc0 | ((val
>> 3) & 7),
2975 contents
+ rel
->r_offset
- 1);
2982 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
2983 contents
+ rel
->r_offset
);
2988 unsigned int val
, type
;
2990 /* {IE_32,GOTIE}->LE transition:
2991 Originally it can be one of:
2992 subl foo(%reg1), %reg2
2993 movl foo(%reg1), %reg2
2994 addl foo(%reg1), %reg2
2997 movl $foo, %reg2 (6 byte form)
2998 addl $foo, %reg2. */
2999 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3000 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3004 bfd_put_8 (output_bfd
, 0xc7,
3005 contents
+ rel
->r_offset
- 2);
3006 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3007 contents
+ rel
->r_offset
- 1);
3009 else if (type
== 0x2b)
3012 bfd_put_8 (output_bfd
, 0x81,
3013 contents
+ rel
->r_offset
- 2);
3014 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3015 contents
+ rel
->r_offset
- 1);
3017 else if (type
== 0x03)
3020 bfd_put_8 (output_bfd
, 0x81,
3021 contents
+ rel
->r_offset
- 2);
3022 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3023 contents
+ rel
->r_offset
- 1);
3027 if (r_type
== R_386_TLS_GOTIE
)
3028 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3029 contents
+ rel
->r_offset
);
3031 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3032 contents
+ rel
->r_offset
);
3037 if (htab
->elf
.sgot
== NULL
)
3042 off
= h
->got
.offset
;
3043 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3047 if (local_got_offsets
== NULL
)
3050 off
= local_got_offsets
[r_symndx
];
3051 offplt
= local_tlsdesc_gotents
[r_symndx
];
3058 Elf_Internal_Rela outrel
;
3062 if (htab
->elf
.srelgot
== NULL
)
3065 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3067 if (GOT_TLS_GDESC_P (tls_type
))
3070 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3071 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3072 <= htab
->elf
.sgotplt
->size
);
3073 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3074 + htab
->elf
.sgotplt
->output_offset
3076 + htab
->sgotplt_jump_table_size
);
3077 sreloc
= htab
->elf
.srelplt
;
3078 loc
= sreloc
->contents
;
3079 loc
+= (htab
->next_tls_desc_index
++
3080 * sizeof (Elf32_External_Rel
));
3081 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3082 <= sreloc
->contents
+ sreloc
->size
);
3083 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3086 BFD_ASSERT (! unresolved_reloc
);
3087 bfd_put_32 (output_bfd
,
3088 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3089 htab
->elf
.sgotplt
->contents
+ offplt
3090 + htab
->sgotplt_jump_table_size
+ 4);
3094 bfd_put_32 (output_bfd
, 0,
3095 htab
->elf
.sgotplt
->contents
+ offplt
3096 + htab
->sgotplt_jump_table_size
+ 4);
3100 sreloc
= htab
->elf
.srelgot
;
3102 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3103 + htab
->elf
.sgot
->output_offset
+ off
);
3105 if (GOT_TLS_GD_P (tls_type
))
3106 dr_type
= R_386_TLS_DTPMOD32
;
3107 else if (GOT_TLS_GDESC_P (tls_type
))
3109 else if (tls_type
== GOT_TLS_IE_POS
)
3110 dr_type
= R_386_TLS_TPOFF
;
3112 dr_type
= R_386_TLS_TPOFF32
;
3114 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3115 bfd_put_32 (output_bfd
,
3116 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3117 htab
->elf
.sgot
->contents
+ off
);
3118 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3119 bfd_put_32 (output_bfd
,
3120 _bfd_x86_elf_dtpoff_base (info
) - relocation
,
3121 htab
->elf
.sgot
->contents
+ off
);
3122 else if (dr_type
!= R_386_TLS_DESC
)
3123 bfd_put_32 (output_bfd
, 0,
3124 htab
->elf
.sgot
->contents
+ off
);
3125 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3127 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3129 if (GOT_TLS_GD_P (tls_type
))
3133 BFD_ASSERT (! unresolved_reloc
);
3134 bfd_put_32 (output_bfd
,
3135 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3136 htab
->elf
.sgot
->contents
+ off
+ 4);
3140 bfd_put_32 (output_bfd
, 0,
3141 htab
->elf
.sgot
->contents
+ off
+ 4);
3142 outrel
.r_info
= ELF32_R_INFO (indx
,
3143 R_386_TLS_DTPOFF32
);
3144 outrel
.r_offset
+= 4;
3145 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3148 else if (tls_type
== GOT_TLS_IE_BOTH
)
3150 bfd_put_32 (output_bfd
,
3152 ? relocation
- _bfd_x86_elf_dtpoff_base (info
)
3154 htab
->elf
.sgot
->contents
+ off
+ 4);
3155 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3156 outrel
.r_offset
+= 4;
3157 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3164 local_got_offsets
[r_symndx
] |= 1;
3167 if (off
>= (bfd_vma
) -2
3168 && ! GOT_TLS_GDESC_P (tls_type
))
3170 if (r_type_tls
== R_386_TLS_GOTDESC
3171 || r_type_tls
== R_386_TLS_DESC_CALL
)
3173 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3174 unresolved_reloc
= FALSE
;
3176 else if (r_type_tls
== r_type
)
3178 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3179 + htab
->elf
.sgotplt
->output_offset
;
3180 relocation
= htab
->elf
.sgot
->output_section
->vma
3181 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3182 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3183 && tls_type
== GOT_TLS_IE_BOTH
)
3185 if (r_type
== R_386_TLS_IE
)
3186 relocation
+= g_o_t
;
3187 unresolved_reloc
= FALSE
;
3189 else if (r_type
== R_386_TLS_GD
)
3191 unsigned int val
, type
;
3194 /* GD->IE transition. */
3195 type
= *(contents
+ rel
->r_offset
- 2);
3196 val
= *(contents
+ rel
->r_offset
- 1);
3200 leal foo@tlsgd(,%ebx,1), %eax
3201 call ___tls_get_addr@PLT
3204 subl $foo@gottpoff(%ebx), %eax. */
3206 roff
= rel
->r_offset
- 3;
3211 leal foo@tlsgd(%ebx), %eax
3212 call ___tls_get_addr@PLT
3215 leal foo@tlsgd(%reg), %eax
3216 call *___tls_get_addr@GOT(%reg)
3217 which may be converted to
3218 addr32 call ___tls_get_addr
3221 subl $foo@gottpoff(%reg), %eax. */
3222 roff
= rel
->r_offset
- 2;
3224 memcpy (contents
+ roff
,
3225 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3226 contents
[roff
+ 7] = 0x80 | (val
& 7);
3227 /* If foo is used only with foo@gotntpoff(%reg) and
3228 foo@indntpoff, but not with foo@gottpoff(%reg), change
3229 subl $foo@gottpoff(%reg), %eax
3231 addl $foo@gotntpoff(%reg), %eax. */
3232 if (tls_type
== GOT_TLS_IE_POS
)
3233 contents
[roff
+ 6] = 0x03;
3234 bfd_put_32 (output_bfd
,
3235 htab
->elf
.sgot
->output_section
->vma
3236 + htab
->elf
.sgot
->output_offset
+ off
3237 - htab
->elf
.sgotplt
->output_section
->vma
3238 - htab
->elf
.sgotplt
->output_offset
,
3239 contents
+ roff
+ 8);
3240 /* Skip R_386_PLT32 and R_386_GOT32X. */
3245 else if (r_type
== R_386_TLS_GOTDESC
)
3247 /* GDesc -> IE transition.
3248 It's originally something like:
3249 leal x@tlsdesc(%ebx), %eax
3252 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3254 movl x@gottpoff(%ebx), %eax # before negl %eax
3256 Registers other than %eax may be set up here. */
3260 /* First, make sure it's a leal adding ebx to a 32-bit
3261 offset into any register, although it's probably
3262 almost always going to be eax. */
3263 roff
= rel
->r_offset
;
3265 /* Now modify the instruction as appropriate. */
3266 /* To turn a leal into a movl in the form we use it, it
3267 suffices to change the first byte from 0x8d to 0x8b.
3268 aoliva FIXME: should we decide to keep the leal, all
3269 we have to do is remove the statement below, and
3270 adjust the relaxation of R_386_TLS_DESC_CALL. */
3271 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3273 if (tls_type
== GOT_TLS_IE_BOTH
)
3276 bfd_put_32 (output_bfd
,
3277 htab
->elf
.sgot
->output_section
->vma
3278 + htab
->elf
.sgot
->output_offset
+ off
3279 - htab
->elf
.sgotplt
->output_section
->vma
3280 - htab
->elf
.sgotplt
->output_offset
,
3284 else if (r_type
== R_386_TLS_DESC_CALL
)
3286 /* GDesc -> IE transition.
3294 depending on how we transformed the TLS_GOTDESC above.
3299 roff
= rel
->r_offset
;
3301 /* Now modify the instruction as appropriate. */
3302 if (tls_type
!= GOT_TLS_IE_NEG
)
3305 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3306 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3311 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3312 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3322 if (! elf_i386_tls_transition (info
, input_bfd
,
3323 input_section
, contents
,
3324 symtab_hdr
, sym_hashes
,
3325 &r_type
, GOT_UNKNOWN
, rel
,
3326 relend
, h
, r_symndx
, TRUE
))
3329 if (r_type
!= R_386_TLS_LDM
)
3331 /* LD->LE transition. Change
3332 leal foo@tlsldm(%ebx) %eax
3333 call ___tls_get_addr@PLT
3337 leal 0(%esi,1), %esi
3339 leal foo@tlsldm(%reg) %eax
3340 call *___tls_get_addr@GOT(%reg)
3341 which may be converted to
3342 addr32 call ___tls_get_addr
3345 leal 0(%esi), %esi */
3346 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3347 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
3348 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
3349 memcpy (contents
+ rel
->r_offset
- 2,
3350 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
3352 memcpy (contents
+ rel
->r_offset
- 2,
3353 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3354 /* Skip R_386_PC32/R_386_PLT32. */
3360 if (htab
->elf
.sgot
== NULL
)
3363 off
= htab
->tls_ld_or_ldm_got
.offset
;
3368 Elf_Internal_Rela outrel
;
3370 if (htab
->elf
.srelgot
== NULL
)
3373 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3374 + htab
->elf
.sgot
->output_offset
+ off
);
3376 bfd_put_32 (output_bfd
, 0,
3377 htab
->elf
.sgot
->contents
+ off
);
3378 bfd_put_32 (output_bfd
, 0,
3379 htab
->elf
.sgot
->contents
+ off
+ 4);
3380 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3381 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3382 htab
->tls_ld_or_ldm_got
.offset
|= 1;
3384 relocation
= htab
->elf
.sgot
->output_section
->vma
3385 + htab
->elf
.sgot
->output_offset
+ off
3386 - htab
->elf
.sgotplt
->output_section
->vma
3387 - htab
->elf
.sgotplt
->output_offset
;
3388 unresolved_reloc
= FALSE
;
3391 case R_386_TLS_LDO_32
:
3392 if (!bfd_link_executable (info
)
3393 || (input_section
->flags
& SEC_CODE
) == 0)
3394 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3396 /* When converting LDO to LE, we must negate. */
3397 relocation
= -elf_i386_tpoff (info
, relocation
);
3400 case R_386_TLS_LE_32
:
3402 if (!bfd_link_executable (info
))
3404 Elf_Internal_Rela outrel
;
3407 outrel
.r_offset
= rel
->r_offset
3408 + input_section
->output_section
->vma
3409 + input_section
->output_offset
;
3410 if (h
!= NULL
&& h
->dynindx
!= -1)
3414 if (r_type
== R_386_TLS_LE_32
)
3415 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3417 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3418 sreloc
= elf_section_data (input_section
)->sreloc
;
3421 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3424 else if (r_type
== R_386_TLS_LE_32
)
3425 relocation
= _bfd_x86_elf_dtpoff_base (info
) - relocation
;
3427 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3429 else if (r_type
== R_386_TLS_LE_32
)
3430 relocation
= elf_i386_tpoff (info
, relocation
);
3432 relocation
= -elf_i386_tpoff (info
, relocation
);
3439 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3440 because such sections are not SEC_ALLOC and thus ld.so will
3441 not process them. */
3442 if (unresolved_reloc
3443 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3445 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3446 rel
->r_offset
) != (bfd_vma
) -1)
3449 /* xgettext:c-format */
3450 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
3455 h
->root
.root
.string
);
3460 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3461 contents
, rel
->r_offset
,
3464 check_relocation_error
:
3465 if (r
!= bfd_reloc_ok
)
3470 name
= h
->root
.root
.string
;
3473 name
= bfd_elf_string_from_elf_section (input_bfd
,
3474 symtab_hdr
->sh_link
,
3479 name
= bfd_section_name (input_bfd
, sec
);
3482 if (r
== bfd_reloc_overflow
)
3483 (*info
->callbacks
->reloc_overflow
)
3484 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3485 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3489 /* xgettext:c-format */
3490 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
3491 input_bfd
, input_section
,
3492 rel
->r_offset
, name
, (int) r
);
3503 Elf_Internal_Shdr
*rel_hdr
;
3504 size_t deleted
= rel
- wrel
;
3506 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
3507 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3508 if (rel_hdr
->sh_size
== 0)
3510 /* It is too late to remove an empty reloc section. Leave
3512 ??? What is wrong with an empty section??? */
3513 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
3516 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
3517 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3518 input_section
->reloc_count
-= deleted
;
3524 /* Finish up dynamic symbol handling. We set the contents of various
3525 dynamic sections here. */
3528 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3529 struct bfd_link_info
*info
,
3530 struct elf_link_hash_entry
*h
,
3531 Elf_Internal_Sym
*sym
)
3533 struct elf_x86_link_hash_table
*htab
;
3534 unsigned plt_entry_size
;
3535 struct elf_x86_link_hash_entry
*eh
;
3536 bfd_boolean local_undefweak
;
3537 bfd_boolean use_plt_second
;
3539 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
3543 plt_entry_size
= htab
->plt
.plt_entry_size
;
3545 /* Use the second PLT section only if there is .plt section. */
3546 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
3548 eh
= (struct elf_x86_link_hash_entry
*) h
;
3549 if (eh
->no_finish_dynamic_symbol
)
3552 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
3553 resolved undefined weak symbols in executable so that their
3554 references have value 0 at run-time. */
3555 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
3557 if (h
->plt
.offset
!= (bfd_vma
) -1)
3559 bfd_vma plt_index
, plt_offset
;
3561 Elf_Internal_Rela rel
;
3563 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
3565 /* When building a static executable, use .iplt, .igot.plt and
3566 .rel.iplt sections for STT_GNU_IFUNC symbols. */
3567 if (htab
->elf
.splt
!= NULL
)
3569 plt
= htab
->elf
.splt
;
3570 gotplt
= htab
->elf
.sgotplt
;
3571 relplt
= htab
->elf
.srelplt
;
3575 plt
= htab
->elf
.iplt
;
3576 gotplt
= htab
->elf
.igotplt
;
3577 relplt
= htab
->elf
.irelplt
;
3580 VERIFY_PLT_ENTRY (info
, h
, plt
, gotplt
, relplt
, local_undefweak
)
3582 /* Get the index in the procedure linkage table which
3583 corresponds to this symbol. This is the index of this symbol
3584 in all the symbols for which we are making plt entries. The
3585 first entry in the procedure linkage table is reserved.
3587 Get the offset into the .got table of the entry that
3588 corresponds to this function. Each .got entry is 4 bytes.
3589 The first three are reserved.
3591 For static executables, we don't reserve anything. */
3593 if (plt
== htab
->elf
.splt
)
3595 got_offset
= (h
->plt
.offset
/ plt_entry_size
3596 - htab
->plt
.has_plt0
);
3597 got_offset
= (got_offset
+ 3) * 4;
3601 got_offset
= h
->plt
.offset
/ plt_entry_size
;
3602 got_offset
= got_offset
* 4;
3605 /* Fill in the entry in the procedure linkage table and update
3607 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
3612 const bfd_byte
*plt_entry
;
3613 if (bfd_link_pic (info
))
3614 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3616 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3617 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
3618 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
3620 resolved_plt
= htab
->plt_second
;
3621 plt_offset
= eh
->plt_second
.offset
;
3626 plt_offset
= h
->plt
.offset
;
3629 if (! bfd_link_pic (info
))
3631 bfd_put_32 (output_bfd
,
3632 (gotplt
->output_section
->vma
3633 + gotplt
->output_offset
3635 resolved_plt
->contents
+ plt_offset
3636 + htab
->plt
.plt_got_offset
);
3638 if (htab
->is_vxworks
)
3640 int s
, k
, reloc_index
;
3642 /* Create the R_386_32 relocation referencing the GOT
3643 for this PLT entry. */
3645 /* S: Current slot number (zero-based). */
3646 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
3647 / htab
->plt
.plt_entry_size
);
3648 /* K: Number of relocations for PLTResolve. */
3649 if (bfd_link_pic (info
))
3650 k
= PLTRESOLVE_RELOCS_SHLIB
;
3652 k
= PLTRESOLVE_RELOCS
;
3653 /* Skip the PLTresolve relocations, and the relocations for
3654 the other PLT slots. */
3655 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3656 loc
= (htab
->srelplt2
->contents
+ reloc_index
3657 * sizeof (Elf32_External_Rel
));
3659 rel
.r_offset
= (plt
->output_section
->vma
3660 + plt
->output_offset
3661 + h
->plt
.offset
+ 2),
3662 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3663 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3665 /* Create the R_386_32 relocation referencing the beginning of
3666 the PLT for this GOT entry. */
3667 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3668 + htab
->elf
.sgotplt
->output_offset
3670 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3671 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3672 loc
+ sizeof (Elf32_External_Rel
));
3677 bfd_put_32 (output_bfd
, got_offset
,
3678 resolved_plt
->contents
+ plt_offset
3679 + htab
->plt
.plt_got_offset
);
3682 /* Fill in the entry in the global offset table. Leave the entry
3683 as zero for undefined weak symbol in PIE. No PLT relocation
3684 against undefined weak symbol in PIE. */
3685 if (!local_undefweak
)
3687 if (htab
->plt
.has_plt0
)
3688 bfd_put_32 (output_bfd
,
3689 (plt
->output_section
->vma
3690 + plt
->output_offset
3692 + htab
->lazy_plt
->plt_lazy_offset
),
3693 gotplt
->contents
+ got_offset
);
3695 /* Fill in the entry in the .rel.plt section. */
3696 rel
.r_offset
= (gotplt
->output_section
->vma
3697 + gotplt
->output_offset
3699 if (PLT_LOCAL_IFUNC_P (info
, h
))
3701 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3702 h
->root
.root
.string
,
3703 h
->root
.u
.def
.section
->owner
);
3705 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3706 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
3707 in the .got.plt section. */
3708 bfd_put_32 (output_bfd
,
3709 (h
->root
.u
.def
.value
3710 + h
->root
.u
.def
.section
->output_section
->vma
3711 + h
->root
.u
.def
.section
->output_offset
),
3712 gotplt
->contents
+ got_offset
);
3713 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3714 /* R_386_IRELATIVE comes last. */
3715 plt_index
= htab
->next_irelative_index
--;
3719 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3720 plt_index
= htab
->next_jump_slot_index
++;
3723 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3724 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3726 /* Don't fill the second and third slots in PLT entry for
3727 static executables nor without PLT0. */
3728 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
3730 bfd_put_32 (output_bfd
,
3731 plt_index
* sizeof (Elf32_External_Rel
),
3732 plt
->contents
+ h
->plt
.offset
3733 + htab
->lazy_plt
->plt_reloc_offset
);
3734 bfd_put_32 (output_bfd
,
3736 + htab
->lazy_plt
->plt_plt_offset
+ 4),
3737 (plt
->contents
+ h
->plt
.offset
3738 + htab
->lazy_plt
->plt_plt_offset
));
3742 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
3744 bfd_vma got_offset
, plt_offset
;
3745 asection
*plt
, *got
, *gotplt
;
3746 const bfd_byte
*got_plt_entry
;
3748 /* Set the entry in the GOT procedure linkage table. */
3749 plt
= htab
->plt_got
;
3750 got
= htab
->elf
.sgot
;
3751 gotplt
= htab
->elf
.sgotplt
;
3752 got_offset
= h
->got
.offset
;
3754 if (got_offset
== (bfd_vma
) -1
3760 /* Fill in the entry in the GOT procedure linkage table. */
3761 if (! bfd_link_pic (info
))
3763 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3764 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
3768 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3769 got_offset
+= (got
->output_section
->vma
3770 + got
->output_offset
3771 - gotplt
->output_section
->vma
3772 - gotplt
->output_offset
);
3775 plt_offset
= eh
->plt_got
.offset
;
3776 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
3777 htab
->non_lazy_plt
->plt_entry_size
);
3778 bfd_put_32 (output_bfd
, got_offset
,
3779 (plt
->contents
+ plt_offset
3780 + htab
->non_lazy_plt
->plt_got_offset
));
3783 if (!local_undefweak
3785 && (h
->plt
.offset
!= (bfd_vma
) -1
3786 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
3788 /* Mark the symbol as undefined, rather than as defined in
3789 the .plt section. Leave the value if there were any
3790 relocations where pointer equality matters (this is a clue
3791 for the dynamic linker, to make function pointer
3792 comparisons work between an application and shared
3793 library), otherwise set it to zero. If a function is only
3794 called from a binary, there is no need to slow down
3795 shared libraries because of that. */
3796 sym
->st_shndx
= SHN_UNDEF
;
3797 if (!h
->pointer_equality_needed
)
3801 /* Don't generate dynamic GOT relocation against undefined weak
3802 symbol in executable. */
3803 if (h
->got
.offset
!= (bfd_vma
) -1
3804 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h
)->tls_type
)
3805 && (elf_x86_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
3806 && !local_undefweak
)
3808 Elf_Internal_Rela rel
;
3809 asection
*relgot
= htab
->elf
.srelgot
;
3811 /* This symbol has an entry in the global offset table. Set it
3814 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
3817 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3818 + htab
->elf
.sgot
->output_offset
3819 + (h
->got
.offset
& ~(bfd_vma
) 1));
3821 /* If this is a static link, or it is a -Bsymbolic link and the
3822 symbol is defined locally or was forced to be local because
3823 of a version file, we just want to emit a RELATIVE reloc.
3824 The entry in the global offset table will already have been
3825 initialized in the relocate_section function. */
3827 && h
->type
== STT_GNU_IFUNC
)
3829 if (h
->plt
.offset
== (bfd_vma
) -1)
3831 /* STT_GNU_IFUNC is referenced without PLT. */
3832 if (htab
->elf
.splt
== NULL
)
3834 /* use .rel[a].iplt section to store .got relocations
3835 in static executable. */
3836 relgot
= htab
->elf
.irelplt
;
3838 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3840 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3841 h
->root
.root
.string
,
3842 h
->root
.u
.def
.section
->owner
);
3844 bfd_put_32 (output_bfd
,
3845 (h
->root
.u
.def
.value
3846 + h
->root
.u
.def
.section
->output_section
->vma
3847 + h
->root
.u
.def
.section
->output_offset
),
3848 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3849 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3854 else if (bfd_link_pic (info
))
3856 /* Generate R_386_GLOB_DAT. */
3864 if (!h
->pointer_equality_needed
)
3867 /* For non-shared object, we can't use .got.plt, which
3868 contains the real function addres if we need pointer
3869 equality. We load the GOT entry with the PLT entry. */
3870 if (htab
->plt_second
!= NULL
)
3872 plt
= htab
->plt_second
;
3873 plt_offset
= eh
->plt_second
.offset
;
3877 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3878 plt_offset
= h
->plt
.offset
;
3880 bfd_put_32 (output_bfd
,
3881 (plt
->output_section
->vma
3882 + plt
->output_offset
+ plt_offset
),
3883 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3887 else if (bfd_link_pic (info
)
3888 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3890 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3891 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3895 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3897 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3898 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3899 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3902 elf_append_rel (output_bfd
, relgot
, &rel
);
3907 Elf_Internal_Rela rel
;
3910 /* This symbol needs a copy reloc. Set it up. */
3911 VERIFY_COPY_RELOC (h
, htab
)
3913 rel
.r_offset
= (h
->root
.u
.def
.value
3914 + h
->root
.u
.def
.section
->output_section
->vma
3915 + h
->root
.u
.def
.section
->output_offset
);
3916 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
3917 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
3918 s
= htab
->elf
.sreldynrelro
;
3920 s
= htab
->elf
.srelbss
;
3921 elf_append_rel (output_bfd
, s
, &rel
);
3927 /* Finish up local dynamic symbol handling. We set the contents of
3928 various dynamic sections here. */
3931 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
3933 struct elf_link_hash_entry
*h
3934 = (struct elf_link_hash_entry
*) *slot
;
3935 struct bfd_link_info
*info
3936 = (struct bfd_link_info
*) inf
;
3938 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
3942 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
3943 here since undefined weak symbol may not be dynamic and may not be
3944 called for elf_i386_finish_dynamic_symbol. */
3947 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
3950 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
3951 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3953 if (h
->root
.type
!= bfd_link_hash_undefweak
3954 || h
->dynindx
!= -1)
3957 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
3961 /* Used to decide how to sort relocs in an optimal manner for the
3962 dynamic linker, before writing them out. */
3964 static enum elf_reloc_type_class
3965 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
3966 const asection
*rel_sec ATTRIBUTE_UNUSED
,
3967 const Elf_Internal_Rela
*rela
)
3969 bfd
*abfd
= info
->output_bfd
;
3970 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3971 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3973 if (htab
->dynsym
!= NULL
3974 && htab
->dynsym
->contents
!= NULL
)
3976 /* Check relocation against STT_GNU_IFUNC symbol if there are
3978 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
3979 if (r_symndx
!= STN_UNDEF
)
3981 Elf_Internal_Sym sym
;
3982 if (!bed
->s
->swap_symbol_in (abfd
,
3983 (htab
->dynsym
->contents
3984 + r_symndx
* sizeof (Elf32_External_Sym
)),
3988 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
3989 return reloc_class_ifunc
;
3993 switch (ELF32_R_TYPE (rela
->r_info
))
3995 case R_386_IRELATIVE
:
3996 return reloc_class_ifunc
;
3997 case R_386_RELATIVE
:
3998 return reloc_class_relative
;
3999 case R_386_JUMP_SLOT
:
4000 return reloc_class_plt
;
4002 return reloc_class_copy
;
4004 return reloc_class_normal
;
4008 /* Finish up the dynamic sections. */
4011 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4012 struct bfd_link_info
*info
)
4014 struct elf_x86_link_hash_table
*htab
;
4017 const struct elf_i386_backend_data
*abed
;
4019 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
4023 dynobj
= htab
->elf
.dynobj
;
4024 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4025 abed
= get_elf_i386_backend_data (output_bfd
);
4027 if (htab
->elf
.dynamic_sections_created
)
4029 Elf32_External_Dyn
*dyncon
, *dynconend
;
4031 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4034 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4035 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4036 for (; dyncon
< dynconend
; dyncon
++)
4038 Elf_Internal_Dyn dyn
;
4041 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4046 if (htab
->is_vxworks
4047 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4052 s
= htab
->elf
.sgotplt
;
4053 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4057 s
= htab
->elf
.srelplt
;
4058 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4062 s
= htab
->elf
.srelplt
;
4063 dyn
.d_un
.d_val
= s
->size
;
4067 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4070 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4072 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4073 really seem like the right value. */
4074 elf_section_data (htab
->elf
.splt
->output_section
)
4075 ->this_hdr
.sh_entsize
= 4;
4077 if (htab
->plt
.has_plt0
)
4079 /* Fill in the special first entry in the procedure linkage
4081 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
4082 htab
->lazy_plt
->plt0_entry_size
);
4083 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
4084 abed
->plt0_pad_byte
,
4085 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
4086 if (!bfd_link_pic (info
))
4088 bfd_put_32 (output_bfd
,
4089 (htab
->elf
.sgotplt
->output_section
->vma
4090 + htab
->elf
.sgotplt
->output_offset
4092 htab
->elf
.splt
->contents
4093 + htab
->lazy_plt
->plt0_got1_offset
);
4094 bfd_put_32 (output_bfd
,
4095 (htab
->elf
.sgotplt
->output_section
->vma
4096 + htab
->elf
.sgotplt
->output_offset
4098 htab
->elf
.splt
->contents
4099 + htab
->lazy_plt
->plt0_got2_offset
);
4101 if (htab
->is_vxworks
)
4103 Elf_Internal_Rela rel
;
4104 int num_plts
= (htab
->elf
.splt
->size
4105 / htab
->plt
.plt_entry_size
) - 1;
4107 asection
*srelplt2
= htab
->srelplt2
;
4109 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4110 + 4. On IA32 we use REL relocations so the
4111 addend goes in the PLT directly. */
4112 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4113 + htab
->elf
.splt
->output_offset
4114 + htab
->lazy_plt
->plt0_got1_offset
);
4115 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4117 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4118 srelplt2
->contents
);
4119 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4121 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4122 + htab
->elf
.splt
->output_offset
4123 + htab
->lazy_plt
->plt0_got2_offset
);
4124 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4126 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4127 srelplt2
->contents
+
4128 sizeof (Elf32_External_Rel
));
4129 /* Correct the .rel.plt.unloaded relocations. */
4130 p
= srelplt2
->contents
;
4131 if (bfd_link_pic (info
))
4132 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4134 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4136 for (; num_plts
; num_plts
--)
4138 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4139 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4141 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4142 p
+= sizeof (Elf32_External_Rel
);
4144 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4145 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
4147 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4148 p
+= sizeof (Elf32_External_Rel
);
4155 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
4156 elf_section_data (htab
->plt_got
->output_section
)
4157 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4159 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
4160 elf_section_data (htab
->plt_second
->output_section
)
4161 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4164 /* Fill in the first three entries in the global offset table. */
4165 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
4167 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4170 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4174 bfd_put_32 (output_bfd
,
4176 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4177 htab
->elf
.sgotplt
->contents
);
4178 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4179 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4181 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4184 /* Adjust .eh_frame for .plt section. */
4185 if (htab
->plt_eh_frame
!= NULL
4186 && htab
->plt_eh_frame
->contents
!= NULL
)
4188 if (htab
->elf
.splt
!= NULL
4189 && htab
->elf
.splt
->size
!= 0
4190 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4191 && htab
->elf
.splt
->output_section
!= NULL
4192 && htab
->plt_eh_frame
->output_section
!= NULL
)
4194 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4195 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4196 + htab
->plt_eh_frame
->output_offset
4197 + PLT_FDE_START_OFFSET
;
4198 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4199 htab
->plt_eh_frame
->contents
4200 + PLT_FDE_START_OFFSET
);
4202 if (htab
->plt_eh_frame
->sec_info_type
4203 == SEC_INFO_TYPE_EH_FRAME
)
4205 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4207 htab
->plt_eh_frame
->contents
))
4212 /* Adjust .eh_frame for .plt.got section. */
4213 if (htab
->plt_got_eh_frame
!= NULL
4214 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4216 if (htab
->plt_got
!= NULL
4217 && htab
->plt_got
->size
!= 0
4218 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
4219 && htab
->plt_got
->output_section
!= NULL
4220 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
4222 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
4223 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
4224 + htab
->plt_got_eh_frame
->output_offset
4225 + PLT_FDE_START_OFFSET
;
4226 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4227 htab
->plt_got_eh_frame
->contents
4228 + PLT_FDE_START_OFFSET
);
4230 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4232 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4233 htab
->plt_got_eh_frame
,
4234 htab
->plt_got_eh_frame
->contents
))
4239 /* Adjust .eh_frame for the second PLT section. */
4240 if (htab
->plt_second_eh_frame
!= NULL
4241 && htab
->plt_second_eh_frame
->contents
!= NULL
)
4243 if (htab
->plt_second
!= NULL
4244 && htab
->plt_second
->size
!= 0
4245 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
4246 && htab
->plt_second
->output_section
!= NULL
4247 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
4249 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
4250 bfd_vma eh_frame_start
4251 = (htab
->plt_second_eh_frame
->output_section
->vma
4252 + htab
->plt_second_eh_frame
->output_offset
4253 + PLT_FDE_START_OFFSET
);
4254 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4255 htab
->plt_second_eh_frame
->contents
4256 + PLT_FDE_START_OFFSET
);
4258 if (htab
->plt_second_eh_frame
->sec_info_type
4259 == SEC_INFO_TYPE_EH_FRAME
)
4261 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4262 htab
->plt_second_eh_frame
,
4263 htab
->plt_second_eh_frame
->contents
))
4268 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4269 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4271 /* Fill PLT entries for undefined weak symbols in PIE. */
4272 if (bfd_link_pie (info
))
4273 bfd_hash_traverse (&info
->hash
->table
,
4274 elf_i386_pie_finish_undefweak_symbol
,
4280 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4281 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4282 It has to be done before elf_link_sort_relocs is called so that
4283 dynamic relocations are properly sorted. */
4286 elf_i386_output_arch_local_syms
4287 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4288 struct bfd_link_info
*info
,
4289 void *flaginfo ATTRIBUTE_UNUSED
,
4290 int (*func
) (void *, const char *,
4293 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4295 struct elf_x86_link_hash_table
*htab
4296 = elf_x86_hash_table (info
, I386_ELF_DATA
);
4300 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4301 htab_traverse (htab
->loc_hash_table
,
4302 elf_i386_finish_local_dynamic_symbol
,
4308 /* Forward declaration. */
4309 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
;
4311 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4312 dynamic relocations. */
4315 elf_i386_get_synthetic_symtab (bfd
*abfd
,
4316 long symcount ATTRIBUTE_UNUSED
,
4317 asymbol
**syms ATTRIBUTE_UNUSED
,
4324 bfd_byte
*plt_contents
;
4326 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4327 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4328 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4329 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4332 enum elf_x86_plt_type plt_type
;
4333 struct elf_x86_plt plts
[] =
4335 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4336 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4337 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4338 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4343 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4346 if (dynsymcount
<= 0)
4349 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4353 non_lazy_plt
= NULL
;
4354 /* Silence GCC 6. */
4356 non_lazy_ibt_plt
= NULL
;
4357 lazy_ibt_plt
= NULL
;
4358 switch (get_elf_i386_backend_data (abfd
)->os
)
4361 non_lazy_plt
= &elf_i386_non_lazy_plt
;
4362 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4363 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4366 lazy_plt
= &elf_i386_lazy_plt
;
4369 lazy_plt
= &elf_i386_nacl_plt
;
4376 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4378 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4379 if (plt
== NULL
|| plt
->size
== 0)
4382 /* Get the PLT section contents. */
4383 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
4384 if (plt_contents
== NULL
)
4386 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
4387 plt_contents
, 0, plt
->size
))
4389 free (plt_contents
);
4393 /* Check what kind of PLT it is. */
4394 plt_type
= plt_unknown
;
4395 if (plts
[j
].type
== plt_unknown
4396 && (plt
->size
>= (lazy_plt
->plt0_entry_size
4397 + lazy_plt
->plt_entry_size
)))
4399 /* Match lazy PLT first. */
4400 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4401 lazy_plt
->plt0_got1_offset
) == 0)
4403 /* The fist entry in the lazy IBT PLT is the same as the
4405 if (lazy_ibt_plt
!= NULL
4406 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4407 lazy_ibt_plt
->plt_entry
,
4408 lazy_ibt_plt
->plt_got_offset
) == 0))
4409 plt_type
= plt_lazy
| plt_second
;
4411 plt_type
= plt_lazy
;
4413 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
4414 lazy_plt
->plt0_got1_offset
) == 0)
4416 /* The fist entry in the PIC lazy IBT PLT is the same as
4417 the normal PIC lazy PLT. */
4418 if (lazy_ibt_plt
!= NULL
4419 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4420 lazy_ibt_plt
->pic_plt_entry
,
4421 lazy_ibt_plt
->plt_got_offset
) == 0))
4422 plt_type
= plt_lazy
| plt_pic
| plt_second
;
4424 plt_type
= plt_lazy
| plt_pic
;
4428 if (non_lazy_plt
!= NULL
4429 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
4430 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
4432 /* Match non-lazy PLT. */
4433 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
4434 non_lazy_plt
->plt_got_offset
) == 0)
4435 plt_type
= plt_non_lazy
;
4436 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
4437 non_lazy_plt
->plt_got_offset
) == 0)
4441 if ((non_lazy_ibt_plt
!= NULL
)
4442 && (plt_type
== plt_unknown
|| plt_type
== plt_second
)
4443 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
)
4445 if (memcmp (plt_contents
,
4446 non_lazy_ibt_plt
->plt_entry
,
4447 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4449 /* Match IBT PLT. */
4450 plt_type
= plt_second
;
4451 non_lazy_plt
= non_lazy_ibt_plt
;
4453 else if (memcmp (plt_contents
,
4454 non_lazy_ibt_plt
->pic_plt_entry
,
4455 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4457 /* Match PIC IBT PLT. */
4458 plt_type
= plt_second
| plt_pic
;
4459 non_lazy_plt
= non_lazy_ibt_plt
;
4463 if (plt_type
== plt_unknown
)
4465 free (plt_contents
);
4470 plts
[j
].type
= plt_type
;
4472 if ((plt_type
& plt_lazy
))
4474 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
4475 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
4476 /* Skip PLT0 in lazy PLT. */
4481 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
4482 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
4486 /* Skip lazy PLT when the second PLT is used. */
4487 if ((plt_type
& (plt_lazy
| plt_second
))
4488 == (plt_lazy
| plt_second
))
4492 n
= plt
->size
/ plts
[j
].plt_entry_size
;
4497 plts
[j
].contents
= plt_contents
;
4499 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
4500 if ((plt_type
& plt_pic
))
4501 got_addr
= (bfd_vma
) -1;
4504 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
4505 got_addr
, plts
, dynsyms
,
4509 /* Set up i386 GNU properties. Return the first relocatable ELF input
4510 with GNU properties if found. Otherwise, return NULL. */
4513 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
4515 struct elf_x86_init_table init_table
;
4517 init_table
.normal_target
= FALSE
;
4518 init_table
.is_vxworks
= FALSE
;
4519 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
4522 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4523 init_table
.non_lazy_plt
= &elf_i386_non_lazy_plt
;
4524 init_table
.lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4525 init_table
.non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4526 init_table
.normal_target
= TRUE
;
4529 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4530 init_table
.non_lazy_plt
= NULL
;
4531 init_table
.lazy_ibt_plt
= NULL
;
4532 init_table
.non_lazy_ibt_plt
= NULL
;
4533 init_table
.is_vxworks
= TRUE
;
4536 init_table
.lazy_plt
= &elf_i386_nacl_plt
;
4537 init_table
.non_lazy_plt
= NULL
;
4538 init_table
.lazy_ibt_plt
= NULL
;
4539 init_table
.non_lazy_ibt_plt
= NULL
;
4543 init_table
.r_info
= elf32_r_info
;
4544 init_table
.r_sym
= elf32_r_sym
;
4546 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
4549 #define TARGET_LITTLE_SYM i386_elf32_vec
4550 #define TARGET_LITTLE_NAME "elf32-i386"
4551 #define ELF_ARCH bfd_arch_i386
4552 #define ELF_TARGET_ID I386_ELF_DATA
4553 #define ELF_MACHINE_CODE EM_386
4554 #define ELF_MAXPAGESIZE 0x1000
4556 #define elf_backend_can_gc_sections 1
4557 #define elf_backend_can_refcount 1
4558 #define elf_backend_want_got_plt 1
4559 #define elf_backend_plt_readonly 1
4560 #define elf_backend_want_plt_sym 0
4561 #define elf_backend_got_header_size 12
4562 #define elf_backend_plt_alignment 4
4563 #define elf_backend_dtrel_excludes_plt 1
4564 #define elf_backend_extern_protected_data 1
4565 #define elf_backend_caches_rawsize 1
4566 #define elf_backend_want_dynrelro 1
4568 /* Support RELA for objdump of prelink objects. */
4569 #define elf_info_to_howto elf_i386_info_to_howto_rel
4570 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4572 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4573 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4574 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4575 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
4577 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4578 #define elf_backend_check_relocs elf_i386_check_relocs
4579 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
4580 #define elf_backend_fake_sections elf_i386_fake_sections
4581 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4582 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4583 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
4584 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4585 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4586 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4587 #define elf_backend_relocate_section elf_i386_relocate_section
4588 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
4590 #include "elf32-target.h"
4592 /* FreeBSD support. */
4594 #undef TARGET_LITTLE_SYM
4595 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
4596 #undef TARGET_LITTLE_NAME
4597 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4599 #define ELF_OSABI ELFOSABI_FREEBSD
4601 /* The kernel recognizes executables as valid only if they carry a
4602 "FreeBSD" label in the ELF header. So we put this label on all
4603 executables and (for simplicity) also all other object files. */
4606 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4608 _bfd_elf_post_process_headers (abfd
, info
);
4610 #ifdef OLD_FREEBSD_ABI_LABEL
4612 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4613 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
4614 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4619 #undef elf_backend_post_process_headers
4620 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4622 #define elf32_bed elf32_i386_fbsd_bed
4624 #undef elf_backend_add_symbol_hook
4626 #include "elf32-target.h"
4630 #undef TARGET_LITTLE_SYM
4631 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
4632 #undef TARGET_LITTLE_NAME
4633 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
4635 #undef elf_backend_post_process_headers
4637 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4638 objects won't be recognized. */
4642 #define elf32_bed elf32_i386_sol2_bed
4644 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
4646 #undef elf_backend_static_tls_alignment
4647 #define elf_backend_static_tls_alignment 8
4649 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4651 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4653 #undef elf_backend_want_plt_sym
4654 #define elf_backend_want_plt_sym 1
4656 #undef elf_backend_strtab_flags
4657 #define elf_backend_strtab_flags SHF_STRINGS
4659 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
4660 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
4661 FALSE otherwise. ISECTION is the best guess matching section from the
4662 input bfd IBFD, but it might be NULL. */
4665 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
4666 bfd
*obfd ATTRIBUTE_UNUSED
,
4667 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
4668 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
4670 /* PR 19938: FIXME: Need to add code for setting the sh_info
4671 and sh_link fields of Solaris specific section types. */
4674 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
4675 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
4677 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
4679 The following values should be set:
4682 -----------------------------------------------------------------------------
4683 SHT_SUNW_ancillary The section header index of 0
4684 [0x6fffffee] the associated string table.
4686 SHT_SUNW_capinfo The section header index of For a dynamic object, the
4687 [0x6ffffff0] the associated symbol table. section header index of
4689 SHT_SUNW_capchain table,
4692 SHT_SUNW_symsort The section header index of 0
4693 [0x6ffffff1] the associated symbol table.
4695 SHT_SUNW_tlssort The section header index of 0
4696 [0x6ffffff2] the associated symbol table.
4698 SHT_SUNW_LDYNSYM The section header index of One greater than the
4699 [0x6ffffff3] the associated string table. symbol table index of the
4700 This index is the same string last local symbol,
4701 table used by the SHT_DYNSYM STB_LOCAL. Since
4702 section. SHT_SUNW_LDYNSYM only
4703 contains local symbols,
4704 sh_info is equivalent to
4705 the number of symbols in
4708 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
4709 [0x6ffffff5] the section header index of to named strings, the
4710 the associated section header index of
4711 SHT_SUNW_capinfo table, the associated string
4712 otherwise 0. table, otherwise 0.
4714 SHT_SUNW_move The section header index of 0
4715 [0x6ffffffa] the associated symbol table.
4720 SHT_SUNW_syminfo The section header index of The section header index
4721 [0x6ffffffc] the associated symbol table. of the associated
4724 SHT_SUNW_verdef The section header index of The number of version
4725 [0x6ffffffd] the associated string table. definitions within the
4728 SHT_SUNW_verneed The section header index of The number of version
4729 [0x6ffffffe] the associated string table. dependencies within the
4732 SHT_SUNW_versym The section header index of 0
4733 [0x6fffffff] the associated symbol table. */
4736 #undef elf_backend_copy_special_section_fields
4737 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
4739 #include "elf32-target.h"
4741 /* Intel MCU support. */
4744 elf32_iamcu_elf_object_p (bfd
*abfd
)
4746 /* Set the right machine number for an IAMCU elf32 file. */
4747 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
4751 #undef TARGET_LITTLE_SYM
4752 #define TARGET_LITTLE_SYM iamcu_elf32_vec
4753 #undef TARGET_LITTLE_NAME
4754 #define TARGET_LITTLE_NAME "elf32-iamcu"
4756 #define ELF_ARCH bfd_arch_iamcu
4758 #undef ELF_MACHINE_CODE
4759 #define ELF_MACHINE_CODE EM_IAMCU
4764 #define elf32_bed elf32_iamcu_bed
4766 #undef elf_backend_object_p
4767 #define elf_backend_object_p elf32_iamcu_elf_object_p
4769 #undef elf_backend_static_tls_alignment
4771 #undef elf_backend_want_plt_sym
4772 #define elf_backend_want_plt_sym 0
4774 #undef elf_backend_strtab_flags
4775 #undef elf_backend_copy_special_section_fields
4777 #include "elf32-target.h"
4779 /* Restore defaults. */
4781 #define ELF_ARCH bfd_arch_i386
4782 #undef ELF_MACHINE_CODE
4783 #define ELF_MACHINE_CODE EM_386
4785 /* Native Client support. */
4787 #undef TARGET_LITTLE_SYM
4788 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
4789 #undef TARGET_LITTLE_NAME
4790 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
4792 #define elf32_bed elf32_i386_nacl_bed
4794 #undef ELF_MAXPAGESIZE
4795 #define ELF_MAXPAGESIZE 0x10000
4797 /* Restore defaults. */
4799 #undef elf_backend_want_plt_sym
4800 #define elf_backend_want_plt_sym 0
4801 #undef elf_backend_post_process_headers
4802 #undef elf_backend_static_tls_alignment
4804 /* NaCl uses substantially different PLT entries for the same effects. */
4806 #undef elf_backend_plt_alignment
4807 #define elf_backend_plt_alignment 5
4808 #define NACL_PLT_ENTRY_SIZE 64
4809 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
4811 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
4813 0xff, 0x35, /* pushl contents of address */
4814 0, 0, 0, 0, /* replaced with address of .got + 4. */
4815 0x8b, 0x0d, /* movl contents of address, %ecx */
4816 0, 0, 0, 0, /* replaced with address of .got + 8. */
4817 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
4818 0xff, 0xe1 /* jmp *%ecx */
4821 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
4823 0x8b, 0x0d, /* movl contents of address, %ecx */
4824 0, 0, 0, 0, /* replaced with GOT slot address. */
4825 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
4826 0xff, 0xe1, /* jmp *%ecx */
4828 /* Pad to the next 32-byte boundary with nop instructions. */
4830 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4831 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4833 /* Lazy GOT entries point here (32-byte aligned). */
4834 0x68, /* pushl immediate */
4835 0, 0, 0, 0, /* replaced with reloc offset. */
4836 0xe9, /* jmp relative */
4837 0, 0, 0, 0, /* replaced with offset to .plt. */
4839 /* Pad to the next 32-byte boundary with nop instructions. */
4840 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4841 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4845 static const bfd_byte
4846 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
4848 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
4849 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
4850 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
4851 0xff, 0xe1, /* jmp *%ecx */
4853 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
4854 so pad to that size with nop instructions. */
4855 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
4858 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
4860 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
4861 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
4862 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
4863 0xff, 0xe1, /* jmp *%ecx */
4865 /* Pad to the next 32-byte boundary with nop instructions. */
4867 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4868 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4870 /* Lazy GOT entries point here (32-byte aligned). */
4871 0x68, /* pushl immediate */
4872 0, 0, 0, 0, /* replaced with offset into relocation table. */
4873 0xe9, /* jmp relative */
4874 0, 0, 0, 0, /* replaced with offset to start of .plt. */
4876 /* Pad to the next 32-byte boundary with nop instructions. */
4877 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4878 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4882 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
4884 #if (PLT_CIE_LENGTH != 20 \
4885 || PLT_FDE_LENGTH != 36 \
4886 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
4887 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
4888 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
4890 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
4891 0, 0, 0, 0, /* CIE ID */
4892 1, /* CIE version */
4893 'z', 'R', 0, /* Augmentation string */
4894 1, /* Code alignment factor */
4895 0x7c, /* Data alignment factor: -4 */
4896 8, /* Return address column */
4897 1, /* Augmentation size */
4898 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
4899 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
4900 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
4901 DW_CFA_nop
, DW_CFA_nop
,
4903 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
4904 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
4905 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
4906 0, 0, 0, 0, /* .plt size goes here */
4907 0, /* Augmentation size */
4908 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
4909 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
4910 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
4911 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
4912 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
4913 13, /* Block length */
4914 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
4915 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
4916 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
4917 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
4918 DW_CFA_nop
, DW_CFA_nop
4921 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
=
4923 elf_i386_nacl_plt0_entry
, /* plt0_entry */
4924 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
4925 elf_i386_nacl_plt_entry
, /* plt_entry */
4926 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
4927 2, /* plt0_got1_offset */
4928 8, /* plt0_got2_offset */
4929 0, /* plt0_got2_insn_end */
4930 2, /* plt_got_offset */
4931 33, /* plt_reloc_offset */
4932 38, /* plt_plt_offset */
4933 0, /* plt_got_insn_size */
4934 0, /* plt_plt_insn_end */
4935 32, /* plt_lazy_offset */
4936 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
4937 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
4938 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
4939 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
4942 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
4944 0x90, /* plt0_pad_byte: nop insn */
4949 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
4951 /* Set the right machine number for a NaCl i386 ELF32 file. */
4952 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
4956 #undef elf_backend_arch_data
4957 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
4959 #undef elf_backend_object_p
4960 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
4961 #undef elf_backend_modify_segment_map
4962 #define elf_backend_modify_segment_map nacl_modify_segment_map
4963 #undef elf_backend_modify_program_headers
4964 #define elf_backend_modify_program_headers nacl_modify_program_headers
4965 #undef elf_backend_final_write_processing
4966 #define elf_backend_final_write_processing nacl_final_write_processing
4968 #include "elf32-target.h"
4970 /* Restore defaults. */
4971 #undef elf_backend_object_p
4972 #undef elf_backend_modify_segment_map
4973 #undef elf_backend_modify_program_headers
4974 #undef elf_backend_final_write_processing
4976 /* VxWorks support. */
4978 #undef TARGET_LITTLE_SYM
4979 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
4980 #undef TARGET_LITTLE_NAME
4981 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4983 #undef ELF_MAXPAGESIZE
4984 #define ELF_MAXPAGESIZE 0x1000
4985 #undef elf_backend_plt_alignment
4986 #define elf_backend_plt_alignment 4
4988 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
4990 0x90, /* plt0_pad_byte */
4994 #undef elf_backend_arch_data
4995 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
4997 #undef elf_backend_relocs_compatible
4998 #undef elf_backend_add_symbol_hook
4999 #define elf_backend_add_symbol_hook \
5000 elf_vxworks_add_symbol_hook
5001 #undef elf_backend_link_output_symbol_hook
5002 #define elf_backend_link_output_symbol_hook \
5003 elf_vxworks_link_output_symbol_hook
5004 #undef elf_backend_emit_relocs
5005 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5006 #undef elf_backend_final_write_processing
5007 #define elf_backend_final_write_processing \
5008 elf_vxworks_final_write_processing
5009 #undef elf_backend_static_tls_alignment
5011 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5013 #undef elf_backend_want_plt_sym
5014 #define elf_backend_want_plt_sym 1
5017 #define elf32_bed elf32_i386_vxworks_bed
5019 #include "elf32-target.h"