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 /* Don't call finish_dynamic_symbol on this symbol. */
824 unsigned int no_finish_dynamic_symbol
: 1;
826 /* 0: symbol isn't ___tls_get_addr.
827 1: symbol is ___tls_get_addr.
828 2: symbol is unknown. */
829 unsigned int tls_get_addr
: 2;
831 /* Reference count of C/C++ function pointer relocations in read-write
832 section which can be resolved at run-time. */
833 bfd_signed_vma func_pointer_refcount
;
835 /* Information about the GOT PLT entry. Filled when there are both
836 GOT and PLT relocations against the same function. */
837 union gotplt_union plt_got
;
839 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
840 starting at the end of the jump table. */
844 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
846 struct elf_i386_obj_tdata
848 struct elf_obj_tdata root
;
850 /* tls_type for each local got entry. */
851 char *local_got_tls_type
;
853 /* GOTPLT entries for TLS descriptors. */
854 bfd_vma
*local_tlsdesc_gotent
;
857 #define elf_i386_tdata(abfd) \
858 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
860 #define elf_i386_local_got_tls_type(abfd) \
861 (elf_i386_tdata (abfd)->local_got_tls_type)
863 #define elf_i386_local_tlsdesc_gotent(abfd) \
864 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
866 #define is_i386_elf(bfd) \
867 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
868 && elf_tdata (bfd) != NULL \
869 && elf_object_id (bfd) == I386_ELF_DATA)
872 elf_i386_mkobject (bfd
*abfd
)
874 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
878 /* i386 ELF linker hash table. */
880 struct elf_i386_link_hash_table
882 struct elf_link_hash_table elf
;
884 /* Short-cuts to get to dynamic linker sections. */
886 asection
*plt_eh_frame
;
888 asection
*plt_got_eh_frame
;
892 bfd_signed_vma refcount
;
896 /* The amount of space used by the reserved portion of the sgotplt
897 section, plus whatever space is used by the jump slots. */
898 bfd_vma sgotplt_jump_table_size
;
900 /* Small local sym cache. */
901 struct sym_cache sym_cache
;
903 /* _TLS_MODULE_BASE_ symbol. */
904 struct bfd_link_hash_entry
*tls_module_base
;
906 /* Used by local STT_GNU_IFUNC symbols. */
907 htab_t loc_hash_table
;
908 void * loc_hash_memory
;
910 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
913 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
914 bfd_vma next_tls_desc_index
;
916 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
917 bfd_vma next_jump_slot_index
;
919 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
920 bfd_vma next_irelative_index
;
922 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
923 to read-only sections. */
924 bfd_boolean readonly_dynrelocs_against_ifunc
;
927 /* Get the i386 ELF linker hash table from a link_info structure. */
929 #define elf_i386_hash_table(p) \
930 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
931 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
933 #define elf_i386_compute_jump_table_size(htab) \
934 ((htab)->elf.srelplt->reloc_count * 4)
936 /* Create an entry in an i386 ELF linker hash table. */
938 static struct bfd_hash_entry
*
939 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
940 struct bfd_hash_table
*table
,
943 /* Allocate the structure if it has not already been allocated by a
947 entry
= (struct bfd_hash_entry
*)
948 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
953 /* Call the allocation method of the superclass. */
954 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
957 struct elf_i386_link_hash_entry
*eh
;
959 eh
= (struct elf_i386_link_hash_entry
*) entry
;
960 eh
->dyn_relocs
= NULL
;
961 eh
->tls_type
= GOT_UNKNOWN
;
963 eh
->has_got_reloc
= 0;
964 eh
->has_non_got_reloc
= 0;
965 eh
->no_finish_dynamic_symbol
= 0;
966 eh
->tls_get_addr
= 2;
967 eh
->func_pointer_refcount
= 0;
968 eh
->plt_got
.offset
= (bfd_vma
) -1;
969 eh
->tlsdesc_got
= (bfd_vma
) -1;
975 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
976 for local symbol so that we can handle local STT_GNU_IFUNC symbols
977 as global symbol. We reuse indx and dynstr_index for local symbol
978 hash since they aren't used by global symbols in this backend. */
981 elf_i386_local_htab_hash (const void *ptr
)
983 struct elf_link_hash_entry
*h
984 = (struct elf_link_hash_entry
*) ptr
;
985 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
988 /* Compare local hash entries. */
991 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
993 struct elf_link_hash_entry
*h1
994 = (struct elf_link_hash_entry
*) ptr1
;
995 struct elf_link_hash_entry
*h2
996 = (struct elf_link_hash_entry
*) ptr2
;
998 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1001 /* Find and/or create a hash entry for local symbol. */
1003 static struct elf_link_hash_entry
*
1004 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
1005 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1008 struct elf_i386_link_hash_entry e
, *ret
;
1009 asection
*sec
= abfd
->sections
;
1010 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1011 ELF32_R_SYM (rel
->r_info
));
1014 e
.elf
.indx
= sec
->id
;
1015 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1016 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1017 create
? INSERT
: NO_INSERT
);
1024 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
1028 ret
= (struct elf_i386_link_hash_entry
*)
1029 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1030 sizeof (struct elf_i386_link_hash_entry
));
1033 memset (ret
, 0, sizeof (*ret
));
1034 ret
->elf
.indx
= sec
->id
;
1035 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
1036 ret
->elf
.dynindx
= -1;
1037 ret
->func_pointer_refcount
= 0;
1038 ret
->plt_got
.offset
= (bfd_vma
) -1;
1044 /* Destroy an i386 ELF linker hash table. */
1047 elf_i386_link_hash_table_free (bfd
*obfd
)
1049 struct elf_i386_link_hash_table
*htab
1050 = (struct elf_i386_link_hash_table
*) obfd
->link
.hash
;
1052 if (htab
->loc_hash_table
)
1053 htab_delete (htab
->loc_hash_table
);
1054 if (htab
->loc_hash_memory
)
1055 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1056 _bfd_elf_link_hash_table_free (obfd
);
1059 /* Create an i386 ELF linker hash table. */
1061 static struct bfd_link_hash_table
*
1062 elf_i386_link_hash_table_create (bfd
*abfd
)
1064 struct elf_i386_link_hash_table
*ret
;
1065 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
1067 ret
= (struct elf_i386_link_hash_table
*) bfd_zmalloc (amt
);
1071 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1072 elf_i386_link_hash_newfunc
,
1073 sizeof (struct elf_i386_link_hash_entry
),
1080 ret
->loc_hash_table
= htab_try_create (1024,
1081 elf_i386_local_htab_hash
,
1082 elf_i386_local_htab_eq
,
1084 ret
->loc_hash_memory
= objalloc_create ();
1085 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1087 elf_i386_link_hash_table_free (abfd
);
1090 ret
->elf
.root
.hash_table_free
= elf_i386_link_hash_table_free
;
1092 return &ret
->elf
.root
;
1095 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1096 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1100 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1102 struct elf_i386_link_hash_table
*htab
;
1104 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1107 htab
= elf_i386_hash_table (info
);
1111 /* Set the contents of the .interp section to the interpreter. */
1112 if (bfd_link_executable (info
) && !info
->nointerp
)
1114 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
1117 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1118 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1122 if (get_elf_i386_backend_data (dynobj
)->is_vxworks
1123 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
1127 if (!info
->no_ld_generated_unwind_info
1128 && htab
->plt_eh_frame
== NULL
1129 && htab
->elf
.splt
!= NULL
)
1131 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1132 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1133 | SEC_LINKER_CREATED
);
1135 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1136 if (htab
->plt_eh_frame
== NULL
1137 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 2))
1144 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1147 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1148 struct elf_link_hash_entry
*dir
,
1149 struct elf_link_hash_entry
*ind
)
1151 struct elf_i386_link_hash_entry
*edir
, *eind
;
1153 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1154 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1156 if (eind
->dyn_relocs
!= NULL
)
1158 if (edir
->dyn_relocs
!= NULL
)
1160 struct elf_dyn_relocs
**pp
;
1161 struct elf_dyn_relocs
*p
;
1163 /* Add reloc counts against the indirect sym to the direct sym
1164 list. Merge any entries against the same section. */
1165 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1167 struct elf_dyn_relocs
*q
;
1169 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1170 if (q
->sec
== p
->sec
)
1172 q
->pc_count
+= p
->pc_count
;
1173 q
->count
+= p
->count
;
1180 *pp
= edir
->dyn_relocs
;
1183 edir
->dyn_relocs
= eind
->dyn_relocs
;
1184 eind
->dyn_relocs
= NULL
;
1187 if (ind
->root
.type
== bfd_link_hash_indirect
1188 && dir
->got
.refcount
<= 0)
1190 edir
->tls_type
= eind
->tls_type
;
1191 eind
->tls_type
= GOT_UNKNOWN
;
1194 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1195 generate a R_386_COPY reloc. */
1196 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1198 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1199 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1201 if (ELIMINATE_COPY_RELOCS
1202 && ind
->root
.type
!= bfd_link_hash_indirect
1203 && dir
->dynamic_adjusted
)
1205 /* If called to transfer flags for a weakdef during processing
1206 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1207 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1208 if (dir
->versioned
!= versioned_hidden
)
1209 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1210 dir
->ref_regular
|= ind
->ref_regular
;
1211 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1212 dir
->needs_plt
|= ind
->needs_plt
;
1213 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1217 if (eind
->func_pointer_refcount
> 0)
1219 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1220 eind
->func_pointer_refcount
= 0;
1223 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1227 /* Return TRUE if the TLS access code sequence support transition
1231 elf_i386_check_tls_transition (asection
*sec
,
1233 Elf_Internal_Shdr
*symtab_hdr
,
1234 struct elf_link_hash_entry
**sym_hashes
,
1235 unsigned int r_type
,
1236 const Elf_Internal_Rela
*rel
,
1237 const Elf_Internal_Rela
*relend
)
1239 unsigned int val
, type
, reg
;
1240 unsigned long r_symndx
;
1241 struct elf_link_hash_entry
*h
;
1244 bfd_boolean indirect_call
, tls_get_addr
;
1246 offset
= rel
->r_offset
;
1251 if (offset
< 2 || (rel
+ 1) >= relend
)
1254 indirect_call
= FALSE
;
1255 call
= contents
+ offset
+ 4;
1258 if (r_type
== R_386_TLS_GD
)
1260 /* Check transition from GD access model. Only
1261 leal foo@tlsgd(,%ebx,1), %eax
1262 call ___tls_get_addr@PLT
1264 leal foo@tlsgd(%ebx) %eax
1265 call ___tls_get_addr@PLT
1268 leal foo@tlsgd(%reg), %eax
1269 call *___tls_get_addr@GOT(%reg)
1270 which may be converted to
1271 addr32 call ___tls_get_addr
1272 can transit to different access model. */
1273 if ((offset
+ 10) > sec
->size
1274 || (type
!= 0x8d && type
!= 0x04))
1279 /* leal foo@tlsgd(,%ebx,1), %eax
1280 call ___tls_get_addr@PLT */
1284 if (*(call
- 7) != 0x8d
1292 leal foo@tlsgd(%ebx), %eax
1293 call ___tls_get_addr@PLT
1296 leal foo@tlsgd(%reg), %eax
1297 call *___tls_get_addr@GOT(%reg)
1298 which may be converted to
1299 addr32 call ___tls_get_addr
1301 %eax can't be used as the GOT base register since it
1302 is used to pass parameter to ___tls_get_addr. */
1304 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1307 indirect_call
= call
[0] == 0xff;
1308 if (!(reg
== 3 && call
[0] == 0xe8 && call
[5] == 0x90)
1309 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1311 && (call
[1] & 0xf8) == 0x90
1312 && (call
[1] & 0x7) == reg
))
1318 /* Check transition from LD access model. Only
1319 leal foo@tlsldm(%ebx), %eax
1320 call ___tls_get_addr@PLT
1322 leal foo@tlsldm(%reg), %eax
1323 call *___tls_get_addr@GOT(%reg)
1324 which may be converted to
1325 addr32 call ___tls_get_addr
1326 can transit to different access model. */
1327 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1330 /* %eax can't be used as the GOT base register since it is
1331 used to pass parameter to ___tls_get_addr. */
1333 if ((val
& 0xf8) != 0x80 || reg
== 4 || reg
== 0)
1336 indirect_call
= call
[0] == 0xff;
1337 if (!(reg
== 3 && call
[0] == 0xe8)
1338 && !(call
[0] == 0x67 && call
[1] == 0xe8)
1340 && (call
[1] & 0xf8) == 0x90
1341 && (call
[1] & 0x7) == reg
))
1345 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1346 if (r_symndx
< symtab_hdr
->sh_info
)
1349 tls_get_addr
= FALSE
;
1350 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1351 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1353 struct elf_i386_link_hash_entry
*eh
1354 = (struct elf_i386_link_hash_entry
*) h
;
1355 tls_get_addr
= eh
->tls_get_addr
== 1;
1356 if (eh
->tls_get_addr
> 1)
1358 /* Use strncmp to check ___tls_get_addr since
1359 ___tls_get_addr may be versioned. */
1360 if (strncmp (h
->root
.root
.string
, "___tls_get_addr", 15)
1363 eh
->tls_get_addr
= 1;
1364 tls_get_addr
= TRUE
;
1367 eh
->tls_get_addr
= 0;
1373 else if (indirect_call
)
1374 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_GOT32X
);
1376 return (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1377 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
1380 /* Check transition from IE access model:
1381 movl foo@indntpoff(%rip), %eax
1382 movl foo@indntpoff(%rip), %reg
1383 addl foo@indntpoff(%rip), %reg
1386 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1389 /* Check "movl foo@tpoff(%rip), %eax" first. */
1390 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1397 /* Check movl|addl foo@tpoff(%rip), %reg. */
1398 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1399 return ((type
== 0x8b || type
== 0x03)
1400 && (val
& 0xc7) == 0x05);
1402 case R_386_TLS_GOTIE
:
1403 case R_386_TLS_IE_32
:
1404 /* Check transition from {IE_32,GOTIE} access model:
1405 subl foo@{tpoff,gontoff}(%reg1), %reg2
1406 movl foo@{tpoff,gontoff}(%reg1), %reg2
1407 addl foo@{tpoff,gontoff}(%reg1), %reg2
1410 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1413 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1414 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1417 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1418 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1420 case R_386_TLS_GOTDESC
:
1421 /* Check transition from GDesc access model:
1422 leal x@tlsdesc(%ebx), %eax
1424 Make sure it's a leal adding ebx to a 32-bit offset
1425 into any register, although it's probably almost always
1428 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1431 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1434 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1435 return (val
& 0xc7) == 0x83;
1437 case R_386_TLS_DESC_CALL
:
1438 /* Check transition from GDesc access model:
1439 call *x@tlsdesc(%eax)
1441 if (offset
+ 2 <= sec
->size
)
1443 /* Make sure that it's a call *x@tlsdesc(%eax). */
1444 call
= contents
+ offset
;
1445 return call
[0] == 0xff && call
[1] == 0x10;
1455 /* Return TRUE if the TLS access transition is OK or no transition
1456 will be performed. Update R_TYPE if there is a transition. */
1459 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1460 asection
*sec
, bfd_byte
*contents
,
1461 Elf_Internal_Shdr
*symtab_hdr
,
1462 struct elf_link_hash_entry
**sym_hashes
,
1463 unsigned int *r_type
, int tls_type
,
1464 const Elf_Internal_Rela
*rel
,
1465 const Elf_Internal_Rela
*relend
,
1466 struct elf_link_hash_entry
*h
,
1467 unsigned long r_symndx
,
1468 bfd_boolean from_relocate_section
)
1470 unsigned int from_type
= *r_type
;
1471 unsigned int to_type
= from_type
;
1472 bfd_boolean check
= TRUE
;
1474 /* Skip TLS transition for functions. */
1476 && (h
->type
== STT_FUNC
1477 || h
->type
== STT_GNU_IFUNC
))
1483 case R_386_TLS_GOTDESC
:
1484 case R_386_TLS_DESC_CALL
:
1485 case R_386_TLS_IE_32
:
1487 case R_386_TLS_GOTIE
:
1488 if (bfd_link_executable (info
))
1491 to_type
= R_386_TLS_LE_32
;
1492 else if (from_type
!= R_386_TLS_IE
1493 && from_type
!= R_386_TLS_GOTIE
)
1494 to_type
= R_386_TLS_IE_32
;
1497 /* When we are called from elf_i386_relocate_section, there may
1498 be additional transitions based on TLS_TYPE. */
1499 if (from_relocate_section
)
1501 unsigned int new_to_type
= to_type
;
1503 if (bfd_link_executable (info
)
1506 && (tls_type
& GOT_TLS_IE
))
1507 new_to_type
= R_386_TLS_LE_32
;
1509 if (to_type
== R_386_TLS_GD
1510 || to_type
== R_386_TLS_GOTDESC
1511 || to_type
== R_386_TLS_DESC_CALL
)
1513 if (tls_type
== GOT_TLS_IE_POS
)
1514 new_to_type
= R_386_TLS_GOTIE
;
1515 else if (tls_type
& GOT_TLS_IE
)
1516 new_to_type
= R_386_TLS_IE_32
;
1519 /* We checked the transition before when we were called from
1520 elf_i386_check_relocs. We only want to check the new
1521 transition which hasn't been checked before. */
1522 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1523 to_type
= new_to_type
;
1529 if (bfd_link_executable (info
))
1530 to_type
= R_386_TLS_LE_32
;
1537 /* Return TRUE if there is no transition. */
1538 if (from_type
== to_type
)
1541 /* Check if the transition can be performed. */
1543 && ! elf_i386_check_tls_transition (sec
, contents
,
1544 symtab_hdr
, sym_hashes
,
1545 from_type
, rel
, relend
))
1547 reloc_howto_type
*from
, *to
;
1550 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1551 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1554 name
= h
->root
.root
.string
;
1557 struct elf_i386_link_hash_table
*htab
;
1559 htab
= elf_i386_hash_table (info
);
1564 Elf_Internal_Sym
*isym
;
1566 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1568 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1573 /* xgettext:c-format */
1574 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1575 "in section `%A' failed"),
1576 abfd
, from
->name
, to
->name
, name
,
1577 (unsigned long) rel
->r_offset
, sec
);
1578 bfd_set_error (bfd_error_bad_value
);
1586 /* With the local symbol, foo, we convert
1587 mov foo@GOT[(%reg1)], %reg2
1589 lea foo[@GOTOFF(%reg1)], %reg2
1591 call/jmp *foo@GOT[(%reg)]
1593 nop call foo/jmp foo nop
1594 When PIC is false, convert
1595 test %reg1, foo@GOT[(%reg2)]
1599 binop foo@GOT[(%reg1)], %reg2
1602 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1607 elf_i386_convert_load_reloc (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
1609 Elf_Internal_Rela
*irel
,
1610 struct elf_link_hash_entry
*h
,
1611 bfd_boolean
*converted
,
1612 struct bfd_link_info
*link_info
)
1614 struct elf_i386_link_hash_table
*htab
;
1615 unsigned int opcode
;
1617 bfd_boolean baseless
;
1618 Elf_Internal_Sym
*isym
;
1619 unsigned int addend
;
1623 bfd_boolean to_reloc_32
;
1624 unsigned int r_type
;
1625 unsigned int r_symndx
;
1626 bfd_vma roff
= irel
->r_offset
;
1631 /* Addend for R_386_GOT32X relocations must be 0. */
1632 addend
= bfd_get_32 (abfd
, contents
+ roff
);
1636 htab
= elf_i386_hash_table (link_info
);
1637 is_pic
= bfd_link_pic (link_info
);
1639 r_type
= ELF32_R_TYPE (irel
->r_info
);
1640 r_symndx
= ELF32_R_SYM (irel
->r_info
);
1642 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1643 baseless
= (modrm
& 0xc7) == 0x5;
1645 if (baseless
&& is_pic
)
1647 /* For PIC, disallow R_386_GOT32X without a base register
1648 since we don't know what the GOT base is. */
1653 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
,
1655 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1658 name
= h
->root
.root
.string
;
1661 /* xgettext:c-format */
1662 (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base"
1663 " register can not be used when making a shared object"),
1668 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1670 /* Convert to R_386_32 if PIC is false or there is no base
1672 to_reloc_32
= !is_pic
|| baseless
;
1674 /* Try to convert R_386_GOT32X. Get the symbol referred to by the
1678 if (opcode
== 0x0ff)
1679 /* Convert "call/jmp *foo@GOT[(%reg)]". */
1680 goto convert_branch
;
1682 /* Convert "mov foo@GOT[(%reg1)], %reg2",
1683 "test %reg1, foo@GOT(%reg2)" and
1684 "binop foo@GOT[(%reg1)], %reg2". */
1688 /* Undefined weak symbol is only bound locally in executable
1689 and its reference is resolved as 0. */
1690 if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
, TRUE
,
1691 elf_i386_hash_entry (h
)))
1695 /* No direct branch to 0 for PIC. */
1699 goto convert_branch
;
1703 /* We can convert load of address 0 to R_386_32. */
1711 /* We have "call/jmp *foo@GOT[(%reg)]". */
1712 if ((h
->root
.type
== bfd_link_hash_defined
1713 || h
->root
.type
== bfd_link_hash_defweak
)
1714 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1716 /* The function is locally defined. */
1718 /* Convert R_386_GOT32X to R_386_PC32. */
1719 if (modrm
== 0x15 || (modrm
& 0xf8) == 0x90)
1721 struct elf_i386_link_hash_entry
*eh
1722 = (struct elf_i386_link_hash_entry
*) h
;
1724 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1727 /* To support TLS optimization, always use addr32 prefix
1728 for "call *___tls_get_addr@GOT(%reg)". */
1729 if (eh
&& eh
->tls_get_addr
== 1)
1732 nop_offset
= irel
->r_offset
- 2;
1736 nop
= link_info
->call_nop_byte
;
1737 if (link_info
->call_nop_as_suffix
)
1739 nop_offset
= roff
+ 3;
1740 irel
->r_offset
-= 1;
1743 nop_offset
= roff
- 2;
1748 /* Convert to "jmp foo nop". */
1751 nop_offset
= roff
+ 3;
1752 irel
->r_offset
-= 1;
1755 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1756 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1757 /* When converting to PC-relative relocation, we
1758 need to adjust addend by -4. */
1759 bfd_put_32 (abfd
, -4, contents
+ irel
->r_offset
);
1760 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_PC32
);
1767 /* We have "mov foo@GOT[(%re1g)], %reg2",
1768 "test %reg1, foo@GOT(%reg2)" and
1769 "binop foo@GOT[(%reg1)], %reg2".
1771 Avoid optimizing _DYNAMIC since ld.so may use its
1772 link-time address. */
1773 if (h
== htab
->elf
.hdynamic
)
1776 /* def_regular is set by an assignment in a linker script in
1777 bfd_elf_record_link_assignment. */
1779 || h
->root
.type
== bfd_link_hash_defined
1780 || h
->root
.type
== bfd_link_hash_defweak
)
1781 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1788 /* Convert "mov foo@GOT[(%reg1)], %reg2" to
1789 "mov $foo, %reg2" with R_386_32. */
1791 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1792 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1797 /* Convert "mov foo@GOT(%reg1), %reg2" to
1798 "lea foo@GOTOFF(%reg1), %reg2". */
1799 r_type
= R_386_GOTOFF
;
1805 /* Only R_386_32 is supported. */
1811 /* Convert "test %reg1, foo@GOT(%reg2)" to
1812 "test $foo, %reg1". */
1813 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1818 /* Convert "binop foo@GOT(%reg1), %reg2" to
1819 "binop $foo, %reg2". */
1821 | (modrm
& 0x38) >> 3
1825 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1829 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1830 irel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
1839 /* Rename some of the generic section flags to better document how they
1841 #define need_convert_load sec_flg0
1842 #define check_relocs_failed sec_flg1
1844 /* Look through the relocs for a section during the first phase, and
1845 calculate needed space in the global offset table, procedure linkage
1846 table, and dynamic reloc sections. */
1849 elf_i386_check_relocs (bfd
*abfd
,
1850 struct bfd_link_info
*info
,
1852 const Elf_Internal_Rela
*relocs
)
1854 struct elf_i386_link_hash_table
*htab
;
1855 Elf_Internal_Shdr
*symtab_hdr
;
1856 struct elf_link_hash_entry
**sym_hashes
;
1857 const Elf_Internal_Rela
*rel
;
1858 const Elf_Internal_Rela
*rel_end
;
1861 bfd_boolean use_plt_got
;
1863 if (bfd_link_relocatable (info
))
1866 /* Don't do anything special with non-loaded, non-alloced sections.
1867 In particular, any relocs in such sections should not affect GOT
1868 and PLT reference counting (ie. we don't allow them to create GOT
1869 or PLT entries), there's no possibility or desire to optimize TLS
1870 relocs, and there's not much point in propagating relocs to shared
1871 libs that the dynamic linker won't relocate. */
1872 if ((sec
->flags
& SEC_ALLOC
) == 0)
1875 BFD_ASSERT (is_i386_elf (abfd
));
1877 htab
= elf_i386_hash_table (info
);
1880 sec
->check_relocs_failed
= 1;
1884 /* Get the section contents. */
1885 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1886 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1887 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1889 sec
->check_relocs_failed
= 1;
1893 use_plt_got
= (!get_elf_i386_backend_data (abfd
)->is_vxworks
1894 && (get_elf_i386_backend_data (abfd
)
1895 == &elf_i386_arch_bed
));
1897 symtab_hdr
= &elf_symtab_hdr (abfd
);
1898 sym_hashes
= elf_sym_hashes (abfd
);
1902 rel_end
= relocs
+ sec
->reloc_count
;
1903 for (rel
= relocs
; rel
< rel_end
; rel
++)
1905 unsigned int r_type
;
1906 unsigned long r_symndx
;
1907 struct elf_link_hash_entry
*h
;
1908 struct elf_i386_link_hash_entry
*eh
;
1909 Elf_Internal_Sym
*isym
;
1911 bfd_boolean size_reloc
;
1913 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1914 r_type
= ELF32_R_TYPE (rel
->r_info
);
1916 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1918 /* xgettext:c-format */
1919 _bfd_error_handler (_("%B: bad symbol index: %d"),
1924 if (r_symndx
< symtab_hdr
->sh_info
)
1926 /* A local symbol. */
1927 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1932 /* Check relocation against local STT_GNU_IFUNC symbol. */
1933 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1935 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1939 /* Fake a STT_GNU_IFUNC symbol. */
1940 h
->type
= STT_GNU_IFUNC
;
1943 h
->forced_local
= 1;
1944 h
->root
.type
= bfd_link_hash_defined
;
1952 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1953 while (h
->root
.type
== bfd_link_hash_indirect
1954 || h
->root
.type
== bfd_link_hash_warning
)
1955 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1958 eh
= (struct elf_i386_link_hash_entry
*) h
;
1974 if (htab
->elf
.dynobj
== NULL
)
1975 htab
->elf
.dynobj
= abfd
;
1976 /* Create the ifunc sections for static executables. */
1977 if (h
->type
== STT_GNU_IFUNC
1978 && !_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
,
1984 /* It is referenced by a non-shared object. */
1986 h
->root
.non_ir_ref
= 1;
1988 if (h
->type
== STT_GNU_IFUNC
)
1989 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1990 |= elf_gnu_symbol_ifunc
;
1993 if (! elf_i386_tls_transition (info
, abfd
, sec
, contents
,
1994 symtab_hdr
, sym_hashes
,
1995 &r_type
, GOT_UNKNOWN
,
1996 rel
, rel_end
, h
, r_symndx
, FALSE
))
2002 htab
->tls_ldm_got
.refcount
+= 1;
2006 /* This symbol requires a procedure linkage table entry. We
2007 actually build the entry in adjust_dynamic_symbol,
2008 because this might be a case of linking PIC code which is
2009 never referenced by a dynamic object, in which case we
2010 don't need to generate a procedure linkage table entry
2013 /* If this is a local symbol, we resolve it directly without
2014 creating a procedure linkage table entry. */
2018 eh
->has_got_reloc
= 1;
2020 h
->plt
.refcount
+= 1;
2027 case R_386_TLS_IE_32
:
2029 case R_386_TLS_GOTIE
:
2030 if (!bfd_link_executable (info
))
2031 info
->flags
|= DF_STATIC_TLS
;
2037 case R_386_TLS_GOTDESC
:
2038 case R_386_TLS_DESC_CALL
:
2039 /* This symbol requires a global offset table entry. */
2041 int tls_type
, old_tls_type
;
2048 tls_type
= GOT_NORMAL
;
2050 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
2051 case R_386_TLS_GOTDESC
:
2052 case R_386_TLS_DESC_CALL
:
2053 tls_type
= GOT_TLS_GDESC
; break;
2054 case R_386_TLS_IE_32
:
2055 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
2056 tls_type
= GOT_TLS_IE_NEG
;
2058 /* If this is a GD->IE transition, we may use either of
2059 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
2060 tls_type
= GOT_TLS_IE
;
2063 case R_386_TLS_GOTIE
:
2064 tls_type
= GOT_TLS_IE_POS
; break;
2069 h
->got
.refcount
+= 1;
2070 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2074 bfd_signed_vma
*local_got_refcounts
;
2076 /* This is a global offset table entry for a local symbol. */
2077 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2078 if (local_got_refcounts
== NULL
)
2082 size
= symtab_hdr
->sh_info
;
2083 size
*= (sizeof (bfd_signed_vma
)
2084 + sizeof (bfd_vma
) + sizeof(char));
2085 local_got_refcounts
= (bfd_signed_vma
*)
2086 bfd_zalloc (abfd
, size
);
2087 if (local_got_refcounts
== NULL
)
2089 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2090 elf_i386_local_tlsdesc_gotent (abfd
)
2091 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2092 elf_i386_local_got_tls_type (abfd
)
2093 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2095 local_got_refcounts
[r_symndx
] += 1;
2096 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
2099 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
2100 tls_type
|= old_tls_type
;
2101 /* If a TLS symbol is accessed using IE at least once,
2102 there is no point to use dynamic model for it. */
2103 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2104 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2105 || (tls_type
& GOT_TLS_IE
) == 0))
2107 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
2108 tls_type
= old_tls_type
;
2109 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2110 && GOT_TLS_GD_ANY_P (tls_type
))
2111 tls_type
|= old_tls_type
;
2115 name
= h
->root
.root
.string
;
2117 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2120 /* xgettext:c-format */
2121 (_("%B: `%s' accessed both as normal and "
2122 "thread local symbol"),
2124 bfd_set_error (bfd_error_bad_value
);
2129 if (old_tls_type
!= tls_type
)
2132 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
2134 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2142 if (htab
->elf
.sgot
== NULL
)
2144 if (htab
->elf
.dynobj
== NULL
)
2145 htab
->elf
.dynobj
= abfd
;
2146 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2149 if (r_type
!= R_386_TLS_IE
)
2152 eh
->has_got_reloc
= 1;
2157 case R_386_TLS_LE_32
:
2160 eh
->has_got_reloc
= 1;
2161 if (bfd_link_executable (info
))
2163 info
->flags
|= DF_STATIC_TLS
;
2168 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2169 eh
->has_non_got_reloc
= 1;
2171 /* We are called after all symbols have been resolved. Only
2172 relocation against STT_GNU_IFUNC symbol must go through
2175 && (bfd_link_executable (info
)
2176 || h
->type
== STT_GNU_IFUNC
))
2178 /* If this reloc is in a read-only section, we might
2179 need a copy reloc. We can't check reliably at this
2180 stage whether the section is read-only, as input
2181 sections have not yet been mapped to output sections.
2182 Tentatively set the flag for now, and correct in
2183 adjust_dynamic_symbol. */
2186 /* We may need a .plt entry if the symbol is a function
2187 defined in a shared lib or is a STT_GNU_IFUNC function
2188 referenced from the code or read-only section. */
2190 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2191 h
->plt
.refcount
+= 1;
2193 if (r_type
== R_386_PC32
)
2195 /* Since something like ".long foo - ." may be used
2196 as pointer, make sure that PLT is used if foo is
2197 a function defined in a shared library. */
2198 if ((sec
->flags
& SEC_CODE
) == 0)
2199 h
->pointer_equality_needed
= 1;
2200 else if (h
->type
== STT_GNU_IFUNC
2201 && bfd_link_pic (info
))
2204 name
= h
->root
.root
.string
;
2206 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2209 /* xgettext:c-format */
2210 (_("%B: unsupported non-PIC call to IFUNC `%s'"),
2212 bfd_set_error (bfd_error_bad_value
);
2218 h
->pointer_equality_needed
= 1;
2219 /* R_386_32 can be resolved at run-time. */
2220 if (r_type
== R_386_32
2221 && (sec
->flags
& SEC_READONLY
) == 0)
2222 eh
->func_pointer_refcount
+= 1;
2228 /* If we are creating a shared library, and this is a reloc
2229 against a global symbol, or a non PC relative reloc
2230 against a local symbol, then we need to copy the reloc
2231 into the shared library. However, if we are linking with
2232 -Bsymbolic, we do not need to copy a reloc against a
2233 global symbol which is defined in an object we are
2234 including in the link (i.e., DEF_REGULAR is set). At
2235 this point we have not seen all the input files, so it is
2236 possible that DEF_REGULAR is not set now but will be set
2237 later (it is never cleared). In case of a weak definition,
2238 DEF_REGULAR may be cleared later by a strong definition in
2239 a shared library. We account for that possibility below by
2240 storing information in the relocs_copied field of the hash
2241 table entry. A similar situation occurs when creating
2242 shared libraries and symbol visibility changes render the
2245 If on the other hand, we are creating an executable, we
2246 may need to keep relocations for symbols satisfied by a
2247 dynamic library if we manage to avoid copy relocs for the
2250 Generate dynamic pointer relocation against STT_GNU_IFUNC
2251 symbol in the non-code section. */
2252 if ((bfd_link_pic (info
)
2253 && (r_type
!= R_386_PC32
2255 && (! (bfd_link_pie (info
)
2256 || SYMBOLIC_BIND (info
, h
))
2257 || h
->root
.type
== bfd_link_hash_defweak
2258 || !h
->def_regular
))))
2260 && h
->type
== STT_GNU_IFUNC
2261 && r_type
== R_386_32
2262 && (sec
->flags
& SEC_CODE
) == 0)
2263 || (ELIMINATE_COPY_RELOCS
2264 && !bfd_link_pic (info
)
2266 && (h
->root
.type
== bfd_link_hash_defweak
2267 || !h
->def_regular
)))
2269 struct elf_dyn_relocs
*p
;
2270 struct elf_dyn_relocs
**head
;
2272 /* We must copy these reloc types into the output file.
2273 Create a reloc section in dynobj and make room for
2277 if (htab
->elf
.dynobj
== NULL
)
2278 htab
->elf
.dynobj
= abfd
;
2280 sreloc
= _bfd_elf_make_dynamic_reloc_section
2281 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
2287 /* If this is a global symbol, we count the number of
2288 relocations we need for this symbol. */
2291 head
= &eh
->dyn_relocs
;
2295 /* Track dynamic relocs needed for local syms too.
2296 We really need local syms available to do this
2301 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2306 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2310 vpp
= &elf_section_data (s
)->local_dynrel
;
2311 head
= (struct elf_dyn_relocs
**)vpp
;
2315 if (p
== NULL
|| p
->sec
!= sec
)
2317 bfd_size_type amt
= sizeof *p
;
2318 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
2330 /* Count size relocation as PC-relative relocation. */
2331 if (r_type
== R_386_PC32
|| size_reloc
)
2336 /* This relocation describes the C++ object vtable hierarchy.
2337 Reconstruct it for later use during GC. */
2338 case R_386_GNU_VTINHERIT
:
2339 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2343 /* This relocation describes which C++ vtable entries are actually
2344 used. Record for later use during GC. */
2345 case R_386_GNU_VTENTRY
:
2346 BFD_ASSERT (h
!= NULL
);
2348 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
2358 && h
->plt
.refcount
> 0
2359 && (((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2360 || h
->got
.refcount
> 0)
2361 && htab
->plt_got
== NULL
)
2363 /* Create the GOT procedure linkage table. */
2364 unsigned int plt_got_align
;
2365 const struct elf_backend_data
*bed
;
2367 bed
= get_elf_backend_data (info
->output_bfd
);
2368 BFD_ASSERT (sizeof (elf_i386_got_plt_entry
) == 8
2369 && (sizeof (elf_i386_got_plt_entry
)
2370 == sizeof (elf_i386_pic_got_plt_entry
)));
2373 if (htab
->elf
.dynobj
== NULL
)
2374 htab
->elf
.dynobj
= abfd
;
2376 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2378 (bed
->dynamic_sec_flags
2383 if (htab
->plt_got
== NULL
2384 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2389 if (!info
->no_ld_generated_unwind_info
2390 && htab
->plt_got_eh_frame
== NULL
2391 && get_elf_i386_backend_data (abfd
)->plt
->eh_frame_plt_got
!= NULL
)
2393 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2394 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2395 | SEC_LINKER_CREATED
);
2396 htab
->plt_got_eh_frame
2397 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2400 if (htab
->plt_got_eh_frame
== NULL
2401 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2402 htab
->plt_got_eh_frame
,
2408 if (r_type
== R_386_GOT32X
2409 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2410 sec
->need_convert_load
= 1;
2413 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2415 if (!info
->keep_memory
)
2419 /* Cache the section contents for elf_link_input_bfd. */
2420 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2427 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2429 sec
->check_relocs_failed
= 1;
2433 /* Return the section that should be marked against GC for a given
2437 elf_i386_gc_mark_hook (asection
*sec
,
2438 struct bfd_link_info
*info
,
2439 Elf_Internal_Rela
*rel
,
2440 struct elf_link_hash_entry
*h
,
2441 Elf_Internal_Sym
*sym
)
2444 switch (ELF32_R_TYPE (rel
->r_info
))
2446 case R_386_GNU_VTINHERIT
:
2447 case R_386_GNU_VTENTRY
:
2451 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2454 /* Remove undefined weak symbol from the dynamic symbol table if it
2455 is resolved to 0. */
2458 elf_i386_fixup_symbol (struct bfd_link_info
*info
,
2459 struct elf_link_hash_entry
*h
)
2461 if (h
->dynindx
!= -1
2462 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2463 elf_i386_hash_entry (h
)->has_got_reloc
,
2464 elf_i386_hash_entry (h
)))
2467 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2473 /* Adjust a symbol defined by a dynamic object and referenced by a
2474 regular object. The current definition is in some section of the
2475 dynamic object, but we're not including those sections. We have to
2476 change the definition to something the rest of the link can
2480 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2481 struct elf_link_hash_entry
*h
)
2483 struct elf_i386_link_hash_table
*htab
;
2485 struct elf_i386_link_hash_entry
*eh
;
2486 struct elf_dyn_relocs
*p
;
2488 /* STT_GNU_IFUNC symbol must go through PLT. */
2489 if (h
->type
== STT_GNU_IFUNC
)
2491 /* All local STT_GNU_IFUNC references must be treate as local
2492 calls via local PLT. */
2494 && SYMBOL_CALLS_LOCAL (info
, h
))
2496 bfd_size_type pc_count
= 0, count
= 0;
2497 struct elf_dyn_relocs
**pp
;
2499 eh
= (struct elf_i386_link_hash_entry
*) h
;
2500 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2502 pc_count
+= p
->pc_count
;
2503 p
->count
-= p
->pc_count
;
2512 if (pc_count
|| count
)
2517 /* Increment PLT reference count only for PC-relative
2520 if (h
->plt
.refcount
<= 0)
2521 h
->plt
.refcount
= 1;
2523 h
->plt
.refcount
+= 1;
2528 if (h
->plt
.refcount
<= 0)
2530 h
->plt
.offset
= (bfd_vma
) -1;
2536 /* If this is a function, put it in the procedure linkage table. We
2537 will fill in the contents of the procedure linkage table later,
2538 when we know the address of the .got section. */
2539 if (h
->type
== STT_FUNC
2542 if (h
->plt
.refcount
<= 0
2543 || SYMBOL_CALLS_LOCAL (info
, h
)
2544 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2545 && h
->root
.type
== bfd_link_hash_undefweak
))
2547 /* This case can occur if we saw a PLT32 reloc in an input
2548 file, but the symbol was never referred to by a dynamic
2549 object, or if all references were garbage collected. In
2550 such a case, we don't actually need to build a procedure
2551 linkage table, and we can just do a PC32 reloc instead. */
2552 h
->plt
.offset
= (bfd_vma
) -1;
2559 /* It's possible that we incorrectly decided a .plt reloc was
2560 needed for an R_386_PC32 reloc to a non-function sym in
2561 check_relocs. We can't decide accurately between function and
2562 non-function syms in check-relocs; Objects loaded later in
2563 the link may change h->type. So fix it now. */
2564 h
->plt
.offset
= (bfd_vma
) -1;
2566 /* If this is a weak symbol, and there is a real definition, the
2567 processor independent code will have arranged for us to see the
2568 real definition first, and we can just use the same value. */
2569 if (h
->u
.weakdef
!= NULL
)
2571 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2572 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2573 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2574 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2575 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2576 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2580 /* This is a reference to a symbol defined by a dynamic object which
2581 is not a function. */
2583 /* If we are creating a shared library, we must presume that the
2584 only references to the symbol are via the global offset table.
2585 For such cases we need not do anything here; the relocations will
2586 be handled correctly by relocate_section. */
2587 if (!bfd_link_executable (info
))
2590 /* If there are no references to this symbol that do not use the
2591 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2593 eh
= (struct elf_i386_link_hash_entry
*) h
;
2594 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2597 /* If -z nocopyreloc was given, we won't generate them either. */
2598 if (info
->nocopyreloc
)
2604 htab
= elf_i386_hash_table (info
);
2608 /* If there aren't any dynamic relocs in read-only sections nor
2609 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2610 avoid the copy reloc. This doesn't work on VxWorks, where we can
2611 not have dynamic relocations (other than copy and jump slot
2612 relocations) in an executable. */
2613 if (ELIMINATE_COPY_RELOCS
2615 && !get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2617 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2619 s
= p
->sec
->output_section
;
2620 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2631 /* We must allocate the symbol in our .dynbss section, which will
2632 become part of the .bss section of the executable. There will be
2633 an entry for this symbol in the .dynsym section. The dynamic
2634 object will contain position independent code, so all references
2635 from the dynamic object to this symbol will go through the global
2636 offset table. The dynamic linker will use the .dynsym entry to
2637 determine the address it must put in the global offset table, so
2638 both the dynamic object and the regular object will refer to the
2639 same memory location for the variable. */
2641 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2642 copy the initial value out of the dynamic object and into the
2643 runtime process image. */
2644 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2646 s
= htab
->elf
.sdynrelro
;
2647 srel
= htab
->elf
.sreldynrelro
;
2651 s
= htab
->elf
.sdynbss
;
2652 srel
= htab
->elf
.srelbss
;
2654 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2656 srel
->size
+= sizeof (Elf32_External_Rel
);
2660 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2663 /* Allocate space in .plt, .got and associated reloc sections for
2667 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2669 struct bfd_link_info
*info
;
2670 struct elf_i386_link_hash_table
*htab
;
2671 struct elf_i386_link_hash_entry
*eh
;
2672 struct elf_dyn_relocs
*p
;
2673 unsigned plt_entry_size
;
2674 bfd_boolean resolved_to_zero
;
2676 if (h
->root
.type
== bfd_link_hash_indirect
)
2679 eh
= (struct elf_i386_link_hash_entry
*) h
;
2681 info
= (struct bfd_link_info
*) inf
;
2682 htab
= elf_i386_hash_table (info
);
2686 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2688 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2692 /* Clear the reference count of function pointer relocations if
2693 symbol isn't a normal function. */
2694 if (h
->type
!= STT_FUNC
)
2695 eh
->func_pointer_refcount
= 0;
2697 /* We can't use the GOT PLT if pointer equality is needed since
2698 finish_dynamic_symbol won't clear symbol value and the dynamic
2699 linker won't update the GOT slot. We will get into an infinite
2700 loop at run-time. */
2701 if (htab
->plt_got
!= NULL
2702 && h
->type
!= STT_GNU_IFUNC
2703 && !h
->pointer_equality_needed
2704 && h
->plt
.refcount
> 0
2705 && h
->got
.refcount
> 0)
2707 /* Don't use the regular PLT if there are both GOT and GOTPLT
2709 h
->plt
.offset
= (bfd_vma
) -1;
2711 /* Use the GOT PLT. */
2712 eh
->plt_got
.refcount
= 1;
2715 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2716 here if it is defined and referenced in a non-shared object. */
2717 if (h
->type
== STT_GNU_IFUNC
2719 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2720 &htab
->readonly_dynrelocs_against_ifunc
,
2722 plt_entry_size
, 4, TRUE
);
2723 /* Don't create the PLT entry if there are only function pointer
2724 relocations which can be resolved at run-time. */
2725 else if (htab
->elf
.dynamic_sections_created
2726 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2727 || eh
->plt_got
.refcount
> 0))
2729 bfd_boolean use_plt_got
;
2731 /* Clear the reference count of function pointer relocations
2733 eh
->func_pointer_refcount
= 0;
2735 if ((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2737 /* Don't use the regular PLT for DF_BIND_NOW. */
2738 h
->plt
.offset
= (bfd_vma
) -1;
2740 /* Use the GOT PLT. */
2741 h
->got
.refcount
= 1;
2742 eh
->plt_got
.refcount
= 1;
2745 use_plt_got
= eh
->plt_got
.refcount
> 0;
2747 /* Make sure this symbol is output as a dynamic symbol.
2748 Undefined weak syms won't yet be marked as dynamic. */
2749 if (h
->dynindx
== -1
2751 && !resolved_to_zero
)
2753 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2757 if (bfd_link_pic (info
)
2758 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2760 asection
*s
= htab
->elf
.splt
;
2761 asection
*got_s
= htab
->plt_got
;
2763 /* If this is the first .plt entry, make room for the special
2764 first entry. The .plt section is used by prelink to undo
2765 prelinking for dynamic relocations. */
2767 s
->size
= plt_entry_size
;
2770 eh
->plt_got
.offset
= got_s
->size
;
2772 h
->plt
.offset
= s
->size
;
2774 /* If this symbol is not defined in a regular file, and we are
2775 not generating a shared library, then set the symbol to this
2776 location in the .plt. This is required to make function
2777 pointers compare as equal between the normal executable and
2778 the shared library. */
2779 if (! bfd_link_pic (info
)
2784 /* We need to make a call to the entry of the GOT PLT
2785 instead of regular PLT entry. */
2786 h
->root
.u
.def
.section
= got_s
;
2787 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2791 h
->root
.u
.def
.section
= s
;
2792 h
->root
.u
.def
.value
= h
->plt
.offset
;
2796 /* Make room for this entry. */
2798 got_s
->size
+= sizeof (elf_i386_got_plt_entry
);
2801 s
->size
+= plt_entry_size
;
2803 /* We also need to make an entry in the .got.plt section,
2804 which will be placed in the .got section by the linker
2806 htab
->elf
.sgotplt
->size
+= 4;
2808 /* There should be no PLT relocation against resolved
2809 undefined weak symbol in executable. */
2810 if (!resolved_to_zero
)
2812 /* We also need to make an entry in the .rel.plt
2814 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2815 htab
->elf
.srelplt
->reloc_count
++;
2819 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
2820 && !bfd_link_pic (info
))
2822 /* VxWorks has a second set of relocations for each PLT entry
2823 in executables. They go in a separate relocation section,
2824 which is processed by the kernel loader. */
2826 /* There are two relocations for the initial PLT entry: an
2827 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2828 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2830 if (h
->plt
.offset
== plt_entry_size
)
2831 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2833 /* There are two extra relocations for each subsequent PLT entry:
2834 an R_386_32 relocation for the GOT entry, and an R_386_32
2835 relocation for the PLT entry. */
2837 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2842 eh
->plt_got
.offset
= (bfd_vma
) -1;
2843 h
->plt
.offset
= (bfd_vma
) -1;
2849 eh
->plt_got
.offset
= (bfd_vma
) -1;
2850 h
->plt
.offset
= (bfd_vma
) -1;
2854 eh
->tlsdesc_got
= (bfd_vma
) -1;
2856 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2857 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2858 if (h
->got
.refcount
> 0
2859 && bfd_link_executable (info
)
2861 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2862 h
->got
.offset
= (bfd_vma
) -1;
2863 else if (h
->got
.refcount
> 0)
2867 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2869 /* Make sure this symbol is output as a dynamic symbol.
2870 Undefined weak syms won't yet be marked as dynamic.
2871 PR ld/21402: If this symbol isn't undefined weak symbol,
2872 don't make it dynamic in PIE. */
2873 if (h
->dynindx
== -1
2875 && !resolved_to_zero
2876 && (h
->root
.type
== bfd_link_hash_undefweak
2877 || !bfd_link_pie (info
)))
2879 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2884 if (GOT_TLS_GDESC_P (tls_type
))
2886 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2887 - elf_i386_compute_jump_table_size (htab
);
2888 htab
->elf
.sgotplt
->size
+= 8;
2889 h
->got
.offset
= (bfd_vma
) -2;
2891 if (! GOT_TLS_GDESC_P (tls_type
)
2892 || GOT_TLS_GD_P (tls_type
))
2894 h
->got
.offset
= s
->size
;
2896 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2897 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2900 dyn
= htab
->elf
.dynamic_sections_created
;
2901 /* R_386_TLS_IE_32 needs one dynamic relocation,
2902 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2903 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2904 need two), R_386_TLS_GD needs one if local symbol and two if
2905 global. No dynamic relocation against resolved undefined weak
2906 symbol in executable. */
2907 if (tls_type
== GOT_TLS_IE_BOTH
)
2908 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2909 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2910 || (tls_type
& GOT_TLS_IE
))
2911 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2912 else if (GOT_TLS_GD_P (tls_type
))
2913 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2914 else if (! GOT_TLS_GDESC_P (tls_type
)
2915 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2916 && !resolved_to_zero
)
2917 || h
->root
.type
!= bfd_link_hash_undefweak
)
2918 && (bfd_link_pic (info
)
2919 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2920 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2921 if (GOT_TLS_GDESC_P (tls_type
))
2922 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2925 h
->got
.offset
= (bfd_vma
) -1;
2927 if (eh
->dyn_relocs
== NULL
)
2930 /* In the shared -Bsymbolic case, discard space allocated for
2931 dynamic pc-relative relocs against symbols which turn out to be
2932 defined in regular objects. For the normal shared case, discard
2933 space for pc-relative relocs that have become local due to symbol
2934 visibility changes. */
2936 if (bfd_link_pic (info
))
2938 /* The only reloc that uses pc_count is R_386_PC32, which will
2939 appear on a call or on something like ".long foo - .". We
2940 want calls to protected symbols to resolve directly to the
2941 function rather than going via the plt. If people want
2942 function pointer comparisons to work as expected then they
2943 should avoid writing assembly like ".long foo - .". */
2944 if (SYMBOL_CALLS_LOCAL (info
, h
))
2946 struct elf_dyn_relocs
**pp
;
2948 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2950 p
->count
-= p
->pc_count
;
2959 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2961 struct elf_dyn_relocs
**pp
;
2962 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2964 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2971 /* Also discard relocs on undefined weak syms with non-default
2972 visibility or in PIE. */
2973 if (eh
->dyn_relocs
!= NULL
2974 && h
->root
.type
== bfd_link_hash_undefweak
)
2976 /* Undefined weak symbol is never bound locally in shared
2978 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2979 || resolved_to_zero
)
2983 /* Keep dynamic non-GOT/non-PLT relocation so that we
2984 can branch to 0 without PLT. */
2985 struct elf_dyn_relocs
**pp
;
2987 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2988 if (p
->pc_count
== 0)
2992 /* Remove non-R_386_PC32 relocation. */
2993 p
->count
= p
->pc_count
;
2997 if (eh
->dyn_relocs
!= NULL
)
2999 /* Make sure undefined weak symbols are output
3000 as dynamic symbols in PIEs for dynamic non-GOT
3001 non-PLT reloations. */
3002 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3007 eh
->dyn_relocs
= NULL
;
3009 else if (h
->dynindx
== -1
3010 && !h
->forced_local
)
3012 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3017 else if (ELIMINATE_COPY_RELOCS
)
3019 /* For the non-shared case, discard space for relocs against
3020 symbols which turn out to need copy relocs or are not
3021 dynamic. Keep dynamic relocations for run-time function
3022 pointer initialization. */
3024 if ((!h
->non_got_ref
3025 || eh
->func_pointer_refcount
> 0
3026 || (h
->root
.type
== bfd_link_hash_undefweak
3027 && !resolved_to_zero
))
3030 || (htab
->elf
.dynamic_sections_created
3031 && (h
->root
.type
== bfd_link_hash_undefweak
3032 || h
->root
.type
== bfd_link_hash_undefined
))))
3034 /* Make sure this symbol is output as a dynamic symbol.
3035 Undefined weak syms won't yet be marked as dynamic. */
3036 if (h
->dynindx
== -1
3038 && !resolved_to_zero
)
3040 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3044 /* If that succeeded, we know we'll be keeping all the
3046 if (h
->dynindx
!= -1)
3050 eh
->dyn_relocs
= NULL
;
3051 eh
->func_pointer_refcount
= 0;
3056 /* Finally, allocate space. */
3057 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3061 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3063 BFD_ASSERT (sreloc
!= NULL
);
3064 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3070 /* Allocate space in .plt, .got and associated reloc sections for
3071 local dynamic relocs. */
3074 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
3076 struct elf_link_hash_entry
*h
3077 = (struct elf_link_hash_entry
*) *slot
;
3079 if (h
->type
!= STT_GNU_IFUNC
3083 || h
->root
.type
!= bfd_link_hash_defined
)
3086 return elf_i386_allocate_dynrelocs (h
, inf
);
3089 /* Find any dynamic relocs that apply to read-only sections. */
3092 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3094 struct elf_i386_link_hash_entry
*eh
;
3095 struct elf_dyn_relocs
*p
;
3097 /* Skip local IFUNC symbols. */
3098 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3101 eh
= (struct elf_i386_link_hash_entry
*) h
;
3102 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3104 asection
*s
= p
->sec
->output_section
;
3106 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3108 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3110 info
->flags
|= DF_TEXTREL
;
3112 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3113 || info
->error_textrel
)
3114 /* xgettext:c-format */
3115 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3116 p
->sec
->owner
, h
->root
.root
.string
,
3119 /* Not an error, just cut short the traversal. */
3126 /* Convert load via the GOT slot to load immediate. */
3129 elf_i386_convert_load (bfd
*abfd
, asection
*sec
,
3130 struct bfd_link_info
*link_info
)
3132 struct elf_i386_link_hash_table
*htab
;
3133 Elf_Internal_Shdr
*symtab_hdr
;
3134 Elf_Internal_Rela
*internal_relocs
;
3135 Elf_Internal_Rela
*irel
, *irelend
;
3137 bfd_boolean changed
;
3138 bfd_signed_vma
*local_got_refcounts
;
3140 /* Don't even try to convert non-ELF outputs. */
3141 if (!is_elf_hash_table (link_info
->hash
))
3144 /* Nothing to do if there is no need or no output. */
3145 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3146 || sec
->need_convert_load
== 0
3147 || bfd_is_abs_section (sec
->output_section
))
3150 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3152 /* Load the relocations for this section. */
3153 internal_relocs
= (_bfd_elf_link_read_relocs
3154 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3155 link_info
->keep_memory
));
3156 if (internal_relocs
== NULL
)
3160 htab
= elf_i386_hash_table (link_info
);
3161 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3163 /* Get the section contents. */
3164 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3165 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3168 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3172 irelend
= internal_relocs
+ sec
->reloc_count
;
3173 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3175 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3176 unsigned int r_symndx
;
3177 struct elf_link_hash_entry
*h
;
3178 bfd_boolean converted
;
3180 /* Don't convert R_386_GOT32 since we can't tell if it is applied
3181 to "mov $foo@GOT, %reg" which isn't a load via GOT. */
3182 if (r_type
!= R_386_GOT32X
)
3185 r_symndx
= ELF32_R_SYM (irel
->r_info
);
3186 if (r_symndx
< symtab_hdr
->sh_info
)
3187 h
= elf_i386_get_local_sym_hash (htab
, sec
->owner
,
3188 (const Elf_Internal_Rela
*) irel
,
3192 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3193 while (h
->root
.type
== bfd_link_hash_indirect
3194 || h
->root
.type
== bfd_link_hash_warning
)
3195 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3198 /* STT_GNU_IFUNC must keep GOT32 relocations. */
3199 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3203 if (!elf_i386_convert_load_reloc (abfd
, symtab_hdr
, contents
,
3204 irel
, h
, &converted
, link_info
))
3209 changed
= converted
;
3212 if (h
->got
.refcount
> 0)
3213 h
->got
.refcount
-= 1;
3217 if (local_got_refcounts
!= NULL
3218 && local_got_refcounts
[r_symndx
] > 0)
3219 local_got_refcounts
[r_symndx
] -= 1;
3224 if (contents
!= NULL
3225 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3227 if (!changed
&& !link_info
->keep_memory
)
3231 /* Cache the section contents for elf_link_input_bfd. */
3232 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3236 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3239 free (internal_relocs
);
3241 elf_section_data (sec
)->relocs
= internal_relocs
;
3247 if (contents
!= NULL
3248 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3250 if (internal_relocs
!= NULL
3251 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3252 free (internal_relocs
);
3256 /* Set the sizes of the dynamic sections. */
3259 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3261 struct elf_i386_link_hash_table
*htab
;
3267 htab
= elf_i386_hash_table (info
);
3270 dynobj
= htab
->elf
.dynobj
;
3274 /* Set up .got offsets for local syms, and space for local dynamic
3276 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3278 bfd_signed_vma
*local_got
;
3279 bfd_signed_vma
*end_local_got
;
3280 char *local_tls_type
;
3281 bfd_vma
*local_tlsdesc_gotent
;
3282 bfd_size_type locsymcount
;
3283 Elf_Internal_Shdr
*symtab_hdr
;
3286 if (! is_i386_elf (ibfd
))
3289 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3291 struct elf_dyn_relocs
*p
;
3293 if (!elf_i386_convert_load (ibfd
, s
, info
))
3296 for (p
= ((struct elf_dyn_relocs
*)
3297 elf_section_data (s
)->local_dynrel
);
3301 if (!bfd_is_abs_section (p
->sec
)
3302 && bfd_is_abs_section (p
->sec
->output_section
))
3304 /* Input section has been discarded, either because
3305 it is a copy of a linkonce section or due to
3306 linker script /DISCARD/, so we'll be discarding
3309 else if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3310 && strcmp (p
->sec
->output_section
->name
,
3313 /* Relocations in vxworks .tls_vars sections are
3314 handled specially by the loader. */
3316 else if (p
->count
!= 0)
3318 srel
= elf_section_data (p
->sec
)->sreloc
;
3319 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3320 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3321 && (info
->flags
& DF_TEXTREL
) == 0)
3323 info
->flags
|= DF_TEXTREL
;
3324 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3325 || info
->error_textrel
)
3326 /* xgettext:c-format */
3327 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3328 p
->sec
->owner
, p
->sec
);
3334 local_got
= elf_local_got_refcounts (ibfd
);
3338 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3339 locsymcount
= symtab_hdr
->sh_info
;
3340 end_local_got
= local_got
+ locsymcount
;
3341 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
3342 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
3344 srel
= htab
->elf
.srelgot
;
3345 for (; local_got
< end_local_got
;
3346 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3348 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3351 if (GOT_TLS_GDESC_P (*local_tls_type
))
3353 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3354 - elf_i386_compute_jump_table_size (htab
);
3355 htab
->elf
.sgotplt
->size
+= 8;
3356 *local_got
= (bfd_vma
) -2;
3358 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3359 || GOT_TLS_GD_P (*local_tls_type
))
3361 *local_got
= s
->size
;
3363 if (GOT_TLS_GD_P (*local_tls_type
)
3364 || *local_tls_type
== GOT_TLS_IE_BOTH
)
3367 if (bfd_link_pic (info
)
3368 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3369 || (*local_tls_type
& GOT_TLS_IE
))
3371 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
3372 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
3373 else if (GOT_TLS_GD_P (*local_tls_type
)
3374 || ! GOT_TLS_GDESC_P (*local_tls_type
))
3375 srel
->size
+= sizeof (Elf32_External_Rel
);
3376 if (GOT_TLS_GDESC_P (*local_tls_type
))
3377 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
3381 *local_got
= (bfd_vma
) -1;
3385 if (htab
->tls_ldm_got
.refcount
> 0)
3387 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
3389 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
3390 htab
->elf
.sgot
->size
+= 8;
3391 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
3394 htab
->tls_ldm_got
.offset
= -1;
3396 /* Allocate global sym .plt and .got entries, and space for global
3397 sym dynamic relocs. */
3398 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
3400 /* Allocate .plt and .got entries, and space for local symbols. */
3401 htab_traverse (htab
->loc_hash_table
,
3402 elf_i386_allocate_local_dynrelocs
,
3405 /* For every jump slot reserved in the sgotplt, reloc_count is
3406 incremented. However, when we reserve space for TLS descriptors,
3407 it's not incremented, so in order to compute the space reserved
3408 for them, it suffices to multiply the reloc count by the jump
3411 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3412 so that R_386_IRELATIVE entries come last. */
3413 if (htab
->elf
.srelplt
)
3415 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
3416 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
3417 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3419 else if (htab
->elf
.irelplt
)
3420 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3423 if (htab
->elf
.sgotplt
)
3425 /* Don't allocate .got.plt section if there are no GOT nor PLT
3426 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
3427 if ((htab
->elf
.hgot
== NULL
3428 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3429 && (htab
->elf
.sgotplt
->size
3430 == get_elf_backend_data (output_bfd
)->got_header_size
)
3431 && (htab
->elf
.splt
== NULL
3432 || htab
->elf
.splt
->size
== 0)
3433 && (htab
->elf
.sgot
== NULL
3434 || htab
->elf
.sgot
->size
== 0)
3435 && (htab
->elf
.iplt
== NULL
3436 || htab
->elf
.iplt
->size
== 0)
3437 && (htab
->elf
.igotplt
== NULL
3438 || htab
->elf
.igotplt
->size
== 0))
3439 htab
->elf
.sgotplt
->size
= 0;
3442 if (_bfd_elf_eh_frame_present (info
))
3444 if (htab
->plt_eh_frame
!= NULL
3445 && htab
->elf
.splt
!= NULL
3446 && htab
->elf
.splt
->size
!= 0
3447 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3448 htab
->plt_eh_frame
->size
3449 = get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt_size
;
3451 if (htab
->plt_got_eh_frame
!= NULL
3452 && htab
->plt_got
!= NULL
3453 && htab
->plt_got
->size
!= 0
3454 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3455 htab
->plt_got_eh_frame
->size
3456 = get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt_got_size
;
3459 /* We now have determined the sizes of the various dynamic sections.
3460 Allocate memory for them. */
3462 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3464 bfd_boolean strip_section
= TRUE
;
3466 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3469 if (s
== htab
->elf
.splt
3470 || s
== htab
->elf
.sgot
)
3472 /* Strip this section if we don't need it; see the
3474 /* We'd like to strip these sections if they aren't needed, but if
3475 we've exported dynamic symbols from them we must leave them.
3476 It's too late to tell BFD to get rid of the symbols. */
3478 if (htab
->elf
.hplt
!= NULL
)
3479 strip_section
= FALSE
;
3481 else if (s
== htab
->elf
.sgotplt
3482 || s
== htab
->elf
.iplt
3483 || s
== htab
->elf
.igotplt
3484 || s
== htab
->plt_got
3485 || s
== htab
->plt_eh_frame
3486 || s
== htab
->plt_got_eh_frame
3487 || s
== htab
->elf
.sdynbss
3488 || s
== htab
->elf
.sdynrelro
)
3490 /* Strip these too. */
3492 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3495 && s
!= htab
->elf
.srelplt
3496 && s
!= htab
->srelplt2
)
3499 /* We use the reloc_count field as a counter if we need
3500 to copy relocs into the output file. */
3505 /* It's not one of our sections, so don't allocate space. */
3511 /* If we don't need this section, strip it from the
3512 output file. This is mostly to handle .rel.bss and
3513 .rel.plt. We must create both sections in
3514 create_dynamic_sections, because they must be created
3515 before the linker maps input sections to output
3516 sections. The linker does that before
3517 adjust_dynamic_symbol is called, and it is that
3518 function which decides whether anything needs to go
3519 into these sections. */
3521 s
->flags
|= SEC_EXCLUDE
;
3525 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3528 /* Allocate memory for the section contents. We use bfd_zalloc
3529 here in case unused entries are not reclaimed before the
3530 section's contents are written out. This should not happen,
3531 but this way if it does, we get a R_386_NONE reloc instead
3533 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3534 if (s
->contents
== NULL
)
3538 if (htab
->plt_eh_frame
!= NULL
3539 && htab
->plt_eh_frame
->contents
!= NULL
)
3541 memcpy (htab
->plt_eh_frame
->contents
,
3542 get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt
,
3543 htab
->plt_eh_frame
->size
);
3544 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3545 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3548 if (htab
->plt_got_eh_frame
!= NULL
3549 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3551 memcpy (htab
->plt_got_eh_frame
->contents
,
3552 get_elf_i386_backend_data (output_bfd
)->plt
->eh_frame_plt_got
,
3553 htab
->plt_got_eh_frame
->size
);
3554 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3555 (htab
->plt_got_eh_frame
->contents
3556 + PLT_FDE_LEN_OFFSET
));
3559 if (htab
->elf
.dynamic_sections_created
)
3561 /* Add some entries to the .dynamic section. We fill in the
3562 values later, in elf_i386_finish_dynamic_sections, but we
3563 must add the entries now so that we get the correct size for
3564 the .dynamic section. The DT_DEBUG entry is filled in by the
3565 dynamic linker and used by the debugger. */
3566 #define add_dynamic_entry(TAG, VAL) \
3567 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3569 if (bfd_link_executable (info
))
3571 if (!add_dynamic_entry (DT_DEBUG
, 0))
3575 if (htab
->elf
.splt
->size
!= 0)
3577 /* DT_PLTGOT is used by prelink even if there is no PLT
3579 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3582 if (htab
->elf
.srelplt
->size
!= 0)
3584 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3585 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3586 || !add_dynamic_entry (DT_JMPREL
, 0))
3593 if (!add_dynamic_entry (DT_REL
, 0)
3594 || !add_dynamic_entry (DT_RELSZ
, 0)
3595 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3598 /* If any dynamic relocs apply to a read-only section,
3599 then we need a DT_TEXTREL entry. */
3600 if ((info
->flags
& DF_TEXTREL
) == 0)
3601 elf_link_hash_traverse (&htab
->elf
,
3602 elf_i386_readonly_dynrelocs
, info
);
3604 if ((info
->flags
& DF_TEXTREL
) != 0)
3606 if (htab
->readonly_dynrelocs_against_ifunc
)
3608 info
->callbacks
->einfo
3609 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3610 bfd_set_error (bfd_error_bad_value
);
3614 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3618 if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3619 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3622 #undef add_dynamic_entry
3628 elf_i386_always_size_sections (bfd
*output_bfd
,
3629 struct bfd_link_info
*info
)
3631 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3635 struct elf_link_hash_entry
*tlsbase
;
3637 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3638 "_TLS_MODULE_BASE_",
3639 FALSE
, FALSE
, FALSE
);
3641 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3643 struct elf_i386_link_hash_table
*htab
;
3644 struct bfd_link_hash_entry
*bh
= NULL
;
3645 const struct elf_backend_data
*bed
3646 = get_elf_backend_data (output_bfd
);
3648 htab
= elf_i386_hash_table (info
);
3652 if (!(_bfd_generic_link_add_one_symbol
3653 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3654 tls_sec
, 0, NULL
, FALSE
,
3655 bed
->collect
, &bh
)))
3658 htab
->tls_module_base
= bh
;
3660 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3661 tlsbase
->def_regular
= 1;
3662 tlsbase
->other
= STV_HIDDEN
;
3663 tlsbase
->root
.linker_def
= 1;
3664 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
3671 /* Set the correct type for an x86 ELF section. We do this by the
3672 section name, which is a hack, but ought to work. */
3675 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3676 Elf_Internal_Shdr
*hdr
,
3681 name
= bfd_get_section_name (abfd
, sec
);
3683 /* This is an ugly, but unfortunately necessary hack that is
3684 needed when producing EFI binaries on x86. It tells
3685 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3686 containing ELF relocation info. We need this hack in order to
3687 be able to generate ELF binaries that can be translated into
3688 EFI applications (which are essentially COFF objects). Those
3689 files contain a COFF ".reloc" section inside an ELFNN object,
3690 which would normally cause BFD to segfault because it would
3691 attempt to interpret this section as containing relocation
3692 entries for section "oc". With this hack enabled, ".reloc"
3693 will be treated as a normal data section, which will avoid the
3694 segfault. However, you won't be able to create an ELFNN binary
3695 with a section named "oc" that needs relocations, but that's
3696 the kind of ugly side-effects you get when detecting section
3697 types based on their names... In practice, this limitation is
3698 unlikely to bite. */
3699 if (strcmp (name
, ".reloc") == 0)
3700 hdr
->sh_type
= SHT_PROGBITS
;
3705 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3706 executables. Rather than setting it to the beginning of the TLS
3707 section, we have to set it to the end. This function may be called
3708 multiple times, it is idempotent. */
3711 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
3713 struct elf_i386_link_hash_table
*htab
;
3714 struct bfd_link_hash_entry
*base
;
3716 if (!bfd_link_executable (info
))
3719 htab
= elf_i386_hash_table (info
);
3723 base
= htab
->tls_module_base
;
3727 base
->u
.def
.value
= htab
->elf
.tls_size
;
3730 /* Return the base VMA address which should be subtracted from real addresses
3731 when resolving @dtpoff relocation.
3732 This is PT_TLS segment p_vaddr. */
3735 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
3737 /* If tls_sec is NULL, we should have signalled an error already. */
3738 if (elf_hash_table (info
)->tls_sec
== NULL
)
3740 return elf_hash_table (info
)->tls_sec
->vma
;
3743 /* Return the relocation value for @tpoff relocation
3744 if STT_TLS virtual address is ADDRESS. */
3747 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3749 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3750 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3751 bfd_vma static_tls_size
;
3753 /* If tls_sec is NULL, we should have signalled an error already. */
3754 if (htab
->tls_sec
== NULL
)
3757 /* Consider special static TLS alignment requirements. */
3758 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3759 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3762 /* Relocate an i386 ELF section. */
3765 elf_i386_relocate_section (bfd
*output_bfd
,
3766 struct bfd_link_info
*info
,
3768 asection
*input_section
,
3770 Elf_Internal_Rela
*relocs
,
3771 Elf_Internal_Sym
*local_syms
,
3772 asection
**local_sections
)
3774 struct elf_i386_link_hash_table
*htab
;
3775 Elf_Internal_Shdr
*symtab_hdr
;
3776 struct elf_link_hash_entry
**sym_hashes
;
3777 bfd_vma
*local_got_offsets
;
3778 bfd_vma
*local_tlsdesc_gotents
;
3779 Elf_Internal_Rela
*rel
;
3780 Elf_Internal_Rela
*wrel
;
3781 Elf_Internal_Rela
*relend
;
3782 bfd_boolean is_vxworks_tls
;
3783 unsigned plt_entry_size
;
3785 BFD_ASSERT (is_i386_elf (input_bfd
));
3787 /* Skip if check_relocs failed. */
3788 if (input_section
->check_relocs_failed
)
3791 htab
= elf_i386_hash_table (info
);
3794 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3795 sym_hashes
= elf_sym_hashes (input_bfd
);
3796 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3797 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3798 /* We have to handle relocations in vxworks .tls_vars sections
3799 specially, because the dynamic loader is 'weird'. */
3800 is_vxworks_tls
= (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3801 && bfd_link_pic (info
)
3802 && !strcmp (input_section
->output_section
->name
,
3805 elf_i386_set_tls_module_base (info
);
3807 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
3809 rel
= wrel
= relocs
;
3810 relend
= relocs
+ input_section
->reloc_count
;
3811 for (; rel
< relend
; wrel
++, rel
++)
3813 unsigned int r_type
;
3814 reloc_howto_type
*howto
;
3815 unsigned long r_symndx
;
3816 struct elf_link_hash_entry
*h
;
3817 struct elf_i386_link_hash_entry
*eh
;
3818 Elf_Internal_Sym
*sym
;
3820 bfd_vma off
, offplt
, plt_offset
;
3822 bfd_boolean unresolved_reloc
;
3823 bfd_reloc_status_type r
;
3827 asection
*resolved_plt
;
3828 bfd_boolean resolved_to_zero
;
3829 bfd_boolean relative_reloc
;
3831 r_type
= ELF32_R_TYPE (rel
->r_info
);
3832 if (r_type
== R_386_GNU_VTINHERIT
3833 || r_type
== R_386_GNU_VTENTRY
)
3840 if ((indx
= r_type
) >= R_386_standard
3841 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3842 >= R_386_ext
- R_386_standard
)
3843 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3844 >= R_386_ext2
- R_386_ext
))
3847 /* xgettext:c-format */
3848 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3849 input_bfd
, r_type
, input_section
);
3850 bfd_set_error (bfd_error_bad_value
);
3853 howto
= elf_howto_table
+ indx
;
3855 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3859 unresolved_reloc
= FALSE
;
3860 if (r_symndx
< symtab_hdr
->sh_info
)
3862 sym
= local_syms
+ r_symndx
;
3863 sec
= local_sections
[r_symndx
];
3864 relocation
= (sec
->output_section
->vma
3865 + sec
->output_offset
3867 st_size
= sym
->st_size
;
3869 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3870 && ((sec
->flags
& SEC_MERGE
) != 0
3871 || (bfd_link_relocatable (info
)
3872 && sec
->output_offset
!= 0)))
3875 bfd_byte
*where
= contents
+ rel
->r_offset
;
3877 switch (howto
->size
)
3880 addend
= bfd_get_8 (input_bfd
, where
);
3881 if (howto
->pc_relative
)
3883 addend
= (addend
^ 0x80) - 0x80;
3888 addend
= bfd_get_16 (input_bfd
, where
);
3889 if (howto
->pc_relative
)
3891 addend
= (addend
^ 0x8000) - 0x8000;
3896 addend
= bfd_get_32 (input_bfd
, where
);
3897 if (howto
->pc_relative
)
3899 addend
= (addend
^ 0x80000000) - 0x80000000;
3907 if (bfd_link_relocatable (info
))
3908 addend
+= sec
->output_offset
;
3911 asection
*msec
= sec
;
3912 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3914 addend
-= relocation
;
3915 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3918 switch (howto
->size
)
3921 /* FIXME: overflow checks. */
3922 if (howto
->pc_relative
)
3924 bfd_put_8 (input_bfd
, addend
, where
);
3927 if (howto
->pc_relative
)
3929 bfd_put_16 (input_bfd
, addend
, where
);
3932 if (howto
->pc_relative
)
3934 bfd_put_32 (input_bfd
, addend
, where
);
3938 else if (!bfd_link_relocatable (info
)
3939 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3941 /* Relocate against local STT_GNU_IFUNC symbol. */
3942 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3947 /* Set STT_GNU_IFUNC symbol value. */
3948 h
->root
.u
.def
.value
= sym
->st_value
;
3949 h
->root
.u
.def
.section
= sec
;
3954 bfd_boolean warned ATTRIBUTE_UNUSED
;
3955 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3957 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3958 r_symndx
, symtab_hdr
, sym_hashes
,
3960 unresolved_reloc
, warned
, ignored
);
3964 if (sec
!= NULL
&& discarded_section (sec
))
3966 _bfd_clear_contents (howto
, input_bfd
, input_section
,
3967 contents
+ rel
->r_offset
);
3968 wrel
->r_offset
= rel
->r_offset
;
3972 /* For ld -r, remove relocations in debug sections against
3973 sections defined in discarded sections. Not done for
3974 eh_frame editing code expects to be present. */
3975 if (bfd_link_relocatable (info
)
3976 && (input_section
->flags
& SEC_DEBUGGING
))
3982 if (bfd_link_relocatable (info
))
3989 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3990 it here if it is defined in a non-shared object. */
3992 && h
->type
== STT_GNU_IFUNC
3995 asection
*plt
, *gotplt
, *base_got
;
3999 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4001 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4002 sections because such sections are not SEC_ALLOC and
4003 thus ld.so will not process them. */
4004 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4009 /* STT_GNU_IFUNC symbol must go through PLT. */
4010 if (htab
->elf
.splt
!= NULL
)
4012 plt
= htab
->elf
.splt
;
4013 gotplt
= htab
->elf
.sgotplt
;
4017 plt
= htab
->elf
.iplt
;
4018 gotplt
= htab
->elf
.igotplt
;
4028 base_got
= htab
->elf
.sgot
;
4029 off
= h
->got
.offset
;
4031 if (base_got
== NULL
)
4034 if (off
== (bfd_vma
) -1)
4036 /* We can't use h->got.offset here to save state, or
4037 even just remember the offset, as finish_dynamic_symbol
4038 would use that as offset into .got. */
4040 if (h
->plt
.offset
== (bfd_vma
) -1)
4043 if (htab
->elf
.splt
!= NULL
)
4045 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4046 off
= (plt_index
+ 3) * 4;
4047 base_got
= htab
->elf
.sgotplt
;
4051 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4052 off
= plt_index
* 4;
4053 base_got
= htab
->elf
.igotplt
;
4056 if (h
->dynindx
== -1
4060 /* This references the local defitionion. We must
4061 initialize this entry in the global offset table.
4062 Since the offset must always be a multiple of 8,
4063 we use the least significant bit to record
4064 whether we have initialized it already.
4066 When doing a dynamic link, we create a .rela.got
4067 relocation entry to initialize the value. This
4068 is done in the finish_dynamic_symbol routine. */
4073 bfd_put_32 (output_bfd
, relocation
,
4074 base_got
->contents
+ off
);
4082 relocation
= (base_got
->output_section
->vma
4083 + base_got
->output_offset
+ off
4084 - gotplt
->output_section
->vma
4085 - gotplt
->output_offset
);
4087 if (rel
->r_offset
> 1
4088 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4089 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4091 if (bfd_link_pic (info
))
4092 goto disallow_got32
;
4094 /* Add the GOT base if there is no base register. */
4095 relocation
+= (gotplt
->output_section
->vma
4096 + gotplt
->output_offset
);
4098 else if (htab
->elf
.splt
== NULL
)
4100 /* Adjust for static executables. */
4101 relocation
+= gotplt
->output_offset
;
4107 if (h
->plt
.offset
== (bfd_vma
) -1)
4109 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4110 if (r_type
== R_386_32
4111 && (input_section
->flags
& SEC_CODE
) == 0)
4112 goto do_ifunc_pointer
;
4113 goto bad_ifunc_reloc
;
4116 relocation
= (plt
->output_section
->vma
4117 + plt
->output_offset
+ h
->plt
.offset
);
4123 if (h
->root
.root
.string
)
4124 name
= h
->root
.root
.string
;
4126 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4129 /* xgettext:c-format */
4130 (_("%B: relocation %s against STT_GNU_IFUNC "
4131 "symbol `%s' isn't supported"), input_bfd
,
4133 bfd_set_error (bfd_error_bad_value
);
4137 /* Generate dynamic relcoation only when there is a
4138 non-GOT reference in a shared object. */
4139 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4140 || h
->plt
.offset
== (bfd_vma
) -1)
4142 Elf_Internal_Rela outrel
;
4147 /* Need a dynamic relocation to get the real function
4149 offset
= _bfd_elf_section_offset (output_bfd
,
4153 if (offset
== (bfd_vma
) -1
4154 || offset
== (bfd_vma
) -2)
4157 outrel
.r_offset
= (input_section
->output_section
->vma
4158 + input_section
->output_offset
4161 if (h
->dynindx
== -1
4163 || bfd_link_executable (info
))
4165 /* This symbol is resolved locally. */
4166 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4167 bfd_put_32 (output_bfd
,
4168 (h
->root
.u
.def
.value
4169 + h
->root
.u
.def
.section
->output_section
->vma
4170 + h
->root
.u
.def
.section
->output_offset
),
4174 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4176 /* Dynamic relocations are stored in
4177 1. .rel.ifunc section in PIC object.
4178 2. .rel.got section in dynamic executable.
4179 3. .rel.iplt section in static executable. */
4180 if (bfd_link_pic (info
))
4181 sreloc
= htab
->elf
.irelifunc
;
4182 else if (htab
->elf
.splt
!= NULL
)
4183 sreloc
= htab
->elf
.srelgot
;
4185 sreloc
= htab
->elf
.irelplt
;
4186 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4188 /* If this reloc is against an external symbol, we
4189 do not want to fiddle with the addend. Otherwise,
4190 we need to include the symbol value so that it
4191 becomes an addend for the dynamic reloc. For an
4192 internal symbol, we have updated addend. */
4201 relocation
-= (gotplt
->output_section
->vma
4202 + gotplt
->output_offset
);
4207 eh
= (struct elf_i386_link_hash_entry
*) h
;
4208 resolved_to_zero
= (eh
!= NULL
4209 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4216 /* Avoid optimizing _DYNAMIC since ld.so may use its
4217 link-time address. */
4218 if (h
== htab
->elf
.hdynamic
)
4221 if (bfd_link_pic (info
))
4223 /* It is OK to convert mov to lea and convert indirect
4224 branch to direct branch. It is OK to convert adc,
4225 add, and, cmp, or, sbb, sub, test, xor only when PIC
4227 unsigned int opcode
, addend
;
4228 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4231 opcode
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4232 if (opcode
!= 0x8b && opcode
!= 0xff)
4236 /* Resolve "mov GOT[(%reg)], %reg",
4237 "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
4238 and "binop foo@GOT[(%reg)], %reg". */
4240 || (h
->plt
.offset
== (bfd_vma
) -1
4241 && h
->got
.offset
== (bfd_vma
) -1)
4242 || htab
->elf
.sgotplt
== NULL
)
4245 offplt
= (htab
->elf
.sgotplt
->output_section
->vma
4246 + htab
->elf
.sgotplt
->output_offset
);
4248 /* It is relative to .got.plt section. */
4249 if (h
->got
.offset
!= (bfd_vma
) -1)
4250 /* Use GOT entry. Mask off the least significant bit in
4251 GOT offset which may be set by R_386_GOT32 processing
4253 relocation
= (htab
->elf
.sgot
->output_section
->vma
4254 + htab
->elf
.sgot
->output_offset
4255 + (h
->got
.offset
& ~1) - offplt
);
4257 /* Use GOTPLT entry. */
4258 relocation
= (h
->plt
.offset
/ plt_entry_size
- 1 + 3) * 4;
4260 if (!bfd_link_pic (info
))
4262 /* If not PIC, add the .got.plt section address for
4263 baseless addressing. */
4265 modrm
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4266 if ((modrm
& 0xc7) == 0x5)
4267 relocation
+= offplt
;
4270 unresolved_reloc
= FALSE
;
4275 /* Relocation is to the entry for this symbol in the global
4277 if (htab
->elf
.sgot
== NULL
)
4280 relative_reloc
= FALSE
;
4285 off
= h
->got
.offset
;
4286 dyn
= htab
->elf
.dynamic_sections_created
;
4287 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4288 bfd_link_pic (info
),
4290 || (bfd_link_pic (info
)
4291 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4292 || (ELF_ST_VISIBILITY (h
->other
)
4293 && h
->root
.type
== bfd_link_hash_undefweak
))
4295 /* This is actually a static link, or it is a
4296 -Bsymbolic link and the symbol is defined
4297 locally, or the symbol was forced to be local
4298 because of a version file. We must initialize
4299 this entry in the global offset table. Since the
4300 offset must always be a multiple of 4, we use the
4301 least significant bit to record whether we have
4302 initialized it already.
4304 When doing a dynamic link, we create a .rel.got
4305 relocation entry to initialize the value. This
4306 is done in the finish_dynamic_symbol routine. */
4311 bfd_put_32 (output_bfd
, relocation
,
4312 htab
->elf
.sgot
->contents
+ off
);
4315 if (h
->dynindx
== -1
4317 && h
->root
.type
!= bfd_link_hash_undefweak
4318 && bfd_link_pie (info
))
4320 /* PR ld/21402: If this symbol isn't dynamic
4321 in PIE, generate R_386_RELATIVE here. */
4322 eh
->no_finish_dynamic_symbol
= 1;
4323 relative_reloc
= TRUE
;
4328 unresolved_reloc
= FALSE
;
4332 if (local_got_offsets
== NULL
)
4335 off
= local_got_offsets
[r_symndx
];
4337 /* The offset must always be a multiple of 4. We use
4338 the least significant bit to record whether we have
4339 already generated the necessary reloc. */
4344 bfd_put_32 (output_bfd
, relocation
,
4345 htab
->elf
.sgot
->contents
+ off
);
4346 local_got_offsets
[r_symndx
] |= 1;
4348 if (bfd_link_pic (info
))
4349 relative_reloc
= TRUE
;
4356 Elf_Internal_Rela outrel
;
4358 s
= htab
->elf
.srelgot
;
4362 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4363 + htab
->elf
.sgot
->output_offset
4365 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4366 elf_append_rel (output_bfd
, s
, &outrel
);
4369 if (off
>= (bfd_vma
) -2)
4372 relocation
= (htab
->elf
.sgot
->output_section
->vma
4373 + htab
->elf
.sgot
->output_offset
+ off
);
4374 if (rel
->r_offset
> 1
4375 && (*(contents
+ rel
->r_offset
- 1) & 0xc7) == 0x5
4376 && *(contents
+ rel
->r_offset
- 2) != 0x8d)
4378 if (bfd_link_pic (info
))
4380 /* For PIC, disallow R_386_GOT32 without a base
4381 register, except for "lea foo@GOT, %reg", since
4382 we don't know what the GOT base is. */
4386 if (h
== NULL
|| h
->root
.root
.string
== NULL
)
4387 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4390 name
= h
->root
.root
.string
;
4393 /* xgettext:c-format */
4394 (_("%B: direct GOT relocation %s against `%s'"
4395 " without base register can not be used"
4396 " when making a shared object"),
4397 input_bfd
, howto
->name
, name
);
4398 bfd_set_error (bfd_error_bad_value
);
4404 /* Subtract the .got.plt section address only with a base
4406 relocation
-= (htab
->elf
.sgotplt
->output_section
->vma
4407 + htab
->elf
.sgotplt
->output_offset
);
4413 /* Relocation is relative to the start of the global offset
4416 /* Check to make sure it isn't a protected function or data
4417 symbol for shared library since it may not be local when
4418 used as function address or with copy relocation. We also
4419 need to make sure that a symbol is referenced locally. */
4420 if (!bfd_link_executable (info
) && h
)
4422 if (!h
->def_regular
)
4426 switch (ELF_ST_VISIBILITY (h
->other
))
4429 v
= _("hidden symbol");
4432 v
= _("internal symbol");
4435 v
= _("protected symbol");
4443 /* xgettext:c-format */
4444 (_("%B: relocation R_386_GOTOFF against undefined %s"
4445 " `%s' can not be used when making a shared object"),
4446 input_bfd
, v
, h
->root
.root
.string
);
4447 bfd_set_error (bfd_error_bad_value
);
4450 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
4451 && (h
->type
== STT_FUNC
4452 || h
->type
== STT_OBJECT
)
4453 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4456 /* xgettext:c-format */
4457 (_("%B: relocation R_386_GOTOFF against protected %s"
4458 " `%s' can not be used when making a shared object"),
4460 h
->type
== STT_FUNC
? "function" : "data",
4461 h
->root
.root
.string
);
4462 bfd_set_error (bfd_error_bad_value
);
4467 /* Note that sgot is not involved in this
4468 calculation. We always want the start of .got.plt. If we
4469 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4470 permitted by the ABI, we might have to change this
4472 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4473 + htab
->elf
.sgotplt
->output_offset
;
4477 /* Use global offset table as symbol value. */
4478 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4479 + htab
->elf
.sgotplt
->output_offset
;
4480 unresolved_reloc
= FALSE
;
4484 /* Relocation is to the entry for this symbol in the
4485 procedure linkage table. */
4487 /* Resolve a PLT32 reloc against a local symbol directly,
4488 without using the procedure linkage table. */
4492 if ((h
->plt
.offset
== (bfd_vma
) -1
4493 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4494 || htab
->elf
.splt
== NULL
)
4496 /* We didn't make a PLT entry for this symbol. This
4497 happens when statically linking PIC code, or when
4498 using -Bsymbolic. */
4502 if (h
->plt
.offset
!= (bfd_vma
) -1)
4504 resolved_plt
= htab
->elf
.splt
;
4505 plt_offset
= h
->plt
.offset
;
4509 resolved_plt
= htab
->plt_got
;
4510 plt_offset
= eh
->plt_got
.offset
;
4513 relocation
= (resolved_plt
->output_section
->vma
4514 + resolved_plt
->output_offset
4516 unresolved_reloc
= FALSE
;
4520 /* Set to symbol size. */
4521 relocation
= st_size
;
4526 if ((input_section
->flags
& SEC_ALLOC
) == 0
4530 /* Copy dynamic function pointer relocations. Don't generate
4531 dynamic relocations against resolved undefined weak symbols
4532 in PIE, except for R_386_PC32. */
4533 if ((bfd_link_pic (info
)
4535 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4536 && (!resolved_to_zero
4537 || r_type
== R_386_PC32
))
4538 || h
->root
.type
!= bfd_link_hash_undefweak
))
4539 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
4540 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4541 || (ELIMINATE_COPY_RELOCS
4542 && !bfd_link_pic (info
)
4546 || eh
->func_pointer_refcount
> 0
4547 || (h
->root
.type
== bfd_link_hash_undefweak
4548 && !resolved_to_zero
))
4549 && ((h
->def_dynamic
&& !h
->def_regular
)
4550 /* Undefined weak symbol is bound locally when
4552 || h
->root
.type
== bfd_link_hash_undefweak
)))
4554 Elf_Internal_Rela outrel
;
4555 bfd_boolean skip
, relocate
;
4558 /* When generating a shared object, these relocations
4559 are copied into the output file to be resolved at run
4566 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4568 if (outrel
.r_offset
== (bfd_vma
) -1)
4570 else if (outrel
.r_offset
== (bfd_vma
) -2)
4571 skip
= TRUE
, relocate
= TRUE
;
4572 outrel
.r_offset
+= (input_section
->output_section
->vma
4573 + input_section
->output_offset
);
4576 memset (&outrel
, 0, sizeof outrel
);
4579 && (r_type
== R_386_PC32
4580 || !(bfd_link_executable (info
)
4581 || SYMBOLIC_BIND (info
, h
))
4582 || !h
->def_regular
))
4583 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4586 /* This symbol is local, or marked to become local. */
4588 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4591 sreloc
= elf_section_data (input_section
)->sreloc
;
4593 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4595 r
= bfd_reloc_notsupported
;
4596 goto check_relocation_error
;
4599 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4601 /* If this reloc is against an external symbol, we do
4602 not want to fiddle with the addend. Otherwise, we
4603 need to include the symbol value so that it becomes
4604 an addend for the dynamic reloc. */
4611 if (!bfd_link_executable (info
))
4613 Elf_Internal_Rela outrel
;
4616 outrel
.r_offset
= rel
->r_offset
4617 + input_section
->output_section
->vma
4618 + input_section
->output_offset
;
4619 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4620 sreloc
= elf_section_data (input_section
)->sreloc
;
4623 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4628 case R_386_TLS_GOTDESC
:
4629 case R_386_TLS_DESC_CALL
:
4630 case R_386_TLS_IE_32
:
4631 case R_386_TLS_GOTIE
:
4632 tls_type
= GOT_UNKNOWN
;
4633 if (h
== NULL
&& local_got_offsets
)
4634 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
4636 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
4637 if (tls_type
== GOT_TLS_IE
)
4638 tls_type
= GOT_TLS_IE_NEG
;
4640 if (! elf_i386_tls_transition (info
, input_bfd
,
4641 input_section
, contents
,
4642 symtab_hdr
, sym_hashes
,
4643 &r_type
, tls_type
, rel
,
4644 relend
, h
, r_symndx
, TRUE
))
4647 if (r_type
== R_386_TLS_LE_32
)
4649 BFD_ASSERT (! unresolved_reloc
);
4650 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4655 /* GD->LE transition. */
4656 type
= *(contents
+ rel
->r_offset
- 2);
4660 leal foo@tlsgd(,%ebx,1), %eax
4661 call ___tls_get_addr@PLT
4664 subl $foo@tpoff, %eax
4665 (6 byte form of subl). */
4666 roff
= rel
->r_offset
+ 5;
4671 leal foo@tlsgd(%ebx), %eax
4672 call ___tls_get_addr@PLT
4675 leal foo@tlsgd(%reg), %eax
4676 call *___tls_get_addr@GOT(%reg)
4677 which may be converted to
4678 addr32 call ___tls_get_addr
4680 movl %gs:0, %eax; subl $foo@tpoff, %eax
4681 (6 byte form of subl). */
4682 roff
= rel
->r_offset
+ 6;
4684 memcpy (contents
+ roff
- 8,
4685 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4686 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4688 /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
4693 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4695 /* GDesc -> LE transition.
4696 It's originally something like:
4697 leal x@tlsdesc(%ebx), %eax
4701 Registers other than %eax may be set up here. */
4706 roff
= rel
->r_offset
;
4707 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4709 /* Now modify the instruction as appropriate. */
4710 /* aoliva FIXME: remove the above and xor the byte
4712 bfd_put_8 (output_bfd
, val
^ 0x86,
4713 contents
+ roff
- 1);
4714 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4718 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4720 /* GDesc -> LE transition.
4728 roff
= rel
->r_offset
;
4729 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4730 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4733 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4737 /* IE->LE transition:
4738 Originally it can be one of:
4746 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4749 /* movl foo, %eax. */
4750 bfd_put_8 (output_bfd
, 0xb8,
4751 contents
+ rel
->r_offset
- 1);
4757 type
= bfd_get_8 (input_bfd
,
4758 contents
+ rel
->r_offset
- 2);
4763 bfd_put_8 (output_bfd
, 0xc7,
4764 contents
+ rel
->r_offset
- 2);
4765 bfd_put_8 (output_bfd
,
4766 0xc0 | ((val
>> 3) & 7),
4767 contents
+ rel
->r_offset
- 1);
4771 bfd_put_8 (output_bfd
, 0x81,
4772 contents
+ rel
->r_offset
- 2);
4773 bfd_put_8 (output_bfd
,
4774 0xc0 | ((val
>> 3) & 7),
4775 contents
+ rel
->r_offset
- 1);
4782 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4783 contents
+ rel
->r_offset
);
4788 unsigned int val
, type
;
4790 /* {IE_32,GOTIE}->LE transition:
4791 Originally it can be one of:
4792 subl foo(%reg1), %reg2
4793 movl foo(%reg1), %reg2
4794 addl foo(%reg1), %reg2
4797 movl $foo, %reg2 (6 byte form)
4798 addl $foo, %reg2. */
4799 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4800 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4804 bfd_put_8 (output_bfd
, 0xc7,
4805 contents
+ rel
->r_offset
- 2);
4806 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4807 contents
+ rel
->r_offset
- 1);
4809 else if (type
== 0x2b)
4812 bfd_put_8 (output_bfd
, 0x81,
4813 contents
+ rel
->r_offset
- 2);
4814 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4815 contents
+ rel
->r_offset
- 1);
4817 else if (type
== 0x03)
4820 bfd_put_8 (output_bfd
, 0x81,
4821 contents
+ rel
->r_offset
- 2);
4822 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4823 contents
+ rel
->r_offset
- 1);
4827 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4828 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4829 contents
+ rel
->r_offset
);
4831 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4832 contents
+ rel
->r_offset
);
4837 if (htab
->elf
.sgot
== NULL
)
4842 off
= h
->got
.offset
;
4843 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
4847 if (local_got_offsets
== NULL
)
4850 off
= local_got_offsets
[r_symndx
];
4851 offplt
= local_tlsdesc_gotents
[r_symndx
];
4858 Elf_Internal_Rela outrel
;
4862 if (htab
->elf
.srelgot
== NULL
)
4865 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4867 if (GOT_TLS_GDESC_P (tls_type
))
4870 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4871 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4872 <= htab
->elf
.sgotplt
->size
);
4873 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4874 + htab
->elf
.sgotplt
->output_offset
4876 + htab
->sgotplt_jump_table_size
);
4877 sreloc
= htab
->elf
.srelplt
;
4878 loc
= sreloc
->contents
;
4879 loc
+= (htab
->next_tls_desc_index
++
4880 * sizeof (Elf32_External_Rel
));
4881 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4882 <= sreloc
->contents
+ sreloc
->size
);
4883 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4886 BFD_ASSERT (! unresolved_reloc
);
4887 bfd_put_32 (output_bfd
,
4888 relocation
- elf_i386_dtpoff_base (info
),
4889 htab
->elf
.sgotplt
->contents
+ offplt
4890 + htab
->sgotplt_jump_table_size
+ 4);
4894 bfd_put_32 (output_bfd
, 0,
4895 htab
->elf
.sgotplt
->contents
+ offplt
4896 + htab
->sgotplt_jump_table_size
+ 4);
4900 sreloc
= htab
->elf
.srelgot
;
4902 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4903 + htab
->elf
.sgot
->output_offset
+ off
);
4905 if (GOT_TLS_GD_P (tls_type
))
4906 dr_type
= R_386_TLS_DTPMOD32
;
4907 else if (GOT_TLS_GDESC_P (tls_type
))
4909 else if (tls_type
== GOT_TLS_IE_POS
)
4910 dr_type
= R_386_TLS_TPOFF
;
4912 dr_type
= R_386_TLS_TPOFF32
;
4914 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
4915 bfd_put_32 (output_bfd
,
4916 relocation
- elf_i386_dtpoff_base (info
),
4917 htab
->elf
.sgot
->contents
+ off
);
4918 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
4919 bfd_put_32 (output_bfd
,
4920 elf_i386_dtpoff_base (info
) - relocation
,
4921 htab
->elf
.sgot
->contents
+ off
);
4922 else if (dr_type
!= R_386_TLS_DESC
)
4923 bfd_put_32 (output_bfd
, 0,
4924 htab
->elf
.sgot
->contents
+ off
);
4925 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
4927 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4929 if (GOT_TLS_GD_P (tls_type
))
4933 BFD_ASSERT (! unresolved_reloc
);
4934 bfd_put_32 (output_bfd
,
4935 relocation
- elf_i386_dtpoff_base (info
),
4936 htab
->elf
.sgot
->contents
+ off
+ 4);
4940 bfd_put_32 (output_bfd
, 0,
4941 htab
->elf
.sgot
->contents
+ off
+ 4);
4942 outrel
.r_info
= ELF32_R_INFO (indx
,
4943 R_386_TLS_DTPOFF32
);
4944 outrel
.r_offset
+= 4;
4945 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4948 else if (tls_type
== GOT_TLS_IE_BOTH
)
4950 bfd_put_32 (output_bfd
,
4952 ? relocation
- elf_i386_dtpoff_base (info
)
4954 htab
->elf
.sgot
->contents
+ off
+ 4);
4955 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4956 outrel
.r_offset
+= 4;
4957 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4964 local_got_offsets
[r_symndx
] |= 1;
4967 if (off
>= (bfd_vma
) -2
4968 && ! GOT_TLS_GDESC_P (tls_type
))
4970 if (r_type
== R_386_TLS_GOTDESC
4971 || r_type
== R_386_TLS_DESC_CALL
)
4973 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4974 unresolved_reloc
= FALSE
;
4976 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4978 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4979 + htab
->elf
.sgotplt
->output_offset
;
4980 relocation
= htab
->elf
.sgot
->output_section
->vma
4981 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4982 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4983 && tls_type
== GOT_TLS_IE_BOTH
)
4985 if (r_type
== R_386_TLS_IE
)
4986 relocation
+= g_o_t
;
4987 unresolved_reloc
= FALSE
;
4989 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4991 unsigned int val
, type
;
4994 /* GD->IE transition. */
4995 type
= *(contents
+ rel
->r_offset
- 2);
4996 val
= *(contents
+ rel
->r_offset
- 1);
5000 leal foo@tlsgd(,%ebx,1), %eax
5001 call ___tls_get_addr@PLT
5004 subl $foo@gottpoff(%ebx), %eax. */
5006 roff
= rel
->r_offset
- 3;
5011 leal foo@tlsgd(%ebx), %eax
5012 call ___tls_get_addr@PLT
5015 leal foo@tlsgd(%reg), %eax
5016 call *___tls_get_addr@GOT(%reg)
5017 which may be converted to
5018 addr32 call ___tls_get_addr
5021 subl $foo@gottpoff(%reg), %eax. */
5022 roff
= rel
->r_offset
- 2;
5024 memcpy (contents
+ roff
,
5025 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
5026 contents
[roff
+ 7] = 0x80 | (val
& 7);
5027 /* If foo is used only with foo@gotntpoff(%reg) and
5028 foo@indntpoff, but not with foo@gottpoff(%reg), change
5029 subl $foo@gottpoff(%reg), %eax
5031 addl $foo@gotntpoff(%reg), %eax. */
5032 if (tls_type
== GOT_TLS_IE_POS
)
5033 contents
[roff
+ 6] = 0x03;
5034 bfd_put_32 (output_bfd
,
5035 htab
->elf
.sgot
->output_section
->vma
5036 + htab
->elf
.sgot
->output_offset
+ off
5037 - htab
->elf
.sgotplt
->output_section
->vma
5038 - htab
->elf
.sgotplt
->output_offset
,
5039 contents
+ roff
+ 8);
5040 /* Skip R_386_PLT32 and R_386_GOT32X. */
5045 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
5047 /* GDesc -> IE transition.
5048 It's originally something like:
5049 leal x@tlsdesc(%ebx), %eax
5052 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
5054 movl x@gottpoff(%ebx), %eax # before negl %eax
5056 Registers other than %eax may be set up here. */
5060 /* First, make sure it's a leal adding ebx to a 32-bit
5061 offset into any register, although it's probably
5062 almost always going to be eax. */
5063 roff
= rel
->r_offset
;
5065 /* Now modify the instruction as appropriate. */
5066 /* To turn a leal into a movl in the form we use it, it
5067 suffices to change the first byte from 0x8d to 0x8b.
5068 aoliva FIXME: should we decide to keep the leal, all
5069 we have to do is remove the statement below, and
5070 adjust the relaxation of R_386_TLS_DESC_CALL. */
5071 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5073 if (tls_type
== GOT_TLS_IE_BOTH
)
5076 bfd_put_32 (output_bfd
,
5077 htab
->elf
.sgot
->output_section
->vma
5078 + htab
->elf
.sgot
->output_offset
+ off
5079 - htab
->elf
.sgotplt
->output_section
->vma
5080 - htab
->elf
.sgotplt
->output_offset
,
5084 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
5086 /* GDesc -> IE transition.
5094 depending on how we transformed the TLS_GOTDESC above.
5099 roff
= rel
->r_offset
;
5101 /* Now modify the instruction as appropriate. */
5102 if (tls_type
!= GOT_TLS_IE_NEG
)
5105 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5106 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5111 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
5112 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
5122 if (! elf_i386_tls_transition (info
, input_bfd
,
5123 input_section
, contents
,
5124 symtab_hdr
, sym_hashes
,
5125 &r_type
, GOT_UNKNOWN
, rel
,
5126 relend
, h
, r_symndx
, TRUE
))
5129 if (r_type
!= R_386_TLS_LDM
)
5131 /* LD->LE transition. Change
5132 leal foo@tlsldm(%ebx) %eax
5133 call ___tls_get_addr@PLT
5137 leal 0(%esi,1), %esi
5139 leal foo@tlsldm(%reg) %eax
5140 call *___tls_get_addr@GOT(%reg)
5141 which may be converted to
5142 addr32 call ___tls_get_addr
5145 leal 0(%esi), %esi */
5146 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
5147 if (*(contents
+ rel
->r_offset
+ 4) == 0xff
5148 || *(contents
+ rel
->r_offset
+ 4) == 0x67)
5149 memcpy (contents
+ rel
->r_offset
- 2,
5150 "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
5152 memcpy (contents
+ rel
->r_offset
- 2,
5153 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
5154 /* Skip R_386_PC32/R_386_PLT32. */
5160 if (htab
->elf
.sgot
== NULL
)
5163 off
= htab
->tls_ldm_got
.offset
;
5168 Elf_Internal_Rela outrel
;
5170 if (htab
->elf
.srelgot
== NULL
)
5173 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5174 + htab
->elf
.sgot
->output_offset
+ off
);
5176 bfd_put_32 (output_bfd
, 0,
5177 htab
->elf
.sgot
->contents
+ off
);
5178 bfd_put_32 (output_bfd
, 0,
5179 htab
->elf
.sgot
->contents
+ off
+ 4);
5180 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
5181 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
5182 htab
->tls_ldm_got
.offset
|= 1;
5184 relocation
= htab
->elf
.sgot
->output_section
->vma
5185 + htab
->elf
.sgot
->output_offset
+ off
5186 - htab
->elf
.sgotplt
->output_section
->vma
5187 - htab
->elf
.sgotplt
->output_offset
;
5188 unresolved_reloc
= FALSE
;
5191 case R_386_TLS_LDO_32
:
5192 if (!bfd_link_executable (info
)
5193 || (input_section
->flags
& SEC_CODE
) == 0)
5194 relocation
-= elf_i386_dtpoff_base (info
);
5196 /* When converting LDO to LE, we must negate. */
5197 relocation
= -elf_i386_tpoff (info
, relocation
);
5200 case R_386_TLS_LE_32
:
5202 if (!bfd_link_executable (info
))
5204 Elf_Internal_Rela outrel
;
5207 outrel
.r_offset
= rel
->r_offset
5208 + input_section
->output_section
->vma
5209 + input_section
->output_offset
;
5210 if (h
!= NULL
&& h
->dynindx
!= -1)
5214 if (r_type
== R_386_TLS_LE_32
)
5215 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
5217 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
5218 sreloc
= elf_section_data (input_section
)->sreloc
;
5221 elf_append_rel (output_bfd
, sreloc
, &outrel
);
5224 else if (r_type
== R_386_TLS_LE_32
)
5225 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
5227 relocation
-= elf_i386_dtpoff_base (info
);
5229 else if (r_type
== R_386_TLS_LE_32
)
5230 relocation
= elf_i386_tpoff (info
, relocation
);
5232 relocation
= -elf_i386_tpoff (info
, relocation
);
5239 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5240 because such sections are not SEC_ALLOC and thus ld.so will
5241 not process them. */
5242 if (unresolved_reloc
5243 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5245 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5246 rel
->r_offset
) != (bfd_vma
) -1)
5249 /* xgettext:c-format */
5250 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5253 (long) rel
->r_offset
,
5255 h
->root
.root
.string
);
5260 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5261 contents
, rel
->r_offset
,
5264 check_relocation_error
:
5265 if (r
!= bfd_reloc_ok
)
5270 name
= h
->root
.root
.string
;
5273 name
= bfd_elf_string_from_elf_section (input_bfd
,
5274 symtab_hdr
->sh_link
,
5279 name
= bfd_section_name (input_bfd
, sec
);
5282 if (r
== bfd_reloc_overflow
)
5283 (*info
->callbacks
->reloc_overflow
)
5284 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5285 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5289 /* xgettext:c-format */
5290 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5291 input_bfd
, input_section
,
5292 (long) rel
->r_offset
, name
, (int) r
);
5303 Elf_Internal_Shdr
*rel_hdr
;
5304 size_t deleted
= rel
- wrel
;
5306 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5307 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5308 if (rel_hdr
->sh_size
== 0)
5310 /* It is too late to remove an empty reloc section. Leave
5312 ??? What is wrong with an empty section??? */
5313 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5316 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5317 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5318 input_section
->reloc_count
-= deleted
;
5324 /* Finish up dynamic symbol handling. We set the contents of various
5325 dynamic sections here. */
5328 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
5329 struct bfd_link_info
*info
,
5330 struct elf_link_hash_entry
*h
,
5331 Elf_Internal_Sym
*sym
)
5333 struct elf_i386_link_hash_table
*htab
;
5334 unsigned plt_entry_size
;
5335 const struct elf_i386_backend_data
*abed
;
5336 struct elf_i386_link_hash_entry
*eh
;
5337 bfd_boolean local_undefweak
;
5339 htab
= elf_i386_hash_table (info
);
5343 abed
= get_elf_i386_backend_data (output_bfd
);
5344 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
5346 eh
= (struct elf_i386_link_hash_entry
*) h
;
5347 if (eh
->no_finish_dynamic_symbol
)
5350 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5351 resolved undefined weak symbols in executable so that their
5352 references have value 0 at run-time. */
5353 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5357 if (h
->plt
.offset
!= (bfd_vma
) -1)
5361 Elf_Internal_Rela rel
;
5363 asection
*plt
, *gotplt
, *relplt
;
5365 /* When building a static executable, use .iplt, .igot.plt and
5366 .rel.iplt sections for STT_GNU_IFUNC symbols. */
5367 if (htab
->elf
.splt
!= NULL
)
5369 plt
= htab
->elf
.splt
;
5370 gotplt
= htab
->elf
.sgotplt
;
5371 relplt
= htab
->elf
.srelplt
;
5375 plt
= htab
->elf
.iplt
;
5376 gotplt
= htab
->elf
.igotplt
;
5377 relplt
= htab
->elf
.irelplt
;
5380 /* This symbol has an entry in the procedure linkage table. Set
5383 if ((h
->dynindx
== -1
5385 && !((h
->forced_local
|| bfd_link_executable (info
))
5387 && h
->type
== STT_GNU_IFUNC
))
5393 /* Get the index in the procedure linkage table which
5394 corresponds to this symbol. This is the index of this symbol
5395 in all the symbols for which we are making plt entries. The
5396 first entry in the procedure linkage table is reserved.
5398 Get the offset into the .got table of the entry that
5399 corresponds to this function. Each .got entry is 4 bytes.
5400 The first three are reserved.
5402 For static executables, we don't reserve anything. */
5404 if (plt
== htab
->elf
.splt
)
5406 got_offset
= h
->plt
.offset
/ plt_entry_size
- 1;
5407 got_offset
= (got_offset
+ 3) * 4;
5411 got_offset
= h
->plt
.offset
/ plt_entry_size
;
5412 got_offset
= got_offset
* 4;
5415 /* Fill in the entry in the procedure linkage table. */
5416 if (! bfd_link_pic (info
))
5418 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->plt_entry
,
5419 abed
->plt
->plt_entry_size
);
5420 bfd_put_32 (output_bfd
,
5421 (gotplt
->output_section
->vma
5422 + gotplt
->output_offset
5424 plt
->contents
+ h
->plt
.offset
5425 + abed
->plt
->plt_got_offset
);
5427 if (abed
->is_vxworks
)
5429 int s
, k
, reloc_index
;
5431 /* Create the R_386_32 relocation referencing the GOT
5432 for this PLT entry. */
5434 /* S: Current slot number (zero-based). */
5435 s
= ((h
->plt
.offset
- abed
->plt
->plt_entry_size
)
5436 / abed
->plt
->plt_entry_size
);
5437 /* K: Number of relocations for PLTResolve. */
5438 if (bfd_link_pic (info
))
5439 k
= PLTRESOLVE_RELOCS_SHLIB
;
5441 k
= PLTRESOLVE_RELOCS
;
5442 /* Skip the PLTresolve relocations, and the relocations for
5443 the other PLT slots. */
5444 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
5445 loc
= (htab
->srelplt2
->contents
+ reloc_index
5446 * sizeof (Elf32_External_Rel
));
5448 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5449 + htab
->elf
.splt
->output_offset
5450 + h
->plt
.offset
+ 2),
5451 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5452 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5454 /* Create the R_386_32 relocation referencing the beginning of
5455 the PLT for this GOT entry. */
5456 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5457 + htab
->elf
.sgotplt
->output_offset
5459 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5460 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5461 loc
+ sizeof (Elf32_External_Rel
));
5466 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->pic_plt_entry
,
5467 abed
->plt
->plt_entry_size
);
5468 bfd_put_32 (output_bfd
, got_offset
,
5469 plt
->contents
+ h
->plt
.offset
5470 + abed
->plt
->plt_got_offset
);
5473 /* Fill in the entry in the global offset table. Leave the entry
5474 as zero for undefined weak symbol in PIE. No PLT relocation
5475 against undefined weak symbol in PIE. */
5476 if (!local_undefweak
)
5478 bfd_put_32 (output_bfd
,
5479 (plt
->output_section
->vma
5480 + plt
->output_offset
5482 + abed
->plt
->plt_lazy_offset
),
5483 gotplt
->contents
+ got_offset
);
5485 /* Fill in the entry in the .rel.plt section. */
5486 rel
.r_offset
= (gotplt
->output_section
->vma
5487 + gotplt
->output_offset
5489 if (h
->dynindx
== -1
5490 || ((bfd_link_executable (info
)
5491 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5493 && h
->type
== STT_GNU_IFUNC
))
5495 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5496 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
5497 in the .got.plt section. */
5498 bfd_put_32 (output_bfd
,
5499 (h
->root
.u
.def
.value
5500 + h
->root
.u
.def
.section
->output_section
->vma
5501 + h
->root
.u
.def
.section
->output_offset
),
5502 gotplt
->contents
+ got_offset
);
5503 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5504 /* R_386_IRELATIVE comes last. */
5505 plt_index
= htab
->next_irelative_index
--;
5509 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
5510 plt_index
= htab
->next_jump_slot_index
++;
5513 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5514 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5516 /* Don't fill PLT entry for static executables. */
5517 if (plt
== htab
->elf
.splt
)
5519 bfd_put_32 (output_bfd
,
5520 plt_index
* sizeof (Elf32_External_Rel
),
5521 plt
->contents
+ h
->plt
.offset
5522 + abed
->plt
->plt_reloc_offset
);
5523 bfd_put_32 (output_bfd
, - (h
->plt
.offset
5524 + abed
->plt
->plt_plt_offset
+ 4),
5525 plt
->contents
+ h
->plt
.offset
5526 + abed
->plt
->plt_plt_offset
);
5530 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5532 bfd_vma got_offset
, plt_offset
;
5533 asection
*plt
, *got
, *gotplt
;
5534 const bfd_byte
*got_plt_entry
;
5536 /* Offset of displacement of the indirect jump. */
5537 bfd_vma plt_got_offset
= 2;
5539 /* Set the entry in the GOT procedure linkage table. */
5540 plt
= htab
->plt_got
;
5541 got
= htab
->elf
.sgot
;
5542 gotplt
= htab
->elf
.sgotplt
;
5543 got_offset
= h
->got
.offset
;
5545 if (got_offset
== (bfd_vma
) -1
5551 /* Fill in the entry in the GOT procedure linkage table. */
5552 if (! bfd_link_pic (info
))
5554 got_plt_entry
= elf_i386_got_plt_entry
;
5555 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
5559 got_plt_entry
= elf_i386_pic_got_plt_entry
;
5560 got_offset
+= (got
->output_section
->vma
5561 + got
->output_offset
5562 - gotplt
->output_section
->vma
5563 - gotplt
->output_offset
);
5566 plt_offset
= eh
->plt_got
.offset
;
5567 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
5568 sizeof (elf_i386_got_plt_entry
));
5569 bfd_put_32 (output_bfd
, got_offset
,
5570 plt
->contents
+ plt_offset
+ plt_got_offset
);
5573 if (!local_undefweak
5575 && (h
->plt
.offset
!= (bfd_vma
) -1
5576 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5578 /* Mark the symbol as undefined, rather than as defined in
5579 the .plt section. Leave the value if there were any
5580 relocations where pointer equality matters (this is a clue
5581 for the dynamic linker, to make function pointer
5582 comparisons work between an application and shared
5583 library), otherwise set it to zero. If a function is only
5584 called from a binary, there is no need to slow down
5585 shared libraries because of that. */
5586 sym
->st_shndx
= SHN_UNDEF
;
5587 if (!h
->pointer_equality_needed
)
5591 /* Don't generate dynamic GOT relocation against undefined weak
5592 symbol in executable. */
5593 if (h
->got
.offset
!= (bfd_vma
) -1
5594 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
5595 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0
5596 && !local_undefweak
)
5598 Elf_Internal_Rela rel
;
5599 asection
*relgot
= htab
->elf
.srelgot
;
5601 /* This symbol has an entry in the global offset table. Set it
5604 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5607 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5608 + htab
->elf
.sgot
->output_offset
5609 + (h
->got
.offset
& ~(bfd_vma
) 1));
5611 /* If this is a static link, or it is a -Bsymbolic link and the
5612 symbol is defined locally or was forced to be local because
5613 of a version file, we just want to emit a RELATIVE reloc.
5614 The entry in the global offset table will already have been
5615 initialized in the relocate_section function. */
5617 && h
->type
== STT_GNU_IFUNC
)
5619 if (h
->plt
.offset
== (bfd_vma
) -1)
5621 /* STT_GNU_IFUNC is referenced without PLT. */
5622 if (htab
->elf
.splt
== NULL
)
5624 /* use .rel[a].iplt section to store .got relocations
5625 in static executable. */
5626 relgot
= htab
->elf
.irelplt
;
5628 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5630 bfd_put_32 (output_bfd
,
5631 (h
->root
.u
.def
.value
5632 + h
->root
.u
.def
.section
->output_section
->vma
5633 + h
->root
.u
.def
.section
->output_offset
),
5634 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5635 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
5640 else if (bfd_link_pic (info
))
5642 /* Generate R_386_GLOB_DAT. */
5649 if (!h
->pointer_equality_needed
)
5652 /* For non-shared object, we can't use .got.plt, which
5653 contains the real function addres if we need pointer
5654 equality. We load the GOT entry with the PLT entry. */
5655 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5656 bfd_put_32 (output_bfd
,
5657 (plt
->output_section
->vma
5658 + plt
->output_offset
+ h
->plt
.offset
),
5659 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5663 else if (bfd_link_pic (info
)
5664 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5666 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5667 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
5671 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5673 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5674 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5675 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
5678 elf_append_rel (output_bfd
, relgot
, &rel
);
5683 Elf_Internal_Rela rel
;
5686 /* This symbol needs a copy reloc. Set it up. */
5688 if (h
->dynindx
== -1
5689 || (h
->root
.type
!= bfd_link_hash_defined
5690 && h
->root
.type
!= bfd_link_hash_defweak
)
5691 || htab
->elf
.srelbss
== NULL
5692 || htab
->elf
.sreldynrelro
== NULL
)
5695 rel
.r_offset
= (h
->root
.u
.def
.value
5696 + h
->root
.u
.def
.section
->output_section
->vma
5697 + h
->root
.u
.def
.section
->output_offset
);
5698 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5699 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5700 s
= htab
->elf
.sreldynrelro
;
5702 s
= htab
->elf
.srelbss
;
5703 elf_append_rel (output_bfd
, s
, &rel
);
5709 /* Finish up local dynamic symbol handling. We set the contents of
5710 various dynamic sections here. */
5713 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5715 struct elf_link_hash_entry
*h
5716 = (struct elf_link_hash_entry
*) *slot
;
5717 struct bfd_link_info
*info
5718 = (struct bfd_link_info
*) inf
;
5720 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5724 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5725 here since undefined weak symbol may not be dynamic and may not be
5726 called for elf_i386_finish_dynamic_symbol. */
5729 elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5732 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5733 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5735 if (h
->root
.type
!= bfd_link_hash_undefweak
5736 || h
->dynindx
!= -1)
5739 return elf_i386_finish_dynamic_symbol (info
->output_bfd
,
5743 /* Used to decide how to sort relocs in an optimal manner for the
5744 dynamic linker, before writing them out. */
5746 static enum elf_reloc_type_class
5747 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5748 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5749 const Elf_Internal_Rela
*rela
)
5751 bfd
*abfd
= info
->output_bfd
;
5752 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5753 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5755 if (htab
->dynsym
!= NULL
5756 && htab
->dynsym
->contents
!= NULL
)
5758 /* Check relocation against STT_GNU_IFUNC symbol if there are
5760 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5761 if (r_symndx
!= STN_UNDEF
)
5763 Elf_Internal_Sym sym
;
5764 if (!bed
->s
->swap_symbol_in (abfd
,
5765 (htab
->dynsym
->contents
5766 + r_symndx
* sizeof (Elf32_External_Sym
)),
5770 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5771 return reloc_class_ifunc
;
5775 switch (ELF32_R_TYPE (rela
->r_info
))
5777 case R_386_IRELATIVE
:
5778 return reloc_class_ifunc
;
5779 case R_386_RELATIVE
:
5780 return reloc_class_relative
;
5781 case R_386_JUMP_SLOT
:
5782 return reloc_class_plt
;
5784 return reloc_class_copy
;
5786 return reloc_class_normal
;
5790 /* Finish up the dynamic sections. */
5793 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5794 struct bfd_link_info
*info
)
5796 struct elf_i386_link_hash_table
*htab
;
5799 const struct elf_i386_backend_data
*abed
;
5801 htab
= elf_i386_hash_table (info
);
5805 dynobj
= htab
->elf
.dynobj
;
5806 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5807 abed
= get_elf_i386_backend_data (output_bfd
);
5809 if (htab
->elf
.dynamic_sections_created
)
5811 Elf32_External_Dyn
*dyncon
, *dynconend
;
5813 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5816 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5817 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5818 for (; dyncon
< dynconend
; dyncon
++)
5820 Elf_Internal_Dyn dyn
;
5823 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5828 if (abed
->is_vxworks
5829 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5834 s
= htab
->elf
.sgotplt
;
5835 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5839 s
= htab
->elf
.srelplt
;
5840 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5844 s
= htab
->elf
.srelplt
;
5845 dyn
.d_un
.d_val
= s
->size
;
5849 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5852 /* Fill in the first entry in the procedure linkage table. */
5853 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5855 if (bfd_link_pic (info
))
5857 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->pic_plt0_entry
,
5858 abed
->plt
->plt0_entry_size
);
5859 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5860 abed
->plt0_pad_byte
,
5861 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5865 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->plt0_entry
,
5866 abed
->plt
->plt0_entry_size
);
5867 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5868 abed
->plt0_pad_byte
,
5869 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5870 bfd_put_32 (output_bfd
,
5871 (htab
->elf
.sgotplt
->output_section
->vma
5872 + htab
->elf
.sgotplt
->output_offset
5874 htab
->elf
.splt
->contents
5875 + abed
->plt
->plt0_got1_offset
);
5876 bfd_put_32 (output_bfd
,
5877 (htab
->elf
.sgotplt
->output_section
->vma
5878 + htab
->elf
.sgotplt
->output_offset
5880 htab
->elf
.splt
->contents
5881 + abed
->plt
->plt0_got2_offset
);
5883 if (abed
->is_vxworks
)
5885 Elf_Internal_Rela rel
;
5887 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
5888 On IA32 we use REL relocations so the addend goes in
5889 the PLT directly. */
5890 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5891 + htab
->elf
.splt
->output_offset
5892 + abed
->plt
->plt0_got1_offset
);
5893 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5894 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5895 htab
->srelplt2
->contents
);
5896 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
5897 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5898 + htab
->elf
.splt
->output_offset
5899 + abed
->plt
->plt0_got2_offset
);
5900 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5901 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5902 htab
->srelplt2
->contents
+
5903 sizeof (Elf32_External_Rel
));
5907 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5908 really seem like the right value. */
5909 elf_section_data (htab
->elf
.splt
->output_section
)
5910 ->this_hdr
.sh_entsize
= 4;
5912 /* Correct the .rel.plt.unloaded relocations. */
5913 if (abed
->is_vxworks
&& !bfd_link_pic (info
))
5915 int num_plts
= (htab
->elf
.splt
->size
5916 / abed
->plt
->plt_entry_size
) - 1;
5919 p
= htab
->srelplt2
->contents
;
5920 if (bfd_link_pic (info
))
5921 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
5923 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
5925 for (; num_plts
; num_plts
--)
5927 Elf_Internal_Rela rel
;
5928 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5929 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5930 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5931 p
+= sizeof (Elf32_External_Rel
);
5933 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5934 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5935 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5936 p
+= sizeof (Elf32_External_Rel
);
5942 if (htab
->elf
.sgotplt
)
5944 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5947 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5951 /* Fill in the first three entries in the global offset table. */
5952 if (htab
->elf
.sgotplt
->size
> 0)
5954 bfd_put_32 (output_bfd
,
5956 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
5957 htab
->elf
.sgotplt
->contents
);
5958 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
5959 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
5962 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
5965 /* Adjust .eh_frame for .plt section. */
5966 if (htab
->plt_eh_frame
!= NULL
5967 && htab
->plt_eh_frame
->contents
!= NULL
)
5969 if (htab
->elf
.splt
!= NULL
5970 && htab
->elf
.splt
->size
!= 0
5971 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5972 && htab
->elf
.splt
->output_section
!= NULL
5973 && htab
->plt_eh_frame
->output_section
!= NULL
)
5975 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5976 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5977 + htab
->plt_eh_frame
->output_offset
5978 + PLT_FDE_START_OFFSET
;
5979 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5980 htab
->plt_eh_frame
->contents
5981 + PLT_FDE_START_OFFSET
);
5983 if (htab
->plt_eh_frame
->sec_info_type
5984 == SEC_INFO_TYPE_EH_FRAME
)
5986 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5988 htab
->plt_eh_frame
->contents
))
5993 /* Adjust .eh_frame for .plt.got section. */
5994 if (htab
->plt_got_eh_frame
!= NULL
5995 && htab
->plt_got_eh_frame
->contents
!= NULL
)
5997 if (htab
->plt_got
!= NULL
5998 && htab
->plt_got
->size
!= 0
5999 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6000 && htab
->plt_got
->output_section
!= NULL
6001 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6003 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6004 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6005 + htab
->plt_got_eh_frame
->output_offset
6006 + PLT_FDE_START_OFFSET
;
6007 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6008 htab
->plt_got_eh_frame
->contents
6009 + PLT_FDE_START_OFFSET
);
6011 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6013 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6014 htab
->plt_got_eh_frame
,
6015 htab
->plt_got_eh_frame
->contents
))
6020 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6021 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6023 /* Fill PLT entries for undefined weak symbols in PIE. */
6024 if (bfd_link_pie (info
))
6025 bfd_hash_traverse (&info
->hash
->table
,
6026 elf_i386_pie_finish_undefweak_symbol
,
6032 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6033 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6034 It has to be done before elf_link_sort_relocs is called so that
6035 dynamic relocations are properly sorted. */
6038 elf_i386_output_arch_local_syms
6039 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6040 struct bfd_link_info
*info
,
6041 void *flaginfo ATTRIBUTE_UNUSED
,
6042 int (*func
) (void *, const char *,
6045 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6047 struct elf_i386_link_hash_table
*htab
= elf_i386_hash_table (info
);
6051 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6052 htab_traverse (htab
->loc_hash_table
,
6053 elf_i386_finish_local_dynamic_symbol
,
6059 /* Return an array of PLT entry symbol values. */
6062 elf_i386_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
6065 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
6068 bfd_vma
*plt_sym_val
;
6070 bfd_byte
*plt_contents
;
6071 const struct elf_i386_backend_data
*bed
6072 = get_elf_i386_backend_data (abfd
);
6073 Elf_Internal_Shdr
*hdr
;
6075 /* Get the .plt section contents. */
6076 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6077 if (plt_contents
== NULL
)
6079 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6080 plt_contents
, 0, plt
->size
))
6083 free (plt_contents
);
6087 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
6088 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
6091 hdr
= &elf_section_data (relplt
)->this_hdr
;
6092 count
= relplt
->size
/ hdr
->sh_entsize
;
6094 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
6095 if (plt_sym_val
== NULL
)
6098 for (i
= 0; i
< count
; i
++)
6099 plt_sym_val
[i
] = -1;
6101 plt_offset
= bed
->plt
->plt_entry_size
;
6102 p
= relplt
->relocation
;
6103 for (i
= 0; i
< count
; i
++, p
++)
6107 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6108 if (p
->howto
== NULL
)
6111 if (p
->howto
->type
!= R_386_JUMP_SLOT
6112 && p
->howto
->type
!= R_386_IRELATIVE
)
6115 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
6116 + bed
->plt
->plt_reloc_offset
));
6117 reloc_index
/= sizeof (Elf32_External_Rel
);
6118 if (reloc_index
< count
)
6119 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
6121 plt_offset
+= bed
->plt
->plt_entry_size
;
6123 /* PR binutils/18437: Skip extra relocations in the .rel.plt
6125 if (plt_offset
>= plt
->size
)
6129 free (plt_contents
);
6134 /* Similar to _bfd_elf_get_synthetic_symtab. */
6137 elf_i386_get_synthetic_symtab (bfd
*abfd
,
6144 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt");
6145 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
6146 dynsymcount
, dynsyms
, ret
,
6148 elf_i386_get_plt_sym_val
);
6151 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6154 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
6156 if (h
->plt
.offset
!= (bfd_vma
) -1
6158 && !h
->pointer_equality_needed
)
6161 return _bfd_elf_hash_symbol (h
);
6164 /* Parse i386 GNU properties. */
6166 static enum elf_property_kind
6167 elf_i386_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6168 bfd_byte
*ptr
, unsigned int datasz
)
6174 case GNU_PROPERTY_X86_ISA_1_USED
:
6175 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6179 ((type
== GNU_PROPERTY_X86_ISA_1_USED
6180 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6181 : _("error: %B: <corrupt x86 ISA needed size: 0x%x>")),
6183 return property_corrupt
;
6185 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
6186 prop
->u
.number
= bfd_h_get_32 (abfd
, ptr
);
6187 prop
->pr_kind
= property_number
;
6191 return property_ignored
;
6194 return property_number
;
6197 /* Merge i386 GNU property BPROP with APROP. If APROP isn't NULL,
6198 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6199 should be merged with ABFD. */
6202 elf_i386_merge_gnu_properties (bfd
*abfd ATTRIBUTE_UNUSED
,
6203 elf_property
*aprop
,
6204 elf_property
*bprop
)
6206 unsigned int number
;
6207 bfd_boolean updated
= FALSE
;
6208 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
6212 case GNU_PROPERTY_X86_ISA_1_USED
:
6213 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6214 if (aprop
!= NULL
&& bprop
!= NULL
)
6216 number
= aprop
->u
.number
;
6217 aprop
->u
.number
= number
| bprop
->u
.number
;
6218 updated
= number
!= (unsigned int) aprop
->u
.number
;
6222 /* Return TRUE if APROP is NULL to indicate that BPROP should
6223 be added to ABFD. */
6224 updated
= aprop
== NULL
;
6229 /* Never should happen. */
6236 #define TARGET_LITTLE_SYM i386_elf32_vec
6237 #define TARGET_LITTLE_NAME "elf32-i386"
6238 #define ELF_ARCH bfd_arch_i386
6239 #define ELF_TARGET_ID I386_ELF_DATA
6240 #define ELF_MACHINE_CODE EM_386
6241 #define ELF_MAXPAGESIZE 0x1000
6243 #define elf_backend_can_gc_sections 1
6244 #define elf_backend_can_refcount 1
6245 #define elf_backend_want_got_plt 1
6246 #define elf_backend_plt_readonly 1
6247 #define elf_backend_want_plt_sym 0
6248 #define elf_backend_got_header_size 12
6249 #define elf_backend_plt_alignment 4
6250 #define elf_backend_dtrel_excludes_plt 1
6251 #define elf_backend_extern_protected_data 1
6252 #define elf_backend_caches_rawsize 1
6253 #define elf_backend_want_dynrelro 1
6255 /* Support RELA for objdump of prelink objects. */
6256 #define elf_info_to_howto elf_i386_info_to_howto_rel
6257 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
6259 #define bfd_elf32_mkobject elf_i386_mkobject
6261 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
6262 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
6263 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
6264 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
6265 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
6267 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
6268 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
6269 #define elf_backend_check_relocs elf_i386_check_relocs
6270 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
6271 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
6272 #define elf_backend_fake_sections elf_i386_fake_sections
6273 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
6274 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
6275 #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
6276 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
6277 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
6278 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
6279 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
6280 #define elf_backend_relocate_section elf_i386_relocate_section
6281 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
6282 #define elf_backend_always_size_sections elf_i386_always_size_sections
6283 #define elf_backend_omit_section_dynsym \
6284 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
6285 #define elf_backend_hash_symbol elf_i386_hash_symbol
6286 #define elf_backend_fixup_symbol elf_i386_fixup_symbol
6287 #define elf_backend_parse_gnu_properties elf_i386_parse_gnu_properties
6288 #define elf_backend_merge_gnu_properties elf_i386_merge_gnu_properties
6290 #include "elf32-target.h"
6292 /* FreeBSD support. */
6294 #undef TARGET_LITTLE_SYM
6295 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
6296 #undef TARGET_LITTLE_NAME
6297 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
6299 #define ELF_OSABI ELFOSABI_FREEBSD
6301 /* The kernel recognizes executables as valid only if they carry a
6302 "FreeBSD" label in the ELF header. So we put this label on all
6303 executables and (for simplicity) also all other object files. */
6306 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
6308 _bfd_elf_post_process_headers (abfd
, info
);
6310 #ifdef OLD_FREEBSD_ABI_LABEL
6312 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
6313 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
6314 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
6319 #undef elf_backend_post_process_headers
6320 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
6322 #define elf32_bed elf32_i386_fbsd_bed
6324 #undef elf_backend_add_symbol_hook
6326 #include "elf32-target.h"
6330 #undef TARGET_LITTLE_SYM
6331 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
6332 #undef TARGET_LITTLE_NAME
6333 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
6335 #undef elf_backend_post_process_headers
6337 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
6338 objects won't be recognized. */
6342 #define elf32_bed elf32_i386_sol2_bed
6344 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
6346 #undef elf_backend_static_tls_alignment
6347 #define elf_backend_static_tls_alignment 8
6349 /* The Solaris 2 ABI requires a plt symbol on all platforms.
6351 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
6353 #undef elf_backend_want_plt_sym
6354 #define elf_backend_want_plt_sym 1
6356 #undef elf_backend_strtab_flags
6357 #define elf_backend_strtab_flags SHF_STRINGS
6359 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
6360 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
6361 FALSE otherwise. ISECTION is the best guess matching section from the
6362 input bfd IBFD, but it might be NULL. */
6365 elf32_i386_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
6366 bfd
*obfd ATTRIBUTE_UNUSED
,
6367 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
6368 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
6370 /* PR 19938: FIXME: Need to add code for setting the sh_info
6371 and sh_link fields of Solaris specific section types. */
6374 /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
6375 Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
6377 http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
6379 The following values should be set:
6382 -----------------------------------------------------------------------------
6383 SHT_SUNW_ancillary The section header index of 0
6384 [0x6fffffee] the associated string table.
6386 SHT_SUNW_capinfo The section header index of For a dynamic object, the
6387 [0x6ffffff0] the associated symbol table. section header index of
6389 SHT_SUNW_capchain table,
6392 SHT_SUNW_symsort The section header index of 0
6393 [0x6ffffff1] the associated symbol table.
6395 SHT_SUNW_tlssort The section header index of 0
6396 [0x6ffffff2] the associated symbol table.
6398 SHT_SUNW_LDYNSYM The section header index of One greater than the
6399 [0x6ffffff3] the associated string table. symbol table index of the
6400 This index is the same string last local symbol,
6401 table used by the SHT_DYNSYM STB_LOCAL. Since
6402 section. SHT_SUNW_LDYNSYM only
6403 contains local symbols,
6404 sh_info is equivalent to
6405 the number of symbols in
6408 SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
6409 [0x6ffffff5] the section header index of to named strings, the
6410 the associated section header index of
6411 SHT_SUNW_capinfo table, the associated string
6412 otherwise 0. table, otherwise 0.
6414 SHT_SUNW_move The section header index of 0
6415 [0x6ffffffa] the associated symbol table.
6420 SHT_SUNW_syminfo The section header index of The section header index
6421 [0x6ffffffc] the associated symbol table. of the associated
6424 SHT_SUNW_verdef The section header index of The number of version
6425 [0x6ffffffd] the associated string table. definitions within the
6428 SHT_SUNW_verneed The section header index of The number of version
6429 [0x6ffffffe] the associated string table. dependencies within the
6432 SHT_SUNW_versym The section header index of 0
6433 [0x6fffffff] the associated symbol table. */
6436 #undef elf_backend_copy_special_section_fields
6437 #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
6439 #include "elf32-target.h"
6441 /* Intel MCU support. */
6444 elf32_iamcu_elf_object_p (bfd
*abfd
)
6446 /* Set the right machine number for an IAMCU elf32 file. */
6447 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
6451 #undef TARGET_LITTLE_SYM
6452 #define TARGET_LITTLE_SYM iamcu_elf32_vec
6453 #undef TARGET_LITTLE_NAME
6454 #define TARGET_LITTLE_NAME "elf32-iamcu"
6456 #define ELF_ARCH bfd_arch_iamcu
6458 #undef ELF_MACHINE_CODE
6459 #define ELF_MACHINE_CODE EM_IAMCU
6464 #define elf32_bed elf32_iamcu_bed
6466 #undef elf_backend_object_p
6467 #define elf_backend_object_p elf32_iamcu_elf_object_p
6469 #undef elf_backend_static_tls_alignment
6471 #undef elf_backend_want_plt_sym
6472 #define elf_backend_want_plt_sym 0
6474 #undef elf_backend_strtab_flags
6475 #undef elf_backend_copy_special_section_fields
6477 #include "elf32-target.h"
6479 /* Restore defaults. */
6481 #define ELF_ARCH bfd_arch_i386
6482 #undef ELF_MACHINE_CODE
6483 #define ELF_MACHINE_CODE EM_386
6485 /* Native Client support. */
6487 #undef TARGET_LITTLE_SYM
6488 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
6489 #undef TARGET_LITTLE_NAME
6490 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
6492 #define elf32_bed elf32_i386_nacl_bed
6494 #undef ELF_MAXPAGESIZE
6495 #define ELF_MAXPAGESIZE 0x10000
6497 /* Restore defaults. */
6499 #undef elf_backend_want_plt_sym
6500 #define elf_backend_want_plt_sym 0
6501 #undef elf_backend_post_process_headers
6502 #undef elf_backend_static_tls_alignment
6504 /* NaCl uses substantially different PLT entries for the same effects. */
6506 #undef elf_backend_plt_alignment
6507 #define elf_backend_plt_alignment 5
6508 #define NACL_PLT_ENTRY_SIZE 64
6509 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
6511 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
6513 0xff, 0x35, /* pushl contents of address */
6514 0, 0, 0, 0, /* replaced with address of .got + 4. */
6515 0x8b, 0x0d, /* movl contents of address, %ecx */
6516 0, 0, 0, 0, /* replaced with address of .got + 8. */
6517 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6518 0xff, 0xe1 /* jmp *%ecx */
6521 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6523 0x8b, 0x0d, /* movl contents of address, %ecx */
6524 0, 0, 0, 0, /* replaced with GOT slot address. */
6525 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
6526 0xff, 0xe1, /* jmp *%ecx */
6528 /* Pad to the next 32-byte boundary with nop instructions. */
6530 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6531 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6533 /* Lazy GOT entries point here (32-byte aligned). */
6534 0x68, /* pushl immediate */
6535 0, 0, 0, 0, /* replaced with reloc offset. */
6536 0xe9, /* jmp relative */
6537 0, 0, 0, 0, /* replaced with offset to .plt. */
6539 /* Pad to the next 32-byte boundary with nop instructions. */
6540 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6541 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6545 static const bfd_byte
6546 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
6548 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
6549 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
6550 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
6551 0xff, 0xe1, /* jmp *%ecx */
6553 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
6554 so pad to that size with nop instructions. */
6555 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
6558 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6560 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
6561 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
6562 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
6563 0xff, 0xe1, /* jmp *%ecx */
6565 /* Pad to the next 32-byte boundary with nop instructions. */
6567 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6568 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6570 /* Lazy GOT entries point here (32-byte aligned). */
6571 0x68, /* pushl immediate */
6572 0, 0, 0, 0, /* replaced with offset into relocation table. */
6573 0xe9, /* jmp relative */
6574 0, 0, 0, 0, /* replaced with offset to start of .plt. */
6576 /* Pad to the next 32-byte boundary with nop instructions. */
6577 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6578 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
6582 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
6584 #if (PLT_CIE_LENGTH != 20 \
6585 || PLT_FDE_LENGTH != 36 \
6586 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
6587 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
6588 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
6590 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
6591 0, 0, 0, 0, /* CIE ID */
6592 1, /* CIE version */
6593 'z', 'R', 0, /* Augmentation string */
6594 1, /* Code alignment factor */
6595 0x7c, /* Data alignment factor: -4 */
6596 8, /* Return address column */
6597 1, /* Augmentation size */
6598 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
6599 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
6600 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
6601 DW_CFA_nop
, DW_CFA_nop
,
6603 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
6604 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
6605 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
6606 0, 0, 0, 0, /* .plt size goes here */
6607 0, /* Augmentation size */
6608 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
6609 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
6610 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
6611 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
6612 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
6613 13, /* Block length */
6614 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
6615 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
6616 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
6617 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
6618 DW_CFA_nop
, DW_CFA_nop
6621 static const struct elf_i386_plt_layout elf_i386_nacl_plt
=
6623 elf_i386_nacl_plt0_entry
, /* plt0_entry */
6624 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
6625 2, /* plt0_got1_offset */
6626 8, /* plt0_got2_offset */
6627 elf_i386_nacl_plt_entry
, /* plt_entry */
6628 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
6629 2, /* plt_got_offset */
6630 33, /* plt_reloc_offset */
6631 38, /* plt_plt_offset */
6632 32, /* plt_lazy_offset */
6633 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
6634 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
6635 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
6636 sizeof (elf_i386_nacl_eh_frame_plt
),/* eh_frame_plt_size */
6637 NULL
, /* eh_frame_plt_got */
6638 0, /* eh_frame_plt_got_size */
6641 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
6643 &elf_i386_nacl_plt
, /* plt */
6644 0x90, /* plt0_pad_byte: nop insn */
6649 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
6651 /* Set the right machine number for a NaCl i386 ELF32 file. */
6652 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
6656 #undef elf_backend_arch_data
6657 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
6659 #undef elf_backend_object_p
6660 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
6661 #undef elf_backend_modify_segment_map
6662 #define elf_backend_modify_segment_map nacl_modify_segment_map
6663 #undef elf_backend_modify_program_headers
6664 #define elf_backend_modify_program_headers nacl_modify_program_headers
6665 #undef elf_backend_final_write_processing
6666 #define elf_backend_final_write_processing nacl_final_write_processing
6668 #include "elf32-target.h"
6670 /* Restore defaults. */
6671 #undef elf_backend_object_p
6672 #undef elf_backend_modify_segment_map
6673 #undef elf_backend_modify_program_headers
6674 #undef elf_backend_final_write_processing
6676 /* VxWorks support. */
6678 #undef TARGET_LITTLE_SYM
6679 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
6680 #undef TARGET_LITTLE_NAME
6681 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
6683 #undef ELF_MAXPAGESIZE
6684 #define ELF_MAXPAGESIZE 0x1000
6685 #undef elf_backend_plt_alignment
6686 #define elf_backend_plt_alignment 4
6688 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
6690 &elf_i386_plt
, /* plt */
6691 0x90, /* plt0_pad_byte */
6695 #undef elf_backend_arch_data
6696 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
6698 #undef elf_backend_relocs_compatible
6699 #undef elf_backend_add_symbol_hook
6700 #define elf_backend_add_symbol_hook \
6701 elf_vxworks_add_symbol_hook
6702 #undef elf_backend_link_output_symbol_hook
6703 #define elf_backend_link_output_symbol_hook \
6704 elf_vxworks_link_output_symbol_hook
6705 #undef elf_backend_emit_relocs
6706 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
6707 #undef elf_backend_final_write_processing
6708 #define elf_backend_final_write_processing \
6709 elf_vxworks_final_write_processing
6710 #undef elf_backend_static_tls_alignment
6712 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
6714 #undef elf_backend_want_plt_sym
6715 #define elf_backend_want_plt_sym 1
6718 #define elf32_bed elf32_i386_vxworks_bed
6720 #include "elf32-target.h"