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 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
28 #include "bfd_stdint.h"
32 /* 386 uses REL relocations instead of RELA. */
37 static reloc_howto_type elf_howto_table
[]=
39 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
40 bfd_elf_generic_reloc
, "R_386_NONE",
41 TRUE
, 0x00000000, 0x00000000, FALSE
),
42 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
43 bfd_elf_generic_reloc
, "R_386_32",
44 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
45 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
46 bfd_elf_generic_reloc
, "R_386_PC32",
47 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
48 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
49 bfd_elf_generic_reloc
, "R_386_GOT32",
50 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
51 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
52 bfd_elf_generic_reloc
, "R_386_PLT32",
53 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
54 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
55 bfd_elf_generic_reloc
, "R_386_COPY",
56 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
57 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
58 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
59 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
60 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
61 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
62 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
63 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_386_RELATIVE",
65 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
66 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_386_GOTOFF",
68 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
69 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
70 bfd_elf_generic_reloc
, "R_386_GOTPC",
71 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
73 /* We have a gap in the reloc numbers here.
74 R_386_standard counts the number up to this point, and
75 R_386_ext_offset is the value to subtract from a reloc type of
76 R_386_16 thru R_386_PC8 to form an index into this table. */
77 #define R_386_standard (R_386_GOTPC + 1)
78 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
80 /* These relocs are a GNU extension. */
81 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
82 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
83 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
84 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_386_TLS_IE",
86 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
87 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
89 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
90 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
91 bfd_elf_generic_reloc
, "R_386_TLS_LE",
92 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
93 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
94 bfd_elf_generic_reloc
, "R_386_TLS_GD",
95 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
96 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
98 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
99 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
100 bfd_elf_generic_reloc
, "R_386_16",
101 TRUE
, 0xffff, 0xffff, FALSE
),
102 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_386_PC16",
104 TRUE
, 0xffff, 0xffff, TRUE
),
105 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_386_8",
107 TRUE
, 0xff, 0xff, FALSE
),
108 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
109 bfd_elf_generic_reloc
, "R_386_PC8",
110 TRUE
, 0xff, 0xff, TRUE
),
112 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
113 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
114 /* These are common with Solaris TLS implementation. */
115 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
116 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
117 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
118 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
119 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
120 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
121 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
122 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
123 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
124 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
125 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
126 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
127 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
129 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
130 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
131 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
132 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
135 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
136 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
137 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
138 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
140 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
141 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
142 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
143 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
148 #define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
149 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
151 /* GNU extension to record C++ vtable hierarchy. */
152 HOWTO (R_386_GNU_VTINHERIT
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_dont
, /* complain_on_overflow */
159 NULL
, /* special_function */
160 "R_386_GNU_VTINHERIT", /* name */
161 FALSE
, /* partial_inplace */
164 FALSE
), /* pcrel_offset */
166 /* GNU extension to record C++ vtable member usage. */
167 HOWTO (R_386_GNU_VTENTRY
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE
, /* pc_relative */
173 complain_overflow_dont
, /* complain_on_overflow */
174 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
175 "R_386_GNU_VTENTRY", /* name */
176 FALSE
, /* partial_inplace */
179 FALSE
) /* pcrel_offset */
181 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
185 #ifdef DEBUG_GEN_RELOC
187 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
192 static reloc_howto_type
*
193 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
194 bfd_reloc_code_real_type code
)
199 TRACE ("BFD_RELOC_NONE");
200 return &elf_howto_table
[R_386_NONE
];
203 TRACE ("BFD_RELOC_32");
204 return &elf_howto_table
[R_386_32
];
207 TRACE ("BFD_RELOC_CTOR");
208 return &elf_howto_table
[R_386_32
];
210 case BFD_RELOC_32_PCREL
:
211 TRACE ("BFD_RELOC_PC32");
212 return &elf_howto_table
[R_386_PC32
];
214 case BFD_RELOC_386_GOT32
:
215 TRACE ("BFD_RELOC_386_GOT32");
216 return &elf_howto_table
[R_386_GOT32
];
218 case BFD_RELOC_386_PLT32
:
219 TRACE ("BFD_RELOC_386_PLT32");
220 return &elf_howto_table
[R_386_PLT32
];
222 case BFD_RELOC_386_COPY
:
223 TRACE ("BFD_RELOC_386_COPY");
224 return &elf_howto_table
[R_386_COPY
];
226 case BFD_RELOC_386_GLOB_DAT
:
227 TRACE ("BFD_RELOC_386_GLOB_DAT");
228 return &elf_howto_table
[R_386_GLOB_DAT
];
230 case BFD_RELOC_386_JUMP_SLOT
:
231 TRACE ("BFD_RELOC_386_JUMP_SLOT");
232 return &elf_howto_table
[R_386_JUMP_SLOT
];
234 case BFD_RELOC_386_RELATIVE
:
235 TRACE ("BFD_RELOC_386_RELATIVE");
236 return &elf_howto_table
[R_386_RELATIVE
];
238 case BFD_RELOC_386_GOTOFF
:
239 TRACE ("BFD_RELOC_386_GOTOFF");
240 return &elf_howto_table
[R_386_GOTOFF
];
242 case BFD_RELOC_386_GOTPC
:
243 TRACE ("BFD_RELOC_386_GOTPC");
244 return &elf_howto_table
[R_386_GOTPC
];
246 /* These relocs are a GNU extension. */
247 case BFD_RELOC_386_TLS_TPOFF
:
248 TRACE ("BFD_RELOC_386_TLS_TPOFF");
249 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
251 case BFD_RELOC_386_TLS_IE
:
252 TRACE ("BFD_RELOC_386_TLS_IE");
253 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
255 case BFD_RELOC_386_TLS_GOTIE
:
256 TRACE ("BFD_RELOC_386_TLS_GOTIE");
257 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
259 case BFD_RELOC_386_TLS_LE
:
260 TRACE ("BFD_RELOC_386_TLS_LE");
261 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
263 case BFD_RELOC_386_TLS_GD
:
264 TRACE ("BFD_RELOC_386_TLS_GD");
265 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
267 case BFD_RELOC_386_TLS_LDM
:
268 TRACE ("BFD_RELOC_386_TLS_LDM");
269 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
272 TRACE ("BFD_RELOC_16");
273 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
275 case BFD_RELOC_16_PCREL
:
276 TRACE ("BFD_RELOC_16_PCREL");
277 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
280 TRACE ("BFD_RELOC_8");
281 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
283 case BFD_RELOC_8_PCREL
:
284 TRACE ("BFD_RELOC_8_PCREL");
285 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
287 /* Common with Sun TLS implementation. */
288 case BFD_RELOC_386_TLS_LDO_32
:
289 TRACE ("BFD_RELOC_386_TLS_LDO_32");
290 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
292 case BFD_RELOC_386_TLS_IE_32
:
293 TRACE ("BFD_RELOC_386_TLS_IE_32");
294 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
296 case BFD_RELOC_386_TLS_LE_32
:
297 TRACE ("BFD_RELOC_386_TLS_LE_32");
298 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
300 case BFD_RELOC_386_TLS_DTPMOD32
:
301 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
302 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
304 case BFD_RELOC_386_TLS_DTPOFF32
:
305 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
306 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
308 case BFD_RELOC_386_TLS_TPOFF32
:
309 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
310 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
312 case BFD_RELOC_386_TLS_GOTDESC
:
313 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
314 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
316 case BFD_RELOC_386_TLS_DESC_CALL
:
317 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
318 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
320 case BFD_RELOC_386_TLS_DESC
:
321 TRACE ("BFD_RELOC_386_TLS_DESC");
322 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
324 case BFD_RELOC_386_IRELATIVE
:
325 TRACE ("BFD_RELOC_386_IRELATIVE");
326 return &elf_howto_table
[R_386_IRELATIVE
];
328 case BFD_RELOC_VTABLE_INHERIT
:
329 TRACE ("BFD_RELOC_VTABLE_INHERIT");
330 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
332 case BFD_RELOC_VTABLE_ENTRY
:
333 TRACE ("BFD_RELOC_VTABLE_ENTRY");
334 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
344 static reloc_howto_type
*
345 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
350 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
351 if (elf_howto_table
[i
].name
!= NULL
352 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
353 return &elf_howto_table
[i
];
358 static reloc_howto_type
*
359 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
363 if ((indx
= r_type
) >= R_386_standard
364 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
365 >= R_386_ext
- R_386_standard
)
366 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
367 >= R_386_irelative
- R_386_ext
)
368 && ((indx
= r_type
- R_386_vt_offset
) - R_386_irelative
369 >= R_386_vt
- R_386_irelative
))
371 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
375 BFD_ASSERT (elf_howto_table
[indx
].type
== r_type
);
376 return &elf_howto_table
[indx
];
380 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
382 Elf_Internal_Rela
*dst
)
384 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
385 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
388 /* Return whether a symbol name implies a local label. The UnixWare
389 2.1 cc generates temporary symbols that start with .X, so we
390 recognize them here. FIXME: do other SVR4 compilers also use .X?.
391 If so, we should move the .X recognition into
392 _bfd_elf_is_local_label_name. */
395 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
397 if (name
[0] == '.' && name
[1] == 'X')
400 return _bfd_elf_is_local_label_name (abfd
, name
);
403 /* Support for core dump NOTE sections. */
406 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
411 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
413 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
419 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
422 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
426 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
430 switch (note
->descsz
)
435 case 144: /* Linux/i386 */
437 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
440 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
450 /* Make a ".reg/999" section. */
451 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
452 size
, note
->descpos
+ offset
);
456 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
458 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
460 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
465 elf_tdata (abfd
)->core_program
466 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
467 elf_tdata (abfd
)->core_command
468 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
472 switch (note
->descsz
)
477 case 124: /* Linux/i386 elf_prpsinfo. */
478 elf_tdata (abfd
)->core_program
479 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
480 elf_tdata (abfd
)->core_command
481 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
485 /* Note that for some reason, a spurious space is tacked
486 onto the end of the args in some (at least one anyway)
487 implementations, so strip it off if it exists. */
489 char *command
= elf_tdata (abfd
)->core_command
;
490 int n
= strlen (command
);
492 if (0 < n
&& command
[n
- 1] == ' ')
493 command
[n
- 1] = '\0';
499 /* Functions for the i386 ELF linker.
501 In order to gain some understanding of code in this file without
502 knowing all the intricate details of the linker, note the
505 Functions named elf_i386_* are called by external routines, other
506 functions are only called locally. elf_i386_* functions appear
507 in this file more or less in the order in which they are called
508 from external routines. eg. elf_i386_check_relocs is called
509 early in the link process, elf_i386_finish_dynamic_sections is
510 one of the last functions. */
513 /* The name of the dynamic interpreter. This is put in the .interp
516 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
518 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
519 copying dynamic variables from a shared lib into an app's dynbss
520 section, and instead use a dynamic relocation to point into the
522 #define ELIMINATE_COPY_RELOCS 1
524 /* The size in bytes of an entry in the procedure linkage table. */
526 #define PLT_ENTRY_SIZE 16
528 /* The first entry in an absolute procedure linkage table looks like
529 this. See the SVR4 ABI i386 supplement to see how this works.
530 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
532 static const bfd_byte elf_i386_plt0_entry
[12] =
534 0xff, 0x35, /* pushl contents of address */
535 0, 0, 0, 0, /* replaced with address of .got + 4. */
536 0xff, 0x25, /* jmp indirect */
537 0, 0, 0, 0 /* replaced with address of .got + 8. */
540 /* Subsequent entries in an absolute procedure linkage table look like
543 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
545 0xff, 0x25, /* jmp indirect */
546 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
547 0x68, /* pushl immediate */
548 0, 0, 0, 0, /* replaced with offset into relocation table. */
549 0xe9, /* jmp relative */
550 0, 0, 0, 0 /* replaced with offset to start of .plt. */
553 /* The first entry in a PIC procedure linkage table look like this.
554 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
556 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
558 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
559 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
562 /* Subsequent entries in a PIC procedure linkage table look like this. */
564 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
566 0xff, 0xa3, /* jmp *offset(%ebx) */
567 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
568 0x68, /* pushl immediate */
569 0, 0, 0, 0, /* replaced with offset into relocation table. */
570 0xe9, /* jmp relative */
571 0, 0, 0, 0 /* replaced with offset to start of .plt. */
574 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
575 for the PLTResolve stub and then for each PLT entry. */
576 #define PLTRESOLVE_RELOCS_SHLIB 0
577 #define PLTRESOLVE_RELOCS 2
578 #define PLT_NON_JUMP_SLOT_RELOCS 2
580 /* The i386 linker needs to keep track of the number of relocs that it
581 decides to copy as dynamic relocs in check_relocs for each symbol.
582 This is so that it can later discard them if they are found to be
583 unnecessary. We store the information in a field extending the
584 regular ELF linker hash table. */
586 struct elf_i386_dyn_relocs
588 struct elf_i386_dyn_relocs
*next
;
590 /* The input section of the reloc. */
593 /* Total number of relocs copied for the input section. */
596 /* Number of pc-relative relocs copied for the input section. */
597 bfd_size_type pc_count
;
600 /* i386 ELF linker hash entry. */
602 struct elf_i386_link_hash_entry
604 struct elf_link_hash_entry elf
;
606 /* Track dynamic relocs copied for this symbol. */
607 struct elf_i386_dyn_relocs
*dyn_relocs
;
609 #define GOT_UNKNOWN 0
613 #define GOT_TLS_IE_POS 5
614 #define GOT_TLS_IE_NEG 6
615 #define GOT_TLS_IE_BOTH 7
616 #define GOT_TLS_GDESC 8
617 #define GOT_TLS_GD_BOTH_P(type) \
618 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
619 #define GOT_TLS_GD_P(type) \
620 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
621 #define GOT_TLS_GDESC_P(type) \
622 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
623 #define GOT_TLS_GD_ANY_P(type) \
624 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
625 unsigned char tls_type
;
627 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
628 starting at the end of the jump table. */
632 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
634 struct elf_i386_obj_tdata
636 struct elf_obj_tdata root
;
638 /* tls_type for each local got entry. */
639 char *local_got_tls_type
;
641 /* GOTPLT entries for TLS descriptors. */
642 bfd_vma
*local_tlsdesc_gotent
;
645 #define elf_i386_tdata(abfd) \
646 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
648 #define elf_i386_local_got_tls_type(abfd) \
649 (elf_i386_tdata (abfd)->local_got_tls_type)
651 #define elf_i386_local_tlsdesc_gotent(abfd) \
652 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
654 #define is_i386_elf(bfd) \
655 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
656 && elf_tdata (bfd) != NULL \
657 && elf_object_id (bfd) == I386_ELF_TDATA)
660 elf_i386_mkobject (bfd
*abfd
)
662 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
666 /* i386 ELF linker hash table. */
668 struct elf_i386_link_hash_table
670 struct elf_link_hash_table elf
;
672 /* Short-cuts to get to dynamic linker sections. */
676 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
679 /* True if the target system is VxWorks. */
682 /* Value used to fill the last word of the first plt entry. */
683 bfd_byte plt0_pad_byte
;
685 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
686 bfd_vma next_tls_desc_index
;
689 bfd_signed_vma refcount
;
693 /* The amount of space used by the reserved portion of the sgotplt
694 section, plus whatever space is used by the jump slots. */
695 bfd_vma sgotplt_jump_table_size
;
697 /* Small local sym to section mapping cache. */
698 struct sym_sec_cache sym_sec
;
700 /* _TLS_MODULE_BASE_ symbol. */
701 struct bfd_link_hash_entry
*tls_module_base
;
703 /* Used by local STT_GNU_IFUNC symbols. */
704 htab_t loc_hash_table
;
705 void *loc_hash_memory
;
708 /* Get the i386 ELF linker hash table from a link_info structure. */
710 #define elf_i386_hash_table(p) \
711 ((struct elf_i386_link_hash_table *) ((p)->hash))
713 #define elf_i386_compute_jump_table_size(htab) \
714 ((htab)->next_tls_desc_index * 4)
716 /* Create an entry in an i386 ELF linker hash table. */
718 static struct bfd_hash_entry
*
719 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
720 struct bfd_hash_table
*table
,
723 /* Allocate the structure if it has not already been allocated by a
727 entry
= bfd_hash_allocate (table
,
728 sizeof (struct elf_i386_link_hash_entry
));
733 /* Call the allocation method of the superclass. */
734 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
737 struct elf_i386_link_hash_entry
*eh
;
739 eh
= (struct elf_i386_link_hash_entry
*) entry
;
740 eh
->dyn_relocs
= NULL
;
741 eh
->tls_type
= GOT_UNKNOWN
;
742 eh
->tlsdesc_got
= (bfd_vma
) -1;
748 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
749 for local symbol so that we can handle local STT_GNU_IFUNC symbols
750 as global symbol. We reuse indx and dynstr_index for local symbol
751 hash since they aren't used by global symbols in this backend. */
754 elf_i386_local_htab_hash (const void *ptr
)
756 struct elf_link_hash_entry
*h
757 = (struct elf_link_hash_entry
*) ptr
;
758 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
761 /* Compare local hash entries. */
764 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
766 struct elf_link_hash_entry
*h1
767 = (struct elf_link_hash_entry
*) ptr1
;
768 struct elf_link_hash_entry
*h2
769 = (struct elf_link_hash_entry
*) ptr2
;
771 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
774 /* Find and/or create a hash entry for local symbol. */
776 static struct elf_link_hash_entry
*
777 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
778 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
781 struct elf_i386_link_hash_entry e
, *ret
;
782 asection
*sec
= abfd
->sections
;
783 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
784 ELF32_R_SYM (rel
->r_info
));
787 e
.elf
.indx
= sec
->id
;
788 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
789 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
790 create
? INSERT
: NO_INSERT
);
797 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
801 ret
= (struct elf_i386_link_hash_entry
*)
802 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
803 sizeof (struct elf_i386_link_hash_entry
));
806 memset (ret
, 0, sizeof (*ret
));
807 ret
->elf
.indx
= sec
->id
;
808 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
809 ret
->elf
.dynindx
= -1;
810 ret
->elf
.plt
.offset
= (bfd_vma
) -1;
811 ret
->elf
.got
.offset
= (bfd_vma
) -1;
817 /* Create an i386 ELF linker hash table. */
819 static struct bfd_link_hash_table
*
820 elf_i386_link_hash_table_create (bfd
*abfd
)
822 struct elf_i386_link_hash_table
*ret
;
823 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
825 ret
= bfd_malloc (amt
);
829 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
830 elf_i386_link_hash_newfunc
,
831 sizeof (struct elf_i386_link_hash_entry
)))
839 ret
->tls_ldm_got
.refcount
= 0;
840 ret
->next_tls_desc_index
= 0;
841 ret
->sgotplt_jump_table_size
= 0;
842 ret
->sym_sec
.abfd
= NULL
;
844 ret
->srelplt2
= NULL
;
845 ret
->plt0_pad_byte
= 0;
846 ret
->tls_module_base
= NULL
;
848 ret
->loc_hash_table
= htab_try_create (1024,
849 elf_i386_local_htab_hash
,
850 elf_i386_local_htab_eq
,
852 ret
->loc_hash_memory
= objalloc_create ();
853 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
859 return &ret
->elf
.root
;
862 /* Destroy an i386 ELF linker hash table. */
865 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
867 struct elf_i386_link_hash_table
*htab
868 = (struct elf_i386_link_hash_table
*) hash
;
870 if (htab
->loc_hash_table
)
871 htab_delete (htab
->loc_hash_table
);
872 if (htab
->loc_hash_memory
)
873 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
874 _bfd_generic_link_hash_table_free (hash
);
877 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
878 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
882 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
884 struct elf_i386_link_hash_table
*htab
;
886 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
889 htab
= elf_i386_hash_table (info
);
890 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
892 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
895 || (!info
->shared
&& !htab
->srelbss
))
899 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
906 /* Copy the extra info we tack onto an elf_link_hash_entry. */
909 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
910 struct elf_link_hash_entry
*dir
,
911 struct elf_link_hash_entry
*ind
)
913 struct elf_i386_link_hash_entry
*edir
, *eind
;
915 edir
= (struct elf_i386_link_hash_entry
*) dir
;
916 eind
= (struct elf_i386_link_hash_entry
*) ind
;
918 if (eind
->dyn_relocs
!= NULL
)
920 if (edir
->dyn_relocs
!= NULL
)
922 struct elf_i386_dyn_relocs
**pp
;
923 struct elf_i386_dyn_relocs
*p
;
925 /* Add reloc counts against the indirect sym to the direct sym
926 list. Merge any entries against the same section. */
927 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
929 struct elf_i386_dyn_relocs
*q
;
931 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
932 if (q
->sec
== p
->sec
)
934 q
->pc_count
+= p
->pc_count
;
935 q
->count
+= p
->count
;
942 *pp
= edir
->dyn_relocs
;
945 edir
->dyn_relocs
= eind
->dyn_relocs
;
946 eind
->dyn_relocs
= NULL
;
949 if (ind
->root
.type
== bfd_link_hash_indirect
950 && dir
->got
.refcount
<= 0)
952 edir
->tls_type
= eind
->tls_type
;
953 eind
->tls_type
= GOT_UNKNOWN
;
956 if (ELIMINATE_COPY_RELOCS
957 && ind
->root
.type
!= bfd_link_hash_indirect
958 && dir
->dynamic_adjusted
)
960 /* If called to transfer flags for a weakdef during processing
961 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
962 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
963 dir
->ref_dynamic
|= ind
->ref_dynamic
;
964 dir
->ref_regular
|= ind
->ref_regular
;
965 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
966 dir
->needs_plt
|= ind
->needs_plt
;
967 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
970 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
980 /* Return TRUE if the TLS access code sequence support transition
984 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
986 Elf_Internal_Shdr
*symtab_hdr
,
987 struct elf_link_hash_entry
**sym_hashes
,
989 const Elf_Internal_Rela
*rel
,
990 const Elf_Internal_Rela
*relend
)
992 unsigned int val
, type
;
993 unsigned long r_symndx
;
994 struct elf_link_hash_entry
*h
;
997 /* Get the section contents. */
998 if (contents
== NULL
)
1000 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1001 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1004 /* FIXME: How to better handle error condition? */
1005 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1008 /* Cache the section contents for elf_link_input_bfd. */
1009 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1013 offset
= rel
->r_offset
;
1018 if (offset
< 2 || (rel
+ 1) >= relend
)
1021 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1022 if (r_type
== R_386_TLS_GD
)
1024 /* Check transition from GD access model. Only
1025 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1026 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1027 can transit to different access model. */
1028 if ((offset
+ 10) > sec
->size
||
1029 (type
!= 0x8d && type
!= 0x04))
1032 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1035 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1039 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1042 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1047 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1048 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1051 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1057 /* Check transition from LD access model. Only
1058 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1059 can transit to different access model. */
1060 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1063 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1064 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1068 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1071 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1072 if (r_symndx
< symtab_hdr
->sh_info
)
1075 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1076 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1077 may be versioned. */
1079 && h
->root
.root
.string
!= NULL
1080 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1081 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1082 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1086 /* Check transition from IE access model:
1087 movl foo@indntpoff(%rip), %eax
1088 movl foo@indntpoff(%rip), %reg
1089 addl foo@indntpoff(%rip), %reg
1092 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1095 /* Check "movl foo@tpoff(%rip), %eax" first. */
1096 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1103 /* Check movl|addl foo@tpoff(%rip), %reg. */
1104 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1105 return ((type
== 0x8b || type
== 0x03)
1106 && (val
& 0xc7) == 0x05);
1108 case R_386_TLS_GOTIE
:
1109 case R_386_TLS_IE_32
:
1110 /* Check transition from {IE_32,GOTIE} access model:
1111 subl foo@{tpoff,gontoff}(%reg1), %reg2
1112 movl foo@{tpoff,gontoff}(%reg1), %reg2
1113 addl foo@{tpoff,gontoff}(%reg1), %reg2
1116 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1119 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1120 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1123 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1124 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1126 case R_386_TLS_GOTDESC
:
1127 /* Check transition from GDesc access model:
1128 leal x@tlsdesc(%ebx), %eax
1130 Make sure it's a leal adding ebx to a 32-bit offset
1131 into any register, although it's probably almost always
1134 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1137 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1140 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1141 return (val
& 0xc7) == 0x83;
1143 case R_386_TLS_DESC_CALL
:
1144 /* Check transition from GDesc access model:
1145 call *x@tlsdesc(%rax)
1147 if (offset
+ 2 <= sec
->size
)
1149 /* Make sure that it's a call *x@tlsdesc(%rax). */
1150 static i386_opcode16 call
= { { 0xff, 0x10 } };
1151 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1161 /* Return TRUE if the TLS access transition is OK or no transition
1162 will be performed. Update R_TYPE if there is a transition. */
1165 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1166 asection
*sec
, bfd_byte
*contents
,
1167 Elf_Internal_Shdr
*symtab_hdr
,
1168 struct elf_link_hash_entry
**sym_hashes
,
1169 unsigned int *r_type
, int tls_type
,
1170 const Elf_Internal_Rela
*rel
,
1171 const Elf_Internal_Rela
*relend
,
1172 struct elf_link_hash_entry
*h
)
1174 unsigned int from_type
= *r_type
;
1175 unsigned int to_type
= from_type
;
1176 bfd_boolean check
= TRUE
;
1181 case R_386_TLS_GOTDESC
:
1182 case R_386_TLS_DESC_CALL
:
1183 case R_386_TLS_IE_32
:
1185 case R_386_TLS_GOTIE
:
1189 to_type
= R_386_TLS_LE_32
;
1190 else if (from_type
!= R_386_TLS_IE
1191 && from_type
!= R_386_TLS_GOTIE
)
1192 to_type
= R_386_TLS_IE_32
;
1195 /* When we are called from elf_i386_relocate_section, CONTENTS
1196 isn't NULL and there may be additional transitions based on
1198 if (contents
!= NULL
)
1200 unsigned int new_to_type
= to_type
;
1205 && (tls_type
& GOT_TLS_IE
))
1206 new_to_type
= R_386_TLS_LE_32
;
1208 if (to_type
== R_386_TLS_GD
1209 || to_type
== R_386_TLS_GOTDESC
1210 || to_type
== R_386_TLS_DESC_CALL
)
1212 if (tls_type
== GOT_TLS_IE_POS
)
1213 new_to_type
= R_386_TLS_GOTIE
;
1214 else if (tls_type
& GOT_TLS_IE
)
1215 new_to_type
= R_386_TLS_IE_32
;
1218 /* We checked the transition before when we were called from
1219 elf_i386_check_relocs. We only want to check the new
1220 transition which hasn't been checked before. */
1221 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1222 to_type
= new_to_type
;
1229 to_type
= R_386_TLS_LE_32
;
1236 /* Return TRUE if there is no transition. */
1237 if (from_type
== to_type
)
1240 /* Check if the transition can be performed. */
1242 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1243 symtab_hdr
, sym_hashes
,
1244 from_type
, rel
, relend
))
1246 reloc_howto_type
*from
, *to
;
1248 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1249 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1251 (*_bfd_error_handler
)
1252 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1253 "in section `%A' failed"),
1254 abfd
, sec
, from
->name
, to
->name
,
1255 h
? h
->root
.root
.string
: "a local symbol",
1256 (unsigned long) rel
->r_offset
);
1257 bfd_set_error (bfd_error_bad_value
);
1265 /* Look through the relocs for a section during the first phase, and
1266 calculate needed space in the global offset table, procedure linkage
1267 table, and dynamic reloc sections. */
1270 elf_i386_check_relocs (bfd
*abfd
,
1271 struct bfd_link_info
*info
,
1273 const Elf_Internal_Rela
*relocs
)
1275 struct elf_i386_link_hash_table
*htab
;
1276 Elf_Internal_Shdr
*symtab_hdr
;
1277 struct elf_link_hash_entry
**sym_hashes
;
1278 const Elf_Internal_Rela
*rel
;
1279 const Elf_Internal_Rela
*rel_end
;
1281 Elf_Internal_Sym
*isymbuf
;
1283 if (info
->relocatable
)
1286 BFD_ASSERT (is_i386_elf (abfd
));
1288 htab
= elf_i386_hash_table (info
);
1289 symtab_hdr
= &elf_symtab_hdr (abfd
);
1290 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1291 sym_hashes
= elf_sym_hashes (abfd
);
1295 rel_end
= relocs
+ sec
->reloc_count
;
1296 for (rel
= relocs
; rel
< rel_end
; rel
++)
1298 unsigned int r_type
;
1299 unsigned long r_symndx
;
1300 struct elf_link_hash_entry
*h
;
1302 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1303 r_type
= ELF32_R_TYPE (rel
->r_info
);
1305 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1307 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1313 if (r_symndx
< symtab_hdr
->sh_info
)
1315 /* A local symbol. */
1316 Elf_Internal_Sym
*isym
;
1318 /* Read this BFD's local symbols. */
1319 if (isymbuf
== NULL
)
1321 if (isymbuf
== NULL
)
1322 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1323 symtab_hdr
->sh_info
, 0,
1325 if (isymbuf
== NULL
)
1329 /* Check relocation against local STT_GNU_IFUNC symbol. */
1330 isym
= isymbuf
+ r_symndx
;
1331 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1333 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
,
1338 /* Fake a STT_GNU_IFUNC symbol. */
1339 h
->type
= STT_GNU_IFUNC
;
1342 h
->forced_local
= 1;
1343 h
->root
.type
= bfd_link_hash_defined
;
1350 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1351 while (h
->root
.type
== bfd_link_hash_indirect
1352 || h
->root
.type
== bfd_link_hash_warning
)
1353 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1358 /* Create the ifunc sections for static executables. If we
1359 never see an indirect function symbol nor we are building
1360 a static executable, those sections will be empty and
1361 won't appear in output. */
1372 if (!_bfd_elf_create_ifunc_sections (abfd
, info
))
1377 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1378 it here if it is defined in a non-shared object. */
1379 if (h
->type
== STT_GNU_IFUNC
1382 /* It is referenced by a non-shared object. */
1385 /* STT_GNU_IFUNC symbol must go through PLT. */
1386 h
->plt
.refcount
+= 1;
1388 /* STT_GNU_IFUNC needs dynamic sections. */
1389 if (htab
->elf
.dynobj
== NULL
)
1390 htab
->elf
.dynobj
= abfd
;
1395 (*_bfd_error_handler
)
1396 (_("%B: relocation %s against STT_GNU_IFUNC "
1397 "symbol `%s' isn't handled by %s"), abfd
,
1398 elf_howto_table
[r_type
].name
,
1399 (h
->root
.root
.string
1400 ? h
->root
.root
.string
: "a local symbol"),
1402 bfd_set_error (bfd_error_bad_value
);
1407 h
->pointer_equality_needed
= 1;
1410 struct elf_i386_dyn_relocs
*p
;
1411 struct elf_i386_dyn_relocs
**head
;
1413 /* We must copy these reloc types into the
1414 output file. Create a reloc section in
1415 dynobj and make room for this reloc. */
1418 if (htab
->elf
.dynobj
== NULL
)
1419 htab
->elf
.dynobj
= abfd
;
1421 sreloc
= _bfd_elf_make_dynamic_reloc_section
1422 (sec
, htab
->elf
.dynobj
, 2, abfd
, FALSE
);
1428 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1430 if (p
== NULL
|| p
->sec
!= sec
)
1432 bfd_size_type amt
= sizeof *p
;
1433 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
1455 h
->got
.refcount
+= 1;
1456 if (htab
->elf
.sgot
== NULL
1457 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1467 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1468 symtab_hdr
, sym_hashes
,
1469 &r_type
, GOT_UNKNOWN
,
1476 htab
->tls_ldm_got
.refcount
+= 1;
1480 /* This symbol requires a procedure linkage table entry. We
1481 actually build the entry in adjust_dynamic_symbol,
1482 because this might be a case of linking PIC code which is
1483 never referenced by a dynamic object, in which case we
1484 don't need to generate a procedure linkage table entry
1487 /* If this is a local symbol, we resolve it directly without
1488 creating a procedure linkage table entry. */
1493 h
->plt
.refcount
+= 1;
1496 case R_386_TLS_IE_32
:
1498 case R_386_TLS_GOTIE
:
1500 info
->flags
|= DF_STATIC_TLS
;
1505 case R_386_TLS_GOTDESC
:
1506 case R_386_TLS_DESC_CALL
:
1507 /* This symbol requires a global offset table entry. */
1509 int tls_type
, old_tls_type
;
1514 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1515 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1516 case R_386_TLS_GOTDESC
:
1517 case R_386_TLS_DESC_CALL
:
1518 tls_type
= GOT_TLS_GDESC
; break;
1519 case R_386_TLS_IE_32
:
1520 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1521 tls_type
= GOT_TLS_IE_NEG
;
1523 /* If this is a GD->IE transition, we may use either of
1524 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1525 tls_type
= GOT_TLS_IE
;
1528 case R_386_TLS_GOTIE
:
1529 tls_type
= GOT_TLS_IE_POS
; break;
1534 h
->got
.refcount
+= 1;
1535 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1539 bfd_signed_vma
*local_got_refcounts
;
1541 /* This is a global offset table entry for a local symbol. */
1542 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1543 if (local_got_refcounts
== NULL
)
1547 size
= symtab_hdr
->sh_info
;
1548 size
*= (sizeof (bfd_signed_vma
)
1549 + sizeof (bfd_vma
) + sizeof(char));
1550 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1551 if (local_got_refcounts
== NULL
)
1553 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1554 elf_i386_local_tlsdesc_gotent (abfd
)
1555 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1556 elf_i386_local_got_tls_type (abfd
)
1557 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1559 local_got_refcounts
[r_symndx
] += 1;
1560 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1563 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1564 tls_type
|= old_tls_type
;
1565 /* If a TLS symbol is accessed using IE at least once,
1566 there is no point to use dynamic model for it. */
1567 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1568 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1569 || (tls_type
& GOT_TLS_IE
) == 0))
1571 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1572 tls_type
= old_tls_type
;
1573 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1574 && GOT_TLS_GD_ANY_P (tls_type
))
1575 tls_type
|= old_tls_type
;
1578 (*_bfd_error_handler
)
1579 (_("%B: `%s' accessed both as normal and "
1580 "thread local symbol"),
1582 h
? h
->root
.root
.string
: "<local>");
1587 if (old_tls_type
!= tls_type
)
1590 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1592 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1600 if (htab
->elf
.sgot
== NULL
)
1602 if (htab
->elf
.dynobj
== NULL
)
1603 htab
->elf
.dynobj
= abfd
;
1604 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1607 if (r_type
!= R_386_TLS_IE
)
1611 case R_386_TLS_LE_32
:
1615 info
->flags
|= DF_STATIC_TLS
;
1620 if (h
!= NULL
&& info
->executable
)
1622 /* If this reloc is in a read-only section, we might
1623 need a copy reloc. We can't check reliably at this
1624 stage whether the section is read-only, as input
1625 sections have not yet been mapped to output sections.
1626 Tentatively set the flag for now, and correct in
1627 adjust_dynamic_symbol. */
1630 /* We may need a .plt entry if the function this reloc
1631 refers to is in a shared lib. */
1632 h
->plt
.refcount
+= 1;
1633 if (r_type
!= R_386_PC32
)
1634 h
->pointer_equality_needed
= 1;
1637 /* If we are creating a shared library, and this is a reloc
1638 against a global symbol, or a non PC relative reloc
1639 against a local symbol, then we need to copy the reloc
1640 into the shared library. However, if we are linking with
1641 -Bsymbolic, we do not need to copy a reloc against a
1642 global symbol which is defined in an object we are
1643 including in the link (i.e., DEF_REGULAR is set). At
1644 this point we have not seen all the input files, so it is
1645 possible that DEF_REGULAR is not set now but will be set
1646 later (it is never cleared). In case of a weak definition,
1647 DEF_REGULAR may be cleared later by a strong definition in
1648 a shared library. We account for that possibility below by
1649 storing information in the relocs_copied field of the hash
1650 table entry. A similar situation occurs when creating
1651 shared libraries and symbol visibility changes render the
1654 If on the other hand, we are creating an executable, we
1655 may need to keep relocations for symbols satisfied by a
1656 dynamic library if we manage to avoid copy relocs for the
1659 && (sec
->flags
& SEC_ALLOC
) != 0
1660 && (r_type
!= R_386_PC32
1662 && (! SYMBOLIC_BIND (info
, h
)
1663 || h
->root
.type
== bfd_link_hash_defweak
1664 || !h
->def_regular
))))
1665 || (ELIMINATE_COPY_RELOCS
1667 && (sec
->flags
& SEC_ALLOC
) != 0
1669 && (h
->root
.type
== bfd_link_hash_defweak
1670 || !h
->def_regular
)))
1672 struct elf_i386_dyn_relocs
*p
;
1673 struct elf_i386_dyn_relocs
**head
;
1675 /* We must copy these reloc types into the output file.
1676 Create a reloc section in dynobj and make room for
1680 if (htab
->elf
.dynobj
== NULL
)
1681 htab
->elf
.dynobj
= abfd
;
1683 sreloc
= _bfd_elf_make_dynamic_reloc_section
1684 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1690 /* If this is a global symbol, we count the number of
1691 relocations we need for this symbol. */
1694 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1699 /* Track dynamic relocs needed for local syms too.
1700 We really need local syms available to do this
1704 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1709 vpp
= &elf_section_data (s
)->local_dynrel
;
1710 head
= (struct elf_i386_dyn_relocs
**)vpp
;
1714 if (p
== NULL
|| p
->sec
!= sec
)
1716 bfd_size_type amt
= sizeof *p
;
1717 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
1728 if (r_type
== R_386_PC32
)
1733 /* This relocation describes the C++ object vtable hierarchy.
1734 Reconstruct it for later use during GC. */
1735 case R_386_GNU_VTINHERIT
:
1736 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1740 /* This relocation describes which C++ vtable entries are actually
1741 used. Record for later use during GC. */
1742 case R_386_GNU_VTENTRY
:
1743 BFD_ASSERT (h
!= NULL
);
1745 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1757 /* Return the section that should be marked against GC for a given
1761 elf_i386_gc_mark_hook (asection
*sec
,
1762 struct bfd_link_info
*info
,
1763 Elf_Internal_Rela
*rel
,
1764 struct elf_link_hash_entry
*h
,
1765 Elf_Internal_Sym
*sym
)
1768 switch (ELF32_R_TYPE (rel
->r_info
))
1770 case R_386_GNU_VTINHERIT
:
1771 case R_386_GNU_VTENTRY
:
1775 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1778 /* Update the got entry reference counts for the section being removed. */
1781 elf_i386_gc_sweep_hook (bfd
*abfd
,
1782 struct bfd_link_info
*info
,
1784 const Elf_Internal_Rela
*relocs
)
1786 Elf_Internal_Shdr
*symtab_hdr
;
1787 struct elf_link_hash_entry
**sym_hashes
;
1788 bfd_signed_vma
*local_got_refcounts
;
1789 const Elf_Internal_Rela
*rel
, *relend
;
1791 if (info
->relocatable
)
1794 elf_section_data (sec
)->local_dynrel
= NULL
;
1796 symtab_hdr
= &elf_symtab_hdr (abfd
);
1797 sym_hashes
= elf_sym_hashes (abfd
);
1798 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1800 relend
= relocs
+ sec
->reloc_count
;
1801 for (rel
= relocs
; rel
< relend
; rel
++)
1803 unsigned long r_symndx
;
1804 unsigned int r_type
;
1805 struct elf_link_hash_entry
*h
= NULL
;
1807 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1808 if (r_symndx
>= symtab_hdr
->sh_info
)
1810 struct elf_i386_link_hash_entry
*eh
;
1811 struct elf_i386_dyn_relocs
**pp
;
1812 struct elf_i386_dyn_relocs
*p
;
1814 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1815 while (h
->root
.type
== bfd_link_hash_indirect
1816 || h
->root
.type
== bfd_link_hash_warning
)
1817 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1818 eh
= (struct elf_i386_link_hash_entry
*) h
;
1820 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1823 /* Everything must go for SEC. */
1829 r_type
= ELF32_R_TYPE (rel
->r_info
);
1830 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1831 symtab_hdr
, sym_hashes
,
1832 &r_type
, GOT_UNKNOWN
,
1839 if (elf_i386_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1840 elf_i386_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1844 case R_386_TLS_GOTDESC
:
1845 case R_386_TLS_DESC_CALL
:
1846 case R_386_TLS_IE_32
:
1848 case R_386_TLS_GOTIE
:
1852 if (h
->got
.refcount
> 0)
1853 h
->got
.refcount
-= 1;
1855 else if (local_got_refcounts
!= NULL
)
1857 if (local_got_refcounts
[r_symndx
] > 0)
1858 local_got_refcounts
[r_symndx
] -= 1;
1871 if (h
->plt
.refcount
> 0)
1872 h
->plt
.refcount
-= 1;
1884 /* Adjust a symbol defined by a dynamic object and referenced by a
1885 regular object. The current definition is in some section of the
1886 dynamic object, but we're not including those sections. We have to
1887 change the definition to something the rest of the link can
1891 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1892 struct elf_link_hash_entry
*h
)
1894 struct elf_i386_link_hash_table
*htab
;
1897 /* STT_GNU_IFUNC symbol must go through PLT. */
1898 if (h
->type
== STT_GNU_IFUNC
)
1900 if (h
->plt
.refcount
<= 0)
1902 h
->plt
.offset
= (bfd_vma
) -1;
1908 /* If this is a function, put it in the procedure linkage table. We
1909 will fill in the contents of the procedure linkage table later,
1910 when we know the address of the .got section. */
1911 if (h
->type
== STT_FUNC
1914 if (h
->plt
.refcount
<= 0
1915 || SYMBOL_CALLS_LOCAL (info
, h
)
1916 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1917 && h
->root
.type
== bfd_link_hash_undefweak
))
1919 /* This case can occur if we saw a PLT32 reloc in an input
1920 file, but the symbol was never referred to by a dynamic
1921 object, or if all references were garbage collected. In
1922 such a case, we don't actually need to build a procedure
1923 linkage table, and we can just do a PC32 reloc instead. */
1924 h
->plt
.offset
= (bfd_vma
) -1;
1931 /* It's possible that we incorrectly decided a .plt reloc was
1932 needed for an R_386_PC32 reloc to a non-function sym in
1933 check_relocs. We can't decide accurately between function and
1934 non-function syms in check-relocs; Objects loaded later in
1935 the link may change h->type. So fix it now. */
1936 h
->plt
.offset
= (bfd_vma
) -1;
1938 /* If this is a weak symbol, and there is a real definition, the
1939 processor independent code will have arranged for us to see the
1940 real definition first, and we can just use the same value. */
1941 if (h
->u
.weakdef
!= NULL
)
1943 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1944 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1945 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1946 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1947 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1948 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1952 /* This is a reference to a symbol defined by a dynamic object which
1953 is not a function. */
1955 /* If we are creating a shared library, we must presume that the
1956 only references to the symbol are via the global offset table.
1957 For such cases we need not do anything here; the relocations will
1958 be handled correctly by relocate_section. */
1962 /* If there are no references to this symbol that do not use the
1963 GOT, we don't need to generate a copy reloc. */
1964 if (!h
->non_got_ref
)
1967 /* If -z nocopyreloc was given, we won't generate them either. */
1968 if (info
->nocopyreloc
)
1974 htab
= elf_i386_hash_table (info
);
1976 /* If there aren't any dynamic relocs in read-only sections, then
1977 we can keep the dynamic relocs and avoid the copy reloc. This
1978 doesn't work on VxWorks, where we can not have dynamic relocations
1979 (other than copy and jump slot relocations) in an executable. */
1980 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
1982 struct elf_i386_link_hash_entry
* eh
;
1983 struct elf_i386_dyn_relocs
*p
;
1985 eh
= (struct elf_i386_link_hash_entry
*) h
;
1986 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1988 s
= p
->sec
->output_section
;
1989 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2002 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2003 h
->root
.root
.string
);
2007 /* We must allocate the symbol in our .dynbss section, which will
2008 become part of the .bss section of the executable. There will be
2009 an entry for this symbol in the .dynsym section. The dynamic
2010 object will contain position independent code, so all references
2011 from the dynamic object to this symbol will go through the global
2012 offset table. The dynamic linker will use the .dynsym entry to
2013 determine the address it must put in the global offset table, so
2014 both the dynamic object and the regular object will refer to the
2015 same memory location for the variable. */
2017 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2018 copy the initial value out of the dynamic object and into the
2019 runtime process image. */
2020 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2022 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2028 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2031 /* Allocate space in .plt, .got and associated reloc sections for
2035 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2037 struct bfd_link_info
*info
;
2038 struct elf_i386_link_hash_table
*htab
;
2039 struct elf_i386_link_hash_entry
*eh
;
2040 struct elf_i386_dyn_relocs
*p
;
2042 if (h
->root
.type
== bfd_link_hash_indirect
)
2045 if (h
->root
.type
== bfd_link_hash_warning
)
2046 /* When warning symbols are created, they **replace** the "real"
2047 entry in the hash table, thus we never get to see the real
2048 symbol in a hash traversal. So look at it now. */
2049 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2050 eh
= (struct elf_i386_link_hash_entry
*) h
;
2052 info
= (struct bfd_link_info
*) inf
;
2053 htab
= elf_i386_hash_table (info
);
2055 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2056 here if it is defined and referenced in a non-shared object. */
2057 if (h
->type
== STT_GNU_IFUNC
2060 asection
*plt
, *gotplt
, *relplt
;
2062 /* When a shared library references a STT_GNU_IFUNC symbol
2063 defined in executable, the address of the resolved function
2064 may be used. But in non-shared executable, the address of
2065 its .plt slot may be used. Pointer equality may not work
2066 correctly. PIE should be used if pointer equality is
2069 && (h
->dynindx
!= -1
2070 || info
->export_dynamic
)
2071 && h
->pointer_equality_needed
)
2073 info
->callbacks
->einfo
2074 (_("%F%P: dynamic STT_GNU_IFUNC symbol `%s' with pointer "
2075 "equality in `%B' can not be used when making an "
2076 "executable; recompile with -fPIE and relink with -pie\n"),
2077 h
->root
.root
.string
,
2078 h
->root
.u
.def
.section
->owner
);
2079 bfd_set_error (bfd_error_bad_value
);
2083 /* Return and discard space for dynamic relocations against it if
2084 it is never referenced in a non-shared object. */
2085 if (!h
->ref_regular
)
2087 if (h
->plt
.refcount
> 0
2088 || h
->got
.refcount
> 0)
2090 h
->got
.offset
= (bfd_vma
) -1;
2091 eh
->dyn_relocs
= NULL
;
2095 /* When building a static executable, use .iplt, .igot.plt and
2096 .rel.iplt sections for STT_GNU_IFUNC symbols. */
2097 if (htab
->elf
.splt
!= NULL
)
2099 plt
= htab
->elf
.splt
;
2100 gotplt
= htab
->elf
.sgotplt
;
2101 relplt
= htab
->elf
.srelplt
;
2103 /* If this is the first .plt entry, make room for the special
2106 plt
->size
+= PLT_ENTRY_SIZE
;
2110 plt
= htab
->elf
.iplt
;
2111 gotplt
= htab
->elf
.igotplt
;
2112 relplt
= htab
->elf
.irelplt
;
2115 /* Don't update value of STT_GNU_IFUNC symbol to PLT. We need
2116 the original value for R_386_IRELATIVE. */
2117 h
->plt
.offset
= plt
->size
;
2119 /* Make room for this entry in the .plt/.iplt section. */
2120 plt
->size
+= PLT_ENTRY_SIZE
;
2122 /* We also need to make an entry in the .got.plt/.got.iplt
2123 section, which will be placed in the .got section by the
2127 /* We also need to make an entry in the .rela.plt/.rela.iplt
2129 relplt
->size
+= sizeof (Elf32_External_Rel
);
2130 relplt
->reloc_count
++;
2132 /* We need dynamic relocation for STT_GNU_IFUNC symbol only
2133 when there is a non-GOT reference in a shared object. */
2136 eh
->dyn_relocs
= NULL
;
2138 /* Finally, allocate space. */
2139 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2140 htab
->elf
.irelifunc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2142 /* For STT_GNU_IFUNC symbol, .got.plt has the real function
2143 addres and .got has the PLT entry adddress. We will load
2144 the GOT entry with the PLT entry in finish_dynamic_symbol if
2145 it is used. For branch, it uses .got.plt. For symbol value,
2146 1. Use .got.plt in a shared object if it is forced local or
2148 2. Use .got.plt in a non-shared object if pointer equality
2150 3. Use .got.plt in PIE.
2151 4. Use .got.plt if .got isn't used.
2152 5. Otherwise use .got so that it can be shared among different
2153 objects at run-time.
2154 We only need to relocate .got entry in shared object. */
2156 && (h
->dynindx
== -1
2157 || h
->forced_local
))
2159 && !h
->pointer_equality_needed
)
2160 || (info
->executable
&& info
->shared
)
2161 || htab
->elf
.sgot
== NULL
)
2164 h
->got
.offset
= (bfd_vma
) -1;
2168 h
->got
.offset
= htab
->elf
.sgot
->size
;
2169 htab
->elf
.sgot
->size
+= 4;
2171 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2176 else if (htab
->elf
.dynamic_sections_created
2177 && h
->plt
.refcount
> 0)
2179 /* Make sure this symbol is output as a dynamic symbol.
2180 Undefined weak syms won't yet be marked as dynamic. */
2181 if (h
->dynindx
== -1
2182 && !h
->forced_local
)
2184 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2189 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2191 asection
*s
= htab
->elf
.splt
;
2193 /* If this is the first .plt entry, make room for the special
2196 s
->size
+= PLT_ENTRY_SIZE
;
2198 h
->plt
.offset
= s
->size
;
2200 /* If this symbol is not defined in a regular file, and we are
2201 not generating a shared library, then set the symbol to this
2202 location in the .plt. This is required to make function
2203 pointers compare as equal between the normal executable and
2204 the shared library. */
2208 h
->root
.u
.def
.section
= s
;
2209 h
->root
.u
.def
.value
= h
->plt
.offset
;
2212 /* Make room for this entry. */
2213 s
->size
+= PLT_ENTRY_SIZE
;
2215 /* We also need to make an entry in the .got.plt section, which
2216 will be placed in the .got section by the linker script. */
2217 htab
->elf
.sgotplt
->size
+= 4;
2219 /* We also need to make an entry in the .rel.plt section. */
2220 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2221 htab
->next_tls_desc_index
++;
2223 if (htab
->is_vxworks
&& !info
->shared
)
2225 /* VxWorks has a second set of relocations for each PLT entry
2226 in executables. They go in a separate relocation section,
2227 which is processed by the kernel loader. */
2229 /* There are two relocations for the initial PLT entry: an
2230 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2231 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2233 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
2234 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2236 /* There are two extra relocations for each subsequent PLT entry:
2237 an R_386_32 relocation for the GOT entry, and an R_386_32
2238 relocation for the PLT entry. */
2240 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2245 h
->plt
.offset
= (bfd_vma
) -1;
2251 h
->plt
.offset
= (bfd_vma
) -1;
2255 eh
->tlsdesc_got
= (bfd_vma
) -1;
2257 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2258 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2259 if (h
->got
.refcount
> 0
2262 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2263 h
->got
.offset
= (bfd_vma
) -1;
2264 else if (h
->got
.refcount
> 0)
2268 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2270 /* Make sure this symbol is output as a dynamic symbol.
2271 Undefined weak syms won't yet be marked as dynamic. */
2272 if (h
->dynindx
== -1
2273 && !h
->forced_local
)
2275 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2280 if (GOT_TLS_GDESC_P (tls_type
))
2282 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2283 - elf_i386_compute_jump_table_size (htab
);
2284 htab
->elf
.sgotplt
->size
+= 8;
2285 h
->got
.offset
= (bfd_vma
) -2;
2287 if (! GOT_TLS_GDESC_P (tls_type
)
2288 || GOT_TLS_GD_P (tls_type
))
2290 h
->got
.offset
= s
->size
;
2292 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2293 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2296 dyn
= htab
->elf
.dynamic_sections_created
;
2297 /* R_386_TLS_IE_32 needs one dynamic relocation,
2298 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2299 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2300 need two), R_386_TLS_GD needs one if local symbol and two if
2302 if (tls_type
== GOT_TLS_IE_BOTH
)
2303 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2304 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2305 || (tls_type
& GOT_TLS_IE
))
2306 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2307 else if (GOT_TLS_GD_P (tls_type
))
2308 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2309 else if (! GOT_TLS_GDESC_P (tls_type
)
2310 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2311 || h
->root
.type
!= bfd_link_hash_undefweak
)
2313 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2314 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2315 if (GOT_TLS_GDESC_P (tls_type
))
2316 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2319 h
->got
.offset
= (bfd_vma
) -1;
2321 if (eh
->dyn_relocs
== NULL
)
2324 /* In the shared -Bsymbolic case, discard space allocated for
2325 dynamic pc-relative relocs against symbols which turn out to be
2326 defined in regular objects. For the normal shared case, discard
2327 space for pc-relative relocs that have become local due to symbol
2328 visibility changes. */
2332 /* The only reloc that uses pc_count is R_386_PC32, which will
2333 appear on a call or on something like ".long foo - .". We
2334 want calls to protected symbols to resolve directly to the
2335 function rather than going via the plt. If people want
2336 function pointer comparisons to work as expected then they
2337 should avoid writing assembly like ".long foo - .". */
2338 if (SYMBOL_CALLS_LOCAL (info
, h
))
2340 struct elf_i386_dyn_relocs
**pp
;
2342 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2344 p
->count
-= p
->pc_count
;
2353 if (htab
->is_vxworks
)
2355 struct elf_i386_dyn_relocs
**pp
;
2356 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2358 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2365 /* Also discard relocs on undefined weak syms with non-default
2367 if (eh
->dyn_relocs
!= NULL
2368 && h
->root
.type
== bfd_link_hash_undefweak
)
2370 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2371 eh
->dyn_relocs
= NULL
;
2373 /* Make sure undefined weak symbols are output as a dynamic
2375 else if (h
->dynindx
== -1
2376 && !h
->forced_local
)
2378 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2383 else if (ELIMINATE_COPY_RELOCS
)
2385 /* For the non-shared case, discard space for relocs against
2386 symbols which turn out to need copy relocs or are not
2392 || (htab
->elf
.dynamic_sections_created
2393 && (h
->root
.type
== bfd_link_hash_undefweak
2394 || h
->root
.type
== bfd_link_hash_undefined
))))
2396 /* Make sure this symbol is output as a dynamic symbol.
2397 Undefined weak syms won't yet be marked as dynamic. */
2398 if (h
->dynindx
== -1
2399 && !h
->forced_local
)
2401 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2405 /* If that succeeded, we know we'll be keeping all the
2407 if (h
->dynindx
!= -1)
2411 eh
->dyn_relocs
= NULL
;
2416 /* Finally, allocate space. */
2417 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2421 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2423 BFD_ASSERT (sreloc
!= NULL
);
2424 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2430 /* Allocate space in .plt, .got and associated reloc sections for
2431 local dynamic relocs. */
2434 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2436 struct elf_link_hash_entry
*h
2437 = (struct elf_link_hash_entry
*) *slot
;
2439 if (h
->type
!= STT_GNU_IFUNC
2443 || h
->root
.type
!= bfd_link_hash_defined
)
2446 return elf_i386_allocate_dynrelocs (h
, inf
);
2449 /* Find any dynamic relocs that apply to read-only sections. */
2452 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2454 struct elf_i386_link_hash_entry
*eh
;
2455 struct elf_i386_dyn_relocs
*p
;
2457 if (h
->root
.type
== bfd_link_hash_warning
)
2458 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2460 eh
= (struct elf_i386_link_hash_entry
*) h
;
2461 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2463 asection
*s
= p
->sec
->output_section
;
2465 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2467 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2469 info
->flags
|= DF_TEXTREL
;
2471 /* Not an error, just cut short the traversal. */
2478 /* Set the sizes of the dynamic sections. */
2481 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2482 struct bfd_link_info
*info
)
2484 struct elf_i386_link_hash_table
*htab
;
2490 htab
= elf_i386_hash_table (info
);
2491 dynobj
= htab
->elf
.dynobj
;
2495 if (htab
->elf
.dynamic_sections_created
)
2497 /* Set the contents of the .interp section to the interpreter. */
2498 if (info
->executable
)
2500 s
= bfd_get_section_by_name (dynobj
, ".interp");
2503 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2504 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2508 /* Set up .got offsets for local syms, and space for local dynamic
2510 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2512 bfd_signed_vma
*local_got
;
2513 bfd_signed_vma
*end_local_got
;
2514 char *local_tls_type
;
2515 bfd_vma
*local_tlsdesc_gotent
;
2516 bfd_size_type locsymcount
;
2517 Elf_Internal_Shdr
*symtab_hdr
;
2520 if (! is_i386_elf (ibfd
))
2523 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2525 struct elf_i386_dyn_relocs
*p
;
2527 for (p
= ((struct elf_i386_dyn_relocs
*)
2528 elf_section_data (s
)->local_dynrel
);
2532 if (!bfd_is_abs_section (p
->sec
)
2533 && bfd_is_abs_section (p
->sec
->output_section
))
2535 /* Input section has been discarded, either because
2536 it is a copy of a linkonce section or due to
2537 linker script /DISCARD/, so we'll be discarding
2540 else if (htab
->is_vxworks
2541 && strcmp (p
->sec
->output_section
->name
,
2544 /* Relocations in vxworks .tls_vars sections are
2545 handled specially by the loader. */
2547 else if (p
->count
!= 0)
2549 srel
= elf_section_data (p
->sec
)->sreloc
;
2550 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2551 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2552 info
->flags
|= DF_TEXTREL
;
2557 local_got
= elf_local_got_refcounts (ibfd
);
2561 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2562 locsymcount
= symtab_hdr
->sh_info
;
2563 end_local_got
= local_got
+ locsymcount
;
2564 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2565 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2567 srel
= htab
->elf
.srelgot
;
2568 for (; local_got
< end_local_got
;
2569 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2571 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2574 if (GOT_TLS_GDESC_P (*local_tls_type
))
2576 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2577 - elf_i386_compute_jump_table_size (htab
);
2578 htab
->elf
.sgotplt
->size
+= 8;
2579 *local_got
= (bfd_vma
) -2;
2581 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2582 || GOT_TLS_GD_P (*local_tls_type
))
2584 *local_got
= s
->size
;
2586 if (GOT_TLS_GD_P (*local_tls_type
)
2587 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2591 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2592 || (*local_tls_type
& GOT_TLS_IE
))
2594 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2595 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2596 else if (GOT_TLS_GD_P (*local_tls_type
)
2597 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2598 srel
->size
+= sizeof (Elf32_External_Rel
);
2599 if (GOT_TLS_GDESC_P (*local_tls_type
))
2600 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2604 *local_got
= (bfd_vma
) -1;
2608 if (htab
->tls_ldm_got
.refcount
> 0)
2610 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2612 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2613 htab
->elf
.sgot
->size
+= 8;
2614 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2617 htab
->tls_ldm_got
.offset
= -1;
2619 /* Allocate global sym .plt and .got entries, and space for global
2620 sym dynamic relocs. */
2621 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2623 /* Allocate .plt and .got entries, and space for local symbols. */
2624 htab_traverse (htab
->loc_hash_table
,
2625 elf_i386_allocate_local_dynrelocs
,
2628 /* For every jump slot reserved in the sgotplt, reloc_count is
2629 incremented. However, when we reserve space for TLS descriptors,
2630 it's not incremented, so in order to compute the space reserved
2631 for them, it suffices to multiply the reloc count by the jump
2633 if (htab
->elf
.srelplt
)
2634 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2636 /* We now have determined the sizes of the various dynamic sections.
2637 Allocate memory for them. */
2639 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2641 bfd_boolean strip_section
= TRUE
;
2643 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2646 if (s
== htab
->elf
.splt
2647 || s
== htab
->elf
.sgot
2648 || s
== htab
->elf
.sgotplt
2649 || s
== htab
->elf
.iplt
2650 || s
== htab
->elf
.igotplt
2651 || s
== htab
->sdynbss
)
2653 /* Strip this section if we don't need it; see the
2655 /* We'd like to strip these sections if they aren't needed, but if
2656 we've exported dynamic symbols from them we must leave them.
2657 It's too late to tell BFD to get rid of the symbols. */
2659 if (htab
->elf
.hplt
!= NULL
)
2660 strip_section
= FALSE
;
2662 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2665 && s
!= htab
->elf
.srelplt
2666 && s
!= htab
->srelplt2
)
2669 /* We use the reloc_count field as a counter if we need
2670 to copy relocs into the output file. */
2675 /* It's not one of our sections, so don't allocate space. */
2681 /* If we don't need this section, strip it from the
2682 output file. This is mostly to handle .rel.bss and
2683 .rel.plt. We must create both sections in
2684 create_dynamic_sections, because they must be created
2685 before the linker maps input sections to output
2686 sections. The linker does that before
2687 adjust_dynamic_symbol is called, and it is that
2688 function which decides whether anything needs to go
2689 into these sections. */
2691 s
->flags
|= SEC_EXCLUDE
;
2695 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2698 /* Allocate memory for the section contents. We use bfd_zalloc
2699 here in case unused entries are not reclaimed before the
2700 section's contents are written out. This should not happen,
2701 but this way if it does, we get a R_386_NONE reloc instead
2703 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
2704 if (s
->contents
== NULL
)
2708 if (htab
->elf
.dynamic_sections_created
)
2710 /* Add some entries to the .dynamic section. We fill in the
2711 values later, in elf_i386_finish_dynamic_sections, but we
2712 must add the entries now so that we get the correct size for
2713 the .dynamic section. The DT_DEBUG entry is filled in by the
2714 dynamic linker and used by the debugger. */
2715 #define add_dynamic_entry(TAG, VAL) \
2716 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2718 if (info
->executable
)
2720 if (!add_dynamic_entry (DT_DEBUG
, 0))
2724 if (htab
->elf
.splt
->size
!= 0)
2726 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2727 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2728 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2729 || !add_dynamic_entry (DT_JMPREL
, 0))
2735 if (!add_dynamic_entry (DT_REL
, 0)
2736 || !add_dynamic_entry (DT_RELSZ
, 0)
2737 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2740 /* If any dynamic relocs apply to a read-only section,
2741 then we need a DT_TEXTREL entry. */
2742 if ((info
->flags
& DF_TEXTREL
) == 0)
2743 elf_link_hash_traverse (&htab
->elf
,
2744 elf_i386_readonly_dynrelocs
, info
);
2746 if ((info
->flags
& DF_TEXTREL
) != 0)
2748 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2752 if (htab
->is_vxworks
2753 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2756 #undef add_dynamic_entry
2762 elf_i386_always_size_sections (bfd
*output_bfd
,
2763 struct bfd_link_info
*info
)
2765 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2769 struct elf_link_hash_entry
*tlsbase
;
2771 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2772 "_TLS_MODULE_BASE_",
2773 FALSE
, FALSE
, FALSE
);
2775 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2777 struct bfd_link_hash_entry
*bh
= NULL
;
2778 const struct elf_backend_data
*bed
2779 = get_elf_backend_data (output_bfd
);
2781 if (!(_bfd_generic_link_add_one_symbol
2782 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2783 tls_sec
, 0, NULL
, FALSE
,
2784 bed
->collect
, &bh
)))
2787 elf_i386_hash_table (info
)->tls_module_base
= bh
;
2789 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2790 tlsbase
->def_regular
= 1;
2791 tlsbase
->other
= STV_HIDDEN
;
2792 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2799 /* Set the correct type for an x86 ELF section. We do this by the
2800 section name, which is a hack, but ought to work. */
2803 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2804 Elf_Internal_Shdr
*hdr
,
2807 register const char *name
;
2809 name
= bfd_get_section_name (abfd
, sec
);
2811 /* This is an ugly, but unfortunately necessary hack that is
2812 needed when producing EFI binaries on x86. It tells
2813 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2814 containing ELF relocation info. We need this hack in order to
2815 be able to generate ELF binaries that can be translated into
2816 EFI applications (which are essentially COFF objects). Those
2817 files contain a COFF ".reloc" section inside an ELFNN object,
2818 which would normally cause BFD to segfault because it would
2819 attempt to interpret this section as containing relocation
2820 entries for section "oc". With this hack enabled, ".reloc"
2821 will be treated as a normal data section, which will avoid the
2822 segfault. However, you won't be able to create an ELFNN binary
2823 with a section named "oc" that needs relocations, but that's
2824 the kind of ugly side-effects you get when detecting section
2825 types based on their names... In practice, this limitation is
2826 unlikely to bite. */
2827 if (strcmp (name
, ".reloc") == 0)
2828 hdr
->sh_type
= SHT_PROGBITS
;
2833 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2834 executables. Rather than setting it to the beginning of the TLS
2835 section, we have to set it to the end. This function may be called
2836 multiple times, it is idempotent. */
2839 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2841 struct bfd_link_hash_entry
*base
;
2843 if (!info
->executable
)
2846 base
= elf_i386_hash_table (info
)->tls_module_base
;
2851 base
->u
.def
.value
= elf_hash_table (info
)->tls_size
;
2854 /* Return the base VMA address which should be subtracted from real addresses
2855 when resolving @dtpoff relocation.
2856 This is PT_TLS segment p_vaddr. */
2859 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2861 /* If tls_sec is NULL, we should have signalled an error already. */
2862 if (elf_hash_table (info
)->tls_sec
== NULL
)
2864 return elf_hash_table (info
)->tls_sec
->vma
;
2867 /* Return the relocation value for @tpoff relocation
2868 if STT_TLS virtual address is ADDRESS. */
2871 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2873 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2875 /* If tls_sec is NULL, we should have signalled an error already. */
2876 if (htab
->tls_sec
== NULL
)
2878 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2881 /* Relocate an i386 ELF section. */
2884 elf_i386_relocate_section (bfd
*output_bfd
,
2885 struct bfd_link_info
*info
,
2887 asection
*input_section
,
2889 Elf_Internal_Rela
*relocs
,
2890 Elf_Internal_Sym
*local_syms
,
2891 asection
**local_sections
)
2893 struct elf_i386_link_hash_table
*htab
;
2894 Elf_Internal_Shdr
*symtab_hdr
;
2895 struct elf_link_hash_entry
**sym_hashes
;
2896 bfd_vma
*local_got_offsets
;
2897 bfd_vma
*local_tlsdesc_gotents
;
2898 Elf_Internal_Rela
*rel
;
2899 Elf_Internal_Rela
*relend
;
2900 bfd_boolean is_vxworks_tls
;
2902 BFD_ASSERT (is_i386_elf (input_bfd
));
2904 htab
= elf_i386_hash_table (info
);
2905 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2906 sym_hashes
= elf_sym_hashes (input_bfd
);
2907 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2908 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2909 /* We have to handle relocations in vxworks .tls_vars sections
2910 specially, because the dynamic loader is 'weird'. */
2911 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
2912 && !strcmp (input_section
->output_section
->name
,
2915 elf_i386_set_tls_module_base (info
);
2918 relend
= relocs
+ input_section
->reloc_count
;
2919 for (; rel
< relend
; rel
++)
2921 unsigned int r_type
;
2922 reloc_howto_type
*howto
;
2923 unsigned long r_symndx
;
2924 struct elf_link_hash_entry
*h
;
2925 Elf_Internal_Sym
*sym
;
2927 bfd_vma off
, offplt
;
2929 bfd_boolean unresolved_reloc
;
2930 bfd_reloc_status_type r
;
2934 r_type
= ELF32_R_TYPE (rel
->r_info
);
2935 if (r_type
== R_386_GNU_VTINHERIT
2936 || r_type
== R_386_GNU_VTENTRY
)
2939 if ((indx
= r_type
) >= R_386_standard
2940 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2941 >= R_386_ext
- R_386_standard
)
2942 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2943 >= R_386_irelative
- R_386_ext
))
2945 (*_bfd_error_handler
)
2946 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2947 input_bfd
, input_section
, r_type
);
2948 bfd_set_error (bfd_error_bad_value
);
2951 howto
= elf_howto_table
+ indx
;
2953 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2957 unresolved_reloc
= FALSE
;
2958 if (r_symndx
< symtab_hdr
->sh_info
)
2960 sym
= local_syms
+ r_symndx
;
2961 sec
= local_sections
[r_symndx
];
2962 relocation
= (sec
->output_section
->vma
2963 + sec
->output_offset
2966 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2967 && ((sec
->flags
& SEC_MERGE
) != 0
2968 || (info
->relocatable
2969 && sec
->output_offset
!= 0)))
2972 bfd_byte
*where
= contents
+ rel
->r_offset
;
2974 switch (howto
->size
)
2977 addend
= bfd_get_8 (input_bfd
, where
);
2978 if (howto
->pc_relative
)
2980 addend
= (addend
^ 0x80) - 0x80;
2985 addend
= bfd_get_16 (input_bfd
, where
);
2986 if (howto
->pc_relative
)
2988 addend
= (addend
^ 0x8000) - 0x8000;
2993 addend
= bfd_get_32 (input_bfd
, where
);
2994 if (howto
->pc_relative
)
2996 addend
= (addend
^ 0x80000000) - 0x80000000;
3004 if (info
->relocatable
)
3005 addend
+= sec
->output_offset
;
3008 asection
*msec
= sec
;
3009 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3011 addend
-= relocation
;
3012 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3015 switch (howto
->size
)
3018 /* FIXME: overflow checks. */
3019 if (howto
->pc_relative
)
3021 bfd_put_8 (input_bfd
, addend
, where
);
3024 if (howto
->pc_relative
)
3026 bfd_put_16 (input_bfd
, addend
, where
);
3029 if (howto
->pc_relative
)
3031 bfd_put_32 (input_bfd
, addend
, where
);
3035 else if (ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3037 /* Relocate against local STT_GNU_IFUNC symbol. */
3038 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
,
3043 /* Set STT_GNU_IFUNC symbol value. */
3044 h
->root
.u
.def
.value
= sym
->st_value
;
3045 h
->root
.u
.def
.section
= sec
;
3052 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3053 r_symndx
, symtab_hdr
, sym_hashes
,
3055 unresolved_reloc
, warned
);
3058 if (sec
!= NULL
&& elf_discarded_section (sec
))
3060 /* For relocs against symbols from removed linkonce sections,
3061 or sections discarded by a linker script, we just want the
3062 section contents zeroed. Avoid any special processing. */
3063 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
3069 if (info
->relocatable
)
3072 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3073 it here if it is defined in a non-shared object. */
3075 && h
->type
== STT_GNU_IFUNC
3078 asection
*plt
, *gotplt
, *base_got
;
3081 if ((input_section
->flags
& SEC_ALLOC
) == 0
3082 || h
->plt
.offset
== (bfd_vma
) -1)
3085 /* STT_GNU_IFUNC symbol must go through PLT. */
3086 if (htab
->elf
.splt
!= NULL
)
3088 plt
= htab
->elf
.splt
;
3089 gotplt
= htab
->elf
.sgotplt
;
3093 plt
= htab
->elf
.iplt
;
3094 gotplt
= htab
->elf
.igotplt
;
3097 relocation
= (plt
->output_section
->vma
3098 + plt
->output_offset
+ h
->plt
.offset
);
3103 (*_bfd_error_handler
)
3104 (_("%B: relocation %s against STT_GNU_IFUNC "
3105 "symbol `%s' isn't handled by %s"), input_bfd
,
3106 elf_howto_table
[r_type
].name
,
3107 (h
->root
.root
.string
3108 ? h
->root
.root
.string
: "a local symbol"),
3110 bfd_set_error (bfd_error_bad_value
);
3114 /* Generate dynamic relcoation only when there is a
3115 non-GOF reference in a shared object. */
3116 if (info
->shared
&& h
->non_got_ref
)
3118 Elf_Internal_Rela outrel
;
3123 /* Need a dynamic relocation to get the real function
3125 offset
= _bfd_elf_section_offset (output_bfd
,
3129 if (offset
== (bfd_vma
) -1
3130 || offset
== (bfd_vma
) -2)
3133 outrel
.r_offset
= (input_section
->output_section
->vma
3134 + input_section
->output_offset
3137 if (h
->dynindx
== -1
3139 || info
->executable
)
3141 /* This symbol is resolved locally. */
3142 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3143 bfd_put_32 (output_bfd
,
3144 (h
->root
.u
.def
.value
3145 + h
->root
.u
.def
.section
->output_section
->vma
3146 + h
->root
.u
.def
.section
->output_offset
),
3150 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3152 sreloc
= htab
->elf
.irelifunc
;
3153 loc
= sreloc
->contents
;
3154 loc
+= (sreloc
->reloc_count
++
3155 * sizeof (Elf32_External_Rel
));
3156 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3158 /* If this reloc is against an external symbol, we
3159 do not want to fiddle with the addend. Otherwise,
3160 we need to include the symbol value so that it
3161 becomes an addend for the dynamic reloc. For an
3162 internal symbol, we have updated addend. */
3171 base_got
= htab
->elf
.sgot
;
3172 off
= h
->got
.offset
;
3174 if (base_got
== NULL
)
3177 if (off
== (bfd_vma
) -1)
3179 /* We can't use h->got.offset here to save state, or
3180 even just remember the offset, as finish_dynamic_symbol
3181 would use that as offset into .got. */
3183 if (htab
->elf
.splt
!= NULL
)
3185 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3186 off
= (plt_index
+ 3) * 4;
3187 base_got
= htab
->elf
.sgotplt
;
3191 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3192 off
= plt_index
* 4;
3193 base_got
= htab
->elf
.igotplt
;
3196 if (h
->dynindx
== -1
3200 /* This references the local defitionion. We must
3201 initialize this entry in the global offset table.
3202 Since the offset must always be a multiple of 8,
3203 we use the least significant bit to record
3204 whether we have initialized it already.
3206 When doing a dynamic link, we create a .rela.got
3207 relocation entry to initialize the value. This
3208 is done in the finish_dynamic_symbol routine. */
3213 bfd_put_32 (output_bfd
, relocation
,
3214 base_got
->contents
+ off
);
3221 /* Adjust for static executables. */
3222 if (htab
->elf
.splt
== NULL
)
3223 relocation
+= gotplt
->output_offset
;
3227 relocation
= (base_got
->output_section
->vma
3228 + base_got
->output_offset
+ off
3229 - gotplt
->output_section
->vma
3230 - gotplt
->output_offset
);
3231 /* Adjust for static executables. */
3232 if (htab
->elf
.splt
== NULL
)
3233 relocation
+= gotplt
->output_offset
;
3239 relocation
-= (gotplt
->output_section
->vma
3240 + gotplt
->output_offset
);
3248 /* Relocation is to the entry for this symbol in the global
3250 if (htab
->elf
.sgot
== NULL
)
3257 off
= h
->got
.offset
;
3258 dyn
= htab
->elf
.dynamic_sections_created
;
3259 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3261 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3262 || (ELF_ST_VISIBILITY (h
->other
)
3263 && h
->root
.type
== bfd_link_hash_undefweak
))
3265 /* This is actually a static link, or it is a
3266 -Bsymbolic link and the symbol is defined
3267 locally, or the symbol was forced to be local
3268 because of a version file. We must initialize
3269 this entry in the global offset table. Since the
3270 offset must always be a multiple of 4, we use the
3271 least significant bit to record whether we have
3272 initialized it already.
3274 When doing a dynamic link, we create a .rel.got
3275 relocation entry to initialize the value. This
3276 is done in the finish_dynamic_symbol routine. */
3281 bfd_put_32 (output_bfd
, relocation
,
3282 htab
->elf
.sgot
->contents
+ off
);
3287 unresolved_reloc
= FALSE
;
3291 if (local_got_offsets
== NULL
)
3294 off
= local_got_offsets
[r_symndx
];
3296 /* The offset must always be a multiple of 4. We use
3297 the least significant bit to record whether we have
3298 already generated the necessary reloc. */
3303 bfd_put_32 (output_bfd
, relocation
,
3304 htab
->elf
.sgot
->contents
+ off
);
3309 Elf_Internal_Rela outrel
;
3312 s
= htab
->elf
.srelgot
;
3316 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3317 + htab
->elf
.sgot
->output_offset
3319 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3321 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3322 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3325 local_got_offsets
[r_symndx
] |= 1;
3329 if (off
>= (bfd_vma
) -2)
3332 relocation
= htab
->elf
.sgot
->output_section
->vma
3333 + htab
->elf
.sgot
->output_offset
+ off
3334 - htab
->elf
.sgotplt
->output_section
->vma
3335 - htab
->elf
.sgotplt
->output_offset
;
3339 /* Relocation is relative to the start of the global offset
3342 /* Check to make sure it isn't a protected function symbol
3343 for shared library since it may not be local when used
3344 as function address. We also need to make sure that a
3345 symbol is defined locally. */
3346 if (info
->shared
&& h
)
3348 if (!h
->def_regular
)
3352 switch (ELF_ST_VISIBILITY (h
->other
))
3355 v
= _("hidden symbol");
3358 v
= _("internal symbol");
3361 v
= _("protected symbol");
3368 (*_bfd_error_handler
)
3369 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3370 input_bfd
, v
, h
->root
.root
.string
);
3371 bfd_set_error (bfd_error_bad_value
);
3374 else if (!info
->executable
3375 && h
->type
== STT_FUNC
3376 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3378 (*_bfd_error_handler
)
3379 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3380 input_bfd
, h
->root
.root
.string
);
3381 bfd_set_error (bfd_error_bad_value
);
3386 /* Note that sgot is not involved in this
3387 calculation. We always want the start of .got.plt. If we
3388 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3389 permitted by the ABI, we might have to change this
3391 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3392 + htab
->elf
.sgotplt
->output_offset
;
3396 /* Use global offset table as symbol value. */
3397 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3398 + htab
->elf
.sgotplt
->output_offset
;
3399 unresolved_reloc
= FALSE
;
3403 /* Relocation is to the entry for this symbol in the
3404 procedure linkage table. */
3406 /* Resolve a PLT32 reloc against a local symbol directly,
3407 without using the procedure linkage table. */
3411 if (h
->plt
.offset
== (bfd_vma
) -1
3412 || htab
->elf
.splt
== NULL
)
3414 /* We didn't make a PLT entry for this symbol. This
3415 happens when statically linking PIC code, or when
3416 using -Bsymbolic. */
3420 relocation
= (htab
->elf
.splt
->output_section
->vma
3421 + htab
->elf
.splt
->output_offset
3423 unresolved_reloc
= FALSE
;
3428 if ((input_section
->flags
& SEC_ALLOC
) == 0
3434 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3435 || h
->root
.type
!= bfd_link_hash_undefweak
)
3436 && (r_type
!= R_386_PC32
3437 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3438 || (ELIMINATE_COPY_RELOCS
3445 || h
->root
.type
== bfd_link_hash_undefweak
3446 || h
->root
.type
== bfd_link_hash_undefined
)))
3448 Elf_Internal_Rela outrel
;
3450 bfd_boolean skip
, relocate
;
3453 /* When generating a shared object, these relocations
3454 are copied into the output file to be resolved at run
3461 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3463 if (outrel
.r_offset
== (bfd_vma
) -1)
3465 else if (outrel
.r_offset
== (bfd_vma
) -2)
3466 skip
= TRUE
, relocate
= TRUE
;
3467 outrel
.r_offset
+= (input_section
->output_section
->vma
3468 + input_section
->output_offset
);
3471 memset (&outrel
, 0, sizeof outrel
);
3474 && (r_type
== R_386_PC32
3476 || !SYMBOLIC_BIND (info
, h
)
3477 || !h
->def_regular
))
3478 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3481 /* This symbol is local, or marked to become local. */
3483 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3486 sreloc
= elf_section_data (input_section
)->sreloc
;
3488 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
3490 loc
= sreloc
->contents
;
3491 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3493 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3495 /* If this reloc is against an external symbol, we do
3496 not want to fiddle with the addend. Otherwise, we
3497 need to include the symbol value so that it becomes
3498 an addend for the dynamic reloc. */
3507 Elf_Internal_Rela outrel
;
3511 outrel
.r_offset
= rel
->r_offset
3512 + input_section
->output_section
->vma
3513 + input_section
->output_offset
;
3514 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3515 sreloc
= elf_section_data (input_section
)->sreloc
;
3518 loc
= sreloc
->contents
;
3519 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3520 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3525 case R_386_TLS_GOTDESC
:
3526 case R_386_TLS_DESC_CALL
:
3527 case R_386_TLS_IE_32
:
3528 case R_386_TLS_GOTIE
:
3529 tls_type
= GOT_UNKNOWN
;
3530 if (h
== NULL
&& local_got_offsets
)
3531 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3533 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3534 if (tls_type
== GOT_TLS_IE
)
3535 tls_type
= GOT_TLS_IE_NEG
;
3537 if (! elf_i386_tls_transition (info
, input_bfd
,
3538 input_section
, contents
,
3539 symtab_hdr
, sym_hashes
,
3540 &r_type
, tls_type
, rel
,
3544 if (r_type
== R_386_TLS_LE_32
)
3546 BFD_ASSERT (! unresolved_reloc
);
3547 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3552 /* GD->LE transition. */
3553 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3556 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3558 movl %gs:0, %eax; subl $foo@tpoff, %eax
3559 (6 byte form of subl). */
3560 memcpy (contents
+ rel
->r_offset
- 3,
3561 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3562 roff
= rel
->r_offset
+ 5;
3566 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3568 movl %gs:0, %eax; subl $foo@tpoff, %eax
3569 (6 byte form of subl). */
3570 memcpy (contents
+ rel
->r_offset
- 2,
3571 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3572 roff
= rel
->r_offset
+ 6;
3574 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3576 /* Skip R_386_PC32/R_386_PLT32. */
3580 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3582 /* GDesc -> LE transition.
3583 It's originally something like:
3584 leal x@tlsdesc(%ebx), %eax
3588 Registers other than %eax may be set up here. */
3593 roff
= rel
->r_offset
;
3594 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3596 /* Now modify the instruction as appropriate. */
3597 /* aoliva FIXME: remove the above and xor the byte
3599 bfd_put_8 (output_bfd
, val
^ 0x86,
3600 contents
+ roff
- 1);
3601 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3605 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3607 /* GDesc -> LE transition.
3615 roff
= rel
->r_offset
;
3616 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3617 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3620 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3624 /* IE->LE transition:
3625 Originally it can be one of:
3633 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3636 /* movl foo, %eax. */
3637 bfd_put_8 (output_bfd
, 0xb8,
3638 contents
+ rel
->r_offset
- 1);
3644 type
= bfd_get_8 (input_bfd
,
3645 contents
+ rel
->r_offset
- 2);
3650 bfd_put_8 (output_bfd
, 0xc7,
3651 contents
+ rel
->r_offset
- 2);
3652 bfd_put_8 (output_bfd
,
3653 0xc0 | ((val
>> 3) & 7),
3654 contents
+ rel
->r_offset
- 1);
3658 bfd_put_8 (output_bfd
, 0x81,
3659 contents
+ rel
->r_offset
- 2);
3660 bfd_put_8 (output_bfd
,
3661 0xc0 | ((val
>> 3) & 7),
3662 contents
+ rel
->r_offset
- 1);
3669 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3670 contents
+ rel
->r_offset
);
3675 unsigned int val
, type
;
3677 /* {IE_32,GOTIE}->LE transition:
3678 Originally it can be one of:
3679 subl foo(%reg1), %reg2
3680 movl foo(%reg1), %reg2
3681 addl foo(%reg1), %reg2
3684 movl $foo, %reg2 (6 byte form)
3685 addl $foo, %reg2. */
3686 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3687 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3691 bfd_put_8 (output_bfd
, 0xc7,
3692 contents
+ rel
->r_offset
- 2);
3693 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3694 contents
+ rel
->r_offset
- 1);
3696 else if (type
== 0x2b)
3699 bfd_put_8 (output_bfd
, 0x81,
3700 contents
+ rel
->r_offset
- 2);
3701 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3702 contents
+ rel
->r_offset
- 1);
3704 else if (type
== 0x03)
3707 bfd_put_8 (output_bfd
, 0x81,
3708 contents
+ rel
->r_offset
- 2);
3709 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3710 contents
+ rel
->r_offset
- 1);
3714 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3715 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3716 contents
+ rel
->r_offset
);
3718 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3719 contents
+ rel
->r_offset
);
3724 if (htab
->elf
.sgot
== NULL
)
3729 off
= h
->got
.offset
;
3730 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3734 if (local_got_offsets
== NULL
)
3737 off
= local_got_offsets
[r_symndx
];
3738 offplt
= local_tlsdesc_gotents
[r_symndx
];
3745 Elf_Internal_Rela outrel
;
3750 if (htab
->elf
.srelgot
== NULL
)
3753 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3755 if (GOT_TLS_GDESC_P (tls_type
))
3757 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3758 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3759 <= htab
->elf
.sgotplt
->size
);
3760 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3761 + htab
->elf
.sgotplt
->output_offset
3763 + htab
->sgotplt_jump_table_size
);
3764 sreloc
= htab
->elf
.srelplt
;
3765 loc
= sreloc
->contents
;
3766 loc
+= (htab
->next_tls_desc_index
++
3767 * sizeof (Elf32_External_Rel
));
3768 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3769 <= sreloc
->contents
+ sreloc
->size
);
3770 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3773 BFD_ASSERT (! unresolved_reloc
);
3774 bfd_put_32 (output_bfd
,
3775 relocation
- elf_i386_dtpoff_base (info
),
3776 htab
->elf
.sgotplt
->contents
+ offplt
3777 + htab
->sgotplt_jump_table_size
+ 4);
3781 bfd_put_32 (output_bfd
, 0,
3782 htab
->elf
.sgotplt
->contents
+ offplt
3783 + htab
->sgotplt_jump_table_size
+ 4);
3787 sreloc
= htab
->elf
.srelgot
;
3789 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3790 + htab
->elf
.sgot
->output_offset
+ off
);
3792 if (GOT_TLS_GD_P (tls_type
))
3793 dr_type
= R_386_TLS_DTPMOD32
;
3794 else if (GOT_TLS_GDESC_P (tls_type
))
3796 else if (tls_type
== GOT_TLS_IE_POS
)
3797 dr_type
= R_386_TLS_TPOFF
;
3799 dr_type
= R_386_TLS_TPOFF32
;
3801 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3802 bfd_put_32 (output_bfd
,
3803 relocation
- elf_i386_dtpoff_base (info
),
3804 htab
->elf
.sgot
->contents
+ off
);
3805 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3806 bfd_put_32 (output_bfd
,
3807 elf_i386_dtpoff_base (info
) - relocation
,
3808 htab
->elf
.sgot
->contents
+ off
);
3809 else if (dr_type
!= R_386_TLS_DESC
)
3810 bfd_put_32 (output_bfd
, 0,
3811 htab
->elf
.sgot
->contents
+ off
);
3812 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3814 loc
= sreloc
->contents
;
3815 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3816 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3817 <= sreloc
->contents
+ sreloc
->size
);
3818 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3820 if (GOT_TLS_GD_P (tls_type
))
3824 BFD_ASSERT (! unresolved_reloc
);
3825 bfd_put_32 (output_bfd
,
3826 relocation
- elf_i386_dtpoff_base (info
),
3827 htab
->elf
.sgot
->contents
+ off
+ 4);
3831 bfd_put_32 (output_bfd
, 0,
3832 htab
->elf
.sgot
->contents
+ off
+ 4);
3833 outrel
.r_info
= ELF32_R_INFO (indx
,
3834 R_386_TLS_DTPOFF32
);
3835 outrel
.r_offset
+= 4;
3836 sreloc
->reloc_count
++;
3837 loc
+= sizeof (Elf32_External_Rel
);
3838 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3839 <= sreloc
->contents
+ sreloc
->size
);
3840 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3843 else if (tls_type
== GOT_TLS_IE_BOTH
)
3845 bfd_put_32 (output_bfd
,
3847 ? relocation
- elf_i386_dtpoff_base (info
)
3849 htab
->elf
.sgot
->contents
+ off
+ 4);
3850 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3851 outrel
.r_offset
+= 4;
3852 sreloc
->reloc_count
++;
3853 loc
+= sizeof (Elf32_External_Rel
);
3854 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3861 local_got_offsets
[r_symndx
] |= 1;
3864 if (off
>= (bfd_vma
) -2
3865 && ! GOT_TLS_GDESC_P (tls_type
))
3867 if (r_type
== R_386_TLS_GOTDESC
3868 || r_type
== R_386_TLS_DESC_CALL
)
3870 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3871 unresolved_reloc
= FALSE
;
3873 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3875 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3876 + htab
->elf
.sgotplt
->output_offset
;
3877 relocation
= htab
->elf
.sgot
->output_section
->vma
3878 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3879 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3880 && tls_type
== GOT_TLS_IE_BOTH
)
3882 if (r_type
== R_386_TLS_IE
)
3883 relocation
+= g_o_t
;
3884 unresolved_reloc
= FALSE
;
3886 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3888 unsigned int val
, type
;
3891 /* GD->IE transition. */
3892 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3893 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3896 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3898 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3900 roff
= rel
->r_offset
- 3;
3904 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3906 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3907 roff
= rel
->r_offset
- 2;
3909 memcpy (contents
+ roff
,
3910 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3911 contents
[roff
+ 7] = 0x80 | (val
& 7);
3912 /* If foo is used only with foo@gotntpoff(%reg) and
3913 foo@indntpoff, but not with foo@gottpoff(%reg), change
3914 subl $foo@gottpoff(%reg), %eax
3916 addl $foo@gotntpoff(%reg), %eax. */
3917 if (tls_type
== GOT_TLS_IE_POS
)
3918 contents
[roff
+ 6] = 0x03;
3919 bfd_put_32 (output_bfd
,
3920 htab
->elf
.sgot
->output_section
->vma
3921 + htab
->elf
.sgot
->output_offset
+ off
3922 - htab
->elf
.sgotplt
->output_section
->vma
3923 - htab
->elf
.sgotplt
->output_offset
,
3924 contents
+ roff
+ 8);
3925 /* Skip R_386_PLT32. */
3929 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3931 /* GDesc -> IE transition.
3932 It's originally something like:
3933 leal x@tlsdesc(%ebx), %eax
3936 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3938 movl x@gottpoff(%ebx), %eax # before negl %eax
3940 Registers other than %eax may be set up here. */
3944 /* First, make sure it's a leal adding ebx to a 32-bit
3945 offset into any register, although it's probably
3946 almost always going to be eax. */
3947 roff
= rel
->r_offset
;
3949 /* Now modify the instruction as appropriate. */
3950 /* To turn a leal into a movl in the form we use it, it
3951 suffices to change the first byte from 0x8d to 0x8b.
3952 aoliva FIXME: should we decide to keep the leal, all
3953 we have to do is remove the statement below, and
3954 adjust the relaxation of R_386_TLS_DESC_CALL. */
3955 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3957 if (tls_type
== GOT_TLS_IE_BOTH
)
3960 bfd_put_32 (output_bfd
,
3961 htab
->elf
.sgot
->output_section
->vma
3962 + htab
->elf
.sgot
->output_offset
+ off
3963 - htab
->elf
.sgotplt
->output_section
->vma
3964 - htab
->elf
.sgotplt
->output_offset
,
3968 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3970 /* GDesc -> IE transition.
3978 depending on how we transformed the TLS_GOTDESC above.
3983 roff
= rel
->r_offset
;
3985 /* Now modify the instruction as appropriate. */
3986 if (tls_type
!= GOT_TLS_IE_NEG
)
3989 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3990 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3995 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3996 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4006 if (! elf_i386_tls_transition (info
, input_bfd
,
4007 input_section
, contents
,
4008 symtab_hdr
, sym_hashes
,
4009 &r_type
, GOT_UNKNOWN
, rel
,
4013 if (r_type
!= R_386_TLS_LDM
)
4015 /* LD->LE transition:
4016 leal foo(%reg), %eax; call ___tls_get_addr.
4018 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
4019 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4020 memcpy (contents
+ rel
->r_offset
- 2,
4021 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4022 /* Skip R_386_PC32/R_386_PLT32. */
4027 if (htab
->elf
.sgot
== NULL
)
4030 off
= htab
->tls_ldm_got
.offset
;
4035 Elf_Internal_Rela outrel
;
4038 if (htab
->elf
.srelgot
== NULL
)
4041 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4042 + htab
->elf
.sgot
->output_offset
+ off
);
4044 bfd_put_32 (output_bfd
, 0,
4045 htab
->elf
.sgot
->contents
+ off
);
4046 bfd_put_32 (output_bfd
, 0,
4047 htab
->elf
.sgot
->contents
+ off
+ 4);
4048 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4049 loc
= htab
->elf
.srelgot
->contents
;
4050 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4051 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4052 htab
->tls_ldm_got
.offset
|= 1;
4054 relocation
= htab
->elf
.sgot
->output_section
->vma
4055 + htab
->elf
.sgot
->output_offset
+ off
4056 - htab
->elf
.sgotplt
->output_section
->vma
4057 - htab
->elf
.sgotplt
->output_offset
;
4058 unresolved_reloc
= FALSE
;
4061 case R_386_TLS_LDO_32
:
4062 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
4063 relocation
-= elf_i386_dtpoff_base (info
);
4065 /* When converting LDO to LE, we must negate. */
4066 relocation
= -elf_i386_tpoff (info
, relocation
);
4069 case R_386_TLS_LE_32
:
4073 Elf_Internal_Rela outrel
;
4078 outrel
.r_offset
= rel
->r_offset
4079 + input_section
->output_section
->vma
4080 + input_section
->output_offset
;
4081 if (h
!= NULL
&& h
->dynindx
!= -1)
4085 if (r_type
== R_386_TLS_LE_32
)
4086 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4088 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4089 sreloc
= elf_section_data (input_section
)->sreloc
;
4092 loc
= sreloc
->contents
;
4093 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4094 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4097 else if (r_type
== R_386_TLS_LE_32
)
4098 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4100 relocation
-= elf_i386_dtpoff_base (info
);
4102 else if (r_type
== R_386_TLS_LE_32
)
4103 relocation
= elf_i386_tpoff (info
, relocation
);
4105 relocation
= -elf_i386_tpoff (info
, relocation
);
4112 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4113 because such sections are not SEC_ALLOC and thus ld.so will
4114 not process them. */
4115 if (unresolved_reloc
4116 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4119 (*_bfd_error_handler
)
4120 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4123 (long) rel
->r_offset
,
4125 h
->root
.root
.string
);
4130 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4131 contents
, rel
->r_offset
,
4134 if (r
!= bfd_reloc_ok
)
4139 name
= h
->root
.root
.string
;
4142 name
= bfd_elf_string_from_elf_section (input_bfd
,
4143 symtab_hdr
->sh_link
,
4148 name
= bfd_section_name (input_bfd
, sec
);
4151 if (r
== bfd_reloc_overflow
)
4153 if (! ((*info
->callbacks
->reloc_overflow
)
4154 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4155 (bfd_vma
) 0, input_bfd
, input_section
,
4161 (*_bfd_error_handler
)
4162 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4163 input_bfd
, input_section
,
4164 (long) rel
->r_offset
, name
, (int) r
);
4173 /* Finish up dynamic symbol handling. We set the contents of various
4174 dynamic sections here. */
4177 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4178 struct bfd_link_info
*info
,
4179 struct elf_link_hash_entry
*h
,
4180 Elf_Internal_Sym
*sym
)
4182 struct elf_i386_link_hash_table
*htab
;
4184 htab
= elf_i386_hash_table (info
);
4186 if (h
->plt
.offset
!= (bfd_vma
) -1)
4190 Elf_Internal_Rela rel
;
4192 asection
*plt
, *gotplt
, *relplt
;
4194 /* When building a static executable, use .iplt, .igot.plt and
4195 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4196 if (htab
->elf
.splt
!= NULL
)
4198 plt
= htab
->elf
.splt
;
4199 gotplt
= htab
->elf
.sgotplt
;
4200 relplt
= htab
->elf
.srelplt
;
4204 plt
= htab
->elf
.iplt
;
4205 gotplt
= htab
->elf
.igotplt
;
4206 relplt
= htab
->elf
.irelplt
;
4209 /* This symbol has an entry in the procedure linkage table. Set
4212 if ((h
->dynindx
== -1
4213 && !((h
->forced_local
|| info
->executable
)
4215 && h
->type
== STT_GNU_IFUNC
))
4221 /* Get the index in the procedure linkage table which
4222 corresponds to this symbol. This is the index of this symbol
4223 in all the symbols for which we are making plt entries. The
4224 first entry in the procedure linkage table is reserved.
4226 Get the offset into the .got table of the entry that
4227 corresponds to this function. Each .got entry is 4 bytes.
4228 The first three are reserved.
4230 For static executables, we don't reserve anything. */
4232 if (plt
== htab
->elf
.splt
)
4234 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
4235 got_offset
= (plt_index
+ 3) * 4;
4239 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4240 got_offset
= plt_index
* 4;
4243 /* Fill in the entry in the procedure linkage table. */
4246 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
4248 bfd_put_32 (output_bfd
,
4249 (gotplt
->output_section
->vma
4250 + gotplt
->output_offset
4252 plt
->contents
+ h
->plt
.offset
+ 2);
4254 if (htab
->is_vxworks
)
4256 int s
, k
, reloc_index
;
4258 /* Create the R_386_32 relocation referencing the GOT
4259 for this PLT entry. */
4261 /* S: Current slot number (zero-based). */
4262 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
4263 /* K: Number of relocations for PLTResolve. */
4265 k
= PLTRESOLVE_RELOCS_SHLIB
;
4267 k
= PLTRESOLVE_RELOCS
;
4268 /* Skip the PLTresolve relocations, and the relocations for
4269 the other PLT slots. */
4270 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4271 loc
= (htab
->srelplt2
->contents
+ reloc_index
4272 * sizeof (Elf32_External_Rel
));
4274 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4275 + htab
->elf
.splt
->output_offset
4276 + h
->plt
.offset
+ 2),
4277 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4278 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4280 /* Create the R_386_32 relocation referencing the beginning of
4281 the PLT for this GOT entry. */
4282 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4283 + htab
->elf
.sgotplt
->output_offset
4285 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4286 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4287 loc
+ sizeof (Elf32_External_Rel
));
4292 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
4294 bfd_put_32 (output_bfd
, got_offset
,
4295 plt
->contents
+ h
->plt
.offset
+ 2);
4298 /* Don't fill PLT entry for static executables. */
4299 if (plt
== htab
->elf
.splt
)
4301 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4302 plt
->contents
+ h
->plt
.offset
+ 7);
4303 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4304 plt
->contents
+ h
->plt
.offset
+ 12);
4307 /* Fill in the entry in the global offset table. */
4308 bfd_put_32 (output_bfd
,
4309 (plt
->output_section
->vma
4310 + plt
->output_offset
4313 gotplt
->contents
+ got_offset
);
4315 /* Fill in the entry in the .rel.plt section. */
4316 rel
.r_offset
= (gotplt
->output_section
->vma
4317 + gotplt
->output_offset
4319 if (h
->dynindx
== -1
4320 || ((info
->executable
4321 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4323 && h
->type
== STT_GNU_IFUNC
))
4325 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4326 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4327 in the .got.plt section. */
4328 bfd_put_32 (output_bfd
,
4329 (h
->root
.u
.def
.value
4330 + h
->root
.u
.def
.section
->output_section
->vma
4331 + h
->root
.u
.def
.section
->output_offset
),
4332 gotplt
->contents
+ got_offset
);
4333 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4336 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4337 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4338 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4340 if (!h
->def_regular
)
4342 /* Mark the symbol as undefined, rather than as defined in
4343 the .plt section. Leave the value if there were any
4344 relocations where pointer equality matters (this is a clue
4345 for the dynamic linker, to make function pointer
4346 comparisons work between an application and shared
4347 library), otherwise set it to zero. If a function is only
4348 called from a binary, there is no need to slow down
4349 shared libraries because of that. */
4350 sym
->st_shndx
= SHN_UNDEF
;
4351 if (!h
->pointer_equality_needed
)
4356 if (h
->got
.offset
!= (bfd_vma
) -1
4357 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4358 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4360 Elf_Internal_Rela rel
;
4363 /* This symbol has an entry in the global offset table. Set it
4366 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4369 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4370 + htab
->elf
.sgot
->output_offset
4371 + (h
->got
.offset
& ~(bfd_vma
) 1));
4373 /* If this is a static link, or it is a -Bsymbolic link and the
4374 symbol is defined locally or was forced to be local because
4375 of a version file, we just want to emit a RELATIVE reloc.
4376 The entry in the global offset table will already have been
4377 initialized in the relocate_section function. */
4379 && h
->type
== STT_GNU_IFUNC
)
4383 /* Generate R_386_GLOB_DAT. */
4388 if (!h
->pointer_equality_needed
)
4391 /* For non-shared object, we can't use .got.plt, which
4392 contains the real function addres if we need pointer
4393 equality. We load the GOT entry with the PLT entry. */
4394 asection
*plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4395 bfd_put_32 (output_bfd
,
4396 (plt
->output_section
->vma
4397 + plt
->output_offset
+ h
->plt
.offset
),
4398 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4402 else if (info
->shared
4403 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4405 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4406 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4410 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4412 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4413 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4414 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4417 loc
= htab
->elf
.srelgot
->contents
;
4418 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4419 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4424 Elf_Internal_Rela rel
;
4427 /* This symbol needs a copy reloc. Set it up. */
4429 if (h
->dynindx
== -1
4430 || (h
->root
.type
!= bfd_link_hash_defined
4431 && h
->root
.type
!= bfd_link_hash_defweak
)
4432 || htab
->srelbss
== NULL
)
4435 rel
.r_offset
= (h
->root
.u
.def
.value
4436 + h
->root
.u
.def
.section
->output_section
->vma
4437 + h
->root
.u
.def
.section
->output_offset
);
4438 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4439 loc
= htab
->srelbss
->contents
;
4440 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4441 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4444 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4445 be NULL for local symbols.
4447 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
4448 is relative to the ".got" section. */
4450 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4451 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
)))
4452 sym
->st_shndx
= SHN_ABS
;
4457 /* Finish up local dynamic symbol handling. We set the contents of
4458 various dynamic sections here. */
4461 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4463 struct elf_link_hash_entry
*h
4464 = (struct elf_link_hash_entry
*) *slot
;
4465 struct bfd_link_info
*info
4466 = (struct bfd_link_info
*) inf
;
4468 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4472 /* Used to decide how to sort relocs in an optimal manner for the
4473 dynamic linker, before writing them out. */
4475 static enum elf_reloc_type_class
4476 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4478 switch (ELF32_R_TYPE (rela
->r_info
))
4480 case R_386_RELATIVE
:
4481 return reloc_class_relative
;
4482 case R_386_JUMP_SLOT
:
4483 return reloc_class_plt
;
4485 return reloc_class_copy
;
4487 return reloc_class_normal
;
4491 /* Finish up the dynamic sections. */
4494 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4495 struct bfd_link_info
*info
)
4497 struct elf_i386_link_hash_table
*htab
;
4501 htab
= elf_i386_hash_table (info
);
4502 dynobj
= htab
->elf
.dynobj
;
4503 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4505 if (htab
->elf
.dynamic_sections_created
)
4507 Elf32_External_Dyn
*dyncon
, *dynconend
;
4509 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4512 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4513 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4514 for (; dyncon
< dynconend
; dyncon
++)
4516 Elf_Internal_Dyn dyn
;
4519 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4524 if (htab
->is_vxworks
4525 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4530 s
= htab
->elf
.sgotplt
;
4531 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4535 s
= htab
->elf
.srelplt
;
4536 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4540 s
= htab
->elf
.srelplt
;
4541 dyn
.d_un
.d_val
= s
->size
;
4545 /* My reading of the SVR4 ABI indicates that the
4546 procedure linkage table relocs (DT_JMPREL) should be
4547 included in the overall relocs (DT_REL). This is
4548 what Solaris does. However, UnixWare can not handle
4549 that case. Therefore, we override the DT_RELSZ entry
4550 here to make it not include the JMPREL relocs. */
4551 s
= htab
->elf
.srelplt
;
4554 dyn
.d_un
.d_val
-= s
->size
;
4558 /* We may not be using the standard ELF linker script.
4559 If .rel.plt is the first .rel section, we adjust
4560 DT_REL to not include it. */
4561 s
= htab
->elf
.srelplt
;
4564 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4566 dyn
.d_un
.d_ptr
+= s
->size
;
4570 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4573 /* Fill in the first entry in the procedure linkage table. */
4574 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4578 memcpy (htab
->elf
.splt
->contents
, elf_i386_pic_plt0_entry
,
4579 sizeof (elf_i386_pic_plt0_entry
));
4580 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
4581 htab
->plt0_pad_byte
,
4582 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
4586 memcpy (htab
->elf
.splt
->contents
, elf_i386_plt0_entry
,
4587 sizeof(elf_i386_plt0_entry
));
4588 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_plt0_entry
),
4589 htab
->plt0_pad_byte
,
4590 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
4591 bfd_put_32 (output_bfd
,
4592 (htab
->elf
.sgotplt
->output_section
->vma
4593 + htab
->elf
.sgotplt
->output_offset
4595 htab
->elf
.splt
->contents
+ 2);
4596 bfd_put_32 (output_bfd
,
4597 (htab
->elf
.sgotplt
->output_section
->vma
4598 + htab
->elf
.sgotplt
->output_offset
4600 htab
->elf
.splt
->contents
+ 8);
4602 if (htab
->is_vxworks
)
4604 Elf_Internal_Rela rel
;
4606 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4607 On IA32 we use REL relocations so the addend goes in
4608 the PLT directly. */
4609 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4610 + htab
->elf
.splt
->output_offset
4612 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4613 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4614 htab
->srelplt2
->contents
);
4615 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4616 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4617 + htab
->elf
.splt
->output_offset
4619 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4620 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4621 htab
->srelplt2
->contents
+
4622 sizeof (Elf32_External_Rel
));
4626 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4627 really seem like the right value. */
4628 elf_section_data (htab
->elf
.splt
->output_section
)
4629 ->this_hdr
.sh_entsize
= 4;
4631 /* Correct the .rel.plt.unloaded relocations. */
4632 if (htab
->is_vxworks
&& !info
->shared
)
4634 int num_plts
= (htab
->elf
.splt
->size
/ PLT_ENTRY_SIZE
) - 1;
4637 p
= htab
->srelplt2
->contents
;
4639 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4641 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4643 for (; num_plts
; num_plts
--)
4645 Elf_Internal_Rela rel
;
4646 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4647 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4648 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4649 p
+= sizeof (Elf32_External_Rel
);
4651 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4652 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4653 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4654 p
+= sizeof (Elf32_External_Rel
);
4660 if (htab
->elf
.sgotplt
)
4662 /* Fill in the first three entries in the global offset table. */
4663 if (htab
->elf
.sgotplt
->size
> 0)
4665 bfd_put_32 (output_bfd
,
4667 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4668 htab
->elf
.sgotplt
->contents
);
4669 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4670 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4673 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4676 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4677 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4679 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4680 htab_traverse (htab
->loc_hash_table
,
4681 elf_i386_finish_local_dynamic_symbol
,
4687 /* Return address for Ith PLT stub in section PLT, for relocation REL
4688 or (bfd_vma) -1 if it should not be included. */
4691 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4692 const arelent
*rel ATTRIBUTE_UNUSED
)
4694 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4697 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4700 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4702 if (h
->plt
.offset
!= (bfd_vma
) -1
4704 && !h
->pointer_equality_needed
)
4707 return _bfd_elf_hash_symbol (h
);
4710 /* Hook called by the linker routine which adds symbols from an object
4714 elf_i386_add_symbol_hook (bfd
* abfd ATTRIBUTE_UNUSED
,
4715 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4716 Elf_Internal_Sym
* sym
,
4717 const char ** namep ATTRIBUTE_UNUSED
,
4718 flagword
* flagsp ATTRIBUTE_UNUSED
,
4719 asection
** secp ATTRIBUTE_UNUSED
,
4720 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4722 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4723 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
4728 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4729 #define TARGET_LITTLE_NAME "elf32-i386"
4730 #define ELF_ARCH bfd_arch_i386
4731 #define ELF_MACHINE_CODE EM_386
4732 #define ELF_MAXPAGESIZE 0x1000
4734 #define elf_backend_can_gc_sections 1
4735 #define elf_backend_can_refcount 1
4736 #define elf_backend_want_got_plt 1
4737 #define elf_backend_plt_readonly 1
4738 #define elf_backend_want_plt_sym 0
4739 #define elf_backend_got_header_size 12
4741 /* Support RELA for objdump of prelink objects. */
4742 #define elf_info_to_howto elf_i386_info_to_howto_rel
4743 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4745 #define bfd_elf32_mkobject elf_i386_mkobject
4747 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4748 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4749 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4750 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4751 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4753 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4754 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4755 #define elf_backend_check_relocs elf_i386_check_relocs
4756 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4757 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4758 #define elf_backend_fake_sections elf_i386_fake_sections
4759 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4760 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4761 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4762 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4763 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4764 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4765 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4766 #define elf_backend_relocate_section elf_i386_relocate_section
4767 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4768 #define elf_backend_always_size_sections elf_i386_always_size_sections
4769 #define elf_backend_omit_section_dynsym \
4770 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4771 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4772 #define elf_backend_hash_symbol elf_i386_hash_symbol
4773 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4774 #undef elf_backend_post_process_headers
4775 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4777 #include "elf32-target.h"
4779 /* FreeBSD support. */
4781 #undef TARGET_LITTLE_SYM
4782 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4783 #undef TARGET_LITTLE_NAME
4784 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4786 #define ELF_OSABI ELFOSABI_FREEBSD
4788 /* The kernel recognizes executables as valid only if they carry a
4789 "FreeBSD" label in the ELF header. So we put this label on all
4790 executables and (for simplicity) also all other object files. */
4793 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4795 _bfd_elf_set_osabi (abfd
, info
);
4797 #ifdef OLD_FREEBSD_ABI_LABEL
4798 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4799 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4803 #undef elf_backend_post_process_headers
4804 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4806 #define elf32_bed elf32_i386_fbsd_bed
4808 #undef elf_backend_add_symbol_hook
4810 #include "elf32-target.h"
4812 /* VxWorks support. */
4814 #undef TARGET_LITTLE_SYM
4815 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
4816 #undef TARGET_LITTLE_NAME
4817 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4820 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
4822 static struct bfd_link_hash_table
*
4823 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
4825 struct bfd_link_hash_table
*ret
;
4826 struct elf_i386_link_hash_table
*htab
;
4828 ret
= elf_i386_link_hash_table_create (abfd
);
4831 htab
= (struct elf_i386_link_hash_table
*) ret
;
4832 htab
->is_vxworks
= 1;
4833 htab
->plt0_pad_byte
= 0x90;
4840 #undef elf_backend_relocs_compatible
4841 #undef elf_backend_post_process_headers
4842 #undef bfd_elf32_bfd_link_hash_table_create
4843 #define bfd_elf32_bfd_link_hash_table_create \
4844 elf_i386_vxworks_link_hash_table_create
4845 #undef elf_backend_add_symbol_hook
4846 #define elf_backend_add_symbol_hook \
4847 elf_vxworks_add_symbol_hook
4848 #undef elf_backend_link_output_symbol_hook
4849 #define elf_backend_link_output_symbol_hook \
4850 elf_vxworks_link_output_symbol_hook
4851 #undef elf_backend_emit_relocs
4852 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
4853 #undef elf_backend_final_write_processing
4854 #define elf_backend_final_write_processing \
4855 elf_vxworks_final_write_processing
4857 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
4859 #undef elf_backend_want_plt_sym
4860 #define elf_backend_want_plt_sym 1
4863 #define elf32_bed elf32_i386_vxworks_bed
4865 #include "elf32-target.h"