1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright (C) 1993-2015 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"
33 /* 386 uses REL relocations instead of RELA. */
38 static reloc_howto_type elf_howto_table
[]=
40 HOWTO(R_386_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
41 bfd_elf_generic_reloc
, "R_386_NONE",
42 TRUE
, 0x00000000, 0x00000000, FALSE
),
43 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
44 bfd_elf_generic_reloc
, "R_386_32",
45 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
46 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
47 bfd_elf_generic_reloc
, "R_386_PC32",
48 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
49 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
50 bfd_elf_generic_reloc
, "R_386_GOT32",
51 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
52 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
53 bfd_elf_generic_reloc
, "R_386_PLT32",
54 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
55 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
56 bfd_elf_generic_reloc
, "R_386_COPY",
57 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
58 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
59 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
60 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
61 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
63 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
64 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
65 bfd_elf_generic_reloc
, "R_386_RELATIVE",
66 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
67 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
68 bfd_elf_generic_reloc
, "R_386_GOTOFF",
69 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
70 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
71 bfd_elf_generic_reloc
, "R_386_GOTPC",
72 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
74 /* We have a gap in the reloc numbers here.
75 R_386_standard counts the number up to this point, and
76 R_386_ext_offset is the value to subtract from a reloc type of
77 R_386_16 thru R_386_PC8 to form an index into this table. */
78 #define R_386_standard (R_386_GOTPC + 1)
79 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
81 /* These relocs are a GNU extension. */
82 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
84 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
85 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
86 bfd_elf_generic_reloc
, "R_386_TLS_IE",
87 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
88 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
90 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
91 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
92 bfd_elf_generic_reloc
, "R_386_TLS_LE",
93 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
94 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_386_TLS_GD",
96 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
97 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
98 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
99 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
100 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
101 bfd_elf_generic_reloc
, "R_386_16",
102 TRUE
, 0xffff, 0xffff, FALSE
),
103 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
104 bfd_elf_generic_reloc
, "R_386_PC16",
105 TRUE
, 0xffff, 0xffff, TRUE
),
106 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
107 bfd_elf_generic_reloc
, "R_386_8",
108 TRUE
, 0xff, 0xff, FALSE
),
109 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
110 bfd_elf_generic_reloc
, "R_386_PC8",
111 TRUE
, 0xff, 0xff, TRUE
),
113 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
114 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
115 /* These are common with Solaris TLS implementation. */
116 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
118 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
119 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
121 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
122 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
123 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
124 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
125 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
126 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
127 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
128 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
129 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
130 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
131 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
132 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
133 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
135 bfd_elf_generic_reloc
, "R_386_SIZE32",
136 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
137 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
139 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
140 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
141 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
143 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
146 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
147 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
148 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
151 #define R_386_ext2 (R_386_IRELATIVE + 1 - R_386_tls_offset)
152 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
154 /* GNU extension to record C++ vtable hierarchy. */
155 HOWTO (R_386_GNU_VTINHERIT
, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 FALSE
, /* pc_relative */
161 complain_overflow_dont
, /* complain_on_overflow */
162 NULL
, /* special_function */
163 "R_386_GNU_VTINHERIT", /* name */
164 FALSE
, /* partial_inplace */
167 FALSE
), /* pcrel_offset */
169 /* GNU extension to record C++ vtable member usage. */
170 HOWTO (R_386_GNU_VTENTRY
, /* type */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
174 FALSE
, /* pc_relative */
176 complain_overflow_dont
, /* complain_on_overflow */
177 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
178 "R_386_GNU_VTENTRY", /* name */
179 FALSE
, /* partial_inplace */
182 FALSE
) /* pcrel_offset */
184 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
188 #ifdef DEBUG_GEN_RELOC
190 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
195 static reloc_howto_type
*
196 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
197 bfd_reloc_code_real_type code
)
202 TRACE ("BFD_RELOC_NONE");
203 return &elf_howto_table
[R_386_NONE
];
206 TRACE ("BFD_RELOC_32");
207 return &elf_howto_table
[R_386_32
];
210 TRACE ("BFD_RELOC_CTOR");
211 return &elf_howto_table
[R_386_32
];
213 case BFD_RELOC_32_PCREL
:
214 TRACE ("BFD_RELOC_PC32");
215 return &elf_howto_table
[R_386_PC32
];
217 case BFD_RELOC_386_GOT32
:
218 TRACE ("BFD_RELOC_386_GOT32");
219 return &elf_howto_table
[R_386_GOT32
];
221 case BFD_RELOC_386_PLT32
:
222 TRACE ("BFD_RELOC_386_PLT32");
223 return &elf_howto_table
[R_386_PLT32
];
225 case BFD_RELOC_386_COPY
:
226 TRACE ("BFD_RELOC_386_COPY");
227 return &elf_howto_table
[R_386_COPY
];
229 case BFD_RELOC_386_GLOB_DAT
:
230 TRACE ("BFD_RELOC_386_GLOB_DAT");
231 return &elf_howto_table
[R_386_GLOB_DAT
];
233 case BFD_RELOC_386_JUMP_SLOT
:
234 TRACE ("BFD_RELOC_386_JUMP_SLOT");
235 return &elf_howto_table
[R_386_JUMP_SLOT
];
237 case BFD_RELOC_386_RELATIVE
:
238 TRACE ("BFD_RELOC_386_RELATIVE");
239 return &elf_howto_table
[R_386_RELATIVE
];
241 case BFD_RELOC_386_GOTOFF
:
242 TRACE ("BFD_RELOC_386_GOTOFF");
243 return &elf_howto_table
[R_386_GOTOFF
];
245 case BFD_RELOC_386_GOTPC
:
246 TRACE ("BFD_RELOC_386_GOTPC");
247 return &elf_howto_table
[R_386_GOTPC
];
249 /* These relocs are a GNU extension. */
250 case BFD_RELOC_386_TLS_TPOFF
:
251 TRACE ("BFD_RELOC_386_TLS_TPOFF");
252 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
254 case BFD_RELOC_386_TLS_IE
:
255 TRACE ("BFD_RELOC_386_TLS_IE");
256 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
258 case BFD_RELOC_386_TLS_GOTIE
:
259 TRACE ("BFD_RELOC_386_TLS_GOTIE");
260 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
262 case BFD_RELOC_386_TLS_LE
:
263 TRACE ("BFD_RELOC_386_TLS_LE");
264 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
266 case BFD_RELOC_386_TLS_GD
:
267 TRACE ("BFD_RELOC_386_TLS_GD");
268 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
270 case BFD_RELOC_386_TLS_LDM
:
271 TRACE ("BFD_RELOC_386_TLS_LDM");
272 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
275 TRACE ("BFD_RELOC_16");
276 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
278 case BFD_RELOC_16_PCREL
:
279 TRACE ("BFD_RELOC_16_PCREL");
280 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
283 TRACE ("BFD_RELOC_8");
284 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
286 case BFD_RELOC_8_PCREL
:
287 TRACE ("BFD_RELOC_8_PCREL");
288 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
290 /* Common with Sun TLS implementation. */
291 case BFD_RELOC_386_TLS_LDO_32
:
292 TRACE ("BFD_RELOC_386_TLS_LDO_32");
293 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
295 case BFD_RELOC_386_TLS_IE_32
:
296 TRACE ("BFD_RELOC_386_TLS_IE_32");
297 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
299 case BFD_RELOC_386_TLS_LE_32
:
300 TRACE ("BFD_RELOC_386_TLS_LE_32");
301 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
303 case BFD_RELOC_386_TLS_DTPMOD32
:
304 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
305 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
307 case BFD_RELOC_386_TLS_DTPOFF32
:
308 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
309 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
311 case BFD_RELOC_386_TLS_TPOFF32
:
312 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
313 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
315 case BFD_RELOC_SIZE32
:
316 TRACE ("BFD_RELOC_SIZE32");
317 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
319 case BFD_RELOC_386_TLS_GOTDESC
:
320 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
321 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
323 case BFD_RELOC_386_TLS_DESC_CALL
:
324 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
325 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
327 case BFD_RELOC_386_TLS_DESC
:
328 TRACE ("BFD_RELOC_386_TLS_DESC");
329 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
331 case BFD_RELOC_386_IRELATIVE
:
332 TRACE ("BFD_RELOC_386_IRELATIVE");
333 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
335 case BFD_RELOC_VTABLE_INHERIT
:
336 TRACE ("BFD_RELOC_VTABLE_INHERIT");
337 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
339 case BFD_RELOC_VTABLE_ENTRY
:
340 TRACE ("BFD_RELOC_VTABLE_ENTRY");
341 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
351 static reloc_howto_type
*
352 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
357 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
358 if (elf_howto_table
[i
].name
!= NULL
359 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
360 return &elf_howto_table
[i
];
365 static reloc_howto_type
*
366 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
370 if ((indx
= r_type
) >= R_386_standard
371 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
372 >= R_386_ext
- R_386_standard
)
373 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
374 >= R_386_ext2
- R_386_ext
)
375 && ((indx
= r_type
- R_386_vt_offset
) - R_386_ext2
376 >= R_386_vt
- R_386_ext2
))
378 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
382 /* PR 17512: file: 0f67f69d. */
383 if (elf_howto_table
[indx
].type
!= r_type
)
385 return &elf_howto_table
[indx
];
389 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
391 Elf_Internal_Rela
*dst
)
393 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
394 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
397 /* Return whether a symbol name implies a local label. The UnixWare
398 2.1 cc generates temporary symbols that start with .X, so we
399 recognize them here. FIXME: do other SVR4 compilers also use .X?.
400 If so, we should move the .X recognition into
401 _bfd_elf_is_local_label_name. */
404 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
406 if (name
[0] == '.' && name
[1] == 'X')
409 return _bfd_elf_is_local_label_name (abfd
, name
);
412 /* Support for core dump NOTE sections. */
415 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
420 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
422 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
428 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
431 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
435 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
439 switch (note
->descsz
)
444 case 144: /* Linux/i386 */
446 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
449 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
459 /* Make a ".reg/999" section. */
460 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
461 size
, note
->descpos
+ offset
);
465 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
467 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
469 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
474 elf_tdata (abfd
)->core
->program
475 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
476 elf_tdata (abfd
)->core
->command
477 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
481 switch (note
->descsz
)
486 case 124: /* Linux/i386 elf_prpsinfo. */
487 elf_tdata (abfd
)->core
->pid
488 = bfd_get_32 (abfd
, note
->descdata
+ 12);
489 elf_tdata (abfd
)->core
->program
490 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
491 elf_tdata (abfd
)->core
->command
492 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
496 /* Note that for some reason, a spurious space is tacked
497 onto the end of the args in some (at least one anyway)
498 implementations, so strip it off if it exists. */
500 char *command
= elf_tdata (abfd
)->core
->command
;
501 int n
= strlen (command
);
503 if (0 < n
&& command
[n
- 1] == ' ')
504 command
[n
- 1] = '\0';
510 /* Functions for the i386 ELF linker.
512 In order to gain some understanding of code in this file without
513 knowing all the intricate details of the linker, note the
516 Functions named elf_i386_* are called by external routines, other
517 functions are only called locally. elf_i386_* functions appear
518 in this file more or less in the order in which they are called
519 from external routines. eg. elf_i386_check_relocs is called
520 early in the link process, elf_i386_finish_dynamic_sections is
521 one of the last functions. */
524 /* The name of the dynamic interpreter. This is put in the .interp
527 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
529 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
530 copying dynamic variables from a shared lib into an app's dynbss
531 section, and instead use a dynamic relocation to point into the
533 #define ELIMINATE_COPY_RELOCS 1
535 /* The size in bytes of an entry in the procedure linkage table. */
537 #define PLT_ENTRY_SIZE 16
539 /* The first entry in an absolute procedure linkage table looks like
540 this. See the SVR4 ABI i386 supplement to see how this works.
541 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
543 static const bfd_byte elf_i386_plt0_entry
[12] =
545 0xff, 0x35, /* pushl contents of address */
546 0, 0, 0, 0, /* replaced with address of .got + 4. */
547 0xff, 0x25, /* jmp indirect */
548 0, 0, 0, 0 /* replaced with address of .got + 8. */
551 /* Subsequent entries in an absolute procedure linkage table look like
554 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
556 0xff, 0x25, /* jmp indirect */
557 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
558 0x68, /* pushl immediate */
559 0, 0, 0, 0, /* replaced with offset into relocation table. */
560 0xe9, /* jmp relative */
561 0, 0, 0, 0 /* replaced with offset to start of .plt. */
564 /* The first entry in a PIC procedure linkage table look like this.
565 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
567 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
569 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
570 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
573 /* Subsequent entries in a PIC procedure linkage table look like this. */
575 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
577 0xff, 0xa3, /* jmp *offset(%ebx) */
578 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
579 0x68, /* pushl immediate */
580 0, 0, 0, 0, /* replaced with offset into relocation table. */
581 0xe9, /* jmp relative */
582 0, 0, 0, 0 /* replaced with offset to start of .plt. */
585 /* Entries in the GOT procedure linkage table look like this. */
587 static const bfd_byte elf_i386_got_plt_entry
[8] =
589 0xff, 0x25, /* jmp indirect */
590 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
591 0x66, 0x90 /* xchg %ax,%ax */
594 /* Entries in the PIC GOT procedure linkage table look like this. */
596 static const bfd_byte elf_i386_pic_got_plt_entry
[8] =
598 0xff, 0xa3, /* jmp *offset(%ebx) */
599 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
600 0x66, 0x90 /* xchg %ax,%ax */
603 /* .eh_frame covering the .plt section. */
605 static const bfd_byte elf_i386_eh_frame_plt
[] =
607 #define PLT_CIE_LENGTH 20
608 #define PLT_FDE_LENGTH 36
609 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
610 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
611 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
612 0, 0, 0, 0, /* CIE ID */
614 'z', 'R', 0, /* Augmentation string */
615 1, /* Code alignment factor */
616 0x7c, /* Data alignment factor */
617 8, /* Return address column */
618 1, /* Augmentation size */
619 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
620 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
621 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
622 DW_CFA_nop
, DW_CFA_nop
,
624 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
625 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
626 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
627 0, 0, 0, 0, /* .plt size goes here */
628 0, /* Augmentation size */
629 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
630 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
631 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
632 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
633 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
634 11, /* Block length */
635 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
636 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
637 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
638 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
639 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
642 struct elf_i386_plt_layout
644 /* The first entry in an absolute procedure linkage table looks like this. */
645 const bfd_byte
*plt0_entry
;
646 unsigned int plt0_entry_size
;
648 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
649 unsigned int plt0_got1_offset
;
650 unsigned int plt0_got2_offset
;
652 /* Later entries in an absolute procedure linkage table look like this. */
653 const bfd_byte
*plt_entry
;
654 unsigned int plt_entry_size
;
656 /* Offsets into plt_entry that are to be replaced with... */
657 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
658 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
659 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
661 /* Offset into plt_entry where the initial value of the GOT entry points. */
662 unsigned int plt_lazy_offset
;
664 /* The first entry in a PIC procedure linkage table looks like this. */
665 const bfd_byte
*pic_plt0_entry
;
667 /* Subsequent entries in a PIC procedure linkage table look like this. */
668 const bfd_byte
*pic_plt_entry
;
670 /* .eh_frame covering the .plt section. */
671 const bfd_byte
*eh_frame_plt
;
672 unsigned int eh_frame_plt_size
;
675 #define GET_PLT_ENTRY_SIZE(abfd) \
676 get_elf_i386_backend_data (abfd)->plt->plt_entry_size
678 /* These are the standard parameters. */
679 static const struct elf_i386_plt_layout elf_i386_plt
=
681 elf_i386_plt0_entry
, /* plt0_entry */
682 sizeof (elf_i386_plt0_entry
), /* plt0_entry_size */
683 2, /* plt0_got1_offset */
684 8, /* plt0_got2_offset */
685 elf_i386_plt_entry
, /* plt_entry */
686 PLT_ENTRY_SIZE
, /* plt_entry_size */
687 2, /* plt_got_offset */
688 7, /* plt_reloc_offset */
689 12, /* plt_plt_offset */
690 6, /* plt_lazy_offset */
691 elf_i386_pic_plt0_entry
, /* pic_plt0_entry */
692 elf_i386_pic_plt_entry
, /* pic_plt_entry */
693 elf_i386_eh_frame_plt
, /* eh_frame_plt */
694 sizeof (elf_i386_eh_frame_plt
), /* eh_frame_plt_size */
698 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
699 for the PLTResolve stub and then for each PLT entry. */
700 #define PLTRESOLVE_RELOCS_SHLIB 0
701 #define PLTRESOLVE_RELOCS 2
702 #define PLT_NON_JUMP_SLOT_RELOCS 2
704 /* Architecture-specific backend data for i386. */
706 struct elf_i386_backend_data
708 /* Parameters describing PLT generation. */
709 const struct elf_i386_plt_layout
*plt
;
711 /* Value used to fill the unused bytes of the first PLT entry. */
712 bfd_byte plt0_pad_byte
;
714 /* True if the target system is VxWorks. */
718 #define get_elf_i386_backend_data(abfd) \
719 ((const struct elf_i386_backend_data *) \
720 get_elf_backend_data (abfd)->arch_data)
722 /* These are the standard parameters. */
723 static const struct elf_i386_backend_data elf_i386_arch_bed
=
725 &elf_i386_plt
, /* plt */
726 0, /* plt0_pad_byte */
730 #define elf_backend_arch_data &elf_i386_arch_bed
732 /* i386 ELF linker hash entry. */
734 struct elf_i386_link_hash_entry
736 struct elf_link_hash_entry elf
;
738 /* Track dynamic relocs copied for this symbol. */
739 struct elf_dyn_relocs
*dyn_relocs
;
741 #define GOT_UNKNOWN 0
745 #define GOT_TLS_IE_POS 5
746 #define GOT_TLS_IE_NEG 6
747 #define GOT_TLS_IE_BOTH 7
748 #define GOT_TLS_GDESC 8
749 #define GOT_TLS_GD_BOTH_P(type) \
750 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
751 #define GOT_TLS_GD_P(type) \
752 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
753 #define GOT_TLS_GDESC_P(type) \
754 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
755 #define GOT_TLS_GD_ANY_P(type) \
756 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
757 unsigned char tls_type
;
759 /* Symbol is referenced by R_386_GOTOFF relocation. */
760 unsigned int gotoff_ref
: 1;
762 /* Reference count of C/C++ function pointer relocations in read-write
763 section which can be resolved at run-time. */
764 bfd_signed_vma func_pointer_refcount
;
766 /* Information about the GOT PLT entry. Filled when there are both
767 GOT and PLT relocations against the same function. */
768 union gotplt_union plt_got
;
770 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
771 starting at the end of the jump table. */
775 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
777 struct elf_i386_obj_tdata
779 struct elf_obj_tdata root
;
781 /* tls_type for each local got entry. */
782 char *local_got_tls_type
;
784 /* GOTPLT entries for TLS descriptors. */
785 bfd_vma
*local_tlsdesc_gotent
;
788 #define elf_i386_tdata(abfd) \
789 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
791 #define elf_i386_local_got_tls_type(abfd) \
792 (elf_i386_tdata (abfd)->local_got_tls_type)
794 #define elf_i386_local_tlsdesc_gotent(abfd) \
795 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
797 #define is_i386_elf(bfd) \
798 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
799 && elf_tdata (bfd) != NULL \
800 && elf_object_id (bfd) == I386_ELF_DATA)
803 elf_i386_mkobject (bfd
*abfd
)
805 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
809 /* i386 ELF linker hash table. */
811 struct elf_i386_link_hash_table
813 struct elf_link_hash_table elf
;
815 /* Short-cuts to get to dynamic linker sections. */
818 asection
*plt_eh_frame
;
823 bfd_signed_vma refcount
;
827 /* The amount of space used by the reserved portion of the sgotplt
828 section, plus whatever space is used by the jump slots. */
829 bfd_vma sgotplt_jump_table_size
;
831 /* Small local sym cache. */
832 struct sym_cache sym_cache
;
834 /* _TLS_MODULE_BASE_ symbol. */
835 struct bfd_link_hash_entry
*tls_module_base
;
837 /* Used by local STT_GNU_IFUNC symbols. */
838 htab_t loc_hash_table
;
839 void * loc_hash_memory
;
841 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
844 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
845 bfd_vma next_tls_desc_index
;
847 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
848 bfd_vma next_jump_slot_index
;
850 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
851 bfd_vma next_irelative_index
;
854 /* Get the i386 ELF linker hash table from a link_info structure. */
856 #define elf_i386_hash_table(p) \
857 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
858 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
860 #define elf_i386_compute_jump_table_size(htab) \
861 ((htab)->elf.srelplt->reloc_count * 4)
863 /* Create an entry in an i386 ELF linker hash table. */
865 static struct bfd_hash_entry
*
866 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
867 struct bfd_hash_table
*table
,
870 /* Allocate the structure if it has not already been allocated by a
874 entry
= (struct bfd_hash_entry
*)
875 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
880 /* Call the allocation method of the superclass. */
881 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
884 struct elf_i386_link_hash_entry
*eh
;
886 eh
= (struct elf_i386_link_hash_entry
*) entry
;
887 eh
->dyn_relocs
= NULL
;
888 eh
->tls_type
= GOT_UNKNOWN
;
890 eh
->func_pointer_refcount
= 0;
891 eh
->plt_got
.offset
= (bfd_vma
) -1;
892 eh
->tlsdesc_got
= (bfd_vma
) -1;
898 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
899 for local symbol so that we can handle local STT_GNU_IFUNC symbols
900 as global symbol. We reuse indx and dynstr_index for local symbol
901 hash since they aren't used by global symbols in this backend. */
904 elf_i386_local_htab_hash (const void *ptr
)
906 struct elf_link_hash_entry
*h
907 = (struct elf_link_hash_entry
*) ptr
;
908 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
911 /* Compare local hash entries. */
914 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
916 struct elf_link_hash_entry
*h1
917 = (struct elf_link_hash_entry
*) ptr1
;
918 struct elf_link_hash_entry
*h2
919 = (struct elf_link_hash_entry
*) ptr2
;
921 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
924 /* Find and/or create a hash entry for local symbol. */
926 static struct elf_link_hash_entry
*
927 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
928 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
931 struct elf_i386_link_hash_entry e
, *ret
;
932 asection
*sec
= abfd
->sections
;
933 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
934 ELF32_R_SYM (rel
->r_info
));
937 e
.elf
.indx
= sec
->id
;
938 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
939 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
940 create
? INSERT
: NO_INSERT
);
947 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
951 ret
= (struct elf_i386_link_hash_entry
*)
952 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
953 sizeof (struct elf_i386_link_hash_entry
));
956 memset (ret
, 0, sizeof (*ret
));
957 ret
->elf
.indx
= sec
->id
;
958 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
959 ret
->elf
.dynindx
= -1;
960 ret
->func_pointer_refcount
= 0;
961 ret
->plt_got
.offset
= (bfd_vma
) -1;
967 /* Destroy an i386 ELF linker hash table. */
970 elf_i386_link_hash_table_free (bfd
*obfd
)
972 struct elf_i386_link_hash_table
*htab
973 = (struct elf_i386_link_hash_table
*) obfd
->link
.hash
;
975 if (htab
->loc_hash_table
)
976 htab_delete (htab
->loc_hash_table
);
977 if (htab
->loc_hash_memory
)
978 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
979 _bfd_elf_link_hash_table_free (obfd
);
982 /* Create an i386 ELF linker hash table. */
984 static struct bfd_link_hash_table
*
985 elf_i386_link_hash_table_create (bfd
*abfd
)
987 struct elf_i386_link_hash_table
*ret
;
988 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
990 ret
= (struct elf_i386_link_hash_table
*) bfd_zmalloc (amt
);
994 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
995 elf_i386_link_hash_newfunc
,
996 sizeof (struct elf_i386_link_hash_entry
),
1003 ret
->loc_hash_table
= htab_try_create (1024,
1004 elf_i386_local_htab_hash
,
1005 elf_i386_local_htab_eq
,
1007 ret
->loc_hash_memory
= objalloc_create ();
1008 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1010 elf_i386_link_hash_table_free (abfd
);
1013 ret
->elf
.root
.hash_table_free
= elf_i386_link_hash_table_free
;
1015 return &ret
->elf
.root
;
1018 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1019 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1023 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1025 struct elf_i386_link_hash_table
*htab
;
1027 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1030 htab
= elf_i386_hash_table (info
);
1034 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
1038 if (bfd_link_executable (info
))
1040 /* Always allow copy relocs for building executables. */
1041 asection
*s
= bfd_get_linker_section (dynobj
, ".rel.bss");
1044 const struct elf_backend_data
*bed
= get_elf_backend_data (dynobj
);
1045 s
= bfd_make_section_anyway_with_flags (dynobj
,
1047 (bed
->dynamic_sec_flags
1050 || ! bfd_set_section_alignment (dynobj
, s
,
1051 bed
->s
->log_file_align
))
1057 if (get_elf_i386_backend_data (dynobj
)->is_vxworks
1058 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
1062 if (!info
->no_ld_generated_unwind_info
1063 && htab
->plt_eh_frame
== NULL
1064 && htab
->elf
.splt
!= NULL
)
1066 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1067 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1068 | SEC_LINKER_CREATED
);
1070 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1071 if (htab
->plt_eh_frame
== NULL
1072 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 2))
1079 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1082 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1083 struct elf_link_hash_entry
*dir
,
1084 struct elf_link_hash_entry
*ind
)
1086 struct elf_i386_link_hash_entry
*edir
, *eind
;
1088 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1089 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1091 if (eind
->dyn_relocs
!= NULL
)
1093 if (edir
->dyn_relocs
!= NULL
)
1095 struct elf_dyn_relocs
**pp
;
1096 struct elf_dyn_relocs
*p
;
1098 /* Add reloc counts against the indirect sym to the direct sym
1099 list. Merge any entries against the same section. */
1100 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1102 struct elf_dyn_relocs
*q
;
1104 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1105 if (q
->sec
== p
->sec
)
1107 q
->pc_count
+= p
->pc_count
;
1108 q
->count
+= p
->count
;
1115 *pp
= edir
->dyn_relocs
;
1118 edir
->dyn_relocs
= eind
->dyn_relocs
;
1119 eind
->dyn_relocs
= NULL
;
1122 if (ind
->root
.type
== bfd_link_hash_indirect
1123 && dir
->got
.refcount
<= 0)
1125 edir
->tls_type
= eind
->tls_type
;
1126 eind
->tls_type
= GOT_UNKNOWN
;
1129 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1130 generate a R_386_COPY reloc. */
1131 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1133 if (ELIMINATE_COPY_RELOCS
1134 && ind
->root
.type
!= bfd_link_hash_indirect
1135 && dir
->dynamic_adjusted
)
1137 /* If called to transfer flags for a weakdef during processing
1138 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1139 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1140 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1141 dir
->ref_regular
|= ind
->ref_regular
;
1142 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1143 dir
->needs_plt
|= ind
->needs_plt
;
1144 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1148 if (eind
->func_pointer_refcount
> 0)
1150 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1151 eind
->func_pointer_refcount
= 0;
1154 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1158 /* Return TRUE if the TLS access code sequence support transition
1162 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
1164 Elf_Internal_Shdr
*symtab_hdr
,
1165 struct elf_link_hash_entry
**sym_hashes
,
1166 unsigned int r_type
,
1167 const Elf_Internal_Rela
*rel
,
1168 const Elf_Internal_Rela
*relend
)
1170 unsigned int val
, type
;
1171 unsigned long r_symndx
;
1172 struct elf_link_hash_entry
*h
;
1175 /* Get the section contents. */
1176 if (contents
== NULL
)
1178 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1179 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1182 /* FIXME: How to better handle error condition? */
1183 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1186 /* Cache the section contents for elf_link_input_bfd. */
1187 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1191 offset
= rel
->r_offset
;
1196 if (offset
< 2 || (rel
+ 1) >= relend
)
1199 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1200 if (r_type
== R_386_TLS_GD
)
1202 /* Check transition from GD access model. Only
1203 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1204 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1205 can transit to different access model. */
1206 if ((offset
+ 10) > sec
->size
||
1207 (type
!= 0x8d && type
!= 0x04))
1210 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1213 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1217 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1220 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1225 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1226 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1229 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1235 /* Check transition from LD access model. Only
1236 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1237 can transit to different access model. */
1238 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1241 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1242 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1246 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1249 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1250 if (r_symndx
< symtab_hdr
->sh_info
)
1253 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1254 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1255 may be versioned. */
1257 && h
->root
.root
.string
!= NULL
1258 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1259 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1260 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1264 /* Check transition from IE access model:
1265 movl foo@indntpoff(%rip), %eax
1266 movl foo@indntpoff(%rip), %reg
1267 addl foo@indntpoff(%rip), %reg
1270 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1273 /* Check "movl foo@tpoff(%rip), %eax" first. */
1274 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1281 /* Check movl|addl foo@tpoff(%rip), %reg. */
1282 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1283 return ((type
== 0x8b || type
== 0x03)
1284 && (val
& 0xc7) == 0x05);
1286 case R_386_TLS_GOTIE
:
1287 case R_386_TLS_IE_32
:
1288 /* Check transition from {IE_32,GOTIE} access model:
1289 subl foo@{tpoff,gontoff}(%reg1), %reg2
1290 movl foo@{tpoff,gontoff}(%reg1), %reg2
1291 addl foo@{tpoff,gontoff}(%reg1), %reg2
1294 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1297 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1298 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1301 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1302 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1304 case R_386_TLS_GOTDESC
:
1305 /* Check transition from GDesc access model:
1306 leal x@tlsdesc(%ebx), %eax
1308 Make sure it's a leal adding ebx to a 32-bit offset
1309 into any register, although it's probably almost always
1312 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1315 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1318 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1319 return (val
& 0xc7) == 0x83;
1321 case R_386_TLS_DESC_CALL
:
1322 /* Check transition from GDesc access model:
1323 call *x@tlsdesc(%rax)
1325 if (offset
+ 2 <= sec
->size
)
1327 /* Make sure that it's a call *x@tlsdesc(%rax). */
1328 static const unsigned char call
[] = { 0xff, 0x10 };
1329 return memcmp (contents
+ offset
, call
, 2) == 0;
1339 /* Return TRUE if the TLS access transition is OK or no transition
1340 will be performed. Update R_TYPE if there is a transition. */
1343 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1344 asection
*sec
, bfd_byte
*contents
,
1345 Elf_Internal_Shdr
*symtab_hdr
,
1346 struct elf_link_hash_entry
**sym_hashes
,
1347 unsigned int *r_type
, int tls_type
,
1348 const Elf_Internal_Rela
*rel
,
1349 const Elf_Internal_Rela
*relend
,
1350 struct elf_link_hash_entry
*h
,
1351 unsigned long r_symndx
)
1353 unsigned int from_type
= *r_type
;
1354 unsigned int to_type
= from_type
;
1355 bfd_boolean check
= TRUE
;
1357 /* Skip TLS transition for functions. */
1359 && (h
->type
== STT_FUNC
1360 || h
->type
== STT_GNU_IFUNC
))
1366 case R_386_TLS_GOTDESC
:
1367 case R_386_TLS_DESC_CALL
:
1368 case R_386_TLS_IE_32
:
1370 case R_386_TLS_GOTIE
:
1371 if (bfd_link_executable (info
))
1374 to_type
= R_386_TLS_LE_32
;
1375 else if (from_type
!= R_386_TLS_IE
1376 && from_type
!= R_386_TLS_GOTIE
)
1377 to_type
= R_386_TLS_IE_32
;
1380 /* When we are called from elf_i386_relocate_section, CONTENTS
1381 isn't NULL and there may be additional transitions based on
1383 if (contents
!= NULL
)
1385 unsigned int new_to_type
= to_type
;
1387 if (bfd_link_executable (info
)
1390 && (tls_type
& GOT_TLS_IE
))
1391 new_to_type
= R_386_TLS_LE_32
;
1393 if (to_type
== R_386_TLS_GD
1394 || to_type
== R_386_TLS_GOTDESC
1395 || to_type
== R_386_TLS_DESC_CALL
)
1397 if (tls_type
== GOT_TLS_IE_POS
)
1398 new_to_type
= R_386_TLS_GOTIE
;
1399 else if (tls_type
& GOT_TLS_IE
)
1400 new_to_type
= R_386_TLS_IE_32
;
1403 /* We checked the transition before when we were called from
1404 elf_i386_check_relocs. We only want to check the new
1405 transition which hasn't been checked before. */
1406 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1407 to_type
= new_to_type
;
1413 if (bfd_link_executable (info
))
1414 to_type
= R_386_TLS_LE_32
;
1421 /* Return TRUE if there is no transition. */
1422 if (from_type
== to_type
)
1425 /* Check if the transition can be performed. */
1427 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1428 symtab_hdr
, sym_hashes
,
1429 from_type
, rel
, relend
))
1431 reloc_howto_type
*from
, *to
;
1434 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1435 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1438 name
= h
->root
.root
.string
;
1441 struct elf_i386_link_hash_table
*htab
;
1443 htab
= elf_i386_hash_table (info
);
1448 Elf_Internal_Sym
*isym
;
1450 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1452 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1456 (*_bfd_error_handler
)
1457 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1458 "in section `%A' failed"),
1459 abfd
, sec
, from
->name
, to
->name
, name
,
1460 (unsigned long) rel
->r_offset
);
1461 bfd_set_error (bfd_error_bad_value
);
1469 /* Rename some of the generic section flags to better document how they
1471 #define need_convert_mov_to_lea sec_flg0
1473 /* Look through the relocs for a section during the first phase, and
1474 calculate needed space in the global offset table, procedure linkage
1475 table, and dynamic reloc sections. */
1478 elf_i386_check_relocs (bfd
*abfd
,
1479 struct bfd_link_info
*info
,
1481 const Elf_Internal_Rela
*relocs
)
1483 struct elf_i386_link_hash_table
*htab
;
1484 Elf_Internal_Shdr
*symtab_hdr
;
1485 struct elf_link_hash_entry
**sym_hashes
;
1486 const Elf_Internal_Rela
*rel
;
1487 const Elf_Internal_Rela
*rel_end
;
1489 bfd_boolean use_plt_got
;
1491 if (bfd_link_relocatable (info
))
1494 BFD_ASSERT (is_i386_elf (abfd
));
1496 htab
= elf_i386_hash_table (info
);
1500 use_plt_got
= (!get_elf_i386_backend_data (abfd
)->is_vxworks
1501 && (get_elf_i386_backend_data (abfd
)
1502 == &elf_i386_arch_bed
));
1504 symtab_hdr
= &elf_symtab_hdr (abfd
);
1505 sym_hashes
= elf_sym_hashes (abfd
);
1509 rel_end
= relocs
+ sec
->reloc_count
;
1510 for (rel
= relocs
; rel
< rel_end
; rel
++)
1512 unsigned int r_type
;
1513 unsigned long r_symndx
;
1514 struct elf_link_hash_entry
*h
;
1515 struct elf_i386_link_hash_entry
*eh
;
1516 Elf_Internal_Sym
*isym
;
1518 bfd_boolean size_reloc
;
1520 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1521 r_type
= ELF32_R_TYPE (rel
->r_info
);
1523 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1525 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1531 if (r_symndx
< symtab_hdr
->sh_info
)
1533 /* A local symbol. */
1534 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1539 /* Check relocation against local STT_GNU_IFUNC symbol. */
1540 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1542 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1546 /* Fake a STT_GNU_IFUNC symbol. */
1547 h
->type
= STT_GNU_IFUNC
;
1550 h
->forced_local
= 1;
1551 h
->root
.type
= bfd_link_hash_defined
;
1559 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1560 while (h
->root
.type
== bfd_link_hash_indirect
1561 || h
->root
.type
== bfd_link_hash_warning
)
1562 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1565 eh
= (struct elf_i386_link_hash_entry
*) h
;
1568 /* Create the ifunc sections for static executables. If we
1569 never see an indirect function symbol nor we are building
1570 a static executable, those sections will be empty and
1571 won't appear in output. */
1583 if (htab
->elf
.dynobj
== NULL
)
1584 htab
->elf
.dynobj
= abfd
;
1585 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1590 /* It is referenced by a non-shared object. */
1592 h
->root
.non_ir_ref
= 1;
1594 if (h
->type
== STT_GNU_IFUNC
)
1595 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1596 |= elf_gnu_symbol_ifunc
;
1599 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1600 symtab_hdr
, sym_hashes
,
1601 &r_type
, GOT_UNKNOWN
,
1602 rel
, rel_end
, h
, r_symndx
))
1608 htab
->tls_ldm_got
.refcount
+= 1;
1612 /* This symbol requires a procedure linkage table entry. We
1613 actually build the entry in adjust_dynamic_symbol,
1614 because this might be a case of linking PIC code which is
1615 never referenced by a dynamic object, in which case we
1616 don't need to generate a procedure linkage table entry
1619 /* If this is a local symbol, we resolve it directly without
1620 creating a procedure linkage table entry. */
1625 h
->plt
.refcount
+= 1;
1632 case R_386_TLS_IE_32
:
1634 case R_386_TLS_GOTIE
:
1635 if (!bfd_link_executable (info
))
1636 info
->flags
|= DF_STATIC_TLS
;
1641 case R_386_TLS_GOTDESC
:
1642 case R_386_TLS_DESC_CALL
:
1643 /* This symbol requires a global offset table entry. */
1645 int tls_type
, old_tls_type
;
1650 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1651 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1652 case R_386_TLS_GOTDESC
:
1653 case R_386_TLS_DESC_CALL
:
1654 tls_type
= GOT_TLS_GDESC
; break;
1655 case R_386_TLS_IE_32
:
1656 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1657 tls_type
= GOT_TLS_IE_NEG
;
1659 /* If this is a GD->IE transition, we may use either of
1660 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1661 tls_type
= GOT_TLS_IE
;
1664 case R_386_TLS_GOTIE
:
1665 tls_type
= GOT_TLS_IE_POS
; break;
1670 h
->got
.refcount
+= 1;
1671 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1675 bfd_signed_vma
*local_got_refcounts
;
1677 /* This is a global offset table entry for a local symbol. */
1678 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1679 if (local_got_refcounts
== NULL
)
1683 size
= symtab_hdr
->sh_info
;
1684 size
*= (sizeof (bfd_signed_vma
)
1685 + sizeof (bfd_vma
) + sizeof(char));
1686 local_got_refcounts
= (bfd_signed_vma
*)
1687 bfd_zalloc (abfd
, size
);
1688 if (local_got_refcounts
== NULL
)
1690 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1691 elf_i386_local_tlsdesc_gotent (abfd
)
1692 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1693 elf_i386_local_got_tls_type (abfd
)
1694 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1696 local_got_refcounts
[r_symndx
] += 1;
1697 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1700 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1701 tls_type
|= old_tls_type
;
1702 /* If a TLS symbol is accessed using IE at least once,
1703 there is no point to use dynamic model for it. */
1704 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1705 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1706 || (tls_type
& GOT_TLS_IE
) == 0))
1708 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1709 tls_type
= old_tls_type
;
1710 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1711 && GOT_TLS_GD_ANY_P (tls_type
))
1712 tls_type
|= old_tls_type
;
1716 name
= h
->root
.root
.string
;
1718 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1720 (*_bfd_error_handler
)
1721 (_("%B: `%s' accessed both as normal and "
1722 "thread local symbol"),
1724 bfd_set_error (bfd_error_bad_value
);
1729 if (old_tls_type
!= tls_type
)
1732 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1734 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1742 if (htab
->elf
.sgot
== NULL
)
1744 if (htab
->elf
.dynobj
== NULL
)
1745 htab
->elf
.dynobj
= abfd
;
1746 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1749 if (r_type
!= R_386_TLS_IE
)
1753 case R_386_TLS_LE_32
:
1755 if (bfd_link_executable (info
))
1757 info
->flags
|= DF_STATIC_TLS
;
1762 if (h
!= NULL
&& bfd_link_executable (info
))
1764 /* If this reloc is in a read-only section, we might
1765 need a copy reloc. We can't check reliably at this
1766 stage whether the section is read-only, as input
1767 sections have not yet been mapped to output sections.
1768 Tentatively set the flag for now, and correct in
1769 adjust_dynamic_symbol. */
1772 /* We may need a .plt entry if the function this reloc
1773 refers to is in a shared lib. */
1774 h
->plt
.refcount
+= 1;
1775 if (r_type
== R_386_PC32
)
1777 /* Since something like ".long foo - ." may be used
1778 as pointer, make sure that PLT is used if foo is
1779 a function defined in a shared library. */
1780 if ((sec
->flags
& SEC_CODE
) == 0)
1781 h
->pointer_equality_needed
= 1;
1785 h
->pointer_equality_needed
= 1;
1786 /* R_386_32 can be resolved at run-time. */
1787 if (r_type
== R_386_32
1788 && (sec
->flags
& SEC_READONLY
) == 0)
1789 eh
->func_pointer_refcount
+= 1;
1795 /* If we are creating a shared library, and this is a reloc
1796 against a global symbol, or a non PC relative reloc
1797 against a local symbol, then we need to copy the reloc
1798 into the shared library. However, if we are linking with
1799 -Bsymbolic, we do not need to copy a reloc against a
1800 global symbol which is defined in an object we are
1801 including in the link (i.e., DEF_REGULAR is set). At
1802 this point we have not seen all the input files, so it is
1803 possible that DEF_REGULAR is not set now but will be set
1804 later (it is never cleared). In case of a weak definition,
1805 DEF_REGULAR may be cleared later by a strong definition in
1806 a shared library. We account for that possibility below by
1807 storing information in the relocs_copied field of the hash
1808 table entry. A similar situation occurs when creating
1809 shared libraries and symbol visibility changes render the
1812 If on the other hand, we are creating an executable, we
1813 may need to keep relocations for symbols satisfied by a
1814 dynamic library if we manage to avoid copy relocs for the
1816 if ((bfd_link_pic (info
)
1817 && (sec
->flags
& SEC_ALLOC
) != 0
1818 && (r_type
!= R_386_PC32
1820 && (! SYMBOLIC_BIND (info
, h
)
1821 || h
->root
.type
== bfd_link_hash_defweak
1822 || !h
->def_regular
))))
1823 || (ELIMINATE_COPY_RELOCS
1824 && !bfd_link_pic (info
)
1825 && (sec
->flags
& SEC_ALLOC
) != 0
1827 && (h
->root
.type
== bfd_link_hash_defweak
1828 || !h
->def_regular
)))
1830 struct elf_dyn_relocs
*p
;
1831 struct elf_dyn_relocs
**head
;
1833 /* We must copy these reloc types into the output file.
1834 Create a reloc section in dynobj and make room for
1838 if (htab
->elf
.dynobj
== NULL
)
1839 htab
->elf
.dynobj
= abfd
;
1841 sreloc
= _bfd_elf_make_dynamic_reloc_section
1842 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1848 /* If this is a global symbol, we count the number of
1849 relocations we need for this symbol. */
1852 head
= &eh
->dyn_relocs
;
1856 /* Track dynamic relocs needed for local syms too.
1857 We really need local syms available to do this
1862 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1867 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1871 vpp
= &elf_section_data (s
)->local_dynrel
;
1872 head
= (struct elf_dyn_relocs
**)vpp
;
1876 if (p
== NULL
|| p
->sec
!= sec
)
1878 bfd_size_type amt
= sizeof *p
;
1879 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1891 /* Count size relocation as PC-relative relocation. */
1892 if (r_type
== R_386_PC32
|| size_reloc
)
1897 /* This relocation describes the C++ object vtable hierarchy.
1898 Reconstruct it for later use during GC. */
1899 case R_386_GNU_VTINHERIT
:
1900 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1904 /* This relocation describes which C++ vtable entries are actually
1905 used. Record for later use during GC. */
1906 case R_386_GNU_VTENTRY
:
1907 BFD_ASSERT (h
!= NULL
);
1909 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1919 && h
->plt
.refcount
> 0
1920 && (((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
1921 || h
->got
.refcount
> 0)
1922 && htab
->plt_got
== NULL
)
1924 /* Create the GOT procedure linkage table. */
1925 unsigned int plt_got_align
;
1926 const struct elf_backend_data
*bed
;
1928 bed
= get_elf_backend_data (info
->output_bfd
);
1929 BFD_ASSERT (sizeof (elf_i386_got_plt_entry
) == 8
1930 && (sizeof (elf_i386_got_plt_entry
)
1931 == sizeof (elf_i386_pic_got_plt_entry
)));
1934 if (htab
->elf
.dynobj
== NULL
)
1935 htab
->elf
.dynobj
= abfd
;
1937 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
1939 (bed
->dynamic_sec_flags
1944 if (htab
->plt_got
== NULL
1945 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
1951 if (r_type
== R_386_GOT32
1952 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1953 sec
->need_convert_mov_to_lea
= 1;
1959 /* Return the section that should be marked against GC for a given
1963 elf_i386_gc_mark_hook (asection
*sec
,
1964 struct bfd_link_info
*info
,
1965 Elf_Internal_Rela
*rel
,
1966 struct elf_link_hash_entry
*h
,
1967 Elf_Internal_Sym
*sym
)
1970 switch (ELF32_R_TYPE (rel
->r_info
))
1972 case R_386_GNU_VTINHERIT
:
1973 case R_386_GNU_VTENTRY
:
1977 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1980 /* Update the got entry reference counts for the section being removed. */
1983 elf_i386_gc_sweep_hook (bfd
*abfd
,
1984 struct bfd_link_info
*info
,
1986 const Elf_Internal_Rela
*relocs
)
1988 struct elf_i386_link_hash_table
*htab
;
1989 Elf_Internal_Shdr
*symtab_hdr
;
1990 struct elf_link_hash_entry
**sym_hashes
;
1991 bfd_signed_vma
*local_got_refcounts
;
1992 const Elf_Internal_Rela
*rel
, *relend
;
1994 if (bfd_link_relocatable (info
))
1997 htab
= elf_i386_hash_table (info
);
2001 elf_section_data (sec
)->local_dynrel
= NULL
;
2003 symtab_hdr
= &elf_symtab_hdr (abfd
);
2004 sym_hashes
= elf_sym_hashes (abfd
);
2005 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2007 relend
= relocs
+ sec
->reloc_count
;
2008 for (rel
= relocs
; rel
< relend
; rel
++)
2010 unsigned long r_symndx
;
2011 unsigned int r_type
;
2012 struct elf_link_hash_entry
*h
= NULL
;
2014 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2015 if (r_symndx
>= symtab_hdr
->sh_info
)
2017 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2018 while (h
->root
.type
== bfd_link_hash_indirect
2019 || h
->root
.type
== bfd_link_hash_warning
)
2020 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2024 /* A local symbol. */
2025 Elf_Internal_Sym
*isym
;
2027 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2030 /* Check relocation against local STT_GNU_IFUNC symbol. */
2032 && ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2034 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
2042 struct elf_i386_link_hash_entry
*eh
;
2043 struct elf_dyn_relocs
**pp
;
2044 struct elf_dyn_relocs
*p
;
2046 eh
= (struct elf_i386_link_hash_entry
*) h
;
2047 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2050 /* Everything must go for SEC. */
2056 r_type
= ELF32_R_TYPE (rel
->r_info
);
2057 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
2058 symtab_hdr
, sym_hashes
,
2059 &r_type
, GOT_UNKNOWN
,
2060 rel
, relend
, h
, r_symndx
))
2066 if (htab
->tls_ldm_got
.refcount
> 0)
2067 htab
->tls_ldm_got
.refcount
-= 1;
2071 case R_386_TLS_GOTDESC
:
2072 case R_386_TLS_DESC_CALL
:
2073 case R_386_TLS_IE_32
:
2075 case R_386_TLS_GOTIE
:
2079 if (h
->got
.refcount
> 0)
2080 h
->got
.refcount
-= 1;
2081 if (h
->type
== STT_GNU_IFUNC
)
2083 if (h
->plt
.refcount
> 0)
2084 h
->plt
.refcount
-= 1;
2087 else if (local_got_refcounts
!= NULL
)
2089 if (local_got_refcounts
[r_symndx
] > 0)
2090 local_got_refcounts
[r_symndx
] -= 1;
2097 if (bfd_link_pic (info
)
2098 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2105 if (h
->plt
.refcount
> 0)
2106 h
->plt
.refcount
-= 1;
2107 if (r_type
== R_386_32
2108 && (sec
->flags
& SEC_READONLY
) == 0)
2110 struct elf_i386_link_hash_entry
*eh
2111 = (struct elf_i386_link_hash_entry
*) h
;
2112 if (eh
->func_pointer_refcount
> 0)
2113 eh
->func_pointer_refcount
-= 1;
2119 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2121 if (h
->got
.refcount
> 0)
2122 h
->got
.refcount
-= 1;
2123 if (h
->plt
.refcount
> 0)
2124 h
->plt
.refcount
-= 1;
2136 /* Adjust a symbol defined by a dynamic object and referenced by a
2137 regular object. The current definition is in some section of the
2138 dynamic object, but we're not including those sections. We have to
2139 change the definition to something the rest of the link can
2143 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2144 struct elf_link_hash_entry
*h
)
2146 struct elf_i386_link_hash_table
*htab
;
2148 struct elf_i386_link_hash_entry
*eh
;
2149 struct elf_dyn_relocs
*p
;
2151 /* STT_GNU_IFUNC symbol must go through PLT. */
2152 if (h
->type
== STT_GNU_IFUNC
)
2154 /* All local STT_GNU_IFUNC references must be treate as local
2155 calls via local PLT. */
2157 && SYMBOL_CALLS_LOCAL (info
, h
))
2159 bfd_size_type pc_count
= 0, count
= 0;
2160 struct elf_dyn_relocs
**pp
;
2162 eh
= (struct elf_i386_link_hash_entry
*) h
;
2163 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2165 pc_count
+= p
->pc_count
;
2166 p
->count
-= p
->pc_count
;
2175 if (pc_count
|| count
)
2179 if (h
->plt
.refcount
<= 0)
2180 h
->plt
.refcount
= 1;
2182 h
->plt
.refcount
+= 1;
2186 if (h
->plt
.refcount
<= 0)
2188 h
->plt
.offset
= (bfd_vma
) -1;
2194 /* If this is a function, put it in the procedure linkage table. We
2195 will fill in the contents of the procedure linkage table later,
2196 when we know the address of the .got section. */
2197 if (h
->type
== STT_FUNC
2200 if (h
->plt
.refcount
<= 0
2201 || SYMBOL_CALLS_LOCAL (info
, h
)
2202 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2203 && h
->root
.type
== bfd_link_hash_undefweak
))
2205 /* This case can occur if we saw a PLT32 reloc in an input
2206 file, but the symbol was never referred to by a dynamic
2207 object, or if all references were garbage collected. In
2208 such a case, we don't actually need to build a procedure
2209 linkage table, and we can just do a PC32 reloc instead. */
2210 h
->plt
.offset
= (bfd_vma
) -1;
2217 /* It's possible that we incorrectly decided a .plt reloc was
2218 needed for an R_386_PC32 reloc to a non-function sym in
2219 check_relocs. We can't decide accurately between function and
2220 non-function syms in check-relocs; Objects loaded later in
2221 the link may change h->type. So fix it now. */
2222 h
->plt
.offset
= (bfd_vma
) -1;
2224 /* If this is a weak symbol, and there is a real definition, the
2225 processor independent code will have arranged for us to see the
2226 real definition first, and we can just use the same value. */
2227 if (h
->u
.weakdef
!= NULL
)
2229 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2230 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2231 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2232 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2233 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2234 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2238 /* This is a reference to a symbol defined by a dynamic object which
2239 is not a function. */
2241 /* If we are creating a shared library, we must presume that the
2242 only references to the symbol are via the global offset table.
2243 For such cases we need not do anything here; the relocations will
2244 be handled correctly by relocate_section. */
2245 if (!bfd_link_executable (info
))
2248 /* If there are no references to this symbol that do not use the
2249 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2251 eh
= (struct elf_i386_link_hash_entry
*) h
;
2252 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2255 /* If -z nocopyreloc was given, we won't generate them either. */
2256 if (info
->nocopyreloc
)
2262 htab
= elf_i386_hash_table (info
);
2266 /* If there aren't any dynamic relocs in read-only sections nor
2267 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2268 avoid the copy reloc. This doesn't work on VxWorks, where we can
2269 not have dynamic relocations (other than copy and jump slot
2270 relocations) in an executable. */
2271 if (ELIMINATE_COPY_RELOCS
2273 && !get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2275 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2277 s
= p
->sec
->output_section
;
2278 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2289 /* We must allocate the symbol in our .dynbss section, which will
2290 become part of the .bss section of the executable. There will be
2291 an entry for this symbol in the .dynsym section. The dynamic
2292 object will contain position independent code, so all references
2293 from the dynamic object to this symbol will go through the global
2294 offset table. The dynamic linker will use the .dynsym entry to
2295 determine the address it must put in the global offset table, so
2296 both the dynamic object and the regular object will refer to the
2297 same memory location for the variable. */
2299 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2300 copy the initial value out of the dynamic object and into the
2301 runtime process image. */
2302 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2304 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2310 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2313 /* Allocate space in .plt, .got and associated reloc sections for
2317 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2319 struct bfd_link_info
*info
;
2320 struct elf_i386_link_hash_table
*htab
;
2321 struct elf_i386_link_hash_entry
*eh
;
2322 struct elf_dyn_relocs
*p
;
2323 unsigned plt_entry_size
;
2325 if (h
->root
.type
== bfd_link_hash_indirect
)
2328 eh
= (struct elf_i386_link_hash_entry
*) h
;
2330 info
= (struct bfd_link_info
*) inf
;
2331 htab
= elf_i386_hash_table (info
);
2335 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2337 /* Clear the reference count of function pointer relocations if
2338 symbol isn't a normal function. */
2339 if (h
->type
!= STT_FUNC
)
2340 eh
->func_pointer_refcount
= 0;
2342 /* We can't use the GOT PLT if pointer equality is needed since
2343 finish_dynamic_symbol won't clear symbol value and the dynamic
2344 linker won't update the GOT slot. We will get into an infinite
2345 loop at run-time. */
2346 if (htab
->plt_got
!= NULL
2347 && h
->type
!= STT_GNU_IFUNC
2348 && !h
->pointer_equality_needed
2349 && h
->plt
.refcount
> 0
2350 && h
->got
.refcount
> 0)
2352 /* Don't use the regular PLT if there are both GOT and GOTPLT
2354 h
->plt
.offset
= (bfd_vma
) -1;
2356 /* Use the GOT PLT. */
2357 eh
->plt_got
.refcount
= 1;
2360 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2361 here if it is defined and referenced in a non-shared object. */
2362 if (h
->type
== STT_GNU_IFUNC
2364 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2367 /* Don't create the PLT entry if there are only function pointer
2368 relocations which can be resolved at run-time. */
2369 else if (htab
->elf
.dynamic_sections_created
2370 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2371 || eh
->plt_got
.refcount
> 0))
2373 bfd_boolean use_plt_got
;
2375 /* Clear the reference count of function pointer relocations
2377 eh
->func_pointer_refcount
= 0;
2379 if ((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2381 /* Don't use the regular PLT for DF_BIND_NOW. */
2382 h
->plt
.offset
= (bfd_vma
) -1;
2384 /* Use the GOT PLT. */
2385 h
->got
.refcount
= 1;
2386 eh
->plt_got
.refcount
= 1;
2389 use_plt_got
= eh
->plt_got
.refcount
> 0;
2391 /* Make sure this symbol is output as a dynamic symbol.
2392 Undefined weak syms won't yet be marked as dynamic. */
2393 if (h
->dynindx
== -1
2394 && !h
->forced_local
)
2396 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2400 if (bfd_link_pic (info
)
2401 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2403 asection
*s
= htab
->elf
.splt
;
2404 asection
*got_s
= htab
->plt_got
;
2406 /* If this is the first .plt entry, make room for the special
2407 first entry. The .plt section is used by prelink to undo
2408 prelinking for dynamic relocations. */
2410 s
->size
= plt_entry_size
;
2413 eh
->plt_got
.offset
= got_s
->size
;
2415 h
->plt
.offset
= s
->size
;
2417 /* If this symbol is not defined in a regular file, and we are
2418 not generating a shared library, then set the symbol to this
2419 location in the .plt. This is required to make function
2420 pointers compare as equal between the normal executable and
2421 the shared library. */
2422 if (! bfd_link_pic (info
)
2427 /* We need to make a call to the entry of the GOT PLT
2428 instead of regular PLT entry. */
2429 h
->root
.u
.def
.section
= got_s
;
2430 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2434 h
->root
.u
.def
.section
= s
;
2435 h
->root
.u
.def
.value
= h
->plt
.offset
;
2439 /* Make room for this entry. */
2441 got_s
->size
+= sizeof (elf_i386_got_plt_entry
);
2444 s
->size
+= plt_entry_size
;
2446 /* We also need to make an entry in the .got.plt section,
2447 which will be placed in the .got section by the linker
2449 htab
->elf
.sgotplt
->size
+= 4;
2451 /* We also need to make an entry in the .rel.plt section. */
2452 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2453 htab
->elf
.srelplt
->reloc_count
++;
2456 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
2457 && !bfd_link_pic (info
))
2459 /* VxWorks has a second set of relocations for each PLT entry
2460 in executables. They go in a separate relocation section,
2461 which is processed by the kernel loader. */
2463 /* There are two relocations for the initial PLT entry: an
2464 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2465 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2467 if (h
->plt
.offset
== plt_entry_size
)
2468 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2470 /* There are two extra relocations for each subsequent PLT entry:
2471 an R_386_32 relocation for the GOT entry, and an R_386_32
2472 relocation for the PLT entry. */
2474 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2479 h
->plt
.offset
= (bfd_vma
) -1;
2485 h
->plt
.offset
= (bfd_vma
) -1;
2489 eh
->tlsdesc_got
= (bfd_vma
) -1;
2491 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2492 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2493 if (h
->got
.refcount
> 0
2494 && bfd_link_executable (info
)
2496 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2497 h
->got
.offset
= (bfd_vma
) -1;
2498 else if (h
->got
.refcount
> 0)
2502 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2504 /* Make sure this symbol is output as a dynamic symbol.
2505 Undefined weak syms won't yet be marked as dynamic. */
2506 if (h
->dynindx
== -1
2507 && !h
->forced_local
)
2509 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2514 if (GOT_TLS_GDESC_P (tls_type
))
2516 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2517 - elf_i386_compute_jump_table_size (htab
);
2518 htab
->elf
.sgotplt
->size
+= 8;
2519 h
->got
.offset
= (bfd_vma
) -2;
2521 if (! GOT_TLS_GDESC_P (tls_type
)
2522 || GOT_TLS_GD_P (tls_type
))
2524 h
->got
.offset
= s
->size
;
2526 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2527 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2530 dyn
= htab
->elf
.dynamic_sections_created
;
2531 /* R_386_TLS_IE_32 needs one dynamic relocation,
2532 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2533 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2534 need two), R_386_TLS_GD needs one if local symbol and two if
2536 if (tls_type
== GOT_TLS_IE_BOTH
)
2537 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2538 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2539 || (tls_type
& GOT_TLS_IE
))
2540 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2541 else if (GOT_TLS_GD_P (tls_type
))
2542 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2543 else if (! GOT_TLS_GDESC_P (tls_type
)
2544 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2545 || h
->root
.type
!= bfd_link_hash_undefweak
)
2546 && (bfd_link_pic (info
)
2547 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2548 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2549 if (GOT_TLS_GDESC_P (tls_type
))
2550 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2553 h
->got
.offset
= (bfd_vma
) -1;
2555 if (eh
->dyn_relocs
== NULL
)
2558 /* In the shared -Bsymbolic case, discard space allocated for
2559 dynamic pc-relative relocs against symbols which turn out to be
2560 defined in regular objects. For the normal shared case, discard
2561 space for pc-relative relocs that have become local due to symbol
2562 visibility changes. */
2564 if (bfd_link_pic (info
))
2566 /* The only reloc that uses pc_count is R_386_PC32, which will
2567 appear on a call or on something like ".long foo - .". We
2568 want calls to protected symbols to resolve directly to the
2569 function rather than going via the plt. If people want
2570 function pointer comparisons to work as expected then they
2571 should avoid writing assembly like ".long foo - .". */
2572 if (SYMBOL_CALLS_LOCAL (info
, h
))
2574 struct elf_dyn_relocs
**pp
;
2576 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2578 p
->count
-= p
->pc_count
;
2587 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2589 struct elf_dyn_relocs
**pp
;
2590 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2592 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2599 /* Also discard relocs on undefined weak syms with non-default
2601 if (eh
->dyn_relocs
!= NULL
2602 && h
->root
.type
== bfd_link_hash_undefweak
)
2604 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2605 eh
->dyn_relocs
= NULL
;
2607 /* Make sure undefined weak symbols are output as a dynamic
2609 else if (h
->dynindx
== -1
2610 && !h
->forced_local
)
2612 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2617 else if (ELIMINATE_COPY_RELOCS
)
2619 /* For the non-shared case, discard space for relocs against
2620 symbols which turn out to need copy relocs or are not
2621 dynamic. Keep dynamic relocations for run-time function
2622 pointer initialization. */
2624 if ((!h
->non_got_ref
|| eh
->func_pointer_refcount
> 0)
2627 || (htab
->elf
.dynamic_sections_created
2628 && (h
->root
.type
== bfd_link_hash_undefweak
2629 || h
->root
.type
== bfd_link_hash_undefined
))))
2631 /* Make sure this symbol is output as a dynamic symbol.
2632 Undefined weak syms won't yet be marked as dynamic. */
2633 if (h
->dynindx
== -1
2634 && !h
->forced_local
)
2636 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2640 /* If that succeeded, we know we'll be keeping all the
2642 if (h
->dynindx
!= -1)
2646 eh
->dyn_relocs
= NULL
;
2647 eh
->func_pointer_refcount
= 0;
2652 /* Finally, allocate space. */
2653 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2657 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2659 BFD_ASSERT (sreloc
!= NULL
);
2660 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2666 /* Allocate space in .plt, .got and associated reloc sections for
2667 local dynamic relocs. */
2670 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2672 struct elf_link_hash_entry
*h
2673 = (struct elf_link_hash_entry
*) *slot
;
2675 if (h
->type
!= STT_GNU_IFUNC
2679 || h
->root
.type
!= bfd_link_hash_defined
)
2682 return elf_i386_allocate_dynrelocs (h
, inf
);
2685 /* Find any dynamic relocs that apply to read-only sections. */
2688 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2690 struct elf_i386_link_hash_entry
*eh
;
2691 struct elf_dyn_relocs
*p
;
2693 /* Skip local IFUNC symbols. */
2694 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2697 eh
= (struct elf_i386_link_hash_entry
*) h
;
2698 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2700 asection
*s
= p
->sec
->output_section
;
2702 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2704 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2706 info
->flags
|= DF_TEXTREL
;
2708 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
2709 || info
->error_textrel
)
2710 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
2711 p
->sec
->owner
, h
->root
.root
.string
,
2714 /* Not an error, just cut short the traversal. */
2722 mov foo@GOT(%reg), %reg
2724 lea foo@GOTOFF(%reg), %reg
2725 with the local symbol, foo. */
2728 elf_i386_convert_mov_to_lea (bfd
*abfd
, asection
*sec
,
2729 struct bfd_link_info
*link_info
)
2731 Elf_Internal_Shdr
*symtab_hdr
;
2732 Elf_Internal_Rela
*internal_relocs
;
2733 Elf_Internal_Rela
*irel
, *irelend
;
2735 struct elf_i386_link_hash_table
*htab
;
2736 bfd_boolean changed_contents
;
2737 bfd_boolean changed_relocs
;
2738 bfd_signed_vma
*local_got_refcounts
;
2740 /* Don't even try to convert non-ELF outputs. */
2741 if (!is_elf_hash_table (link_info
->hash
))
2744 /* Nothing to do if there is no need or no output. */
2745 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
2746 || sec
->need_convert_mov_to_lea
== 0
2747 || bfd_is_abs_section (sec
->output_section
))
2750 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2752 /* Load the relocations for this section. */
2753 internal_relocs
= (_bfd_elf_link_read_relocs
2754 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2755 link_info
->keep_memory
));
2756 if (internal_relocs
== NULL
)
2759 htab
= elf_i386_hash_table (link_info
);
2760 changed_contents
= FALSE
;
2761 changed_relocs
= FALSE
;
2762 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2764 /* Get the section contents. */
2765 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2766 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2769 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2773 irelend
= internal_relocs
+ sec
->reloc_count
;
2774 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2776 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
2777 unsigned int r_symndx
= ELF32_R_SYM (irel
->r_info
);
2779 struct elf_link_hash_entry
*h
;
2781 if (r_type
!= R_386_GOT32
)
2784 /* Get the symbol referred to by the reloc. */
2785 if (r_symndx
< symtab_hdr
->sh_info
)
2787 Elf_Internal_Sym
*isym
;
2789 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2792 /* STT_GNU_IFUNC must keep R_386_GOT32 relocation. */
2793 if (ELF_ST_TYPE (isym
->st_info
) != STT_GNU_IFUNC
2794 && irel
->r_offset
>= 2
2795 && bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 2) == 0x8b)
2797 bfd_put_8 (abfd
, 0x8d, contents
+ irel
->r_offset
- 2);
2798 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_GOTOFF
);
2799 if (local_got_refcounts
!= NULL
2800 && local_got_refcounts
[r_symndx
] > 0)
2801 local_got_refcounts
[r_symndx
] -= 1;
2802 changed_contents
= TRUE
;
2803 changed_relocs
= TRUE
;
2808 indx
= r_symndx
- symtab_hdr
->sh_info
;
2809 h
= elf_sym_hashes (abfd
)[indx
];
2810 BFD_ASSERT (h
!= NULL
);
2812 while (h
->root
.type
== bfd_link_hash_indirect
2813 || h
->root
.type
== bfd_link_hash_warning
)
2814 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2816 /* STT_GNU_IFUNC must keep R_386_GOT32 relocation. We also avoid
2817 optimizing _DYNAMIC since ld.so may use its link-time address. */
2819 && h
->type
!= STT_GNU_IFUNC
2820 && h
!= htab
->elf
.hdynamic
2821 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)
2822 && irel
->r_offset
>= 2
2823 && bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 2) == 0x8b)
2825 bfd_put_8 (abfd
, 0x8d, contents
+ irel
->r_offset
- 2);
2826 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_GOTOFF
);
2827 if (h
->got
.refcount
> 0)
2828 h
->got
.refcount
-= 1;
2829 changed_contents
= TRUE
;
2830 changed_relocs
= TRUE
;
2834 if (contents
!= NULL
2835 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2837 if (!changed_contents
&& !link_info
->keep_memory
)
2841 /* Cache the section contents for elf_link_input_bfd. */
2842 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2846 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2848 if (!changed_relocs
)
2849 free (internal_relocs
);
2851 elf_section_data (sec
)->relocs
= internal_relocs
;
2857 if (contents
!= NULL
2858 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2860 if (internal_relocs
!= NULL
2861 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2862 free (internal_relocs
);
2866 /* Set the sizes of the dynamic sections. */
2869 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2871 struct elf_i386_link_hash_table
*htab
;
2877 htab
= elf_i386_hash_table (info
);
2880 dynobj
= htab
->elf
.dynobj
;
2884 if (htab
->elf
.dynamic_sections_created
)
2886 /* Set the contents of the .interp section to the interpreter. */
2887 if (bfd_link_executable (info
) && !info
->nointerp
)
2889 s
= bfd_get_linker_section (dynobj
, ".interp");
2892 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2893 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2897 /* Set up .got offsets for local syms, and space for local dynamic
2899 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2901 bfd_signed_vma
*local_got
;
2902 bfd_signed_vma
*end_local_got
;
2903 char *local_tls_type
;
2904 bfd_vma
*local_tlsdesc_gotent
;
2905 bfd_size_type locsymcount
;
2906 Elf_Internal_Shdr
*symtab_hdr
;
2909 if (! is_i386_elf (ibfd
))
2912 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2914 struct elf_dyn_relocs
*p
;
2916 if (!elf_i386_convert_mov_to_lea (ibfd
, s
, info
))
2919 for (p
= ((struct elf_dyn_relocs
*)
2920 elf_section_data (s
)->local_dynrel
);
2924 if (!bfd_is_abs_section (p
->sec
)
2925 && bfd_is_abs_section (p
->sec
->output_section
))
2927 /* Input section has been discarded, either because
2928 it is a copy of a linkonce section or due to
2929 linker script /DISCARD/, so we'll be discarding
2932 else if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2933 && strcmp (p
->sec
->output_section
->name
,
2936 /* Relocations in vxworks .tls_vars sections are
2937 handled specially by the loader. */
2939 else if (p
->count
!= 0)
2941 srel
= elf_section_data (p
->sec
)->sreloc
;
2942 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2943 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2944 && (info
->flags
& DF_TEXTREL
) == 0)
2946 info
->flags
|= DF_TEXTREL
;
2947 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
2948 || info
->error_textrel
)
2949 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
2950 p
->sec
->owner
, p
->sec
);
2956 local_got
= elf_local_got_refcounts (ibfd
);
2960 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2961 locsymcount
= symtab_hdr
->sh_info
;
2962 end_local_got
= local_got
+ locsymcount
;
2963 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2964 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2966 srel
= htab
->elf
.srelgot
;
2967 for (; local_got
< end_local_got
;
2968 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2970 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2973 if (GOT_TLS_GDESC_P (*local_tls_type
))
2975 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2976 - elf_i386_compute_jump_table_size (htab
);
2977 htab
->elf
.sgotplt
->size
+= 8;
2978 *local_got
= (bfd_vma
) -2;
2980 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2981 || GOT_TLS_GD_P (*local_tls_type
))
2983 *local_got
= s
->size
;
2985 if (GOT_TLS_GD_P (*local_tls_type
)
2986 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2989 if (bfd_link_pic (info
)
2990 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2991 || (*local_tls_type
& GOT_TLS_IE
))
2993 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2994 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2995 else if (GOT_TLS_GD_P (*local_tls_type
)
2996 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2997 srel
->size
+= sizeof (Elf32_External_Rel
);
2998 if (GOT_TLS_GDESC_P (*local_tls_type
))
2999 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
3003 *local_got
= (bfd_vma
) -1;
3007 if (htab
->tls_ldm_got
.refcount
> 0)
3009 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
3011 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
3012 htab
->elf
.sgot
->size
+= 8;
3013 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
3016 htab
->tls_ldm_got
.offset
= -1;
3018 /* Allocate global sym .plt and .got entries, and space for global
3019 sym dynamic relocs. */
3020 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
3022 /* Allocate .plt and .got entries, and space for local symbols. */
3023 htab_traverse (htab
->loc_hash_table
,
3024 elf_i386_allocate_local_dynrelocs
,
3027 /* For every jump slot reserved in the sgotplt, reloc_count is
3028 incremented. However, when we reserve space for TLS descriptors,
3029 it's not incremented, so in order to compute the space reserved
3030 for them, it suffices to multiply the reloc count by the jump
3033 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3034 so that R_386_IRELATIVE entries come last. */
3035 if (htab
->elf
.srelplt
)
3037 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
3038 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
3039 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3041 else if (htab
->elf
.irelplt
)
3042 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3045 if (htab
->elf
.sgotplt
)
3047 /* Don't allocate .got.plt section if there are no GOT nor PLT
3048 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
3049 if ((htab
->elf
.hgot
== NULL
3050 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3051 && (htab
->elf
.sgotplt
->size
3052 == get_elf_backend_data (output_bfd
)->got_header_size
)
3053 && (htab
->elf
.splt
== NULL
3054 || htab
->elf
.splt
->size
== 0)
3055 && (htab
->elf
.sgot
== NULL
3056 || htab
->elf
.sgot
->size
== 0)
3057 && (htab
->elf
.iplt
== NULL
3058 || htab
->elf
.iplt
->size
== 0)
3059 && (htab
->elf
.igotplt
== NULL
3060 || htab
->elf
.igotplt
->size
== 0))
3061 htab
->elf
.sgotplt
->size
= 0;
3065 if (htab
->plt_eh_frame
!= NULL
3066 && htab
->elf
.splt
!= NULL
3067 && htab
->elf
.splt
->size
!= 0
3068 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
)
3069 && _bfd_elf_eh_frame_present (info
))
3070 htab
->plt_eh_frame
->size
= sizeof (elf_i386_eh_frame_plt
);
3072 /* We now have determined the sizes of the various dynamic sections.
3073 Allocate memory for them. */
3075 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3077 bfd_boolean strip_section
= TRUE
;
3079 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3082 if (s
== htab
->elf
.splt
3083 || s
== htab
->elf
.sgot
)
3085 /* Strip this section if we don't need it; see the
3087 /* We'd like to strip these sections if they aren't needed, but if
3088 we've exported dynamic symbols from them we must leave them.
3089 It's too late to tell BFD to get rid of the symbols. */
3091 if (htab
->elf
.hplt
!= NULL
)
3092 strip_section
= FALSE
;
3094 else if (s
== htab
->elf
.sgotplt
3095 || s
== htab
->elf
.iplt
3096 || s
== htab
->elf
.igotplt
3097 || s
== htab
->plt_got
3098 || s
== htab
->plt_eh_frame
3099 || s
== htab
->sdynbss
)
3101 /* Strip these too. */
3103 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3106 && s
!= htab
->elf
.srelplt
3107 && s
!= htab
->srelplt2
)
3110 /* We use the reloc_count field as a counter if we need
3111 to copy relocs into the output file. */
3116 /* It's not one of our sections, so don't allocate space. */
3122 /* If we don't need this section, strip it from the
3123 output file. This is mostly to handle .rel.bss and
3124 .rel.plt. We must create both sections in
3125 create_dynamic_sections, because they must be created
3126 before the linker maps input sections to output
3127 sections. The linker does that before
3128 adjust_dynamic_symbol is called, and it is that
3129 function which decides whether anything needs to go
3130 into these sections. */
3132 s
->flags
|= SEC_EXCLUDE
;
3136 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3139 /* Allocate memory for the section contents. We use bfd_zalloc
3140 here in case unused entries are not reclaimed before the
3141 section's contents are written out. This should not happen,
3142 but this way if it does, we get a R_386_NONE reloc instead
3144 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3145 if (s
->contents
== NULL
)
3149 if (htab
->plt_eh_frame
!= NULL
3150 && htab
->plt_eh_frame
->contents
!= NULL
)
3152 memcpy (htab
->plt_eh_frame
->contents
, elf_i386_eh_frame_plt
,
3153 sizeof (elf_i386_eh_frame_plt
));
3154 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3155 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3158 if (htab
->elf
.dynamic_sections_created
)
3160 /* Add some entries to the .dynamic section. We fill in the
3161 values later, in elf_i386_finish_dynamic_sections, but we
3162 must add the entries now so that we get the correct size for
3163 the .dynamic section. The DT_DEBUG entry is filled in by the
3164 dynamic linker and used by the debugger. */
3165 #define add_dynamic_entry(TAG, VAL) \
3166 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3168 if (bfd_link_executable (info
))
3170 if (!add_dynamic_entry (DT_DEBUG
, 0))
3174 if (htab
->elf
.splt
->size
!= 0)
3176 /* DT_PLTGOT is used by prelink even if there is no PLT
3178 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3181 if (htab
->elf
.srelplt
->size
!= 0)
3183 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3184 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3185 || !add_dynamic_entry (DT_JMPREL
, 0))
3192 if (!add_dynamic_entry (DT_REL
, 0)
3193 || !add_dynamic_entry (DT_RELSZ
, 0)
3194 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3197 /* If any dynamic relocs apply to a read-only section,
3198 then we need a DT_TEXTREL entry. */
3199 if ((info
->flags
& DF_TEXTREL
) == 0)
3200 elf_link_hash_traverse (&htab
->elf
,
3201 elf_i386_readonly_dynrelocs
, info
);
3203 if ((info
->flags
& DF_TEXTREL
) != 0)
3205 if ((elf_tdata (output_bfd
)->has_gnu_symbols
3206 & elf_gnu_symbol_ifunc
) == elf_gnu_symbol_ifunc
)
3208 info
->callbacks
->einfo
3209 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3210 bfd_set_error (bfd_error_bad_value
);
3214 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3218 if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3219 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3222 #undef add_dynamic_entry
3228 elf_i386_always_size_sections (bfd
*output_bfd
,
3229 struct bfd_link_info
*info
)
3231 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3235 struct elf_link_hash_entry
*tlsbase
;
3237 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3238 "_TLS_MODULE_BASE_",
3239 FALSE
, FALSE
, FALSE
);
3241 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3243 struct elf_i386_link_hash_table
*htab
;
3244 struct bfd_link_hash_entry
*bh
= NULL
;
3245 const struct elf_backend_data
*bed
3246 = get_elf_backend_data (output_bfd
);
3248 htab
= elf_i386_hash_table (info
);
3252 if (!(_bfd_generic_link_add_one_symbol
3253 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3254 tls_sec
, 0, NULL
, FALSE
,
3255 bed
->collect
, &bh
)))
3258 htab
->tls_module_base
= bh
;
3260 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3261 tlsbase
->def_regular
= 1;
3262 tlsbase
->other
= STV_HIDDEN
;
3263 tlsbase
->root
.linker_def
= 1;
3264 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
3271 /* Set the correct type for an x86 ELF section. We do this by the
3272 section name, which is a hack, but ought to work. */
3275 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3276 Elf_Internal_Shdr
*hdr
,
3281 name
= bfd_get_section_name (abfd
, sec
);
3283 /* This is an ugly, but unfortunately necessary hack that is
3284 needed when producing EFI binaries on x86. It tells
3285 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3286 containing ELF relocation info. We need this hack in order to
3287 be able to generate ELF binaries that can be translated into
3288 EFI applications (which are essentially COFF objects). Those
3289 files contain a COFF ".reloc" section inside an ELFNN object,
3290 which would normally cause BFD to segfault because it would
3291 attempt to interpret this section as containing relocation
3292 entries for section "oc". With this hack enabled, ".reloc"
3293 will be treated as a normal data section, which will avoid the
3294 segfault. However, you won't be able to create an ELFNN binary
3295 with a section named "oc" that needs relocations, but that's
3296 the kind of ugly side-effects you get when detecting section
3297 types based on their names... In practice, this limitation is
3298 unlikely to bite. */
3299 if (strcmp (name
, ".reloc") == 0)
3300 hdr
->sh_type
= SHT_PROGBITS
;
3305 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3306 executables. Rather than setting it to the beginning of the TLS
3307 section, we have to set it to the end. This function may be called
3308 multiple times, it is idempotent. */
3311 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
3313 struct elf_i386_link_hash_table
*htab
;
3314 struct bfd_link_hash_entry
*base
;
3316 if (!bfd_link_executable (info
))
3319 htab
= elf_i386_hash_table (info
);
3323 base
= htab
->tls_module_base
;
3327 base
->u
.def
.value
= htab
->elf
.tls_size
;
3330 /* Return the base VMA address which should be subtracted from real addresses
3331 when resolving @dtpoff relocation.
3332 This is PT_TLS segment p_vaddr. */
3335 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
3337 /* If tls_sec is NULL, we should have signalled an error already. */
3338 if (elf_hash_table (info
)->tls_sec
== NULL
)
3340 return elf_hash_table (info
)->tls_sec
->vma
;
3343 /* Return the relocation value for @tpoff relocation
3344 if STT_TLS virtual address is ADDRESS. */
3347 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3349 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3350 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3351 bfd_vma static_tls_size
;
3353 /* If tls_sec is NULL, we should have signalled an error already. */
3354 if (htab
->tls_sec
== NULL
)
3357 /* Consider special static TLS alignment requirements. */
3358 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3359 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3362 /* Relocate an i386 ELF section. */
3365 elf_i386_relocate_section (bfd
*output_bfd
,
3366 struct bfd_link_info
*info
,
3368 asection
*input_section
,
3370 Elf_Internal_Rela
*relocs
,
3371 Elf_Internal_Sym
*local_syms
,
3372 asection
**local_sections
)
3374 struct elf_i386_link_hash_table
*htab
;
3375 Elf_Internal_Shdr
*symtab_hdr
;
3376 struct elf_link_hash_entry
**sym_hashes
;
3377 bfd_vma
*local_got_offsets
;
3378 bfd_vma
*local_tlsdesc_gotents
;
3379 Elf_Internal_Rela
*rel
;
3380 Elf_Internal_Rela
*relend
;
3381 bfd_boolean is_vxworks_tls
;
3382 unsigned plt_entry_size
;
3384 BFD_ASSERT (is_i386_elf (input_bfd
));
3386 htab
= elf_i386_hash_table (info
);
3389 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3390 sym_hashes
= elf_sym_hashes (input_bfd
);
3391 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3392 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3393 /* We have to handle relocations in vxworks .tls_vars sections
3394 specially, because the dynamic loader is 'weird'. */
3395 is_vxworks_tls
= (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3396 && bfd_link_pic (info
)
3397 && !strcmp (input_section
->output_section
->name
,
3400 elf_i386_set_tls_module_base (info
);
3402 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
3405 relend
= relocs
+ input_section
->reloc_count
;
3406 for (; rel
< relend
; rel
++)
3408 unsigned int r_type
;
3409 reloc_howto_type
*howto
;
3410 unsigned long r_symndx
;
3411 struct elf_link_hash_entry
*h
;
3412 struct elf_i386_link_hash_entry
*eh
;
3413 Elf_Internal_Sym
*sym
;
3415 bfd_vma off
, offplt
, plt_offset
;
3417 bfd_boolean unresolved_reloc
;
3418 bfd_reloc_status_type r
;
3422 asection
*resolved_plt
;
3424 r_type
= ELF32_R_TYPE (rel
->r_info
);
3425 if (r_type
== R_386_GNU_VTINHERIT
3426 || r_type
== R_386_GNU_VTENTRY
)
3429 if ((indx
= r_type
) >= R_386_standard
3430 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3431 >= R_386_ext
- R_386_standard
)
3432 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3433 >= R_386_ext2
- R_386_ext
))
3435 (*_bfd_error_handler
)
3436 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3437 input_bfd
, input_section
, r_type
);
3438 bfd_set_error (bfd_error_bad_value
);
3441 howto
= elf_howto_table
+ indx
;
3443 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3447 unresolved_reloc
= FALSE
;
3448 if (r_symndx
< symtab_hdr
->sh_info
)
3450 sym
= local_syms
+ r_symndx
;
3451 sec
= local_sections
[r_symndx
];
3452 relocation
= (sec
->output_section
->vma
3453 + sec
->output_offset
3455 st_size
= sym
->st_size
;
3457 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3458 && ((sec
->flags
& SEC_MERGE
) != 0
3459 || (bfd_link_relocatable (info
)
3460 && sec
->output_offset
!= 0)))
3463 bfd_byte
*where
= contents
+ rel
->r_offset
;
3465 switch (howto
->size
)
3468 addend
= bfd_get_8 (input_bfd
, where
);
3469 if (howto
->pc_relative
)
3471 addend
= (addend
^ 0x80) - 0x80;
3476 addend
= bfd_get_16 (input_bfd
, where
);
3477 if (howto
->pc_relative
)
3479 addend
= (addend
^ 0x8000) - 0x8000;
3484 addend
= bfd_get_32 (input_bfd
, where
);
3485 if (howto
->pc_relative
)
3487 addend
= (addend
^ 0x80000000) - 0x80000000;
3495 if (bfd_link_relocatable (info
))
3496 addend
+= sec
->output_offset
;
3499 asection
*msec
= sec
;
3500 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3502 addend
-= relocation
;
3503 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3506 switch (howto
->size
)
3509 /* FIXME: overflow checks. */
3510 if (howto
->pc_relative
)
3512 bfd_put_8 (input_bfd
, addend
, where
);
3515 if (howto
->pc_relative
)
3517 bfd_put_16 (input_bfd
, addend
, where
);
3520 if (howto
->pc_relative
)
3522 bfd_put_32 (input_bfd
, addend
, where
);
3526 else if (!bfd_link_relocatable (info
)
3527 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3529 /* Relocate against local STT_GNU_IFUNC symbol. */
3530 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3535 /* Set STT_GNU_IFUNC symbol value. */
3536 h
->root
.u
.def
.value
= sym
->st_value
;
3537 h
->root
.u
.def
.section
= sec
;
3542 bfd_boolean warned ATTRIBUTE_UNUSED
;
3543 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3545 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3546 r_symndx
, symtab_hdr
, sym_hashes
,
3548 unresolved_reloc
, warned
, ignored
);
3552 if (sec
!= NULL
&& discarded_section (sec
))
3553 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3554 rel
, 1, relend
, howto
, 0, contents
);
3556 if (bfd_link_relocatable (info
))
3559 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3560 it here if it is defined in a non-shared object. */
3562 && h
->type
== STT_GNU_IFUNC
3565 asection
*plt
, *gotplt
, *base_got
;
3569 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3571 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3572 sections because such sections are not SEC_ALLOC and
3573 thus ld.so will not process them. */
3574 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
3578 else if (h
->plt
.offset
== (bfd_vma
) -1)
3581 /* STT_GNU_IFUNC symbol must go through PLT. */
3582 if (htab
->elf
.splt
!= NULL
)
3584 plt
= htab
->elf
.splt
;
3585 gotplt
= htab
->elf
.sgotplt
;
3589 plt
= htab
->elf
.iplt
;
3590 gotplt
= htab
->elf
.igotplt
;
3593 relocation
= (plt
->output_section
->vma
3594 + plt
->output_offset
+ h
->plt
.offset
);
3599 if (h
->root
.root
.string
)
3600 name
= h
->root
.root
.string
;
3602 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3604 (*_bfd_error_handler
)
3605 (_("%B: relocation %s against STT_GNU_IFUNC "
3606 "symbol `%s' isn't handled by %s"), input_bfd
,
3607 elf_howto_table
[r_type
].name
,
3608 name
, __FUNCTION__
);
3609 bfd_set_error (bfd_error_bad_value
);
3613 /* Generate dynamic relcoation only when there is a
3614 non-GOT reference in a shared object. */
3615 if (bfd_link_pic (info
) && h
->non_got_ref
)
3617 Elf_Internal_Rela outrel
;
3621 /* Need a dynamic relocation to get the real function
3623 offset
= _bfd_elf_section_offset (output_bfd
,
3627 if (offset
== (bfd_vma
) -1
3628 || offset
== (bfd_vma
) -2)
3631 outrel
.r_offset
= (input_section
->output_section
->vma
3632 + input_section
->output_offset
3635 if (h
->dynindx
== -1
3637 || bfd_link_executable (info
))
3639 /* This symbol is resolved locally. */
3640 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3641 bfd_put_32 (output_bfd
,
3642 (h
->root
.u
.def
.value
3643 + h
->root
.u
.def
.section
->output_section
->vma
3644 + h
->root
.u
.def
.section
->output_offset
),
3648 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3650 sreloc
= htab
->elf
.irelifunc
;
3651 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3653 /* If this reloc is against an external symbol, we
3654 do not want to fiddle with the addend. Otherwise,
3655 we need to include the symbol value so that it
3656 becomes an addend for the dynamic reloc. For an
3657 internal symbol, we have updated addend. */
3666 base_got
= htab
->elf
.sgot
;
3667 off
= h
->got
.offset
;
3669 if (base_got
== NULL
)
3672 if (off
== (bfd_vma
) -1)
3674 /* We can't use h->got.offset here to save state, or
3675 even just remember the offset, as finish_dynamic_symbol
3676 would use that as offset into .got. */
3678 if (htab
->elf
.splt
!= NULL
)
3680 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3681 off
= (plt_index
+ 3) * 4;
3682 base_got
= htab
->elf
.sgotplt
;
3686 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3687 off
= plt_index
* 4;
3688 base_got
= htab
->elf
.igotplt
;
3691 if (h
->dynindx
== -1
3695 /* This references the local defitionion. We must
3696 initialize this entry in the global offset table.
3697 Since the offset must always be a multiple of 8,
3698 we use the least significant bit to record
3699 whether we have initialized it already.
3701 When doing a dynamic link, we create a .rela.got
3702 relocation entry to initialize the value. This
3703 is done in the finish_dynamic_symbol routine. */
3708 bfd_put_32 (output_bfd
, relocation
,
3709 base_got
->contents
+ off
);
3716 /* Adjust for static executables. */
3717 if (htab
->elf
.splt
== NULL
)
3718 relocation
+= gotplt
->output_offset
;
3722 relocation
= (base_got
->output_section
->vma
3723 + base_got
->output_offset
+ off
3724 - gotplt
->output_section
->vma
3725 - gotplt
->output_offset
);
3726 /* Adjust for static executables. */
3727 if (htab
->elf
.splt
== NULL
)
3728 relocation
+= gotplt
->output_offset
;
3734 relocation
-= (gotplt
->output_section
->vma
3735 + gotplt
->output_offset
);
3740 eh
= (struct elf_i386_link_hash_entry
*) h
;
3744 /* Relocation is to the entry for this symbol in the global
3746 if (htab
->elf
.sgot
== NULL
)
3753 off
= h
->got
.offset
;
3754 dyn
= htab
->elf
.dynamic_sections_created
;
3755 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
3756 bfd_link_pic (info
),
3758 || (bfd_link_pic (info
)
3759 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3760 || (ELF_ST_VISIBILITY (h
->other
)
3761 && h
->root
.type
== bfd_link_hash_undefweak
))
3763 /* This is actually a static link, or it is a
3764 -Bsymbolic link and the symbol is defined
3765 locally, or the symbol was forced to be local
3766 because of a version file. We must initialize
3767 this entry in the global offset table. Since the
3768 offset must always be a multiple of 4, we use the
3769 least significant bit to record whether we have
3770 initialized it already.
3772 When doing a dynamic link, we create a .rel.got
3773 relocation entry to initialize the value. This
3774 is done in the finish_dynamic_symbol routine. */
3779 bfd_put_32 (output_bfd
, relocation
,
3780 htab
->elf
.sgot
->contents
+ off
);
3785 unresolved_reloc
= FALSE
;
3789 if (local_got_offsets
== NULL
)
3792 off
= local_got_offsets
[r_symndx
];
3794 /* The offset must always be a multiple of 4. We use
3795 the least significant bit to record whether we have
3796 already generated the necessary reloc. */
3801 bfd_put_32 (output_bfd
, relocation
,
3802 htab
->elf
.sgot
->contents
+ off
);
3804 if (bfd_link_pic (info
))
3807 Elf_Internal_Rela outrel
;
3809 s
= htab
->elf
.srelgot
;
3813 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3814 + htab
->elf
.sgot
->output_offset
3816 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3817 elf_append_rel (output_bfd
, s
, &outrel
);
3820 local_got_offsets
[r_symndx
] |= 1;
3824 if (off
>= (bfd_vma
) -2)
3827 relocation
= htab
->elf
.sgot
->output_section
->vma
3828 + htab
->elf
.sgot
->output_offset
+ off
3829 - htab
->elf
.sgotplt
->output_section
->vma
3830 - htab
->elf
.sgotplt
->output_offset
;
3834 /* Relocation is relative to the start of the global offset
3837 /* Check to make sure it isn't a protected function or data
3838 symbol for shared library since it may not be local when
3839 used as function address or with copy relocation. We also
3840 need to make sure that a symbol is referenced locally. */
3841 if (!bfd_link_executable (info
) && h
)
3843 if (!h
->def_regular
)
3847 switch (ELF_ST_VISIBILITY (h
->other
))
3850 v
= _("hidden symbol");
3853 v
= _("internal symbol");
3856 v
= _("protected symbol");
3863 (*_bfd_error_handler
)
3864 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3865 input_bfd
, v
, h
->root
.root
.string
);
3866 bfd_set_error (bfd_error_bad_value
);
3869 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
3870 && (h
->type
== STT_FUNC
3871 || h
->type
== STT_OBJECT
)
3872 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3874 (*_bfd_error_handler
)
3875 (_("%B: relocation R_386_GOTOFF against protected %s `%s' can not be used when making a shared object"),
3877 h
->type
== STT_FUNC
? "function" : "data",
3878 h
->root
.root
.string
);
3879 bfd_set_error (bfd_error_bad_value
);
3884 /* Note that sgot is not involved in this
3885 calculation. We always want the start of .got.plt. If we
3886 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3887 permitted by the ABI, we might have to change this
3889 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3890 + htab
->elf
.sgotplt
->output_offset
;
3894 /* Use global offset table as symbol value. */
3895 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3896 + htab
->elf
.sgotplt
->output_offset
;
3897 unresolved_reloc
= FALSE
;
3901 /* Relocation is to the entry for this symbol in the
3902 procedure linkage table. */
3904 /* Resolve a PLT32 reloc against a local symbol directly,
3905 without using the procedure linkage table. */
3909 if ((h
->plt
.offset
== (bfd_vma
) -1
3910 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3911 || htab
->elf
.splt
== NULL
)
3913 /* We didn't make a PLT entry for this symbol. This
3914 happens when statically linking PIC code, or when
3915 using -Bsymbolic. */
3919 if (h
->plt
.offset
!= (bfd_vma
) -1)
3921 resolved_plt
= htab
->elf
.splt
;
3922 plt_offset
= h
->plt
.offset
;
3926 resolved_plt
= htab
->plt_got
;
3927 plt_offset
= eh
->plt_got
.offset
;
3930 relocation
= (resolved_plt
->output_section
->vma
3931 + resolved_plt
->output_offset
3933 unresolved_reloc
= FALSE
;
3937 /* Set to symbol size. */
3938 relocation
= st_size
;
3943 if ((input_section
->flags
& SEC_ALLOC
) == 0
3947 /* Copy dynamic function pointer relocations. */
3948 if ((bfd_link_pic (info
)
3950 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3951 || h
->root
.type
!= bfd_link_hash_undefweak
)
3952 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
3953 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3954 || (ELIMINATE_COPY_RELOCS
3955 && !bfd_link_pic (info
)
3958 && (!h
->non_got_ref
|| eh
->func_pointer_refcount
> 0)
3961 || h
->root
.type
== bfd_link_hash_undefweak
3962 || h
->root
.type
== bfd_link_hash_undefined
)))
3964 Elf_Internal_Rela outrel
;
3965 bfd_boolean skip
, relocate
;
3968 /* When generating a shared object, these relocations
3969 are copied into the output file to be resolved at run
3976 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3978 if (outrel
.r_offset
== (bfd_vma
) -1)
3980 else if (outrel
.r_offset
== (bfd_vma
) -2)
3981 skip
= TRUE
, relocate
= TRUE
;
3982 outrel
.r_offset
+= (input_section
->output_section
->vma
3983 + input_section
->output_offset
);
3986 memset (&outrel
, 0, sizeof outrel
);
3989 && (r_type
== R_386_PC32
3990 || !bfd_link_pic (info
)
3991 || !SYMBOLIC_BIND (info
, h
)
3992 || !h
->def_regular
))
3993 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3996 /* This symbol is local, or marked to become local. */
3998 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4001 sreloc
= elf_section_data (input_section
)->sreloc
;
4003 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4005 r
= bfd_reloc_notsupported
;
4006 goto check_relocation_error
;
4009 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4011 /* If this reloc is against an external symbol, we do
4012 not want to fiddle with the addend. Otherwise, we
4013 need to include the symbol value so that it becomes
4014 an addend for the dynamic reloc. */
4021 if (!bfd_link_executable (info
))
4023 Elf_Internal_Rela outrel
;
4026 outrel
.r_offset
= rel
->r_offset
4027 + input_section
->output_section
->vma
4028 + input_section
->output_offset
;
4029 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4030 sreloc
= elf_section_data (input_section
)->sreloc
;
4033 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4038 case R_386_TLS_GOTDESC
:
4039 case R_386_TLS_DESC_CALL
:
4040 case R_386_TLS_IE_32
:
4041 case R_386_TLS_GOTIE
:
4042 tls_type
= GOT_UNKNOWN
;
4043 if (h
== NULL
&& local_got_offsets
)
4044 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
4046 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
4047 if (tls_type
== GOT_TLS_IE
)
4048 tls_type
= GOT_TLS_IE_NEG
;
4050 if (! elf_i386_tls_transition (info
, input_bfd
,
4051 input_section
, contents
,
4052 symtab_hdr
, sym_hashes
,
4053 &r_type
, tls_type
, rel
,
4054 relend
, h
, r_symndx
))
4057 if (r_type
== R_386_TLS_LE_32
)
4059 BFD_ASSERT (! unresolved_reloc
);
4060 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4065 /* GD->LE transition. */
4066 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4069 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
4071 movl %gs:0, %eax; subl $foo@tpoff, %eax
4072 (6 byte form of subl). */
4073 memcpy (contents
+ rel
->r_offset
- 3,
4074 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4075 roff
= rel
->r_offset
+ 5;
4079 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
4081 movl %gs:0, %eax; subl $foo@tpoff, %eax
4082 (6 byte form of subl). */
4083 memcpy (contents
+ rel
->r_offset
- 2,
4084 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
4085 roff
= rel
->r_offset
+ 6;
4087 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4089 /* Skip R_386_PC32/R_386_PLT32. */
4093 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4095 /* GDesc -> LE transition.
4096 It's originally something like:
4097 leal x@tlsdesc(%ebx), %eax
4101 Registers other than %eax may be set up here. */
4106 roff
= rel
->r_offset
;
4107 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4109 /* Now modify the instruction as appropriate. */
4110 /* aoliva FIXME: remove the above and xor the byte
4112 bfd_put_8 (output_bfd
, val
^ 0x86,
4113 contents
+ roff
- 1);
4114 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4118 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4120 /* GDesc -> LE transition.
4128 roff
= rel
->r_offset
;
4129 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4130 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4133 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4137 /* IE->LE transition:
4138 Originally it can be one of:
4146 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4149 /* movl foo, %eax. */
4150 bfd_put_8 (output_bfd
, 0xb8,
4151 contents
+ rel
->r_offset
- 1);
4157 type
= bfd_get_8 (input_bfd
,
4158 contents
+ rel
->r_offset
- 2);
4163 bfd_put_8 (output_bfd
, 0xc7,
4164 contents
+ rel
->r_offset
- 2);
4165 bfd_put_8 (output_bfd
,
4166 0xc0 | ((val
>> 3) & 7),
4167 contents
+ rel
->r_offset
- 1);
4171 bfd_put_8 (output_bfd
, 0x81,
4172 contents
+ rel
->r_offset
- 2);
4173 bfd_put_8 (output_bfd
,
4174 0xc0 | ((val
>> 3) & 7),
4175 contents
+ rel
->r_offset
- 1);
4182 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4183 contents
+ rel
->r_offset
);
4188 unsigned int val
, type
;
4190 /* {IE_32,GOTIE}->LE transition:
4191 Originally it can be one of:
4192 subl foo(%reg1), %reg2
4193 movl foo(%reg1), %reg2
4194 addl foo(%reg1), %reg2
4197 movl $foo, %reg2 (6 byte form)
4198 addl $foo, %reg2. */
4199 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4200 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4204 bfd_put_8 (output_bfd
, 0xc7,
4205 contents
+ rel
->r_offset
- 2);
4206 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4207 contents
+ rel
->r_offset
- 1);
4209 else if (type
== 0x2b)
4212 bfd_put_8 (output_bfd
, 0x81,
4213 contents
+ rel
->r_offset
- 2);
4214 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4215 contents
+ rel
->r_offset
- 1);
4217 else if (type
== 0x03)
4220 bfd_put_8 (output_bfd
, 0x81,
4221 contents
+ rel
->r_offset
- 2);
4222 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4223 contents
+ rel
->r_offset
- 1);
4227 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4228 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4229 contents
+ rel
->r_offset
);
4231 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4232 contents
+ rel
->r_offset
);
4237 if (htab
->elf
.sgot
== NULL
)
4242 off
= h
->got
.offset
;
4243 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
4247 if (local_got_offsets
== NULL
)
4250 off
= local_got_offsets
[r_symndx
];
4251 offplt
= local_tlsdesc_gotents
[r_symndx
];
4258 Elf_Internal_Rela outrel
;
4262 if (htab
->elf
.srelgot
== NULL
)
4265 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4267 if (GOT_TLS_GDESC_P (tls_type
))
4270 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4271 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4272 <= htab
->elf
.sgotplt
->size
);
4273 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4274 + htab
->elf
.sgotplt
->output_offset
4276 + htab
->sgotplt_jump_table_size
);
4277 sreloc
= htab
->elf
.srelplt
;
4278 loc
= sreloc
->contents
;
4279 loc
+= (htab
->next_tls_desc_index
++
4280 * sizeof (Elf32_External_Rel
));
4281 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4282 <= sreloc
->contents
+ sreloc
->size
);
4283 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4286 BFD_ASSERT (! unresolved_reloc
);
4287 bfd_put_32 (output_bfd
,
4288 relocation
- elf_i386_dtpoff_base (info
),
4289 htab
->elf
.sgotplt
->contents
+ offplt
4290 + htab
->sgotplt_jump_table_size
+ 4);
4294 bfd_put_32 (output_bfd
, 0,
4295 htab
->elf
.sgotplt
->contents
+ offplt
4296 + htab
->sgotplt_jump_table_size
+ 4);
4300 sreloc
= htab
->elf
.srelgot
;
4302 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4303 + htab
->elf
.sgot
->output_offset
+ off
);
4305 if (GOT_TLS_GD_P (tls_type
))
4306 dr_type
= R_386_TLS_DTPMOD32
;
4307 else if (GOT_TLS_GDESC_P (tls_type
))
4309 else if (tls_type
== GOT_TLS_IE_POS
)
4310 dr_type
= R_386_TLS_TPOFF
;
4312 dr_type
= R_386_TLS_TPOFF32
;
4314 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
4315 bfd_put_32 (output_bfd
,
4316 relocation
- elf_i386_dtpoff_base (info
),
4317 htab
->elf
.sgot
->contents
+ off
);
4318 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
4319 bfd_put_32 (output_bfd
,
4320 elf_i386_dtpoff_base (info
) - relocation
,
4321 htab
->elf
.sgot
->contents
+ off
);
4322 else if (dr_type
!= R_386_TLS_DESC
)
4323 bfd_put_32 (output_bfd
, 0,
4324 htab
->elf
.sgot
->contents
+ off
);
4325 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
4327 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4329 if (GOT_TLS_GD_P (tls_type
))
4333 BFD_ASSERT (! unresolved_reloc
);
4334 bfd_put_32 (output_bfd
,
4335 relocation
- elf_i386_dtpoff_base (info
),
4336 htab
->elf
.sgot
->contents
+ off
+ 4);
4340 bfd_put_32 (output_bfd
, 0,
4341 htab
->elf
.sgot
->contents
+ off
+ 4);
4342 outrel
.r_info
= ELF32_R_INFO (indx
,
4343 R_386_TLS_DTPOFF32
);
4344 outrel
.r_offset
+= 4;
4345 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4348 else if (tls_type
== GOT_TLS_IE_BOTH
)
4350 bfd_put_32 (output_bfd
,
4352 ? relocation
- elf_i386_dtpoff_base (info
)
4354 htab
->elf
.sgot
->contents
+ off
+ 4);
4355 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4356 outrel
.r_offset
+= 4;
4357 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4364 local_got_offsets
[r_symndx
] |= 1;
4367 if (off
>= (bfd_vma
) -2
4368 && ! GOT_TLS_GDESC_P (tls_type
))
4370 if (r_type
== R_386_TLS_GOTDESC
4371 || r_type
== R_386_TLS_DESC_CALL
)
4373 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4374 unresolved_reloc
= FALSE
;
4376 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4378 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4379 + htab
->elf
.sgotplt
->output_offset
;
4380 relocation
= htab
->elf
.sgot
->output_section
->vma
4381 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4382 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4383 && tls_type
== GOT_TLS_IE_BOTH
)
4385 if (r_type
== R_386_TLS_IE
)
4386 relocation
+= g_o_t
;
4387 unresolved_reloc
= FALSE
;
4389 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4391 unsigned int val
, type
;
4394 /* GD->IE transition. */
4395 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4396 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4399 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
4401 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4403 roff
= rel
->r_offset
- 3;
4407 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
4409 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4410 roff
= rel
->r_offset
- 2;
4412 memcpy (contents
+ roff
,
4413 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4414 contents
[roff
+ 7] = 0x80 | (val
& 7);
4415 /* If foo is used only with foo@gotntpoff(%reg) and
4416 foo@indntpoff, but not with foo@gottpoff(%reg), change
4417 subl $foo@gottpoff(%reg), %eax
4419 addl $foo@gotntpoff(%reg), %eax. */
4420 if (tls_type
== GOT_TLS_IE_POS
)
4421 contents
[roff
+ 6] = 0x03;
4422 bfd_put_32 (output_bfd
,
4423 htab
->elf
.sgot
->output_section
->vma
4424 + htab
->elf
.sgot
->output_offset
+ off
4425 - htab
->elf
.sgotplt
->output_section
->vma
4426 - htab
->elf
.sgotplt
->output_offset
,
4427 contents
+ roff
+ 8);
4428 /* Skip R_386_PLT32. */
4432 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4434 /* GDesc -> IE transition.
4435 It's originally something like:
4436 leal x@tlsdesc(%ebx), %eax
4439 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4441 movl x@gottpoff(%ebx), %eax # before negl %eax
4443 Registers other than %eax may be set up here. */
4447 /* First, make sure it's a leal adding ebx to a 32-bit
4448 offset into any register, although it's probably
4449 almost always going to be eax. */
4450 roff
= rel
->r_offset
;
4452 /* Now modify the instruction as appropriate. */
4453 /* To turn a leal into a movl in the form we use it, it
4454 suffices to change the first byte from 0x8d to 0x8b.
4455 aoliva FIXME: should we decide to keep the leal, all
4456 we have to do is remove the statement below, and
4457 adjust the relaxation of R_386_TLS_DESC_CALL. */
4458 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4460 if (tls_type
== GOT_TLS_IE_BOTH
)
4463 bfd_put_32 (output_bfd
,
4464 htab
->elf
.sgot
->output_section
->vma
4465 + htab
->elf
.sgot
->output_offset
+ off
4466 - htab
->elf
.sgotplt
->output_section
->vma
4467 - htab
->elf
.sgotplt
->output_offset
,
4471 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4473 /* GDesc -> IE transition.
4481 depending on how we transformed the TLS_GOTDESC above.
4486 roff
= rel
->r_offset
;
4488 /* Now modify the instruction as appropriate. */
4489 if (tls_type
!= GOT_TLS_IE_NEG
)
4492 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4493 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4498 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4499 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4509 if (! elf_i386_tls_transition (info
, input_bfd
,
4510 input_section
, contents
,
4511 symtab_hdr
, sym_hashes
,
4512 &r_type
, GOT_UNKNOWN
, rel
,
4513 relend
, h
, r_symndx
))
4516 if (r_type
!= R_386_TLS_LDM
)
4518 /* LD->LE transition:
4519 leal foo(%reg), %eax; call ___tls_get_addr.
4521 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
4522 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4523 memcpy (contents
+ rel
->r_offset
- 2,
4524 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4525 /* Skip R_386_PC32/R_386_PLT32. */
4530 if (htab
->elf
.sgot
== NULL
)
4533 off
= htab
->tls_ldm_got
.offset
;
4538 Elf_Internal_Rela outrel
;
4540 if (htab
->elf
.srelgot
== NULL
)
4543 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4544 + htab
->elf
.sgot
->output_offset
+ off
);
4546 bfd_put_32 (output_bfd
, 0,
4547 htab
->elf
.sgot
->contents
+ off
);
4548 bfd_put_32 (output_bfd
, 0,
4549 htab
->elf
.sgot
->contents
+ off
+ 4);
4550 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4551 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
4552 htab
->tls_ldm_got
.offset
|= 1;
4554 relocation
= htab
->elf
.sgot
->output_section
->vma
4555 + htab
->elf
.sgot
->output_offset
+ off
4556 - htab
->elf
.sgotplt
->output_section
->vma
4557 - htab
->elf
.sgotplt
->output_offset
;
4558 unresolved_reloc
= FALSE
;
4561 case R_386_TLS_LDO_32
:
4562 if (!bfd_link_executable (info
)
4563 || (input_section
->flags
& SEC_CODE
) == 0)
4564 relocation
-= elf_i386_dtpoff_base (info
);
4566 /* When converting LDO to LE, we must negate. */
4567 relocation
= -elf_i386_tpoff (info
, relocation
);
4570 case R_386_TLS_LE_32
:
4572 if (!bfd_link_executable (info
))
4574 Elf_Internal_Rela outrel
;
4577 outrel
.r_offset
= rel
->r_offset
4578 + input_section
->output_section
->vma
4579 + input_section
->output_offset
;
4580 if (h
!= NULL
&& h
->dynindx
!= -1)
4584 if (r_type
== R_386_TLS_LE_32
)
4585 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4587 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4588 sreloc
= elf_section_data (input_section
)->sreloc
;
4591 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4594 else if (r_type
== R_386_TLS_LE_32
)
4595 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4597 relocation
-= elf_i386_dtpoff_base (info
);
4599 else if (r_type
== R_386_TLS_LE_32
)
4600 relocation
= elf_i386_tpoff (info
, relocation
);
4602 relocation
= -elf_i386_tpoff (info
, relocation
);
4609 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4610 because such sections are not SEC_ALLOC and thus ld.so will
4611 not process them. */
4612 if (unresolved_reloc
4613 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4615 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4616 rel
->r_offset
) != (bfd_vma
) -1)
4618 (*_bfd_error_handler
)
4619 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4622 (long) rel
->r_offset
,
4624 h
->root
.root
.string
);
4629 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4630 contents
, rel
->r_offset
,
4633 check_relocation_error
:
4634 if (r
!= bfd_reloc_ok
)
4639 name
= h
->root
.root
.string
;
4642 name
= bfd_elf_string_from_elf_section (input_bfd
,
4643 symtab_hdr
->sh_link
,
4648 name
= bfd_section_name (input_bfd
, sec
);
4651 if (r
== bfd_reloc_overflow
)
4653 if (! ((*info
->callbacks
->reloc_overflow
)
4654 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4655 (bfd_vma
) 0, input_bfd
, input_section
,
4661 (*_bfd_error_handler
)
4662 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4663 input_bfd
, input_section
,
4664 (long) rel
->r_offset
, name
, (int) r
);
4673 /* Finish up dynamic symbol handling. We set the contents of various
4674 dynamic sections here. */
4677 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4678 struct bfd_link_info
*info
,
4679 struct elf_link_hash_entry
*h
,
4680 Elf_Internal_Sym
*sym
)
4682 struct elf_i386_link_hash_table
*htab
;
4683 unsigned plt_entry_size
;
4684 const struct elf_i386_backend_data
*abed
;
4685 struct elf_i386_link_hash_entry
*eh
;
4687 htab
= elf_i386_hash_table (info
);
4691 abed
= get_elf_i386_backend_data (output_bfd
);
4692 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
4694 eh
= (struct elf_i386_link_hash_entry
*) h
;
4696 if (h
->plt
.offset
!= (bfd_vma
) -1)
4700 Elf_Internal_Rela rel
;
4702 asection
*plt
, *gotplt
, *relplt
;
4704 /* When building a static executable, use .iplt, .igot.plt and
4705 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4706 if (htab
->elf
.splt
!= NULL
)
4708 plt
= htab
->elf
.splt
;
4709 gotplt
= htab
->elf
.sgotplt
;
4710 relplt
= htab
->elf
.srelplt
;
4714 plt
= htab
->elf
.iplt
;
4715 gotplt
= htab
->elf
.igotplt
;
4716 relplt
= htab
->elf
.irelplt
;
4719 /* This symbol has an entry in the procedure linkage table. Set
4722 if ((h
->dynindx
== -1
4723 && !((h
->forced_local
|| bfd_link_executable (info
))
4725 && h
->type
== STT_GNU_IFUNC
))
4731 /* Get the index in the procedure linkage table which
4732 corresponds to this symbol. This is the index of this symbol
4733 in all the symbols for which we are making plt entries. The
4734 first entry in the procedure linkage table is reserved.
4736 Get the offset into the .got table of the entry that
4737 corresponds to this function. Each .got entry is 4 bytes.
4738 The first three are reserved.
4740 For static executables, we don't reserve anything. */
4742 if (plt
== htab
->elf
.splt
)
4744 got_offset
= h
->plt
.offset
/ plt_entry_size
- 1;
4745 got_offset
= (got_offset
+ 3) * 4;
4749 got_offset
= h
->plt
.offset
/ plt_entry_size
;
4750 got_offset
= got_offset
* 4;
4753 /* Fill in the entry in the procedure linkage table. */
4754 if (! bfd_link_pic (info
))
4756 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->plt_entry
,
4757 abed
->plt
->plt_entry_size
);
4758 bfd_put_32 (output_bfd
,
4759 (gotplt
->output_section
->vma
4760 + gotplt
->output_offset
4762 plt
->contents
+ h
->plt
.offset
4763 + abed
->plt
->plt_got_offset
);
4765 if (abed
->is_vxworks
)
4767 int s
, k
, reloc_index
;
4769 /* Create the R_386_32 relocation referencing the GOT
4770 for this PLT entry. */
4772 /* S: Current slot number (zero-based). */
4773 s
= ((h
->plt
.offset
- abed
->plt
->plt_entry_size
)
4774 / abed
->plt
->plt_entry_size
);
4775 /* K: Number of relocations for PLTResolve. */
4776 if (bfd_link_pic (info
))
4777 k
= PLTRESOLVE_RELOCS_SHLIB
;
4779 k
= PLTRESOLVE_RELOCS
;
4780 /* Skip the PLTresolve relocations, and the relocations for
4781 the other PLT slots. */
4782 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4783 loc
= (htab
->srelplt2
->contents
+ reloc_index
4784 * sizeof (Elf32_External_Rel
));
4786 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4787 + htab
->elf
.splt
->output_offset
4788 + h
->plt
.offset
+ 2),
4789 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4790 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4792 /* Create the R_386_32 relocation referencing the beginning of
4793 the PLT for this GOT entry. */
4794 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4795 + htab
->elf
.sgotplt
->output_offset
4797 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4798 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4799 loc
+ sizeof (Elf32_External_Rel
));
4804 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->pic_plt_entry
,
4805 abed
->plt
->plt_entry_size
);
4806 bfd_put_32 (output_bfd
, got_offset
,
4807 plt
->contents
+ h
->plt
.offset
4808 + abed
->plt
->plt_got_offset
);
4811 /* Fill in the entry in the global offset table. */
4812 bfd_put_32 (output_bfd
,
4813 (plt
->output_section
->vma
4814 + plt
->output_offset
4816 + abed
->plt
->plt_lazy_offset
),
4817 gotplt
->contents
+ got_offset
);
4819 /* Fill in the entry in the .rel.plt section. */
4820 rel
.r_offset
= (gotplt
->output_section
->vma
4821 + gotplt
->output_offset
4823 if (h
->dynindx
== -1
4824 || ((bfd_link_executable (info
)
4825 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4827 && h
->type
== STT_GNU_IFUNC
))
4829 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4830 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4831 in the .got.plt section. */
4832 bfd_put_32 (output_bfd
,
4833 (h
->root
.u
.def
.value
4834 + h
->root
.u
.def
.section
->output_section
->vma
4835 + h
->root
.u
.def
.section
->output_offset
),
4836 gotplt
->contents
+ got_offset
);
4837 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4838 /* R_386_IRELATIVE comes last. */
4839 plt_index
= htab
->next_irelative_index
--;
4843 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4844 plt_index
= htab
->next_jump_slot_index
++;
4846 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4847 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4849 /* Don't fill PLT entry for static executables. */
4850 if (plt
== htab
->elf
.splt
)
4852 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4853 plt
->contents
+ h
->plt
.offset
4854 + abed
->plt
->plt_reloc_offset
);
4855 bfd_put_32 (output_bfd
, - (h
->plt
.offset
4856 + abed
->plt
->plt_plt_offset
+ 4),
4857 plt
->contents
+ h
->plt
.offset
4858 + abed
->plt
->plt_plt_offset
);
4861 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4863 bfd_vma got_offset
, plt_offset
;
4864 asection
*plt
, *got
, *gotplt
;
4865 const bfd_byte
*got_plt_entry
;
4867 /* Offset of displacement of the indirect jump. */
4868 bfd_vma plt_got_offset
= 2;
4870 /* Set the entry in the GOT procedure linkage table. */
4871 plt
= htab
->plt_got
;
4872 got
= htab
->elf
.sgot
;
4873 gotplt
= htab
->elf
.sgotplt
;
4874 got_offset
= h
->got
.offset
;
4876 if (got_offset
== (bfd_vma
) -1
4882 /* Fill in the entry in the GOT procedure linkage table. */
4883 if (! bfd_link_pic (info
))
4885 got_plt_entry
= elf_i386_got_plt_entry
;
4886 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
4890 got_plt_entry
= elf_i386_pic_got_plt_entry
;
4891 got_offset
+= (got
->output_section
->vma
4892 + got
->output_offset
4893 - gotplt
->output_section
->vma
4894 - gotplt
->output_offset
);
4897 plt_offset
= eh
->plt_got
.offset
;
4898 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
4899 sizeof (elf_i386_got_plt_entry
));
4900 bfd_put_32 (output_bfd
, got_offset
,
4901 plt
->contents
+ plt_offset
+ plt_got_offset
);
4905 && (h
->plt
.offset
!= (bfd_vma
) -1
4906 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4908 /* Mark the symbol as undefined, rather than as defined in
4909 the .plt section. Leave the value if there were any
4910 relocations where pointer equality matters (this is a clue
4911 for the dynamic linker, to make function pointer
4912 comparisons work between an application and shared
4913 library), otherwise set it to zero. If a function is only
4914 called from a binary, there is no need to slow down
4915 shared libraries because of that. */
4916 sym
->st_shndx
= SHN_UNDEF
;
4917 if (!h
->pointer_equality_needed
)
4921 if (h
->got
.offset
!= (bfd_vma
) -1
4922 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4923 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4925 Elf_Internal_Rela rel
;
4927 /* This symbol has an entry in the global offset table. Set it
4930 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4933 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4934 + htab
->elf
.sgot
->output_offset
4935 + (h
->got
.offset
& ~(bfd_vma
) 1));
4937 /* If this is a static link, or it is a -Bsymbolic link and the
4938 symbol is defined locally or was forced to be local because
4939 of a version file, we just want to emit a RELATIVE reloc.
4940 The entry in the global offset table will already have been
4941 initialized in the relocate_section function. */
4943 && h
->type
== STT_GNU_IFUNC
)
4945 if (bfd_link_pic (info
))
4947 /* Generate R_386_GLOB_DAT. */
4954 if (!h
->pointer_equality_needed
)
4957 /* For non-shared object, we can't use .got.plt, which
4958 contains the real function addres if we need pointer
4959 equality. We load the GOT entry with the PLT entry. */
4960 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4961 bfd_put_32 (output_bfd
,
4962 (plt
->output_section
->vma
4963 + plt
->output_offset
+ h
->plt
.offset
),
4964 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4968 else if (bfd_link_pic (info
)
4969 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4971 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4972 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4976 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4978 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4979 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4980 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4983 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &rel
);
4988 Elf_Internal_Rela rel
;
4990 /* This symbol needs a copy reloc. Set it up. */
4992 if (h
->dynindx
== -1
4993 || (h
->root
.type
!= bfd_link_hash_defined
4994 && h
->root
.type
!= bfd_link_hash_defweak
)
4995 || htab
->srelbss
== NULL
)
4998 rel
.r_offset
= (h
->root
.u
.def
.value
4999 + h
->root
.u
.def
.section
->output_section
->vma
5000 + h
->root
.u
.def
.section
->output_offset
);
5001 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
5002 elf_append_rel (output_bfd
, htab
->srelbss
, &rel
);
5008 /* Finish up local dynamic symbol handling. We set the contents of
5009 various dynamic sections here. */
5012 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
5014 struct elf_link_hash_entry
*h
5015 = (struct elf_link_hash_entry
*) *slot
;
5016 struct bfd_link_info
*info
5017 = (struct bfd_link_info
*) inf
;
5019 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
5023 /* Used to decide how to sort relocs in an optimal manner for the
5024 dynamic linker, before writing them out. */
5026 static enum elf_reloc_type_class
5027 elf_i386_reloc_type_class (const struct bfd_link_info
*info
,
5028 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5029 const Elf_Internal_Rela
*rela
)
5031 bfd
*abfd
= info
->output_bfd
;
5032 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5033 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5034 unsigned long r_symndx
= ELF32_R_SYM (rela
->r_info
);
5035 Elf_Internal_Sym sym
;
5037 if (htab
->dynsym
== NULL
5038 || !bed
->s
->swap_symbol_in (abfd
,
5039 (htab
->dynsym
->contents
5040 + r_symndx
* sizeof (Elf32_External_Sym
)),
5044 /* Check relocation against STT_GNU_IFUNC symbol. */
5045 if (ELF32_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5046 return reloc_class_ifunc
;
5048 switch (ELF32_R_TYPE (rela
->r_info
))
5050 case R_386_RELATIVE
:
5051 return reloc_class_relative
;
5052 case R_386_JUMP_SLOT
:
5053 return reloc_class_plt
;
5055 return reloc_class_copy
;
5057 return reloc_class_normal
;
5061 /* Finish up the dynamic sections. */
5064 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
5065 struct bfd_link_info
*info
)
5067 struct elf_i386_link_hash_table
*htab
;
5070 const struct elf_i386_backend_data
*abed
;
5072 htab
= elf_i386_hash_table (info
);
5076 dynobj
= htab
->elf
.dynobj
;
5077 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5078 abed
= get_elf_i386_backend_data (output_bfd
);
5080 if (htab
->elf
.dynamic_sections_created
)
5082 Elf32_External_Dyn
*dyncon
, *dynconend
;
5084 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5087 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5088 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5089 for (; dyncon
< dynconend
; dyncon
++)
5091 Elf_Internal_Dyn dyn
;
5094 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5099 if (abed
->is_vxworks
5100 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
5105 s
= htab
->elf
.sgotplt
;
5106 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5110 s
= htab
->elf
.srelplt
;
5111 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5115 s
= htab
->elf
.srelplt
;
5116 dyn
.d_un
.d_val
= s
->size
;
5120 /* My reading of the SVR4 ABI indicates that the
5121 procedure linkage table relocs (DT_JMPREL) should be
5122 included in the overall relocs (DT_REL). This is
5123 what Solaris does. However, UnixWare can not handle
5124 that case. Therefore, we override the DT_RELSZ entry
5125 here to make it not include the JMPREL relocs. */
5126 s
= htab
->elf
.srelplt
;
5129 dyn
.d_un
.d_val
-= s
->size
;
5133 /* We may not be using the standard ELF linker script.
5134 If .rel.plt is the first .rel section, we adjust
5135 DT_REL to not include it. */
5136 s
= htab
->elf
.srelplt
;
5139 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
5141 dyn
.d_un
.d_ptr
+= s
->size
;
5145 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5148 /* Fill in the first entry in the procedure linkage table. */
5149 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5151 if (bfd_link_pic (info
))
5153 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->pic_plt0_entry
,
5154 abed
->plt
->plt0_entry_size
);
5155 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5156 abed
->plt0_pad_byte
,
5157 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5161 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->plt0_entry
,
5162 abed
->plt
->plt0_entry_size
);
5163 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5164 abed
->plt0_pad_byte
,
5165 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5166 bfd_put_32 (output_bfd
,
5167 (htab
->elf
.sgotplt
->output_section
->vma
5168 + htab
->elf
.sgotplt
->output_offset
5170 htab
->elf
.splt
->contents
5171 + abed
->plt
->plt0_got1_offset
);
5172 bfd_put_32 (output_bfd
,
5173 (htab
->elf
.sgotplt
->output_section
->vma
5174 + htab
->elf
.sgotplt
->output_offset
5176 htab
->elf
.splt
->contents
5177 + abed
->plt
->plt0_got2_offset
);
5179 if (abed
->is_vxworks
)
5181 Elf_Internal_Rela rel
;
5183 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
5184 On IA32 we use REL relocations so the addend goes in
5185 the PLT directly. */
5186 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5187 + htab
->elf
.splt
->output_offset
5188 + abed
->plt
->plt0_got1_offset
);
5189 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5190 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5191 htab
->srelplt2
->contents
);
5192 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
5193 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5194 + htab
->elf
.splt
->output_offset
5195 + abed
->plt
->plt0_got2_offset
);
5196 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5197 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5198 htab
->srelplt2
->contents
+
5199 sizeof (Elf32_External_Rel
));
5203 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5204 really seem like the right value. */
5205 elf_section_data (htab
->elf
.splt
->output_section
)
5206 ->this_hdr
.sh_entsize
= 4;
5208 /* Correct the .rel.plt.unloaded relocations. */
5209 if (abed
->is_vxworks
&& !bfd_link_pic (info
))
5211 int num_plts
= (htab
->elf
.splt
->size
5212 / abed
->plt
->plt_entry_size
) - 1;
5215 p
= htab
->srelplt2
->contents
;
5216 if (bfd_link_pic (info
))
5217 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
5219 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
5221 for (; num_plts
; num_plts
--)
5223 Elf_Internal_Rela rel
;
5224 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5225 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5226 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5227 p
+= sizeof (Elf32_External_Rel
);
5229 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5230 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5231 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5232 p
+= sizeof (Elf32_External_Rel
);
5238 if (htab
->elf
.sgotplt
)
5240 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5242 (*_bfd_error_handler
)
5243 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5247 /* Fill in the first three entries in the global offset table. */
5248 if (htab
->elf
.sgotplt
->size
> 0)
5250 bfd_put_32 (output_bfd
,
5252 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
5253 htab
->elf
.sgotplt
->contents
);
5254 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
5255 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
5258 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
5261 /* Adjust .eh_frame for .plt section. */
5262 if (htab
->plt_eh_frame
!= NULL
5263 && htab
->plt_eh_frame
->contents
!= NULL
)
5265 if (htab
->elf
.splt
!= NULL
5266 && htab
->elf
.splt
->size
!= 0
5267 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5268 && htab
->elf
.splt
->output_section
!= NULL
5269 && htab
->plt_eh_frame
->output_section
!= NULL
)
5271 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5272 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5273 + htab
->plt_eh_frame
->output_offset
5274 + PLT_FDE_START_OFFSET
;
5275 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5276 htab
->plt_eh_frame
->contents
5277 + PLT_FDE_START_OFFSET
);
5279 if (htab
->plt_eh_frame
->sec_info_type
5280 == SEC_INFO_TYPE_EH_FRAME
)
5282 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5284 htab
->plt_eh_frame
->contents
))
5289 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5290 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5292 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5293 htab_traverse (htab
->loc_hash_table
,
5294 elf_i386_finish_local_dynamic_symbol
,
5300 /* Return an array of PLT entry symbol values. */
5303 elf_i386_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
5306 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
5309 bfd_vma
*plt_sym_val
;
5311 bfd_byte
*plt_contents
;
5312 const struct elf_i386_backend_data
*bed
5313 = get_elf_i386_backend_data (abfd
);
5314 Elf_Internal_Shdr
*hdr
;
5316 /* Get the .plt section contents. */
5317 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
5318 if (plt_contents
== NULL
)
5320 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
5321 plt_contents
, 0, plt
->size
))
5324 free (plt_contents
);
5328 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
5329 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
5332 hdr
= &elf_section_data (relplt
)->this_hdr
;
5333 count
= relplt
->size
/ hdr
->sh_entsize
;
5335 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
5336 if (plt_sym_val
== NULL
)
5339 for (i
= 0; i
< count
; i
++)
5340 plt_sym_val
[i
] = -1;
5342 plt_offset
= bed
->plt
->plt_entry_size
;
5343 p
= relplt
->relocation
;
5344 for (i
= 0; i
< count
; i
++, p
++)
5348 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
5349 if (p
->howto
== NULL
)
5352 if (p
->howto
->type
!= R_386_JUMP_SLOT
5353 && p
->howto
->type
!= R_386_IRELATIVE
)
5356 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
5357 + bed
->plt
->plt_reloc_offset
));
5358 reloc_index
/= sizeof (Elf32_External_Rel
);
5359 if (reloc_index
>= count
)
5361 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
5362 plt_offset
+= bed
->plt
->plt_entry_size
;
5364 /* PR binutils/18437: Skip extra relocations in the .rel.plt
5366 if (plt_offset
>= plt
->size
)
5370 free (plt_contents
);
5375 /* Similar to _bfd_elf_get_synthetic_symtab. */
5378 elf_i386_get_synthetic_symtab (bfd
*abfd
,
5385 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt");
5386 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
5387 dynsymcount
, dynsyms
, ret
,
5389 elf_i386_get_plt_sym_val
);
5392 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5395 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
5397 if (h
->plt
.offset
!= (bfd_vma
) -1
5399 && !h
->pointer_equality_needed
)
5402 return _bfd_elf_hash_symbol (h
);
5405 /* Hook called by the linker routine which adds symbols from an object
5409 elf_i386_add_symbol_hook (bfd
* abfd
,
5410 struct bfd_link_info
* info
,
5411 Elf_Internal_Sym
* sym
,
5412 const char ** namep ATTRIBUTE_UNUSED
,
5413 flagword
* flagsp ATTRIBUTE_UNUSED
,
5414 asection
** secp ATTRIBUTE_UNUSED
,
5415 bfd_vma
* valp ATTRIBUTE_UNUSED
)
5417 if (ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
5418 && (abfd
->flags
& DYNAMIC
) == 0
5419 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
5420 elf_tdata (info
->output_bfd
)->has_gnu_symbols
5421 |= elf_gnu_symbol_unique
;
5426 #define TARGET_LITTLE_SYM i386_elf32_vec
5427 #define TARGET_LITTLE_NAME "elf32-i386"
5428 #define ELF_ARCH bfd_arch_i386
5429 #define ELF_TARGET_ID I386_ELF_DATA
5430 #define ELF_MACHINE_CODE EM_386
5431 #define ELF_MAXPAGESIZE 0x1000
5433 #define elf_backend_can_gc_sections 1
5434 #define elf_backend_can_refcount 1
5435 #define elf_backend_want_got_plt 1
5436 #define elf_backend_plt_readonly 1
5437 #define elf_backend_want_plt_sym 0
5438 #define elf_backend_got_header_size 12
5439 #define elf_backend_plt_alignment 4
5440 #define elf_backend_extern_protected_data 1
5442 /* Support RELA for objdump of prelink objects. */
5443 #define elf_info_to_howto elf_i386_info_to_howto_rel
5444 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
5446 #define bfd_elf32_mkobject elf_i386_mkobject
5448 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
5449 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
5450 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
5451 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
5452 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
5454 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
5455 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
5456 #define elf_backend_check_relocs elf_i386_check_relocs
5457 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
5458 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
5459 #define elf_backend_fake_sections elf_i386_fake_sections
5460 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
5461 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
5462 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
5463 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
5464 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
5465 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
5466 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
5467 #define elf_backend_relocate_section elf_i386_relocate_section
5468 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
5469 #define elf_backend_always_size_sections elf_i386_always_size_sections
5470 #define elf_backend_omit_section_dynsym \
5471 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
5472 #define elf_backend_hash_symbol elf_i386_hash_symbol
5473 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
5475 #include "elf32-target.h"
5477 /* FreeBSD support. */
5479 #undef TARGET_LITTLE_SYM
5480 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
5481 #undef TARGET_LITTLE_NAME
5482 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
5484 #define ELF_OSABI ELFOSABI_FREEBSD
5486 /* The kernel recognizes executables as valid only if they carry a
5487 "FreeBSD" label in the ELF header. So we put this label on all
5488 executables and (for simplicity) also all other object files. */
5491 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
5493 _bfd_elf_post_process_headers (abfd
, info
);
5495 #ifdef OLD_FREEBSD_ABI_LABEL
5497 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5498 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
5499 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5504 #undef elf_backend_post_process_headers
5505 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
5507 #define elf32_bed elf32_i386_fbsd_bed
5509 #undef elf_backend_add_symbol_hook
5511 #include "elf32-target.h"
5515 #undef TARGET_LITTLE_SYM
5516 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
5517 #undef TARGET_LITTLE_NAME
5518 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
5520 #undef elf_backend_post_process_headers
5522 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5523 objects won't be recognized. */
5527 #define elf32_bed elf32_i386_sol2_bed
5529 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5531 #undef elf_backend_static_tls_alignment
5532 #define elf_backend_static_tls_alignment 8
5534 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5536 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5538 #undef elf_backend_want_plt_sym
5539 #define elf_backend_want_plt_sym 1
5541 #include "elf32-target.h"
5543 /* Intel MCU support. */
5546 elf32_iamcu_elf_object_p (bfd
*abfd
)
5548 /* Set the right machine number for an IAMCU elf32 file. */
5549 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
5553 #undef TARGET_LITTLE_SYM
5554 #define TARGET_LITTLE_SYM iamcu_elf32_vec
5555 #undef TARGET_LITTLE_NAME
5556 #define TARGET_LITTLE_NAME "elf32-iamcu"
5558 #define ELF_ARCH bfd_arch_iamcu
5560 #undef ELF_MACHINE_CODE
5561 #define ELF_MACHINE_CODE EM_IAMCU
5566 #define elf32_bed elf32_iamcu_bed
5568 #undef elf_backend_object_p
5569 #define elf_backend_object_p elf32_iamcu_elf_object_p
5571 #undef elf_backend_static_tls_alignment
5573 #undef elf_backend_want_plt_sym
5574 #define elf_backend_want_plt_sym 0
5576 #include "elf32-target.h"
5578 /* Restore defaults. */
5580 #define ELF_ARCH bfd_arch_i386
5581 #undef ELF_MACHINE_CODE
5582 #define ELF_MACHINE_CODE EM_386
5584 /* Native Client support. */
5586 #undef TARGET_LITTLE_SYM
5587 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
5588 #undef TARGET_LITTLE_NAME
5589 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
5591 #define elf32_bed elf32_i386_nacl_bed
5593 #undef ELF_MAXPAGESIZE
5594 #define ELF_MAXPAGESIZE 0x10000
5596 /* Restore defaults. */
5598 #undef elf_backend_want_plt_sym
5599 #define elf_backend_want_plt_sym 0
5600 #undef elf_backend_post_process_headers
5601 #undef elf_backend_static_tls_alignment
5603 /* NaCl uses substantially different PLT entries for the same effects. */
5605 #undef elf_backend_plt_alignment
5606 #define elf_backend_plt_alignment 5
5607 #define NACL_PLT_ENTRY_SIZE 64
5608 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5610 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
5612 0xff, 0x35, /* pushl contents of address */
5613 0, 0, 0, 0, /* replaced with address of .got + 4. */
5614 0x8b, 0x0d, /* movl contents of address, %ecx */
5615 0, 0, 0, 0, /* replaced with address of .got + 8. */
5616 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5617 0xff, 0xe1 /* jmp *%ecx */
5620 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5622 0x8b, 0x0d, /* movl contents of address, %ecx */
5623 0, 0, 0, 0, /* replaced with GOT slot address. */
5624 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5625 0xff, 0xe1, /* jmp *%ecx */
5627 /* Pad to the next 32-byte boundary with nop instructions. */
5629 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5630 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5632 /* Lazy GOT entries point here (32-byte aligned). */
5633 0x68, /* pushl immediate */
5634 0, 0, 0, 0, /* replaced with reloc offset. */
5635 0xe9, /* jmp relative */
5636 0, 0, 0, 0, /* replaced with offset to .plt. */
5638 /* Pad to the next 32-byte boundary with nop instructions. */
5639 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5640 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5644 static const bfd_byte
5645 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
5647 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5648 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5649 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5650 0xff, 0xe1, /* jmp *%ecx */
5652 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
5653 so pad to that size with nop instructions. */
5654 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
5657 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5659 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5660 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5661 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5662 0xff, 0xe1, /* jmp *%ecx */
5664 /* Pad to the next 32-byte boundary with nop instructions. */
5666 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5667 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5669 /* Lazy GOT entries point here (32-byte aligned). */
5670 0x68, /* pushl immediate */
5671 0, 0, 0, 0, /* replaced with offset into relocation table. */
5672 0xe9, /* jmp relative */
5673 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5675 /* Pad to the next 32-byte boundary with nop instructions. */
5676 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5677 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5681 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
5683 #if (PLT_CIE_LENGTH != 20 \
5684 || PLT_FDE_LENGTH != 36 \
5685 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5686 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5687 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5689 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5690 0, 0, 0, 0, /* CIE ID */
5691 1, /* CIE version */
5692 'z', 'R', 0, /* Augmentation string */
5693 1, /* Code alignment factor */
5694 0x7c, /* Data alignment factor: -4 */
5695 8, /* Return address column */
5696 1, /* Augmentation size */
5697 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5698 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5699 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5700 DW_CFA_nop
, DW_CFA_nop
,
5702 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5703 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
5704 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5705 0, 0, 0, 0, /* .plt size goes here */
5706 0, /* Augmentation size */
5707 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
5708 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5709 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
5710 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5711 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5712 13, /* Block length */
5713 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
5714 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
5715 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5716 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
5717 DW_CFA_nop
, DW_CFA_nop
5720 static const struct elf_i386_plt_layout elf_i386_nacl_plt
=
5722 elf_i386_nacl_plt0_entry
, /* plt0_entry */
5723 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
5724 2, /* plt0_got1_offset */
5725 8, /* plt0_got2_offset */
5726 elf_i386_nacl_plt_entry
, /* plt_entry */
5727 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5728 2, /* plt_got_offset */
5729 33, /* plt_reloc_offset */
5730 38, /* plt_plt_offset */
5731 32, /* plt_lazy_offset */
5732 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
5733 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
5734 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
5735 sizeof (elf_i386_nacl_eh_frame_plt
),/* eh_frame_plt_size */
5738 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
5740 &elf_i386_nacl_plt
, /* plt */
5741 0x90, /* plt0_pad_byte: nop insn */
5746 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
5748 /* Set the right machine number for a NaCl i386 ELF32 file. */
5749 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
5753 #undef elf_backend_arch_data
5754 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
5756 #undef elf_backend_object_p
5757 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
5758 #undef elf_backend_modify_segment_map
5759 #define elf_backend_modify_segment_map nacl_modify_segment_map
5760 #undef elf_backend_modify_program_headers
5761 #define elf_backend_modify_program_headers nacl_modify_program_headers
5762 #undef elf_backend_final_write_processing
5763 #define elf_backend_final_write_processing nacl_final_write_processing
5765 #include "elf32-target.h"
5767 /* Restore defaults. */
5768 #undef elf_backend_object_p
5769 #undef elf_backend_modify_segment_map
5770 #undef elf_backend_modify_program_headers
5771 #undef elf_backend_final_write_processing
5773 /* VxWorks support. */
5775 #undef TARGET_LITTLE_SYM
5776 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
5777 #undef TARGET_LITTLE_NAME
5778 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
5780 #undef elf_backend_plt_alignment
5781 #define elf_backend_plt_alignment 4
5783 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
5785 &elf_i386_plt
, /* plt */
5786 0x90, /* plt0_pad_byte */
5790 #undef elf_backend_arch_data
5791 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
5793 #undef elf_backend_relocs_compatible
5794 #undef elf_backend_add_symbol_hook
5795 #define elf_backend_add_symbol_hook \
5796 elf_vxworks_add_symbol_hook
5797 #undef elf_backend_link_output_symbol_hook
5798 #define elf_backend_link_output_symbol_hook \
5799 elf_vxworks_link_output_symbol_hook
5800 #undef elf_backend_emit_relocs
5801 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5802 #undef elf_backend_final_write_processing
5803 #define elf_backend_final_write_processing \
5804 elf_vxworks_final_write_processing
5805 #undef elf_backend_static_tls_alignment
5807 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5809 #undef elf_backend_want_plt_sym
5810 #define elf_backend_want_plt_sym 1
5813 #define elf32_bed elf32_i386_vxworks_bed
5815 #include "elf32-target.h"