1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #include "elf-vxworks.h"
29 #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, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
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
),
135 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
136 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
137 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
138 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
139 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
141 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
142 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
143 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
144 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
145 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
146 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
149 #define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
150 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
152 /* GNU extension to record C++ vtable hierarchy. */
153 HOWTO (R_386_GNU_VTINHERIT
, /* type */
155 2, /* size (0 = byte, 1 = short, 2 = long) */
157 FALSE
, /* pc_relative */
159 complain_overflow_dont
, /* complain_on_overflow */
160 NULL
, /* special_function */
161 "R_386_GNU_VTINHERIT", /* name */
162 FALSE
, /* partial_inplace */
165 FALSE
), /* pcrel_offset */
167 /* GNU extension to record C++ vtable member usage. */
168 HOWTO (R_386_GNU_VTENTRY
, /* type */
170 2, /* size (0 = byte, 1 = short, 2 = long) */
172 FALSE
, /* pc_relative */
174 complain_overflow_dont
, /* complain_on_overflow */
175 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
176 "R_386_GNU_VTENTRY", /* name */
177 FALSE
, /* partial_inplace */
180 FALSE
) /* pcrel_offset */
182 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
186 #ifdef DEBUG_GEN_RELOC
188 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
193 static reloc_howto_type
*
194 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
195 bfd_reloc_code_real_type code
)
200 TRACE ("BFD_RELOC_NONE");
201 return &elf_howto_table
[R_386_NONE
];
204 TRACE ("BFD_RELOC_32");
205 return &elf_howto_table
[R_386_32
];
208 TRACE ("BFD_RELOC_CTOR");
209 return &elf_howto_table
[R_386_32
];
211 case BFD_RELOC_32_PCREL
:
212 TRACE ("BFD_RELOC_PC32");
213 return &elf_howto_table
[R_386_PC32
];
215 case BFD_RELOC_386_GOT32
:
216 TRACE ("BFD_RELOC_386_GOT32");
217 return &elf_howto_table
[R_386_GOT32
];
219 case BFD_RELOC_386_PLT32
:
220 TRACE ("BFD_RELOC_386_PLT32");
221 return &elf_howto_table
[R_386_PLT32
];
223 case BFD_RELOC_386_COPY
:
224 TRACE ("BFD_RELOC_386_COPY");
225 return &elf_howto_table
[R_386_COPY
];
227 case BFD_RELOC_386_GLOB_DAT
:
228 TRACE ("BFD_RELOC_386_GLOB_DAT");
229 return &elf_howto_table
[R_386_GLOB_DAT
];
231 case BFD_RELOC_386_JUMP_SLOT
:
232 TRACE ("BFD_RELOC_386_JUMP_SLOT");
233 return &elf_howto_table
[R_386_JUMP_SLOT
];
235 case BFD_RELOC_386_RELATIVE
:
236 TRACE ("BFD_RELOC_386_RELATIVE");
237 return &elf_howto_table
[R_386_RELATIVE
];
239 case BFD_RELOC_386_GOTOFF
:
240 TRACE ("BFD_RELOC_386_GOTOFF");
241 return &elf_howto_table
[R_386_GOTOFF
];
243 case BFD_RELOC_386_GOTPC
:
244 TRACE ("BFD_RELOC_386_GOTPC");
245 return &elf_howto_table
[R_386_GOTPC
];
247 /* These relocs are a GNU extension. */
248 case BFD_RELOC_386_TLS_TPOFF
:
249 TRACE ("BFD_RELOC_386_TLS_TPOFF");
250 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
252 case BFD_RELOC_386_TLS_IE
:
253 TRACE ("BFD_RELOC_386_TLS_IE");
254 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
256 case BFD_RELOC_386_TLS_GOTIE
:
257 TRACE ("BFD_RELOC_386_TLS_GOTIE");
258 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
260 case BFD_RELOC_386_TLS_LE
:
261 TRACE ("BFD_RELOC_386_TLS_LE");
262 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
264 case BFD_RELOC_386_TLS_GD
:
265 TRACE ("BFD_RELOC_386_TLS_GD");
266 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
268 case BFD_RELOC_386_TLS_LDM
:
269 TRACE ("BFD_RELOC_386_TLS_LDM");
270 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
273 TRACE ("BFD_RELOC_16");
274 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
276 case BFD_RELOC_16_PCREL
:
277 TRACE ("BFD_RELOC_16_PCREL");
278 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
281 TRACE ("BFD_RELOC_8");
282 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
284 case BFD_RELOC_8_PCREL
:
285 TRACE ("BFD_RELOC_8_PCREL");
286 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
288 /* Common with Sun TLS implementation. */
289 case BFD_RELOC_386_TLS_LDO_32
:
290 TRACE ("BFD_RELOC_386_TLS_LDO_32");
291 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
293 case BFD_RELOC_386_TLS_IE_32
:
294 TRACE ("BFD_RELOC_386_TLS_IE_32");
295 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
297 case BFD_RELOC_386_TLS_LE_32
:
298 TRACE ("BFD_RELOC_386_TLS_LE_32");
299 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
301 case BFD_RELOC_386_TLS_DTPMOD32
:
302 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
303 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
305 case BFD_RELOC_386_TLS_DTPOFF32
:
306 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
307 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
309 case BFD_RELOC_386_TLS_TPOFF32
:
310 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
311 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
313 case BFD_RELOC_386_TLS_GOTDESC
:
314 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
315 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
317 case BFD_RELOC_386_TLS_DESC_CALL
:
318 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
319 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
321 case BFD_RELOC_386_TLS_DESC
:
322 TRACE ("BFD_RELOC_386_TLS_DESC");
323 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
325 case BFD_RELOC_386_IRELATIVE
:
326 TRACE ("BFD_RELOC_386_IRELATIVE");
327 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
329 case BFD_RELOC_VTABLE_INHERIT
:
330 TRACE ("BFD_RELOC_VTABLE_INHERIT");
331 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
333 case BFD_RELOC_VTABLE_ENTRY
:
334 TRACE ("BFD_RELOC_VTABLE_ENTRY");
335 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
345 static reloc_howto_type
*
346 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
351 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
352 if (elf_howto_table
[i
].name
!= NULL
353 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
354 return &elf_howto_table
[i
];
359 static reloc_howto_type
*
360 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
364 if ((indx
= r_type
) >= R_386_standard
365 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
366 >= R_386_ext
- R_386_standard
)
367 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
368 >= R_386_irelative
- R_386_ext
)
369 && ((indx
= r_type
- R_386_vt_offset
) - R_386_irelative
370 >= R_386_vt
- R_386_irelative
))
372 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
376 BFD_ASSERT (elf_howto_table
[indx
].type
== r_type
);
377 return &elf_howto_table
[indx
];
381 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
383 Elf_Internal_Rela
*dst
)
385 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
386 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
389 /* Return whether a symbol name implies a local label. The UnixWare
390 2.1 cc generates temporary symbols that start with .X, so we
391 recognize them here. FIXME: do other SVR4 compilers also use .X?.
392 If so, we should move the .X recognition into
393 _bfd_elf_is_local_label_name. */
396 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
398 if (name
[0] == '.' && name
[1] == 'X')
401 return _bfd_elf_is_local_label_name (abfd
, name
);
404 /* Support for core dump NOTE sections. */
407 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
412 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
414 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
420 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
423 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
427 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
431 switch (note
->descsz
)
436 case 144: /* Linux/i386 */
438 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
441 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
451 /* Make a ".reg/999" section. */
452 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
453 size
, note
->descpos
+ offset
);
457 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
459 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
461 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
466 elf_tdata (abfd
)->core_program
467 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
468 elf_tdata (abfd
)->core_command
469 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
473 switch (note
->descsz
)
478 case 124: /* Linux/i386 elf_prpsinfo. */
479 elf_tdata (abfd
)->core_pid
480 = bfd_get_32 (abfd
, note
->descdata
+ 12);
481 elf_tdata (abfd
)->core_program
482 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
483 elf_tdata (abfd
)->core_command
484 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
488 /* Note that for some reason, a spurious space is tacked
489 onto the end of the args in some (at least one anyway)
490 implementations, so strip it off if it exists. */
492 char *command
= elf_tdata (abfd
)->core_command
;
493 int n
= strlen (command
);
495 if (0 < n
&& command
[n
- 1] == ' ')
496 command
[n
- 1] = '\0';
502 /* Functions for the i386 ELF linker.
504 In order to gain some understanding of code in this file without
505 knowing all the intricate details of the linker, note the
508 Functions named elf_i386_* are called by external routines, other
509 functions are only called locally. elf_i386_* functions appear
510 in this file more or less in the order in which they are called
511 from external routines. eg. elf_i386_check_relocs is called
512 early in the link process, elf_i386_finish_dynamic_sections is
513 one of the last functions. */
516 /* The name of the dynamic interpreter. This is put in the .interp
519 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
521 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
522 copying dynamic variables from a shared lib into an app's dynbss
523 section, and instead use a dynamic relocation to point into the
525 #define ELIMINATE_COPY_RELOCS 1
527 /* The size in bytes of an entry in the procedure linkage table. */
529 #define PLT_ENTRY_SIZE 16
531 /* The first entry in an absolute procedure linkage table looks like
532 this. See the SVR4 ABI i386 supplement to see how this works.
533 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
535 static const bfd_byte elf_i386_plt0_entry
[12] =
537 0xff, 0x35, /* pushl contents of address */
538 0, 0, 0, 0, /* replaced with address of .got + 4. */
539 0xff, 0x25, /* jmp indirect */
540 0, 0, 0, 0 /* replaced with address of .got + 8. */
543 /* Subsequent entries in an absolute procedure linkage table look like
546 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
548 0xff, 0x25, /* jmp indirect */
549 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
550 0x68, /* pushl immediate */
551 0, 0, 0, 0, /* replaced with offset into relocation table. */
552 0xe9, /* jmp relative */
553 0, 0, 0, 0 /* replaced with offset to start of .plt. */
556 /* The first entry in a PIC procedure linkage table look like this.
557 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
559 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
561 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
562 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
565 /* Subsequent entries in a PIC procedure linkage table look like this. */
567 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
569 0xff, 0xa3, /* jmp *offset(%ebx) */
570 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
571 0x68, /* pushl immediate */
572 0, 0, 0, 0, /* replaced with offset into relocation table. */
573 0xe9, /* jmp relative */
574 0, 0, 0, 0 /* replaced with offset to start of .plt. */
577 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
578 for the PLTResolve stub and then for each PLT entry. */
579 #define PLTRESOLVE_RELOCS_SHLIB 0
580 #define PLTRESOLVE_RELOCS 2
581 #define PLT_NON_JUMP_SLOT_RELOCS 2
583 /* i386 ELF linker hash entry. */
585 struct elf_i386_link_hash_entry
587 struct elf_link_hash_entry elf
;
589 /* Track dynamic relocs copied for this symbol. */
590 struct elf_dyn_relocs
*dyn_relocs
;
592 #define GOT_UNKNOWN 0
596 #define GOT_TLS_IE_POS 5
597 #define GOT_TLS_IE_NEG 6
598 #define GOT_TLS_IE_BOTH 7
599 #define GOT_TLS_GDESC 8
600 #define GOT_TLS_GD_BOTH_P(type) \
601 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
602 #define GOT_TLS_GD_P(type) \
603 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
604 #define GOT_TLS_GDESC_P(type) \
605 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
606 #define GOT_TLS_GD_ANY_P(type) \
607 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
608 unsigned char tls_type
;
610 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
611 starting at the end of the jump table. */
615 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
617 struct elf_i386_obj_tdata
619 struct elf_obj_tdata root
;
621 /* tls_type for each local got entry. */
622 char *local_got_tls_type
;
624 /* GOTPLT entries for TLS descriptors. */
625 bfd_vma
*local_tlsdesc_gotent
;
628 #define elf_i386_tdata(abfd) \
629 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
631 #define elf_i386_local_got_tls_type(abfd) \
632 (elf_i386_tdata (abfd)->local_got_tls_type)
634 #define elf_i386_local_tlsdesc_gotent(abfd) \
635 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
637 #define is_i386_elf(bfd) \
638 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
639 && elf_tdata (bfd) != NULL \
640 && elf_object_id (bfd) == I386_ELF_DATA)
643 elf_i386_mkobject (bfd
*abfd
)
645 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
649 /* i386 ELF linker hash table. */
651 struct elf_i386_link_hash_table
653 struct elf_link_hash_table elf
;
655 /* Short-cuts to get to dynamic linker sections. */
661 bfd_signed_vma refcount
;
665 /* The amount of space used by the reserved portion of the sgotplt
666 section, plus whatever space is used by the jump slots. */
667 bfd_vma sgotplt_jump_table_size
;
669 /* Small local sym cache. */
670 struct sym_cache sym_cache
;
672 /* _TLS_MODULE_BASE_ symbol. */
673 struct bfd_link_hash_entry
*tls_module_base
;
675 /* Used by local STT_GNU_IFUNC symbols. */
676 htab_t loc_hash_table
;
677 void * loc_hash_memory
;
679 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
682 /* True if the target system is VxWorks. */
685 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
686 bfd_vma next_tls_desc_index
;
688 /* Value used to fill the last word of the first plt entry. */
689 bfd_byte plt0_pad_byte
;
692 /* Get the i386 ELF linker hash table from a link_info structure. */
694 #define elf_i386_hash_table(p) \
695 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
696 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
698 #define elf_i386_compute_jump_table_size(htab) \
699 ((htab)->next_tls_desc_index * 4)
701 /* Create an entry in an i386 ELF linker hash table. */
703 static struct bfd_hash_entry
*
704 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
705 struct bfd_hash_table
*table
,
708 /* Allocate the structure if it has not already been allocated by a
712 entry
= (struct bfd_hash_entry
*)
713 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
718 /* Call the allocation method of the superclass. */
719 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
722 struct elf_i386_link_hash_entry
*eh
;
724 eh
= (struct elf_i386_link_hash_entry
*) entry
;
725 eh
->dyn_relocs
= NULL
;
726 eh
->tls_type
= GOT_UNKNOWN
;
727 eh
->tlsdesc_got
= (bfd_vma
) -1;
733 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
734 for local symbol so that we can handle local STT_GNU_IFUNC symbols
735 as global symbol. We reuse indx and dynstr_index for local symbol
736 hash since they aren't used by global symbols in this backend. */
739 elf_i386_local_htab_hash (const void *ptr
)
741 struct elf_link_hash_entry
*h
742 = (struct elf_link_hash_entry
*) ptr
;
743 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
746 /* Compare local hash entries. */
749 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
751 struct elf_link_hash_entry
*h1
752 = (struct elf_link_hash_entry
*) ptr1
;
753 struct elf_link_hash_entry
*h2
754 = (struct elf_link_hash_entry
*) ptr2
;
756 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
759 /* Find and/or create a hash entry for local symbol. */
761 static struct elf_link_hash_entry
*
762 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
763 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
766 struct elf_i386_link_hash_entry e
, *ret
;
767 asection
*sec
= abfd
->sections
;
768 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
769 ELF32_R_SYM (rel
->r_info
));
772 e
.elf
.indx
= sec
->id
;
773 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
774 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
775 create
? INSERT
: NO_INSERT
);
782 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
786 ret
= (struct elf_i386_link_hash_entry
*)
787 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
788 sizeof (struct elf_i386_link_hash_entry
));
791 memset (ret
, 0, sizeof (*ret
));
792 ret
->elf
.indx
= sec
->id
;
793 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
794 ret
->elf
.dynindx
= -1;
800 /* Create an i386 ELF linker hash table. */
802 static struct bfd_link_hash_table
*
803 elf_i386_link_hash_table_create (bfd
*abfd
)
805 struct elf_i386_link_hash_table
*ret
;
806 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
808 ret
= (struct elf_i386_link_hash_table
*) bfd_malloc (amt
);
812 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
813 elf_i386_link_hash_newfunc
,
814 sizeof (struct elf_i386_link_hash_entry
),
823 ret
->tls_ldm_got
.refcount
= 0;
824 ret
->next_tls_desc_index
= 0;
825 ret
->sgotplt_jump_table_size
= 0;
826 ret
->sym_cache
.abfd
= NULL
;
828 ret
->srelplt2
= NULL
;
829 ret
->plt0_pad_byte
= 0;
830 ret
->tls_module_base
= NULL
;
832 ret
->loc_hash_table
= htab_try_create (1024,
833 elf_i386_local_htab_hash
,
834 elf_i386_local_htab_eq
,
836 ret
->loc_hash_memory
= objalloc_create ();
837 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
843 return &ret
->elf
.root
;
846 /* Destroy an i386 ELF linker hash table. */
849 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
851 struct elf_i386_link_hash_table
*htab
852 = (struct elf_i386_link_hash_table
*) hash
;
854 if (htab
->loc_hash_table
)
855 htab_delete (htab
->loc_hash_table
);
856 if (htab
->loc_hash_memory
)
857 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
858 _bfd_generic_link_hash_table_free (hash
);
861 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
862 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
866 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
868 struct elf_i386_link_hash_table
*htab
;
870 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
873 htab
= elf_i386_hash_table (info
);
877 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
879 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
882 || (!info
->shared
&& !htab
->srelbss
))
886 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
893 /* Copy the extra info we tack onto an elf_link_hash_entry. */
896 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
897 struct elf_link_hash_entry
*dir
,
898 struct elf_link_hash_entry
*ind
)
900 struct elf_i386_link_hash_entry
*edir
, *eind
;
902 edir
= (struct elf_i386_link_hash_entry
*) dir
;
903 eind
= (struct elf_i386_link_hash_entry
*) ind
;
905 if (eind
->dyn_relocs
!= NULL
)
907 if (edir
->dyn_relocs
!= NULL
)
909 struct elf_dyn_relocs
**pp
;
910 struct elf_dyn_relocs
*p
;
912 /* Add reloc counts against the indirect sym to the direct sym
913 list. Merge any entries against the same section. */
914 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
916 struct elf_dyn_relocs
*q
;
918 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
919 if (q
->sec
== p
->sec
)
921 q
->pc_count
+= p
->pc_count
;
922 q
->count
+= p
->count
;
929 *pp
= edir
->dyn_relocs
;
932 edir
->dyn_relocs
= eind
->dyn_relocs
;
933 eind
->dyn_relocs
= NULL
;
936 if (ind
->root
.type
== bfd_link_hash_indirect
937 && dir
->got
.refcount
<= 0)
939 edir
->tls_type
= eind
->tls_type
;
940 eind
->tls_type
= GOT_UNKNOWN
;
943 if (ELIMINATE_COPY_RELOCS
944 && ind
->root
.type
!= bfd_link_hash_indirect
945 && dir
->dynamic_adjusted
)
947 /* If called to transfer flags for a weakdef during processing
948 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
949 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
950 dir
->ref_dynamic
|= ind
->ref_dynamic
;
951 dir
->ref_regular
|= ind
->ref_regular
;
952 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
953 dir
->needs_plt
|= ind
->needs_plt
;
954 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
957 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
967 /* Return TRUE if the TLS access code sequence support transition
971 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
973 Elf_Internal_Shdr
*symtab_hdr
,
974 struct elf_link_hash_entry
**sym_hashes
,
976 const Elf_Internal_Rela
*rel
,
977 const Elf_Internal_Rela
*relend
)
979 unsigned int val
, type
;
980 unsigned long r_symndx
;
981 struct elf_link_hash_entry
*h
;
984 /* Get the section contents. */
985 if (contents
== NULL
)
987 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
988 contents
= elf_section_data (sec
)->this_hdr
.contents
;
991 /* FIXME: How to better handle error condition? */
992 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
995 /* Cache the section contents for elf_link_input_bfd. */
996 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1000 offset
= rel
->r_offset
;
1005 if (offset
< 2 || (rel
+ 1) >= relend
)
1008 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1009 if (r_type
== R_386_TLS_GD
)
1011 /* Check transition from GD access model. Only
1012 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1013 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1014 can transit to different access model. */
1015 if ((offset
+ 10) > sec
->size
||
1016 (type
!= 0x8d && type
!= 0x04))
1019 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1022 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1026 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1029 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1034 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1035 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1038 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1044 /* Check transition from LD access model. Only
1045 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1046 can transit to different access model. */
1047 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1050 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1051 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1055 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1058 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1059 if (r_symndx
< symtab_hdr
->sh_info
)
1062 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1063 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1064 may be versioned. */
1066 && h
->root
.root
.string
!= NULL
1067 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1068 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1069 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1073 /* Check transition from IE access model:
1074 movl foo@indntpoff(%rip), %eax
1075 movl foo@indntpoff(%rip), %reg
1076 addl foo@indntpoff(%rip), %reg
1079 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1082 /* Check "movl foo@tpoff(%rip), %eax" first. */
1083 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1090 /* Check movl|addl foo@tpoff(%rip), %reg. */
1091 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1092 return ((type
== 0x8b || type
== 0x03)
1093 && (val
& 0xc7) == 0x05);
1095 case R_386_TLS_GOTIE
:
1096 case R_386_TLS_IE_32
:
1097 /* Check transition from {IE_32,GOTIE} access model:
1098 subl foo@{tpoff,gontoff}(%reg1), %reg2
1099 movl foo@{tpoff,gontoff}(%reg1), %reg2
1100 addl foo@{tpoff,gontoff}(%reg1), %reg2
1103 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1106 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1107 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1110 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1111 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1113 case R_386_TLS_GOTDESC
:
1114 /* Check transition from GDesc access model:
1115 leal x@tlsdesc(%ebx), %eax
1117 Make sure it's a leal adding ebx to a 32-bit offset
1118 into any register, although it's probably almost always
1121 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1124 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1127 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1128 return (val
& 0xc7) == 0x83;
1130 case R_386_TLS_DESC_CALL
:
1131 /* Check transition from GDesc access model:
1132 call *x@tlsdesc(%rax)
1134 if (offset
+ 2 <= sec
->size
)
1136 /* Make sure that it's a call *x@tlsdesc(%rax). */
1137 static i386_opcode16 call
= { { 0xff, 0x10 } };
1138 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1148 /* Return TRUE if the TLS access transition is OK or no transition
1149 will be performed. Update R_TYPE if there is a transition. */
1152 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1153 asection
*sec
, bfd_byte
*contents
,
1154 Elf_Internal_Shdr
*symtab_hdr
,
1155 struct elf_link_hash_entry
**sym_hashes
,
1156 unsigned int *r_type
, int tls_type
,
1157 const Elf_Internal_Rela
*rel
,
1158 const Elf_Internal_Rela
*relend
,
1159 struct elf_link_hash_entry
*h
,
1160 unsigned long r_symndx
)
1162 unsigned int from_type
= *r_type
;
1163 unsigned int to_type
= from_type
;
1164 bfd_boolean check
= TRUE
;
1166 /* Skip TLS transition for functions. */
1168 && (h
->type
== STT_FUNC
1169 || h
->type
== STT_GNU_IFUNC
))
1175 case R_386_TLS_GOTDESC
:
1176 case R_386_TLS_DESC_CALL
:
1177 case R_386_TLS_IE_32
:
1179 case R_386_TLS_GOTIE
:
1180 if (info
->executable
)
1183 to_type
= R_386_TLS_LE_32
;
1184 else if (from_type
!= R_386_TLS_IE
1185 && from_type
!= R_386_TLS_GOTIE
)
1186 to_type
= R_386_TLS_IE_32
;
1189 /* When we are called from elf_i386_relocate_section, CONTENTS
1190 isn't NULL and there may be additional transitions based on
1192 if (contents
!= NULL
)
1194 unsigned int new_to_type
= to_type
;
1196 if (info
->executable
1199 && (tls_type
& GOT_TLS_IE
))
1200 new_to_type
= R_386_TLS_LE_32
;
1202 if (to_type
== R_386_TLS_GD
1203 || to_type
== R_386_TLS_GOTDESC
1204 || to_type
== R_386_TLS_DESC_CALL
)
1206 if (tls_type
== GOT_TLS_IE_POS
)
1207 new_to_type
= R_386_TLS_GOTIE
;
1208 else if (tls_type
& GOT_TLS_IE
)
1209 new_to_type
= R_386_TLS_IE_32
;
1212 /* We checked the transition before when we were called from
1213 elf_i386_check_relocs. We only want to check the new
1214 transition which hasn't been checked before. */
1215 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1216 to_type
= new_to_type
;
1222 if (info
->executable
)
1223 to_type
= R_386_TLS_LE_32
;
1230 /* Return TRUE if there is no transition. */
1231 if (from_type
== to_type
)
1234 /* Check if the transition can be performed. */
1236 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1237 symtab_hdr
, sym_hashes
,
1238 from_type
, rel
, relend
))
1240 reloc_howto_type
*from
, *to
;
1243 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1244 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1247 name
= h
->root
.root
.string
;
1250 struct elf_i386_link_hash_table
*htab
;
1252 htab
= elf_i386_hash_table (info
);
1257 Elf_Internal_Sym
*isym
;
1259 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1261 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1265 (*_bfd_error_handler
)
1266 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1267 "in section `%A' failed"),
1268 abfd
, sec
, from
->name
, to
->name
, name
,
1269 (unsigned long) rel
->r_offset
);
1270 bfd_set_error (bfd_error_bad_value
);
1278 /* Look through the relocs for a section during the first phase, and
1279 calculate needed space in the global offset table, procedure linkage
1280 table, and dynamic reloc sections. */
1283 elf_i386_check_relocs (bfd
*abfd
,
1284 struct bfd_link_info
*info
,
1286 const Elf_Internal_Rela
*relocs
)
1288 struct elf_i386_link_hash_table
*htab
;
1289 Elf_Internal_Shdr
*symtab_hdr
;
1290 struct elf_link_hash_entry
**sym_hashes
;
1291 const Elf_Internal_Rela
*rel
;
1292 const Elf_Internal_Rela
*rel_end
;
1295 if (info
->relocatable
)
1298 BFD_ASSERT (is_i386_elf (abfd
));
1300 htab
= elf_i386_hash_table (info
);
1304 symtab_hdr
= &elf_symtab_hdr (abfd
);
1305 sym_hashes
= elf_sym_hashes (abfd
);
1309 rel_end
= relocs
+ sec
->reloc_count
;
1310 for (rel
= relocs
; rel
< rel_end
; rel
++)
1312 unsigned int r_type
;
1313 unsigned long r_symndx
;
1314 struct elf_link_hash_entry
*h
;
1315 Elf_Internal_Sym
*isym
;
1318 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1319 r_type
= ELF32_R_TYPE (rel
->r_info
);
1321 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1323 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1329 if (r_symndx
< symtab_hdr
->sh_info
)
1331 /* A local symbol. */
1332 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1337 /* Check relocation against local STT_GNU_IFUNC symbol. */
1338 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1340 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1344 /* Fake a STT_GNU_IFUNC symbol. */
1345 h
->type
= STT_GNU_IFUNC
;
1348 h
->forced_local
= 1;
1349 h
->root
.type
= bfd_link_hash_defined
;
1357 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1358 while (h
->root
.type
== bfd_link_hash_indirect
1359 || h
->root
.type
== bfd_link_hash_warning
)
1360 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1365 /* Create the ifunc sections for static executables. If we
1366 never see an indirect function symbol nor we are building
1367 a static executable, those sections will be empty and
1368 won't appear in output. */
1379 if (htab
->elf
.dynobj
== NULL
)
1380 htab
->elf
.dynobj
= abfd
;
1381 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1386 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1387 it here if it is defined in a non-shared object. */
1388 if (h
->type
== STT_GNU_IFUNC
1391 /* It is referenced by a non-shared object. */
1395 /* STT_GNU_IFUNC symbol must go through PLT. */
1396 h
->plt
.refcount
+= 1;
1398 /* STT_GNU_IFUNC needs dynamic sections. */
1399 if (htab
->elf
.dynobj
== NULL
)
1400 htab
->elf
.dynobj
= abfd
;
1405 if (h
->root
.root
.string
)
1406 name
= h
->root
.root
.string
;
1408 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1410 (*_bfd_error_handler
)
1411 (_("%B: relocation %s against STT_GNU_IFUNC "
1412 "symbol `%s' isn't handled by %s"), abfd
,
1413 elf_howto_table
[r_type
].name
,
1414 name
, __FUNCTION__
);
1415 bfd_set_error (bfd_error_bad_value
);
1420 h
->pointer_equality_needed
= 1;
1423 /* We must copy these reloc types into the
1424 output file. Create a reloc section in
1425 dynobj and make room for this reloc. */
1426 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1427 (abfd
, info
, sec
, sreloc
,
1428 &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
);
1443 h
->got
.refcount
+= 1;
1444 if (htab
->elf
.sgot
== NULL
1445 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1455 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1456 symtab_hdr
, sym_hashes
,
1457 &r_type
, GOT_UNKNOWN
,
1458 rel
, rel_end
, h
, r_symndx
))
1464 htab
->tls_ldm_got
.refcount
+= 1;
1468 /* This symbol requires a procedure linkage table entry. We
1469 actually build the entry in adjust_dynamic_symbol,
1470 because this might be a case of linking PIC code which is
1471 never referenced by a dynamic object, in which case we
1472 don't need to generate a procedure linkage table entry
1475 /* If this is a local symbol, we resolve it directly without
1476 creating a procedure linkage table entry. */
1481 h
->plt
.refcount
+= 1;
1484 case R_386_TLS_IE_32
:
1486 case R_386_TLS_GOTIE
:
1487 if (!info
->executable
)
1488 info
->flags
|= DF_STATIC_TLS
;
1493 case R_386_TLS_GOTDESC
:
1494 case R_386_TLS_DESC_CALL
:
1495 /* This symbol requires a global offset table entry. */
1497 int tls_type
, old_tls_type
;
1502 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1503 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1504 case R_386_TLS_GOTDESC
:
1505 case R_386_TLS_DESC_CALL
:
1506 tls_type
= GOT_TLS_GDESC
; break;
1507 case R_386_TLS_IE_32
:
1508 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1509 tls_type
= GOT_TLS_IE_NEG
;
1511 /* If this is a GD->IE transition, we may use either of
1512 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1513 tls_type
= GOT_TLS_IE
;
1516 case R_386_TLS_GOTIE
:
1517 tls_type
= GOT_TLS_IE_POS
; break;
1522 h
->got
.refcount
+= 1;
1523 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1527 bfd_signed_vma
*local_got_refcounts
;
1529 /* This is a global offset table entry for a local symbol. */
1530 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1531 if (local_got_refcounts
== NULL
)
1535 size
= symtab_hdr
->sh_info
;
1536 size
*= (sizeof (bfd_signed_vma
)
1537 + sizeof (bfd_vma
) + sizeof(char));
1538 local_got_refcounts
= (bfd_signed_vma
*)
1539 bfd_zalloc (abfd
, size
);
1540 if (local_got_refcounts
== NULL
)
1542 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1543 elf_i386_local_tlsdesc_gotent (abfd
)
1544 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1545 elf_i386_local_got_tls_type (abfd
)
1546 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1548 local_got_refcounts
[r_symndx
] += 1;
1549 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1552 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1553 tls_type
|= old_tls_type
;
1554 /* If a TLS symbol is accessed using IE at least once,
1555 there is no point to use dynamic model for it. */
1556 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1557 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1558 || (tls_type
& GOT_TLS_IE
) == 0))
1560 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1561 tls_type
= old_tls_type
;
1562 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1563 && GOT_TLS_GD_ANY_P (tls_type
))
1564 tls_type
|= old_tls_type
;
1568 name
= h
->root
.root
.string
;
1570 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1572 (*_bfd_error_handler
)
1573 (_("%B: `%s' accessed both as normal and "
1574 "thread local symbol"),
1580 if (old_tls_type
!= tls_type
)
1583 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1585 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1593 if (htab
->elf
.sgot
== NULL
)
1595 if (htab
->elf
.dynobj
== NULL
)
1596 htab
->elf
.dynobj
= abfd
;
1597 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1600 if (r_type
!= R_386_TLS_IE
)
1604 case R_386_TLS_LE_32
:
1606 if (info
->executable
)
1608 info
->flags
|= DF_STATIC_TLS
;
1613 if (h
!= NULL
&& info
->executable
)
1615 /* If this reloc is in a read-only section, we might
1616 need a copy reloc. We can't check reliably at this
1617 stage whether the section is read-only, as input
1618 sections have not yet been mapped to output sections.
1619 Tentatively set the flag for now, and correct in
1620 adjust_dynamic_symbol. */
1623 /* We may need a .plt entry if the function this reloc
1624 refers to is in a shared lib. */
1625 h
->plt
.refcount
+= 1;
1626 if (r_type
!= R_386_PC32
)
1627 h
->pointer_equality_needed
= 1;
1630 /* If we are creating a shared library, and this is a reloc
1631 against a global symbol, or a non PC relative reloc
1632 against a local symbol, then we need to copy the reloc
1633 into the shared library. However, if we are linking with
1634 -Bsymbolic, we do not need to copy a reloc against a
1635 global symbol which is defined in an object we are
1636 including in the link (i.e., DEF_REGULAR is set). At
1637 this point we have not seen all the input files, so it is
1638 possible that DEF_REGULAR is not set now but will be set
1639 later (it is never cleared). In case of a weak definition,
1640 DEF_REGULAR may be cleared later by a strong definition in
1641 a shared library. We account for that possibility below by
1642 storing information in the relocs_copied field of the hash
1643 table entry. A similar situation occurs when creating
1644 shared libraries and symbol visibility changes render the
1647 If on the other hand, we are creating an executable, we
1648 may need to keep relocations for symbols satisfied by a
1649 dynamic library if we manage to avoid copy relocs for the
1652 && (sec
->flags
& SEC_ALLOC
) != 0
1653 && (r_type
!= R_386_PC32
1655 && (! SYMBOLIC_BIND (info
, h
)
1656 || h
->root
.type
== bfd_link_hash_defweak
1657 || !h
->def_regular
))))
1658 || (ELIMINATE_COPY_RELOCS
1660 && (sec
->flags
& SEC_ALLOC
) != 0
1662 && (h
->root
.type
== bfd_link_hash_defweak
1663 || !h
->def_regular
)))
1665 struct elf_dyn_relocs
*p
;
1666 struct elf_dyn_relocs
**head
;
1668 /* We must copy these reloc types into the output file.
1669 Create a reloc section in dynobj and make room for
1673 if (htab
->elf
.dynobj
== NULL
)
1674 htab
->elf
.dynobj
= abfd
;
1676 sreloc
= _bfd_elf_make_dynamic_reloc_section
1677 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1683 /* If this is a global symbol, we count the number of
1684 relocations we need for this symbol. */
1687 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1691 /* Track dynamic relocs needed for local syms too.
1692 We really need local syms available to do this
1697 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1702 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1706 vpp
= &elf_section_data (s
)->local_dynrel
;
1707 head
= (struct elf_dyn_relocs
**)vpp
;
1711 if (p
== NULL
|| p
->sec
!= sec
)
1713 bfd_size_type amt
= sizeof *p
;
1714 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1726 if (r_type
== R_386_PC32
)
1731 /* This relocation describes the C++ object vtable hierarchy.
1732 Reconstruct it for later use during GC. */
1733 case R_386_GNU_VTINHERIT
:
1734 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1738 /* This relocation describes which C++ vtable entries are actually
1739 used. Record for later use during GC. */
1740 case R_386_GNU_VTENTRY
:
1741 BFD_ASSERT (h
!= NULL
);
1743 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1755 /* Return the section that should be marked against GC for a given
1759 elf_i386_gc_mark_hook (asection
*sec
,
1760 struct bfd_link_info
*info
,
1761 Elf_Internal_Rela
*rel
,
1762 struct elf_link_hash_entry
*h
,
1763 Elf_Internal_Sym
*sym
)
1766 switch (ELF32_R_TYPE (rel
->r_info
))
1768 case R_386_GNU_VTINHERIT
:
1769 case R_386_GNU_VTENTRY
:
1773 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1776 /* Update the got entry reference counts for the section being removed. */
1779 elf_i386_gc_sweep_hook (bfd
*abfd
,
1780 struct bfd_link_info
*info
,
1782 const Elf_Internal_Rela
*relocs
)
1784 struct elf_i386_link_hash_table
*htab
;
1785 Elf_Internal_Shdr
*symtab_hdr
;
1786 struct elf_link_hash_entry
**sym_hashes
;
1787 bfd_signed_vma
*local_got_refcounts
;
1788 const Elf_Internal_Rela
*rel
, *relend
;
1790 if (info
->relocatable
)
1793 htab
= elf_i386_hash_table (info
);
1797 elf_section_data (sec
)->local_dynrel
= NULL
;
1799 symtab_hdr
= &elf_symtab_hdr (abfd
);
1800 sym_hashes
= elf_sym_hashes (abfd
);
1801 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1803 relend
= relocs
+ sec
->reloc_count
;
1804 for (rel
= relocs
; rel
< relend
; rel
++)
1806 unsigned long r_symndx
;
1807 unsigned int r_type
;
1808 struct elf_link_hash_entry
*h
= NULL
;
1810 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1811 if (r_symndx
>= symtab_hdr
->sh_info
)
1813 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1814 while (h
->root
.type
== bfd_link_hash_indirect
1815 || h
->root
.type
== bfd_link_hash_warning
)
1816 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1820 /* A local symbol. */
1821 Elf_Internal_Sym
*isym
;
1823 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1826 /* Check relocation against local STT_GNU_IFUNC symbol. */
1828 && ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1830 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1838 struct elf_i386_link_hash_entry
*eh
;
1839 struct elf_dyn_relocs
**pp
;
1840 struct elf_dyn_relocs
*p
;
1842 eh
= (struct elf_i386_link_hash_entry
*) h
;
1843 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1846 /* Everything must go for SEC. */
1852 r_type
= ELF32_R_TYPE (rel
->r_info
);
1853 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1854 symtab_hdr
, sym_hashes
,
1855 &r_type
, GOT_UNKNOWN
,
1856 rel
, relend
, h
, r_symndx
))
1862 if (htab
->tls_ldm_got
.refcount
> 0)
1863 htab
->tls_ldm_got
.refcount
-= 1;
1867 case R_386_TLS_GOTDESC
:
1868 case R_386_TLS_DESC_CALL
:
1869 case R_386_TLS_IE_32
:
1871 case R_386_TLS_GOTIE
:
1875 if (h
->got
.refcount
> 0)
1876 h
->got
.refcount
-= 1;
1877 if (h
->type
== STT_GNU_IFUNC
)
1879 if (h
->plt
.refcount
> 0)
1880 h
->plt
.refcount
-= 1;
1883 else if (local_got_refcounts
!= NULL
)
1885 if (local_got_refcounts
[r_symndx
] > 0)
1886 local_got_refcounts
[r_symndx
] -= 1;
1893 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1900 if (h
->plt
.refcount
> 0)
1901 h
->plt
.refcount
-= 1;
1906 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
1908 if (h
->got
.refcount
> 0)
1909 h
->got
.refcount
-= 1;
1910 if (h
->plt
.refcount
> 0)
1911 h
->plt
.refcount
-= 1;
1923 /* Adjust a symbol defined by a dynamic object and referenced by a
1924 regular object. The current definition is in some section of the
1925 dynamic object, but we're not including those sections. We have to
1926 change the definition to something the rest of the link can
1930 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1931 struct elf_link_hash_entry
*h
)
1933 struct elf_i386_link_hash_table
*htab
;
1936 /* STT_GNU_IFUNC symbol must go through PLT. */
1937 if (h
->type
== STT_GNU_IFUNC
)
1939 if (h
->plt
.refcount
<= 0)
1941 h
->plt
.offset
= (bfd_vma
) -1;
1947 /* If this is a function, put it in the procedure linkage table. We
1948 will fill in the contents of the procedure linkage table later,
1949 when we know the address of the .got section. */
1950 if (h
->type
== STT_FUNC
1953 if (h
->plt
.refcount
<= 0
1954 || SYMBOL_CALLS_LOCAL (info
, h
)
1955 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1956 && h
->root
.type
== bfd_link_hash_undefweak
))
1958 /* This case can occur if we saw a PLT32 reloc in an input
1959 file, but the symbol was never referred to by a dynamic
1960 object, or if all references were garbage collected. In
1961 such a case, we don't actually need to build a procedure
1962 linkage table, and we can just do a PC32 reloc instead. */
1963 h
->plt
.offset
= (bfd_vma
) -1;
1970 /* It's possible that we incorrectly decided a .plt reloc was
1971 needed for an R_386_PC32 reloc to a non-function sym in
1972 check_relocs. We can't decide accurately between function and
1973 non-function syms in check-relocs; Objects loaded later in
1974 the link may change h->type. So fix it now. */
1975 h
->plt
.offset
= (bfd_vma
) -1;
1977 /* If this is a weak symbol, and there is a real definition, the
1978 processor independent code will have arranged for us to see the
1979 real definition first, and we can just use the same value. */
1980 if (h
->u
.weakdef
!= NULL
)
1982 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1983 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1984 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1985 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1986 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1987 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1991 /* This is a reference to a symbol defined by a dynamic object which
1992 is not a function. */
1994 /* If we are creating a shared library, we must presume that the
1995 only references to the symbol are via the global offset table.
1996 For such cases we need not do anything here; the relocations will
1997 be handled correctly by relocate_section. */
2001 /* If there are no references to this symbol that do not use the
2002 GOT, we don't need to generate a copy reloc. */
2003 if (!h
->non_got_ref
)
2006 /* If -z nocopyreloc was given, we won't generate them either. */
2007 if (info
->nocopyreloc
)
2013 htab
= elf_i386_hash_table (info
);
2017 /* If there aren't any dynamic relocs in read-only sections, then
2018 we can keep the dynamic relocs and avoid the copy reloc. This
2019 doesn't work on VxWorks, where we can not have dynamic relocations
2020 (other than copy and jump slot relocations) in an executable. */
2021 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
2023 struct elf_i386_link_hash_entry
* eh
;
2024 struct elf_dyn_relocs
*p
;
2026 eh
= (struct elf_i386_link_hash_entry
*) h
;
2027 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2029 s
= p
->sec
->output_section
;
2030 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2043 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2044 h
->root
.root
.string
);
2048 /* We must allocate the symbol in our .dynbss section, which will
2049 become part of the .bss section of the executable. There will be
2050 an entry for this symbol in the .dynsym section. The dynamic
2051 object will contain position independent code, so all references
2052 from the dynamic object to this symbol will go through the global
2053 offset table. The dynamic linker will use the .dynsym entry to
2054 determine the address it must put in the global offset table, so
2055 both the dynamic object and the regular object will refer to the
2056 same memory location for the variable. */
2058 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2059 copy the initial value out of the dynamic object and into the
2060 runtime process image. */
2061 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2063 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2069 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2072 /* Allocate space in .plt, .got and associated reloc sections for
2076 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2078 struct bfd_link_info
*info
;
2079 struct elf_i386_link_hash_table
*htab
;
2080 struct elf_i386_link_hash_entry
*eh
;
2081 struct elf_dyn_relocs
*p
;
2083 if (h
->root
.type
== bfd_link_hash_indirect
)
2086 eh
= (struct elf_i386_link_hash_entry
*) h
;
2088 info
= (struct bfd_link_info
*) inf
;
2089 htab
= elf_i386_hash_table (info
);
2093 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2094 here if it is defined and referenced in a non-shared object. */
2095 if (h
->type
== STT_GNU_IFUNC
2097 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2100 else if (htab
->elf
.dynamic_sections_created
2101 && h
->plt
.refcount
> 0)
2103 /* Make sure this symbol is output as a dynamic symbol.
2104 Undefined weak syms won't yet be marked as dynamic. */
2105 if (h
->dynindx
== -1
2106 && !h
->forced_local
)
2108 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2113 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2115 asection
*s
= htab
->elf
.splt
;
2117 /* If this is the first .plt entry, make room for the special
2120 s
->size
+= PLT_ENTRY_SIZE
;
2122 h
->plt
.offset
= s
->size
;
2124 /* If this symbol is not defined in a regular file, and we are
2125 not generating a shared library, then set the symbol to this
2126 location in the .plt. This is required to make function
2127 pointers compare as equal between the normal executable and
2128 the shared library. */
2132 h
->root
.u
.def
.section
= s
;
2133 h
->root
.u
.def
.value
= h
->plt
.offset
;
2136 /* Make room for this entry. */
2137 s
->size
+= PLT_ENTRY_SIZE
;
2139 /* We also need to make an entry in the .got.plt section, which
2140 will be placed in the .got section by the linker script. */
2141 htab
->elf
.sgotplt
->size
+= 4;
2143 /* We also need to make an entry in the .rel.plt section. */
2144 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2145 htab
->next_tls_desc_index
++;
2147 if (htab
->is_vxworks
&& !info
->shared
)
2149 /* VxWorks has a second set of relocations for each PLT entry
2150 in executables. They go in a separate relocation section,
2151 which is processed by the kernel loader. */
2153 /* There are two relocations for the initial PLT entry: an
2154 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2155 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2157 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
2158 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2160 /* There are two extra relocations for each subsequent PLT entry:
2161 an R_386_32 relocation for the GOT entry, and an R_386_32
2162 relocation for the PLT entry. */
2164 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2169 h
->plt
.offset
= (bfd_vma
) -1;
2175 h
->plt
.offset
= (bfd_vma
) -1;
2179 eh
->tlsdesc_got
= (bfd_vma
) -1;
2181 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2182 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2183 if (h
->got
.refcount
> 0
2186 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2187 h
->got
.offset
= (bfd_vma
) -1;
2188 else if (h
->got
.refcount
> 0)
2192 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2194 /* Make sure this symbol is output as a dynamic symbol.
2195 Undefined weak syms won't yet be marked as dynamic. */
2196 if (h
->dynindx
== -1
2197 && !h
->forced_local
)
2199 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2204 if (GOT_TLS_GDESC_P (tls_type
))
2206 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2207 - elf_i386_compute_jump_table_size (htab
);
2208 htab
->elf
.sgotplt
->size
+= 8;
2209 h
->got
.offset
= (bfd_vma
) -2;
2211 if (! GOT_TLS_GDESC_P (tls_type
)
2212 || GOT_TLS_GD_P (tls_type
))
2214 h
->got
.offset
= s
->size
;
2216 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2217 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2220 dyn
= htab
->elf
.dynamic_sections_created
;
2221 /* R_386_TLS_IE_32 needs one dynamic relocation,
2222 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2223 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2224 need two), R_386_TLS_GD needs one if local symbol and two if
2226 if (tls_type
== GOT_TLS_IE_BOTH
)
2227 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2228 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2229 || (tls_type
& GOT_TLS_IE
))
2230 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2231 else if (GOT_TLS_GD_P (tls_type
))
2232 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2233 else if (! GOT_TLS_GDESC_P (tls_type
)
2234 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2235 || h
->root
.type
!= bfd_link_hash_undefweak
)
2237 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2238 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2239 if (GOT_TLS_GDESC_P (tls_type
))
2240 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2243 h
->got
.offset
= (bfd_vma
) -1;
2245 if (eh
->dyn_relocs
== NULL
)
2248 /* In the shared -Bsymbolic case, discard space allocated for
2249 dynamic pc-relative relocs against symbols which turn out to be
2250 defined in regular objects. For the normal shared case, discard
2251 space for pc-relative relocs that have become local due to symbol
2252 visibility changes. */
2256 /* The only reloc that uses pc_count is R_386_PC32, which will
2257 appear on a call or on something like ".long foo - .". We
2258 want calls to protected symbols to resolve directly to the
2259 function rather than going via the plt. If people want
2260 function pointer comparisons to work as expected then they
2261 should avoid writing assembly like ".long foo - .". */
2262 if (SYMBOL_CALLS_LOCAL (info
, h
))
2264 struct elf_dyn_relocs
**pp
;
2266 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2268 p
->count
-= p
->pc_count
;
2277 if (htab
->is_vxworks
)
2279 struct elf_dyn_relocs
**pp
;
2280 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2282 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2289 /* Also discard relocs on undefined weak syms with non-default
2291 if (eh
->dyn_relocs
!= NULL
2292 && h
->root
.type
== bfd_link_hash_undefweak
)
2294 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2295 eh
->dyn_relocs
= NULL
;
2297 /* Make sure undefined weak symbols are output as a dynamic
2299 else if (h
->dynindx
== -1
2300 && !h
->forced_local
)
2302 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2307 else if (ELIMINATE_COPY_RELOCS
)
2309 /* For the non-shared case, discard space for relocs against
2310 symbols which turn out to need copy relocs or are not
2316 || (htab
->elf
.dynamic_sections_created
2317 && (h
->root
.type
== bfd_link_hash_undefweak
2318 || h
->root
.type
== bfd_link_hash_undefined
))))
2320 /* Make sure this symbol is output as a dynamic symbol.
2321 Undefined weak syms won't yet be marked as dynamic. */
2322 if (h
->dynindx
== -1
2323 && !h
->forced_local
)
2325 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2329 /* If that succeeded, we know we'll be keeping all the
2331 if (h
->dynindx
!= -1)
2335 eh
->dyn_relocs
= NULL
;
2340 /* Finally, allocate space. */
2341 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2345 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2347 BFD_ASSERT (sreloc
!= NULL
);
2348 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2354 /* Allocate space in .plt, .got and associated reloc sections for
2355 local dynamic relocs. */
2358 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2360 struct elf_link_hash_entry
*h
2361 = (struct elf_link_hash_entry
*) *slot
;
2363 if (h
->type
!= STT_GNU_IFUNC
2367 || h
->root
.type
!= bfd_link_hash_defined
)
2370 return elf_i386_allocate_dynrelocs (h
, inf
);
2373 /* Find any dynamic relocs that apply to read-only sections. */
2376 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2378 struct elf_i386_link_hash_entry
*eh
;
2379 struct elf_dyn_relocs
*p
;
2381 /* Skip local IFUNC symbols. */
2382 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2385 eh
= (struct elf_i386_link_hash_entry
*) h
;
2386 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2388 asection
*s
= p
->sec
->output_section
;
2390 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2392 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2394 info
->flags
|= DF_TEXTREL
;
2396 if (info
->warn_shared_textrel
&& info
->shared
)
2397 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2398 p
->sec
->owner
, h
->root
.root
.string
,
2401 /* Not an error, just cut short the traversal. */
2408 /* Set the sizes of the dynamic sections. */
2411 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2412 struct bfd_link_info
*info
)
2414 struct elf_i386_link_hash_table
*htab
;
2420 htab
= elf_i386_hash_table (info
);
2423 dynobj
= htab
->elf
.dynobj
;
2427 if (htab
->elf
.dynamic_sections_created
)
2429 /* Set the contents of the .interp section to the interpreter. */
2430 if (info
->executable
)
2432 s
= bfd_get_section_by_name (dynobj
, ".interp");
2435 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2436 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2440 /* Set up .got offsets for local syms, and space for local dynamic
2442 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2444 bfd_signed_vma
*local_got
;
2445 bfd_signed_vma
*end_local_got
;
2446 char *local_tls_type
;
2447 bfd_vma
*local_tlsdesc_gotent
;
2448 bfd_size_type locsymcount
;
2449 Elf_Internal_Shdr
*symtab_hdr
;
2452 if (! is_i386_elf (ibfd
))
2455 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2457 struct elf_dyn_relocs
*p
;
2459 for (p
= ((struct elf_dyn_relocs
*)
2460 elf_section_data (s
)->local_dynrel
);
2464 if (!bfd_is_abs_section (p
->sec
)
2465 && bfd_is_abs_section (p
->sec
->output_section
))
2467 /* Input section has been discarded, either because
2468 it is a copy of a linkonce section or due to
2469 linker script /DISCARD/, so we'll be discarding
2472 else if (htab
->is_vxworks
2473 && strcmp (p
->sec
->output_section
->name
,
2476 /* Relocations in vxworks .tls_vars sections are
2477 handled specially by the loader. */
2479 else if (p
->count
!= 0)
2481 srel
= elf_section_data (p
->sec
)->sreloc
;
2482 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2483 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2484 && (info
->flags
& DF_TEXTREL
) == 0)
2486 info
->flags
|= DF_TEXTREL
;
2487 if (info
->warn_shared_textrel
&& info
->shared
)
2488 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2489 p
->sec
->owner
, p
->sec
);
2495 local_got
= elf_local_got_refcounts (ibfd
);
2499 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2500 locsymcount
= symtab_hdr
->sh_info
;
2501 end_local_got
= local_got
+ locsymcount
;
2502 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2503 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2505 srel
= htab
->elf
.srelgot
;
2506 for (; local_got
< end_local_got
;
2507 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2509 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2512 if (GOT_TLS_GDESC_P (*local_tls_type
))
2514 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2515 - elf_i386_compute_jump_table_size (htab
);
2516 htab
->elf
.sgotplt
->size
+= 8;
2517 *local_got
= (bfd_vma
) -2;
2519 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2520 || GOT_TLS_GD_P (*local_tls_type
))
2522 *local_got
= s
->size
;
2524 if (GOT_TLS_GD_P (*local_tls_type
)
2525 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2529 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2530 || (*local_tls_type
& GOT_TLS_IE
))
2532 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2533 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2534 else if (GOT_TLS_GD_P (*local_tls_type
)
2535 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2536 srel
->size
+= sizeof (Elf32_External_Rel
);
2537 if (GOT_TLS_GDESC_P (*local_tls_type
))
2538 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2542 *local_got
= (bfd_vma
) -1;
2546 if (htab
->tls_ldm_got
.refcount
> 0)
2548 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2550 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2551 htab
->elf
.sgot
->size
+= 8;
2552 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2555 htab
->tls_ldm_got
.offset
= -1;
2557 /* Allocate global sym .plt and .got entries, and space for global
2558 sym dynamic relocs. */
2559 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2561 /* Allocate .plt and .got entries, and space for local symbols. */
2562 htab_traverse (htab
->loc_hash_table
,
2563 elf_i386_allocate_local_dynrelocs
,
2566 /* For every jump slot reserved in the sgotplt, reloc_count is
2567 incremented. However, when we reserve space for TLS descriptors,
2568 it's not incremented, so in order to compute the space reserved
2569 for them, it suffices to multiply the reloc count by the jump
2571 if (htab
->elf
.srelplt
)
2572 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2574 if (htab
->elf
.sgotplt
)
2576 struct elf_link_hash_entry
*got
;
2577 got
= elf_link_hash_lookup (elf_hash_table (info
),
2578 "_GLOBAL_OFFSET_TABLE_",
2579 FALSE
, FALSE
, FALSE
);
2581 /* Don't allocate .got.plt section if there are no GOT nor PLT
2582 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2584 || !got
->ref_regular_nonweak
)
2585 && (htab
->elf
.sgotplt
->size
2586 == get_elf_backend_data (output_bfd
)->got_header_size
)
2587 && (htab
->elf
.splt
== NULL
2588 || htab
->elf
.splt
->size
== 0)
2589 && (htab
->elf
.sgot
== NULL
2590 || htab
->elf
.sgot
->size
== 0)
2591 && (htab
->elf
.iplt
== NULL
2592 || htab
->elf
.iplt
->size
== 0)
2593 && (htab
->elf
.igotplt
== NULL
2594 || htab
->elf
.igotplt
->size
== 0))
2595 htab
->elf
.sgotplt
->size
= 0;
2598 /* We now have determined the sizes of the various dynamic sections.
2599 Allocate memory for them. */
2601 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2603 bfd_boolean strip_section
= TRUE
;
2605 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2608 if (s
== htab
->elf
.splt
2609 || s
== htab
->elf
.sgot
2610 || s
== htab
->elf
.sgotplt
2611 || s
== htab
->elf
.iplt
2612 || s
== htab
->elf
.igotplt
2613 || s
== htab
->sdynbss
)
2615 /* Strip this section if we don't need it; see the
2617 /* We'd like to strip these sections if they aren't needed, but if
2618 we've exported dynamic symbols from them we must leave them.
2619 It's too late to tell BFD to get rid of the symbols. */
2621 if (htab
->elf
.hplt
!= NULL
)
2622 strip_section
= FALSE
;
2624 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2627 && s
!= htab
->elf
.srelplt
2628 && s
!= htab
->srelplt2
)
2631 /* We use the reloc_count field as a counter if we need
2632 to copy relocs into the output file. */
2637 /* It's not one of our sections, so don't allocate space. */
2643 /* If we don't need this section, strip it from the
2644 output file. This is mostly to handle .rel.bss and
2645 .rel.plt. We must create both sections in
2646 create_dynamic_sections, because they must be created
2647 before the linker maps input sections to output
2648 sections. The linker does that before
2649 adjust_dynamic_symbol is called, and it is that
2650 function which decides whether anything needs to go
2651 into these sections. */
2653 s
->flags
|= SEC_EXCLUDE
;
2657 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2660 /* Allocate memory for the section contents. We use bfd_zalloc
2661 here in case unused entries are not reclaimed before the
2662 section's contents are written out. This should not happen,
2663 but this way if it does, we get a R_386_NONE reloc instead
2665 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2666 if (s
->contents
== NULL
)
2670 if (htab
->elf
.dynamic_sections_created
)
2672 /* Add some entries to the .dynamic section. We fill in the
2673 values later, in elf_i386_finish_dynamic_sections, but we
2674 must add the entries now so that we get the correct size for
2675 the .dynamic section. The DT_DEBUG entry is filled in by the
2676 dynamic linker and used by the debugger. */
2677 #define add_dynamic_entry(TAG, VAL) \
2678 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2680 if (info
->executable
)
2682 if (!add_dynamic_entry (DT_DEBUG
, 0))
2686 if (htab
->elf
.splt
->size
!= 0)
2688 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2689 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2690 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2691 || !add_dynamic_entry (DT_JMPREL
, 0))
2697 if (!add_dynamic_entry (DT_REL
, 0)
2698 || !add_dynamic_entry (DT_RELSZ
, 0)
2699 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2702 /* If any dynamic relocs apply to a read-only section,
2703 then we need a DT_TEXTREL entry. */
2704 if ((info
->flags
& DF_TEXTREL
) == 0)
2705 elf_link_hash_traverse (&htab
->elf
,
2706 elf_i386_readonly_dynrelocs
, info
);
2708 if ((info
->flags
& DF_TEXTREL
) != 0)
2710 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2714 if (htab
->is_vxworks
2715 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2718 #undef add_dynamic_entry
2724 elf_i386_always_size_sections (bfd
*output_bfd
,
2725 struct bfd_link_info
*info
)
2727 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2731 struct elf_link_hash_entry
*tlsbase
;
2733 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2734 "_TLS_MODULE_BASE_",
2735 FALSE
, FALSE
, FALSE
);
2737 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2739 struct elf_i386_link_hash_table
*htab
;
2740 struct bfd_link_hash_entry
*bh
= NULL
;
2741 const struct elf_backend_data
*bed
2742 = get_elf_backend_data (output_bfd
);
2744 htab
= elf_i386_hash_table (info
);
2748 if (!(_bfd_generic_link_add_one_symbol
2749 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2750 tls_sec
, 0, NULL
, FALSE
,
2751 bed
->collect
, &bh
)))
2754 htab
->tls_module_base
= bh
;
2756 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2757 tlsbase
->def_regular
= 1;
2758 tlsbase
->other
= STV_HIDDEN
;
2759 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2766 /* Set the correct type for an x86 ELF section. We do this by the
2767 section name, which is a hack, but ought to work. */
2770 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2771 Elf_Internal_Shdr
*hdr
,
2776 name
= bfd_get_section_name (abfd
, sec
);
2778 /* This is an ugly, but unfortunately necessary hack that is
2779 needed when producing EFI binaries on x86. It tells
2780 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2781 containing ELF relocation info. We need this hack in order to
2782 be able to generate ELF binaries that can be translated into
2783 EFI applications (which are essentially COFF objects). Those
2784 files contain a COFF ".reloc" section inside an ELFNN object,
2785 which would normally cause BFD to segfault because it would
2786 attempt to interpret this section as containing relocation
2787 entries for section "oc". With this hack enabled, ".reloc"
2788 will be treated as a normal data section, which will avoid the
2789 segfault. However, you won't be able to create an ELFNN binary
2790 with a section named "oc" that needs relocations, but that's
2791 the kind of ugly side-effects you get when detecting section
2792 types based on their names... In practice, this limitation is
2793 unlikely to bite. */
2794 if (strcmp (name
, ".reloc") == 0)
2795 hdr
->sh_type
= SHT_PROGBITS
;
2800 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2801 executables. Rather than setting it to the beginning of the TLS
2802 section, we have to set it to the end. This function may be called
2803 multiple times, it is idempotent. */
2806 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2808 struct elf_i386_link_hash_table
*htab
;
2809 struct bfd_link_hash_entry
*base
;
2811 if (!info
->executable
)
2814 htab
= elf_i386_hash_table (info
);
2818 base
= htab
->tls_module_base
;
2822 base
->u
.def
.value
= htab
->elf
.tls_size
;
2825 /* Return the base VMA address which should be subtracted from real addresses
2826 when resolving @dtpoff relocation.
2827 This is PT_TLS segment p_vaddr. */
2830 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2832 /* If tls_sec is NULL, we should have signalled an error already. */
2833 if (elf_hash_table (info
)->tls_sec
== NULL
)
2835 return elf_hash_table (info
)->tls_sec
->vma
;
2838 /* Return the relocation value for @tpoff relocation
2839 if STT_TLS virtual address is ADDRESS. */
2842 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2844 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2845 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2846 bfd_vma static_tls_size
;
2848 /* If tls_sec is NULL, we should have signalled an error already. */
2849 if (htab
->tls_sec
== NULL
)
2852 /* Consider special static TLS alignment requirements. */
2853 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2854 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
2857 /* Relocate an i386 ELF section. */
2860 elf_i386_relocate_section (bfd
*output_bfd
,
2861 struct bfd_link_info
*info
,
2863 asection
*input_section
,
2865 Elf_Internal_Rela
*relocs
,
2866 Elf_Internal_Sym
*local_syms
,
2867 asection
**local_sections
)
2869 struct elf_i386_link_hash_table
*htab
;
2870 Elf_Internal_Shdr
*symtab_hdr
;
2871 struct elf_link_hash_entry
**sym_hashes
;
2872 bfd_vma
*local_got_offsets
;
2873 bfd_vma
*local_tlsdesc_gotents
;
2874 Elf_Internal_Rela
*rel
;
2875 Elf_Internal_Rela
*relend
;
2876 bfd_boolean is_vxworks_tls
;
2878 BFD_ASSERT (is_i386_elf (input_bfd
));
2880 htab
= elf_i386_hash_table (info
);
2883 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2884 sym_hashes
= elf_sym_hashes (input_bfd
);
2885 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2886 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2887 /* We have to handle relocations in vxworks .tls_vars sections
2888 specially, because the dynamic loader is 'weird'. */
2889 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
2890 && !strcmp (input_section
->output_section
->name
,
2893 elf_i386_set_tls_module_base (info
);
2896 relend
= relocs
+ input_section
->reloc_count
;
2897 for (; rel
< relend
; rel
++)
2899 unsigned int r_type
;
2900 reloc_howto_type
*howto
;
2901 unsigned long r_symndx
;
2902 struct elf_link_hash_entry
*h
;
2903 Elf_Internal_Sym
*sym
;
2905 bfd_vma off
, offplt
;
2907 bfd_boolean unresolved_reloc
;
2908 bfd_reloc_status_type r
;
2912 r_type
= ELF32_R_TYPE (rel
->r_info
);
2913 if (r_type
== R_386_GNU_VTINHERIT
2914 || r_type
== R_386_GNU_VTENTRY
)
2917 if ((indx
= r_type
) >= R_386_standard
2918 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2919 >= R_386_ext
- R_386_standard
)
2920 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2921 >= R_386_irelative
- R_386_ext
))
2923 (*_bfd_error_handler
)
2924 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2925 input_bfd
, input_section
, r_type
);
2926 bfd_set_error (bfd_error_bad_value
);
2929 howto
= elf_howto_table
+ indx
;
2931 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2935 unresolved_reloc
= FALSE
;
2936 if (r_symndx
< symtab_hdr
->sh_info
)
2938 sym
= local_syms
+ r_symndx
;
2939 sec
= local_sections
[r_symndx
];
2940 relocation
= (sec
->output_section
->vma
2941 + sec
->output_offset
2944 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2945 && ((sec
->flags
& SEC_MERGE
) != 0
2946 || (info
->relocatable
2947 && sec
->output_offset
!= 0)))
2950 bfd_byte
*where
= contents
+ rel
->r_offset
;
2952 switch (howto
->size
)
2955 addend
= bfd_get_8 (input_bfd
, where
);
2956 if (howto
->pc_relative
)
2958 addend
= (addend
^ 0x80) - 0x80;
2963 addend
= bfd_get_16 (input_bfd
, where
);
2964 if (howto
->pc_relative
)
2966 addend
= (addend
^ 0x8000) - 0x8000;
2971 addend
= bfd_get_32 (input_bfd
, where
);
2972 if (howto
->pc_relative
)
2974 addend
= (addend
^ 0x80000000) - 0x80000000;
2982 if (info
->relocatable
)
2983 addend
+= sec
->output_offset
;
2986 asection
*msec
= sec
;
2987 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2989 addend
-= relocation
;
2990 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2993 switch (howto
->size
)
2996 /* FIXME: overflow checks. */
2997 if (howto
->pc_relative
)
2999 bfd_put_8 (input_bfd
, addend
, where
);
3002 if (howto
->pc_relative
)
3004 bfd_put_16 (input_bfd
, addend
, where
);
3007 if (howto
->pc_relative
)
3009 bfd_put_32 (input_bfd
, addend
, where
);
3013 else if (!info
->relocatable
3014 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3016 /* Relocate against local STT_GNU_IFUNC symbol. */
3017 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3022 /* Set STT_GNU_IFUNC symbol value. */
3023 h
->root
.u
.def
.value
= sym
->st_value
;
3024 h
->root
.u
.def
.section
= sec
;
3029 bfd_boolean warned ATTRIBUTE_UNUSED
;
3031 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3032 r_symndx
, symtab_hdr
, sym_hashes
,
3034 unresolved_reloc
, warned
);
3037 if (sec
!= NULL
&& elf_discarded_section (sec
))
3038 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3039 rel
, relend
, howto
, contents
);
3041 if (info
->relocatable
)
3044 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3045 it here if it is defined in a non-shared object. */
3047 && h
->type
== STT_GNU_IFUNC
3050 asection
*plt
, *gotplt
, *base_got
;
3054 if ((input_section
->flags
& SEC_ALLOC
) == 0
3055 || h
->plt
.offset
== (bfd_vma
) -1)
3058 /* STT_GNU_IFUNC symbol must go through PLT. */
3059 if (htab
->elf
.splt
!= NULL
)
3061 plt
= htab
->elf
.splt
;
3062 gotplt
= htab
->elf
.sgotplt
;
3066 plt
= htab
->elf
.iplt
;
3067 gotplt
= htab
->elf
.igotplt
;
3070 relocation
= (plt
->output_section
->vma
3071 + plt
->output_offset
+ h
->plt
.offset
);
3076 if (h
->root
.root
.string
)
3077 name
= h
->root
.root
.string
;
3079 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3081 (*_bfd_error_handler
)
3082 (_("%B: relocation %s against STT_GNU_IFUNC "
3083 "symbol `%s' isn't handled by %s"), input_bfd
,
3084 elf_howto_table
[r_type
].name
,
3085 name
, __FUNCTION__
);
3086 bfd_set_error (bfd_error_bad_value
);
3090 /* Generate dynamic relcoation only when there is a
3091 non-GOF reference in a shared object. */
3092 if (info
->shared
&& h
->non_got_ref
)
3094 Elf_Internal_Rela outrel
;
3099 /* Need a dynamic relocation to get the real function
3101 offset
= _bfd_elf_section_offset (output_bfd
,
3105 if (offset
== (bfd_vma
) -1
3106 || offset
== (bfd_vma
) -2)
3109 outrel
.r_offset
= (input_section
->output_section
->vma
3110 + input_section
->output_offset
3113 if (h
->dynindx
== -1
3115 || info
->executable
)
3117 /* This symbol is resolved locally. */
3118 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3119 bfd_put_32 (output_bfd
,
3120 (h
->root
.u
.def
.value
3121 + h
->root
.u
.def
.section
->output_section
->vma
3122 + h
->root
.u
.def
.section
->output_offset
),
3126 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3128 sreloc
= htab
->elf
.irelifunc
;
3129 loc
= sreloc
->contents
;
3130 loc
+= (sreloc
->reloc_count
++
3131 * sizeof (Elf32_External_Rel
));
3132 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3134 /* If this reloc is against an external symbol, we
3135 do not want to fiddle with the addend. Otherwise,
3136 we need to include the symbol value so that it
3137 becomes an addend for the dynamic reloc. For an
3138 internal symbol, we have updated addend. */
3147 base_got
= htab
->elf
.sgot
;
3148 off
= h
->got
.offset
;
3150 if (base_got
== NULL
)
3153 if (off
== (bfd_vma
) -1)
3155 /* We can't use h->got.offset here to save state, or
3156 even just remember the offset, as finish_dynamic_symbol
3157 would use that as offset into .got. */
3159 if (htab
->elf
.splt
!= NULL
)
3161 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3162 off
= (plt_index
+ 3) * 4;
3163 base_got
= htab
->elf
.sgotplt
;
3167 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3168 off
= plt_index
* 4;
3169 base_got
= htab
->elf
.igotplt
;
3172 if (h
->dynindx
== -1
3176 /* This references the local defitionion. We must
3177 initialize this entry in the global offset table.
3178 Since the offset must always be a multiple of 8,
3179 we use the least significant bit to record
3180 whether we have initialized it already.
3182 When doing a dynamic link, we create a .rela.got
3183 relocation entry to initialize the value. This
3184 is done in the finish_dynamic_symbol routine. */
3189 bfd_put_32 (output_bfd
, relocation
,
3190 base_got
->contents
+ off
);
3197 /* Adjust for static executables. */
3198 if (htab
->elf
.splt
== NULL
)
3199 relocation
+= gotplt
->output_offset
;
3203 relocation
= (base_got
->output_section
->vma
3204 + base_got
->output_offset
+ off
3205 - gotplt
->output_section
->vma
3206 - gotplt
->output_offset
);
3207 /* Adjust for static executables. */
3208 if (htab
->elf
.splt
== NULL
)
3209 relocation
+= gotplt
->output_offset
;
3215 relocation
-= (gotplt
->output_section
->vma
3216 + gotplt
->output_offset
);
3224 /* Relocation is to the entry for this symbol in the global
3226 if (htab
->elf
.sgot
== NULL
)
3233 off
= h
->got
.offset
;
3234 dyn
= htab
->elf
.dynamic_sections_created
;
3235 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3237 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3238 || (ELF_ST_VISIBILITY (h
->other
)
3239 && h
->root
.type
== bfd_link_hash_undefweak
))
3241 /* This is actually a static link, or it is a
3242 -Bsymbolic link and the symbol is defined
3243 locally, or the symbol was forced to be local
3244 because of a version file. We must initialize
3245 this entry in the global offset table. Since the
3246 offset must always be a multiple of 4, we use the
3247 least significant bit to record whether we have
3248 initialized it already.
3250 When doing a dynamic link, we create a .rel.got
3251 relocation entry to initialize the value. This
3252 is done in the finish_dynamic_symbol routine. */
3257 bfd_put_32 (output_bfd
, relocation
,
3258 htab
->elf
.sgot
->contents
+ off
);
3263 unresolved_reloc
= FALSE
;
3267 if (local_got_offsets
== NULL
)
3270 off
= local_got_offsets
[r_symndx
];
3272 /* The offset must always be a multiple of 4. We use
3273 the least significant bit to record whether we have
3274 already generated the necessary reloc. */
3279 bfd_put_32 (output_bfd
, relocation
,
3280 htab
->elf
.sgot
->contents
+ off
);
3285 Elf_Internal_Rela outrel
;
3288 s
= htab
->elf
.srelgot
;
3292 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3293 + htab
->elf
.sgot
->output_offset
3295 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3297 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3298 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3301 local_got_offsets
[r_symndx
] |= 1;
3305 if (off
>= (bfd_vma
) -2)
3308 relocation
= htab
->elf
.sgot
->output_section
->vma
3309 + htab
->elf
.sgot
->output_offset
+ off
3310 - htab
->elf
.sgotplt
->output_section
->vma
3311 - htab
->elf
.sgotplt
->output_offset
;
3315 /* Relocation is relative to the start of the global offset
3318 /* Check to make sure it isn't a protected function symbol
3319 for shared library since it may not be local when used
3320 as function address. We also need to make sure that a
3321 symbol is defined locally. */
3322 if (info
->shared
&& h
)
3324 if (!h
->def_regular
)
3328 switch (ELF_ST_VISIBILITY (h
->other
))
3331 v
= _("hidden symbol");
3334 v
= _("internal symbol");
3337 v
= _("protected symbol");
3344 (*_bfd_error_handler
)
3345 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3346 input_bfd
, v
, h
->root
.root
.string
);
3347 bfd_set_error (bfd_error_bad_value
);
3350 else if (!info
->executable
3351 && h
->type
== STT_FUNC
3352 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3354 (*_bfd_error_handler
)
3355 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3356 input_bfd
, h
->root
.root
.string
);
3357 bfd_set_error (bfd_error_bad_value
);
3362 /* Note that sgot is not involved in this
3363 calculation. We always want the start of .got.plt. If we
3364 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3365 permitted by the ABI, we might have to change this
3367 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3368 + htab
->elf
.sgotplt
->output_offset
;
3372 /* Use global offset table as symbol value. */
3373 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3374 + htab
->elf
.sgotplt
->output_offset
;
3375 unresolved_reloc
= FALSE
;
3379 /* Relocation is to the entry for this symbol in the
3380 procedure linkage table. */
3382 /* Resolve a PLT32 reloc against a local symbol directly,
3383 without using the procedure linkage table. */
3387 if (h
->plt
.offset
== (bfd_vma
) -1
3388 || htab
->elf
.splt
== NULL
)
3390 /* We didn't make a PLT entry for this symbol. This
3391 happens when statically linking PIC code, or when
3392 using -Bsymbolic. */
3396 relocation
= (htab
->elf
.splt
->output_section
->vma
3397 + htab
->elf
.splt
->output_offset
3399 unresolved_reloc
= FALSE
;
3404 if ((input_section
->flags
& SEC_ALLOC
) == 0
3410 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3411 || h
->root
.type
!= bfd_link_hash_undefweak
)
3412 && (r_type
!= R_386_PC32
3413 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3414 || (ELIMINATE_COPY_RELOCS
3421 || h
->root
.type
== bfd_link_hash_undefweak
3422 || h
->root
.type
== bfd_link_hash_undefined
)))
3424 Elf_Internal_Rela outrel
;
3426 bfd_boolean skip
, relocate
;
3429 /* When generating a shared object, these relocations
3430 are copied into the output file to be resolved at run
3437 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3439 if (outrel
.r_offset
== (bfd_vma
) -1)
3441 else if (outrel
.r_offset
== (bfd_vma
) -2)
3442 skip
= TRUE
, relocate
= TRUE
;
3443 outrel
.r_offset
+= (input_section
->output_section
->vma
3444 + input_section
->output_offset
);
3447 memset (&outrel
, 0, sizeof outrel
);
3450 && (r_type
== R_386_PC32
3452 || !SYMBOLIC_BIND (info
, h
)
3453 || !h
->def_regular
))
3454 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3457 /* This symbol is local, or marked to become local. */
3459 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3462 sreloc
= elf_section_data (input_section
)->sreloc
;
3464 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3466 r
= bfd_reloc_notsupported
;
3467 goto check_relocation_error
;
3470 loc
= sreloc
->contents
;
3471 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3473 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3475 /* If this reloc is against an external symbol, we do
3476 not want to fiddle with the addend. Otherwise, we
3477 need to include the symbol value so that it becomes
3478 an addend for the dynamic reloc. */
3485 if (!info
->executable
)
3487 Elf_Internal_Rela outrel
;
3491 outrel
.r_offset
= rel
->r_offset
3492 + input_section
->output_section
->vma
3493 + input_section
->output_offset
;
3494 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3495 sreloc
= elf_section_data (input_section
)->sreloc
;
3498 loc
= sreloc
->contents
;
3499 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3500 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3505 case R_386_TLS_GOTDESC
:
3506 case R_386_TLS_DESC_CALL
:
3507 case R_386_TLS_IE_32
:
3508 case R_386_TLS_GOTIE
:
3509 tls_type
= GOT_UNKNOWN
;
3510 if (h
== NULL
&& local_got_offsets
)
3511 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3513 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3514 if (tls_type
== GOT_TLS_IE
)
3515 tls_type
= GOT_TLS_IE_NEG
;
3517 if (! elf_i386_tls_transition (info
, input_bfd
,
3518 input_section
, contents
,
3519 symtab_hdr
, sym_hashes
,
3520 &r_type
, tls_type
, rel
,
3521 relend
, h
, r_symndx
))
3524 if (r_type
== R_386_TLS_LE_32
)
3526 BFD_ASSERT (! unresolved_reloc
);
3527 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3532 /* GD->LE transition. */
3533 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3536 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3538 movl %gs:0, %eax; subl $foo@tpoff, %eax
3539 (6 byte form of subl). */
3540 memcpy (contents
+ rel
->r_offset
- 3,
3541 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3542 roff
= rel
->r_offset
+ 5;
3546 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3548 movl %gs:0, %eax; subl $foo@tpoff, %eax
3549 (6 byte form of subl). */
3550 memcpy (contents
+ rel
->r_offset
- 2,
3551 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3552 roff
= rel
->r_offset
+ 6;
3554 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3556 /* Skip R_386_PC32/R_386_PLT32. */
3560 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3562 /* GDesc -> LE transition.
3563 It's originally something like:
3564 leal x@tlsdesc(%ebx), %eax
3568 Registers other than %eax may be set up here. */
3573 roff
= rel
->r_offset
;
3574 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3576 /* Now modify the instruction as appropriate. */
3577 /* aoliva FIXME: remove the above and xor the byte
3579 bfd_put_8 (output_bfd
, val
^ 0x86,
3580 contents
+ roff
- 1);
3581 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3585 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3587 /* GDesc -> LE transition.
3595 roff
= rel
->r_offset
;
3596 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3597 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3600 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3604 /* IE->LE transition:
3605 Originally it can be one of:
3613 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3616 /* movl foo, %eax. */
3617 bfd_put_8 (output_bfd
, 0xb8,
3618 contents
+ rel
->r_offset
- 1);
3624 type
= bfd_get_8 (input_bfd
,
3625 contents
+ rel
->r_offset
- 2);
3630 bfd_put_8 (output_bfd
, 0xc7,
3631 contents
+ rel
->r_offset
- 2);
3632 bfd_put_8 (output_bfd
,
3633 0xc0 | ((val
>> 3) & 7),
3634 contents
+ rel
->r_offset
- 1);
3638 bfd_put_8 (output_bfd
, 0x81,
3639 contents
+ rel
->r_offset
- 2);
3640 bfd_put_8 (output_bfd
,
3641 0xc0 | ((val
>> 3) & 7),
3642 contents
+ rel
->r_offset
- 1);
3649 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3650 contents
+ rel
->r_offset
);
3655 unsigned int val
, type
;
3657 /* {IE_32,GOTIE}->LE transition:
3658 Originally it can be one of:
3659 subl foo(%reg1), %reg2
3660 movl foo(%reg1), %reg2
3661 addl foo(%reg1), %reg2
3664 movl $foo, %reg2 (6 byte form)
3665 addl $foo, %reg2. */
3666 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3667 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3671 bfd_put_8 (output_bfd
, 0xc7,
3672 contents
+ rel
->r_offset
- 2);
3673 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3674 contents
+ rel
->r_offset
- 1);
3676 else if (type
== 0x2b)
3679 bfd_put_8 (output_bfd
, 0x81,
3680 contents
+ rel
->r_offset
- 2);
3681 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3682 contents
+ rel
->r_offset
- 1);
3684 else if (type
== 0x03)
3687 bfd_put_8 (output_bfd
, 0x81,
3688 contents
+ rel
->r_offset
- 2);
3689 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3690 contents
+ rel
->r_offset
- 1);
3694 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3695 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3696 contents
+ rel
->r_offset
);
3698 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3699 contents
+ rel
->r_offset
);
3704 if (htab
->elf
.sgot
== NULL
)
3709 off
= h
->got
.offset
;
3710 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3714 if (local_got_offsets
== NULL
)
3717 off
= local_got_offsets
[r_symndx
];
3718 offplt
= local_tlsdesc_gotents
[r_symndx
];
3725 Elf_Internal_Rela outrel
;
3730 if (htab
->elf
.srelgot
== NULL
)
3733 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3735 if (GOT_TLS_GDESC_P (tls_type
))
3737 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3738 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3739 <= htab
->elf
.sgotplt
->size
);
3740 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3741 + htab
->elf
.sgotplt
->output_offset
3743 + htab
->sgotplt_jump_table_size
);
3744 sreloc
= htab
->elf
.srelplt
;
3745 loc
= sreloc
->contents
;
3746 loc
+= (htab
->next_tls_desc_index
++
3747 * sizeof (Elf32_External_Rel
));
3748 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3749 <= sreloc
->contents
+ sreloc
->size
);
3750 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3753 BFD_ASSERT (! unresolved_reloc
);
3754 bfd_put_32 (output_bfd
,
3755 relocation
- elf_i386_dtpoff_base (info
),
3756 htab
->elf
.sgotplt
->contents
+ offplt
3757 + htab
->sgotplt_jump_table_size
+ 4);
3761 bfd_put_32 (output_bfd
, 0,
3762 htab
->elf
.sgotplt
->contents
+ offplt
3763 + htab
->sgotplt_jump_table_size
+ 4);
3767 sreloc
= htab
->elf
.srelgot
;
3769 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3770 + htab
->elf
.sgot
->output_offset
+ off
);
3772 if (GOT_TLS_GD_P (tls_type
))
3773 dr_type
= R_386_TLS_DTPMOD32
;
3774 else if (GOT_TLS_GDESC_P (tls_type
))
3776 else if (tls_type
== GOT_TLS_IE_POS
)
3777 dr_type
= R_386_TLS_TPOFF
;
3779 dr_type
= R_386_TLS_TPOFF32
;
3781 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3782 bfd_put_32 (output_bfd
,
3783 relocation
- elf_i386_dtpoff_base (info
),
3784 htab
->elf
.sgot
->contents
+ off
);
3785 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3786 bfd_put_32 (output_bfd
,
3787 elf_i386_dtpoff_base (info
) - relocation
,
3788 htab
->elf
.sgot
->contents
+ off
);
3789 else if (dr_type
!= R_386_TLS_DESC
)
3790 bfd_put_32 (output_bfd
, 0,
3791 htab
->elf
.sgot
->contents
+ off
);
3792 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3794 loc
= sreloc
->contents
;
3795 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3796 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3797 <= sreloc
->contents
+ sreloc
->size
);
3798 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3800 if (GOT_TLS_GD_P (tls_type
))
3804 BFD_ASSERT (! unresolved_reloc
);
3805 bfd_put_32 (output_bfd
,
3806 relocation
- elf_i386_dtpoff_base (info
),
3807 htab
->elf
.sgot
->contents
+ off
+ 4);
3811 bfd_put_32 (output_bfd
, 0,
3812 htab
->elf
.sgot
->contents
+ off
+ 4);
3813 outrel
.r_info
= ELF32_R_INFO (indx
,
3814 R_386_TLS_DTPOFF32
);
3815 outrel
.r_offset
+= 4;
3816 sreloc
->reloc_count
++;
3817 loc
+= sizeof (Elf32_External_Rel
);
3818 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3819 <= sreloc
->contents
+ sreloc
->size
);
3820 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3823 else if (tls_type
== GOT_TLS_IE_BOTH
)
3825 bfd_put_32 (output_bfd
,
3827 ? relocation
- elf_i386_dtpoff_base (info
)
3829 htab
->elf
.sgot
->contents
+ off
+ 4);
3830 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3831 outrel
.r_offset
+= 4;
3832 sreloc
->reloc_count
++;
3833 loc
+= sizeof (Elf32_External_Rel
);
3834 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3841 local_got_offsets
[r_symndx
] |= 1;
3844 if (off
>= (bfd_vma
) -2
3845 && ! GOT_TLS_GDESC_P (tls_type
))
3847 if (r_type
== R_386_TLS_GOTDESC
3848 || r_type
== R_386_TLS_DESC_CALL
)
3850 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3851 unresolved_reloc
= FALSE
;
3853 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3855 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3856 + htab
->elf
.sgotplt
->output_offset
;
3857 relocation
= htab
->elf
.sgot
->output_section
->vma
3858 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3859 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3860 && tls_type
== GOT_TLS_IE_BOTH
)
3862 if (r_type
== R_386_TLS_IE
)
3863 relocation
+= g_o_t
;
3864 unresolved_reloc
= FALSE
;
3866 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3868 unsigned int val
, type
;
3871 /* GD->IE transition. */
3872 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3873 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3876 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3878 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3880 roff
= rel
->r_offset
- 3;
3884 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3886 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3887 roff
= rel
->r_offset
- 2;
3889 memcpy (contents
+ roff
,
3890 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3891 contents
[roff
+ 7] = 0x80 | (val
& 7);
3892 /* If foo is used only with foo@gotntpoff(%reg) and
3893 foo@indntpoff, but not with foo@gottpoff(%reg), change
3894 subl $foo@gottpoff(%reg), %eax
3896 addl $foo@gotntpoff(%reg), %eax. */
3897 if (tls_type
== GOT_TLS_IE_POS
)
3898 contents
[roff
+ 6] = 0x03;
3899 bfd_put_32 (output_bfd
,
3900 htab
->elf
.sgot
->output_section
->vma
3901 + htab
->elf
.sgot
->output_offset
+ off
3902 - htab
->elf
.sgotplt
->output_section
->vma
3903 - htab
->elf
.sgotplt
->output_offset
,
3904 contents
+ roff
+ 8);
3905 /* Skip R_386_PLT32. */
3909 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3911 /* GDesc -> IE transition.
3912 It's originally something like:
3913 leal x@tlsdesc(%ebx), %eax
3916 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3918 movl x@gottpoff(%ebx), %eax # before negl %eax
3920 Registers other than %eax may be set up here. */
3924 /* First, make sure it's a leal adding ebx to a 32-bit
3925 offset into any register, although it's probably
3926 almost always going to be eax. */
3927 roff
= rel
->r_offset
;
3929 /* Now modify the instruction as appropriate. */
3930 /* To turn a leal into a movl in the form we use it, it
3931 suffices to change the first byte from 0x8d to 0x8b.
3932 aoliva FIXME: should we decide to keep the leal, all
3933 we have to do is remove the statement below, and
3934 adjust the relaxation of R_386_TLS_DESC_CALL. */
3935 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3937 if (tls_type
== GOT_TLS_IE_BOTH
)
3940 bfd_put_32 (output_bfd
,
3941 htab
->elf
.sgot
->output_section
->vma
3942 + htab
->elf
.sgot
->output_offset
+ off
3943 - htab
->elf
.sgotplt
->output_section
->vma
3944 - htab
->elf
.sgotplt
->output_offset
,
3948 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3950 /* GDesc -> IE transition.
3958 depending on how we transformed the TLS_GOTDESC above.
3963 roff
= rel
->r_offset
;
3965 /* Now modify the instruction as appropriate. */
3966 if (tls_type
!= GOT_TLS_IE_NEG
)
3969 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3970 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3975 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3976 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3986 if (! elf_i386_tls_transition (info
, input_bfd
,
3987 input_section
, contents
,
3988 symtab_hdr
, sym_hashes
,
3989 &r_type
, GOT_UNKNOWN
, rel
,
3990 relend
, h
, r_symndx
))
3993 if (r_type
!= R_386_TLS_LDM
)
3995 /* LD->LE transition:
3996 leal foo(%reg), %eax; call ___tls_get_addr.
3998 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3999 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4000 memcpy (contents
+ rel
->r_offset
- 2,
4001 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4002 /* Skip R_386_PC32/R_386_PLT32. */
4007 if (htab
->elf
.sgot
== NULL
)
4010 off
= htab
->tls_ldm_got
.offset
;
4015 Elf_Internal_Rela outrel
;
4018 if (htab
->elf
.srelgot
== NULL
)
4021 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4022 + htab
->elf
.sgot
->output_offset
+ off
);
4024 bfd_put_32 (output_bfd
, 0,
4025 htab
->elf
.sgot
->contents
+ off
);
4026 bfd_put_32 (output_bfd
, 0,
4027 htab
->elf
.sgot
->contents
+ off
+ 4);
4028 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4029 loc
= htab
->elf
.srelgot
->contents
;
4030 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4031 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4032 htab
->tls_ldm_got
.offset
|= 1;
4034 relocation
= htab
->elf
.sgot
->output_section
->vma
4035 + htab
->elf
.sgot
->output_offset
+ off
4036 - htab
->elf
.sgotplt
->output_section
->vma
4037 - htab
->elf
.sgotplt
->output_offset
;
4038 unresolved_reloc
= FALSE
;
4041 case R_386_TLS_LDO_32
:
4042 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4043 relocation
-= elf_i386_dtpoff_base (info
);
4045 /* When converting LDO to LE, we must negate. */
4046 relocation
= -elf_i386_tpoff (info
, relocation
);
4049 case R_386_TLS_LE_32
:
4051 if (!info
->executable
)
4053 Elf_Internal_Rela outrel
;
4057 outrel
.r_offset
= rel
->r_offset
4058 + input_section
->output_section
->vma
4059 + input_section
->output_offset
;
4060 if (h
!= NULL
&& h
->dynindx
!= -1)
4064 if (r_type
== R_386_TLS_LE_32
)
4065 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4067 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4068 sreloc
= elf_section_data (input_section
)->sreloc
;
4071 loc
= sreloc
->contents
;
4072 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4073 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4076 else if (r_type
== R_386_TLS_LE_32
)
4077 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4079 relocation
-= elf_i386_dtpoff_base (info
);
4081 else if (r_type
== R_386_TLS_LE_32
)
4082 relocation
= elf_i386_tpoff (info
, relocation
);
4084 relocation
= -elf_i386_tpoff (info
, relocation
);
4091 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4092 because such sections are not SEC_ALLOC and thus ld.so will
4093 not process them. */
4094 if (unresolved_reloc
4095 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4098 (*_bfd_error_handler
)
4099 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4102 (long) rel
->r_offset
,
4104 h
->root
.root
.string
);
4109 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4110 contents
, rel
->r_offset
,
4113 check_relocation_error
:
4114 if (r
!= bfd_reloc_ok
)
4119 name
= h
->root
.root
.string
;
4122 name
= bfd_elf_string_from_elf_section (input_bfd
,
4123 symtab_hdr
->sh_link
,
4128 name
= bfd_section_name (input_bfd
, sec
);
4131 if (r
== bfd_reloc_overflow
)
4133 if (! ((*info
->callbacks
->reloc_overflow
)
4134 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4135 (bfd_vma
) 0, input_bfd
, input_section
,
4141 (*_bfd_error_handler
)
4142 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4143 input_bfd
, input_section
,
4144 (long) rel
->r_offset
, name
, (int) r
);
4153 /* Finish up dynamic symbol handling. We set the contents of various
4154 dynamic sections here. */
4157 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4158 struct bfd_link_info
*info
,
4159 struct elf_link_hash_entry
*h
,
4160 Elf_Internal_Sym
*sym
)
4162 struct elf_i386_link_hash_table
*htab
;
4164 htab
= elf_i386_hash_table (info
);
4168 if (h
->plt
.offset
!= (bfd_vma
) -1)
4172 Elf_Internal_Rela rel
;
4174 asection
*plt
, *gotplt
, *relplt
;
4176 /* When building a static executable, use .iplt, .igot.plt and
4177 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4178 if (htab
->elf
.splt
!= NULL
)
4180 plt
= htab
->elf
.splt
;
4181 gotplt
= htab
->elf
.sgotplt
;
4182 relplt
= htab
->elf
.srelplt
;
4186 plt
= htab
->elf
.iplt
;
4187 gotplt
= htab
->elf
.igotplt
;
4188 relplt
= htab
->elf
.irelplt
;
4191 /* This symbol has an entry in the procedure linkage table. Set
4194 if ((h
->dynindx
== -1
4195 && !((h
->forced_local
|| info
->executable
)
4197 && h
->type
== STT_GNU_IFUNC
))
4203 /* Get the index in the procedure linkage table which
4204 corresponds to this symbol. This is the index of this symbol
4205 in all the symbols for which we are making plt entries. The
4206 first entry in the procedure linkage table is reserved.
4208 Get the offset into the .got table of the entry that
4209 corresponds to this function. Each .got entry is 4 bytes.
4210 The first three are reserved.
4212 For static executables, we don't reserve anything. */
4214 if (plt
== htab
->elf
.splt
)
4216 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
4217 got_offset
= (plt_index
+ 3) * 4;
4221 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4222 got_offset
= plt_index
* 4;
4225 /* Fill in the entry in the procedure linkage table. */
4228 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
4230 bfd_put_32 (output_bfd
,
4231 (gotplt
->output_section
->vma
4232 + gotplt
->output_offset
4234 plt
->contents
+ h
->plt
.offset
+ 2);
4236 if (htab
->is_vxworks
)
4238 int s
, k
, reloc_index
;
4240 /* Create the R_386_32 relocation referencing the GOT
4241 for this PLT entry. */
4243 /* S: Current slot number (zero-based). */
4244 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
4245 /* K: Number of relocations for PLTResolve. */
4247 k
= PLTRESOLVE_RELOCS_SHLIB
;
4249 k
= PLTRESOLVE_RELOCS
;
4250 /* Skip the PLTresolve relocations, and the relocations for
4251 the other PLT slots. */
4252 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4253 loc
= (htab
->srelplt2
->contents
+ reloc_index
4254 * sizeof (Elf32_External_Rel
));
4256 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4257 + htab
->elf
.splt
->output_offset
4258 + h
->plt
.offset
+ 2),
4259 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4260 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4262 /* Create the R_386_32 relocation referencing the beginning of
4263 the PLT for this GOT entry. */
4264 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4265 + htab
->elf
.sgotplt
->output_offset
4267 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4268 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4269 loc
+ sizeof (Elf32_External_Rel
));
4274 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
4276 bfd_put_32 (output_bfd
, got_offset
,
4277 plt
->contents
+ h
->plt
.offset
+ 2);
4280 /* Don't fill PLT entry for static executables. */
4281 if (plt
== htab
->elf
.splt
)
4283 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4284 plt
->contents
+ h
->plt
.offset
+ 7);
4285 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4286 plt
->contents
+ h
->plt
.offset
+ 12);
4289 /* Fill in the entry in the global offset table. */
4290 bfd_put_32 (output_bfd
,
4291 (plt
->output_section
->vma
4292 + plt
->output_offset
4295 gotplt
->contents
+ got_offset
);
4297 /* Fill in the entry in the .rel.plt section. */
4298 rel
.r_offset
= (gotplt
->output_section
->vma
4299 + gotplt
->output_offset
4301 if (h
->dynindx
== -1
4302 || ((info
->executable
4303 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4305 && h
->type
== STT_GNU_IFUNC
))
4307 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4308 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4309 in the .got.plt section. */
4310 bfd_put_32 (output_bfd
,
4311 (h
->root
.u
.def
.value
4312 + h
->root
.u
.def
.section
->output_section
->vma
4313 + h
->root
.u
.def
.section
->output_offset
),
4314 gotplt
->contents
+ got_offset
);
4315 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4318 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4319 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4320 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4322 if (!h
->def_regular
)
4324 /* Mark the symbol as undefined, rather than as defined in
4325 the .plt section. Leave the value if there were any
4326 relocations where pointer equality matters (this is a clue
4327 for the dynamic linker, to make function pointer
4328 comparisons work between an application and shared
4329 library), otherwise set it to zero. If a function is only
4330 called from a binary, there is no need to slow down
4331 shared libraries because of that. */
4332 sym
->st_shndx
= SHN_UNDEF
;
4333 if (!h
->pointer_equality_needed
)
4338 if (h
->got
.offset
!= (bfd_vma
) -1
4339 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4340 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4342 Elf_Internal_Rela rel
;
4345 /* This symbol has an entry in the global offset table. Set it
4348 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4351 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4352 + htab
->elf
.sgot
->output_offset
4353 + (h
->got
.offset
& ~(bfd_vma
) 1));
4355 /* If this is a static link, or it is a -Bsymbolic link and the
4356 symbol is defined locally or was forced to be local because
4357 of a version file, we just want to emit a RELATIVE reloc.
4358 The entry in the global offset table will already have been
4359 initialized in the relocate_section function. */
4361 && h
->type
== STT_GNU_IFUNC
)
4365 /* Generate R_386_GLOB_DAT. */
4372 if (!h
->pointer_equality_needed
)
4375 /* For non-shared object, we can't use .got.plt, which
4376 contains the real function addres if we need pointer
4377 equality. We load the GOT entry with the PLT entry. */
4378 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4379 bfd_put_32 (output_bfd
,
4380 (plt
->output_section
->vma
4381 + plt
->output_offset
+ h
->plt
.offset
),
4382 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4386 else if (info
->shared
4387 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4389 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4390 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4394 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4396 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4397 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4398 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4401 loc
= htab
->elf
.srelgot
->contents
;
4402 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4403 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4408 Elf_Internal_Rela rel
;
4411 /* This symbol needs a copy reloc. Set it up. */
4413 if (h
->dynindx
== -1
4414 || (h
->root
.type
!= bfd_link_hash_defined
4415 && h
->root
.type
!= bfd_link_hash_defweak
)
4416 || htab
->srelbss
== NULL
)
4419 rel
.r_offset
= (h
->root
.u
.def
.value
4420 + h
->root
.u
.def
.section
->output_section
->vma
4421 + h
->root
.u
.def
.section
->output_offset
);
4422 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4423 loc
= htab
->srelbss
->contents
;
4424 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4425 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4428 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4429 be NULL for local symbols.
4431 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
4432 is relative to the ".got" section. */
4434 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4435 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
)))
4436 sym
->st_shndx
= SHN_ABS
;
4441 /* Finish up local dynamic symbol handling. We set the contents of
4442 various dynamic sections here. */
4445 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4447 struct elf_link_hash_entry
*h
4448 = (struct elf_link_hash_entry
*) *slot
;
4449 struct bfd_link_info
*info
4450 = (struct bfd_link_info
*) inf
;
4452 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4456 /* Used to decide how to sort relocs in an optimal manner for the
4457 dynamic linker, before writing them out. */
4459 static enum elf_reloc_type_class
4460 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4462 switch (ELF32_R_TYPE (rela
->r_info
))
4464 case R_386_RELATIVE
:
4465 return reloc_class_relative
;
4466 case R_386_JUMP_SLOT
:
4467 return reloc_class_plt
;
4469 return reloc_class_copy
;
4471 return reloc_class_normal
;
4475 /* Finish up the dynamic sections. */
4478 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4479 struct bfd_link_info
*info
)
4481 struct elf_i386_link_hash_table
*htab
;
4485 htab
= elf_i386_hash_table (info
);
4489 dynobj
= htab
->elf
.dynobj
;
4490 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4492 if (htab
->elf
.dynamic_sections_created
)
4494 Elf32_External_Dyn
*dyncon
, *dynconend
;
4496 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4499 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4500 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4501 for (; dyncon
< dynconend
; dyncon
++)
4503 Elf_Internal_Dyn dyn
;
4506 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4511 if (htab
->is_vxworks
4512 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4517 s
= htab
->elf
.sgotplt
;
4518 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4522 s
= htab
->elf
.srelplt
;
4523 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4527 s
= htab
->elf
.srelplt
;
4528 dyn
.d_un
.d_val
= s
->size
;
4532 /* My reading of the SVR4 ABI indicates that the
4533 procedure linkage table relocs (DT_JMPREL) should be
4534 included in the overall relocs (DT_REL). This is
4535 what Solaris does. However, UnixWare can not handle
4536 that case. Therefore, we override the DT_RELSZ entry
4537 here to make it not include the JMPREL relocs. */
4538 s
= htab
->elf
.srelplt
;
4541 dyn
.d_un
.d_val
-= s
->size
;
4545 /* We may not be using the standard ELF linker script.
4546 If .rel.plt is the first .rel section, we adjust
4547 DT_REL to not include it. */
4548 s
= htab
->elf
.srelplt
;
4551 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4553 dyn
.d_un
.d_ptr
+= s
->size
;
4557 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4560 /* Fill in the first entry in the procedure linkage table. */
4561 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4565 memcpy (htab
->elf
.splt
->contents
, elf_i386_pic_plt0_entry
,
4566 sizeof (elf_i386_pic_plt0_entry
));
4567 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
4568 htab
->plt0_pad_byte
,
4569 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
4573 memcpy (htab
->elf
.splt
->contents
, elf_i386_plt0_entry
,
4574 sizeof(elf_i386_plt0_entry
));
4575 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_plt0_entry
),
4576 htab
->plt0_pad_byte
,
4577 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
4578 bfd_put_32 (output_bfd
,
4579 (htab
->elf
.sgotplt
->output_section
->vma
4580 + htab
->elf
.sgotplt
->output_offset
4582 htab
->elf
.splt
->contents
+ 2);
4583 bfd_put_32 (output_bfd
,
4584 (htab
->elf
.sgotplt
->output_section
->vma
4585 + htab
->elf
.sgotplt
->output_offset
4587 htab
->elf
.splt
->contents
+ 8);
4589 if (htab
->is_vxworks
)
4591 Elf_Internal_Rela rel
;
4593 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4594 On IA32 we use REL relocations so the addend goes in
4595 the PLT directly. */
4596 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4597 + htab
->elf
.splt
->output_offset
4599 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4600 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4601 htab
->srelplt2
->contents
);
4602 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4603 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4604 + htab
->elf
.splt
->output_offset
4606 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4607 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4608 htab
->srelplt2
->contents
+
4609 sizeof (Elf32_External_Rel
));
4613 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4614 really seem like the right value. */
4615 elf_section_data (htab
->elf
.splt
->output_section
)
4616 ->this_hdr
.sh_entsize
= 4;
4618 /* Correct the .rel.plt.unloaded relocations. */
4619 if (htab
->is_vxworks
&& !info
->shared
)
4621 int num_plts
= (htab
->elf
.splt
->size
/ PLT_ENTRY_SIZE
) - 1;
4624 p
= htab
->srelplt2
->contents
;
4626 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4628 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4630 for (; num_plts
; num_plts
--)
4632 Elf_Internal_Rela rel
;
4633 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4634 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4635 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4636 p
+= sizeof (Elf32_External_Rel
);
4638 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4639 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4640 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4641 p
+= sizeof (Elf32_External_Rel
);
4647 if (htab
->elf
.sgotplt
)
4649 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4651 (*_bfd_error_handler
)
4652 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4656 /* Fill in the first three entries in the global offset table. */
4657 if (htab
->elf
.sgotplt
->size
> 0)
4659 bfd_put_32 (output_bfd
,
4661 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4662 htab
->elf
.sgotplt
->contents
);
4663 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4664 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4667 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4670 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4671 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4673 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4674 htab_traverse (htab
->loc_hash_table
,
4675 elf_i386_finish_local_dynamic_symbol
,
4681 /* Return address for Ith PLT stub in section PLT, for relocation REL
4682 or (bfd_vma) -1 if it should not be included. */
4685 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4686 const arelent
*rel ATTRIBUTE_UNUSED
)
4688 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4691 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4694 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4696 if (h
->plt
.offset
!= (bfd_vma
) -1
4698 && !h
->pointer_equality_needed
)
4701 return _bfd_elf_hash_symbol (h
);
4704 /* Hook called by the linker routine which adds symbols from an object
4708 elf_i386_add_symbol_hook (bfd
* abfd
,
4709 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4710 Elf_Internal_Sym
* sym
,
4711 const char ** namep ATTRIBUTE_UNUSED
,
4712 flagword
* flagsp ATTRIBUTE_UNUSED
,
4713 asection
** secp ATTRIBUTE_UNUSED
,
4714 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4716 if ((abfd
->flags
& DYNAMIC
) == 0
4717 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4718 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4719 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4724 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4725 #define TARGET_LITTLE_NAME "elf32-i386"
4726 #define ELF_ARCH bfd_arch_i386
4727 #define ELF_TARGET_ID I386_ELF_DATA
4728 #define ELF_MACHINE_CODE EM_386
4729 #define ELF_MAXPAGESIZE 0x1000
4731 #define elf_backend_can_gc_sections 1
4732 #define elf_backend_can_refcount 1
4733 #define elf_backend_want_got_plt 1
4734 #define elf_backend_plt_readonly 1
4735 #define elf_backend_want_plt_sym 0
4736 #define elf_backend_got_header_size 12
4738 /* Support RELA for objdump of prelink objects. */
4739 #define elf_info_to_howto elf_i386_info_to_howto_rel
4740 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4742 #define bfd_elf32_mkobject elf_i386_mkobject
4744 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4745 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4746 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4747 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4748 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4750 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4751 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4752 #define elf_backend_check_relocs elf_i386_check_relocs
4753 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4754 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4755 #define elf_backend_fake_sections elf_i386_fake_sections
4756 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4757 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4758 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4759 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4760 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4761 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4762 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4763 #define elf_backend_relocate_section elf_i386_relocate_section
4764 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4765 #define elf_backend_always_size_sections elf_i386_always_size_sections
4766 #define elf_backend_omit_section_dynsym \
4767 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4768 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4769 #define elf_backend_hash_symbol elf_i386_hash_symbol
4770 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4771 #undef elf_backend_post_process_headers
4772 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4774 #include "elf32-target.h"
4776 /* FreeBSD support. */
4778 #undef TARGET_LITTLE_SYM
4779 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4780 #undef TARGET_LITTLE_NAME
4781 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4783 #define ELF_OSABI ELFOSABI_FREEBSD
4785 /* The kernel recognizes executables as valid only if they carry a
4786 "FreeBSD" label in the ELF header. So we put this label on all
4787 executables and (for simplicity) also all other object files. */
4790 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4792 _bfd_elf_set_osabi (abfd
, info
);
4794 #ifdef OLD_FREEBSD_ABI_LABEL
4795 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4796 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4800 #undef elf_backend_post_process_headers
4801 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4803 #define elf32_bed elf32_i386_fbsd_bed
4805 #undef elf_backend_add_symbol_hook
4807 #include "elf32-target.h"
4811 #undef TARGET_LITTLE_SYM
4812 #define TARGET_LITTLE_SYM bfd_elf32_i386_sol2_vec
4813 #undef TARGET_LITTLE_NAME
4814 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
4816 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4817 objects won't be recognized. */
4821 #define elf32_bed elf32_i386_sol2_bed
4823 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
4825 #undef elf_backend_static_tls_alignment
4826 #define elf_backend_static_tls_alignment 8
4828 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4830 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4832 #undef elf_backend_want_plt_sym
4833 #define elf_backend_want_plt_sym 1
4835 #include "elf32-target.h"
4837 /* VxWorks support. */
4839 #undef TARGET_LITTLE_SYM
4840 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
4841 #undef TARGET_LITTLE_NAME
4842 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4845 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
4847 static struct bfd_link_hash_table
*
4848 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
4850 struct bfd_link_hash_table
*ret
;
4851 struct elf_i386_link_hash_table
*htab
;
4853 ret
= elf_i386_link_hash_table_create (abfd
);
4856 htab
= (struct elf_i386_link_hash_table
*) ret
;
4857 htab
->is_vxworks
= 1;
4858 htab
->plt0_pad_byte
= 0x90;
4865 #undef elf_backend_relocs_compatible
4866 #undef elf_backend_post_process_headers
4867 #undef bfd_elf32_bfd_link_hash_table_create
4868 #define bfd_elf32_bfd_link_hash_table_create \
4869 elf_i386_vxworks_link_hash_table_create
4870 #undef elf_backend_add_symbol_hook
4871 #define elf_backend_add_symbol_hook \
4872 elf_vxworks_add_symbol_hook
4873 #undef elf_backend_link_output_symbol_hook
4874 #define elf_backend_link_output_symbol_hook \
4875 elf_vxworks_link_output_symbol_hook
4876 #undef elf_backend_emit_relocs
4877 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
4878 #undef elf_backend_final_write_processing
4879 #define elf_backend_final_write_processing \
4880 elf_vxworks_final_write_processing
4881 #undef elf_backend_static_tls_alignment
4883 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
4885 #undef elf_backend_want_plt_sym
4886 #define elf_backend_want_plt_sym 1
4889 #define elf32_bed elf32_i386_vxworks_bed
4891 #include "elf32-target.h"