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. */
27 #include "elf-vxworks.h"
28 #include "bfd_stdint.h"
32 #include "opcode/i386.h"
34 /* 386 uses REL relocations instead of RELA. */
39 static reloc_howto_type elf_howto_table
[]=
41 HOWTO(R_386_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
42 bfd_elf_generic_reloc
, "R_386_NONE",
43 TRUE
, 0x00000000, 0x00000000, FALSE
),
44 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
45 bfd_elf_generic_reloc
, "R_386_32",
46 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
47 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
48 bfd_elf_generic_reloc
, "R_386_PC32",
49 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
50 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
51 bfd_elf_generic_reloc
, "R_386_GOT32",
52 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
53 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
54 bfd_elf_generic_reloc
, "R_386_PLT32",
55 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
56 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
57 bfd_elf_generic_reloc
, "R_386_COPY",
58 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
59 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
60 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
61 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
62 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
64 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
65 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
66 bfd_elf_generic_reloc
, "R_386_RELATIVE",
67 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
68 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
69 bfd_elf_generic_reloc
, "R_386_GOTOFF",
70 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
71 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
72 bfd_elf_generic_reloc
, "R_386_GOTPC",
73 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
75 /* We have a gap in the reloc numbers here.
76 R_386_standard counts the number up to this point, and
77 R_386_ext_offset is the value to subtract from a reloc type of
78 R_386_16 thru R_386_PC8 to form an index into this table. */
79 #define R_386_standard (R_386_GOTPC + 1)
80 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
82 /* These relocs are a GNU extension. */
83 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
84 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
85 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
86 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_386_TLS_IE",
88 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
89 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
90 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
91 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
92 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_386_TLS_LE",
94 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
95 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_386_TLS_GD",
97 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
98 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
100 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
101 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
102 bfd_elf_generic_reloc
, "R_386_16",
103 TRUE
, 0xffff, 0xffff, FALSE
),
104 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
105 bfd_elf_generic_reloc
, "R_386_PC16",
106 TRUE
, 0xffff, 0xffff, TRUE
),
107 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
108 bfd_elf_generic_reloc
, "R_386_8",
109 TRUE
, 0xff, 0xff, FALSE
),
110 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
111 bfd_elf_generic_reloc
, "R_386_PC8",
112 TRUE
, 0xff, 0xff, TRUE
),
114 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
115 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
116 /* These are common with Solaris TLS implementation. */
117 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
118 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
119 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
120 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
121 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
122 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
123 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
124 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
125 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
126 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
128 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
129 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
131 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
132 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
133 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
134 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
135 HOWTO(R_386_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
136 bfd_elf_generic_reloc
, "R_386_SIZE32",
137 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
138 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
139 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
140 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
141 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
142 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
144 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
145 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
146 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
147 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
148 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
149 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
150 HOWTO(R_386_GOT32X
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
151 bfd_elf_generic_reloc
, "R_386_GOT32X",
152 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
155 #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
156 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
158 /* GNU extension to record C++ vtable hierarchy. */
159 HOWTO (R_386_GNU_VTINHERIT
, /* type */
161 2, /* size (0 = byte, 1 = short, 2 = long) */
163 FALSE
, /* pc_relative */
165 complain_overflow_dont
, /* complain_on_overflow */
166 NULL
, /* special_function */
167 "R_386_GNU_VTINHERIT", /* name */
168 FALSE
, /* partial_inplace */
171 FALSE
), /* pcrel_offset */
173 /* GNU extension to record C++ vtable member usage. */
174 HOWTO (R_386_GNU_VTENTRY
, /* type */
176 2, /* size (0 = byte, 1 = short, 2 = long) */
178 FALSE
, /* pc_relative */
180 complain_overflow_dont
, /* complain_on_overflow */
181 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
182 "R_386_GNU_VTENTRY", /* name */
183 FALSE
, /* partial_inplace */
186 FALSE
) /* pcrel_offset */
188 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
192 #ifdef DEBUG_GEN_RELOC
194 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
199 static reloc_howto_type
*
200 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
201 bfd_reloc_code_real_type code
)
206 TRACE ("BFD_RELOC_NONE");
207 return &elf_howto_table
[R_386_NONE
];
210 TRACE ("BFD_RELOC_32");
211 return &elf_howto_table
[R_386_32
];
214 TRACE ("BFD_RELOC_CTOR");
215 return &elf_howto_table
[R_386_32
];
217 case BFD_RELOC_32_PCREL
:
218 TRACE ("BFD_RELOC_PC32");
219 return &elf_howto_table
[R_386_PC32
];
221 case BFD_RELOC_386_GOT32
:
222 TRACE ("BFD_RELOC_386_GOT32");
223 return &elf_howto_table
[R_386_GOT32
];
225 case BFD_RELOC_386_PLT32
:
226 TRACE ("BFD_RELOC_386_PLT32");
227 return &elf_howto_table
[R_386_PLT32
];
229 case BFD_RELOC_386_COPY
:
230 TRACE ("BFD_RELOC_386_COPY");
231 return &elf_howto_table
[R_386_COPY
];
233 case BFD_RELOC_386_GLOB_DAT
:
234 TRACE ("BFD_RELOC_386_GLOB_DAT");
235 return &elf_howto_table
[R_386_GLOB_DAT
];
237 case BFD_RELOC_386_JUMP_SLOT
:
238 TRACE ("BFD_RELOC_386_JUMP_SLOT");
239 return &elf_howto_table
[R_386_JUMP_SLOT
];
241 case BFD_RELOC_386_RELATIVE
:
242 TRACE ("BFD_RELOC_386_RELATIVE");
243 return &elf_howto_table
[R_386_RELATIVE
];
245 case BFD_RELOC_386_GOTOFF
:
246 TRACE ("BFD_RELOC_386_GOTOFF");
247 return &elf_howto_table
[R_386_GOTOFF
];
249 case BFD_RELOC_386_GOTPC
:
250 TRACE ("BFD_RELOC_386_GOTPC");
251 return &elf_howto_table
[R_386_GOTPC
];
253 /* These relocs are a GNU extension. */
254 case BFD_RELOC_386_TLS_TPOFF
:
255 TRACE ("BFD_RELOC_386_TLS_TPOFF");
256 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
258 case BFD_RELOC_386_TLS_IE
:
259 TRACE ("BFD_RELOC_386_TLS_IE");
260 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
262 case BFD_RELOC_386_TLS_GOTIE
:
263 TRACE ("BFD_RELOC_386_TLS_GOTIE");
264 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
266 case BFD_RELOC_386_TLS_LE
:
267 TRACE ("BFD_RELOC_386_TLS_LE");
268 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
270 case BFD_RELOC_386_TLS_GD
:
271 TRACE ("BFD_RELOC_386_TLS_GD");
272 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
274 case BFD_RELOC_386_TLS_LDM
:
275 TRACE ("BFD_RELOC_386_TLS_LDM");
276 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
279 TRACE ("BFD_RELOC_16");
280 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
282 case BFD_RELOC_16_PCREL
:
283 TRACE ("BFD_RELOC_16_PCREL");
284 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
287 TRACE ("BFD_RELOC_8");
288 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
290 case BFD_RELOC_8_PCREL
:
291 TRACE ("BFD_RELOC_8_PCREL");
292 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
294 /* Common with Sun TLS implementation. */
295 case BFD_RELOC_386_TLS_LDO_32
:
296 TRACE ("BFD_RELOC_386_TLS_LDO_32");
297 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
299 case BFD_RELOC_386_TLS_IE_32
:
300 TRACE ("BFD_RELOC_386_TLS_IE_32");
301 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
303 case BFD_RELOC_386_TLS_LE_32
:
304 TRACE ("BFD_RELOC_386_TLS_LE_32");
305 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
307 case BFD_RELOC_386_TLS_DTPMOD32
:
308 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
309 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
311 case BFD_RELOC_386_TLS_DTPOFF32
:
312 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
313 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
315 case BFD_RELOC_386_TLS_TPOFF32
:
316 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
317 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
319 case BFD_RELOC_SIZE32
:
320 TRACE ("BFD_RELOC_SIZE32");
321 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
323 case BFD_RELOC_386_TLS_GOTDESC
:
324 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
325 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
327 case BFD_RELOC_386_TLS_DESC_CALL
:
328 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
329 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
331 case BFD_RELOC_386_TLS_DESC
:
332 TRACE ("BFD_RELOC_386_TLS_DESC");
333 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
335 case BFD_RELOC_386_IRELATIVE
:
336 TRACE ("BFD_RELOC_386_IRELATIVE");
337 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
339 case BFD_RELOC_386_GOT32X
:
340 TRACE ("BFD_RELOC_386_GOT32X");
341 return &elf_howto_table
[R_386_GOT32X
- R_386_tls_offset
];
343 case BFD_RELOC_VTABLE_INHERIT
:
344 TRACE ("BFD_RELOC_VTABLE_INHERIT");
345 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
347 case BFD_RELOC_VTABLE_ENTRY
:
348 TRACE ("BFD_RELOC_VTABLE_ENTRY");
349 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
359 static reloc_howto_type
*
360 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
365 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
366 if (elf_howto_table
[i
].name
!= NULL
367 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
368 return &elf_howto_table
[i
];
373 static reloc_howto_type
*
374 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
378 if ((indx
= r_type
) >= R_386_standard
379 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
380 >= R_386_ext
- R_386_standard
)
381 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
382 >= R_386_ext2
- R_386_ext
)
383 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
384 >= R_386_vt
- R_386_ext2
))
386 /* xgettext:c-format */
387 _bfd_error_handler (_("%B: invalid relocation type %d"),
391 /* PR 17512: file: 0f67f69d. */
392 if (elf_howto_table
[indx
].type
!= r_type
)
394 return &elf_howto_table
[indx
];
398 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
400 Elf_Internal_Rela
*dst
)
402 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
403 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
406 /* Return whether a symbol name implies a local label. The UnixWare
407 2.1 cc generates temporary symbols that start with .X, so we
408 recognize them here. FIXME: do other SVR4 compilers also use .X?.
409 If so, we should move the .X recognition into
410 _bfd_elf_is_local_label_name. */
413 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
415 if (name
[0] == '.' && name
[1] == 'X')
418 return _bfd_elf_is_local_label_name (abfd
, name
);
421 /* Support for core dump NOTE sections. */
424 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
429 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
431 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
437 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
440 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
444 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
448 switch (note
->descsz
)
453 case 144: /* Linux/i386 */
455 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
458 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
468 /* Make a ".reg/999" section. */
469 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
470 size
, note
->descpos
+ offset
);
474 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
476 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
478 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
483 elf_tdata (abfd
)->core
->program
484 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
485 elf_tdata (abfd
)->core
->command
486 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
490 switch (note
->descsz
)
495 case 124: /* Linux/i386 elf_prpsinfo. */
496 elf_tdata (abfd
)->core
->pid
497 = bfd_get_32 (abfd
, note
->descdata
+ 12);
498 elf_tdata (abfd
)->core
->program
499 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
500 elf_tdata (abfd
)->core
->command
501 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
505 /* Note that for some reason, a spurious space is tacked
506 onto the end of the args in some (at least one anyway)
507 implementations, so strip it off if it exists. */
509 char *command
= elf_tdata (abfd
)->core
->command
;
510 int n
= strlen (command
);
512 if (0 < n
&& command
[n
- 1] == ' ')
513 command
[n
- 1] = '\0';
519 /* Functions for the i386 ELF linker.
521 In order to gain some understanding of code in this file without
522 knowing all the intricate details of the linker, note the
525 Functions named elf_i386_* are called by external routines, other
526 functions are only called locally. elf_i386_* functions appear
527 in this file more or less in the order in which they are called
528 from external routines. eg. elf_i386_check_relocs is called
529 early in the link process, elf_i386_finish_dynamic_sections is
530 one of the last functions. */
533 /* The name of the dynamic interpreter. This is put in the .interp
536 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
538 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
539 copying dynamic variables from a shared lib into an app's dynbss
540 section, and instead use a dynamic relocation to point into the
542 #define ELIMINATE_COPY_RELOCS 1
544 /* The size in bytes of an entry in the procedure linkage table. */
546 #define PLT_ENTRY_SIZE 16
548 /* The first entry in an absolute procedure linkage table looks like
549 this. See the SVR4 ABI i386 supplement to see how this works.
550 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
552 static const bfd_byte elf_i386_plt0_entry
[12] =
554 0xff, 0x35, /* pushl contents of address */
555 0, 0, 0, 0, /* replaced with address of .got + 4. */
556 0xff, 0x25, /* jmp indirect */
557 0, 0, 0, 0 /* replaced with address of .got + 8. */
560 /* Subsequent entries in an absolute procedure linkage table look like
563 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
565 0xff, 0x25, /* jmp indirect */
566 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
567 0x68, /* pushl immediate */
568 0, 0, 0, 0, /* replaced with offset into relocation table. */
569 0xe9, /* jmp relative */
570 0, 0, 0, 0 /* replaced with offset to start of .plt. */
573 /* The first entry in a PIC procedure linkage table look like this.
574 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
576 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
578 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
579 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
582 /* Subsequent entries in a PIC procedure linkage table look like this. */
584 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
586 0xff, 0xa3, /* jmp *offset(%ebx) */
587 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
588 0x68, /* pushl immediate */
589 0, 0, 0, 0, /* replaced with offset into relocation table. */
590 0xe9, /* jmp relative */
591 0, 0, 0, 0 /* replaced with offset to start of .plt. */
594 /* Entries in the GOT procedure linkage table look like this. */
596 static const bfd_byte elf_i386_got_plt_entry
[8] =
598 0xff, 0x25, /* jmp indirect */
599 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
600 0x66, 0x90 /* xchg %ax,%ax */
603 /* Entries in the PIC GOT procedure linkage table look like this. */
605 static const bfd_byte elf_i386_pic_got_plt_entry
[8] =
607 0xff, 0xa3, /* jmp *offset(%ebx) */
608 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
609 0x66, 0x90 /* xchg %ax,%ax */
612 /* .eh_frame covering the .plt section. */
614 static const bfd_byte elf_i386_eh_frame_plt
[] =
616 #define PLT_CIE_LENGTH 20
617 #define PLT_FDE_LENGTH 36
618 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
619 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
620 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
621 0, 0, 0, 0, /* CIE ID */
623 'z', 'R', 0, /* Augmentation string */
624 1, /* Code alignment factor */
625 0x7c, /* Data alignment factor */
626 8, /* Return address column */
627 1, /* Augmentation size */
628 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
629 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
630 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
631 DW_CFA_nop
, DW_CFA_nop
,
633 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
634 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
635 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
636 0, 0, 0, 0, /* .plt size goes here */
637 0, /* Augmentation size */
638 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
639 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
640 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
641 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
642 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
643 11, /* Block length */
644 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
645 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
646 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
647 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
648 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
651 /* .eh_frame covering the .plt.got section. */
653 static const bfd_byte elf_i386_eh_frame_plt_got
[] =
655 #define PLT_GOT_FDE_LENGTH 16
656 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
657 0, 0, 0, 0, /* CIE ID */
659 'z', 'R', 0, /* Augmentation string */
660 1, /* Code alignment factor */
661 0x7c, /* Data alignment factor */
662 8, /* Return address column */
663 1, /* Augmentation size */
664 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
665 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
666 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
667 DW_CFA_nop
, DW_CFA_nop
,
669 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
670 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
671 0, 0, 0, 0, /* the start of .plt.got goes here */
672 0, 0, 0, 0, /* .plt.got size goes here */
673 0, /* Augmentation size */
674 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
677 struct elf_i386_plt_layout
679 /* The first entry in an absolute procedure linkage table looks like this. */
680 const bfd_byte
*plt0_entry
;
681 unsigned int plt0_entry_size
;
683 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
684 unsigned int plt0_got1_offset
;
685 unsigned int plt0_got2_offset
;
687 /* Later entries in an absolute procedure linkage table look like this. */
688 const bfd_byte
*plt_entry
;
689 unsigned int plt_entry_size
;
691 /* Offsets into plt_entry that are to be replaced with... */
692 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
693 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
694 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
696 /* Offset into plt_entry where the initial value of the GOT entry points. */
697 unsigned int plt_lazy_offset
;
699 /* The first entry in a PIC procedure linkage table looks like this. */
700 const bfd_byte
*pic_plt0_entry
;
702 /* Subsequent entries in a PIC procedure linkage table look like this. */
703 const bfd_byte
*pic_plt_entry
;
705 /* .eh_frame covering the .plt section. */
706 const bfd_byte
*eh_frame_plt
;
707 unsigned int eh_frame_plt_size
;
709 /* .eh_frame covering the .plt.got section. */
710 const bfd_byte
*eh_frame_plt_got
;
711 unsigned int eh_frame_plt_got_size
;
714 #define GET_PLT_ENTRY_SIZE(abfd) \
715 get_elf_i386_backend_data (abfd)->plt->plt_entry_size
717 /* These are the standard parameters. */
718 static const struct elf_i386_plt_layout elf_i386_plt
=
720 elf_i386_plt0_entry
, /* plt0_entry */
721 sizeof (elf_i386_plt0_entry
), /* plt0_entry_size */
722 2, /* plt0_got1_offset */
723 8, /* plt0_got2_offset */
724 elf_i386_plt_entry
, /* plt_entry */
725 PLT_ENTRY_SIZE
, /* plt_entry_size */
726 2, /* plt_got_offset */
727 7, /* plt_reloc_offset */
728 12, /* plt_plt_offset */
729 6, /* plt_lazy_offset */
730 elf_i386_pic_plt0_entry
, /* pic_plt0_entry */
731 elf_i386_pic_plt_entry
, /* pic_plt_entry */
732 elf_i386_eh_frame_plt
, /* eh_frame_plt */
733 sizeof (elf_i386_eh_frame_plt
), /* eh_frame_plt_size */
734 elf_i386_eh_frame_plt_got
, /* eh_frame_plt_got */
735 sizeof (elf_i386_eh_frame_plt_got
), /* eh_frame_plt_got_size */
739 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
740 for the PLTResolve stub and then for each PLT entry. */
741 #define PLTRESOLVE_RELOCS_SHLIB 0
742 #define PLTRESOLVE_RELOCS 2
743 #define PLT_NON_JUMP_SLOT_RELOCS 2
745 /* Architecture-specific backend data for i386. */
747 struct elf_i386_backend_data
749 /* Parameters describing PLT generation. */
750 const struct elf_i386_plt_layout
*plt
;
752 /* Value used to fill the unused bytes of the first PLT entry. */
753 bfd_byte plt0_pad_byte
;
755 /* True if the target system is VxWorks. */
759 #define get_elf_i386_backend_data(abfd) \
760 ((const struct elf_i386_backend_data *) \
761 get_elf_backend_data (abfd)->arch_data)
763 /* These are the standard parameters. */
764 static const struct elf_i386_backend_data elf_i386_arch_bed
=
766 &elf_i386_plt
, /* plt */
767 0, /* plt0_pad_byte */
771 #define elf_backend_arch_data &elf_i386_arch_bed
773 /* Is a undefined weak symbol which is resolved to 0. Reference to an
774 undefined weak symbol is resolved to 0 when building executable if
776 1. Has non-GOT/non-PLT relocations in text section. Or
777 2. Has no GOT/PLT relocation.
779 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
780 ((EH)->elf.root.type == bfd_link_hash_undefweak \
781 && bfd_link_executable (INFO) \
782 && (elf_i386_hash_table (INFO)->interp == NULL \
784 || (EH)->has_non_got_reloc \
785 || !(INFO)->dynamic_undefined_weak))
787 /* i386 ELF linker hash entry. */
789 struct elf_i386_link_hash_entry
791 struct elf_link_hash_entry elf
;
793 /* Track dynamic relocs copied for this symbol. */
794 struct elf_dyn_relocs
*dyn_relocs
;
796 #define GOT_UNKNOWN 0
800 #define GOT_TLS_IE_POS 5
801 #define GOT_TLS_IE_NEG 6
802 #define GOT_TLS_IE_BOTH 7
803 #define GOT_TLS_GDESC 8
804 #define GOT_TLS_GD_BOTH_P(type) \
805 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
806 #define GOT_TLS_GD_P(type) \
807 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
808 #define GOT_TLS_GDESC_P(type) \
809 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
810 #define GOT_TLS_GD_ANY_P(type) \
811 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
812 unsigned char tls_type
;
814 /* Symbol is referenced by R_386_GOTOFF relocation. */
815 unsigned int gotoff_ref
: 1;
817 /* Symbol has GOT or PLT relocations. */
818 unsigned int has_got_reloc
: 1;
820 /* Symbol has non-GOT/non-PLT relocations in text sections. */
821 unsigned int has_non_got_reloc
: 1;
823 /* 0: symbol isn't ___tls_get_addr.
824 1: symbol is ___tls_get_addr.
825 2: symbol is unknown. */
826 unsigned int tls_get_addr
: 2;
828 /* Reference count of C/C++ function pointer relocations in read-write
829 section which can be resolved at run-time. */
830 bfd_signed_vma func_pointer_refcount
;
832 /* Information about the GOT PLT entry. Filled when there are both
833 GOT and PLT relocations against the same function. */
834 union gotplt_union plt_got
;
836 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
837 starting at the end of the jump table. */
841 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
843 struct elf_i386_obj_tdata
845 struct elf_obj_tdata root
;
847 /* tls_type for each local got entry. */
848 char *local_got_tls_type
;
850 /* GOTPLT entries for TLS descriptors. */
851 bfd_vma
*local_tlsdesc_gotent
;
854 #define elf_i386_tdata(abfd) \
855 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
857 #define elf_i386_local_got_tls_type(abfd) \
858 (elf_i386_tdata (abfd)->local_got_tls_type)
860 #define elf_i386_local_tlsdesc_gotent(abfd) \
861 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
863 #define is_i386_elf(bfd) \
864 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
865 && elf_tdata (bfd) != NULL \
866 && elf_object_id (bfd) == I386_ELF_DATA)
869 elf_i386_mkobject (bfd
*abfd
)
871 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
875 /* i386 ELF linker hash table. */
877 struct elf_i386_link_hash_table
879 struct elf_link_hash_table elf
;
881 /* Short-cuts to get to dynamic linker sections. */
883 asection
*plt_eh_frame
;
885 asection
*plt_got_eh_frame
;
889 bfd_signed_vma refcount
;
893 /* The amount of space used by the reserved portion of the sgotplt
894 section, plus whatever space is used by the jump slots. */
895 bfd_vma sgotplt_jump_table_size
;
897 /* Small local sym cache. */
898 struct sym_cache sym_cache
;
900 /* _TLS_MODULE_BASE_ symbol. */
901 struct bfd_link_hash_entry
*tls_module_base
;
903 /* Used by local STT_GNU_IFUNC symbols. */
904 htab_t loc_hash_table
;
905 void * loc_hash_memory
;
907 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
910 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
911 bfd_vma next_tls_desc_index
;
913 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
914 bfd_vma next_jump_slot_index
;
916 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
917 bfd_vma next_irelative_index
;
919 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
920 to read-only sections. */
921 bfd_boolean readonly_dynrelocs_against_ifunc
;
924 /* Get the i386 ELF linker hash table from a link_info structure. */
926 #define elf_i386_hash_table(p) \
927 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
928 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
930 #define elf_i386_compute_jump_table_size(htab) \
931 ((htab)->elf.srelplt->reloc_count * 4)
933 /* Create an entry in an i386 ELF linker hash table. */
935 static struct bfd_hash_entry
*
936 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
937 struct bfd_hash_table
*table
,
940 /* Allocate the structure if it has not already been allocated by a
944 entry
= (struct bfd_hash_entry
*)
945 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
950 /* Call the allocation method of the superclass. */
951 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
954 struct elf_i386_link_hash_entry
*eh
;
956 eh
= (struct elf_i386_link_hash_entry
*) entry
;
957 eh
->dyn_relocs
= NULL
;
958 eh
->tls_type
= GOT_UNKNOWN
;
960 eh
->has_got_reloc
= 0;
961 eh
->has_non_got_reloc
= 0;
962 eh
->tls_get_addr
= 2;
963 eh
->func_pointer_refcount
= 0;
964 eh
->plt_got
.offset
= (bfd_vma
) -1;
965 eh
->tlsdesc_got
= (bfd_vma
) -1;
971 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
972 for local symbol so that we can handle local STT_GNU_IFUNC symbols
973 as global symbol. We reuse indx and dynstr_index for local symbol
974 hash since they aren't used by global symbols in this backend. */
977 elf_i386_local_htab_hash (const void *ptr
)
979 struct elf_link_hash_entry
*h
980 = (struct elf_link_hash_entry
*) ptr
;
981 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
984 /* Compare local hash entries. */
987 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
989 struct elf_link_hash_entry
*h1
990 = (struct elf_link_hash_entry
*) ptr1
;
991 struct elf_link_hash_entry
*h2
992 = (struct elf_link_hash_entry
*) ptr2
;
994 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
997 /* Find and/or create a hash entry for local symbol. */
999 static struct elf_link_hash_entry
*
1000 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
1001 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1004 struct elf_i386_link_hash_entry e
, *ret
;
1005 asection
*sec
= abfd
->sections
;
1006 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1007 ELF32_R_SYM (rel
->r_info
));
1010 e
.elf
.indx
= sec
->id
;
1011 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1012 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1013 create
? INSERT
: NO_INSERT
);
1020 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
1024 ret
= (struct elf_i386_link_hash_entry
*)
1025 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1026 sizeof (struct elf_i386_link_hash_entry
));
1029 memset (ret
, 0, sizeof (*ret
));
1030 ret
->elf
.indx
= sec
->id
;
1031 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1032 ret
->elf
.dynindx
= -1;
1033 ret
->func_pointer_refcount
= 0;
1034 ret
->plt_got
.offset
= (bfd_vma
) -1;
1040 /* Destroy an i386 ELF linker hash table. */
1043 elf_i386_link_hash_table_free (bfd
*obfd
)
1045 struct elf_i386_link_hash_table
*htab
1046 = (struct elf_i386_link_hash_table
*) obfd
->link
.hash
;
1048 if (htab
->loc_hash_table
)
1049 htab_delete (htab
->loc_hash_table
);
1050 if (htab
->loc_hash_memory
)
1051 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1052 _bfd_elf_link_hash_table_free (obfd
);
1055 /* Create an i386 ELF linker hash table. */
1057 static struct bfd_link_hash_table
*
1058 elf_i386_link_hash_table_create (bfd
*abfd
)
1060 struct elf_i386_link_hash_table
*ret
;
1061 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
1063 ret
= (struct elf_i386_link_hash_table
*) bfd_zmalloc (amt
);
1067 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1068 elf_i386_link_hash_newfunc
,
1069 sizeof (struct elf_i386_link_hash_entry
),
1076 ret
->loc_hash_table
= htab_try_create (1024,
1077 elf_i386_local_htab_hash
,
1078 elf_i386_local_htab_eq
,
1080 ret
->loc_hash_memory
= objalloc_create ();
1081 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1083 elf_i386_link_hash_table_free (abfd
);
1086 ret
->elf
.root
.hash_table_free
= elf_i386_link_hash_table_free
;
1088 return &ret
->elf
.root
;
1091 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1092 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1096 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1098 struct elf_i386_link_hash_table
*htab
;
1100 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1103 htab
= elf_i386_hash_table (info
);
1107 /* Set the contents of the .interp section to the interpreter. */
1108 if (bfd_link_executable (info
) && !info
->nointerp
)
1110 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
1113 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1114 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1118 if (get_elf_i386_backend_data (dynobj
)->is_vxworks
1119 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
1123 if (!info
->no_ld_generated_unwind_info
1124 && htab
->plt_eh_frame
== NULL
1125 && htab
->elf
.splt
!= NULL
)
1127 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1128 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1129 | SEC_LINKER_CREATED
);
1131 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1132 if (htab
->plt_eh_frame
== NULL
1133 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 2))
1140 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1143 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1144 struct elf_link_hash_entry
*dir
,
1145 struct elf_link_hash_entry
*ind
)
1147 struct elf_i386_link_hash_entry
*edir
, *eind
;
1149 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1150 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1152 if (eind
->dyn_relocs
!= NULL
)
1154 if (edir
->dyn_relocs
!= NULL
)
1156 struct elf_dyn_relocs
**pp
;
1157 struct elf_dyn_relocs
*p
;
1159 /* Add reloc counts against the indirect sym to the direct sym
1160 list. Merge any entries against the same section. */
1161 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1163 struct elf_dyn_relocs
*q
;
1165 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1166 if (q
->sec
== p
->sec
)
1168 q
->pc_count
+= p
->pc_count
;
1169 q
->count
+= p
->count
;
1176 *pp
= edir
->dyn_relocs
;
1179 edir
->dyn_relocs
= eind
->dyn_relocs
;
1180 eind
->dyn_relocs
= NULL
;
1183 if (ind
->root
.type
== bfd_link_hash_indirect
1184 && dir
->got
.refcount
<= 0)
1186 edir
->tls_type
= eind
->tls_type
;
1187 eind
->tls_type
= GOT_UNKNOWN
;
1190 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1191 generate a R_386_COPY reloc. */
1192 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1194 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1195 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1197 if (ELIMINATE_COPY_RELOCS
1198 && ind
->root
.type
!= bfd_link_hash_indirect
1199 && dir
->dynamic_adjusted
)
1201 /* If called to transfer flags for a weakdef during processing
1202 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1203 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1204 if (dir
->versioned
!= versioned_hidden
)
1205 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1206 dir
->ref_regular
|= ind
->ref_regular
;
1207 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1208 dir
->needs_plt
|= ind
->needs_plt
;
1209 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1213 if (eind
->func_pointer_refcount
> 0)
1215 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1216 eind
->func_pointer_refcount
= 0;
1219 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1223 /* Return TRUE if the TLS access code sequence support transition
1227 elf_i386_check_tls_transition (asection
*sec
,
1229 Elf_Internal_Shdr
*symtab_hdr
,
1230 struct elf_link_hash_entry
**sym_hashes
,
1231 unsigned int r_type
,
1232 const Elf_Internal_Rela
*rel
,
1233 const Elf_Internal_Rela
*relend
)
1235 unsigned int val
, type
, reg
;
1236 unsigned long r_symndx
;
1237 struct elf_link_hash_entry
*h
;
1240 bfd_boolean indirect_call
, tls_get_addr
;
1242 offset
= rel
->r_offset
;
1247 if (offset
< 2 || (rel
+ 1) >= relend
)
1250 indirect_call
= FALSE
;
1251 call
= contents
+ offset
+ 4;
1254 if (r_type
== R_386_TLS_GD
)
1256 /* Check transition from GD access model. Only
1257 leal foo@tlsgd(,%ebx,1), %eax
1258 call ___tls_get_addr@PLT
1260 leal foo@tlsgd(%ebx) %eax
1261 call ___tls_get_addr@PLT
1264 leal foo@tlsgd(%reg), %eax
1265 call *___tls_get_addr@GOT(%reg)
1266 which may be converted to
1267 addr32 call ___tls_get_addr
1268 can transit to different access model. */
1269 if ((offset
+ 10) > sec
->size
1270 || (type
!= 0x8d && type
!= 0x04))
1275 /* leal foo@tlsgd(,%ebx,1), %eax
1276 call ___tls_get_addr@PLT */
1280 if (*(call
- 7) != 0x8d
1288 leal foo@tlsgd(%ebx), %eax
1289 call ___tls_get_addr@PLT
1292 leal foo@tlsgd(%reg), %eax
1293 call *___tls_get_addr@GOT(%reg)
1294 which may be converted to
1295 addr32 call ___tls_get_addr
1297 %eax can't be used as the GOT base register since it
1298 is used to pass parameter to ___tls_get_addr. */
1300 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1303 indirect_call
= call
[0] == 0xff;
1304 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
1305 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1307 && (call
[1] & 0xf8) == 0x90
1308 && (call
[1] & 0x7) == reg
))
1314 /* Check transition from LD access model. Only
1315 leal foo@tlsldm(%ebx), %eax
1316 call ___tls_get_addr@PLT
1318 leal foo@tlsldm(%reg), %eax
1319 call *___tls_get_addr@GOT(%reg)
1320 which may be converted to
1321 addr32 call ___tls_get_addr
1322 can transit to different access model. */
1323 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1326 /* %eax can't be used as the GOT base register since it is
1327 used to pass parameter to ___tls_get_addr. */
1329 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1332 indirect_call
= call
[0] == 0xff;
1333 if (!(reg
== 3 && call
[0] == 0xe8)
1334 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1336 && (call
[1] & 0xf8) == 0x90
1337 && (call
[1] & 0x7) == reg
))
1341 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1342 if (r_symndx
< symtab_hdr
->sh_info
)
1345 tls_get_addr
= FALSE
;
1346 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1347 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1349 struct elf_i386_link_hash_entry
*eh
1350 = (struct elf_i386_link_hash_entry
*) h
;
1351 tls_get_addr
= eh
->tls_get_addr
== 1;
1352 if (eh
->tls_get_addr
> 1)
1354 /* Use strncmp to check ___tls_get_addr since
1355 ___tls_get_addr may be versioned. */
1356 if (strncmp (h
->root
.root
.string
, "___tls_get_addr", 15)
1359 eh
->tls_get_addr
= 1;
1360 tls_get_addr
= TRUE
;
1363 eh
->tls_get_addr
= 0;
1369 else if (indirect_call
)
1370 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
1372 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1373 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
1376 /* Check transition from IE access model:
1377 movl foo@indntpoff(%rip), %eax
1378 movl foo@indntpoff(%rip), %reg
1379 addl foo@indntpoff(%rip), %reg
1382 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1385 /* Check "movl foo@tpoff(%rip), %eax" first. */
1386 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1393 /* Check movl|addl foo@tpoff(%rip), %reg. */
1394 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1395 return ((type
== 0x8b || type
== 0x03)
1396 && (val
& 0xc7) == 0x05);
1398 case R_386_TLS_GOTIE
:
1399 case R_386_TLS_IE_32
:
1400 /* Check transition from {IE_32,GOTIE} access model:
1401 subl foo@{tpoff,gontoff}(%reg1), %reg2
1402 movl foo@{tpoff,gontoff}(%reg1), %reg2
1403 addl foo@{tpoff,gontoff}(%reg1), %reg2
1406 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1409 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1410 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1413 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1414 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1416 case R_386_TLS_GOTDESC
:
1417 /* Check transition from GDesc access model:
1418 leal x@tlsdesc(%ebx), %eax
1420 Make sure it's a leal adding ebx to a 32-bit offset
1421 into any register, although it's probably almost always
1424 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1427 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1430 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1431 return (val
& 0xc7) == 0x83;
1433 case R_386_TLS_DESC_CALL
:
1434 /* Check transition from GDesc access model:
1435 call *x@tlsdesc(%eax)
1437 if (offset
+ 2 <= sec
->size
)
1439 /* Make sure that it's a call *x@tlsdesc(%eax). */
1440 call
= contents
+ offset
;
1441 return call
[0] == 0xff && call
[1] == 0x10;
1451 /* Return TRUE if the TLS access transition is OK or no transition
1452 will be performed. Update R_TYPE if there is a transition. */
1455 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1456 asection
*sec
, bfd_byte
*contents
,
1457 Elf_Internal_Shdr
*symtab_hdr
,
1458 struct elf_link_hash_entry
**sym_hashes
,
1459 unsigned int *r_type
, int tls_type
,
1460 const Elf_Internal_Rela
*rel
,
1461 const Elf_Internal_Rela
*relend
,
1462 struct elf_link_hash_entry
*h
,
1463 unsigned long r_symndx
,
1464 bfd_boolean from_relocate_section
)
1466 unsigned int from_type
= *r_type
;
1467 unsigned int to_type
= from_type
;
1468 bfd_boolean check
= TRUE
;
1470 /* Skip TLS transition for functions. */
1472 && (h
->type
== STT_FUNC
1473 || h
->type
== STT_GNU_IFUNC
))
1479 case R_386_TLS_GOTDESC
:
1480 case R_386_TLS_DESC_CALL
:
1481 case R_386_TLS_IE_32
:
1483 case R_386_TLS_GOTIE
:
1484 if (bfd_link_executable (info
))
1487 to_type
= R_386_TLS_LE_32
;
1488 else if (from_type
!= R_386_TLS_IE
1489 && from_type
!= R_386_TLS_GOTIE
)
1490 to_type
= R_386_TLS_IE_32
;
1493 /* When we are called from elf_i386_relocate_section, there may
1494 be additional transitions based on TLS_TYPE. */
1495 if (from_relocate_section
)
1497 unsigned int new_to_type
= to_type
;
1499 if (bfd_link_executable (info
)
1502 && (tls_type
& GOT_TLS_IE
))
1503 new_to_type
= R_386_TLS_LE_32
;
1505 if (to_type
== R_386_TLS_GD
1506 || to_type
== R_386_TLS_GOTDESC
1507 || to_type
== R_386_TLS_DESC_CALL
)
1509 if (tls_type
== GOT_TLS_IE_POS
)
1510 new_to_type
= R_386_TLS_GOTIE
;
1511 else if (tls_type
& GOT_TLS_IE
)
1512 new_to_type
= R_386_TLS_IE_32
;
1515 /* We checked the transition before when we were called from
1516 elf_i386_check_relocs. We only want to check the new
1517 transition which hasn't been checked before. */
1518 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1519 to_type
= new_to_type
;
1525 if (bfd_link_executable (info
))
1526 to_type
= R_386_TLS_LE_32
;
1533 /* Return TRUE if there is no transition. */
1534 if (from_type
== to_type
)
1537 /* Check if the transition can be performed. */
1539 && ! elf_i386_check_tls_transition (sec
, contents
,
1540 symtab_hdr
, sym_hashes
,
1541 from_type
, rel
, relend
))
1543 reloc_howto_type
*from
, *to
;
1546 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1547 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1550 name
= h
->root
.root
.string
;
1553 struct elf_i386_link_hash_table
*htab
;
1555 htab
= elf_i386_hash_table (info
);
1560 Elf_Internal_Sym
*isym
;
1562 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1564 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1569 /* xgettext:c-format */
1570 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1571 "in section `%A' failed"),
1572 abfd
, sec
, from
->name
, to
->name
, name
,
1573 (unsigned long) rel
->r_offset
);
1574 bfd_set_error (bfd_error_bad_value
);
1582 /* With the local symbol, foo, we convert
1583 mov foo@GOT[(%reg1)], %reg2
1585 lea foo[@GOTOFF(%reg1)], %reg2
1587 call/jmp *foo@GOT[(%reg)]
1589 nop call foo/jmp foo nop
1590 When PIC is false, convert
1591 test %reg1, foo@GOT[(%reg2)]
1595 binop foo@GOT[(%reg1)], %reg2
1598 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1603 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1605 Elf_Internal_Rela
*irel
,
1606 struct elf_link_hash_entry
*h
,
1607 bfd_boolean
*converted
,
1608 struct bfd_link_info
*link_info
)
1610 struct elf_i386_link_hash_table
*htab
;
1611 unsigned int opcode
;
1613 bfd_boolean baseless
;
1614 Elf_Internal_Sym
*isym
;
1615 unsigned int addend
;
1619 bfd_boolean to_reloc_32
;
1620 unsigned int r_type
;
1621 unsigned int r_symndx
;
1622 bfd_vma roff
= irel
->r_offset
;
1627 /* Addend for R_386_GOT32X relocations must be 0. */
1628 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1632 htab
= elf_i386_hash_table (link_info
);
1633 is_pic
= bfd_link_pic (link_info
);
1635 r_type
= ELF32_R_TYPE (irel
->r_info
);
1636 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1638 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1639 baseless
= (modrm
& 0xc7) == 0x5;
1641 if (baseless
&& is_pic
)
1643 /* For PIC, disallow R_386_GOT32X without a base register
1644 since we don't know what the GOT base is. */
1649 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1651 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1654 name
= h
->root
.root
.string
;
1657 /* xgettext:c-format */
1658 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base register can not be used when making a shared object"),
1663 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1665 /* Convert to R_386_32 if PIC is false or there is no base
1667 to_reloc_32
= !is_pic
|| baseless
;
1669 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1673 if (opcode
== 0x0ff)
1674 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1675 goto convert_branch
;
1677 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1678 "test %reg1, foo@GOT(%reg2)" and
1679 "binop foo@GOT[(%reg1)], %reg2". */
1683 /* Undefined weak symbol is only bound locally in executable
1684 and its reference is resolved as 0. */
1685 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
, TRUE
,
1686 elf_i386_hash_entry (h
)))
1690 /* No direct branch to 0 for PIC. */
1694 goto convert_branch
;
1698 /* We can convert load of address 0 to R_386_32. */
1706 /* We have "call/jmp *foo@GOT[(%reg)]". */
1707 if ((h
->root
.type
== bfd_link_hash_defined
1708 || h
->root
.type
== bfd_link_hash_defweak
)
1709 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1711 /* The function is locally defined. */
1713 /* Convert R_386_GOT32X to R_386_PC32. */
1714 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1716 struct elf_i386_link_hash_entry
*eh
1717 = (struct elf_i386_link_hash_entry
*) h
;
1719 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1722 /* To support TLS optimization, always use addr32 prefix
1723 for "call *___tls_get_addr@GOT(%reg)". */
1724 if (eh
&& eh
->tls_get_addr
== 1)
1727 nop_offset
= irel
->r_offset
- 2;
1731 nop
= link_info
->call_nop_byte
;
1732 if (link_info
->call_nop_as_suffix
)
1734 nop_offset
= roff
+ 3;
1735 irel
->r_offset
-= 1;
1738 nop_offset
= roff
- 2;
1743 /* Convert to "jmp foo nop". */
1746 nop_offset
= roff
+ 3;
1747 irel
->r_offset
-= 1;
1750 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1751 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1752 /* When converting to PC-relative relocation, we
1753 need to adjust addend by -4. */
1754 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1755 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1762 /* We have "mov foo@GOT[(%re1g)], %reg2",
1763 "test %reg1, foo@GOT(%reg2)" and
1764 "binop foo@GOT[(%reg1)], %reg2".
1766 Avoid optimizing _DYNAMIC since ld.so may use its
1767 link-time address. */
1768 if (h
== htab
->elf
.hdynamic
)
1771 /* def_regular is set by an assignment in a linker script in
1772 bfd_elf_record_link_assignment. */
1774 || h
->root
.type
== bfd_link_hash_defined
1775 || h
->root
.type
== bfd_link_hash_defweak
)
1776 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1783 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1784 "mov $foo, %reg2" with R_386_32. */
1786 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1787 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1792 /* Convert "mov foo@GOT(%reg1), %reg2" to
1793 "lea foo@GOTOFF(%reg1), %reg2". */
1794 r_type
= R_386_GOTOFF
;
1800 /* Only R_386_32 is supported. */
1806 /* Convert "test %reg1, foo@GOT(%reg2)" to
1807 "test $foo, %reg1". */
1808 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1813 /* Convert "binop foo@GOT(%reg1), %reg2" to
1814 "binop $foo, %reg2". */
1816 | (modrm
& 0x38) >> 3
1820 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1824 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1825 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1834 /* Rename some of the generic section flags to better document how they
1836 #define need_convert_load sec_flg0
1837 #define check_relocs_failed sec_flg1
1839 /* Look through the relocs for a section during the first phase, and
1840 calculate needed space in the global offset table, procedure linkage
1841 table, and dynamic reloc sections. */
1844 elf_i386_check_relocs (bfd
*abfd
,
1845 struct bfd_link_info
*info
,
1847 const Elf_Internal_Rela
*relocs
)
1849 struct elf_i386_link_hash_table
*htab
;
1850 Elf_Internal_Shdr
*symtab_hdr
;
1851 struct elf_link_hash_entry
**sym_hashes
;
1852 const Elf_Internal_Rela
*rel
;
1853 const Elf_Internal_Rela
*rel_end
;
1856 bfd_boolean use_plt_got
;
1858 if (bfd_link_relocatable (info
))
1861 /* Don't do anything special with non-loaded, non-alloced sections.
1862 In particular, any relocs in such sections should not affect GOT
1863 and PLT reference counting (ie. we don't allow them to create GOT
1864 or PLT entries), there's no possibility or desire to optimize TLS
1865 relocs, and there's not much point in propagating relocs to shared
1866 libs that the dynamic linker won't relocate. */
1867 if ((sec
->flags
& SEC_ALLOC
) == 0)
1870 BFD_ASSERT (is_i386_elf (abfd
));
1872 htab
= elf_i386_hash_table (info
);
1875 sec
->check_relocs_failed
= 1;
1879 /* Get the section contents. */
1880 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1881 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1882 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1884 sec
->check_relocs_failed
= 1;
1888 use_plt_got
= (!get_elf_i386_backend_data (abfd
)->is_vxworks
1889 && (get_elf_i386_backend_data (abfd
)
1890 == &elf_i386_arch_bed
));
1892 symtab_hdr
= &elf_symtab_hdr (abfd
);
1893 sym_hashes
= elf_sym_hashes (abfd
);
1897 rel_end
= relocs
+ sec
->reloc_count
;
1898 for (rel
= relocs
; rel
< rel_end
; rel
++)
1900 unsigned int r_type
;
1901 unsigned long r_symndx
;
1902 struct elf_link_hash_entry
*h
;
1903 struct elf_i386_link_hash_entry
*eh
;
1904 Elf_Internal_Sym
*isym
;
1906 bfd_boolean size_reloc
;
1908 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1909 r_type
= ELF32_R_TYPE (rel
->r_info
);
1911 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1913 /* xgettext:c-format */
1914 _bfd_error_handler (_("%B: bad symbol index: %d"),
1919 if (r_symndx
< symtab_hdr
->sh_info
)
1921 /* A local symbol. */
1922 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1927 /* Check relocation against local STT_GNU_IFUNC symbol. */
1928 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1930 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1934 /* Fake a STT_GNU_IFUNC symbol. */
1935 h
->type
= STT_GNU_IFUNC
;
1938 h
->forced_local
= 1;
1939 h
->root
.type
= bfd_link_hash_defined
;
1947 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1948 while (h
->root
.type
== bfd_link_hash_indirect
1949 || h
->root
.type
== bfd_link_hash_warning
)
1950 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1953 eh
= (struct elf_i386_link_hash_entry
*) h
;
1969 if (htab
->elf
.dynobj
== NULL
)
1970 htab
->elf
.dynobj
= abfd
;
1971 /* Create the ifunc sections for static executables. */
1972 if (h
->type
== STT_GNU_IFUNC
1973 && !_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
,
1979 /* It is referenced by a non-shared object. */
1981 h
->root
.non_ir_ref
= 1;
1983 if (h
->type
== STT_GNU_IFUNC
)
1984 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1985 |= elf_gnu_symbol_ifunc
;
1988 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1989 symtab_hdr
, sym_hashes
,
1990 &r_type
, GOT_UNKNOWN
,
1991 rel
, rel_end
, h
, r_symndx
, FALSE
))
1997 htab
->tls_ldm_got
.refcount
+= 1;
2001 /* This symbol requires a procedure linkage table entry. We
2002 actually build the entry in adjust_dynamic_symbol,
2003 because this might be a case of linking PIC code which is
2004 never referenced by a dynamic object, in which case we
2005 don't need to generate a procedure linkage table entry
2008 /* If this is a local symbol, we resolve it directly without
2009 creating a procedure linkage table entry. */
2013 eh
->has_got_reloc
= 1;
2015 h
->plt
.refcount
+= 1;
2022 case R_386_TLS_IE_32
:
2024 case R_386_TLS_GOTIE
:
2025 if (!bfd_link_executable (info
))
2026 info
->flags
|= DF_STATIC_TLS
;
2032 case R_386_TLS_GOTDESC
:
2033 case R_386_TLS_DESC_CALL
:
2034 /* This symbol requires a global offset table entry. */
2036 int tls_type
, old_tls_type
;
2043 tls_type
= GOT_NORMAL
;
2045 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
2046 case R_386_TLS_GOTDESC
:
2047 case R_386_TLS_DESC_CALL
:
2048 tls_type
= GOT_TLS_GDESC
; break;
2049 case R_386_TLS_IE_32
:
2050 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
2051 tls_type
= GOT_TLS_IE_NEG
;
2053 /* If this is a GD->IE transition, we may use either of
2054 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
2055 tls_type
= GOT_TLS_IE
;
2058 case R_386_TLS_GOTIE
:
2059 tls_type
= GOT_TLS_IE_POS
; break;
2064 h
->got
.refcount
+= 1;
2065 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2069 bfd_signed_vma
*local_got_refcounts
;
2071 /* This is a global offset table entry for a local symbol. */
2072 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2073 if (local_got_refcounts
== NULL
)
2077 size
= symtab_hdr
->sh_info
;
2078 size
*= (sizeof (bfd_signed_vma
)
2079 + sizeof (bfd_vma
) + sizeof(char));
2080 local_got_refcounts
= (bfd_signed_vma
*)
2081 bfd_zalloc (abfd
, size
);
2082 if (local_got_refcounts
== NULL
)
2084 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2085 elf_i386_local_tlsdesc_gotent (abfd
)
2086 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2087 elf_i386_local_got_tls_type (abfd
)
2088 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2090 local_got_refcounts
[r_symndx
] += 1;
2091 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
2094 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
2095 tls_type
|= old_tls_type
;
2096 /* If a TLS symbol is accessed using IE at least once,
2097 there is no point to use dynamic model for it. */
2098 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2099 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2100 || (tls_type
& GOT_TLS_IE
) == 0))
2102 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
2103 tls_type
= old_tls_type
;
2104 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2105 && GOT_TLS_GD_ANY_P (tls_type
))
2106 tls_type
|= old_tls_type
;
2110 name
= h
->root
.root
.string
;
2112 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2115 /* xgettext:c-format */
2116 (_("%B: `%s' accessed both as normal and "
2117 "thread local symbol"),
2119 bfd_set_error (bfd_error_bad_value
);
2124 if (old_tls_type
!= tls_type
)
2127 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
2129 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2137 if (htab
->elf
.sgot
== NULL
)
2139 if (htab
->elf
.dynobj
== NULL
)
2140 htab
->elf
.dynobj
= abfd
;
2141 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2144 if (r_type
!= R_386_TLS_IE
)
2147 eh
->has_got_reloc
= 1;
2152 case R_386_TLS_LE_32
:
2155 eh
->has_got_reloc
= 1;
2156 if (bfd_link_executable (info
))
2158 info
->flags
|= DF_STATIC_TLS
;
2163 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2164 eh
->has_non_got_reloc
= 1;
2166 /* We are called after all symbols have been resolved. Only
2167 relocation against STT_GNU_IFUNC symbol must go through
2170 && (bfd_link_executable (info
)
2171 || h
->type
== STT_GNU_IFUNC
))
2173 /* If this reloc is in a read-only section, we might
2174 need a copy reloc. We can't check reliably at this
2175 stage whether the section is read-only, as input
2176 sections have not yet been mapped to output sections.
2177 Tentatively set the flag for now, and correct in
2178 adjust_dynamic_symbol. */
2181 /* We may need a .plt entry if the symbol is a function
2182 defined in a shared lib or is a STT_GNU_IFUNC function
2183 referenced from the code or read-only section. */
2185 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2186 h
->plt
.refcount
+= 1;
2188 if (r_type
== R_386_PC32
)
2190 /* Since something like ".long foo - ." may be used
2191 as pointer, make sure that PLT is used if foo is
2192 a function defined in a shared library. */
2193 if ((sec
->flags
& SEC_CODE
) == 0)
2194 h
->pointer_equality_needed
= 1;
2195 else if (h
->type
== STT_GNU_IFUNC
2196 && bfd_link_pic (info
))
2199 name
= h
->root
.root
.string
;
2201 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2204 /* xgettext:c-format */
2205 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
2207 bfd_set_error (bfd_error_bad_value
);
2213 h
->pointer_equality_needed
= 1;
2214 /* R_386_32 can be resolved at run-time. */
2215 if (r_type
== R_386_32
2216 && (sec
->flags
& SEC_READONLY
) == 0)
2217 eh
->func_pointer_refcount
+= 1;
2223 /* If we are creating a shared library, and this is a reloc
2224 against a global symbol, or a non PC relative reloc
2225 against a local symbol, then we need to copy the reloc
2226 into the shared library. However, if we are linking with
2227 -Bsymbolic, we do not need to copy a reloc against a
2228 global symbol which is defined in an object we are
2229 including in the link (i.e., DEF_REGULAR is set). At
2230 this point we have not seen all the input files, so it is
2231 possible that DEF_REGULAR is not set now but will be set
2232 later (it is never cleared). In case of a weak definition,
2233 DEF_REGULAR may be cleared later by a strong definition in
2234 a shared library. We account for that possibility below by
2235 storing information in the relocs_copied field of the hash
2236 table entry. A similar situation occurs when creating
2237 shared libraries and symbol visibility changes render the
2240 If on the other hand, we are creating an executable, we
2241 may need to keep relocations for symbols satisfied by a
2242 dynamic library if we manage to avoid copy relocs for the
2245 Generate dynamic pointer relocation against STT_GNU_IFUNC
2246 symbol in the non-code section. */
2247 if ((bfd_link_pic (info
)
2248 && (r_type
!= R_386_PC32
2250 && (! (bfd_link_pie (info
)
2251 || SYMBOLIC_BIND (info
, h
))
2252 || h
->root
.type
== bfd_link_hash_defweak
2253 || !h
->def_regular
))))
2255 && h
->type
== STT_GNU_IFUNC
2256 && r_type
== R_386_32
2257 && (sec
->flags
& SEC_CODE
) == 0)
2258 || (ELIMINATE_COPY_RELOCS
2259 && !bfd_link_pic (info
)
2261 && (h
->root
.type
== bfd_link_hash_defweak
2262 || !h
->def_regular
)))
2264 struct elf_dyn_relocs
*p
;
2265 struct elf_dyn_relocs
**head
;
2267 /* We must copy these reloc types into the output file.
2268 Create a reloc section in dynobj and make room for
2272 if (htab
->elf
.dynobj
== NULL
)
2273 htab
->elf
.dynobj
= abfd
;
2275 sreloc
= _bfd_elf_make_dynamic_reloc_section
2276 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
2282 /* If this is a global symbol, we count the number of
2283 relocations we need for this symbol. */
2286 head
= &eh
->dyn_relocs
;
2290 /* Track dynamic relocs needed for local syms too.
2291 We really need local syms available to do this
2296 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2301 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2305 vpp
= &elf_section_data (s
)->local_dynrel
;
2306 head
= (struct elf_dyn_relocs
**)vpp
;
2310 if (p
== NULL
|| p
->sec
!= sec
)
2312 bfd_size_type amt
= sizeof *p
;
2313 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
2325 /* Count size relocation as PC-relative relocation. */
2326 if (r_type
== R_386_PC32
|| size_reloc
)
2331 /* This relocation describes the C++ object vtable hierarchy.
2332 Reconstruct it for later use during GC. */
2333 case R_386_GNU_VTINHERIT
:
2334 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2338 /* This relocation describes which C++ vtable entries are actually
2339 used. Record for later use during GC. */
2340 case R_386_GNU_VTENTRY
:
2341 BFD_ASSERT (h
!= NULL
);
2343 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
2353 && h
->plt
.refcount
> 0
2354 && (((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2355 || h
->got
.refcount
> 0)
2356 && htab
->plt_got
== NULL
)
2358 /* Create the GOT procedure linkage table. */
2359 unsigned int plt_got_align
;
2360 const struct elf_backend_data
*bed
;
2362 bed
= get_elf_backend_data (info
->output_bfd
);
2363 BFD_ASSERT (sizeof (elf_i386_got_plt_entry
) == 8
2364 && (sizeof (elf_i386_got_plt_entry
)
2365 == sizeof (elf_i386_pic_got_plt_entry
)));
2368 if (htab
->elf
.dynobj
== NULL
)
2369 htab
->elf
.dynobj
= abfd
;
2371 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2373 (bed
->dynamic_sec_flags
2378 if (htab
->plt_got
== NULL
2379 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2384 if (!info
->no_ld_generated_unwind_info
2385 && htab
->plt_got_eh_frame
== NULL
2386 && get_elf_i386_backend_data (abfd
)->plt
->eh_frame_plt_got
!= NULL
)
2388 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2389 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2390 | SEC_LINKER_CREATED
);
2391 htab
->plt_got_eh_frame
2392 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2395 if (htab
->plt_got_eh_frame
== NULL
2396 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2397 htab
->plt_got_eh_frame
,
2403 if (r_type
== R_386_GOT32X
2404 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2405 sec
->need_convert_load
= 1;
2408 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2410 if (!info
->keep_memory
)
2414 /* Cache the section contents for elf_link_input_bfd. */
2415 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2422 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2424 sec
->check_relocs_failed
= 1;
2428 /* Return the section that should be marked against GC for a given
2432 elf_i386_gc_mark_hook (asection
*sec
,
2433 struct bfd_link_info
*info
,
2434 Elf_Internal_Rela
*rel
,
2435 struct elf_link_hash_entry
*h
,
2436 Elf_Internal_Sym
*sym
)
2439 switch (ELF32_R_TYPE (rel
->r_info
))
2441 case R_386_GNU_VTINHERIT
:
2442 case R_386_GNU_VTENTRY
:
2446 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2449 /* Remove undefined weak symbol from the dynamic symbol table if it
2450 is resolved to 0. */
2453 elf_i386_fixup_symbol (struct bfd_link_info
*info
,
2454 struct elf_link_hash_entry
*h
)
2456 if (h
->dynindx
!= -1
2457 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2458 elf_i386_hash_entry (h
)->has_got_reloc
,
2459 elf_i386_hash_entry (h
)))
2462 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2468 /* Adjust a symbol defined by a dynamic object and referenced by a
2469 regular object. The current definition is in some section of the
2470 dynamic object, but we're not including those sections. We have to
2471 change the definition to something the rest of the link can
2475 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2476 struct elf_link_hash_entry
*h
)
2478 struct elf_i386_link_hash_table
*htab
;
2480 struct elf_i386_link_hash_entry
*eh
;
2481 struct elf_dyn_relocs
*p
;
2483 /* STT_GNU_IFUNC symbol must go through PLT. */
2484 if (h
->type
== STT_GNU_IFUNC
)
2486 /* All local STT_GNU_IFUNC references must be treate as local
2487 calls via local PLT. */
2489 && SYMBOL_CALLS_LOCAL (info
, h
))
2491 bfd_size_type pc_count
= 0, count
= 0;
2492 struct elf_dyn_relocs
**pp
;
2494 eh
= (struct elf_i386_link_hash_entry
*) h
;
2495 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2497 pc_count
+= p
->pc_count
;
2498 p
->count
-= p
->pc_count
;
2507 if (pc_count
|| count
)
2512 /* Increment PLT reference count only for PC-relative
2515 if (h
->plt
.refcount
<= 0)
2516 h
->plt
.refcount
= 1;
2518 h
->plt
.refcount
+= 1;
2523 if (h
->plt
.refcount
<= 0)
2525 h
->plt
.offset
= (bfd_vma
) -1;
2531 /* If this is a function, put it in the procedure linkage table. We
2532 will fill in the contents of the procedure linkage table later,
2533 when we know the address of the .got section. */
2534 if (h
->type
== STT_FUNC
2537 if (h
->plt
.refcount
<= 0
2538 || SYMBOL_CALLS_LOCAL (info
, h
)
2539 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2540 && h
->root
.type
== bfd_link_hash_undefweak
))
2542 /* This case can occur if we saw a PLT32 reloc in an input
2543 file, but the symbol was never referred to by a dynamic
2544 object, or if all references were garbage collected. In
2545 such a case, we don't actually need to build a procedure
2546 linkage table, and we can just do a PC32 reloc instead. */
2547 h
->plt
.offset
= (bfd_vma
) -1;
2554 /* It's possible that we incorrectly decided a .plt reloc was
2555 needed for an R_386_PC32 reloc to a non-function sym in
2556 check_relocs. We can't decide accurately between function and
2557 non-function syms in check-relocs; Objects loaded later in
2558 the link may change h->type. So fix it now. */
2559 h
->plt
.offset
= (bfd_vma
) -1;
2561 /* If this is a weak symbol, and there is a real definition, the
2562 processor independent code will have arranged for us to see the
2563 real definition first, and we can just use the same value. */
2564 if (h
->u
.weakdef
!= NULL
)
2566 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2567 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2568 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2569 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2570 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2571 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2575 /* This is a reference to a symbol defined by a dynamic object which
2576 is not a function. */
2578 /* If we are creating a shared library, we must presume that the
2579 only references to the symbol are via the global offset table.
2580 For such cases we need not do anything here; the relocations will
2581 be handled correctly by relocate_section. */
2582 if (!bfd_link_executable (info
))
2585 /* If there are no references to this symbol that do not use the
2586 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2588 eh
= (struct elf_i386_link_hash_entry
*) h
;
2589 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2592 /* If -z nocopyreloc was given, we won't generate them either. */
2593 if (info
->nocopyreloc
)
2599 htab
= elf_i386_hash_table (info
);
2603 /* If there aren't any dynamic relocs in read-only sections nor
2604 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2605 avoid the copy reloc. This doesn't work on VxWorks, where we can
2606 not have dynamic relocations (other than copy and jump slot
2607 relocations) in an executable. */
2608 if (ELIMINATE_COPY_RELOCS
2610 && !get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2612 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2614 s
= p
->sec
->output_section
;
2615 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2626 /* We must allocate the symbol in our .dynbss section, which will
2627 become part of the .bss section of the executable. There will be
2628 an entry for this symbol in the .dynsym section. The dynamic
2629 object will contain position independent code, so all references
2630 from the dynamic object to this symbol will go through the global
2631 offset table. The dynamic linker will use the .dynsym entry to
2632 determine the address it must put in the global offset table, so
2633 both the dynamic object and the regular object will refer to the
2634 same memory location for the variable. */
2636 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2637 copy the initial value out of the dynamic object and into the
2638 runtime process image. */
2639 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2641 s
= htab
->elf
.sdynrelro
;
2642 srel
= htab
->elf
.sreldynrelro
;
2646 s
= htab
->elf
.sdynbss
;
2647 srel
= htab
->elf
.srelbss
;
2649 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2651 srel
->size
+= sizeof (Elf32_External_Rel
);
2655 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2658 /* Allocate space in .plt, .got and associated reloc sections for
2662 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2664 struct bfd_link_info
*info
;
2665 struct elf_i386_link_hash_table
*htab
;
2666 struct elf_i386_link_hash_entry
*eh
;
2667 struct elf_dyn_relocs
*p
;
2668 unsigned plt_entry_size
;
2669 bfd_boolean resolved_to_zero
;
2671 if (h
->root
.type
== bfd_link_hash_indirect
)
2674 eh
= (struct elf_i386_link_hash_entry
*) h
;
2676 info
= (struct bfd_link_info
*) inf
;
2677 htab
= elf_i386_hash_table (info
);
2681 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2683 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2687 /* Clear the reference count of function pointer relocations if
2688 symbol isn't a normal function. */
2689 if (h
->type
!= STT_FUNC
)
2690 eh
->func_pointer_refcount
= 0;
2692 /* We can't use the GOT PLT if pointer equality is needed since
2693 finish_dynamic_symbol won't clear symbol value and the dynamic
2694 linker won't update the GOT slot. We will get into an infinite
2695 loop at run-time. */
2696 if (htab
->plt_got
!= NULL
2697 && h
->type
!= STT_GNU_IFUNC
2698 && !h
->pointer_equality_needed
2699 && h
->plt
.refcount
> 0
2700 && h
->got
.refcount
> 0)
2702 /* Don't use the regular PLT if there are both GOT and GOTPLT
2704 h
->plt
.offset
= (bfd_vma
) -1;
2706 /* Use the GOT PLT. */
2707 eh
->plt_got
.refcount
= 1;
2710 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2711 here if it is defined and referenced in a non-shared object. */
2712 if (h
->type
== STT_GNU_IFUNC
2714 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2715 &htab
->readonly_dynrelocs_against_ifunc
,
2717 plt_entry_size
, 4, TRUE
);
2718 /* Don't create the PLT entry if there are only function pointer
2719 relocations which can be resolved at run-time. */
2720 else if (htab
->elf
.dynamic_sections_created
2721 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2722 || eh
->plt_got
.refcount
> 0))
2724 bfd_boolean use_plt_got
;
2726 /* Clear the reference count of function pointer relocations
2728 eh
->func_pointer_refcount
= 0;
2730 if ((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2732 /* Don't use the regular PLT for DF_BIND_NOW. */
2733 h
->plt
.offset
= (bfd_vma
) -1;
2735 /* Use the GOT PLT. */
2736 h
->got
.refcount
= 1;
2737 eh
->plt_got
.refcount
= 1;
2740 use_plt_got
= eh
->plt_got
.refcount
> 0;
2742 /* Make sure this symbol is output as a dynamic symbol.
2743 Undefined weak syms won't yet be marked as dynamic. */
2744 if (h
->dynindx
== -1
2746 && !resolved_to_zero
)
2748 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2752 if (bfd_link_pic (info
)
2753 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2755 asection
*s
= htab
->elf
.splt
;
2756 asection
*got_s
= htab
->plt_got
;
2758 /* If this is the first .plt entry, make room for the special
2759 first entry. The .plt section is used by prelink to undo
2760 prelinking for dynamic relocations. */
2762 s
->size
= plt_entry_size
;
2765 eh
->plt_got
.offset
= got_s
->size
;
2767 h
->plt
.offset
= s
->size
;
2769 /* If this symbol is not defined in a regular file, and we are
2770 not generating a shared library, then set the symbol to this
2771 location in the .plt. This is required to make function
2772 pointers compare as equal between the normal executable and
2773 the shared library. */
2774 if (! bfd_link_pic (info
)
2779 /* We need to make a call to the entry of the GOT PLT
2780 instead of regular PLT entry. */
2781 h
->root
.u
.def
.section
= got_s
;
2782 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2786 h
->root
.u
.def
.section
= s
;
2787 h
->root
.u
.def
.value
= h
->plt
.offset
;
2791 /* Make room for this entry. */
2793 got_s
->size
+= sizeof (elf_i386_got_plt_entry
);
2796 s
->size
+= plt_entry_size
;
2798 /* We also need to make an entry in the .got.plt section,
2799 which will be placed in the .got section by the linker
2801 htab
->elf
.sgotplt
->size
+= 4;
2803 /* There should be no PLT relocation against resolved
2804 undefined weak symbol in executable. */
2805 if (!resolved_to_zero
)
2807 /* We also need to make an entry in the .rel.plt
2809 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2810 htab
->elf
.srelplt
->reloc_count
++;
2814 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
2815 && !bfd_link_pic (info
))
2817 /* VxWorks has a second set of relocations for each PLT entry
2818 in executables. They go in a separate relocation section,
2819 which is processed by the kernel loader. */
2821 /* There are two relocations for the initial PLT entry: an
2822 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2823 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2825 if (h
->plt
.offset
== plt_entry_size
)
2826 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2828 /* There are two extra relocations for each subsequent PLT entry:
2829 an R_386_32 relocation for the GOT entry, and an R_386_32
2830 relocation for the PLT entry. */
2832 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2837 eh
->plt_got
.offset
= (bfd_vma
) -1;
2838 h
->plt
.offset
= (bfd_vma
) -1;
2844 eh
->plt_got
.offset
= (bfd_vma
) -1;
2845 h
->plt
.offset
= (bfd_vma
) -1;
2849 eh
->tlsdesc_got
= (bfd_vma
) -1;
2851 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2852 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2853 if (h
->got
.refcount
> 0
2854 && bfd_link_executable (info
)
2856 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2857 h
->got
.offset
= (bfd_vma
) -1;
2858 else if (h
->got
.refcount
> 0)
2862 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2864 /* Make sure this symbol is output as a dynamic symbol.
2865 Undefined weak syms won't yet be marked as dynamic. */
2866 if (h
->dynindx
== -1
2868 && !resolved_to_zero
)
2870 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2875 if (GOT_TLS_GDESC_P (tls_type
))
2877 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2878 - elf_i386_compute_jump_table_size (htab
);
2879 htab
->elf
.sgotplt
->size
+= 8;
2880 h
->got
.offset
= (bfd_vma
) -2;
2882 if (! GOT_TLS_GDESC_P (tls_type
)
2883 || GOT_TLS_GD_P (tls_type
))
2885 h
->got
.offset
= s
->size
;
2887 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2888 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2891 dyn
= htab
->elf
.dynamic_sections_created
;
2892 /* R_386_TLS_IE_32 needs one dynamic relocation,
2893 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2894 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2895 need two), R_386_TLS_GD needs one if local symbol and two if
2896 global. No dynamic relocation against resolved undefined weak
2897 symbol in executable. */
2898 if (tls_type
== GOT_TLS_IE_BOTH
)
2899 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2900 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2901 || (tls_type
& GOT_TLS_IE
))
2902 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2903 else if (GOT_TLS_GD_P (tls_type
))
2904 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2905 else if (! GOT_TLS_GDESC_P (tls_type
)
2906 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2907 && !resolved_to_zero
)
2908 || h
->root
.type
!= bfd_link_hash_undefweak
)
2909 && (bfd_link_pic (info
)
2910 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2911 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2912 if (GOT_TLS_GDESC_P (tls_type
))
2913 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2916 h
->got
.offset
= (bfd_vma
) -1;
2918 if (eh
->dyn_relocs
== NULL
)
2921 /* In the shared -Bsymbolic case, discard space allocated for
2922 dynamic pc-relative relocs against symbols which turn out to be
2923 defined in regular objects. For the normal shared case, discard
2924 space for pc-relative relocs that have become local due to symbol
2925 visibility changes. */
2927 if (bfd_link_pic (info
))
2929 /* The only reloc that uses pc_count is R_386_PC32, which will
2930 appear on a call or on something like ".long foo - .". We
2931 want calls to protected symbols to resolve directly to the
2932 function rather than going via the plt. If people want
2933 function pointer comparisons to work as expected then they
2934 should avoid writing assembly like ".long foo - .". */
2935 if (SYMBOL_CALLS_LOCAL (info
, h
))
2937 struct elf_dyn_relocs
**pp
;
2939 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2941 p
->count
-= p
->pc_count
;
2950 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2952 struct elf_dyn_relocs
**pp
;
2953 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2955 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2962 /* Also discard relocs on undefined weak syms with non-default
2963 visibility or in PIE. */
2964 if (eh
->dyn_relocs
!= NULL
2965 && h
->root
.type
== bfd_link_hash_undefweak
)
2967 /* Undefined weak symbol is never bound locally in shared
2969 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2970 || resolved_to_zero
)
2974 /* Keep dynamic non-GOT/non-PLT relocation so that we
2975 can branch to 0 without PLT. */
2976 struct elf_dyn_relocs
**pp
;
2978 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2979 if (p
->pc_count
== 0)
2983 /* Remove non-R_386_PC32 relocation. */
2984 p
->count
= p
->pc_count
;
2988 if (eh
->dyn_relocs
!= NULL
)
2990 /* Make sure undefined weak symbols are output
2991 as dynamic symbols in PIEs for dynamic non-GOT
2992 non-PLT reloations. */
2993 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2998 eh
->dyn_relocs
= NULL
;
3000 else if (h
->dynindx
== -1
3001 && !h
->forced_local
)
3003 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3008 else if (ELIMINATE_COPY_RELOCS
)
3010 /* For the non-shared case, discard space for relocs against
3011 symbols which turn out to need copy relocs or are not
3012 dynamic. Keep dynamic relocations for run-time function
3013 pointer initialization. */
3015 if ((!h
->non_got_ref
3016 || eh
->func_pointer_refcount
> 0
3017 || (h
->root
.type
== bfd_link_hash_undefweak
3018 && !resolved_to_zero
))
3021 || (htab
->elf
.dynamic_sections_created
3022 && (h
->root
.type
== bfd_link_hash_undefweak
3023 || h
->root
.type
== bfd_link_hash_undefined
))))
3025 /* Make sure this symbol is output as a dynamic symbol.
3026 Undefined weak syms won't yet be marked as dynamic. */
3027 if (h
->dynindx
== -1
3029 && !resolved_to_zero
)
3031 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3035 /* If that succeeded, we know we'll be keeping all the
3037 if (h
->dynindx
!= -1)
3041 eh
->dyn_relocs
= NULL
;
3042 eh
->func_pointer_refcount
= 0;
3047 /* Finally, allocate space. */
3048 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3052 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3054 BFD_ASSERT (sreloc
!= NULL
);
3055 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3061 /* Allocate space in .plt, .got and associated reloc sections for
3062 local dynamic relocs. */
3065 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
3067 struct elf_link_hash_entry
*h
3068 = (struct elf_link_hash_entry
*) *slot
;
3070 if (h
->type
!= STT_GNU_IFUNC
3074 || h
->root
.type
!= bfd_link_hash_defined
)
3077 return elf_i386_allocate_dynrelocs (h
, inf
);
3080 /* Find any dynamic relocs that apply to read-only sections. */
3083 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3085 struct elf_i386_link_hash_entry
*eh
;
3086 struct elf_dyn_relocs
*p
;
3088 /* Skip local IFUNC symbols. */
3089 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3092 eh
= (struct elf_i386_link_hash_entry
*) h
;
3093 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3095 asection
*s
= p
->sec
->output_section
;
3097 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3099 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3101 info
->flags
|= DF_TEXTREL
;
3103 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3104 || info
->error_textrel
)
3105 /* xgettext:c-format */
3106 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3107 p
->sec
->owner
, h
->root
.root
.string
,
3110 /* Not an error, just cut short the traversal. */
3117 /* Convert load via the GOT slot to load immediate. */
3120 elf_i386_convert_load (bfd
*abfd
, asection
*sec
,
3121 struct bfd_link_info
*link_info
)
3123 struct elf_i386_link_hash_table
*htab
;
3124 Elf_Internal_Shdr
*symtab_hdr
;
3125 Elf_Internal_Rela
*internal_relocs
;
3126 Elf_Internal_Rela
*irel
, *irelend
;
3128 bfd_boolean changed
;
3129 bfd_signed_vma
*local_got_refcounts
;
3131 /* Don't even try to convert non-ELF outputs. */
3132 if (!is_elf_hash_table (link_info
->hash
))
3135 /* Nothing to do if there is no need or no output. */
3136 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3137 || sec
->need_convert_load
== 0
3138 || bfd_is_abs_section (sec
->output_section
))
3141 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3143 /* Load the relocations for this section. */
3144 internal_relocs
= (_bfd_elf_link_read_relocs
3145 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3146 link_info
->keep_memory
));
3147 if (internal_relocs
== NULL
)
3151 htab
= elf_i386_hash_table (link_info
);
3152 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3154 /* Get the section contents. */
3155 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3156 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3159 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3163 irelend
= internal_relocs
+ sec
->reloc_count
;
3164 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3166 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3167 unsigned int r_symndx
;
3168 struct elf_link_hash_entry
*h
;
3169 bfd_boolean converted
;
3171 /* Don't convert R_386_GOT32 since we can't tell if it is applied
3172 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
3173 if (r_type
!= R_386_GOT32X
)
3176 r_symndx
= ELF32_R_SYM (irel
->r_info
);
3177 if (r_symndx
< symtab_hdr
->sh_info
)
3178 h
= elf_i386_get_local_sym_hash (htab
, sec
->owner
,
3179 (const Elf_Internal_Rela
*) irel
,
3183 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3184 while (h
->root
.type
== bfd_link_hash_indirect
3185 || h
->root
.type
== bfd_link_hash_warning
)
3186 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3189 /* STT_GNU_IFUNC must keep GOT32 relocations. */
3190 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3194 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
3195 irel
, h
, &converted
, link_info
))
3200 changed
= converted
;
3203 if (h
->got
.refcount
> 0)
3204 h
->got
.refcount
-= 1;
3208 if (local_got_refcounts
!= NULL
3209 && local_got_refcounts
[r_symndx
] > 0)
3210 local_got_refcounts
[r_symndx
] -= 1;
3215 if (contents
!= NULL
3216 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3218 if (!changed
&& !link_info
->keep_memory
)
3222 /* Cache the section contents for elf_link_input_bfd. */
3223 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3227 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3230 free (internal_relocs
);
3232 elf_section_data (sec
)->relocs
= internal_relocs
;
3238 if (contents
!= NULL
3239 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3241 if (internal_relocs
!= NULL
3242 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3243 free (internal_relocs
);
3247 /* Set the sizes of the dynamic sections. */
3250 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3252 struct elf_i386_link_hash_table
*htab
;
3258 htab
= elf_i386_hash_table (info
);
3261 dynobj
= htab
->elf
.dynobj
;
3265 /* Set up .got offsets for local syms, and space for local dynamic
3267 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3269 bfd_signed_vma
*local_got
;
3270 bfd_signed_vma
*end_local_got
;
3271 char *local_tls_type
;
3272 bfd_vma
*local_tlsdesc_gotent
;
3273 bfd_size_type locsymcount
;
3274 Elf_Internal_Shdr
*symtab_hdr
;
3277 if (! is_i386_elf (ibfd
))
3280 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3282 struct elf_dyn_relocs
*p
;
3284 if (!elf_i386_convert_load (ibfd
, s
, info
))
3287 for (p
= ((struct elf_dyn_relocs
*)
3288 elf_section_data (s
)->local_dynrel
);
3292 if (!bfd_is_abs_section (p
->sec
)
3293 && bfd_is_abs_section (p
->sec
->output_section
))
3295 /* Input section has been discarded, either because
3296 it is a copy of a linkonce section or due to
3297 linker script /DISCARD/, so we'll be discarding
3300 else if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3301 && strcmp (p
->sec
->output_section
->name
,
3304 /* Relocations in vxworks .tls_vars sections are
3305 handled specially by the loader. */
3307 else if (p
->count
!= 0)
3309 srel
= elf_section_data (p
->sec
)->sreloc
;
3310 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3311 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3312 && (info
->flags
& DF_TEXTREL
) == 0)
3314 info
->flags
|= DF_TEXTREL
;
3315 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3316 || info
->error_textrel
)
3317 /* xgettext:c-format */
3318 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3319 p
->sec
->owner
, p
->sec
);
3325 local_got
= elf_local_got_refcounts (ibfd
);
3329 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3330 locsymcount
= symtab_hdr
->sh_info
;
3331 end_local_got
= local_got
+ locsymcount
;
3332 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
3333 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
3335 srel
= htab
->elf
.srelgot
;
3336 for (; local_got
< end_local_got
;
3337 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3339 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3342 if (GOT_TLS_GDESC_P (*local_tls_type
))
3344 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3345 - elf_i386_compute_jump_table_size (htab
);
3346 htab
->elf
.sgotplt
->size
+= 8;
3347 *local_got
= (bfd_vma
) -2;
3349 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3350 || GOT_TLS_GD_P (*local_tls_type
))
3352 *local_got
= s
->size
;
3354 if (GOT_TLS_GD_P (*local_tls_type
)
3355 || *local_tls_type
== GOT_TLS_IE_BOTH
)
3358 if (bfd_link_pic (info
)
3359 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3360 || (*local_tls_type
& GOT_TLS_IE
))
3362 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
3363 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
3364 else if (GOT_TLS_GD_P (*local_tls_type
)
3365 || ! GOT_TLS_GDESC_P (*local_tls_type
))
3366 srel
->size
+= sizeof (Elf32_External_Rel
);
3367 if (GOT_TLS_GDESC_P (*local_tls_type
))
3368 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
3372 *local_got
= (bfd_vma
) -1;
3376 if (htab
->tls_ldm_got
.refcount
> 0)
3378 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
3380 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
3381 htab
->elf
.sgot
->size
+= 8;
3382 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
3385 htab
->tls_ldm_got
.offset
= -1;
3387 /* Allocate global sym .plt and .got entries, and space for global
3388 sym dynamic relocs. */
3389 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
3391 /* Allocate .plt and .got entries, and space for local symbols. */
3392 htab_traverse (htab
->loc_hash_table
,
3393 elf_i386_allocate_local_dynrelocs
,
3396 /* For every jump slot reserved in the sgotplt, reloc_count is
3397 incremented. However, when we reserve space for TLS descriptors,
3398 it's not incremented, so in order to compute the space reserved
3399 for them, it suffices to multiply the reloc count by the jump
3402 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3403 so that R_386_IRELATIVE entries come last. */
3404 if (htab
->elf
.srelplt
)
3406 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
3407 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
3408 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3410 else if (htab
->elf
.irelplt
)
3411 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3414 if (htab
->elf
.sgotplt
)
3416 /* Don't allocate .got.plt section if there are no GOT nor PLT
3417 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
3418 if ((htab
->elf
.hgot
== NULL
3419 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3420 && (htab
->elf
.sgotplt
->size
3421 == get_elf_backend_data (output_bfd
)->got_header_size
)
3422 && (htab
->elf
.splt
== NULL
3423 || htab
->elf
.splt
->size
== 0)
3424 && (htab
->elf
.sgot
== NULL
3425 || htab
->elf
.sgot
->size
== 0)
3426 && (htab
->elf
.iplt
== NULL
3427 || htab
->elf
.iplt
->size
== 0)
3428 && (htab
->elf
.igotplt
== NULL
3429 || htab
->elf
.igotplt
->size
== 0))
3430 htab
->elf
.sgotplt
->size
= 0;
3433 if (_bfd_elf_eh_frame_present (info
))
3435 if (htab
->plt_eh_frame
!= NULL
3436 && htab
->elf
.splt
!= NULL
3437 && htab
->elf
.splt
->size
!= 0
3438 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3439 htab
->plt_eh_frame
->size
3440 = get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt_size
;
3442 if (htab
->plt_got_eh_frame
!= NULL
3443 && htab
->plt_got
!= NULL
3444 && htab
->plt_got
->size
!= 0
3445 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3446 htab
->plt_got_eh_frame
->size
3447 = get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt_got_size
;
3450 /* We now have determined the sizes of the various dynamic sections.
3451 Allocate memory for them. */
3453 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3455 bfd_boolean strip_section
= TRUE
;
3457 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3460 if (s
== htab
->elf
.splt
3461 || s
== htab
->elf
.sgot
)
3463 /* Strip this section if we don't need it; see the
3465 /* We'd like to strip these sections if they aren't needed, but if
3466 we've exported dynamic symbols from them we must leave them.
3467 It's too late to tell BFD to get rid of the symbols. */
3469 if (htab
->elf
.hplt
!= NULL
)
3470 strip_section
= FALSE
;
3472 else if (s
== htab
->elf
.sgotplt
3473 || s
== htab
->elf
.iplt
3474 || s
== htab
->elf
.igotplt
3475 || s
== htab
->plt_got
3476 || s
== htab
->plt_eh_frame
3477 || s
== htab
->plt_got_eh_frame
3478 || s
== htab
->elf
.sdynbss
3479 || s
== htab
->elf
.sdynrelro
)
3481 /* Strip these too. */
3483 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3486 && s
!= htab
->elf
.srelplt
3487 && s
!= htab
->srelplt2
)
3490 /* We use the reloc_count field as a counter if we need
3491 to copy relocs into the output file. */
3496 /* It's not one of our sections, so don't allocate space. */
3502 /* If we don't need this section, strip it from the
3503 output file. This is mostly to handle .rel.bss and
3504 .rel.plt. We must create both sections in
3505 create_dynamic_sections, because they must be created
3506 before the linker maps input sections to output
3507 sections. The linker does that before
3508 adjust_dynamic_symbol is called, and it is that
3509 function which decides whether anything needs to go
3510 into these sections. */
3512 s
->flags
|= SEC_EXCLUDE
;
3516 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3519 /* Allocate memory for the section contents. We use bfd_zalloc
3520 here in case unused entries are not reclaimed before the
3521 section's contents are written out. This should not happen,
3522 but this way if it does, we get a R_386_NONE reloc instead
3524 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3525 if (s
->contents
== NULL
)
3529 if (htab
->plt_eh_frame
!= NULL
3530 && htab
->plt_eh_frame
->contents
!= NULL
)
3532 memcpy (htab
->plt_eh_frame
->contents
,
3533 get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt
,
3534 htab
->plt_eh_frame
->size
);
3535 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3536 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3539 if (htab
->plt_got_eh_frame
!= NULL
3540 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3542 memcpy (htab
->plt_got_eh_frame
->contents
,
3543 get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt_got
,
3544 htab
->plt_got_eh_frame
->size
);
3545 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3546 (htab
->plt_got_eh_frame
->contents
3547 + PLT_FDE_LEN_OFFSET
));
3550 if (htab
->elf
.dynamic_sections_created
)
3552 /* Add some entries to the .dynamic section. We fill in the
3553 values later, in elf_i386_finish_dynamic_sections, but we
3554 must add the entries now so that we get the correct size for
3555 the .dynamic section. The DT_DEBUG entry is filled in by the
3556 dynamic linker and used by the debugger. */
3557 #define add_dynamic_entry(TAG, VAL) \
3558 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3560 if (bfd_link_executable (info
))
3562 if (!add_dynamic_entry (DT_DEBUG
, 0))
3566 if (htab
->elf
.splt
->size
!= 0)
3568 /* DT_PLTGOT is used by prelink even if there is no PLT
3570 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3573 if (htab
->elf
.srelplt
->size
!= 0)
3575 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3576 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3577 || !add_dynamic_entry (DT_JMPREL
, 0))
3584 if (!add_dynamic_entry (DT_REL
, 0)
3585 || !add_dynamic_entry (DT_RELSZ
, 0)
3586 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3589 /* If any dynamic relocs apply to a read-only section,
3590 then we need a DT_TEXTREL entry. */
3591 if ((info
->flags
& DF_TEXTREL
) == 0)
3592 elf_link_hash_traverse (&htab
->elf
,
3593 elf_i386_readonly_dynrelocs
, info
);
3595 if ((info
->flags
& DF_TEXTREL
) != 0)
3597 if (htab
->readonly_dynrelocs_against_ifunc
)
3599 info
->callbacks
->einfo
3600 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3601 bfd_set_error (bfd_error_bad_value
);
3605 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3609 if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3610 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3613 #undef add_dynamic_entry
3619 elf_i386_always_size_sections (bfd
*output_bfd
,
3620 struct bfd_link_info
*info
)
3622 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3626 struct elf_link_hash_entry
*tlsbase
;
3628 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3629 "_TLS_MODULE_BASE_",
3630 FALSE
, FALSE
, FALSE
);
3632 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3634 struct elf_i386_link_hash_table
*htab
;
3635 struct bfd_link_hash_entry
*bh
= NULL
;
3636 const struct elf_backend_data
*bed
3637 = get_elf_backend_data (output_bfd
);
3639 htab
= elf_i386_hash_table (info
);
3643 if (!(_bfd_generic_link_add_one_symbol
3644 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3645 tls_sec
, 0, NULL
, FALSE
,
3646 bed
->collect
, &bh
)))
3649 htab
->tls_module_base
= bh
;
3651 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3652 tlsbase
->def_regular
= 1;
3653 tlsbase
->other
= STV_HIDDEN
;
3654 tlsbase
->root
.linker_def
= 1;
3655 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
3662 /* Set the correct type for an x86 ELF section. We do this by the
3663 section name, which is a hack, but ought to work. */
3666 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3667 Elf_Internal_Shdr
*hdr
,
3672 name
= bfd_get_section_name (abfd
, sec
);
3674 /* This is an ugly, but unfortunately necessary hack that is
3675 needed when producing EFI binaries on x86. It tells
3676 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3677 containing ELF relocation info. We need this hack in order to
3678 be able to generate ELF binaries that can be translated into
3679 EFI applications (which are essentially COFF objects). Those
3680 files contain a COFF ".reloc" section inside an ELFNN object,
3681 which would normally cause BFD to segfault because it would
3682 attempt to interpret this section as containing relocation
3683 entries for section "oc". With this hack enabled, ".reloc"
3684 will be treated as a normal data section, which will avoid the
3685 segfault. However, you won't be able to create an ELFNN binary
3686 with a section named "oc" that needs relocations, but that's
3687 the kind of ugly side-effects you get when detecting section
3688 types based on their names... In practice, this limitation is
3689 unlikely to bite. */
3690 if (strcmp (name
, ".reloc") == 0)
3691 hdr
->sh_type
= SHT_PROGBITS
;
3696 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3697 executables. Rather than setting it to the beginning of the TLS
3698 section, we have to set it to the end. This function may be called
3699 multiple times, it is idempotent. */
3702 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
3704 struct elf_i386_link_hash_table
*htab
;
3705 struct bfd_link_hash_entry
*base
;
3707 if (!bfd_link_executable (info
))
3710 htab
= elf_i386_hash_table (info
);
3714 base
= htab
->tls_module_base
;
3718 base
->u
.def
.value
= htab
->elf
.tls_size
;
3721 /* Return the base VMA address which should be subtracted from real addresses
3722 when resolving @dtpoff relocation.
3723 This is PT_TLS segment p_vaddr. */
3726 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
3728 /* If tls_sec is NULL, we should have signalled an error already. */
3729 if (elf_hash_table (info
)->tls_sec
== NULL
)
3731 return elf_hash_table (info
)->tls_sec
->vma
;
3734 /* Return the relocation value for @tpoff relocation
3735 if STT_TLS virtual address is ADDRESS. */
3738 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3740 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3741 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3742 bfd_vma static_tls_size
;
3744 /* If tls_sec is NULL, we should have signalled an error already. */
3745 if (htab
->tls_sec
== NULL
)
3748 /* Consider special static TLS alignment requirements. */
3749 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3750 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3753 /* Relocate an i386 ELF section. */
3756 elf_i386_relocate_section (bfd
*output_bfd
,
3757 struct bfd_link_info
*info
,
3759 asection
*input_section
,
3761 Elf_Internal_Rela
*relocs
,
3762 Elf_Internal_Sym
*local_syms
,
3763 asection
**local_sections
)
3765 struct elf_i386_link_hash_table
*htab
;
3766 Elf_Internal_Shdr
*symtab_hdr
;
3767 struct elf_link_hash_entry
**sym_hashes
;
3768 bfd_vma
*local_got_offsets
;
3769 bfd_vma
*local_tlsdesc_gotents
;
3770 Elf_Internal_Rela
*rel
;
3771 Elf_Internal_Rela
*wrel
;
3772 Elf_Internal_Rela
*relend
;
3773 bfd_boolean is_vxworks_tls
;
3774 unsigned plt_entry_size
;
3776 BFD_ASSERT (is_i386_elf (input_bfd
));
3778 /* Skip if check_relocs failed. */
3779 if (input_section
->check_relocs_failed
)
3782 htab
= elf_i386_hash_table (info
);
3785 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3786 sym_hashes
= elf_sym_hashes (input_bfd
);
3787 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3788 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3789 /* We have to handle relocations in vxworks .tls_vars sections
3790 specially, because the dynamic loader is 'weird'. */
3791 is_vxworks_tls
= (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3792 && bfd_link_pic (info
)
3793 && !strcmp (input_section
->output_section
->name
,
3796 elf_i386_set_tls_module_base (info
);
3798 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
3800 rel
= wrel
= relocs
;
3801 relend
= relocs
+ input_section
->reloc_count
;
3802 for (; rel
< relend
; wrel
++, rel
++)
3804 unsigned int r_type
;
3805 reloc_howto_type
*howto
;
3806 unsigned long r_symndx
;
3807 struct elf_link_hash_entry
*h
;
3808 struct elf_i386_link_hash_entry
*eh
;
3809 Elf_Internal_Sym
*sym
;
3811 bfd_vma off
, offplt
, plt_offset
;
3813 bfd_boolean unresolved_reloc
;
3814 bfd_reloc_status_type r
;
3818 asection
*resolved_plt
;
3819 bfd_boolean resolved_to_zero
;
3821 r_type
= ELF32_R_TYPE (rel
->r_info
);
3822 if (r_type
== R_386_GNU_VTINHERIT
3823 || r_type
== R_386_GNU_VTENTRY
)
3830 if ((indx
= r_type
) >= R_386_standard
3831 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3832 >= R_386_ext
- R_386_standard
)
3833 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3834 >= R_386_ext2
- R_386_ext
))
3837 /* xgettext:c-format */
3838 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3839 input_bfd
, input_section
, r_type
);
3840 bfd_set_error (bfd_error_bad_value
);
3843 howto
= elf_howto_table
+ indx
;
3845 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3849 unresolved_reloc
= FALSE
;
3850 if (r_symndx
< symtab_hdr
->sh_info
)
3852 sym
= local_syms
+ r_symndx
;
3853 sec
= local_sections
[r_symndx
];
3854 relocation
= (sec
->output_section
->vma
3855 + sec
->output_offset
3857 st_size
= sym
->st_size
;
3859 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3860 && ((sec
->flags
& SEC_MERGE
) != 0
3861 || (bfd_link_relocatable (info
)
3862 && sec
->output_offset
!= 0)))
3865 bfd_byte
*where
= contents
+ rel
->r_offset
;
3867 switch (howto
->size
)
3870 addend
= bfd_get_8 (input_bfd
, where
);
3871 if (howto
->pc_relative
)
3873 addend
= (addend
^ 0x80) - 0x80;
3878 addend
= bfd_get_16 (input_bfd
, where
);
3879 if (howto
->pc_relative
)
3881 addend
= (addend
^ 0x8000) - 0x8000;
3886 addend
= bfd_get_32 (input_bfd
, where
);
3887 if (howto
->pc_relative
)
3889 addend
= (addend
^ 0x80000000) - 0x80000000;
3897 if (bfd_link_relocatable (info
))
3898 addend
+= sec
->output_offset
;
3901 asection
*msec
= sec
;
3902 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3904 addend
-= relocation
;
3905 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3908 switch (howto
->size
)
3911 /* FIXME: overflow checks. */
3912 if (howto
->pc_relative
)
3914 bfd_put_8 (input_bfd
, addend
, where
);
3917 if (howto
->pc_relative
)
3919 bfd_put_16 (input_bfd
, addend
, where
);
3922 if (howto
->pc_relative
)
3924 bfd_put_32 (input_bfd
, addend
, where
);
3928 else if (!bfd_link_relocatable (info
)
3929 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3931 /* Relocate against local STT_GNU_IFUNC symbol. */
3932 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3937 /* Set STT_GNU_IFUNC symbol value. */
3938 h
->root
.u
.def
.value
= sym
->st_value
;
3939 h
->root
.u
.def
.section
= sec
;
3944 bfd_boolean warned ATTRIBUTE_UNUSED
;
3945 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3947 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3948 r_symndx
, symtab_hdr
, sym_hashes
,
3950 unresolved_reloc
, warned
, ignored
);
3954 if (sec
!= NULL
&& discarded_section (sec
))
3956 _bfd_clear_contents (howto
, input_bfd
, input_section
,
3957 contents
+ rel
->r_offset
);
3958 wrel
->r_offset
= rel
->r_offset
;
3962 /* For ld -r, remove relocations in debug sections against
3963 sections defined in discarded sections. Not done for
3964 eh_frame editing code expects to be present. */
3965 if (bfd_link_relocatable (info
)
3966 && (input_section
->flags
& SEC_DEBUGGING
))
3972 if (bfd_link_relocatable (info
))
3979 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3980 it here if it is defined in a non-shared object. */
3982 && h
->type
== STT_GNU_IFUNC
3985 asection
*plt
, *gotplt
, *base_got
;
3989 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3991 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3992 sections because such sections are not SEC_ALLOC and
3993 thus ld.so will not process them. */
3994 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
3999 /* STT_GNU_IFUNC symbol must go through PLT. */
4000 if (htab
->elf
.splt
!= NULL
)
4002 plt
= htab
->elf
.splt
;
4003 gotplt
= htab
->elf
.sgotplt
;
4007 plt
= htab
->elf
.iplt
;
4008 gotplt
= htab
->elf
.igotplt
;
4018 base_got
= htab
->elf
.sgot
;
4019 off
= h
->got
.offset
;
4021 if (base_got
== NULL
)
4024 if (off
== (bfd_vma
) -1)
4026 /* We can't use h->got.offset here to save state, or
4027 even just remember the offset, as finish_dynamic_symbol
4028 would use that as offset into .got. */
4030 if (h
->plt
.offset
== (bfd_vma
) -1)
4033 if (htab
->elf
.splt
!= NULL
)
4035 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4036 off
= (plt_index
+ 3) * 4;
4037 base_got
= htab
->elf
.sgotplt
;
4041 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4042 off
= plt_index
* 4;
4043 base_got
= htab
->elf
.igotplt
;
4046 if (h
->dynindx
== -1
4050 /* This references the local defitionion. We must
4051 initialize this entry in the global offset table.
4052 Since the offset must always be a multiple of 8,
4053 we use the least significant bit to record
4054 whether we have initialized it already.
4056 When doing a dynamic link, we create a .rela.got
4057 relocation entry to initialize the value. This
4058 is done in the finish_dynamic_symbol routine. */
4063 bfd_put_32 (output_bfd
, relocation
,
4064 base_got
->contents
+ off
);
4072 relocation
= (base_got
->output_section
->vma
4073 + base_got
->output_offset
+ off
4074 - gotplt
->output_section
->vma
4075 - gotplt
->output_offset
);
4077 if ((*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5)
4079 if (bfd_link_pic (info
))
4080 goto disallow_got32
;
4082 /* Add the GOT base if there is no base register. */
4083 relocation
+= (gotplt
->output_section
->vma
4084 + gotplt
->output_offset
);
4086 else if (htab
->elf
.splt
== NULL
)
4088 /* Adjust for static executables. */
4089 relocation
+= gotplt
->output_offset
;
4095 if (h
->plt
.offset
== (bfd_vma
) -1)
4097 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4098 if (r_type
== R_386_32
4099 && (input_section
->flags
& SEC_CODE
) == 0)
4100 goto do_ifunc_pointer
;
4101 goto bad_ifunc_reloc
;
4104 relocation
= (plt
->output_section
->vma
4105 + plt
->output_offset
+ h
->plt
.offset
);
4111 if (h
->root
.root
.string
)
4112 name
= h
->root
.root
.string
;
4114 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4117 /* xgettext:c-format */
4118 (_("%B: relocation %s against STT_GNU_IFUNC "
4119 "symbol `%s' isn't supported"), input_bfd
,
4121 bfd_set_error (bfd_error_bad_value
);
4125 /* Generate dynamic relcoation only when there is a
4126 non-GOT reference in a shared object. */
4127 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4128 || h
->plt
.offset
== (bfd_vma
) -1)
4130 Elf_Internal_Rela outrel
;
4135 /* Need a dynamic relocation to get the real function
4137 offset
= _bfd_elf_section_offset (output_bfd
,
4141 if (offset
== (bfd_vma
) -1
4142 || offset
== (bfd_vma
) -2)
4145 outrel
.r_offset
= (input_section
->output_section
->vma
4146 + input_section
->output_offset
4149 if (h
->dynindx
== -1
4151 || bfd_link_executable (info
))
4153 /* This symbol is resolved locally. */
4154 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4155 bfd_put_32 (output_bfd
,
4156 (h
->root
.u
.def
.value
4157 + h
->root
.u
.def
.section
->output_section
->vma
4158 + h
->root
.u
.def
.section
->output_offset
),
4162 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4164 /* Dynamic relocations are stored in
4165 1. .rel.ifunc section in PIC object.
4166 2. .rel.got section in dynamic executable.
4167 3. .rel.iplt section in static executable. */
4168 if (bfd_link_pic (info
))
4169 sreloc
= htab
->elf
.irelifunc
;
4170 else if (htab
->elf
.splt
!= NULL
)
4171 sreloc
= htab
->elf
.srelgot
;
4173 sreloc
= htab
->elf
.irelplt
;
4174 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4176 /* If this reloc is against an external symbol, we
4177 do not want to fiddle with the addend. Otherwise,
4178 we need to include the symbol value so that it
4179 becomes an addend for the dynamic reloc. For an
4180 internal symbol, we have updated addend. */
4189 relocation
-= (gotplt
->output_section
->vma
4190 + gotplt
->output_offset
);
4195 eh
= (struct elf_i386_link_hash_entry
*) h
;
4196 resolved_to_zero
= (eh
!= NULL
4197 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4204 /* Avoid optimizing _DYNAMIC since ld.so may use its
4205 link-time address. */
4206 if (h
== htab
->elf
.hdynamic
)
4209 if (bfd_link_pic (info
))
4211 /* It is OK to convert mov to lea and convert indirect
4212 branch to direct branch. It is OK to convert adc,
4213 add, and, cmp, or, sbb, sub, test, xor only when PIC
4215 unsigned int opcode
, addend
;
4216 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4219 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4220 if (opcode
!= 0x8b && opcode
!= 0xff)
4224 /* Resolve "mov GOT[(%reg)], %reg",
4225 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
4226 and "binop foo@GOT[(%reg)], %reg". */
4228 || (h
->plt
.offset
== (bfd_vma
) -1
4229 && h
->got
.offset
== (bfd_vma
) -1)
4230 || htab
->elf
.sgotplt
== NULL
)
4233 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
4234 + htab
->elf
.sgotplt
->output_offset
);
4236 /* It is relative to .got.plt section. */
4237 if (h
->got
.offset
!= (bfd_vma
) -1)
4238 /* Use GOT entry. Mask off the least significant bit in
4239 GOT offset which may be set by R_386_GOT32 processing
4241 relocation
= (htab
->elf
.sgot
->output_section
->vma
4242 + htab
->elf
.sgot
->output_offset
4243 + (h
->got
.offset
& ~1) - offplt
);
4245 /* Use GOTPLT entry. */
4246 relocation
= (h
->plt
.offset
/ plt_entry_size
- 1 + 3) * 4;
4248 if (!bfd_link_pic (info
))
4250 /* If not PIC, add the .got.plt section address for
4251 baseless addressing. */
4253 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4254 if ((modrm
& 0xc7) == 0x5)
4255 relocation
+= offplt
;
4258 unresolved_reloc
= FALSE
;
4263 /* Relocation is to the entry for this symbol in the global
4265 if (htab
->elf
.sgot
== NULL
)
4272 off
= h
->got
.offset
;
4273 dyn
= htab
->elf
.dynamic_sections_created
;
4274 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4275 bfd_link_pic (info
),
4277 || (bfd_link_pic (info
)
4278 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4279 || (ELF_ST_VISIBILITY (h
->other
)
4280 && h
->root
.type
== bfd_link_hash_undefweak
))
4282 /* This is actually a static link, or it is a
4283 -Bsymbolic link and the symbol is defined
4284 locally, or the symbol was forced to be local
4285 because of a version file. We must initialize
4286 this entry in the global offset table. Since the
4287 offset must always be a multiple of 4, we use the
4288 least significant bit to record whether we have
4289 initialized it already.
4291 When doing a dynamic link, we create a .rel.got
4292 relocation entry to initialize the value. This
4293 is done in the finish_dynamic_symbol routine. */
4298 bfd_put_32 (output_bfd
, relocation
,
4299 htab
->elf
.sgot
->contents
+ off
);
4304 unresolved_reloc
= FALSE
;
4308 if (local_got_offsets
== NULL
)
4311 off
= local_got_offsets
[r_symndx
];
4313 /* The offset must always be a multiple of 4. We use
4314 the least significant bit to record whether we have
4315 already generated the necessary reloc. */
4320 bfd_put_32 (output_bfd
, relocation
,
4321 htab
->elf
.sgot
->contents
+ off
);
4323 if (bfd_link_pic (info
))
4326 Elf_Internal_Rela outrel
;
4328 s
= htab
->elf
.srelgot
;
4332 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4333 + htab
->elf
.sgot
->output_offset
4335 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4336 elf_append_rel (output_bfd
, s
, &outrel
);
4339 local_got_offsets
[r_symndx
] |= 1;
4343 if (off
>= (bfd_vma
) -2)
4346 relocation
= (htab
->elf
.sgot
->output_section
->vma
4347 + htab
->elf
.sgot
->output_offset
+ off
);
4348 if ((*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5)
4350 if (bfd_link_pic (info
))
4352 /* For PIC, disallow R_386_GOT32 without a base
4353 register since we don't know what the GOT base
4359 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4362 name
= h
->root
.root
.string
;
4365 /* xgettext:c-format */
4366 (_("%B: direct GOT relocation %s against `%s' without base register can not be used when making a shared object"),
4367 input_bfd
, howto
->name
, name
);
4368 bfd_set_error (bfd_error_bad_value
);
4374 /* Subtract the .got.plt section address only with a base
4376 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
4377 + htab
->elf
.sgotplt
->output_offset
);
4383 /* Relocation is relative to the start of the global offset
4386 /* Check to make sure it isn't a protected function or data
4387 symbol for shared library since it may not be local when
4388 used as function address or with copy relocation. We also
4389 need to make sure that a symbol is referenced locally. */
4390 if (!bfd_link_executable (info
) && h
)
4392 if (!h
->def_regular
)
4396 switch (ELF_ST_VISIBILITY (h
->other
))
4399 v
= _("hidden symbol");
4402 v
= _("internal symbol");
4405 v
= _("protected symbol");
4413 /* xgettext:c-format */
4414 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
4415 input_bfd
, v
, h
->root
.root
.string
);
4416 bfd_set_error (bfd_error_bad_value
);
4419 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
4420 && (h
->type
== STT_FUNC
4421 || h
->type
== STT_OBJECT
)
4422 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4425 /* xgettext:c-format */
4426 (_("%B: relocation R_386_GOTOFF against protected %s `%s' can not be used when making a shared object"),
4428 h
->type
== STT_FUNC
? "function" : "data",
4429 h
->root
.root
.string
);
4430 bfd_set_error (bfd_error_bad_value
);
4435 /* Note that sgot is not involved in this
4436 calculation. We always want the start of .got.plt. If we
4437 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4438 permitted by the ABI, we might have to change this
4440 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4441 + htab
->elf
.sgotplt
->output_offset
;
4445 /* Use global offset table as symbol value. */
4446 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4447 + htab
->elf
.sgotplt
->output_offset
;
4448 unresolved_reloc
= FALSE
;
4452 /* Relocation is to the entry for this symbol in the
4453 procedure linkage table. */
4455 /* Resolve a PLT32 reloc against a local symbol directly,
4456 without using the procedure linkage table. */
4460 if ((h
->plt
.offset
== (bfd_vma
) -1
4461 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4462 || htab
->elf
.splt
== NULL
)
4464 /* We didn't make a PLT entry for this symbol. This
4465 happens when statically linking PIC code, or when
4466 using -Bsymbolic. */
4470 if (h
->plt
.offset
!= (bfd_vma
) -1)
4472 resolved_plt
= htab
->elf
.splt
;
4473 plt_offset
= h
->plt
.offset
;
4477 resolved_plt
= htab
->plt_got
;
4478 plt_offset
= eh
->plt_got
.offset
;
4481 relocation
= (resolved_plt
->output_section
->vma
4482 + resolved_plt
->output_offset
4484 unresolved_reloc
= FALSE
;
4488 /* Set to symbol size. */
4489 relocation
= st_size
;
4494 if ((input_section
->flags
& SEC_ALLOC
) == 0
4498 /* Copy dynamic function pointer relocations. Don't generate
4499 dynamic relocations against resolved undefined weak symbols
4500 in PIE, except for R_386_PC32. */
4501 if ((bfd_link_pic (info
)
4503 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4504 && (!resolved_to_zero
4505 || r_type
== R_386_PC32
))
4506 || h
->root
.type
!= bfd_link_hash_undefweak
))
4507 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
4508 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4509 || (ELIMINATE_COPY_RELOCS
4510 && !bfd_link_pic (info
)
4514 || eh
->func_pointer_refcount
> 0
4515 || (h
->root
.type
== bfd_link_hash_undefweak
4516 && !resolved_to_zero
))
4517 && ((h
->def_dynamic
&& !h
->def_regular
)
4518 /* Undefined weak symbol is bound locally when
4520 || h
->root
.type
== bfd_link_hash_undefweak
)))
4522 Elf_Internal_Rela outrel
;
4523 bfd_boolean skip
, relocate
;
4526 /* When generating a shared object, these relocations
4527 are copied into the output file to be resolved at run
4534 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4536 if (outrel
.r_offset
== (bfd_vma
) -1)
4538 else if (outrel
.r_offset
== (bfd_vma
) -2)
4539 skip
= TRUE
, relocate
= TRUE
;
4540 outrel
.r_offset
+= (input_section
->output_section
->vma
4541 + input_section
->output_offset
);
4544 memset (&outrel
, 0, sizeof outrel
);
4547 && (r_type
== R_386_PC32
4548 || !(bfd_link_executable (info
)
4549 || SYMBOLIC_BIND (info
, h
))
4550 || !h
->def_regular
))
4551 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4554 /* This symbol is local, or marked to become local. */
4556 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4559 sreloc
= elf_section_data (input_section
)->sreloc
;
4561 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4563 r
= bfd_reloc_notsupported
;
4564 goto check_relocation_error
;
4567 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4569 /* If this reloc is against an external symbol, we do
4570 not want to fiddle with the addend. Otherwise, we
4571 need to include the symbol value so that it becomes
4572 an addend for the dynamic reloc. */
4579 if (!bfd_link_executable (info
))
4581 Elf_Internal_Rela outrel
;
4584 outrel
.r_offset
= rel
->r_offset
4585 + input_section
->output_section
->vma
4586 + input_section
->output_offset
;
4587 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4588 sreloc
= elf_section_data (input_section
)->sreloc
;
4591 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4596 case R_386_TLS_GOTDESC
:
4597 case R_386_TLS_DESC_CALL
:
4598 case R_386_TLS_IE_32
:
4599 case R_386_TLS_GOTIE
:
4600 tls_type
= GOT_UNKNOWN
;
4601 if (h
== NULL
&& local_got_offsets
)
4602 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
4604 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
4605 if (tls_type
== GOT_TLS_IE
)
4606 tls_type
= GOT_TLS_IE_NEG
;
4608 if (! elf_i386_tls_transition (info
, input_bfd
,
4609 input_section
, contents
,
4610 symtab_hdr
, sym_hashes
,
4611 &r_type
, tls_type
, rel
,
4612 relend
, h
, r_symndx
, TRUE
))
4615 if (r_type
== R_386_TLS_LE_32
)
4617 BFD_ASSERT (! unresolved_reloc
);
4618 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4623 /* GD->LE transition. */
4624 type
= *(contents
+ rel
->r_offset
- 2);
4628 leal foo@tlsgd(,%ebx,1), %eax
4629 call ___tls_get_addr@PLT
4632 subl $foo@tpoff, %eax
4633 (6 byte form of subl). */
4634 roff
= rel
->r_offset
+ 5;
4639 leal foo@tlsgd(%ebx), %eax
4640 call ___tls_get_addr@PLT
4643 leal foo@tlsgd(%reg), %eax
4644 call *___tls_get_addr@GOT(%reg)
4645 which may be converted to
4646 addr32 call ___tls_get_addr
4648 movl %gs:0, %eax; subl $foo@tpoff, %eax
4649 (6 byte form of subl). */
4650 roff
= rel
->r_offset
+ 6;
4652 memcpy (contents
+ roff
- 8,
4653 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4654 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4656 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4661 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4663 /* GDesc -> LE transition.
4664 It's originally something like:
4665 leal x@tlsdesc(%ebx), %eax
4669 Registers other than %eax may be set up here. */
4674 roff
= rel
->r_offset
;
4675 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4677 /* Now modify the instruction as appropriate. */
4678 /* aoliva FIXME: remove the above and xor the byte
4680 bfd_put_8 (output_bfd
, val
^ 0x86,
4681 contents
+ roff
- 1);
4682 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4686 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4688 /* GDesc -> LE transition.
4696 roff
= rel
->r_offset
;
4697 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4698 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4701 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4705 /* IE->LE transition:
4706 Originally it can be one of:
4714 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4717 /* movl foo, %eax. */
4718 bfd_put_8 (output_bfd
, 0xb8,
4719 contents
+ rel
->r_offset
- 1);
4725 type
= bfd_get_8 (input_bfd
,
4726 contents
+ rel
->r_offset
- 2);
4731 bfd_put_8 (output_bfd
, 0xc7,
4732 contents
+ rel
->r_offset
- 2);
4733 bfd_put_8 (output_bfd
,
4734 0xc0 | ((val
>> 3) & 7),
4735 contents
+ rel
->r_offset
- 1);
4739 bfd_put_8 (output_bfd
, 0x81,
4740 contents
+ rel
->r_offset
- 2);
4741 bfd_put_8 (output_bfd
,
4742 0xc0 | ((val
>> 3) & 7),
4743 contents
+ rel
->r_offset
- 1);
4750 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4751 contents
+ rel
->r_offset
);
4756 unsigned int val
, type
;
4758 /* {IE_32,GOTIE}->LE transition:
4759 Originally it can be one of:
4760 subl foo(%reg1), %reg2
4761 movl foo(%reg1), %reg2
4762 addl foo(%reg1), %reg2
4765 movl $foo, %reg2 (6 byte form)
4766 addl $foo, %reg2. */
4767 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4768 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4772 bfd_put_8 (output_bfd
, 0xc7,
4773 contents
+ rel
->r_offset
- 2);
4774 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4775 contents
+ rel
->r_offset
- 1);
4777 else if (type
== 0x2b)
4780 bfd_put_8 (output_bfd
, 0x81,
4781 contents
+ rel
->r_offset
- 2);
4782 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4783 contents
+ rel
->r_offset
- 1);
4785 else if (type
== 0x03)
4788 bfd_put_8 (output_bfd
, 0x81,
4789 contents
+ rel
->r_offset
- 2);
4790 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4791 contents
+ rel
->r_offset
- 1);
4795 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4796 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4797 contents
+ rel
->r_offset
);
4799 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4800 contents
+ rel
->r_offset
);
4805 if (htab
->elf
.sgot
== NULL
)
4810 off
= h
->got
.offset
;
4811 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
4815 if (local_got_offsets
== NULL
)
4818 off
= local_got_offsets
[r_symndx
];
4819 offplt
= local_tlsdesc_gotents
[r_symndx
];
4826 Elf_Internal_Rela outrel
;
4830 if (htab
->elf
.srelgot
== NULL
)
4833 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4835 if (GOT_TLS_GDESC_P (tls_type
))
4838 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4839 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4840 <= htab
->elf
.sgotplt
->size
);
4841 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4842 + htab
->elf
.sgotplt
->output_offset
4844 + htab
->sgotplt_jump_table_size
);
4845 sreloc
= htab
->elf
.srelplt
;
4846 loc
= sreloc
->contents
;
4847 loc
+= (htab
->next_tls_desc_index
++
4848 * sizeof (Elf32_External_Rel
));
4849 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4850 <= sreloc
->contents
+ sreloc
->size
);
4851 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4854 BFD_ASSERT (! unresolved_reloc
);
4855 bfd_put_32 (output_bfd
,
4856 relocation
- elf_i386_dtpoff_base (info
),
4857 htab
->elf
.sgotplt
->contents
+ offplt
4858 + htab
->sgotplt_jump_table_size
+ 4);
4862 bfd_put_32 (output_bfd
, 0,
4863 htab
->elf
.sgotplt
->contents
+ offplt
4864 + htab
->sgotplt_jump_table_size
+ 4);
4868 sreloc
= htab
->elf
.srelgot
;
4870 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4871 + htab
->elf
.sgot
->output_offset
+ off
);
4873 if (GOT_TLS_GD_P (tls_type
))
4874 dr_type
= R_386_TLS_DTPMOD32
;
4875 else if (GOT_TLS_GDESC_P (tls_type
))
4877 else if (tls_type
== GOT_TLS_IE_POS
)
4878 dr_type
= R_386_TLS_TPOFF
;
4880 dr_type
= R_386_TLS_TPOFF32
;
4882 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
4883 bfd_put_32 (output_bfd
,
4884 relocation
- elf_i386_dtpoff_base (info
),
4885 htab
->elf
.sgot
->contents
+ off
);
4886 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
4887 bfd_put_32 (output_bfd
,
4888 elf_i386_dtpoff_base (info
) - relocation
,
4889 htab
->elf
.sgot
->contents
+ off
);
4890 else if (dr_type
!= R_386_TLS_DESC
)
4891 bfd_put_32 (output_bfd
, 0,
4892 htab
->elf
.sgot
->contents
+ off
);
4893 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
4895 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4897 if (GOT_TLS_GD_P (tls_type
))
4901 BFD_ASSERT (! unresolved_reloc
);
4902 bfd_put_32 (output_bfd
,
4903 relocation
- elf_i386_dtpoff_base (info
),
4904 htab
->elf
.sgot
->contents
+ off
+ 4);
4908 bfd_put_32 (output_bfd
, 0,
4909 htab
->elf
.sgot
->contents
+ off
+ 4);
4910 outrel
.r_info
= ELF32_R_INFO (indx
,
4911 R_386_TLS_DTPOFF32
);
4912 outrel
.r_offset
+= 4;
4913 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4916 else if (tls_type
== GOT_TLS_IE_BOTH
)
4918 bfd_put_32 (output_bfd
,
4920 ? relocation
- elf_i386_dtpoff_base (info
)
4922 htab
->elf
.sgot
->contents
+ off
+ 4);
4923 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4924 outrel
.r_offset
+= 4;
4925 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4932 local_got_offsets
[r_symndx
] |= 1;
4935 if (off
>= (bfd_vma
) -2
4936 && ! GOT_TLS_GDESC_P (tls_type
))
4938 if (r_type
== R_386_TLS_GOTDESC
4939 || r_type
== R_386_TLS_DESC_CALL
)
4941 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4942 unresolved_reloc
= FALSE
;
4944 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4946 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4947 + htab
->elf
.sgotplt
->output_offset
;
4948 relocation
= htab
->elf
.sgot
->output_section
->vma
4949 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4950 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4951 && tls_type
== GOT_TLS_IE_BOTH
)
4953 if (r_type
== R_386_TLS_IE
)
4954 relocation
+= g_o_t
;
4955 unresolved_reloc
= FALSE
;
4957 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4959 unsigned int val
, type
;
4962 /* GD->IE transition. */
4963 type
= *(contents
+ rel
->r_offset
- 2);
4964 val
= *(contents
+ rel
->r_offset
- 1);
4968 leal foo@tlsgd(,%ebx,1), %eax
4969 call ___tls_get_addr@PLT
4972 subl $foo@gottpoff(%ebx), %eax. */
4974 roff
= rel
->r_offset
- 3;
4979 leal foo@tlsgd(%ebx), %eax
4980 call ___tls_get_addr@PLT
4983 leal foo@tlsgd(%reg), %eax
4984 call *___tls_get_addr@GOT(%reg)
4985 which may be converted to
4986 addr32 call ___tls_get_addr
4989 subl $foo@gottpoff(%reg), %eax. */
4990 roff
= rel
->r_offset
- 2;
4992 memcpy (contents
+ roff
,
4993 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4994 contents
[roff
+ 7] = 0x80 | (val
& 7);
4995 /* If foo is used only with foo@gotntpoff(%reg) and
4996 foo@indntpoff, but not with foo@gottpoff(%reg), change
4997 subl $foo@gottpoff(%reg), %eax
4999 addl $foo@gotntpoff(%reg), %eax. */
5000 if (tls_type
== GOT_TLS_IE_POS
)
5001 contents
[roff
+ 6] = 0x03;
5002 bfd_put_32 (output_bfd
,
5003 htab
->elf
.sgot
->output_section
->vma
5004 + htab
->elf
.sgot
->output_offset
+ off
5005 - htab
->elf
.sgotplt
->output_section
->vma
5006 - htab
->elf
.sgotplt
->output_offset
,
5007 contents
+ roff
+ 8);
5008 /* Skip R_386_PLT32 and R_386_GOT32X. */
5013 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
5015 /* GDesc -> IE transition.
5016 It's originally something like:
5017 leal x@tlsdesc(%ebx), %eax
5020 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
5022 movl x@gottpoff(%ebx), %eax # before negl %eax
5024 Registers other than %eax may be set up here. */
5028 /* First, make sure it's a leal adding ebx to a 32-bit
5029 offset into any register, although it's probably
5030 almost always going to be eax. */
5031 roff
= rel
->r_offset
;
5033 /* Now modify the instruction as appropriate. */
5034 /* To turn a leal into a movl in the form we use it, it
5035 suffices to change the first byte from 0x8d to 0x8b.
5036 aoliva FIXME: should we decide to keep the leal, all
5037 we have to do is remove the statement below, and
5038 adjust the relaxation of R_386_TLS_DESC_CALL. */
5039 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5041 if (tls_type
== GOT_TLS_IE_BOTH
)
5044 bfd_put_32 (output_bfd
,
5045 htab
->elf
.sgot
->output_section
->vma
5046 + htab
->elf
.sgot
->output_offset
+ off
5047 - htab
->elf
.sgotplt
->output_section
->vma
5048 - htab
->elf
.sgotplt
->output_offset
,
5052 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
5054 /* GDesc -> IE transition.
5062 depending on how we transformed the TLS_GOTDESC above.
5067 roff
= rel
->r_offset
;
5069 /* Now modify the instruction as appropriate. */
5070 if (tls_type
!= GOT_TLS_IE_NEG
)
5073 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5074 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5079 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
5080 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
5090 if (! elf_i386_tls_transition (info
, input_bfd
,
5091 input_section
, contents
,
5092 symtab_hdr
, sym_hashes
,
5093 &r_type
, GOT_UNKNOWN
, rel
,
5094 relend
, h
, r_symndx
, TRUE
))
5097 if (r_type
!= R_386_TLS_LDM
)
5099 /* LD->LE transition. Change
5100 leal foo@tlsldm(%ebx) %eax
5101 call ___tls_get_addr@PLT
5105 leal 0(%esi,1), %esi
5107 leal foo@tlsldm(%reg) %eax
5108 call *___tls_get_addr@GOT(%reg)
5109 which may be converted to
5110 addr32 call ___tls_get_addr
5113 leal 0(%esi), %esi */
5114 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
5115 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
5116 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
5117 memcpy (contents
+ rel
->r_offset
- 2,
5118 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
5120 memcpy (contents
+ rel
->r_offset
- 2,
5121 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
5122 /* Skip R_386_PC32/R_386_PLT32. */
5128 if (htab
->elf
.sgot
== NULL
)
5131 off
= htab
->tls_ldm_got
.offset
;
5136 Elf_Internal_Rela outrel
;
5138 if (htab
->elf
.srelgot
== NULL
)
5141 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5142 + htab
->elf
.sgot
->output_offset
+ off
);
5144 bfd_put_32 (output_bfd
, 0,
5145 htab
->elf
.sgot
->contents
+ off
);
5146 bfd_put_32 (output_bfd
, 0,
5147 htab
->elf
.sgot
->contents
+ off
+ 4);
5148 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
5149 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
5150 htab
->tls_ldm_got
.offset
|= 1;
5152 relocation
= htab
->elf
.sgot
->output_section
->vma
5153 + htab
->elf
.sgot
->output_offset
+ off
5154 - htab
->elf
.sgotplt
->output_section
->vma
5155 - htab
->elf
.sgotplt
->output_offset
;
5156 unresolved_reloc
= FALSE
;
5159 case R_386_TLS_LDO_32
:
5160 if (!bfd_link_executable (info
)
5161 || (input_section
->flags
& SEC_CODE
) == 0)
5162 relocation
-= elf_i386_dtpoff_base (info
);
5164 /* When converting LDO to LE, we must negate. */
5165 relocation
= -elf_i386_tpoff (info
, relocation
);
5168 case R_386_TLS_LE_32
:
5170 if (!bfd_link_executable (info
))
5172 Elf_Internal_Rela outrel
;
5175 outrel
.r_offset
= rel
->r_offset
5176 + input_section
->output_section
->vma
5177 + input_section
->output_offset
;
5178 if (h
!= NULL
&& h
->dynindx
!= -1)
5182 if (r_type
== R_386_TLS_LE_32
)
5183 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
5185 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5186 sreloc
= elf_section_data (input_section
)->sreloc
;
5189 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5192 else if (r_type
== R_386_TLS_LE_32
)
5193 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
5195 relocation
-= elf_i386_dtpoff_base (info
);
5197 else if (r_type
== R_386_TLS_LE_32
)
5198 relocation
= elf_i386_tpoff (info
, relocation
);
5200 relocation
= -elf_i386_tpoff (info
, relocation
);
5207 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5208 because such sections are not SEC_ALLOC and thus ld.so will
5209 not process them. */
5210 if (unresolved_reloc
5211 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5213 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5214 rel
->r_offset
) != (bfd_vma
) -1)
5217 /* xgettext:c-format */
5218 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5221 (long) rel
->r_offset
,
5223 h
->root
.root
.string
);
5228 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5229 contents
, rel
->r_offset
,
5232 check_relocation_error
:
5233 if (r
!= bfd_reloc_ok
)
5238 name
= h
->root
.root
.string
;
5241 name
= bfd_elf_string_from_elf_section (input_bfd
,
5242 symtab_hdr
->sh_link
,
5247 name
= bfd_section_name (input_bfd
, sec
);
5250 if (r
== bfd_reloc_overflow
)
5251 (*info
->callbacks
->reloc_overflow
)
5252 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5253 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5257 /* xgettext:c-format */
5258 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5259 input_bfd
, input_section
,
5260 (long) rel
->r_offset
, name
, (int) r
);
5271 Elf_Internal_Shdr
*rel_hdr
;
5272 size_t deleted
= rel
- wrel
;
5274 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5275 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5276 if (rel_hdr
->sh_size
== 0)
5278 /* It is too late to remove an empty reloc section. Leave
5280 ??? What is wrong with an empty section??? */
5281 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5284 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5285 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5286 input_section
->reloc_count
-= deleted
;
5292 /* Finish up dynamic symbol handling. We set the contents of various
5293 dynamic sections here. */
5296 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
5297 struct bfd_link_info
*info
,
5298 struct elf_link_hash_entry
*h
,
5299 Elf_Internal_Sym
*sym
)
5301 struct elf_i386_link_hash_table
*htab
;
5302 unsigned plt_entry_size
;
5303 const struct elf_i386_backend_data
*abed
;
5304 struct elf_i386_link_hash_entry
*eh
;
5305 bfd_boolean local_undefweak
;
5307 htab
= elf_i386_hash_table (info
);
5311 abed
= get_elf_i386_backend_data (output_bfd
);
5312 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
5314 eh
= (struct elf_i386_link_hash_entry
*) h
;
5316 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5317 resolved undefined weak symbols in executable so that their
5318 references have value 0 at run-time. */
5319 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5323 if (h
->plt
.offset
!= (bfd_vma
) -1)
5327 Elf_Internal_Rela rel
;
5329 asection
*plt
, *gotplt
, *relplt
;
5331 /* When building a static executable, use .iplt, .igot.plt and
5332 .rel.iplt sections for STT_GNU_IFUNC symbols. */
5333 if (htab
->elf
.splt
!= NULL
)
5335 plt
= htab
->elf
.splt
;
5336 gotplt
= htab
->elf
.sgotplt
;
5337 relplt
= htab
->elf
.srelplt
;
5341 plt
= htab
->elf
.iplt
;
5342 gotplt
= htab
->elf
.igotplt
;
5343 relplt
= htab
->elf
.irelplt
;
5346 /* This symbol has an entry in the procedure linkage table. Set
5349 if ((h
->dynindx
== -1
5351 && !((h
->forced_local
|| bfd_link_executable (info
))
5353 && h
->type
== STT_GNU_IFUNC
))
5359 /* Get the index in the procedure linkage table which
5360 corresponds to this symbol. This is the index of this symbol
5361 in all the symbols for which we are making plt entries. The
5362 first entry in the procedure linkage table is reserved.
5364 Get the offset into the .got table of the entry that
5365 corresponds to this function. Each .got entry is 4 bytes.
5366 The first three are reserved.
5368 For static executables, we don't reserve anything. */
5370 if (plt
== htab
->elf
.splt
)
5372 got_offset
= h
->plt
.offset
/ plt_entry_size
- 1;
5373 got_offset
= (got_offset
+ 3) * 4;
5377 got_offset
= h
->plt
.offset
/ plt_entry_size
;
5378 got_offset
= got_offset
* 4;
5381 /* Fill in the entry in the procedure linkage table. */
5382 if (! bfd_link_pic (info
))
5384 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->plt_entry
,
5385 abed
->plt
->plt_entry_size
);
5386 bfd_put_32 (output_bfd
,
5387 (gotplt
->output_section
->vma
5388 + gotplt
->output_offset
5390 plt
->contents
+ h
->plt
.offset
5391 + abed
->plt
->plt_got_offset
);
5393 if (abed
->is_vxworks
)
5395 int s
, k
, reloc_index
;
5397 /* Create the R_386_32 relocation referencing the GOT
5398 for this PLT entry. */
5400 /* S: Current slot number (zero-based). */
5401 s
= ((h
->plt
.offset
- abed
->plt
->plt_entry_size
)
5402 / abed
->plt
->plt_entry_size
);
5403 /* K: Number of relocations for PLTResolve. */
5404 if (bfd_link_pic (info
))
5405 k
= PLTRESOLVE_RELOCS_SHLIB
;
5407 k
= PLTRESOLVE_RELOCS
;
5408 /* Skip the PLTresolve relocations, and the relocations for
5409 the other PLT slots. */
5410 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
5411 loc
= (htab
->srelplt2
->contents
+ reloc_index
5412 * sizeof (Elf32_External_Rel
));
5414 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5415 + htab
->elf
.splt
->output_offset
5416 + h
->plt
.offset
+ 2),
5417 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5418 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5420 /* Create the R_386_32 relocation referencing the beginning of
5421 the PLT for this GOT entry. */
5422 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5423 + htab
->elf
.sgotplt
->output_offset
5425 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5426 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5427 loc
+ sizeof (Elf32_External_Rel
));
5432 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->pic_plt_entry
,
5433 abed
->plt
->plt_entry_size
);
5434 bfd_put_32 (output_bfd
, got_offset
,
5435 plt
->contents
+ h
->plt
.offset
5436 + abed
->plt
->plt_got_offset
);
5439 /* Fill in the entry in the global offset table. Leave the entry
5440 as zero for undefined weak symbol in PIE. No PLT relocation
5441 against undefined weak symbol in PIE. */
5442 if (!local_undefweak
)
5444 bfd_put_32 (output_bfd
,
5445 (plt
->output_section
->vma
5446 + plt
->output_offset
5448 + abed
->plt
->plt_lazy_offset
),
5449 gotplt
->contents
+ got_offset
);
5451 /* Fill in the entry in the .rel.plt section. */
5452 rel
.r_offset
= (gotplt
->output_section
->vma
5453 + gotplt
->output_offset
5455 if (h
->dynindx
== -1
5456 || ((bfd_link_executable (info
)
5457 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5459 && h
->type
== STT_GNU_IFUNC
))
5461 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5462 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5463 in the .got.plt section. */
5464 bfd_put_32 (output_bfd
,
5465 (h
->root
.u
.def
.value
5466 + h
->root
.u
.def
.section
->output_section
->vma
5467 + h
->root
.u
.def
.section
->output_offset
),
5468 gotplt
->contents
+ got_offset
);
5469 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5470 /* R_386_IRELATIVE comes last. */
5471 plt_index
= htab
->next_irelative_index
--;
5475 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
5476 plt_index
= htab
->next_jump_slot_index
++;
5479 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5480 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5482 /* Don't fill PLT entry for static executables. */
5483 if (plt
== htab
->elf
.splt
)
5485 bfd_put_32 (output_bfd
,
5486 plt_index
* sizeof (Elf32_External_Rel
),
5487 plt
->contents
+ h
->plt
.offset
5488 + abed
->plt
->plt_reloc_offset
);
5489 bfd_put_32 (output_bfd
, - (h
->plt
.offset
5490 + abed
->plt
->plt_plt_offset
+ 4),
5491 plt
->contents
+ h
->plt
.offset
5492 + abed
->plt
->plt_plt_offset
);
5496 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5498 bfd_vma got_offset
, plt_offset
;
5499 asection
*plt
, *got
, *gotplt
;
5500 const bfd_byte
*got_plt_entry
;
5502 /* Offset of displacement of the indirect jump. */
5503 bfd_vma plt_got_offset
= 2;
5505 /* Set the entry in the GOT procedure linkage table. */
5506 plt
= htab
->plt_got
;
5507 got
= htab
->elf
.sgot
;
5508 gotplt
= htab
->elf
.sgotplt
;
5509 got_offset
= h
->got
.offset
;
5511 if (got_offset
== (bfd_vma
) -1
5517 /* Fill in the entry in the GOT procedure linkage table. */
5518 if (! bfd_link_pic (info
))
5520 got_plt_entry
= elf_i386_got_plt_entry
;
5521 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
5525 got_plt_entry
= elf_i386_pic_got_plt_entry
;
5526 got_offset
+= (got
->output_section
->vma
5527 + got
->output_offset
5528 - gotplt
->output_section
->vma
5529 - gotplt
->output_offset
);
5532 plt_offset
= eh
->plt_got
.offset
;
5533 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
5534 sizeof (elf_i386_got_plt_entry
));
5535 bfd_put_32 (output_bfd
, got_offset
,
5536 plt
->contents
+ plt_offset
+ plt_got_offset
);
5539 if (!local_undefweak
5541 && (h
->plt
.offset
!= (bfd_vma
) -1
5542 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5544 /* Mark the symbol as undefined, rather than as defined in
5545 the .plt section. Leave the value if there were any
5546 relocations where pointer equality matters (this is a clue
5547 for the dynamic linker, to make function pointer
5548 comparisons work between an application and shared
5549 library), otherwise set it to zero. If a function is only
5550 called from a binary, there is no need to slow down
5551 shared libraries because of that. */
5552 sym
->st_shndx
= SHN_UNDEF
;
5553 if (!h
->pointer_equality_needed
)
5557 /* Don't generate dynamic GOT relocation against undefined weak
5558 symbol in executable. */
5559 if (h
->got
.offset
!= (bfd_vma
) -1
5560 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
5561 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
5562 && !local_undefweak
)
5564 Elf_Internal_Rela rel
;
5565 asection
*relgot
= htab
->elf
.srelgot
;
5567 /* This symbol has an entry in the global offset table. Set it
5570 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5573 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5574 + htab
->elf
.sgot
->output_offset
5575 + (h
->got
.offset
& ~(bfd_vma
) 1));
5577 /* If this is a static link, or it is a -Bsymbolic link and the
5578 symbol is defined locally or was forced to be local because
5579 of a version file, we just want to emit a RELATIVE reloc.
5580 The entry in the global offset table will already have been
5581 initialized in the relocate_section function. */
5583 && h
->type
== STT_GNU_IFUNC
)
5585 if (h
->plt
.offset
== (bfd_vma
) -1)
5587 /* STT_GNU_IFUNC is referenced without PLT. */
5588 if (htab
->elf
.splt
== NULL
)
5590 /* use .rel[a].iplt section to store .got relocations
5591 in static executable. */
5592 relgot
= htab
->elf
.irelplt
;
5594 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5596 bfd_put_32 (output_bfd
,
5597 (h
->root
.u
.def
.value
5598 + h
->root
.u
.def
.section
->output_section
->vma
5599 + h
->root
.u
.def
.section
->output_offset
),
5600 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5601 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5606 else if (bfd_link_pic (info
))
5608 /* Generate R_386_GLOB_DAT. */
5615 if (!h
->pointer_equality_needed
)
5618 /* For non-shared object, we can't use .got.plt, which
5619 contains the real function addres if we need pointer
5620 equality. We load the GOT entry with the PLT entry. */
5621 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5622 bfd_put_32 (output_bfd
,
5623 (plt
->output_section
->vma
5624 + plt
->output_offset
+ h
->plt
.offset
),
5625 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5629 else if (bfd_link_pic (info
)
5630 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5632 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5633 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
5637 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5639 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5640 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5641 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
5644 elf_append_rel (output_bfd
, relgot
, &rel
);
5649 Elf_Internal_Rela rel
;
5652 /* This symbol needs a copy reloc. Set it up. */
5654 if (h
->dynindx
== -1
5655 || (h
->root
.type
!= bfd_link_hash_defined
5656 && h
->root
.type
!= bfd_link_hash_defweak
)
5657 || htab
->elf
.srelbss
== NULL
5658 || htab
->elf
.sreldynrelro
== NULL
)
5661 rel
.r_offset
= (h
->root
.u
.def
.value
5662 + h
->root
.u
.def
.section
->output_section
->vma
5663 + h
->root
.u
.def
.section
->output_offset
);
5664 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5665 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
5666 s
= htab
->elf
.sreldynrelro
;
5668 s
= htab
->elf
.srelbss
;
5669 elf_append_rel (output_bfd
, s
, &rel
);
5675 /* Finish up local dynamic symbol handling. We set the contents of
5676 various dynamic sections here. */
5679 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5681 struct elf_link_hash_entry
*h
5682 = (struct elf_link_hash_entry
*) *slot
;
5683 struct bfd_link_info
*info
5684 = (struct bfd_link_info
*) inf
;
5686 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5690 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5691 here since undefined weak symbol may not be dynamic and may not be
5692 called for elf_i386_finish_dynamic_symbol. */
5695 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5698 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5699 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5701 if (h
->root
.type
!= bfd_link_hash_undefweak
5702 || h
->dynindx
!= -1)
5705 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5709 /* Used to decide how to sort relocs in an optimal manner for the
5710 dynamic linker, before writing them out. */
5712 static enum elf_reloc_type_class
5713 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5714 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5715 const Elf_Internal_Rela
*rela
)
5717 bfd
*abfd
= info
->output_bfd
;
5718 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5719 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5721 if (htab
->dynsym
!= NULL
5722 && htab
->dynsym
->contents
!= NULL
)
5724 /* Check relocation against STT_GNU_IFUNC symbol if there are
5726 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5727 if (r_symndx
!= STN_UNDEF
)
5729 Elf_Internal_Sym sym
;
5730 if (!bed
->s
->swap_symbol_in (abfd
,
5731 (htab
->dynsym
->contents
5732 + r_symndx
* sizeof (Elf32_External_Sym
)),
5736 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5737 return reloc_class_ifunc
;
5741 switch (ELF32_R_TYPE (rela
->r_info
))
5743 case R_386_IRELATIVE
:
5744 return reloc_class_ifunc
;
5745 case R_386_RELATIVE
:
5746 return reloc_class_relative
;
5747 case R_386_JUMP_SLOT
:
5748 return reloc_class_plt
;
5750 return reloc_class_copy
;
5752 return reloc_class_normal
;
5756 /* Finish up the dynamic sections. */
5759 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5760 struct bfd_link_info
*info
)
5762 struct elf_i386_link_hash_table
*htab
;
5765 const struct elf_i386_backend_data
*abed
;
5767 htab
= elf_i386_hash_table (info
);
5771 dynobj
= htab
->elf
.dynobj
;
5772 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5773 abed
= get_elf_i386_backend_data (output_bfd
);
5775 if (htab
->elf
.dynamic_sections_created
)
5777 Elf32_External_Dyn
*dyncon
, *dynconend
;
5779 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5782 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5783 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5784 for (; dyncon
< dynconend
; dyncon
++)
5786 Elf_Internal_Dyn dyn
;
5789 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5794 if (abed
->is_vxworks
5795 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5800 s
= htab
->elf
.sgotplt
;
5801 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5805 s
= htab
->elf
.srelplt
;
5806 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5810 s
= htab
->elf
.srelplt
;
5811 dyn
.d_un
.d_val
= s
->size
;
5815 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5818 /* Fill in the first entry in the procedure linkage table. */
5819 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5821 if (bfd_link_pic (info
))
5823 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->pic_plt0_entry
,
5824 abed
->plt
->plt0_entry_size
);
5825 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5826 abed
->plt0_pad_byte
,
5827 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5831 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->plt0_entry
,
5832 abed
->plt
->plt0_entry_size
);
5833 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5834 abed
->plt0_pad_byte
,
5835 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5836 bfd_put_32 (output_bfd
,
5837 (htab
->elf
.sgotplt
->output_section
->vma
5838 + htab
->elf
.sgotplt
->output_offset
5840 htab
->elf
.splt
->contents
5841 + abed
->plt
->plt0_got1_offset
);
5842 bfd_put_32 (output_bfd
,
5843 (htab
->elf
.sgotplt
->output_section
->vma
5844 + htab
->elf
.sgotplt
->output_offset
5846 htab
->elf
.splt
->contents
5847 + abed
->plt
->plt0_got2_offset
);
5849 if (abed
->is_vxworks
)
5851 Elf_Internal_Rela rel
;
5853 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
5854 On IA32 we use REL relocations so the addend goes in
5855 the PLT directly. */
5856 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5857 + htab
->elf
.splt
->output_offset
5858 + abed
->plt
->plt0_got1_offset
);
5859 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5860 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5861 htab
->srelplt2
->contents
);
5862 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
5863 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5864 + htab
->elf
.splt
->output_offset
5865 + abed
->plt
->plt0_got2_offset
);
5866 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5867 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5868 htab
->srelplt2
->contents
+
5869 sizeof (Elf32_External_Rel
));
5873 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5874 really seem like the right value. */
5875 elf_section_data (htab
->elf
.splt
->output_section
)
5876 ->this_hdr
.sh_entsize
= 4;
5878 /* Correct the .rel.plt.unloaded relocations. */
5879 if (abed
->is_vxworks
&& !bfd_link_pic (info
))
5881 int num_plts
= (htab
->elf
.splt
->size
5882 / abed
->plt
->plt_entry_size
) - 1;
5885 p
= htab
->srelplt2
->contents
;
5886 if (bfd_link_pic (info
))
5887 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
5889 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
5891 for (; num_plts
; num_plts
--)
5893 Elf_Internal_Rela rel
;
5894 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5895 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5896 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5897 p
+= sizeof (Elf32_External_Rel
);
5899 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5900 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5901 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5902 p
+= sizeof (Elf32_External_Rel
);
5908 if (htab
->elf
.sgotplt
)
5910 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5913 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5917 /* Fill in the first three entries in the global offset table. */
5918 if (htab
->elf
.sgotplt
->size
> 0)
5920 bfd_put_32 (output_bfd
,
5922 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
5923 htab
->elf
.sgotplt
->contents
);
5924 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
5925 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
5928 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
5931 /* Adjust .eh_frame for .plt section. */
5932 if (htab
->plt_eh_frame
!= NULL
5933 && htab
->plt_eh_frame
->contents
!= NULL
)
5935 if (htab
->elf
.splt
!= NULL
5936 && htab
->elf
.splt
->size
!= 0
5937 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5938 && htab
->elf
.splt
->output_section
!= NULL
5939 && htab
->plt_eh_frame
->output_section
!= NULL
)
5941 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5942 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5943 + htab
->plt_eh_frame
->output_offset
5944 + PLT_FDE_START_OFFSET
;
5945 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5946 htab
->plt_eh_frame
->contents
5947 + PLT_FDE_START_OFFSET
);
5949 if (htab
->plt_eh_frame
->sec_info_type
5950 == SEC_INFO_TYPE_EH_FRAME
)
5952 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5954 htab
->plt_eh_frame
->contents
))
5959 /* Adjust .eh_frame for .plt.got section. */
5960 if (htab
->plt_got_eh_frame
!= NULL
5961 && htab
->plt_got_eh_frame
->contents
!= NULL
)
5963 if (htab
->plt_got
!= NULL
5964 && htab
->plt_got
->size
!= 0
5965 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
5966 && htab
->plt_got
->output_section
!= NULL
5967 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
5969 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
5970 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
5971 + htab
->plt_got_eh_frame
->output_offset
5972 + PLT_FDE_START_OFFSET
;
5973 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5974 htab
->plt_got_eh_frame
->contents
5975 + PLT_FDE_START_OFFSET
);
5977 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5979 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5980 htab
->plt_got_eh_frame
,
5981 htab
->plt_got_eh_frame
->contents
))
5986 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5987 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5989 /* Fill PLT entries for undefined weak symbols in PIE. */
5990 if (bfd_link_pie (info
))
5991 bfd_hash_traverse (&info
->hash
->table
,
5992 elf_i386_pie_finish_undefweak_symbol
,
5998 /* Fill PLT/GOT entries and allocate dynamic relocations for local
5999 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6000 It has to be done before elf_link_sort_relocs is called so that
6001 dynamic relocations are properly sorted. */
6004 elf_i386_output_arch_local_syms
6005 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6006 struct bfd_link_info
*info
,
6007 void *flaginfo ATTRIBUTE_UNUSED
,
6008 int (*func
) (void *, const char *,
6011 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6013 struct elf_i386_link_hash_table
*htab
= elf_i386_hash_table (info
);
6017 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6018 htab_traverse (htab
->loc_hash_table
,
6019 elf_i386_finish_local_dynamic_symbol
,
6025 /* Return an array of PLT entry symbol values. */
6028 elf_i386_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
6031 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
6034 bfd_vma
*plt_sym_val
;
6036 bfd_byte
*plt_contents
;
6037 const struct elf_i386_backend_data
*bed
6038 = get_elf_i386_backend_data (abfd
);
6039 Elf_Internal_Shdr
*hdr
;
6041 /* Get the .plt section contents. */
6042 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6043 if (plt_contents
== NULL
)
6045 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6046 plt_contents
, 0, plt
->size
))
6049 free (plt_contents
);
6053 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
6054 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
6057 hdr
= &elf_section_data (relplt
)->this_hdr
;
6058 count
= relplt
->size
/ hdr
->sh_entsize
;
6060 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
6061 if (plt_sym_val
== NULL
)
6064 for (i
= 0; i
< count
; i
++)
6065 plt_sym_val
[i
] = -1;
6067 plt_offset
= bed
->plt
->plt_entry_size
;
6068 p
= relplt
->relocation
;
6069 for (i
= 0; i
< count
; i
++, p
++)
6073 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6074 if (p
->howto
== NULL
)
6077 if (p
->howto
->type
!= R_386_JUMP_SLOT
6078 && p
->howto
->type
!= R_386_IRELATIVE
)
6081 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
6082 + bed
->plt
->plt_reloc_offset
));
6083 reloc_index
/= sizeof (Elf32_External_Rel
);
6084 if (reloc_index
< count
)
6085 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
6087 plt_offset
+= bed
->plt
->plt_entry_size
;
6089 /* PR binutils/18437: Skip extra relocations in the .rel.plt
6091 if (plt_offset
>= plt
->size
)
6095 free (plt_contents
);
6100 /* Similar to _bfd_elf_get_synthetic_symtab. */
6103 elf_i386_get_synthetic_symtab (bfd
*abfd
,
6110 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt");
6111 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
6112 dynsymcount
, dynsyms
, ret
,
6114 elf_i386_get_plt_sym_val
);
6117 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6120 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
6122 if (h
->plt
.offset
!= (bfd_vma
) -1
6124 && !h
->pointer_equality_needed
)
6127 return _bfd_elf_hash_symbol (h
);
6130 #define TARGET_LITTLE_SYM i386_elf32_vec
6131 #define TARGET_LITTLE_NAME "elf32-i386"
6132 #define ELF_ARCH bfd_arch_i386
6133 #define ELF_TARGET_ID I386_ELF_DATA
6134 #define ELF_MACHINE_CODE EM_386
6135 #define ELF_MAXPAGESIZE 0x1000
6137 #define elf_backend_can_gc_sections 1
6138 #define elf_backend_can_refcount 1
6139 #define elf_backend_want_got_plt 1
6140 #define elf_backend_plt_readonly 1
6141 #define elf_backend_want_plt_sym 0
6142 #define elf_backend_got_header_size 12
6143 #define elf_backend_plt_alignment 4
6144 #define elf_backend_dtrel_excludes_plt 1
6145 #define elf_backend_extern_protected_data 1
6146 #define elf_backend_caches_rawsize 1
6147 #define elf_backend_want_dynrelro 1
6149 /* Support RELA for objdump of prelink objects. */
6150 #define elf_info_to_howto elf_i386_info_to_howto_rel
6151 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
6153 #define bfd_elf32_mkobject elf_i386_mkobject
6155 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
6156 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
6157 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
6158 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
6159 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
6161 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
6162 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
6163 #define elf_backend_check_relocs elf_i386_check_relocs
6164 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
6165 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
6166 #define elf_backend_fake_sections elf_i386_fake_sections
6167 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
6168 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
6169 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
6170 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
6171 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
6172 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
6173 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
6174 #define elf_backend_relocate_section elf_i386_relocate_section
6175 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
6176 #define elf_backend_always_size_sections elf_i386_always_size_sections
6177 #define elf_backend_omit_section_dynsym \
6178 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
6179 #define elf_backend_hash_symbol elf_i386_hash_symbol
6180 #define elf_backend_fixup_symbol elf_i386_fixup_symbol
6182 #include "elf32-target.h"
6184 /* FreeBSD support. */
6186 #undef TARGET_LITTLE_SYM
6187 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
6188 #undef TARGET_LITTLE_NAME
6189 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
6191 #define ELF_OSABI ELFOSABI_FREEBSD
6193 /* The kernel recognizes executables as valid only if they carry a
6194 "FreeBSD" label in the ELF header. So we put this label on all
6195 executables and (for simplicity) also all other object files. */
6198 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
6200 _bfd_elf_post_process_headers (abfd
, info
);
6202 #ifdef OLD_FREEBSD_ABI_LABEL
6204 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
6205 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
6206 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
6211 #undef elf_backend_post_process_headers
6212 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
6214 #define elf32_bed elf32_i386_fbsd_bed
6216 #undef elf_backend_add_symbol_hook
6218 #include "elf32-target.h"
6222 #undef TARGET_LITTLE_SYM
6223 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
6224 #undef TARGET_LITTLE_NAME
6225 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
6227 #undef elf_backend_post_process_headers
6229 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
6230 objects won't be recognized. */
6234 #define elf32_bed elf32_i386_sol2_bed
6236 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
6238 #undef elf_backend_static_tls_alignment
6239 #define elf_backend_static_tls_alignment 8
6241 /* The Solaris 2 ABI requires a plt symbol on all platforms.
6243 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
6245 #undef elf_backend_want_plt_sym
6246 #define elf_backend_want_plt_sym 1
6248 #undef elf_backend_strtab_flags
6249 #define elf_backend_strtab_flags SHF_STRINGS
6251 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
6252 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
6253 FALSE otherwise. ISECTION is the best guess matching section from the
6254 input bfd IBFD, but it might be NULL. */
6257 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
6258 bfd
*obfd ATTRIBUTE_UNUSED
,
6259 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
6260 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
6262 /* PR 19938: FIXME: Need to add code for setting the sh_info
6263 and sh_link fields of Solaris specific section types. */
6266 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
6267 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
6269 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
6271 The following values should be set:
6274 -----------------------------------------------------------------------------
6275 SHT_SUNW_ancillary The section header index of 0
6276 [0x6fffffee] the associated string table.
6278 SHT_SUNW_capinfo The section header index of For a dynamic object, the
6279 [0x6ffffff0] the associated symbol table. section header index of
6281 SHT_SUNW_capchain table,
6284 SHT_SUNW_symsort The section header index of 0
6285 [0x6ffffff1] the associated symbol table.
6287 SHT_SUNW_tlssort The section header index of 0
6288 [0x6ffffff2] the associated symbol table.
6290 SHT_SUNW_LDYNSYM The section header index of One greater than the
6291 [0x6ffffff3] the associated string table. symbol table index of the
6292 This index is the same string last local symbol,
6293 table used by the SHT_DYNSYM STB_LOCAL. Since
6294 section. SHT_SUNW_LDYNSYM only
6295 contains local symbols,
6296 sh_info is equivalent to
6297 the number of symbols in
6300 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
6301 [0x6ffffff5] the section header index of to named strings, the
6302 the associated section header index of
6303 SHT_SUNW_capinfo table, the associated string
6304 otherwise 0. table, otherwise 0.
6306 SHT_SUNW_move The section header index of 0
6307 [0x6ffffffa] the associated symbol table.
6312 SHT_SUNW_syminfo The section header index of The section header index
6313 [0x6ffffffc] the associated symbol table. of the associated
6316 SHT_SUNW_verdef The section header index of The number of version
6317 [0x6ffffffd] the associated string table. definitions within the
6320 SHT_SUNW_verneed The section header index of The number of version
6321 [0x6ffffffe] the associated string table. dependencies within the
6324 SHT_SUNW_versym The section header index of 0
6325 [0x6fffffff] the associated symbol table. */
6328 #undef elf_backend_copy_special_section_fields
6329 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
6331 #include "elf32-target.h"
6333 /* Intel MCU support. */
6336 elf32_iamcu_elf_object_p (bfd
*abfd
)
6338 /* Set the right machine number for an IAMCU elf32 file. */
6339 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
6343 #undef TARGET_LITTLE_SYM
6344 #define TARGET_LITTLE_SYM iamcu_elf32_vec
6345 #undef TARGET_LITTLE_NAME
6346 #define TARGET_LITTLE_NAME "elf32-iamcu"
6348 #define ELF_ARCH bfd_arch_iamcu
6350 #undef ELF_MACHINE_CODE
6351 #define ELF_MACHINE_CODE EM_IAMCU
6356 #define elf32_bed elf32_iamcu_bed
6358 #undef elf_backend_object_p
6359 #define elf_backend_object_p elf32_iamcu_elf_object_p
6361 #undef elf_backend_static_tls_alignment
6363 #undef elf_backend_want_plt_sym
6364 #define elf_backend_want_plt_sym 0
6366 #undef elf_backend_strtab_flags
6367 #undef elf_backend_copy_special_section_fields
6369 #include "elf32-target.h"
6371 /* Restore defaults. */
6373 #define ELF_ARCH bfd_arch_i386
6374 #undef ELF_MACHINE_CODE
6375 #define ELF_MACHINE_CODE EM_386
6377 /* Native Client support. */
6379 #undef TARGET_LITTLE_SYM
6380 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
6381 #undef TARGET_LITTLE_NAME
6382 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
6384 #define elf32_bed elf32_i386_nacl_bed
6386 #undef ELF_MAXPAGESIZE
6387 #define ELF_MAXPAGESIZE 0x10000
6389 /* Restore defaults. */
6391 #undef elf_backend_want_plt_sym
6392 #define elf_backend_want_plt_sym 0
6393 #undef elf_backend_post_process_headers
6394 #undef elf_backend_static_tls_alignment
6396 /* NaCl uses substantially different PLT entries for the same effects. */
6398 #undef elf_backend_plt_alignment
6399 #define elf_backend_plt_alignment 5
6400 #define NACL_PLT_ENTRY_SIZE 64
6401 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
6403 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
6405 0xff, 0x35, /* pushl contents of address */
6406 0, 0, 0, 0, /* replaced with address of .got + 4. */
6407 0x8b, 0x0d, /* movl contents of address, %ecx */
6408 0, 0, 0, 0, /* replaced with address of .got + 8. */
6409 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6410 0xff, 0xe1 /* jmp *%ecx */
6413 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6415 0x8b, 0x0d, /* movl contents of address, %ecx */
6416 0, 0, 0, 0, /* replaced with GOT slot address. */
6417 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6418 0xff, 0xe1, /* jmp *%ecx */
6420 /* Pad to the next 32-byte boundary with nop instructions. */
6422 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6423 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6425 /* Lazy GOT entries point here (32-byte aligned). */
6426 0x68, /* pushl immediate */
6427 0, 0, 0, 0, /* replaced with reloc offset. */
6428 0xe9, /* jmp relative */
6429 0, 0, 0, 0, /* replaced with offset to .plt. */
6431 /* Pad to the next 32-byte boundary with nop instructions. */
6432 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6433 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6437 static const bfd_byte
6438 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
6440 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
6441 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
6442 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
6443 0xff, 0xe1, /* jmp *%ecx */
6445 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
6446 so pad to that size with nop instructions. */
6447 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
6450 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6452 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
6453 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
6454 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
6455 0xff, 0xe1, /* jmp *%ecx */
6457 /* Pad to the next 32-byte boundary with nop instructions. */
6459 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6460 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6462 /* Lazy GOT entries point here (32-byte aligned). */
6463 0x68, /* pushl immediate */
6464 0, 0, 0, 0, /* replaced with offset into relocation table. */
6465 0xe9, /* jmp relative */
6466 0, 0, 0, 0, /* replaced with offset to start of .plt. */
6468 /* Pad to the next 32-byte boundary with nop instructions. */
6469 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6470 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6474 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
6476 #if (PLT_CIE_LENGTH != 20 \
6477 || PLT_FDE_LENGTH != 36 \
6478 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
6479 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
6480 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
6482 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
6483 0, 0, 0, 0, /* CIE ID */
6484 1, /* CIE version */
6485 'z', 'R', 0, /* Augmentation string */
6486 1, /* Code alignment factor */
6487 0x7c, /* Data alignment factor: -4 */
6488 8, /* Return address column */
6489 1, /* Augmentation size */
6490 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
6491 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
6492 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
6493 DW_CFA_nop
, DW_CFA_nop
,
6495 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
6496 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
6497 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
6498 0, 0, 0, 0, /* .plt size goes here */
6499 0, /* Augmentation size */
6500 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
6501 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
6502 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
6503 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
6504 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
6505 13, /* Block length */
6506 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
6507 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
6508 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
6509 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
6510 DW_CFA_nop
, DW_CFA_nop
6513 static const struct elf_i386_plt_layout elf_i386_nacl_plt
=
6515 elf_i386_nacl_plt0_entry
, /* plt0_entry */
6516 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
6517 2, /* plt0_got1_offset */
6518 8, /* plt0_got2_offset */
6519 elf_i386_nacl_plt_entry
, /* plt_entry */
6520 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
6521 2, /* plt_got_offset */
6522 33, /* plt_reloc_offset */
6523 38, /* plt_plt_offset */
6524 32, /* plt_lazy_offset */
6525 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
6526 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
6527 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
6528 sizeof (elf_i386_nacl_eh_frame_plt
),/* eh_frame_plt_size */
6529 NULL
, /* eh_frame_plt_got */
6530 0, /* eh_frame_plt_got_size */
6533 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
6535 &elf_i386_nacl_plt
, /* plt */
6536 0x90, /* plt0_pad_byte: nop insn */
6541 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
6543 /* Set the right machine number for a NaCl i386 ELF32 file. */
6544 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
6548 #undef elf_backend_arch_data
6549 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
6551 #undef elf_backend_object_p
6552 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
6553 #undef elf_backend_modify_segment_map
6554 #define elf_backend_modify_segment_map nacl_modify_segment_map
6555 #undef elf_backend_modify_program_headers
6556 #define elf_backend_modify_program_headers nacl_modify_program_headers
6557 #undef elf_backend_final_write_processing
6558 #define elf_backend_final_write_processing nacl_final_write_processing
6560 #include "elf32-target.h"
6562 /* Restore defaults. */
6563 #undef elf_backend_object_p
6564 #undef elf_backend_modify_segment_map
6565 #undef elf_backend_modify_program_headers
6566 #undef elf_backend_final_write_processing
6568 /* VxWorks support. */
6570 #undef TARGET_LITTLE_SYM
6571 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
6572 #undef TARGET_LITTLE_NAME
6573 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
6575 #undef elf_backend_plt_alignment
6576 #define elf_backend_plt_alignment 4
6578 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
6580 &elf_i386_plt
, /* plt */
6581 0x90, /* plt0_pad_byte */
6585 #undef elf_backend_arch_data
6586 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
6588 #undef elf_backend_relocs_compatible
6589 #undef elf_backend_add_symbol_hook
6590 #define elf_backend_add_symbol_hook \
6591 elf_vxworks_add_symbol_hook
6592 #undef elf_backend_link_output_symbol_hook
6593 #define elf_backend_link_output_symbol_hook \
6594 elf_vxworks_link_output_symbol_hook
6595 #undef elf_backend_emit_relocs
6596 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
6597 #undef elf_backend_final_write_processing
6598 #define elf_backend_final_write_processing \
6599 elf_vxworks_final_write_processing
6600 #undef elf_backend_static_tls_alignment
6602 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
6604 #undef elf_backend_want_plt_sym
6605 #define elf_backend_want_plt_sym 1
6608 #define elf32_bed elf32_i386_vxworks_bed
6610 #include "elf32-target.h"