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 #ifdef DEBUG_GEN_RELOC
189 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
194 static reloc_howto_type
*
195 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
196 bfd_reloc_code_real_type code
)
201 TRACE ("BFD_RELOC_NONE");
202 return &elf_howto_table
[R_386_NONE
];
205 TRACE ("BFD_RELOC_32");
206 return &elf_howto_table
[R_386_32
];
209 TRACE ("BFD_RELOC_CTOR");
210 return &elf_howto_table
[R_386_32
];
212 case BFD_RELOC_32_PCREL
:
213 TRACE ("BFD_RELOC_PC32");
214 return &elf_howto_table
[R_386_PC32
];
216 case BFD_RELOC_386_GOT32
:
217 TRACE ("BFD_RELOC_386_GOT32");
218 return &elf_howto_table
[R_386_GOT32
];
220 case BFD_RELOC_386_PLT32
:
221 TRACE ("BFD_RELOC_386_PLT32");
222 return &elf_howto_table
[R_386_PLT32
];
224 case BFD_RELOC_386_COPY
:
225 TRACE ("BFD_RELOC_386_COPY");
226 return &elf_howto_table
[R_386_COPY
];
228 case BFD_RELOC_386_GLOB_DAT
:
229 TRACE ("BFD_RELOC_386_GLOB_DAT");
230 return &elf_howto_table
[R_386_GLOB_DAT
];
232 case BFD_RELOC_386_JUMP_SLOT
:
233 TRACE ("BFD_RELOC_386_JUMP_SLOT");
234 return &elf_howto_table
[R_386_JUMP_SLOT
];
236 case BFD_RELOC_386_RELATIVE
:
237 TRACE ("BFD_RELOC_386_RELATIVE");
238 return &elf_howto_table
[R_386_RELATIVE
];
240 case BFD_RELOC_386_GOTOFF
:
241 TRACE ("BFD_RELOC_386_GOTOFF");
242 return &elf_howto_table
[R_386_GOTOFF
];
244 case BFD_RELOC_386_GOTPC
:
245 TRACE ("BFD_RELOC_386_GOTPC");
246 return &elf_howto_table
[R_386_GOTPC
];
248 /* These relocs are a GNU extension. */
249 case BFD_RELOC_386_TLS_TPOFF
:
250 TRACE ("BFD_RELOC_386_TLS_TPOFF");
251 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
253 case BFD_RELOC_386_TLS_IE
:
254 TRACE ("BFD_RELOC_386_TLS_IE");
255 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
257 case BFD_RELOC_386_TLS_GOTIE
:
258 TRACE ("BFD_RELOC_386_TLS_GOTIE");
259 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
261 case BFD_RELOC_386_TLS_LE
:
262 TRACE ("BFD_RELOC_386_TLS_LE");
263 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
265 case BFD_RELOC_386_TLS_GD
:
266 TRACE ("BFD_RELOC_386_TLS_GD");
267 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
269 case BFD_RELOC_386_TLS_LDM
:
270 TRACE ("BFD_RELOC_386_TLS_LDM");
271 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
274 TRACE ("BFD_RELOC_16");
275 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
277 case BFD_RELOC_16_PCREL
:
278 TRACE ("BFD_RELOC_16_PCREL");
279 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
282 TRACE ("BFD_RELOC_8");
283 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
285 case BFD_RELOC_8_PCREL
:
286 TRACE ("BFD_RELOC_8_PCREL");
287 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
289 /* Common with Sun TLS implementation. */
290 case BFD_RELOC_386_TLS_LDO_32
:
291 TRACE ("BFD_RELOC_386_TLS_LDO_32");
292 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
294 case BFD_RELOC_386_TLS_IE_32
:
295 TRACE ("BFD_RELOC_386_TLS_IE_32");
296 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
298 case BFD_RELOC_386_TLS_LE_32
:
299 TRACE ("BFD_RELOC_386_TLS_LE_32");
300 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
302 case BFD_RELOC_386_TLS_DTPMOD32
:
303 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
304 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
306 case BFD_RELOC_386_TLS_DTPOFF32
:
307 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
308 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
310 case BFD_RELOC_386_TLS_TPOFF32
:
311 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
312 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
314 case BFD_RELOC_SIZE32
:
315 TRACE ("BFD_RELOC_SIZE32");
316 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
318 case BFD_RELOC_386_TLS_GOTDESC
:
319 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
320 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
322 case BFD_RELOC_386_TLS_DESC_CALL
:
323 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
324 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
326 case BFD_RELOC_386_TLS_DESC
:
327 TRACE ("BFD_RELOC_386_TLS_DESC");
328 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
330 case BFD_RELOC_386_IRELATIVE
:
331 TRACE ("BFD_RELOC_386_IRELATIVE");
332 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
334 case BFD_RELOC_386_GOT32X
:
335 TRACE ("BFD_RELOC_386_GOT32X");
336 return &elf_howto_table
[R_386_GOT32X
- R_386_tls_offset
];
338 case BFD_RELOC_VTABLE_INHERIT
:
339 TRACE ("BFD_RELOC_VTABLE_INHERIT");
340 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
342 case BFD_RELOC_VTABLE_ENTRY
:
343 TRACE ("BFD_RELOC_VTABLE_ENTRY");
344 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
354 static reloc_howto_type
*
355 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
360 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
361 if (elf_howto_table
[i
].name
!= NULL
362 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
363 return &elf_howto_table
[i
];
368 static reloc_howto_type
*
369 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
373 if ((indx
= r_type
) >= R_386_standard
374 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
375 >= R_386_ext
- R_386_standard
)
376 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
377 >= R_386_ext2
- R_386_ext
)
378 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
379 >= R_386_vt
- R_386_ext2
))
381 /* xgettext:c-format */
382 _bfd_error_handler (_("%B: invalid relocation type %d"),
386 /* PR 17512: file: 0f67f69d. */
387 if (elf_howto_table
[indx
].type
!= r_type
)
389 return &elf_howto_table
[indx
];
393 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
395 Elf_Internal_Rela
*dst
)
397 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
398 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
401 /* Return whether a symbol name implies a local label. The UnixWare
402 2.1 cc generates temporary symbols that start with .X, so we
403 recognize them here. FIXME: do other SVR4 compilers also use .X?.
404 If so, we should move the .X recognition into
405 _bfd_elf_is_local_label_name. */
408 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
410 if (name
[0] == '.' && name
[1] == 'X')
413 return _bfd_elf_is_local_label_name (abfd
, name
);
416 /* Support for core dump NOTE sections. */
419 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
424 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
426 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
432 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
435 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
439 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
443 switch (note
->descsz
)
448 case 144: /* Linux/i386 */
450 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
453 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
463 /* Make a ".reg/999" section. */
464 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
465 size
, note
->descpos
+ offset
);
469 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
471 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
473 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
478 elf_tdata (abfd
)->core
->program
479 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
480 elf_tdata (abfd
)->core
->command
481 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
485 switch (note
->descsz
)
490 case 124: /* Linux/i386 elf_prpsinfo. */
491 elf_tdata (abfd
)->core
->pid
492 = bfd_get_32 (abfd
, note
->descdata
+ 12);
493 elf_tdata (abfd
)->core
->program
494 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
495 elf_tdata (abfd
)->core
->command
496 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
500 /* Note that for some reason, a spurious space is tacked
501 onto the end of the args in some (at least one anyway)
502 implementations, so strip it off if it exists. */
504 char *command
= elf_tdata (abfd
)->core
->command
;
505 int n
= strlen (command
);
507 if (0 < n
&& command
[n
- 1] == ' ')
508 command
[n
- 1] = '\0';
514 /* Functions for the i386 ELF linker.
516 In order to gain some understanding of code in this file without
517 knowing all the intricate details of the linker, note the
520 Functions named elf_i386_* are called by external routines, other
521 functions are only called locally. elf_i386_* functions appear
522 in this file more or less in the order in which they are called
523 from external routines. eg. elf_i386_check_relocs is called
524 early in the link process, elf_i386_finish_dynamic_sections is
525 one of the last functions. */
527 /* The size in bytes of an entry in the lazy procedure linkage table. */
529 #define LAZY_PLT_ENTRY_SIZE 16
531 /* The size in bytes of an entry in the non-lazy procedure linkage
534 #define NON_LAZY_PLT_ENTRY_SIZE 8
536 /* The first entry in an absolute lazy procedure linkage table looks
537 like this. See the SVR4 ABI i386 supplement to see how this works.
538 Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
540 static const bfd_byte elf_i386_lazy_plt0_entry
[12] =
542 0xff, 0x35, /* pushl contents of address */
543 0, 0, 0, 0, /* replaced with address of .got + 4. */
544 0xff, 0x25, /* jmp indirect */
545 0, 0, 0, 0 /* replaced with address of .got + 8. */
548 /* Subsequent entries in an absolute lazy procedure linkage table look
551 static const bfd_byte elf_i386_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
553 0xff, 0x25, /* jmp indirect */
554 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
555 0x68, /* pushl immediate */
556 0, 0, 0, 0, /* replaced with offset into relocation table. */
557 0xe9, /* jmp relative */
558 0, 0, 0, 0 /* replaced with offset to start of .plt. */
561 /* The first entry in a PIC lazy procedure linkage table look like
562 this. Will be padded to LAZY_PLT_ENTRY_SIZE with
563 lazy_plt->plt0_pad_byte. */
565 static const bfd_byte elf_i386_pic_lazy_plt0_entry
[12] =
567 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
568 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
571 /* Subsequent entries in a PIC lazy procedure linkage table look like
574 static const bfd_byte elf_i386_pic_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
576 0xff, 0xa3, /* jmp *offset(%ebx) */
577 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
578 0x68, /* pushl immediate */
579 0, 0, 0, 0, /* replaced with offset into relocation table. */
580 0xe9, /* jmp relative */
581 0, 0, 0, 0 /* replaced with offset to start of .plt. */
584 /* Entries in the non-lazy procedure linkage table look like this. */
586 static const bfd_byte elf_i386_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
588 0xff, 0x25, /* jmp indirect */
589 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
590 0x66, 0x90 /* xchg %ax,%ax */
593 /* Entries in the PIC non-lazy procedure linkage table look like
596 static const bfd_byte elf_i386_pic_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
598 0xff, 0xa3, /* jmp *offset(%ebx) */
599 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
600 0x66, 0x90 /* xchg %ax,%ax */
603 /* The first entry in an absolute IBT-enabled lazy procedure linkage
604 table looks like this. */
606 static const bfd_byte elf_i386_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
608 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
609 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
610 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
613 /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
614 table look like this. Subsequent entries for a PIC IBT-enabled lazy
615 procedure linkage table are the same. */
617 static const bfd_byte elf_i386_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
619 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
620 0x68, 0, 0, 0, 0, /* pushl immediate */
621 0xe9, 0, 0, 0, 0, /* jmp relative */
622 0x66, 0x90 /* xchg %ax,%ax */
625 /* The first entry in a PIC IBT-enabled lazy procedure linkage table
628 static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
630 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
631 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
632 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
635 /* Entries for branches with IBT-enabled in the absolute non-lazey
636 procedure linkage table look like this. They have the same size
637 as the lazy PLT entry. */
639 static const bfd_byte elf_i386_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
641 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
642 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
643 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
646 /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
647 linkage table look like this. They have the same size as the lazy
650 static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
652 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
653 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
654 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
657 /* .eh_frame covering the lazy .plt section. */
659 static const bfd_byte elf_i386_eh_frame_lazy_plt
[] =
661 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
662 0, 0, 0, 0, /* CIE ID */
664 'z', 'R', 0, /* Augmentation string */
665 1, /* Code alignment factor */
666 0x7c, /* Data alignment factor */
667 8, /* Return address column */
668 1, /* Augmentation size */
669 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
670 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
671 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
672 DW_CFA_nop
, DW_CFA_nop
,
674 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
675 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
676 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
677 0, 0, 0, 0, /* .plt size goes here */
678 0, /* Augmentation size */
679 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
680 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
681 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
682 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
683 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
684 11, /* Block length */
685 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
686 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
687 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
688 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
689 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
692 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
694 static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt
[] =
696 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
697 0, 0, 0, 0, /* CIE ID */
699 'z', 'R', 0, /* Augmentation string */
700 1, /* Code alignment factor */
701 0x7c, /* Data alignment factor */
702 8, /* Return address column */
703 1, /* Augmentation size */
704 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
705 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
706 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
707 DW_CFA_nop
, DW_CFA_nop
,
709 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
710 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
711 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
712 0, 0, 0, 0, /* .plt size goes here */
713 0, /* Augmentation size */
714 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
715 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
716 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
717 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
718 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
719 11, /* Block length */
720 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
721 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
722 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
723 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
724 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
727 /* .eh_frame covering the non-lazy .plt section. */
729 static const bfd_byte elf_i386_eh_frame_non_lazy_plt
[] =
731 #define PLT_GOT_FDE_LENGTH 16
732 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
733 0, 0, 0, 0, /* CIE ID */
735 'z', 'R', 0, /* Augmentation string */
736 1, /* Code alignment factor */
737 0x7c, /* Data alignment factor */
738 8, /* Return address column */
739 1, /* Augmentation size */
740 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
741 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
742 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
743 DW_CFA_nop
, DW_CFA_nop
,
745 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
746 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
747 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
748 0, 0, 0, 0, /* non-lazy .plt size goes here */
749 0, /* Augmentation size */
750 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
753 /* These are the standard parameters. */
754 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt
=
756 elf_i386_lazy_plt0_entry
, /* plt0_entry */
757 sizeof (elf_i386_lazy_plt0_entry
), /* plt0_entry_size */
758 elf_i386_lazy_plt_entry
, /* plt_entry */
759 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
760 2, /* plt0_got1_offset */
761 8, /* plt0_got2_offset */
762 0, /* plt0_got2_insn_end */
763 2, /* plt_got_offset */
764 7, /* plt_reloc_offset */
765 12, /* plt_plt_offset */
766 0, /* plt_got_insn_size */
767 0, /* plt_plt_insn_end */
768 6, /* plt_lazy_offset */
769 elf_i386_pic_lazy_plt0_entry
, /* pic_plt0_entry */
770 elf_i386_pic_lazy_plt_entry
, /* pic_plt_entry */
771 elf_i386_eh_frame_lazy_plt
, /* eh_frame_plt */
772 sizeof (elf_i386_eh_frame_lazy_plt
) /* eh_frame_plt_size */
775 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt
=
777 elf_i386_non_lazy_plt_entry
, /* plt_entry */
778 elf_i386_pic_non_lazy_plt_entry
, /* pic_plt_entry */
779 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
780 2, /* plt_got_offset */
781 0, /* plt_got_insn_size */
782 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
783 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
786 static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt
=
788 elf_i386_lazy_ibt_plt0_entry
, /* plt0_entry */
789 sizeof (elf_i386_lazy_ibt_plt0_entry
), /* plt0_entry_size */
790 elf_i386_lazy_ibt_plt_entry
, /* plt_entry */
791 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
792 2, /* plt0_got1_offset */
793 8, /* plt0_got2_offset */
794 0, /* plt0_got2_insn_end */
795 4+2, /* plt_got_offset */
796 4+1, /* plt_reloc_offset */
797 4+6, /* plt_plt_offset */
798 0, /* plt_got_insn_size */
799 0, /* plt_plt_insn_end */
800 0, /* plt_lazy_offset */
801 elf_i386_pic_lazy_ibt_plt0_entry
, /* pic_plt0_entry */
802 elf_i386_lazy_ibt_plt_entry
, /* pic_plt_entry */
803 elf_i386_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
804 sizeof (elf_i386_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
807 static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt
=
809 elf_i386_non_lazy_ibt_plt_entry
, /* plt_entry */
810 elf_i386_pic_non_lazy_ibt_plt_entry
,/* pic_plt_entry */
811 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
812 4+2, /* plt_got_offset */
813 0, /* plt_got_insn_size */
814 elf_i386_eh_frame_non_lazy_plt
, /* eh_frame_plt */
815 sizeof (elf_i386_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
819 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
820 for the PLTResolve stub and then for each PLT entry. */
821 #define PLTRESOLVE_RELOCS_SHLIB 0
822 #define PLTRESOLVE_RELOCS 2
823 #define PLT_NON_JUMP_SLOT_RELOCS 2
825 /* Architecture-specific backend data for i386. */
827 struct elf_i386_backend_data
829 /* Value used to fill the unused bytes of the first PLT entry. */
830 bfd_byte plt0_pad_byte
;
841 #define get_elf_i386_backend_data(abfd) \
842 ((const struct elf_i386_backend_data *) \
843 get_elf_backend_data (abfd)->arch_data)
845 /* These are the standard parameters. */
846 static const struct elf_i386_backend_data elf_i386_arch_bed
=
848 0, /* plt0_pad_byte */
852 #define elf_backend_arch_data &elf_i386_arch_bed
854 /* Return TRUE if the TLS access code sequence support transition
858 elf_i386_check_tls_transition (asection
*sec
,
860 Elf_Internal_Shdr
*symtab_hdr
,
861 struct elf_link_hash_entry
**sym_hashes
,
863 const Elf_Internal_Rela
*rel
,
864 const Elf_Internal_Rela
*relend
)
866 unsigned int val
, type
, reg
;
867 unsigned long r_symndx
;
868 struct elf_link_hash_entry
*h
;
871 bfd_boolean indirect_call
;
873 offset
= rel
->r_offset
;
878 if (offset
< 2 || (rel
+ 1) >= relend
)
881 indirect_call
= FALSE
;
882 call
= contents
+ offset
+ 4;
885 if (r_type
== R_386_TLS_GD
)
887 /* Check transition from GD access model. Only
888 leal foo@tlsgd(,%ebx,1), %eax
889 call ___tls_get_addr@PLT
891 leal foo@tlsgd(%ebx) %eax
892 call ___tls_get_addr@PLT
895 leal foo@tlsgd(%reg), %eax
896 call *___tls_get_addr@GOT(%reg)
897 which may be converted to
898 addr32 call ___tls_get_addr
899 can transit to different access model. */
900 if ((offset
+ 10) > sec
->size
901 || (type
!= 0x8d && type
!= 0x04))
906 /* leal foo@tlsgd(,%ebx,1), %eax
907 call ___tls_get_addr@PLT */
911 if (*(call
- 7) != 0x8d
919 leal foo@tlsgd(%ebx), %eax
920 call ___tls_get_addr@PLT
923 leal foo@tlsgd(%reg), %eax
924 call *___tls_get_addr@GOT(%reg)
925 which may be converted to
926 addr32 call ___tls_get_addr
928 %eax can't be used as the GOT base register since it
929 is used to pass parameter to ___tls_get_addr. */
931 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
934 indirect_call
= call
[0] == 0xff;
935 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
936 && !(call
[0] == 0x67 && call
[1] == 0xe8)
938 && (call
[1] & 0xf8) == 0x90
939 && (call
[1] & 0x7) == reg
))
945 /* Check transition from LD access model. Only
946 leal foo@tlsldm(%ebx), %eax
947 call ___tls_get_addr@PLT
949 leal foo@tlsldm(%reg), %eax
950 call *___tls_get_addr@GOT(%reg)
951 which may be converted to
952 addr32 call ___tls_get_addr
953 can transit to different access model. */
954 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
957 /* %eax can't be used as the GOT base register since it is
958 used to pass parameter to ___tls_get_addr. */
960 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
963 indirect_call
= call
[0] == 0xff;
964 if (!(reg
== 3 && call
[0] == 0xe8)
965 && !(call
[0] == 0x67 && call
[1] == 0xe8)
967 && (call
[1] & 0xf8) == 0x90
968 && (call
[1] & 0x7) == reg
))
972 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
973 if (r_symndx
< symtab_hdr
->sh_info
)
976 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
978 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
980 else if (indirect_call
)
981 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
983 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
984 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
987 /* Check transition from IE access model:
988 movl foo@indntpoff(%rip), %eax
989 movl foo@indntpoff(%rip), %reg
990 addl foo@indntpoff(%rip), %reg
993 if (offset
< 1 || (offset
+ 4) > sec
->size
)
996 /* Check "movl foo@tpoff(%rip), %eax" first. */
997 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1004 /* Check movl|addl foo@tpoff(%rip), %reg. */
1005 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1006 return ((type
== 0x8b || type
== 0x03)
1007 && (val
& 0xc7) == 0x05);
1009 case R_386_TLS_GOTIE
:
1010 case R_386_TLS_IE_32
:
1011 /* Check transition from {IE_32,GOTIE} access model:
1012 subl foo@{tpoff,gontoff}(%reg1), %reg2
1013 movl foo@{tpoff,gontoff}(%reg1), %reg2
1014 addl foo@{tpoff,gontoff}(%reg1), %reg2
1017 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1020 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1021 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1024 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1025 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1027 case R_386_TLS_GOTDESC
:
1028 /* Check transition from GDesc access model:
1029 leal x@tlsdesc(%ebx), %eax
1031 Make sure it's a leal adding ebx to a 32-bit offset
1032 into any register, although it's probably almost always
1035 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1038 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1041 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1042 return (val
& 0xc7) == 0x83;
1044 case R_386_TLS_DESC_CALL
:
1045 /* Check transition from GDesc access model:
1046 call *x@tlsdesc(%eax)
1048 if (offset
+ 2 <= sec
->size
)
1050 /* Make sure that it's a call *x@tlsdesc(%eax). */
1051 call
= contents
+ offset
;
1052 return call
[0] == 0xff && call
[1] == 0x10;
1062 /* Return TRUE if the TLS access transition is OK or no transition
1063 will be performed. Update R_TYPE if there is a transition. */
1066 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1067 asection
*sec
, bfd_byte
*contents
,
1068 Elf_Internal_Shdr
*symtab_hdr
,
1069 struct elf_link_hash_entry
**sym_hashes
,
1070 unsigned int *r_type
, int tls_type
,
1071 const Elf_Internal_Rela
*rel
,
1072 const Elf_Internal_Rela
*relend
,
1073 struct elf_link_hash_entry
*h
,
1074 unsigned long r_symndx
,
1075 bfd_boolean from_relocate_section
)
1077 unsigned int from_type
= *r_type
;
1078 unsigned int to_type
= from_type
;
1079 bfd_boolean check
= TRUE
;
1081 /* Skip TLS transition for functions. */
1083 && (h
->type
== STT_FUNC
1084 || h
->type
== STT_GNU_IFUNC
))
1090 case R_386_TLS_GOTDESC
:
1091 case R_386_TLS_DESC_CALL
:
1092 case R_386_TLS_IE_32
:
1094 case R_386_TLS_GOTIE
:
1095 if (bfd_link_executable (info
))
1098 to_type
= R_386_TLS_LE_32
;
1099 else if (from_type
!= R_386_TLS_IE
1100 && from_type
!= R_386_TLS_GOTIE
)
1101 to_type
= R_386_TLS_IE_32
;
1104 /* When we are called from elf_i386_relocate_section, there may
1105 be additional transitions based on TLS_TYPE. */
1106 if (from_relocate_section
)
1108 unsigned int new_to_type
= to_type
;
1110 if (TLS_TRANSITION_IE_TO_LE_P (info
, h
, tls_type
))
1111 new_to_type
= R_386_TLS_LE_32
;
1113 if (to_type
== R_386_TLS_GD
1114 || to_type
== R_386_TLS_GOTDESC
1115 || to_type
== R_386_TLS_DESC_CALL
)
1117 if (tls_type
== GOT_TLS_IE_POS
)
1118 new_to_type
= R_386_TLS_GOTIE
;
1119 else if (tls_type
& GOT_TLS_IE
)
1120 new_to_type
= R_386_TLS_IE_32
;
1123 /* We checked the transition before when we were called from
1124 elf_i386_check_relocs. We only want to check the new
1125 transition which hasn't been checked before. */
1126 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1127 to_type
= new_to_type
;
1133 if (bfd_link_executable (info
))
1134 to_type
= R_386_TLS_LE_32
;
1141 /* Return TRUE if there is no transition. */
1142 if (from_type
== to_type
)
1145 /* Check if the transition can be performed. */
1147 && ! elf_i386_check_tls_transition (sec
, contents
,
1148 symtab_hdr
, sym_hashes
,
1149 from_type
, rel
, relend
))
1151 reloc_howto_type
*from
, *to
;
1154 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1155 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1158 name
= h
->root
.root
.string
;
1161 struct elf_x86_link_hash_table
*htab
;
1163 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1168 Elf_Internal_Sym
*isym
;
1170 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1172 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1177 /* xgettext:c-format */
1178 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1179 "in section `%A' failed"),
1180 abfd
, from
->name
, to
->name
, name
,
1181 rel
->r_offset
, sec
);
1182 bfd_set_error (bfd_error_bad_value
);
1190 /* With the local symbol, foo, we convert
1191 mov foo@GOT[(%reg1)], %reg2
1193 lea foo[@GOTOFF(%reg1)], %reg2
1195 call/jmp *foo@GOT[(%reg)]
1197 nop call foo/jmp foo nop
1198 When PIC is false, convert
1199 test %reg1, foo@GOT[(%reg2)]
1203 binop foo@GOT[(%reg1)], %reg2
1206 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1211 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1213 unsigned int *r_type_p
,
1214 Elf_Internal_Rela
*irel
,
1215 struct elf_link_hash_entry
*h
,
1216 bfd_boolean
*converted
,
1217 struct bfd_link_info
*link_info
)
1219 struct elf_x86_link_hash_table
*htab
;
1220 unsigned int opcode
;
1222 bfd_boolean baseless
;
1223 Elf_Internal_Sym
*isym
;
1224 unsigned int addend
;
1228 bfd_boolean to_reloc_32
;
1229 unsigned int r_type
;
1230 unsigned int r_symndx
;
1231 bfd_vma roff
= irel
->r_offset
;
1232 bfd_boolean local_ref
;
1233 struct elf_x86_link_hash_entry
*eh
;
1238 /* Addend for R_386_GOT32X relocations must be 0. */
1239 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1243 htab
= elf_x86_hash_table (link_info
, I386_ELF_DATA
);
1244 is_pic
= bfd_link_pic (link_info
);
1247 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1249 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1250 baseless
= (modrm
& 0xc7) == 0x5;
1252 if (baseless
&& is_pic
)
1254 /* For PIC, disallow R_386_GOT32X without a base register
1255 since we don't know what the GOT base is. */
1260 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1262 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1265 name
= h
->root
.root
.string
;
1268 /* xgettext:c-format */
1269 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1270 " register can not be used when making a shared object"),
1275 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1277 /* Convert to R_386_32 if PIC is false or there is no base
1279 to_reloc_32
= !is_pic
|| baseless
;
1281 eh
= elf_x86_hash_entry (h
);
1283 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1287 if (opcode
== 0x0ff)
1288 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1289 goto convert_branch
;
1291 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1292 "test %reg1, foo@GOT(%reg2)" and
1293 "binop foo@GOT[(%reg1)], %reg2". */
1297 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1298 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1300 /* Undefined weak symbol is only bound locally in executable
1301 and its reference is resolved as 0. */
1302 if (h
->root
.type
== bfd_link_hash_undefweak
1308 /* No direct branch to 0 for PIC. */
1312 goto convert_branch
;
1316 /* We can convert load of address 0 to R_386_32. */
1324 /* We have "call/jmp *foo@GOT[(%reg)]". */
1325 if ((h
->root
.type
== bfd_link_hash_defined
1326 || h
->root
.type
== bfd_link_hash_defweak
)
1329 /* The function is locally defined. */
1331 /* Convert R_386_GOT32X to R_386_PC32. */
1332 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1334 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1337 /* To support TLS optimization, always use addr32 prefix
1338 for "call *___tls_get_addr@GOT(%reg)". */
1339 if (eh
&& eh
->tls_get_addr
)
1342 nop_offset
= irel
->r_offset
- 2;
1346 nop
= link_info
->call_nop_byte
;
1347 if (link_info
->call_nop_as_suffix
)
1349 nop_offset
= roff
+ 3;
1350 irel
->r_offset
-= 1;
1353 nop_offset
= roff
- 2;
1358 /* Convert to "jmp foo nop". */
1361 nop_offset
= roff
+ 3;
1362 irel
->r_offset
-= 1;
1365 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1366 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1367 /* When converting to PC-relative relocation, we
1368 need to adjust addend by -4. */
1369 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1370 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1371 *r_type_p
= R_386_PC32
;
1377 /* We have "mov foo@GOT[(%re1g)], %reg2",
1378 "test %reg1, foo@GOT(%reg2)" and
1379 "binop foo@GOT[(%reg1)], %reg2".
1381 Avoid optimizing _DYNAMIC since ld.so may use its
1382 link-time address. */
1383 if (h
== htab
->elf
.hdynamic
)
1386 /* def_regular is set by an assignment in a linker script in
1387 bfd_elf_record_link_assignment. start_stop is set on
1388 __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
1392 || h
->root
.type
== bfd_link_hash_defined
1393 || h
->root
.type
== bfd_link_hash_defweak
)
1401 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1402 "mov $foo, %reg2" with R_386_32. */
1404 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1405 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1410 /* Convert "mov foo@GOT(%reg1), %reg2" to
1411 "lea foo@GOTOFF(%reg1), %reg2". */
1412 r_type
= R_386_GOTOFF
;
1418 /* Only R_386_32 is supported. */
1424 /* Convert "test %reg1, foo@GOT(%reg2)" to
1425 "test $foo, %reg1". */
1426 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1431 /* Convert "binop foo@GOT(%reg1), %reg2" to
1432 "binop $foo, %reg2". */
1434 | (modrm
& 0x38) >> 3
1438 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1442 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1443 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1452 /* Rename some of the generic section flags to better document how they
1454 #define check_relocs_failed sec_flg0
1456 /* Look through the relocs for a section during the first phase, and
1457 calculate needed space in the global offset table, procedure linkage
1458 table, and dynamic reloc sections. */
1461 elf_i386_check_relocs (bfd
*abfd
,
1462 struct bfd_link_info
*info
,
1464 const Elf_Internal_Rela
*relocs
)
1466 struct elf_x86_link_hash_table
*htab
;
1467 Elf_Internal_Shdr
*symtab_hdr
;
1468 struct elf_link_hash_entry
**sym_hashes
;
1469 const Elf_Internal_Rela
*rel
;
1470 const Elf_Internal_Rela
*rel_end
;
1473 bfd_boolean converted
;
1475 if (bfd_link_relocatable (info
))
1478 /* Don't do anything special with non-loaded, non-alloced sections.
1479 In particular, any relocs in such sections should not affect GOT
1480 and PLT reference counting (ie. we don't allow them to create GOT
1481 or PLT entries), there's no possibility or desire to optimize TLS
1482 relocs, and there's not much point in propagating relocs to shared
1483 libs that the dynamic linker won't relocate. */
1484 if ((sec
->flags
& SEC_ALLOC
) == 0)
1487 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
1490 sec
->check_relocs_failed
= 1;
1494 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1496 /* Get the section contents. */
1497 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1498 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1499 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1501 sec
->check_relocs_failed
= 1;
1505 symtab_hdr
= &elf_symtab_hdr (abfd
);
1506 sym_hashes
= elf_sym_hashes (abfd
);
1512 rel_end
= relocs
+ sec
->reloc_count
;
1513 for (rel
= relocs
; rel
< rel_end
; rel
++)
1515 unsigned int r_type
;
1516 unsigned int r_symndx
;
1517 struct elf_link_hash_entry
*h
;
1518 struct elf_x86_link_hash_entry
*eh
;
1519 Elf_Internal_Sym
*isym
;
1521 bfd_boolean size_reloc
;
1523 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1524 r_type
= ELF32_R_TYPE (rel
->r_info
);
1526 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1528 /* xgettext:c-format */
1529 _bfd_error_handler (_("%B: bad symbol index: %d"),
1534 if (r_symndx
< symtab_hdr
->sh_info
)
1536 /* A local symbol. */
1537 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1542 /* Check relocation against local STT_GNU_IFUNC symbol. */
1543 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1545 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1549 /* Fake a STT_GNU_IFUNC symbol. */
1550 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1552 h
->type
= STT_GNU_IFUNC
;
1555 h
->forced_local
= 1;
1556 h
->root
.type
= bfd_link_hash_defined
;
1564 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1565 while (h
->root
.type
== bfd_link_hash_indirect
1566 || h
->root
.type
== bfd_link_hash_warning
)
1567 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1570 eh
= (struct elf_x86_link_hash_entry
*) h
;
1573 if (r_type
== R_386_GOTOFF
)
1576 /* It is referenced by a non-shared object. */
1578 h
->root
.non_ir_ref_regular
= 1;
1580 if (h
->type
== STT_GNU_IFUNC
)
1581 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1582 |= elf_gnu_symbol_ifunc
;
1585 if (r_type
== R_386_GOT32X
1586 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1588 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
1589 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
1595 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1596 symtab_hdr
, sym_hashes
,
1597 &r_type
, GOT_UNKNOWN
,
1598 rel
, rel_end
, h
, r_symndx
, FALSE
))
1604 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1608 /* This symbol requires a procedure linkage table entry. We
1609 actually build the entry in adjust_dynamic_symbol,
1610 because this might be a case of linking PIC code which is
1611 never referenced by a dynamic object, in which case we
1612 don't need to generate a procedure linkage table entry
1615 /* If this is a local symbol, we resolve it directly without
1616 creating a procedure linkage table entry. */
1620 eh
->has_got_reloc
= 1;
1622 h
->plt
.refcount
+= 1;
1629 case R_386_TLS_IE_32
:
1631 case R_386_TLS_GOTIE
:
1632 if (!bfd_link_executable (info
))
1633 info
->flags
|= DF_STATIC_TLS
;
1639 case R_386_TLS_GOTDESC
:
1640 case R_386_TLS_DESC_CALL
:
1641 /* This symbol requires a global offset table entry. */
1643 int tls_type
, old_tls_type
;
1650 tls_type
= GOT_NORMAL
;
1652 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1653 case R_386_TLS_GOTDESC
:
1654 case R_386_TLS_DESC_CALL
:
1655 tls_type
= GOT_TLS_GDESC
; break;
1656 case R_386_TLS_IE_32
:
1657 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1658 tls_type
= GOT_TLS_IE_NEG
;
1660 /* If this is a GD->IE transition, we may use either of
1661 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1662 tls_type
= GOT_TLS_IE
;
1665 case R_386_TLS_GOTIE
:
1666 tls_type
= GOT_TLS_IE_POS
; break;
1671 h
->got
.refcount
+= 1;
1672 old_tls_type
= elf_x86_hash_entry (h
)->tls_type
;
1676 bfd_signed_vma
*local_got_refcounts
;
1678 /* This is a global offset table entry for a local symbol. */
1679 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1680 if (local_got_refcounts
== NULL
)
1684 size
= symtab_hdr
->sh_info
;
1685 size
*= (sizeof (bfd_signed_vma
)
1686 + sizeof (bfd_vma
) + sizeof(char));
1687 local_got_refcounts
= (bfd_signed_vma
*)
1688 bfd_zalloc (abfd
, size
);
1689 if (local_got_refcounts
== NULL
)
1691 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1692 elf_x86_local_tlsdesc_gotent (abfd
)
1693 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1694 elf_x86_local_got_tls_type (abfd
)
1695 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1697 local_got_refcounts
[r_symndx
] += 1;
1698 old_tls_type
= elf_x86_local_got_tls_type (abfd
) [r_symndx
];
1701 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1702 tls_type
|= old_tls_type
;
1703 /* If a TLS symbol is accessed using IE at least once,
1704 there is no point to use dynamic model for it. */
1705 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1706 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1707 || (tls_type
& GOT_TLS_IE
) == 0))
1709 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1710 tls_type
= old_tls_type
;
1711 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1712 && GOT_TLS_GD_ANY_P (tls_type
))
1713 tls_type
|= old_tls_type
;
1717 name
= h
->root
.root
.string
;
1719 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1722 /* xgettext:c-format */
1723 (_("%B: `%s' accessed both as normal and "
1724 "thread local symbol"),
1726 bfd_set_error (bfd_error_bad_value
);
1731 if (old_tls_type
!= tls_type
)
1734 elf_x86_hash_entry (h
)->tls_type
= tls_type
;
1736 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1744 if (r_type
!= R_386_TLS_IE
)
1747 eh
->has_got_reloc
= 1;
1752 case R_386_TLS_LE_32
:
1755 eh
->has_got_reloc
= 1;
1756 if (bfd_link_executable (info
))
1758 info
->flags
|= DF_STATIC_TLS
;
1763 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
1764 eh
->has_non_got_reloc
= 1;
1766 /* We are called after all symbols have been resolved. Only
1767 relocation against STT_GNU_IFUNC symbol must go through
1770 && (bfd_link_executable (info
)
1771 || h
->type
== STT_GNU_IFUNC
))
1773 /* If this reloc is in a read-only section, we might
1774 need a copy reloc. We can't check reliably at this
1775 stage whether the section is read-only, as input
1776 sections have not yet been mapped to output sections.
1777 Tentatively set the flag for now, and correct in
1778 adjust_dynamic_symbol. */
1781 /* We may need a .plt entry if the symbol is a function
1782 defined in a shared lib or is a STT_GNU_IFUNC function
1783 referenced from the code or read-only section. */
1785 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
1786 h
->plt
.refcount
+= 1;
1788 if (r_type
== R_386_PC32
)
1790 /* Since something like ".long foo - ." may be used
1791 as pointer, make sure that PLT is used if foo is
1792 a function defined in a shared library. */
1793 if ((sec
->flags
& SEC_CODE
) == 0)
1794 h
->pointer_equality_needed
= 1;
1795 else if (h
->type
== STT_GNU_IFUNC
1796 && bfd_link_pic (info
))
1799 /* xgettext:c-format */
1800 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
1801 abfd
, h
->root
.root
.string
);
1802 bfd_set_error (bfd_error_bad_value
);
1808 h
->pointer_equality_needed
= 1;
1809 /* R_386_32 can be resolved at run-time. */
1810 if (r_type
== R_386_32
1811 && (sec
->flags
& SEC_READONLY
) == 0)
1812 eh
->func_pointer_refcount
+= 1;
1818 if (NEED_DYNAMIC_RELOCATION_P (info
, h
, sec
, r_type
,
1821 struct elf_dyn_relocs
*p
;
1822 struct elf_dyn_relocs
**head
;
1824 /* We must copy these reloc types into the output file.
1825 Create a reloc section in dynobj and make room for
1829 sreloc
= _bfd_elf_make_dynamic_reloc_section
1830 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1836 /* If this is a global symbol, we count the number of
1837 relocations we need for this symbol. */
1840 head
= &eh
->dyn_relocs
;
1844 /* Track dynamic relocs needed for local syms too.
1845 We really need local syms available to do this
1850 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1855 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1859 vpp
= &elf_section_data (s
)->local_dynrel
;
1860 head
= (struct elf_dyn_relocs
**)vpp
;
1864 if (p
== NULL
|| p
->sec
!= sec
)
1866 bfd_size_type amt
= sizeof *p
;
1867 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1879 /* Count size relocation as PC-relative relocation. */
1880 if (r_type
== R_386_PC32
|| size_reloc
)
1885 /* This relocation describes the C++ object vtable hierarchy.
1886 Reconstruct it for later use during GC. */
1887 case R_386_GNU_VTINHERIT
:
1888 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1892 /* This relocation describes which C++ vtable entries are actually
1893 used. Record for later use during GC. */
1894 case R_386_GNU_VTENTRY
:
1895 BFD_ASSERT (h
!= NULL
);
1897 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1906 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1908 if (!converted
&& !info
->keep_memory
)
1912 /* Cache the section contents for elf_link_input_bfd if any
1913 load is converted or --no-keep-memory isn't used. */
1914 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1918 /* Cache relocations if any load is converted. */
1919 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
1920 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
1925 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1927 sec
->check_relocs_failed
= 1;
1931 /* Set the correct type for an x86 ELF section. We do this by the
1932 section name, which is a hack, but ought to work. */
1935 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1936 Elf_Internal_Shdr
*hdr
,
1941 name
= bfd_get_section_name (abfd
, sec
);
1943 /* This is an ugly, but unfortunately necessary hack that is
1944 needed when producing EFI binaries on x86. It tells
1945 elf.c:elf_fake_sections() not to consider ".reloc" as a section
1946 containing ELF relocation info. We need this hack in order to
1947 be able to generate ELF binaries that can be translated into
1948 EFI applications (which are essentially COFF objects). Those
1949 files contain a COFF ".reloc" section inside an ELFNN object,
1950 which would normally cause BFD to segfault because it would
1951 attempt to interpret this section as containing relocation
1952 entries for section "oc". With this hack enabled, ".reloc"
1953 will be treated as a normal data section, which will avoid the
1954 segfault. However, you won't be able to create an ELFNN binary
1955 with a section named "oc" that needs relocations, but that's
1956 the kind of ugly side-effects you get when detecting section
1957 types based on their names... In practice, this limitation is
1958 unlikely to bite. */
1959 if (strcmp (name
, ".reloc") == 0)
1960 hdr
->sh_type
= SHT_PROGBITS
;
1965 /* Return the relocation value for @tpoff relocation
1966 if STT_TLS virtual address is ADDRESS. */
1969 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
1971 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1972 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
1973 bfd_vma static_tls_size
;
1975 /* If tls_sec is NULL, we should have signalled an error already. */
1976 if (htab
->tls_sec
== NULL
)
1979 /* Consider special static TLS alignment requirements. */
1980 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
1981 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
1984 /* Relocate an i386 ELF section. */
1987 elf_i386_relocate_section (bfd
*output_bfd
,
1988 struct bfd_link_info
*info
,
1990 asection
*input_section
,
1992 Elf_Internal_Rela
*relocs
,
1993 Elf_Internal_Sym
*local_syms
,
1994 asection
**local_sections
)
1996 struct elf_x86_link_hash_table
*htab
;
1997 Elf_Internal_Shdr
*symtab_hdr
;
1998 struct elf_link_hash_entry
**sym_hashes
;
1999 bfd_vma
*local_got_offsets
;
2000 bfd_vma
*local_tlsdesc_gotents
;
2001 Elf_Internal_Rela
*rel
;
2002 Elf_Internal_Rela
*wrel
;
2003 Elf_Internal_Rela
*relend
;
2004 bfd_boolean is_vxworks_tls
;
2005 unsigned plt_entry_size
;
2007 /* Skip if check_relocs failed. */
2008 if (input_section
->check_relocs_failed
)
2011 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
2015 BFD_ASSERT (is_x86_elf (input_bfd
, htab
));
2017 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2018 sym_hashes
= elf_sym_hashes (input_bfd
);
2019 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2020 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2021 /* We have to handle relocations in vxworks .tls_vars sections
2022 specially, because the dynamic loader is 'weird'. */
2023 is_vxworks_tls
= (htab
->is_vxworks
2024 && bfd_link_pic (info
)
2025 && !strcmp (input_section
->output_section
->name
,
2028 _bfd_x86_elf_set_tls_module_base (info
);
2030 plt_entry_size
= htab
->plt
.plt_entry_size
;
2032 rel
= wrel
= relocs
;
2033 relend
= relocs
+ input_section
->reloc_count
;
2034 for (; rel
< relend
; wrel
++, rel
++)
2036 unsigned int r_type
, r_type_tls
;
2037 reloc_howto_type
*howto
;
2038 unsigned long r_symndx
;
2039 struct elf_link_hash_entry
*h
;
2040 struct elf_x86_link_hash_entry
*eh
;
2041 Elf_Internal_Sym
*sym
;
2043 bfd_vma off
, offplt
, plt_offset
;
2045 bfd_boolean unresolved_reloc
;
2046 bfd_reloc_status_type r
;
2050 asection
*resolved_plt
;
2051 bfd_boolean resolved_to_zero
;
2052 bfd_boolean relative_reloc
;
2054 r_type
= ELF32_R_TYPE (rel
->r_info
);
2055 if (r_type
== R_386_GNU_VTINHERIT
2056 || r_type
== R_386_GNU_VTENTRY
)
2063 if ((indx
= r_type
) >= R_386_standard
2064 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2065 >= R_386_ext
- R_386_standard
)
2066 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2067 >= R_386_ext2
- R_386_ext
))
2068 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2070 howto
= elf_howto_table
+ indx
;
2072 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2076 unresolved_reloc
= FALSE
;
2077 if (r_symndx
< symtab_hdr
->sh_info
)
2079 sym
= local_syms
+ r_symndx
;
2080 sec
= local_sections
[r_symndx
];
2081 relocation
= (sec
->output_section
->vma
2082 + sec
->output_offset
2084 st_size
= sym
->st_size
;
2086 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2087 && ((sec
->flags
& SEC_MERGE
) != 0
2088 || (bfd_link_relocatable (info
)
2089 && sec
->output_offset
!= 0)))
2092 bfd_byte
*where
= contents
+ rel
->r_offset
;
2094 switch (howto
->size
)
2097 addend
= bfd_get_8 (input_bfd
, where
);
2098 if (howto
->pc_relative
)
2100 addend
= (addend
^ 0x80) - 0x80;
2105 addend
= bfd_get_16 (input_bfd
, where
);
2106 if (howto
->pc_relative
)
2108 addend
= (addend
^ 0x8000) - 0x8000;
2113 addend
= bfd_get_32 (input_bfd
, where
);
2114 if (howto
->pc_relative
)
2116 addend
= (addend
^ 0x80000000) - 0x80000000;
2124 if (bfd_link_relocatable (info
))
2125 addend
+= sec
->output_offset
;
2128 asection
*msec
= sec
;
2129 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2131 addend
-= relocation
;
2132 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2135 switch (howto
->size
)
2138 /* FIXME: overflow checks. */
2139 if (howto
->pc_relative
)
2141 bfd_put_8 (input_bfd
, addend
, where
);
2144 if (howto
->pc_relative
)
2146 bfd_put_16 (input_bfd
, addend
, where
);
2149 if (howto
->pc_relative
)
2151 bfd_put_32 (input_bfd
, addend
, where
);
2155 else if (!bfd_link_relocatable (info
)
2156 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2158 /* Relocate against local STT_GNU_IFUNC symbol. */
2159 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
, rel
,
2164 /* Set STT_GNU_IFUNC symbol value. */
2165 h
->root
.u
.def
.value
= sym
->st_value
;
2166 h
->root
.u
.def
.section
= sec
;
2171 bfd_boolean warned ATTRIBUTE_UNUSED
;
2172 bfd_boolean ignored ATTRIBUTE_UNUSED
;
2174 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2175 r_symndx
, symtab_hdr
, sym_hashes
,
2177 unresolved_reloc
, warned
, ignored
);
2181 if (sec
!= NULL
&& discarded_section (sec
))
2183 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2184 contents
+ rel
->r_offset
);
2185 wrel
->r_offset
= rel
->r_offset
;
2189 /* For ld -r, remove relocations in debug sections against
2190 sections defined in discarded sections. Not done for
2191 eh_frame editing code expects to be present. */
2192 if (bfd_link_relocatable (info
)
2193 && (input_section
->flags
& SEC_DEBUGGING
))
2199 if (bfd_link_relocatable (info
))
2206 eh
= (struct elf_x86_link_hash_entry
*) h
;
2208 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2209 it here if it is defined in a non-shared object. */
2211 && h
->type
== STT_GNU_IFUNC
2214 asection
*gotplt
, *base_got
;
2218 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2220 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2221 sections because such sections are not SEC_ALLOC and
2222 thus ld.so will not process them. */
2223 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2228 /* STT_GNU_IFUNC symbol must go through PLT. */
2229 if (htab
->elf
.splt
!= NULL
)
2231 if (htab
->plt_second
!= NULL
)
2233 resolved_plt
= htab
->plt_second
;
2234 plt_offset
= eh
->plt_second
.offset
;
2238 resolved_plt
= htab
->elf
.splt
;
2239 plt_offset
= h
->plt
.offset
;
2241 gotplt
= htab
->elf
.sgotplt
;
2245 resolved_plt
= htab
->elf
.iplt
;
2246 plt_offset
= h
->plt
.offset
;
2247 gotplt
= htab
->elf
.igotplt
;
2257 base_got
= htab
->elf
.sgot
;
2258 off
= h
->got
.offset
;
2260 if (base_got
== NULL
)
2263 if (off
== (bfd_vma
) -1)
2265 /* We can't use h->got.offset here to save state, or
2266 even just remember the offset, as finish_dynamic_symbol
2267 would use that as offset into .got. */
2269 if (h
->plt
.offset
== (bfd_vma
) -1)
2272 if (htab
->elf
.splt
!= NULL
)
2274 plt_index
= (h
->plt
.offset
/ plt_entry_size
2275 - htab
->plt
.has_plt0
);
2276 off
= (plt_index
+ 3) * 4;
2277 base_got
= htab
->elf
.sgotplt
;
2281 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2282 off
= plt_index
* 4;
2283 base_got
= htab
->elf
.igotplt
;
2286 if (h
->dynindx
== -1
2290 /* This references the local defitionion. We must
2291 initialize this entry in the global offset table.
2292 Since the offset must always be a multiple of 8,
2293 we use the least significant bit to record
2294 whether we have initialized it already.
2296 When doing a dynamic link, we create a .rela.got
2297 relocation entry to initialize the value. This
2298 is done in the finish_dynamic_symbol routine. */
2303 bfd_put_32 (output_bfd
, relocation
,
2304 base_got
->contents
+ off
);
2312 relocation
= (base_got
->output_section
->vma
2313 + base_got
->output_offset
+ off
2314 - gotplt
->output_section
->vma
2315 - gotplt
->output_offset
);
2317 if (rel
->r_offset
> 1
2318 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2319 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2321 if (bfd_link_pic (info
))
2322 goto disallow_got32
;
2324 /* Add the GOT base if there is no base register. */
2325 relocation
+= (gotplt
->output_section
->vma
2326 + gotplt
->output_offset
);
2328 else if (htab
->elf
.splt
== NULL
)
2330 /* Adjust for static executables. */
2331 relocation
+= gotplt
->output_offset
;
2337 if (h
->plt
.offset
== (bfd_vma
) -1)
2339 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2340 if (r_type
== R_386_32
2341 && (input_section
->flags
& SEC_CODE
) == 0)
2342 goto do_ifunc_pointer
;
2343 goto bad_ifunc_reloc
;
2346 relocation
= (resolved_plt
->output_section
->vma
2347 + resolved_plt
->output_offset
+ plt_offset
);
2353 if (h
->root
.root
.string
)
2354 name
= h
->root
.root
.string
;
2356 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2359 /* xgettext:c-format */
2360 (_("%B: relocation %s against STT_GNU_IFUNC "
2361 "symbol `%s' isn't supported"), input_bfd
,
2363 bfd_set_error (bfd_error_bad_value
);
2367 /* Generate dynamic relcoation only when there is a
2368 non-GOT reference in a shared object. */
2369 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2370 || h
->plt
.offset
== (bfd_vma
) -1)
2372 Elf_Internal_Rela outrel
;
2377 /* Need a dynamic relocation to get the real function
2379 offset
= _bfd_elf_section_offset (output_bfd
,
2383 if (offset
== (bfd_vma
) -1
2384 || offset
== (bfd_vma
) -2)
2387 outrel
.r_offset
= (input_section
->output_section
->vma
2388 + input_section
->output_offset
2391 if (h
->dynindx
== -1
2393 || bfd_link_executable (info
))
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
;
2517 off
= h
->got
.offset
;
2518 dyn
= htab
->elf
.dynamic_sections_created
;
2519 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2520 bfd_link_pic (info
),
2522 || (bfd_link_pic (info
)
2523 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
2524 || (ELF_ST_VISIBILITY (h
->other
)
2525 && h
->root
.type
== bfd_link_hash_undefweak
))
2527 /* This is actually a static link, or it is a
2528 -Bsymbolic link and the symbol is defined
2529 locally, or the symbol was forced to be local
2530 because of a version file. We must initialize
2531 this entry in the global offset table. Since the
2532 offset must always be a multiple of 4, we use the
2533 least significant bit to record whether we have
2534 initialized it already.
2536 When doing a dynamic link, we create a .rel.got
2537 relocation entry to initialize the value. This
2538 is done in the finish_dynamic_symbol routine. */
2543 bfd_put_32 (output_bfd
, relocation
,
2544 htab
->elf
.sgot
->contents
+ off
);
2547 if (h
->dynindx
== -1
2549 && h
->root
.type
!= bfd_link_hash_undefweak
2550 && bfd_link_pic (info
))
2552 /* PR ld/21402: If this symbol isn't dynamic
2553 in PIC, generate R_386_RELATIVE here. */
2554 eh
->no_finish_dynamic_symbol
= 1;
2555 relative_reloc
= TRUE
;
2560 unresolved_reloc
= FALSE
;
2564 if (local_got_offsets
== NULL
)
2567 off
= local_got_offsets
[r_symndx
];
2569 /* The offset must always be a multiple of 4. We use
2570 the least significant bit to record whether we have
2571 already generated the necessary reloc. */
2576 bfd_put_32 (output_bfd
, relocation
,
2577 htab
->elf
.sgot
->contents
+ off
);
2578 local_got_offsets
[r_symndx
] |= 1;
2580 if (bfd_link_pic (info
))
2581 relative_reloc
= TRUE
;
2588 Elf_Internal_Rela outrel
;
2590 s
= htab
->elf
.srelgot
;
2594 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
2595 + htab
->elf
.sgot
->output_offset
2597 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2598 elf_append_rel (output_bfd
, s
, &outrel
);
2601 if (off
>= (bfd_vma
) -2)
2604 relocation
= (htab
->elf
.sgot
->output_section
->vma
2605 + htab
->elf
.sgot
->output_offset
+ off
);
2606 if (rel
->r_offset
> 1
2607 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
2608 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
2610 if (bfd_link_pic (info
))
2612 /* For PIC, disallow R_386_GOT32 without a base
2613 register, except for "lea foo@GOT, %reg", since
2614 we don't know what the GOT base is. */
2618 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
2619 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2622 name
= h
->root
.root
.string
;
2625 /* xgettext:c-format */
2626 (_("%B: direct GOT relocation %s against `%s'"
2627 " without base register can not be used"
2628 " when making a shared object"),
2629 input_bfd
, howto
->name
, name
);
2630 bfd_set_error (bfd_error_bad_value
);
2636 /* Subtract the .got.plt section address only with a base
2638 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
2639 + htab
->elf
.sgotplt
->output_offset
);
2645 /* Relocation is relative to the start of the global offset
2648 /* Check to make sure it isn't a protected function or data
2649 symbol for shared library since it may not be local when
2650 used as function address or with copy relocation. We also
2651 need to make sure that a symbol is referenced locally. */
2652 if (!bfd_link_executable (info
) && h
)
2654 if (!h
->def_regular
)
2658 switch (ELF_ST_VISIBILITY (h
->other
))
2661 v
= _("hidden symbol");
2664 v
= _("internal symbol");
2667 v
= _("protected symbol");
2675 /* xgettext:c-format */
2676 (_("%B: relocation R_386_GOTOFF against undefined %s"
2677 " `%s' can not be used when making a shared object"),
2678 input_bfd
, v
, h
->root
.root
.string
);
2679 bfd_set_error (bfd_error_bad_value
);
2682 else if (!SYMBOL_REFERENCES_LOCAL_P (info
, h
)
2683 && (h
->type
== STT_FUNC
2684 || h
->type
== STT_OBJECT
)
2685 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2688 /* xgettext:c-format */
2689 (_("%B: relocation R_386_GOTOFF against protected %s"
2690 " `%s' can not be used when making a shared object"),
2692 h
->type
== STT_FUNC
? "function" : "data",
2693 h
->root
.root
.string
);
2694 bfd_set_error (bfd_error_bad_value
);
2699 /* Note that sgot is not involved in this
2700 calculation. We always want the start of .got.plt. If we
2701 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2702 permitted by the ABI, we might have to change this
2704 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2705 + htab
->elf
.sgotplt
->output_offset
;
2709 /* Use global offset table as symbol value. */
2710 relocation
= htab
->elf
.sgotplt
->output_section
->vma
2711 + htab
->elf
.sgotplt
->output_offset
;
2712 unresolved_reloc
= FALSE
;
2716 /* Relocation is to the entry for this symbol in the
2717 procedure linkage table. */
2719 /* Resolve a PLT32 reloc against a local symbol directly,
2720 without using the procedure linkage table. */
2724 if ((h
->plt
.offset
== (bfd_vma
) -1
2725 && eh
->plt_got
.offset
== (bfd_vma
) -1)
2726 || htab
->elf
.splt
== NULL
)
2728 /* We didn't make a PLT entry for this symbol. This
2729 happens when statically linking PIC code, or when
2730 using -Bsymbolic. */
2734 if (h
->plt
.offset
!= (bfd_vma
) -1)
2736 if (htab
->plt_second
!= NULL
)
2738 resolved_plt
= htab
->plt_second
;
2739 plt_offset
= eh
->plt_second
.offset
;
2743 resolved_plt
= htab
->elf
.splt
;
2744 plt_offset
= h
->plt
.offset
;
2749 resolved_plt
= htab
->plt_got
;
2750 plt_offset
= eh
->plt_got
.offset
;
2753 relocation
= (resolved_plt
->output_section
->vma
2754 + resolved_plt
->output_offset
2756 unresolved_reloc
= FALSE
;
2760 /* Set to symbol size. */
2761 relocation
= st_size
;
2766 if ((input_section
->flags
& SEC_ALLOC
) == 0
2770 /* Copy dynamic function pointer relocations. Don't generate
2771 dynamic relocations against resolved undefined weak symbols
2772 in PIE, except for R_386_PC32. */
2773 if ((bfd_link_pic (info
)
2775 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2776 && (!resolved_to_zero
2777 || r_type
== R_386_PC32
))
2778 || h
->root
.type
!= bfd_link_hash_undefweak
))
2779 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
2780 || !SYMBOL_CALLS_LOCAL (info
, h
)))
2781 || (ELIMINATE_COPY_RELOCS
2782 && !bfd_link_pic (info
)
2786 || eh
->func_pointer_refcount
> 0
2787 || (h
->root
.type
== bfd_link_hash_undefweak
2788 && !resolved_to_zero
))
2789 && ((h
->def_dynamic
&& !h
->def_regular
)
2790 /* Undefined weak symbol is bound locally when
2792 || h
->root
.type
== bfd_link_hash_undefweak
)))
2794 Elf_Internal_Rela outrel
;
2795 bfd_boolean skip
, relocate
;
2798 /* When generating a shared object, these relocations
2799 are copied into the output file to be resolved at run
2806 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2808 if (outrel
.r_offset
== (bfd_vma
) -1)
2810 else if (outrel
.r_offset
== (bfd_vma
) -2)
2811 skip
= TRUE
, relocate
= TRUE
;
2812 outrel
.r_offset
+= (input_section
->output_section
->vma
2813 + input_section
->output_offset
);
2816 memset (&outrel
, 0, sizeof outrel
);
2819 && (r_type
== R_386_PC32
2820 || !(bfd_link_executable (info
)
2821 || SYMBOLIC_BIND (info
, h
))
2822 || !h
->def_regular
))
2823 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2826 /* This symbol is local, or marked to become local. */
2828 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2831 sreloc
= elf_section_data (input_section
)->sreloc
;
2833 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
2835 r
= bfd_reloc_notsupported
;
2836 goto check_relocation_error
;
2839 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2841 /* If this reloc is against an external symbol, we do
2842 not want to fiddle with the addend. Otherwise, we
2843 need to include the symbol value so that it becomes
2844 an addend for the dynamic reloc. */
2851 if (!bfd_link_executable (info
))
2853 Elf_Internal_Rela outrel
;
2856 outrel
.r_offset
= rel
->r_offset
2857 + input_section
->output_section
->vma
2858 + input_section
->output_offset
;
2859 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2860 sreloc
= elf_section_data (input_section
)->sreloc
;
2863 elf_append_rel (output_bfd
, sreloc
, &outrel
);
2868 case R_386_TLS_GOTDESC
:
2869 case R_386_TLS_DESC_CALL
:
2870 case R_386_TLS_IE_32
:
2871 case R_386_TLS_GOTIE
:
2872 tls_type
= GOT_UNKNOWN
;
2873 if (h
== NULL
&& local_got_offsets
)
2874 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
2876 tls_type
= elf_x86_hash_entry(h
)->tls_type
;
2877 if (tls_type
== GOT_TLS_IE
)
2878 tls_type
= GOT_TLS_IE_NEG
;
2880 r_type_tls
= r_type
;
2881 if (! elf_i386_tls_transition (info
, input_bfd
,
2882 input_section
, contents
,
2883 symtab_hdr
, sym_hashes
,
2884 &r_type_tls
, tls_type
, rel
,
2885 relend
, h
, r_symndx
, TRUE
))
2888 if (r_type_tls
== R_386_TLS_LE_32
)
2890 BFD_ASSERT (! unresolved_reloc
);
2891 if (r_type
== R_386_TLS_GD
)
2896 /* GD->LE transition. */
2897 type
= *(contents
+ rel
->r_offset
- 2);
2901 leal foo@tlsgd(,%ebx,1), %eax
2902 call ___tls_get_addr@PLT
2905 subl $foo@tpoff, %eax
2906 (6 byte form of subl). */
2907 roff
= rel
->r_offset
+ 5;
2912 leal foo@tlsgd(%ebx), %eax
2913 call ___tls_get_addr@PLT
2916 leal foo@tlsgd(%reg), %eax
2917 call *___tls_get_addr@GOT(%reg)
2918 which may be converted to
2919 addr32 call ___tls_get_addr
2921 movl %gs:0, %eax; subl $foo@tpoff, %eax
2922 (6 byte form of subl). */
2923 roff
= rel
->r_offset
+ 6;
2925 memcpy (contents
+ roff
- 8,
2926 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2927 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
2929 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
2934 else if (r_type
== R_386_TLS_GOTDESC
)
2936 /* GDesc -> LE transition.
2937 It's originally something like:
2938 leal x@tlsdesc(%ebx), %eax
2942 Registers other than %eax may be set up here. */
2947 roff
= rel
->r_offset
;
2948 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2950 /* Now modify the instruction as appropriate. */
2951 /* aoliva FIXME: remove the above and xor the byte
2953 bfd_put_8 (output_bfd
, val
^ 0x86,
2954 contents
+ roff
- 1);
2955 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
2959 else if (r_type
== R_386_TLS_DESC_CALL
)
2961 /* GDesc -> LE transition.
2969 roff
= rel
->r_offset
;
2970 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
2971 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
2974 else if (r_type
== R_386_TLS_IE
)
2978 /* IE->LE transition:
2979 Originally it can be one of:
2987 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2990 /* movl foo, %eax. */
2991 bfd_put_8 (output_bfd
, 0xb8,
2992 contents
+ rel
->r_offset
- 1);
2998 type
= bfd_get_8 (input_bfd
,
2999 contents
+ rel
->r_offset
- 2);
3004 bfd_put_8 (output_bfd
, 0xc7,
3005 contents
+ rel
->r_offset
- 2);
3006 bfd_put_8 (output_bfd
,
3007 0xc0 | ((val
>> 3) & 7),
3008 contents
+ rel
->r_offset
- 1);
3012 bfd_put_8 (output_bfd
, 0x81,
3013 contents
+ rel
->r_offset
- 2);
3014 bfd_put_8 (output_bfd
,
3015 0xc0 | ((val
>> 3) & 7),
3016 contents
+ rel
->r_offset
- 1);
3023 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3024 contents
+ rel
->r_offset
);
3029 unsigned int val
, type
;
3031 /* {IE_32,GOTIE}->LE transition:
3032 Originally it can be one of:
3033 subl foo(%reg1), %reg2
3034 movl foo(%reg1), %reg2
3035 addl foo(%reg1), %reg2
3038 movl $foo, %reg2 (6 byte form)
3039 addl $foo, %reg2. */
3040 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3041 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3045 bfd_put_8 (output_bfd
, 0xc7,
3046 contents
+ rel
->r_offset
- 2);
3047 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3048 contents
+ rel
->r_offset
- 1);
3050 else if (type
== 0x2b)
3053 bfd_put_8 (output_bfd
, 0x81,
3054 contents
+ rel
->r_offset
- 2);
3055 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3056 contents
+ rel
->r_offset
- 1);
3058 else if (type
== 0x03)
3061 bfd_put_8 (output_bfd
, 0x81,
3062 contents
+ rel
->r_offset
- 2);
3063 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3064 contents
+ rel
->r_offset
- 1);
3068 if (r_type
== R_386_TLS_GOTIE
)
3069 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3070 contents
+ rel
->r_offset
);
3072 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3073 contents
+ rel
->r_offset
);
3078 if (htab
->elf
.sgot
== NULL
)
3083 off
= h
->got
.offset
;
3084 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3088 if (local_got_offsets
== NULL
)
3091 off
= local_got_offsets
[r_symndx
];
3092 offplt
= local_tlsdesc_gotents
[r_symndx
];
3099 Elf_Internal_Rela outrel
;
3103 if (htab
->elf
.srelgot
== NULL
)
3106 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3108 if (GOT_TLS_GDESC_P (tls_type
))
3111 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3112 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3113 <= htab
->elf
.sgotplt
->size
);
3114 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3115 + htab
->elf
.sgotplt
->output_offset
3117 + htab
->sgotplt_jump_table_size
);
3118 sreloc
= htab
->elf
.srelplt
;
3119 loc
= sreloc
->contents
;
3120 loc
+= (htab
->next_tls_desc_index
++
3121 * sizeof (Elf32_External_Rel
));
3122 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3123 <= sreloc
->contents
+ sreloc
->size
);
3124 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3127 BFD_ASSERT (! unresolved_reloc
);
3128 bfd_put_32 (output_bfd
,
3129 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3130 htab
->elf
.sgotplt
->contents
+ offplt
3131 + htab
->sgotplt_jump_table_size
+ 4);
3135 bfd_put_32 (output_bfd
, 0,
3136 htab
->elf
.sgotplt
->contents
+ offplt
3137 + htab
->sgotplt_jump_table_size
+ 4);
3141 sreloc
= htab
->elf
.srelgot
;
3143 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3144 + htab
->elf
.sgot
->output_offset
+ off
);
3146 if (GOT_TLS_GD_P (tls_type
))
3147 dr_type
= R_386_TLS_DTPMOD32
;
3148 else if (GOT_TLS_GDESC_P (tls_type
))
3150 else if (tls_type
== GOT_TLS_IE_POS
)
3151 dr_type
= R_386_TLS_TPOFF
;
3153 dr_type
= R_386_TLS_TPOFF32
;
3155 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3156 bfd_put_32 (output_bfd
,
3157 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3158 htab
->elf
.sgot
->contents
+ off
);
3159 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3160 bfd_put_32 (output_bfd
,
3161 _bfd_x86_elf_dtpoff_base (info
) - relocation
,
3162 htab
->elf
.sgot
->contents
+ off
);
3163 else if (dr_type
!= R_386_TLS_DESC
)
3164 bfd_put_32 (output_bfd
, 0,
3165 htab
->elf
.sgot
->contents
+ off
);
3166 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3168 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3170 if (GOT_TLS_GD_P (tls_type
))
3174 BFD_ASSERT (! unresolved_reloc
);
3175 bfd_put_32 (output_bfd
,
3176 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3177 htab
->elf
.sgot
->contents
+ off
+ 4);
3181 bfd_put_32 (output_bfd
, 0,
3182 htab
->elf
.sgot
->contents
+ off
+ 4);
3183 outrel
.r_info
= ELF32_R_INFO (indx
,
3184 R_386_TLS_DTPOFF32
);
3185 outrel
.r_offset
+= 4;
3186 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3189 else if (tls_type
== GOT_TLS_IE_BOTH
)
3191 bfd_put_32 (output_bfd
,
3193 ? relocation
- _bfd_x86_elf_dtpoff_base (info
)
3195 htab
->elf
.sgot
->contents
+ off
+ 4);
3196 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3197 outrel
.r_offset
+= 4;
3198 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3205 local_got_offsets
[r_symndx
] |= 1;
3208 if (off
>= (bfd_vma
) -2
3209 && ! GOT_TLS_GDESC_P (tls_type
))
3211 if (r_type_tls
== R_386_TLS_GOTDESC
3212 || r_type_tls
== R_386_TLS_DESC_CALL
)
3214 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3215 unresolved_reloc
= FALSE
;
3217 else if (r_type_tls
== r_type
)
3219 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3220 + htab
->elf
.sgotplt
->output_offset
;
3221 relocation
= htab
->elf
.sgot
->output_section
->vma
3222 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3223 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3224 && tls_type
== GOT_TLS_IE_BOTH
)
3226 if (r_type
== R_386_TLS_IE
)
3227 relocation
+= g_o_t
;
3228 unresolved_reloc
= FALSE
;
3230 else if (r_type
== R_386_TLS_GD
)
3232 unsigned int val
, type
;
3235 /* GD->IE transition. */
3236 type
= *(contents
+ rel
->r_offset
- 2);
3237 val
= *(contents
+ rel
->r_offset
- 1);
3241 leal foo@tlsgd(,%ebx,1), %eax
3242 call ___tls_get_addr@PLT
3245 subl $foo@gottpoff(%ebx), %eax. */
3247 roff
= rel
->r_offset
- 3;
3252 leal foo@tlsgd(%ebx), %eax
3253 call ___tls_get_addr@PLT
3256 leal foo@tlsgd(%reg), %eax
3257 call *___tls_get_addr@GOT(%reg)
3258 which may be converted to
3259 addr32 call ___tls_get_addr
3262 subl $foo@gottpoff(%reg), %eax. */
3263 roff
= rel
->r_offset
- 2;
3265 memcpy (contents
+ roff
,
3266 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3267 contents
[roff
+ 7] = 0x80 | (val
& 7);
3268 /* If foo is used only with foo@gotntpoff(%reg) and
3269 foo@indntpoff, but not with foo@gottpoff(%reg), change
3270 subl $foo@gottpoff(%reg), %eax
3272 addl $foo@gotntpoff(%reg), %eax. */
3273 if (tls_type
== GOT_TLS_IE_POS
)
3274 contents
[roff
+ 6] = 0x03;
3275 bfd_put_32 (output_bfd
,
3276 htab
->elf
.sgot
->output_section
->vma
3277 + htab
->elf
.sgot
->output_offset
+ off
3278 - htab
->elf
.sgotplt
->output_section
->vma
3279 - htab
->elf
.sgotplt
->output_offset
,
3280 contents
+ roff
+ 8);
3281 /* Skip R_386_PLT32 and R_386_GOT32X. */
3286 else if (r_type
== R_386_TLS_GOTDESC
)
3288 /* GDesc -> IE transition.
3289 It's originally something like:
3290 leal x@tlsdesc(%ebx), %eax
3293 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3295 movl x@gottpoff(%ebx), %eax # before negl %eax
3297 Registers other than %eax may be set up here. */
3301 /* First, make sure it's a leal adding ebx to a 32-bit
3302 offset into any register, although it's probably
3303 almost always going to be eax. */
3304 roff
= rel
->r_offset
;
3306 /* Now modify the instruction as appropriate. */
3307 /* To turn a leal into a movl in the form we use it, it
3308 suffices to change the first byte from 0x8d to 0x8b.
3309 aoliva FIXME: should we decide to keep the leal, all
3310 we have to do is remove the statement below, and
3311 adjust the relaxation of R_386_TLS_DESC_CALL. */
3312 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3314 if (tls_type
== GOT_TLS_IE_BOTH
)
3317 bfd_put_32 (output_bfd
,
3318 htab
->elf
.sgot
->output_section
->vma
3319 + htab
->elf
.sgot
->output_offset
+ off
3320 - htab
->elf
.sgotplt
->output_section
->vma
3321 - htab
->elf
.sgotplt
->output_offset
,
3325 else if (r_type
== R_386_TLS_DESC_CALL
)
3327 /* GDesc -> IE transition.
3335 depending on how we transformed the TLS_GOTDESC above.
3340 roff
= rel
->r_offset
;
3342 /* Now modify the instruction as appropriate. */
3343 if (tls_type
!= GOT_TLS_IE_NEG
)
3346 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3347 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3352 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3353 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3363 if (! elf_i386_tls_transition (info
, input_bfd
,
3364 input_section
, contents
,
3365 symtab_hdr
, sym_hashes
,
3366 &r_type
, GOT_UNKNOWN
, rel
,
3367 relend
, h
, r_symndx
, TRUE
))
3370 if (r_type
!= R_386_TLS_LDM
)
3372 /* LD->LE transition. Change
3373 leal foo@tlsldm(%ebx) %eax
3374 call ___tls_get_addr@PLT
3378 leal 0(%esi,1), %esi
3380 leal foo@tlsldm(%reg) %eax
3381 call *___tls_get_addr@GOT(%reg)
3382 which may be converted to
3383 addr32 call ___tls_get_addr
3386 leal 0(%esi), %esi */
3387 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3388 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
3389 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
3390 memcpy (contents
+ rel
->r_offset
- 2,
3391 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
3393 memcpy (contents
+ rel
->r_offset
- 2,
3394 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3395 /* Skip R_386_PC32/R_386_PLT32. */
3401 if (htab
->elf
.sgot
== NULL
)
3404 off
= htab
->tls_ld_or_ldm_got
.offset
;
3409 Elf_Internal_Rela outrel
;
3411 if (htab
->elf
.srelgot
== NULL
)
3414 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3415 + htab
->elf
.sgot
->output_offset
+ off
);
3417 bfd_put_32 (output_bfd
, 0,
3418 htab
->elf
.sgot
->contents
+ off
);
3419 bfd_put_32 (output_bfd
, 0,
3420 htab
->elf
.sgot
->contents
+ off
+ 4);
3421 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3422 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3423 htab
->tls_ld_or_ldm_got
.offset
|= 1;
3425 relocation
= htab
->elf
.sgot
->output_section
->vma
3426 + htab
->elf
.sgot
->output_offset
+ off
3427 - htab
->elf
.sgotplt
->output_section
->vma
3428 - htab
->elf
.sgotplt
->output_offset
;
3429 unresolved_reloc
= FALSE
;
3432 case R_386_TLS_LDO_32
:
3433 if (!bfd_link_executable (info
)
3434 || (input_section
->flags
& SEC_CODE
) == 0)
3435 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3437 /* When converting LDO to LE, we must negate. */
3438 relocation
= -elf_i386_tpoff (info
, relocation
);
3441 case R_386_TLS_LE_32
:
3443 if (!bfd_link_executable (info
))
3445 Elf_Internal_Rela outrel
;
3448 outrel
.r_offset
= rel
->r_offset
3449 + input_section
->output_section
->vma
3450 + input_section
->output_offset
;
3451 if (h
!= NULL
&& h
->dynindx
!= -1)
3455 if (r_type
== R_386_TLS_LE_32
)
3456 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3458 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3459 sreloc
= elf_section_data (input_section
)->sreloc
;
3462 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3465 else if (r_type
== R_386_TLS_LE_32
)
3466 relocation
= _bfd_x86_elf_dtpoff_base (info
) - relocation
;
3468 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3470 else if (r_type
== R_386_TLS_LE_32
)
3471 relocation
= elf_i386_tpoff (info
, relocation
);
3473 relocation
= -elf_i386_tpoff (info
, relocation
);
3480 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3481 because such sections are not SEC_ALLOC and thus ld.so will
3482 not process them. */
3483 if (unresolved_reloc
3484 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3486 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3487 rel
->r_offset
) != (bfd_vma
) -1)
3490 /* xgettext:c-format */
3491 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
3496 h
->root
.root
.string
);
3501 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3502 contents
, rel
->r_offset
,
3505 check_relocation_error
:
3506 if (r
!= bfd_reloc_ok
)
3511 name
= h
->root
.root
.string
;
3514 name
= bfd_elf_string_from_elf_section (input_bfd
,
3515 symtab_hdr
->sh_link
,
3520 name
= bfd_section_name (input_bfd
, sec
);
3523 if (r
== bfd_reloc_overflow
)
3524 (*info
->callbacks
->reloc_overflow
)
3525 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3526 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3530 /* xgettext:c-format */
3531 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
3532 input_bfd
, input_section
,
3533 rel
->r_offset
, name
, (int) r
);
3544 Elf_Internal_Shdr
*rel_hdr
;
3545 size_t deleted
= rel
- wrel
;
3547 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
3548 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3549 if (rel_hdr
->sh_size
== 0)
3551 /* It is too late to remove an empty reloc section. Leave
3553 ??? What is wrong with an empty section??? */
3554 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
3557 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
3558 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3559 input_section
->reloc_count
-= deleted
;
3565 /* Finish up dynamic symbol handling. We set the contents of various
3566 dynamic sections here. */
3569 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3570 struct bfd_link_info
*info
,
3571 struct elf_link_hash_entry
*h
,
3572 Elf_Internal_Sym
*sym
)
3574 struct elf_x86_link_hash_table
*htab
;
3575 unsigned plt_entry_size
;
3576 struct elf_x86_link_hash_entry
*eh
;
3577 bfd_boolean local_undefweak
;
3578 bfd_boolean use_plt_second
;
3580 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
3584 plt_entry_size
= htab
->plt
.plt_entry_size
;
3586 /* Use the second PLT section only if there is .plt section. */
3587 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
3589 eh
= (struct elf_x86_link_hash_entry
*) h
;
3590 if (eh
->no_finish_dynamic_symbol
)
3593 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
3594 resolved undefined weak symbols in executable so that their
3595 references have value 0 at run-time. */
3596 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
3598 if (h
->plt
.offset
!= (bfd_vma
) -1)
3600 bfd_vma plt_index
, plt_offset
;
3602 Elf_Internal_Rela rel
;
3604 asection
*plt
, *resolved_plt
, *gotplt
, *relplt
;
3606 /* When building a static executable, use .iplt, .igot.plt and
3607 .rel.iplt sections for STT_GNU_IFUNC symbols. */
3608 if (htab
->elf
.splt
!= NULL
)
3610 plt
= htab
->elf
.splt
;
3611 gotplt
= htab
->elf
.sgotplt
;
3612 relplt
= htab
->elf
.srelplt
;
3616 plt
= htab
->elf
.iplt
;
3617 gotplt
= htab
->elf
.igotplt
;
3618 relplt
= htab
->elf
.irelplt
;
3621 /* This symbol has an entry in the procedure linkage table. Set
3624 if ((h
->dynindx
== -1
3626 && !((h
->forced_local
|| bfd_link_executable (info
))
3628 && h
->type
== STT_GNU_IFUNC
))
3634 /* Get the index in the procedure linkage table which
3635 corresponds to this symbol. This is the index of this symbol
3636 in all the symbols for which we are making plt entries. The
3637 first entry in the procedure linkage table is reserved.
3639 Get the offset into the .got table of the entry that
3640 corresponds to this function. Each .got entry is 4 bytes.
3641 The first three are reserved.
3643 For static executables, we don't reserve anything. */
3645 if (plt
== htab
->elf
.splt
)
3647 got_offset
= (h
->plt
.offset
/ plt_entry_size
3648 - htab
->plt
.has_plt0
);
3649 got_offset
= (got_offset
+ 3) * 4;
3653 got_offset
= h
->plt
.offset
/ plt_entry_size
;
3654 got_offset
= got_offset
* 4;
3657 /* Fill in the entry in the procedure linkage table and update
3659 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
3664 const bfd_byte
*plt_entry
;
3665 if (bfd_link_pic (info
))
3666 plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3668 plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3669 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
3670 plt_entry
, htab
->non_lazy_plt
->plt_entry_size
);
3672 resolved_plt
= htab
->plt_second
;
3673 plt_offset
= eh
->plt_second
.offset
;
3678 plt_offset
= h
->plt
.offset
;
3681 if (! bfd_link_pic (info
))
3683 bfd_put_32 (output_bfd
,
3684 (gotplt
->output_section
->vma
3685 + gotplt
->output_offset
3687 resolved_plt
->contents
+ plt_offset
3688 + htab
->plt
.plt_got_offset
);
3690 if (htab
->is_vxworks
)
3692 int s
, k
, reloc_index
;
3694 /* Create the R_386_32 relocation referencing the GOT
3695 for this PLT entry. */
3697 /* S: Current slot number (zero-based). */
3698 s
= ((h
->plt
.offset
- htab
->plt
.plt_entry_size
)
3699 / htab
->plt
.plt_entry_size
);
3700 /* K: Number of relocations for PLTResolve. */
3701 if (bfd_link_pic (info
))
3702 k
= PLTRESOLVE_RELOCS_SHLIB
;
3704 k
= PLTRESOLVE_RELOCS
;
3705 /* Skip the PLTresolve relocations, and the relocations for
3706 the other PLT slots. */
3707 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3708 loc
= (htab
->srelplt2
->contents
+ reloc_index
3709 * sizeof (Elf32_External_Rel
));
3711 rel
.r_offset
= (plt
->output_section
->vma
3712 + plt
->output_offset
3713 + h
->plt
.offset
+ 2),
3714 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3715 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3717 /* Create the R_386_32 relocation referencing the beginning of
3718 the PLT for this GOT entry. */
3719 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3720 + htab
->elf
.sgotplt
->output_offset
3722 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3723 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3724 loc
+ sizeof (Elf32_External_Rel
));
3729 bfd_put_32 (output_bfd
, got_offset
,
3730 resolved_plt
->contents
+ plt_offset
3731 + htab
->plt
.plt_got_offset
);
3734 /* Fill in the entry in the global offset table. Leave the entry
3735 as zero for undefined weak symbol in PIE. No PLT relocation
3736 against undefined weak symbol in PIE. */
3737 if (!local_undefweak
)
3739 if (htab
->plt
.has_plt0
)
3740 bfd_put_32 (output_bfd
,
3741 (plt
->output_section
->vma
3742 + plt
->output_offset
3744 + htab
->lazy_plt
->plt_lazy_offset
),
3745 gotplt
->contents
+ got_offset
);
3747 /* Fill in the entry in the .rel.plt section. */
3748 rel
.r_offset
= (gotplt
->output_section
->vma
3749 + gotplt
->output_offset
3751 if (h
->dynindx
== -1
3752 || ((bfd_link_executable (info
)
3753 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3755 && h
->type
== STT_GNU_IFUNC
))
3757 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3758 h
->root
.root
.string
,
3759 h
->root
.u
.def
.section
->owner
);
3761 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3762 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
3763 in the .got.plt section. */
3764 bfd_put_32 (output_bfd
,
3765 (h
->root
.u
.def
.value
3766 + h
->root
.u
.def
.section
->output_section
->vma
3767 + h
->root
.u
.def
.section
->output_offset
),
3768 gotplt
->contents
+ got_offset
);
3769 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3770 /* R_386_IRELATIVE comes last. */
3771 plt_index
= htab
->next_irelative_index
--;
3775 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3776 plt_index
= htab
->next_jump_slot_index
++;
3779 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3780 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3782 /* Don't fill the second and third slots in PLT entry for
3783 static executables nor without PLT0. */
3784 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
3786 bfd_put_32 (output_bfd
,
3787 plt_index
* sizeof (Elf32_External_Rel
),
3788 plt
->contents
+ h
->plt
.offset
3789 + htab
->lazy_plt
->plt_reloc_offset
);
3790 bfd_put_32 (output_bfd
,
3792 + htab
->lazy_plt
->plt_plt_offset
+ 4),
3793 (plt
->contents
+ h
->plt
.offset
3794 + htab
->lazy_plt
->plt_plt_offset
));
3798 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
3800 bfd_vma got_offset
, plt_offset
;
3801 asection
*plt
, *got
, *gotplt
;
3802 const bfd_byte
*got_plt_entry
;
3804 /* Set the entry in the GOT procedure linkage table. */
3805 plt
= htab
->plt_got
;
3806 got
= htab
->elf
.sgot
;
3807 gotplt
= htab
->elf
.sgotplt
;
3808 got_offset
= h
->got
.offset
;
3810 if (got_offset
== (bfd_vma
) -1
3816 /* Fill in the entry in the GOT procedure linkage table. */
3817 if (! bfd_link_pic (info
))
3819 got_plt_entry
= htab
->non_lazy_plt
->plt_entry
;
3820 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
3824 got_plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
3825 got_offset
+= (got
->output_section
->vma
3826 + got
->output_offset
3827 - gotplt
->output_section
->vma
3828 - gotplt
->output_offset
);
3831 plt_offset
= eh
->plt_got
.offset
;
3832 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
3833 htab
->non_lazy_plt
->plt_entry_size
);
3834 bfd_put_32 (output_bfd
, got_offset
,
3835 (plt
->contents
+ plt_offset
3836 + htab
->non_lazy_plt
->plt_got_offset
));
3839 if (!local_undefweak
3841 && (h
->plt
.offset
!= (bfd_vma
) -1
3842 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
3844 /* Mark the symbol as undefined, rather than as defined in
3845 the .plt section. Leave the value if there were any
3846 relocations where pointer equality matters (this is a clue
3847 for the dynamic linker, to make function pointer
3848 comparisons work between an application and shared
3849 library), otherwise set it to zero. If a function is only
3850 called from a binary, there is no need to slow down
3851 shared libraries because of that. */
3852 sym
->st_shndx
= SHN_UNDEF
;
3853 if (!h
->pointer_equality_needed
)
3857 /* Don't generate dynamic GOT relocation against undefined weak
3858 symbol in executable. */
3859 if (h
->got
.offset
!= (bfd_vma
) -1
3860 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h
)->tls_type
)
3861 && (elf_x86_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
3862 && !local_undefweak
)
3864 Elf_Internal_Rela rel
;
3865 asection
*relgot
= htab
->elf
.srelgot
;
3867 /* This symbol has an entry in the global offset table. Set it
3870 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
3873 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3874 + htab
->elf
.sgot
->output_offset
3875 + (h
->got
.offset
& ~(bfd_vma
) 1));
3877 /* If this is a static link, or it is a -Bsymbolic link and the
3878 symbol is defined locally or was forced to be local because
3879 of a version file, we just want to emit a RELATIVE reloc.
3880 The entry in the global offset table will already have been
3881 initialized in the relocate_section function. */
3883 && h
->type
== STT_GNU_IFUNC
)
3885 if (h
->plt
.offset
== (bfd_vma
) -1)
3887 /* STT_GNU_IFUNC is referenced without PLT. */
3888 if (htab
->elf
.splt
== NULL
)
3890 /* use .rel[a].iplt section to store .got relocations
3891 in static executable. */
3892 relgot
= htab
->elf
.irelplt
;
3894 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3896 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3897 h
->root
.root
.string
,
3898 h
->root
.u
.def
.section
->owner
);
3900 bfd_put_32 (output_bfd
,
3901 (h
->root
.u
.def
.value
3902 + h
->root
.u
.def
.section
->output_section
->vma
3903 + h
->root
.u
.def
.section
->output_offset
),
3904 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3905 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3910 else if (bfd_link_pic (info
))
3912 /* Generate R_386_GLOB_DAT. */
3920 if (!h
->pointer_equality_needed
)
3923 /* For non-shared object, we can't use .got.plt, which
3924 contains the real function addres if we need pointer
3925 equality. We load the GOT entry with the PLT entry. */
3926 if (htab
->plt_second
!= NULL
)
3928 plt
= htab
->plt_second
;
3929 plt_offset
= eh
->plt_second
.offset
;
3933 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3934 plt_offset
= h
->plt
.offset
;
3936 bfd_put_32 (output_bfd
,
3937 (plt
->output_section
->vma
3938 + plt
->output_offset
+ plt_offset
),
3939 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3943 else if (bfd_link_pic (info
)
3944 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3946 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3947 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3951 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3953 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3954 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3955 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3958 elf_append_rel (output_bfd
, relgot
, &rel
);
3963 Elf_Internal_Rela rel
;
3966 /* This symbol needs a copy reloc. Set it up. */
3968 if (h
->dynindx
== -1
3969 || (h
->root
.type
!= bfd_link_hash_defined
3970 && h
->root
.type
!= bfd_link_hash_defweak
)
3971 || htab
->elf
.srelbss
== NULL
3972 || htab
->elf
.sreldynrelro
== NULL
)
3975 rel
.r_offset
= (h
->root
.u
.def
.value
3976 + h
->root
.u
.def
.section
->output_section
->vma
3977 + h
->root
.u
.def
.section
->output_offset
);
3978 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
3979 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
3980 s
= htab
->elf
.sreldynrelro
;
3982 s
= htab
->elf
.srelbss
;
3983 elf_append_rel (output_bfd
, s
, &rel
);
3989 /* Finish up local dynamic symbol handling. We set the contents of
3990 various dynamic sections here. */
3993 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
3995 struct elf_link_hash_entry
*h
3996 = (struct elf_link_hash_entry
*) *slot
;
3997 struct bfd_link_info
*info
3998 = (struct bfd_link_info
*) inf
;
4000 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4004 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4005 here since undefined weak symbol may not be dynamic and may not be
4006 called for elf_i386_finish_dynamic_symbol. */
4009 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
4012 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
4013 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4015 if (h
->root
.type
!= bfd_link_hash_undefweak
4016 || h
->dynindx
!= -1)
4019 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
4023 /* Used to decide how to sort relocs in an optimal manner for the
4024 dynamic linker, before writing them out. */
4026 static enum elf_reloc_type_class
4027 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
4028 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4029 const Elf_Internal_Rela
*rela
)
4031 bfd
*abfd
= info
->output_bfd
;
4032 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4033 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4035 if (htab
->dynsym
!= NULL
4036 && htab
->dynsym
->contents
!= NULL
)
4038 /* Check relocation against STT_GNU_IFUNC symbol if there are
4040 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
4041 if (r_symndx
!= STN_UNDEF
)
4043 Elf_Internal_Sym sym
;
4044 if (!bed
->s
->swap_symbol_in (abfd
,
4045 (htab
->dynsym
->contents
4046 + r_symndx
* sizeof (Elf32_External_Sym
)),
4050 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
4051 return reloc_class_ifunc
;
4055 switch (ELF32_R_TYPE (rela
->r_info
))
4057 case R_386_IRELATIVE
:
4058 return reloc_class_ifunc
;
4059 case R_386_RELATIVE
:
4060 return reloc_class_relative
;
4061 case R_386_JUMP_SLOT
:
4062 return reloc_class_plt
;
4064 return reloc_class_copy
;
4066 return reloc_class_normal
;
4070 /* Finish up the dynamic sections. */
4073 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4074 struct bfd_link_info
*info
)
4076 struct elf_x86_link_hash_table
*htab
;
4079 const struct elf_i386_backend_data
*abed
;
4081 htab
= elf_x86_hash_table (info
, I386_ELF_DATA
);
4085 dynobj
= htab
->elf
.dynobj
;
4086 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4087 abed
= get_elf_i386_backend_data (output_bfd
);
4089 if (htab
->elf
.dynamic_sections_created
)
4091 Elf32_External_Dyn
*dyncon
, *dynconend
;
4093 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4096 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4097 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4098 for (; dyncon
< dynconend
; dyncon
++)
4100 Elf_Internal_Dyn dyn
;
4103 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4108 if (htab
->is_vxworks
4109 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4114 s
= htab
->elf
.sgotplt
;
4115 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4119 s
= htab
->elf
.srelplt
;
4120 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4124 s
= htab
->elf
.srelplt
;
4125 dyn
.d_un
.d_val
= s
->size
;
4129 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4132 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4134 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4135 really seem like the right value. */
4136 elf_section_data (htab
->elf
.splt
->output_section
)
4137 ->this_hdr
.sh_entsize
= 4;
4139 if (htab
->plt
.has_plt0
)
4141 /* Fill in the special first entry in the procedure linkage
4143 memcpy (htab
->elf
.splt
->contents
, htab
->plt
.plt0_entry
,
4144 htab
->lazy_plt
->plt0_entry_size
);
4145 memset (htab
->elf
.splt
->contents
+ htab
->lazy_plt
->plt0_entry_size
,
4146 abed
->plt0_pad_byte
,
4147 htab
->plt
.plt_entry_size
- htab
->lazy_plt
->plt0_entry_size
);
4148 if (!bfd_link_pic (info
))
4150 bfd_put_32 (output_bfd
,
4151 (htab
->elf
.sgotplt
->output_section
->vma
4152 + htab
->elf
.sgotplt
->output_offset
4154 htab
->elf
.splt
->contents
4155 + htab
->lazy_plt
->plt0_got1_offset
);
4156 bfd_put_32 (output_bfd
,
4157 (htab
->elf
.sgotplt
->output_section
->vma
4158 + htab
->elf
.sgotplt
->output_offset
4160 htab
->elf
.splt
->contents
4161 + htab
->lazy_plt
->plt0_got2_offset
);
4163 if (htab
->is_vxworks
)
4165 Elf_Internal_Rela rel
;
4166 int num_plts
= (htab
->elf
.splt
->size
4167 / htab
->plt
.plt_entry_size
) - 1;
4169 asection
*srelplt2
= htab
->srelplt2
;
4171 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4172 + 4. On IA32 we use REL relocations so the
4173 addend goes in the PLT directly. */
4174 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4175 + htab
->elf
.splt
->output_offset
4176 + htab
->lazy_plt
->plt0_got1_offset
);
4177 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4179 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4180 srelplt2
->contents
);
4181 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
4183 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4184 + htab
->elf
.splt
->output_offset
4185 + htab
->lazy_plt
->plt0_got2_offset
);
4186 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4188 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4189 srelplt2
->contents
+
4190 sizeof (Elf32_External_Rel
));
4191 /* Correct the .rel.plt.unloaded relocations. */
4192 p
= srelplt2
->contents
;
4193 if (bfd_link_pic (info
))
4194 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4196 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4198 for (; num_plts
; num_plts
--)
4200 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4201 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
4203 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4204 p
+= sizeof (Elf32_External_Rel
);
4206 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4207 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
4209 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4210 p
+= sizeof (Elf32_External_Rel
);
4217 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
4218 elf_section_data (htab
->plt_got
->output_section
)
4219 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4221 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
4222 elf_section_data (htab
->plt_second
->output_section
)
4223 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4226 /* Fill in the first three entries in the global offset table. */
4227 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
4229 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4232 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4236 bfd_put_32 (output_bfd
,
4238 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4239 htab
->elf
.sgotplt
->contents
);
4240 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4241 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4243 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4246 /* Adjust .eh_frame for .plt section. */
4247 if (htab
->plt_eh_frame
!= NULL
4248 && htab
->plt_eh_frame
->contents
!= NULL
)
4250 if (htab
->elf
.splt
!= NULL
4251 && htab
->elf
.splt
->size
!= 0
4252 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4253 && htab
->elf
.splt
->output_section
!= NULL
4254 && htab
->plt_eh_frame
->output_section
!= NULL
)
4256 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4257 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4258 + htab
->plt_eh_frame
->output_offset
4259 + PLT_FDE_START_OFFSET
;
4260 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4261 htab
->plt_eh_frame
->contents
4262 + PLT_FDE_START_OFFSET
);
4264 if (htab
->plt_eh_frame
->sec_info_type
4265 == SEC_INFO_TYPE_EH_FRAME
)
4267 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4269 htab
->plt_eh_frame
->contents
))
4274 /* Adjust .eh_frame for .plt.got section. */
4275 if (htab
->plt_got_eh_frame
!= NULL
4276 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4278 if (htab
->plt_got
!= NULL
4279 && htab
->plt_got
->size
!= 0
4280 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
4281 && htab
->plt_got
->output_section
!= NULL
4282 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
4284 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
4285 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
4286 + htab
->plt_got_eh_frame
->output_offset
4287 + PLT_FDE_START_OFFSET
;
4288 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4289 htab
->plt_got_eh_frame
->contents
4290 + PLT_FDE_START_OFFSET
);
4292 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4294 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4295 htab
->plt_got_eh_frame
,
4296 htab
->plt_got_eh_frame
->contents
))
4301 /* Adjust .eh_frame for the second PLT section. */
4302 if (htab
->plt_second_eh_frame
!= NULL
4303 && htab
->plt_second_eh_frame
->contents
!= NULL
)
4305 if (htab
->plt_second
!= NULL
4306 && htab
->plt_second
->size
!= 0
4307 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
4308 && htab
->plt_second
->output_section
!= NULL
4309 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
4311 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
4312 bfd_vma eh_frame_start
4313 = (htab
->plt_second_eh_frame
->output_section
->vma
4314 + htab
->plt_second_eh_frame
->output_offset
4315 + PLT_FDE_START_OFFSET
);
4316 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4317 htab
->plt_second_eh_frame
->contents
4318 + PLT_FDE_START_OFFSET
);
4320 if (htab
->plt_second_eh_frame
->sec_info_type
4321 == SEC_INFO_TYPE_EH_FRAME
)
4323 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4324 htab
->plt_second_eh_frame
,
4325 htab
->plt_second_eh_frame
->contents
))
4330 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4331 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4333 /* Fill PLT entries for undefined weak symbols in PIE. */
4334 if (bfd_link_pie (info
))
4335 bfd_hash_traverse (&info
->hash
->table
,
4336 elf_i386_pie_finish_undefweak_symbol
,
4342 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4343 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4344 It has to be done before elf_link_sort_relocs is called so that
4345 dynamic relocations are properly sorted. */
4348 elf_i386_output_arch_local_syms
4349 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4350 struct bfd_link_info
*info
,
4351 void *flaginfo ATTRIBUTE_UNUSED
,
4352 int (*func
) (void *, const char *,
4355 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4357 struct elf_x86_link_hash_table
*htab
4358 = elf_x86_hash_table (info
, I386_ELF_DATA
);
4362 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4363 htab_traverse (htab
->loc_hash_table
,
4364 elf_i386_finish_local_dynamic_symbol
,
4370 /* Forward declaration. */
4371 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
;
4373 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4374 dynamic relocations. */
4377 elf_i386_get_synthetic_symtab (bfd
*abfd
,
4378 long symcount ATTRIBUTE_UNUSED
,
4379 asymbol
**syms ATTRIBUTE_UNUSED
,
4386 bfd_byte
*plt_contents
;
4388 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4389 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4390 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4391 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4394 enum elf_x86_plt_type plt_type
;
4395 struct elf_x86_plt plts
[] =
4397 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4398 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4399 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4400 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4405 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4408 if (dynsymcount
<= 0)
4411 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4415 non_lazy_plt
= NULL
;
4416 /* Silence GCC 6. */
4418 non_lazy_ibt_plt
= NULL
;
4419 lazy_ibt_plt
= NULL
;
4420 switch (get_elf_i386_backend_data (abfd
)->os
)
4423 non_lazy_plt
= &elf_i386_non_lazy_plt
;
4424 lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4425 non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4428 lazy_plt
= &elf_i386_lazy_plt
;
4431 lazy_plt
= &elf_i386_nacl_plt
;
4438 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4440 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4441 if (plt
== NULL
|| plt
->size
== 0)
4444 /* Get the PLT section contents. */
4445 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
4446 if (plt_contents
== NULL
)
4448 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
4449 plt_contents
, 0, plt
->size
))
4451 free (plt_contents
);
4455 /* Check what kind of PLT it is. */
4456 plt_type
= plt_unknown
;
4457 if (plts
[j
].type
== plt_unknown
4458 && (plt
->size
>= (lazy_plt
->plt0_entry_size
4459 + lazy_plt
->plt_entry_size
)))
4461 /* Match lazy PLT first. */
4462 if (memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4463 lazy_plt
->plt0_got1_offset
) == 0)
4465 /* The fist entry in the lazy IBT PLT is the same as the
4467 if (lazy_ibt_plt
!= NULL
4468 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4469 lazy_ibt_plt
->plt_entry
,
4470 lazy_ibt_plt
->plt_got_offset
) == 0))
4471 plt_type
= plt_lazy
| plt_second
;
4473 plt_type
= plt_lazy
;
4475 else if (memcmp (plt_contents
, lazy_plt
->pic_plt0_entry
,
4476 lazy_plt
->plt0_got1_offset
) == 0)
4478 /* The fist entry in the PIC lazy IBT PLT is the same as
4479 the normal PIC lazy PLT. */
4480 if (lazy_ibt_plt
!= NULL
4481 && (memcmp (plt_contents
+ lazy_ibt_plt
->plt0_entry_size
,
4482 lazy_ibt_plt
->pic_plt_entry
,
4483 lazy_ibt_plt
->plt_got_offset
) == 0))
4484 plt_type
= plt_lazy
| plt_pic
| plt_second
;
4486 plt_type
= plt_lazy
| plt_pic
;
4490 if (non_lazy_plt
!= NULL
4491 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
4492 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
4494 /* Match non-lazy PLT. */
4495 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
4496 non_lazy_plt
->plt_got_offset
) == 0)
4497 plt_type
= plt_non_lazy
;
4498 else if (memcmp (plt_contents
, non_lazy_plt
->pic_plt_entry
,
4499 non_lazy_plt
->plt_got_offset
) == 0)
4503 if ((non_lazy_ibt_plt
!= NULL
)
4504 && (plt_type
== plt_unknown
|| plt_type
== plt_second
)
4505 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
)
4507 if (memcmp (plt_contents
,
4508 non_lazy_ibt_plt
->plt_entry
,
4509 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4511 /* Match IBT PLT. */
4512 plt_type
= plt_second
;
4513 non_lazy_plt
= non_lazy_ibt_plt
;
4515 else if (memcmp (plt_contents
,
4516 non_lazy_ibt_plt
->pic_plt_entry
,
4517 non_lazy_ibt_plt
->plt_got_offset
) == 0)
4519 /* Match PIC IBT PLT. */
4520 plt_type
= plt_second
| plt_pic
;
4521 non_lazy_plt
= non_lazy_ibt_plt
;
4525 if (plt_type
== plt_unknown
)
4527 free (plt_contents
);
4532 plts
[j
].type
= plt_type
;
4534 if ((plt_type
& plt_lazy
))
4536 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
4537 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
4538 /* Skip PLT0 in lazy PLT. */
4543 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
4544 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
4548 /* Skip lazy PLT when the second PLT is used. */
4549 if ((plt_type
& (plt_lazy
| plt_second
))
4550 == (plt_lazy
| plt_second
))
4554 n
= plt
->size
/ plts
[j
].plt_entry_size
;
4559 plts
[j
].contents
= plt_contents
;
4561 /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
4562 if ((plt_type
& plt_pic
))
4563 got_addr
= (bfd_vma
) -1;
4566 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
4567 got_addr
, plts
, dynsyms
,
4571 /* Set up i386 GNU properties. Return the first relocatable ELF input
4572 with GNU properties if found. Otherwise, return NULL. */
4575 elf_i386_link_setup_gnu_properties (struct bfd_link_info
*info
)
4577 struct elf_x86_init_table init_table
;
4579 init_table
.normal_target
= FALSE
;
4580 init_table
.is_vxworks
= FALSE
;
4581 switch (get_elf_i386_backend_data (info
->output_bfd
)->os
)
4584 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4585 init_table
.non_lazy_plt
= &elf_i386_non_lazy_plt
;
4586 init_table
.lazy_ibt_plt
= &elf_i386_lazy_ibt_plt
;
4587 init_table
.non_lazy_ibt_plt
= &elf_i386_non_lazy_ibt_plt
;
4588 init_table
.normal_target
= TRUE
;
4591 init_table
.lazy_plt
= &elf_i386_lazy_plt
;
4592 init_table
.non_lazy_plt
= NULL
;
4593 init_table
.lazy_ibt_plt
= NULL
;
4594 init_table
.non_lazy_ibt_plt
= NULL
;
4595 init_table
.is_vxworks
= TRUE
;
4598 init_table
.lazy_plt
= &elf_i386_nacl_plt
;
4599 init_table
.non_lazy_plt
= NULL
;
4600 init_table
.lazy_ibt_plt
= NULL
;
4601 init_table
.non_lazy_ibt_plt
= NULL
;
4605 init_table
.r_info
= elf32_r_info
;
4606 init_table
.r_sym
= elf32_r_sym
;
4608 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
4611 #define TARGET_LITTLE_SYM i386_elf32_vec
4612 #define TARGET_LITTLE_NAME "elf32-i386"
4613 #define ELF_ARCH bfd_arch_i386
4614 #define ELF_TARGET_ID I386_ELF_DATA
4615 #define ELF_MACHINE_CODE EM_386
4616 #define ELF_MAXPAGESIZE 0x1000
4618 #define elf_backend_can_gc_sections 1
4619 #define elf_backend_can_refcount 1
4620 #define elf_backend_want_got_plt 1
4621 #define elf_backend_plt_readonly 1
4622 #define elf_backend_want_plt_sym 0
4623 #define elf_backend_got_header_size 12
4624 #define elf_backend_plt_alignment 4
4625 #define elf_backend_dtrel_excludes_plt 1
4626 #define elf_backend_extern_protected_data 1
4627 #define elf_backend_caches_rawsize 1
4628 #define elf_backend_want_dynrelro 1
4630 /* Support RELA for objdump of prelink objects. */
4631 #define elf_info_to_howto elf_i386_info_to_howto_rel
4632 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4634 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4635 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4636 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4637 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
4639 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4640 #define elf_backend_check_relocs elf_i386_check_relocs
4641 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
4642 #define elf_backend_fake_sections elf_i386_fake_sections
4643 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4644 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4645 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
4646 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4647 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4648 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4649 #define elf_backend_relocate_section elf_i386_relocate_section
4650 #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
4652 #include "elf32-target.h"
4654 /* FreeBSD support. */
4656 #undef TARGET_LITTLE_SYM
4657 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
4658 #undef TARGET_LITTLE_NAME
4659 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4661 #define ELF_OSABI ELFOSABI_FREEBSD
4663 /* The kernel recognizes executables as valid only if they carry a
4664 "FreeBSD" label in the ELF header. So we put this label on all
4665 executables and (for simplicity) also all other object files. */
4668 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4670 _bfd_elf_post_process_headers (abfd
, info
);
4672 #ifdef OLD_FREEBSD_ABI_LABEL
4674 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4675 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
4676 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4681 #undef elf_backend_post_process_headers
4682 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4684 #define elf32_bed elf32_i386_fbsd_bed
4686 #undef elf_backend_add_symbol_hook
4688 #include "elf32-target.h"
4692 #undef TARGET_LITTLE_SYM
4693 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
4694 #undef TARGET_LITTLE_NAME
4695 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
4697 #undef elf_backend_post_process_headers
4699 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4700 objects won't be recognized. */
4704 #define elf32_bed elf32_i386_sol2_bed
4706 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
4708 #undef elf_backend_static_tls_alignment
4709 #define elf_backend_static_tls_alignment 8
4711 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4713 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4715 #undef elf_backend_want_plt_sym
4716 #define elf_backend_want_plt_sym 1
4718 #undef elf_backend_strtab_flags
4719 #define elf_backend_strtab_flags SHF_STRINGS
4721 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
4722 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
4723 FALSE otherwise. ISECTION is the best guess matching section from the
4724 input bfd IBFD, but it might be NULL. */
4727 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
4728 bfd
*obfd ATTRIBUTE_UNUSED
,
4729 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
4730 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
4732 /* PR 19938: FIXME: Need to add code for setting the sh_info
4733 and sh_link fields of Solaris specific section types. */
4736 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
4737 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
4739 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
4741 The following values should be set:
4744 -----------------------------------------------------------------------------
4745 SHT_SUNW_ancillary The section header index of 0
4746 [0x6fffffee] the associated string table.
4748 SHT_SUNW_capinfo The section header index of For a dynamic object, the
4749 [0x6ffffff0] the associated symbol table. section header index of
4751 SHT_SUNW_capchain table,
4754 SHT_SUNW_symsort The section header index of 0
4755 [0x6ffffff1] the associated symbol table.
4757 SHT_SUNW_tlssort The section header index of 0
4758 [0x6ffffff2] the associated symbol table.
4760 SHT_SUNW_LDYNSYM The section header index of One greater than the
4761 [0x6ffffff3] the associated string table. symbol table index of the
4762 This index is the same string last local symbol,
4763 table used by the SHT_DYNSYM STB_LOCAL. Since
4764 section. SHT_SUNW_LDYNSYM only
4765 contains local symbols,
4766 sh_info is equivalent to
4767 the number of symbols in
4770 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
4771 [0x6ffffff5] the section header index of to named strings, the
4772 the associated section header index of
4773 SHT_SUNW_capinfo table, the associated string
4774 otherwise 0. table, otherwise 0.
4776 SHT_SUNW_move The section header index of 0
4777 [0x6ffffffa] the associated symbol table.
4782 SHT_SUNW_syminfo The section header index of The section header index
4783 [0x6ffffffc] the associated symbol table. of the associated
4786 SHT_SUNW_verdef The section header index of The number of version
4787 [0x6ffffffd] the associated string table. definitions within the
4790 SHT_SUNW_verneed The section header index of The number of version
4791 [0x6ffffffe] the associated string table. dependencies within the
4794 SHT_SUNW_versym The section header index of 0
4795 [0x6fffffff] the associated symbol table. */
4798 #undef elf_backend_copy_special_section_fields
4799 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
4801 #include "elf32-target.h"
4803 /* Intel MCU support. */
4806 elf32_iamcu_elf_object_p (bfd
*abfd
)
4808 /* Set the right machine number for an IAMCU elf32 file. */
4809 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
4813 #undef TARGET_LITTLE_SYM
4814 #define TARGET_LITTLE_SYM iamcu_elf32_vec
4815 #undef TARGET_LITTLE_NAME
4816 #define TARGET_LITTLE_NAME "elf32-iamcu"
4818 #define ELF_ARCH bfd_arch_iamcu
4820 #undef ELF_MACHINE_CODE
4821 #define ELF_MACHINE_CODE EM_IAMCU
4826 #define elf32_bed elf32_iamcu_bed
4828 #undef elf_backend_object_p
4829 #define elf_backend_object_p elf32_iamcu_elf_object_p
4831 #undef elf_backend_static_tls_alignment
4833 #undef elf_backend_want_plt_sym
4834 #define elf_backend_want_plt_sym 0
4836 #undef elf_backend_strtab_flags
4837 #undef elf_backend_copy_special_section_fields
4839 #include "elf32-target.h"
4841 /* Restore defaults. */
4843 #define ELF_ARCH bfd_arch_i386
4844 #undef ELF_MACHINE_CODE
4845 #define ELF_MACHINE_CODE EM_386
4847 /* Native Client support. */
4849 #undef TARGET_LITTLE_SYM
4850 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
4851 #undef TARGET_LITTLE_NAME
4852 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
4854 #define elf32_bed elf32_i386_nacl_bed
4856 #undef ELF_MAXPAGESIZE
4857 #define ELF_MAXPAGESIZE 0x10000
4859 /* Restore defaults. */
4861 #undef elf_backend_want_plt_sym
4862 #define elf_backend_want_plt_sym 0
4863 #undef elf_backend_post_process_headers
4864 #undef elf_backend_static_tls_alignment
4866 /* NaCl uses substantially different PLT entries for the same effects. */
4868 #undef elf_backend_plt_alignment
4869 #define elf_backend_plt_alignment 5
4870 #define NACL_PLT_ENTRY_SIZE 64
4871 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
4873 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
4875 0xff, 0x35, /* pushl contents of address */
4876 0, 0, 0, 0, /* replaced with address of .got + 4. */
4877 0x8b, 0x0d, /* movl contents of address, %ecx */
4878 0, 0, 0, 0, /* replaced with address of .got + 8. */
4879 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
4880 0xff, 0xe1 /* jmp *%ecx */
4883 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
4885 0x8b, 0x0d, /* movl contents of address, %ecx */
4886 0, 0, 0, 0, /* replaced with GOT slot address. */
4887 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
4888 0xff, 0xe1, /* jmp *%ecx */
4890 /* Pad to the next 32-byte boundary with nop instructions. */
4892 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4893 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4895 /* Lazy GOT entries point here (32-byte aligned). */
4896 0x68, /* pushl immediate */
4897 0, 0, 0, 0, /* replaced with reloc offset. */
4898 0xe9, /* jmp relative */
4899 0, 0, 0, 0, /* replaced with offset to .plt. */
4901 /* Pad to the next 32-byte boundary with nop instructions. */
4902 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4903 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4907 static const bfd_byte
4908 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
4910 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
4911 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
4912 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
4913 0xff, 0xe1, /* jmp *%ecx */
4915 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
4916 so pad to that size with nop instructions. */
4917 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
4920 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
4922 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
4923 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
4924 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
4925 0xff, 0xe1, /* jmp *%ecx */
4927 /* Pad to the next 32-byte boundary with nop instructions. */
4929 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4930 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4932 /* Lazy GOT entries point here (32-byte aligned). */
4933 0x68, /* pushl immediate */
4934 0, 0, 0, 0, /* replaced with offset into relocation table. */
4935 0xe9, /* jmp relative */
4936 0, 0, 0, 0, /* replaced with offset to start of .plt. */
4938 /* Pad to the next 32-byte boundary with nop instructions. */
4939 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4940 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
4944 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
4946 #if (PLT_CIE_LENGTH != 20 \
4947 || PLT_FDE_LENGTH != 36 \
4948 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
4949 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
4950 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
4952 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
4953 0, 0, 0, 0, /* CIE ID */
4954 1, /* CIE version */
4955 'z', 'R', 0, /* Augmentation string */
4956 1, /* Code alignment factor */
4957 0x7c, /* Data alignment factor: -4 */
4958 8, /* Return address column */
4959 1, /* Augmentation size */
4960 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
4961 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
4962 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
4963 DW_CFA_nop
, DW_CFA_nop
,
4965 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
4966 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
4967 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
4968 0, 0, 0, 0, /* .plt size goes here */
4969 0, /* Augmentation size */
4970 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
4971 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
4972 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
4973 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
4974 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
4975 13, /* Block length */
4976 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
4977 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
4978 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
4979 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
4980 DW_CFA_nop
, DW_CFA_nop
4983 static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt
=
4985 elf_i386_nacl_plt0_entry
, /* plt0_entry */
4986 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
4987 elf_i386_nacl_plt_entry
, /* plt_entry */
4988 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
4989 2, /* plt0_got1_offset */
4990 8, /* plt0_got2_offset */
4991 0, /* plt0_got2_insn_end */
4992 2, /* plt_got_offset */
4993 33, /* plt_reloc_offset */
4994 38, /* plt_plt_offset */
4995 0, /* plt_got_insn_size */
4996 0, /* plt_plt_insn_end */
4997 32, /* plt_lazy_offset */
4998 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
4999 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
5000 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
5001 sizeof (elf_i386_nacl_eh_frame_plt
) /* eh_frame_plt_size */
5004 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
5006 0x90, /* plt0_pad_byte: nop insn */
5011 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
5013 /* Set the right machine number for a NaCl i386 ELF32 file. */
5014 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
5018 #undef elf_backend_arch_data
5019 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
5021 #undef elf_backend_object_p
5022 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
5023 #undef elf_backend_modify_segment_map
5024 #define elf_backend_modify_segment_map nacl_modify_segment_map
5025 #undef elf_backend_modify_program_headers
5026 #define elf_backend_modify_program_headers nacl_modify_program_headers
5027 #undef elf_backend_final_write_processing
5028 #define elf_backend_final_write_processing nacl_final_write_processing
5030 #include "elf32-target.h"
5032 /* Restore defaults. */
5033 #undef elf_backend_object_p
5034 #undef elf_backend_modify_segment_map
5035 #undef elf_backend_modify_program_headers
5036 #undef elf_backend_final_write_processing
5038 /* VxWorks support. */
5040 #undef TARGET_LITTLE_SYM
5041 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
5042 #undef TARGET_LITTLE_NAME
5043 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
5045 #undef ELF_MAXPAGESIZE
5046 #define ELF_MAXPAGESIZE 0x1000
5047 #undef elf_backend_plt_alignment
5048 #define elf_backend_plt_alignment 4
5050 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
5052 0x90, /* plt0_pad_byte */
5056 #undef elf_backend_arch_data
5057 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
5059 #undef elf_backend_relocs_compatible
5060 #undef elf_backend_add_symbol_hook
5061 #define elf_backend_add_symbol_hook \
5062 elf_vxworks_add_symbol_hook
5063 #undef elf_backend_link_output_symbol_hook
5064 #define elf_backend_link_output_symbol_hook \
5065 elf_vxworks_link_output_symbol_hook
5066 #undef elf_backend_emit_relocs
5067 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5068 #undef elf_backend_final_write_processing
5069 #define elf_backend_final_write_processing \
5070 elf_vxworks_final_write_processing
5071 #undef elf_backend_static_tls_alignment
5073 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5075 #undef elf_backend_want_plt_sym
5076 #define elf_backend_want_plt_sym 1
5079 #define elf32_bed elf32_i386_vxworks_bed
5081 #include "elf32-target.h"