1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 /* i386 ELF linker hash entry. */
582 struct elf_i386_link_hash_entry
584 struct elf_link_hash_entry elf
;
586 /* Track dynamic relocs copied for this symbol. */
587 struct elf_dyn_relocs
*dyn_relocs
;
589 #define GOT_UNKNOWN 0
593 #define GOT_TLS_IE_POS 5
594 #define GOT_TLS_IE_NEG 6
595 #define GOT_TLS_IE_BOTH 7
596 #define GOT_TLS_GDESC 8
597 #define GOT_TLS_GD_BOTH_P(type) \
598 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
599 #define GOT_TLS_GD_P(type) \
600 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
601 #define GOT_TLS_GDESC_P(type) \
602 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
603 #define GOT_TLS_GD_ANY_P(type) \
604 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
605 unsigned char tls_type
;
607 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
608 starting at the end of the jump table. */
612 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
614 struct elf_i386_obj_tdata
616 struct elf_obj_tdata root
;
618 /* tls_type for each local got entry. */
619 char *local_got_tls_type
;
621 /* GOTPLT entries for TLS descriptors. */
622 bfd_vma
*local_tlsdesc_gotent
;
625 #define elf_i386_tdata(abfd) \
626 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
628 #define elf_i386_local_got_tls_type(abfd) \
629 (elf_i386_tdata (abfd)->local_got_tls_type)
631 #define elf_i386_local_tlsdesc_gotent(abfd) \
632 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
634 #define is_i386_elf(bfd) \
635 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
636 && elf_tdata (bfd) != NULL \
637 && elf_object_id (bfd) == I386_ELF_DATA)
640 elf_i386_mkobject (bfd
*abfd
)
642 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
646 /* i386 ELF linker hash table. */
648 struct elf_i386_link_hash_table
650 struct elf_link_hash_table elf
;
652 /* Short-cuts to get to dynamic linker sections. */
658 bfd_signed_vma refcount
;
662 /* The amount of space used by the reserved portion of the sgotplt
663 section, plus whatever space is used by the jump slots. */
664 bfd_vma sgotplt_jump_table_size
;
666 /* Small local sym cache. */
667 struct sym_cache sym_cache
;
669 /* _TLS_MODULE_BASE_ symbol. */
670 struct bfd_link_hash_entry
*tls_module_base
;
672 /* Used by local STT_GNU_IFUNC symbols. */
673 htab_t loc_hash_table
;
674 void * loc_hash_memory
;
676 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
679 /* True if the target system is VxWorks. */
682 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
683 bfd_vma next_tls_desc_index
;
685 /* Value used to fill the last word of the first plt entry. */
686 bfd_byte plt0_pad_byte
;
689 /* Get the i386 ELF linker hash table from a link_info structure. */
691 #define elf_i386_hash_table(p) \
692 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
693 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
695 #define elf_i386_compute_jump_table_size(htab) \
696 ((htab)->next_tls_desc_index * 4)
698 /* Create an entry in an i386 ELF linker hash table. */
700 static struct bfd_hash_entry
*
701 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
702 struct bfd_hash_table
*table
,
705 /* Allocate the structure if it has not already been allocated by a
709 entry
= (struct bfd_hash_entry
*)
710 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
715 /* Call the allocation method of the superclass. */
716 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
719 struct elf_i386_link_hash_entry
*eh
;
721 eh
= (struct elf_i386_link_hash_entry
*) entry
;
722 eh
->dyn_relocs
= NULL
;
723 eh
->tls_type
= GOT_UNKNOWN
;
724 eh
->tlsdesc_got
= (bfd_vma
) -1;
730 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
731 for local symbol so that we can handle local STT_GNU_IFUNC symbols
732 as global symbol. We reuse indx and dynstr_index for local symbol
733 hash since they aren't used by global symbols in this backend. */
736 elf_i386_local_htab_hash (const void *ptr
)
738 struct elf_link_hash_entry
*h
739 = (struct elf_link_hash_entry
*) ptr
;
740 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
743 /* Compare local hash entries. */
746 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
748 struct elf_link_hash_entry
*h1
749 = (struct elf_link_hash_entry
*) ptr1
;
750 struct elf_link_hash_entry
*h2
751 = (struct elf_link_hash_entry
*) ptr2
;
753 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
756 /* Find and/or create a hash entry for local symbol. */
758 static struct elf_link_hash_entry
*
759 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
760 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
763 struct elf_i386_link_hash_entry e
, *ret
;
764 asection
*sec
= abfd
->sections
;
765 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
766 ELF32_R_SYM (rel
->r_info
));
769 e
.elf
.indx
= sec
->id
;
770 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
771 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
772 create
? INSERT
: NO_INSERT
);
779 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
783 ret
= (struct elf_i386_link_hash_entry
*)
784 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
785 sizeof (struct elf_i386_link_hash_entry
));
788 memset (ret
, 0, sizeof (*ret
));
789 ret
->elf
.indx
= sec
->id
;
790 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
791 ret
->elf
.dynindx
= -1;
792 ret
->elf
.plt
.offset
= (bfd_vma
) -1;
793 ret
->elf
.got
.offset
= (bfd_vma
) -1;
799 /* Create an i386 ELF linker hash table. */
801 static struct bfd_link_hash_table
*
802 elf_i386_link_hash_table_create (bfd
*abfd
)
804 struct elf_i386_link_hash_table
*ret
;
805 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
807 ret
= (struct elf_i386_link_hash_table
*) bfd_malloc (amt
);
811 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
812 elf_i386_link_hash_newfunc
,
813 sizeof (struct elf_i386_link_hash_entry
),
822 ret
->tls_ldm_got
.refcount
= 0;
823 ret
->next_tls_desc_index
= 0;
824 ret
->sgotplt_jump_table_size
= 0;
825 ret
->sym_cache
.abfd
= NULL
;
827 ret
->srelplt2
= NULL
;
828 ret
->plt0_pad_byte
= 0;
829 ret
->tls_module_base
= NULL
;
831 ret
->loc_hash_table
= htab_try_create (1024,
832 elf_i386_local_htab_hash
,
833 elf_i386_local_htab_eq
,
835 ret
->loc_hash_memory
= objalloc_create ();
836 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
842 return &ret
->elf
.root
;
845 /* Destroy an i386 ELF linker hash table. */
848 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
850 struct elf_i386_link_hash_table
*htab
851 = (struct elf_i386_link_hash_table
*) hash
;
853 if (htab
->loc_hash_table
)
854 htab_delete (htab
->loc_hash_table
);
855 if (htab
->loc_hash_memory
)
856 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
857 _bfd_generic_link_hash_table_free (hash
);
860 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
861 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
865 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
867 struct elf_i386_link_hash_table
*htab
;
869 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
872 htab
= elf_i386_hash_table (info
);
876 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
878 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
881 || (!info
->shared
&& !htab
->srelbss
))
885 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
892 /* Copy the extra info we tack onto an elf_link_hash_entry. */
895 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
896 struct elf_link_hash_entry
*dir
,
897 struct elf_link_hash_entry
*ind
)
899 struct elf_i386_link_hash_entry
*edir
, *eind
;
901 edir
= (struct elf_i386_link_hash_entry
*) dir
;
902 eind
= (struct elf_i386_link_hash_entry
*) ind
;
904 if (eind
->dyn_relocs
!= NULL
)
906 if (edir
->dyn_relocs
!= NULL
)
908 struct elf_dyn_relocs
**pp
;
909 struct elf_dyn_relocs
*p
;
911 /* Add reloc counts against the indirect sym to the direct sym
912 list. Merge any entries against the same section. */
913 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
915 struct elf_dyn_relocs
*q
;
917 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
918 if (q
->sec
== p
->sec
)
920 q
->pc_count
+= p
->pc_count
;
921 q
->count
+= p
->count
;
928 *pp
= edir
->dyn_relocs
;
931 edir
->dyn_relocs
= eind
->dyn_relocs
;
932 eind
->dyn_relocs
= NULL
;
935 if (ind
->root
.type
== bfd_link_hash_indirect
936 && dir
->got
.refcount
<= 0)
938 edir
->tls_type
= eind
->tls_type
;
939 eind
->tls_type
= GOT_UNKNOWN
;
942 if (ELIMINATE_COPY_RELOCS
943 && ind
->root
.type
!= bfd_link_hash_indirect
944 && dir
->dynamic_adjusted
)
946 /* If called to transfer flags for a weakdef during processing
947 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
948 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
949 dir
->ref_dynamic
|= ind
->ref_dynamic
;
950 dir
->ref_regular
|= ind
->ref_regular
;
951 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
952 dir
->needs_plt
|= ind
->needs_plt
;
953 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
956 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
966 /* Return TRUE if the TLS access code sequence support transition
970 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
972 Elf_Internal_Shdr
*symtab_hdr
,
973 struct elf_link_hash_entry
**sym_hashes
,
975 const Elf_Internal_Rela
*rel
,
976 const Elf_Internal_Rela
*relend
)
978 unsigned int val
, type
;
979 unsigned long r_symndx
;
980 struct elf_link_hash_entry
*h
;
983 /* Get the section contents. */
984 if (contents
== NULL
)
986 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
987 contents
= elf_section_data (sec
)->this_hdr
.contents
;
990 /* FIXME: How to better handle error condition? */
991 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
994 /* Cache the section contents for elf_link_input_bfd. */
995 elf_section_data (sec
)->this_hdr
.contents
= contents
;
999 offset
= rel
->r_offset
;
1004 if (offset
< 2 || (rel
+ 1) >= relend
)
1007 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1008 if (r_type
== R_386_TLS_GD
)
1010 /* Check transition from GD access model. Only
1011 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1012 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1013 can transit to different access model. */
1014 if ((offset
+ 10) > sec
->size
||
1015 (type
!= 0x8d && type
!= 0x04))
1018 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1021 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1025 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1028 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1033 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1034 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1037 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1043 /* Check transition from LD access model. Only
1044 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1045 can transit to different access model. */
1046 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1049 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1050 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1054 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1057 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1058 if (r_symndx
< symtab_hdr
->sh_info
)
1061 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1062 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1063 may be versioned. */
1065 && h
->root
.root
.string
!= NULL
1066 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1067 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1068 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1072 /* Check transition from IE access model:
1073 movl foo@indntpoff(%rip), %eax
1074 movl foo@indntpoff(%rip), %reg
1075 addl foo@indntpoff(%rip), %reg
1078 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1081 /* Check "movl foo@tpoff(%rip), %eax" first. */
1082 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1089 /* Check movl|addl foo@tpoff(%rip), %reg. */
1090 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1091 return ((type
== 0x8b || type
== 0x03)
1092 && (val
& 0xc7) == 0x05);
1094 case R_386_TLS_GOTIE
:
1095 case R_386_TLS_IE_32
:
1096 /* Check transition from {IE_32,GOTIE} access model:
1097 subl foo@{tpoff,gontoff}(%reg1), %reg2
1098 movl foo@{tpoff,gontoff}(%reg1), %reg2
1099 addl foo@{tpoff,gontoff}(%reg1), %reg2
1102 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1105 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1106 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1109 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1110 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1112 case R_386_TLS_GOTDESC
:
1113 /* Check transition from GDesc access model:
1114 leal x@tlsdesc(%ebx), %eax
1116 Make sure it's a leal adding ebx to a 32-bit offset
1117 into any register, although it's probably almost always
1120 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1123 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1126 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1127 return (val
& 0xc7) == 0x83;
1129 case R_386_TLS_DESC_CALL
:
1130 /* Check transition from GDesc access model:
1131 call *x@tlsdesc(%rax)
1133 if (offset
+ 2 <= sec
->size
)
1135 /* Make sure that it's a call *x@tlsdesc(%rax). */
1136 static i386_opcode16 call
= { { 0xff, 0x10 } };
1137 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1147 /* Return TRUE if the TLS access transition is OK or no transition
1148 will be performed. Update R_TYPE if there is a transition. */
1151 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1152 asection
*sec
, bfd_byte
*contents
,
1153 Elf_Internal_Shdr
*symtab_hdr
,
1154 struct elf_link_hash_entry
**sym_hashes
,
1155 unsigned int *r_type
, int tls_type
,
1156 const Elf_Internal_Rela
*rel
,
1157 const Elf_Internal_Rela
*relend
,
1158 struct elf_link_hash_entry
*h
,
1159 unsigned long r_symndx
)
1161 unsigned int from_type
= *r_type
;
1162 unsigned int to_type
= from_type
;
1163 bfd_boolean check
= TRUE
;
1168 case R_386_TLS_GOTDESC
:
1169 case R_386_TLS_DESC_CALL
:
1170 case R_386_TLS_IE_32
:
1172 case R_386_TLS_GOTIE
:
1173 if (info
->executable
)
1176 to_type
= R_386_TLS_LE_32
;
1177 else if (from_type
!= R_386_TLS_IE
1178 && from_type
!= R_386_TLS_GOTIE
)
1179 to_type
= R_386_TLS_IE_32
;
1182 /* When we are called from elf_i386_relocate_section, CONTENTS
1183 isn't NULL and there may be additional transitions based on
1185 if (contents
!= NULL
)
1187 unsigned int new_to_type
= to_type
;
1189 if (info
->executable
1192 && (tls_type
& GOT_TLS_IE
))
1193 new_to_type
= R_386_TLS_LE_32
;
1195 if (to_type
== R_386_TLS_GD
1196 || to_type
== R_386_TLS_GOTDESC
1197 || to_type
== R_386_TLS_DESC_CALL
)
1199 if (tls_type
== GOT_TLS_IE_POS
)
1200 new_to_type
= R_386_TLS_GOTIE
;
1201 else if (tls_type
& GOT_TLS_IE
)
1202 new_to_type
= R_386_TLS_IE_32
;
1205 /* We checked the transition before when we were called from
1206 elf_i386_check_relocs. We only want to check the new
1207 transition which hasn't been checked before. */
1208 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1209 to_type
= new_to_type
;
1215 if (info
->executable
)
1216 to_type
= R_386_TLS_LE_32
;
1223 /* Return TRUE if there is no transition. */
1224 if (from_type
== to_type
)
1227 /* Check if the transition can be performed. */
1229 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1230 symtab_hdr
, sym_hashes
,
1231 from_type
, rel
, relend
))
1233 reloc_howto_type
*from
, *to
;
1236 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1237 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1240 name
= h
->root
.root
.string
;
1243 struct elf_i386_link_hash_table
*htab
;
1245 htab
= elf_i386_hash_table (info
);
1250 Elf_Internal_Sym
*isym
;
1252 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1254 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1258 (*_bfd_error_handler
)
1259 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1260 "in section `%A' failed"),
1261 abfd
, sec
, from
->name
, to
->name
, name
,
1262 (unsigned long) rel
->r_offset
);
1263 bfd_set_error (bfd_error_bad_value
);
1271 /* Look through the relocs for a section during the first phase, and
1272 calculate needed space in the global offset table, procedure linkage
1273 table, and dynamic reloc sections. */
1276 elf_i386_check_relocs (bfd
*abfd
,
1277 struct bfd_link_info
*info
,
1279 const Elf_Internal_Rela
*relocs
)
1281 struct elf_i386_link_hash_table
*htab
;
1282 Elf_Internal_Shdr
*symtab_hdr
;
1283 struct elf_link_hash_entry
**sym_hashes
;
1284 const Elf_Internal_Rela
*rel
;
1285 const Elf_Internal_Rela
*rel_end
;
1288 if (info
->relocatable
)
1291 BFD_ASSERT (is_i386_elf (abfd
));
1293 htab
= elf_i386_hash_table (info
);
1297 symtab_hdr
= &elf_symtab_hdr (abfd
);
1298 sym_hashes
= elf_sym_hashes (abfd
);
1302 rel_end
= relocs
+ sec
->reloc_count
;
1303 for (rel
= relocs
; rel
< rel_end
; rel
++)
1305 unsigned int r_type
;
1306 unsigned long r_symndx
;
1307 struct elf_link_hash_entry
*h
;
1308 Elf_Internal_Sym
*isym
;
1311 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1312 r_type
= ELF32_R_TYPE (rel
->r_info
);
1314 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1316 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1322 if (r_symndx
< symtab_hdr
->sh_info
)
1324 /* A local symbol. */
1325 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1330 /* Check relocation against local STT_GNU_IFUNC symbol. */
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
;
1351 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1352 while (h
->root
.type
== bfd_link_hash_indirect
1353 || h
->root
.type
== bfd_link_hash_warning
)
1354 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1359 /* Create the ifunc sections for static executables. If we
1360 never see an indirect function symbol nor we are building
1361 a static executable, those sections will be empty and
1362 won't appear in output. */
1373 if (!_bfd_elf_create_ifunc_sections (abfd
, info
))
1378 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1379 it here if it is defined in a non-shared object. */
1380 if (h
->type
== STT_GNU_IFUNC
1383 /* It is referenced by a non-shared object. */
1387 /* STT_GNU_IFUNC symbol must go through PLT. */
1388 h
->plt
.refcount
+= 1;
1390 /* STT_GNU_IFUNC needs dynamic sections. */
1391 if (htab
->elf
.dynobj
== NULL
)
1392 htab
->elf
.dynobj
= abfd
;
1397 if (h
->root
.root
.string
)
1398 name
= h
->root
.root
.string
;
1400 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1402 (*_bfd_error_handler
)
1403 (_("%B: relocation %s against STT_GNU_IFUNC "
1404 "symbol `%s' isn't handled by %s"), abfd
,
1405 elf_howto_table
[r_type
].name
,
1406 name
, __FUNCTION__
);
1407 bfd_set_error (bfd_error_bad_value
);
1412 h
->pointer_equality_needed
= 1;
1415 /* We must copy these reloc types into the
1416 output file. Create a reloc section in
1417 dynobj and make room for this reloc. */
1418 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1419 (abfd
, info
, sec
, sreloc
,
1420 &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
);
1435 h
->got
.refcount
+= 1;
1436 if (htab
->elf
.sgot
== NULL
1437 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1447 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1448 symtab_hdr
, sym_hashes
,
1449 &r_type
, GOT_UNKNOWN
,
1450 rel
, rel_end
, h
, r_symndx
))
1456 htab
->tls_ldm_got
.refcount
+= 1;
1460 /* This symbol requires a procedure linkage table entry. We
1461 actually build the entry in adjust_dynamic_symbol,
1462 because this might be a case of linking PIC code which is
1463 never referenced by a dynamic object, in which case we
1464 don't need to generate a procedure linkage table entry
1467 /* If this is a local symbol, we resolve it directly without
1468 creating a procedure linkage table entry. */
1473 h
->plt
.refcount
+= 1;
1476 case R_386_TLS_IE_32
:
1478 case R_386_TLS_GOTIE
:
1479 if (!info
->executable
)
1480 info
->flags
|= DF_STATIC_TLS
;
1485 case R_386_TLS_GOTDESC
:
1486 case R_386_TLS_DESC_CALL
:
1487 /* This symbol requires a global offset table entry. */
1489 int tls_type
, old_tls_type
;
1494 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1495 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1496 case R_386_TLS_GOTDESC
:
1497 case R_386_TLS_DESC_CALL
:
1498 tls_type
= GOT_TLS_GDESC
; break;
1499 case R_386_TLS_IE_32
:
1500 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1501 tls_type
= GOT_TLS_IE_NEG
;
1503 /* If this is a GD->IE transition, we may use either of
1504 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1505 tls_type
= GOT_TLS_IE
;
1508 case R_386_TLS_GOTIE
:
1509 tls_type
= GOT_TLS_IE_POS
; break;
1514 h
->got
.refcount
+= 1;
1515 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1519 bfd_signed_vma
*local_got_refcounts
;
1521 /* This is a global offset table entry for a local symbol. */
1522 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1523 if (local_got_refcounts
== NULL
)
1527 size
= symtab_hdr
->sh_info
;
1528 size
*= (sizeof (bfd_signed_vma
)
1529 + sizeof (bfd_vma
) + sizeof(char));
1530 local_got_refcounts
= (bfd_signed_vma
*)
1531 bfd_zalloc (abfd
, size
);
1532 if (local_got_refcounts
== NULL
)
1534 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1535 elf_i386_local_tlsdesc_gotent (abfd
)
1536 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1537 elf_i386_local_got_tls_type (abfd
)
1538 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1540 local_got_refcounts
[r_symndx
] += 1;
1541 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1544 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1545 tls_type
|= old_tls_type
;
1546 /* If a TLS symbol is accessed using IE at least once,
1547 there is no point to use dynamic model for it. */
1548 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1549 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1550 || (tls_type
& GOT_TLS_IE
) == 0))
1552 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1553 tls_type
= old_tls_type
;
1554 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1555 && GOT_TLS_GD_ANY_P (tls_type
))
1556 tls_type
|= old_tls_type
;
1560 name
= h
->root
.root
.string
;
1562 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1564 (*_bfd_error_handler
)
1565 (_("%B: `%s' accessed both as normal and "
1566 "thread local symbol"),
1572 if (old_tls_type
!= tls_type
)
1575 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1577 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1585 if (htab
->elf
.sgot
== NULL
)
1587 if (htab
->elf
.dynobj
== NULL
)
1588 htab
->elf
.dynobj
= abfd
;
1589 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1592 if (r_type
!= R_386_TLS_IE
)
1596 case R_386_TLS_LE_32
:
1598 if (info
->executable
)
1600 info
->flags
|= DF_STATIC_TLS
;
1605 if (h
!= NULL
&& info
->executable
)
1607 /* If this reloc is in a read-only section, we might
1608 need a copy reloc. We can't check reliably at this
1609 stage whether the section is read-only, as input
1610 sections have not yet been mapped to output sections.
1611 Tentatively set the flag for now, and correct in
1612 adjust_dynamic_symbol. */
1615 /* We may need a .plt entry if the function this reloc
1616 refers to is in a shared lib. */
1617 h
->plt
.refcount
+= 1;
1618 if (r_type
!= R_386_PC32
)
1619 h
->pointer_equality_needed
= 1;
1622 /* If we are creating a shared library, and this is a reloc
1623 against a global symbol, or a non PC relative reloc
1624 against a local symbol, then we need to copy the reloc
1625 into the shared library. However, if we are linking with
1626 -Bsymbolic, we do not need to copy a reloc against a
1627 global symbol which is defined in an object we are
1628 including in the link (i.e., DEF_REGULAR is set). At
1629 this point we have not seen all the input files, so it is
1630 possible that DEF_REGULAR is not set now but will be set
1631 later (it is never cleared). In case of a weak definition,
1632 DEF_REGULAR may be cleared later by a strong definition in
1633 a shared library. We account for that possibility below by
1634 storing information in the relocs_copied field of the hash
1635 table entry. A similar situation occurs when creating
1636 shared libraries and symbol visibility changes render the
1639 If on the other hand, we are creating an executable, we
1640 may need to keep relocations for symbols satisfied by a
1641 dynamic library if we manage to avoid copy relocs for the
1644 && (sec
->flags
& SEC_ALLOC
) != 0
1645 && (r_type
!= R_386_PC32
1647 && (! SYMBOLIC_BIND (info
, h
)
1648 || h
->root
.type
== bfd_link_hash_defweak
1649 || !h
->def_regular
))))
1650 || (ELIMINATE_COPY_RELOCS
1652 && (sec
->flags
& SEC_ALLOC
) != 0
1654 && (h
->root
.type
== bfd_link_hash_defweak
1655 || !h
->def_regular
)))
1657 struct elf_dyn_relocs
*p
;
1658 struct elf_dyn_relocs
**head
;
1660 /* We must copy these reloc types into the output file.
1661 Create a reloc section in dynobj and make room for
1665 if (htab
->elf
.dynobj
== NULL
)
1666 htab
->elf
.dynobj
= abfd
;
1668 sreloc
= _bfd_elf_make_dynamic_reloc_section
1669 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1675 /* If this is a global symbol, we count the number of
1676 relocations we need for this symbol. */
1679 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1683 /* Track dynamic relocs needed for local syms too.
1684 We really need local syms available to do this
1689 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1694 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1698 vpp
= &elf_section_data (s
)->local_dynrel
;
1699 head
= (struct elf_dyn_relocs
**)vpp
;
1703 if (p
== NULL
|| p
->sec
!= sec
)
1705 bfd_size_type amt
= sizeof *p
;
1706 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1718 if (r_type
== R_386_PC32
)
1723 /* This relocation describes the C++ object vtable hierarchy.
1724 Reconstruct it for later use during GC. */
1725 case R_386_GNU_VTINHERIT
:
1726 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1730 /* This relocation describes which C++ vtable entries are actually
1731 used. Record for later use during GC. */
1732 case R_386_GNU_VTENTRY
:
1733 BFD_ASSERT (h
!= NULL
);
1735 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1747 /* Return the section that should be marked against GC for a given
1751 elf_i386_gc_mark_hook (asection
*sec
,
1752 struct bfd_link_info
*info
,
1753 Elf_Internal_Rela
*rel
,
1754 struct elf_link_hash_entry
*h
,
1755 Elf_Internal_Sym
*sym
)
1758 switch (ELF32_R_TYPE (rel
->r_info
))
1760 case R_386_GNU_VTINHERIT
:
1761 case R_386_GNU_VTENTRY
:
1765 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1768 /* Update the got entry reference counts for the section being removed. */
1771 elf_i386_gc_sweep_hook (bfd
*abfd
,
1772 struct bfd_link_info
*info
,
1774 const Elf_Internal_Rela
*relocs
)
1776 struct elf_i386_link_hash_table
*htab
;
1777 Elf_Internal_Shdr
*symtab_hdr
;
1778 struct elf_link_hash_entry
**sym_hashes
;
1779 bfd_signed_vma
*local_got_refcounts
;
1780 const Elf_Internal_Rela
*rel
, *relend
;
1782 if (info
->relocatable
)
1785 htab
= elf_i386_hash_table (info
);
1789 elf_section_data (sec
)->local_dynrel
= NULL
;
1791 symtab_hdr
= &elf_symtab_hdr (abfd
);
1792 sym_hashes
= elf_sym_hashes (abfd
);
1793 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1795 relend
= relocs
+ sec
->reloc_count
;
1796 for (rel
= relocs
; rel
< relend
; rel
++)
1798 unsigned long r_symndx
;
1799 unsigned int r_type
;
1800 struct elf_link_hash_entry
*h
= NULL
;
1802 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1803 if (r_symndx
>= symtab_hdr
->sh_info
)
1805 struct elf_i386_link_hash_entry
*eh
;
1806 struct elf_dyn_relocs
**pp
;
1807 struct elf_dyn_relocs
*p
;
1809 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1810 while (h
->root
.type
== bfd_link_hash_indirect
1811 || h
->root
.type
== bfd_link_hash_warning
)
1812 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1813 eh
= (struct elf_i386_link_hash_entry
*) h
;
1815 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1818 /* Everything must go for SEC. */
1824 r_type
= ELF32_R_TYPE (rel
->r_info
);
1825 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1826 symtab_hdr
, sym_hashes
,
1827 &r_type
, GOT_UNKNOWN
,
1828 rel
, relend
, h
, r_symndx
))
1834 if (htab
->tls_ldm_got
.refcount
> 0)
1835 htab
->tls_ldm_got
.refcount
-= 1;
1839 case R_386_TLS_GOTDESC
:
1840 case R_386_TLS_DESC_CALL
:
1841 case R_386_TLS_IE_32
:
1843 case R_386_TLS_GOTIE
:
1847 if (h
->got
.refcount
> 0)
1848 h
->got
.refcount
-= 1;
1850 else if (local_got_refcounts
!= NULL
)
1852 if (local_got_refcounts
[r_symndx
] > 0)
1853 local_got_refcounts
[r_symndx
] -= 1;
1866 if (h
->plt
.refcount
> 0)
1867 h
->plt
.refcount
-= 1;
1879 /* Adjust a symbol defined by a dynamic object and referenced by a
1880 regular object. The current definition is in some section of the
1881 dynamic object, but we're not including those sections. We have to
1882 change the definition to something the rest of the link can
1886 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1887 struct elf_link_hash_entry
*h
)
1889 struct elf_i386_link_hash_table
*htab
;
1892 /* STT_GNU_IFUNC symbol must go through PLT. */
1893 if (h
->type
== STT_GNU_IFUNC
)
1895 if (h
->plt
.refcount
<= 0)
1897 h
->plt
.offset
= (bfd_vma
) -1;
1903 /* If this is a function, put it in the procedure linkage table. We
1904 will fill in the contents of the procedure linkage table later,
1905 when we know the address of the .got section. */
1906 if (h
->type
== STT_FUNC
1909 if (h
->plt
.refcount
<= 0
1910 || SYMBOL_CALLS_LOCAL (info
, h
)
1911 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1912 && h
->root
.type
== bfd_link_hash_undefweak
))
1914 /* This case can occur if we saw a PLT32 reloc in an input
1915 file, but the symbol was never referred to by a dynamic
1916 object, or if all references were garbage collected. In
1917 such a case, we don't actually need to build a procedure
1918 linkage table, and we can just do a PC32 reloc instead. */
1919 h
->plt
.offset
= (bfd_vma
) -1;
1926 /* It's possible that we incorrectly decided a .plt reloc was
1927 needed for an R_386_PC32 reloc to a non-function sym in
1928 check_relocs. We can't decide accurately between function and
1929 non-function syms in check-relocs; Objects loaded later in
1930 the link may change h->type. So fix it now. */
1931 h
->plt
.offset
= (bfd_vma
) -1;
1933 /* If this is a weak symbol, and there is a real definition, the
1934 processor independent code will have arranged for us to see the
1935 real definition first, and we can just use the same value. */
1936 if (h
->u
.weakdef
!= NULL
)
1938 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1939 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1940 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1941 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1942 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1943 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1947 /* This is a reference to a symbol defined by a dynamic object which
1948 is not a function. */
1950 /* If we are creating a shared library, we must presume that the
1951 only references to the symbol are via the global offset table.
1952 For such cases we need not do anything here; the relocations will
1953 be handled correctly by relocate_section. */
1957 /* If there are no references to this symbol that do not use the
1958 GOT, we don't need to generate a copy reloc. */
1959 if (!h
->non_got_ref
)
1962 /* If -z nocopyreloc was given, we won't generate them either. */
1963 if (info
->nocopyreloc
)
1969 htab
= elf_i386_hash_table (info
);
1973 /* If there aren't any dynamic relocs in read-only sections, then
1974 we can keep the dynamic relocs and avoid the copy reloc. This
1975 doesn't work on VxWorks, where we can not have dynamic relocations
1976 (other than copy and jump slot relocations) in an executable. */
1977 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
1979 struct elf_i386_link_hash_entry
* eh
;
1980 struct elf_dyn_relocs
*p
;
1982 eh
= (struct elf_i386_link_hash_entry
*) h
;
1983 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1985 s
= p
->sec
->output_section
;
1986 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1999 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2000 h
->root
.root
.string
);
2004 /* We must allocate the symbol in our .dynbss section, which will
2005 become part of the .bss section of the executable. There will be
2006 an entry for this symbol in the .dynsym section. The dynamic
2007 object will contain position independent code, so all references
2008 from the dynamic object to this symbol will go through the global
2009 offset table. The dynamic linker will use the .dynsym entry to
2010 determine the address it must put in the global offset table, so
2011 both the dynamic object and the regular object will refer to the
2012 same memory location for the variable. */
2014 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2015 copy the initial value out of the dynamic object and into the
2016 runtime process image. */
2017 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2019 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2025 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2028 /* Allocate space in .plt, .got and associated reloc sections for
2032 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2034 struct bfd_link_info
*info
;
2035 struct elf_i386_link_hash_table
*htab
;
2036 struct elf_i386_link_hash_entry
*eh
;
2037 struct elf_dyn_relocs
*p
;
2039 if (h
->root
.type
== bfd_link_hash_indirect
)
2042 if (h
->root
.type
== bfd_link_hash_warning
)
2043 /* When warning symbols are created, they **replace** the "real"
2044 entry in the hash table, thus we never get to see the real
2045 symbol in a hash traversal. So look at it now. */
2046 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2047 eh
= (struct elf_i386_link_hash_entry
*) h
;
2049 info
= (struct bfd_link_info
*) inf
;
2050 htab
= elf_i386_hash_table (info
);
2054 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2055 here if it is defined and referenced in a non-shared object. */
2056 if (h
->type
== STT_GNU_IFUNC
2058 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2061 else if (htab
->elf
.dynamic_sections_created
2062 && h
->plt
.refcount
> 0)
2064 /* Make sure this symbol is output as a dynamic symbol.
2065 Undefined weak syms won't yet be marked as dynamic. */
2066 if (h
->dynindx
== -1
2067 && !h
->forced_local
)
2069 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2074 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2076 asection
*s
= htab
->elf
.splt
;
2078 /* If this is the first .plt entry, make room for the special
2081 s
->size
+= PLT_ENTRY_SIZE
;
2083 h
->plt
.offset
= s
->size
;
2085 /* If this symbol is not defined in a regular file, and we are
2086 not generating a shared library, then set the symbol to this
2087 location in the .plt. This is required to make function
2088 pointers compare as equal between the normal executable and
2089 the shared library. */
2093 h
->root
.u
.def
.section
= s
;
2094 h
->root
.u
.def
.value
= h
->plt
.offset
;
2097 /* Make room for this entry. */
2098 s
->size
+= PLT_ENTRY_SIZE
;
2100 /* We also need to make an entry in the .got.plt section, which
2101 will be placed in the .got section by the linker script. */
2102 htab
->elf
.sgotplt
->size
+= 4;
2104 /* We also need to make an entry in the .rel.plt section. */
2105 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2106 htab
->next_tls_desc_index
++;
2108 if (htab
->is_vxworks
&& !info
->shared
)
2110 /* VxWorks has a second set of relocations for each PLT entry
2111 in executables. They go in a separate relocation section,
2112 which is processed by the kernel loader. */
2114 /* There are two relocations for the initial PLT entry: an
2115 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2116 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2118 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
2119 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2121 /* There are two extra relocations for each subsequent PLT entry:
2122 an R_386_32 relocation for the GOT entry, and an R_386_32
2123 relocation for the PLT entry. */
2125 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2130 h
->plt
.offset
= (bfd_vma
) -1;
2136 h
->plt
.offset
= (bfd_vma
) -1;
2140 eh
->tlsdesc_got
= (bfd_vma
) -1;
2142 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2143 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2144 if (h
->got
.refcount
> 0
2147 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2148 h
->got
.offset
= (bfd_vma
) -1;
2149 else if (h
->got
.refcount
> 0)
2153 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2155 /* Make sure this symbol is output as a dynamic symbol.
2156 Undefined weak syms won't yet be marked as dynamic. */
2157 if (h
->dynindx
== -1
2158 && !h
->forced_local
)
2160 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2165 if (GOT_TLS_GDESC_P (tls_type
))
2167 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2168 - elf_i386_compute_jump_table_size (htab
);
2169 htab
->elf
.sgotplt
->size
+= 8;
2170 h
->got
.offset
= (bfd_vma
) -2;
2172 if (! GOT_TLS_GDESC_P (tls_type
)
2173 || GOT_TLS_GD_P (tls_type
))
2175 h
->got
.offset
= s
->size
;
2177 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2178 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2181 dyn
= htab
->elf
.dynamic_sections_created
;
2182 /* R_386_TLS_IE_32 needs one dynamic relocation,
2183 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2184 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2185 need two), R_386_TLS_GD needs one if local symbol and two if
2187 if (tls_type
== GOT_TLS_IE_BOTH
)
2188 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2189 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2190 || (tls_type
& GOT_TLS_IE
))
2191 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2192 else if (GOT_TLS_GD_P (tls_type
))
2193 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2194 else if (! GOT_TLS_GDESC_P (tls_type
)
2195 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2196 || h
->root
.type
!= bfd_link_hash_undefweak
)
2198 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2199 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2200 if (GOT_TLS_GDESC_P (tls_type
))
2201 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2204 h
->got
.offset
= (bfd_vma
) -1;
2206 if (eh
->dyn_relocs
== NULL
)
2209 /* In the shared -Bsymbolic case, discard space allocated for
2210 dynamic pc-relative relocs against symbols which turn out to be
2211 defined in regular objects. For the normal shared case, discard
2212 space for pc-relative relocs that have become local due to symbol
2213 visibility changes. */
2217 /* The only reloc that uses pc_count is R_386_PC32, which will
2218 appear on a call or on something like ".long foo - .". We
2219 want calls to protected symbols to resolve directly to the
2220 function rather than going via the plt. If people want
2221 function pointer comparisons to work as expected then they
2222 should avoid writing assembly like ".long foo - .". */
2223 if (SYMBOL_CALLS_LOCAL (info
, h
))
2225 struct elf_dyn_relocs
**pp
;
2227 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2229 p
->count
-= p
->pc_count
;
2238 if (htab
->is_vxworks
)
2240 struct elf_dyn_relocs
**pp
;
2241 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2243 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2250 /* Also discard relocs on undefined weak syms with non-default
2252 if (eh
->dyn_relocs
!= NULL
2253 && h
->root
.type
== bfd_link_hash_undefweak
)
2255 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2256 eh
->dyn_relocs
= NULL
;
2258 /* Make sure undefined weak symbols are output as a dynamic
2260 else if (h
->dynindx
== -1
2261 && !h
->forced_local
)
2263 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2268 else if (ELIMINATE_COPY_RELOCS
)
2270 /* For the non-shared case, discard space for relocs against
2271 symbols which turn out to need copy relocs or are not
2277 || (htab
->elf
.dynamic_sections_created
2278 && (h
->root
.type
== bfd_link_hash_undefweak
2279 || h
->root
.type
== bfd_link_hash_undefined
))))
2281 /* Make sure this symbol is output as a dynamic symbol.
2282 Undefined weak syms won't yet be marked as dynamic. */
2283 if (h
->dynindx
== -1
2284 && !h
->forced_local
)
2286 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2290 /* If that succeeded, we know we'll be keeping all the
2292 if (h
->dynindx
!= -1)
2296 eh
->dyn_relocs
= NULL
;
2301 /* Finally, allocate space. */
2302 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2306 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2308 BFD_ASSERT (sreloc
!= NULL
);
2309 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2315 /* Allocate space in .plt, .got and associated reloc sections for
2316 local dynamic relocs. */
2319 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2321 struct elf_link_hash_entry
*h
2322 = (struct elf_link_hash_entry
*) *slot
;
2324 if (h
->type
!= STT_GNU_IFUNC
2328 || h
->root
.type
!= bfd_link_hash_defined
)
2331 return elf_i386_allocate_dynrelocs (h
, inf
);
2334 /* Find any dynamic relocs that apply to read-only sections. */
2337 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2339 struct elf_i386_link_hash_entry
*eh
;
2340 struct elf_dyn_relocs
*p
;
2342 if (h
->root
.type
== bfd_link_hash_warning
)
2343 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2345 eh
= (struct elf_i386_link_hash_entry
*) h
;
2346 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2348 asection
*s
= p
->sec
->output_section
;
2350 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2352 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2354 info
->flags
|= DF_TEXTREL
;
2356 /* Not an error, just cut short the traversal. */
2363 /* Set the sizes of the dynamic sections. */
2366 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2367 struct bfd_link_info
*info
)
2369 struct elf_i386_link_hash_table
*htab
;
2375 htab
= elf_i386_hash_table (info
);
2378 dynobj
= htab
->elf
.dynobj
;
2382 if (htab
->elf
.dynamic_sections_created
)
2384 /* Set the contents of the .interp section to the interpreter. */
2385 if (info
->executable
)
2387 s
= bfd_get_section_by_name (dynobj
, ".interp");
2390 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2391 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2395 /* Set up .got offsets for local syms, and space for local dynamic
2397 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2399 bfd_signed_vma
*local_got
;
2400 bfd_signed_vma
*end_local_got
;
2401 char *local_tls_type
;
2402 bfd_vma
*local_tlsdesc_gotent
;
2403 bfd_size_type locsymcount
;
2404 Elf_Internal_Shdr
*symtab_hdr
;
2407 if (! is_i386_elf (ibfd
))
2410 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2412 struct elf_dyn_relocs
*p
;
2414 for (p
= ((struct elf_dyn_relocs
*)
2415 elf_section_data (s
)->local_dynrel
);
2419 if (!bfd_is_abs_section (p
->sec
)
2420 && bfd_is_abs_section (p
->sec
->output_section
))
2422 /* Input section has been discarded, either because
2423 it is a copy of a linkonce section or due to
2424 linker script /DISCARD/, so we'll be discarding
2427 else if (htab
->is_vxworks
2428 && strcmp (p
->sec
->output_section
->name
,
2431 /* Relocations in vxworks .tls_vars sections are
2432 handled specially by the loader. */
2434 else if (p
->count
!= 0)
2436 srel
= elf_section_data (p
->sec
)->sreloc
;
2437 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2438 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2439 info
->flags
|= DF_TEXTREL
;
2444 local_got
= elf_local_got_refcounts (ibfd
);
2448 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2449 locsymcount
= symtab_hdr
->sh_info
;
2450 end_local_got
= local_got
+ locsymcount
;
2451 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2452 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2454 srel
= htab
->elf
.srelgot
;
2455 for (; local_got
< end_local_got
;
2456 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2458 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2461 if (GOT_TLS_GDESC_P (*local_tls_type
))
2463 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2464 - elf_i386_compute_jump_table_size (htab
);
2465 htab
->elf
.sgotplt
->size
+= 8;
2466 *local_got
= (bfd_vma
) -2;
2468 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2469 || GOT_TLS_GD_P (*local_tls_type
))
2471 *local_got
= s
->size
;
2473 if (GOT_TLS_GD_P (*local_tls_type
)
2474 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2478 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2479 || (*local_tls_type
& GOT_TLS_IE
))
2481 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2482 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2483 else if (GOT_TLS_GD_P (*local_tls_type
)
2484 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2485 srel
->size
+= sizeof (Elf32_External_Rel
);
2486 if (GOT_TLS_GDESC_P (*local_tls_type
))
2487 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2491 *local_got
= (bfd_vma
) -1;
2495 if (htab
->tls_ldm_got
.refcount
> 0)
2497 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2499 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2500 htab
->elf
.sgot
->size
+= 8;
2501 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2504 htab
->tls_ldm_got
.offset
= -1;
2506 /* Allocate global sym .plt and .got entries, and space for global
2507 sym dynamic relocs. */
2508 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2510 /* Allocate .plt and .got entries, and space for local symbols. */
2511 htab_traverse (htab
->loc_hash_table
,
2512 elf_i386_allocate_local_dynrelocs
,
2515 /* For every jump slot reserved in the sgotplt, reloc_count is
2516 incremented. However, when we reserve space for TLS descriptors,
2517 it's not incremented, so in order to compute the space reserved
2518 for them, it suffices to multiply the reloc count by the jump
2520 if (htab
->elf
.srelplt
)
2521 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2523 /* We now have determined the sizes of the various dynamic sections.
2524 Allocate memory for them. */
2526 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2528 bfd_boolean strip_section
= TRUE
;
2530 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2533 if (s
== htab
->elf
.splt
2534 || s
== htab
->elf
.sgot
2535 || s
== htab
->elf
.sgotplt
2536 || s
== htab
->elf
.iplt
2537 || s
== htab
->elf
.igotplt
2538 || s
== htab
->sdynbss
)
2540 /* Strip this section if we don't need it; see the
2542 /* We'd like to strip these sections if they aren't needed, but if
2543 we've exported dynamic symbols from them we must leave them.
2544 It's too late to tell BFD to get rid of the symbols. */
2546 if (htab
->elf
.hplt
!= NULL
)
2547 strip_section
= FALSE
;
2549 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2552 && s
!= htab
->elf
.srelplt
2553 && s
!= htab
->srelplt2
)
2556 /* We use the reloc_count field as a counter if we need
2557 to copy relocs into the output file. */
2562 /* It's not one of our sections, so don't allocate space. */
2568 /* If we don't need this section, strip it from the
2569 output file. This is mostly to handle .rel.bss and
2570 .rel.plt. We must create both sections in
2571 create_dynamic_sections, because they must be created
2572 before the linker maps input sections to output
2573 sections. The linker does that before
2574 adjust_dynamic_symbol is called, and it is that
2575 function which decides whether anything needs to go
2576 into these sections. */
2578 s
->flags
|= SEC_EXCLUDE
;
2582 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2585 /* Allocate memory for the section contents. We use bfd_zalloc
2586 here in case unused entries are not reclaimed before the
2587 section's contents are written out. This should not happen,
2588 but this way if it does, we get a R_386_NONE reloc instead
2590 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2591 if (s
->contents
== NULL
)
2595 if (htab
->elf
.dynamic_sections_created
)
2597 /* Add some entries to the .dynamic section. We fill in the
2598 values later, in elf_i386_finish_dynamic_sections, but we
2599 must add the entries now so that we get the correct size for
2600 the .dynamic section. The DT_DEBUG entry is filled in by the
2601 dynamic linker and used by the debugger. */
2602 #define add_dynamic_entry(TAG, VAL) \
2603 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2605 if (info
->executable
)
2607 if (!add_dynamic_entry (DT_DEBUG
, 0))
2611 if (htab
->elf
.splt
->size
!= 0)
2613 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2614 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2615 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2616 || !add_dynamic_entry (DT_JMPREL
, 0))
2622 if (!add_dynamic_entry (DT_REL
, 0)
2623 || !add_dynamic_entry (DT_RELSZ
, 0)
2624 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2627 /* If any dynamic relocs apply to a read-only section,
2628 then we need a DT_TEXTREL entry. */
2629 if ((info
->flags
& DF_TEXTREL
) == 0)
2630 elf_link_hash_traverse (&htab
->elf
,
2631 elf_i386_readonly_dynrelocs
, info
);
2633 if ((info
->flags
& DF_TEXTREL
) != 0)
2635 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2639 if (htab
->is_vxworks
2640 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2643 #undef add_dynamic_entry
2649 elf_i386_always_size_sections (bfd
*output_bfd
,
2650 struct bfd_link_info
*info
)
2652 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2656 struct elf_link_hash_entry
*tlsbase
;
2658 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2659 "_TLS_MODULE_BASE_",
2660 FALSE
, FALSE
, FALSE
);
2662 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2664 struct elf_i386_link_hash_table
*htab
;
2665 struct bfd_link_hash_entry
*bh
= NULL
;
2666 const struct elf_backend_data
*bed
2667 = get_elf_backend_data (output_bfd
);
2669 htab
= elf_i386_hash_table (info
);
2673 if (!(_bfd_generic_link_add_one_symbol
2674 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2675 tls_sec
, 0, NULL
, FALSE
,
2676 bed
->collect
, &bh
)))
2679 htab
->tls_module_base
= bh
;
2681 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2682 tlsbase
->def_regular
= 1;
2683 tlsbase
->other
= STV_HIDDEN
;
2684 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2691 /* Set the correct type for an x86 ELF section. We do this by the
2692 section name, which is a hack, but ought to work. */
2695 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2696 Elf_Internal_Shdr
*hdr
,
2701 name
= bfd_get_section_name (abfd
, sec
);
2703 /* This is an ugly, but unfortunately necessary hack that is
2704 needed when producing EFI binaries on x86. It tells
2705 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2706 containing ELF relocation info. We need this hack in order to
2707 be able to generate ELF binaries that can be translated into
2708 EFI applications (which are essentially COFF objects). Those
2709 files contain a COFF ".reloc" section inside an ELFNN object,
2710 which would normally cause BFD to segfault because it would
2711 attempt to interpret this section as containing relocation
2712 entries for section "oc". With this hack enabled, ".reloc"
2713 will be treated as a normal data section, which will avoid the
2714 segfault. However, you won't be able to create an ELFNN binary
2715 with a section named "oc" that needs relocations, but that's
2716 the kind of ugly side-effects you get when detecting section
2717 types based on their names... In practice, this limitation is
2718 unlikely to bite. */
2719 if (strcmp (name
, ".reloc") == 0)
2720 hdr
->sh_type
= SHT_PROGBITS
;
2725 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2726 executables. Rather than setting it to the beginning of the TLS
2727 section, we have to set it to the end. This function may be called
2728 multiple times, it is idempotent. */
2731 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2733 struct elf_i386_link_hash_table
*htab
;
2734 struct bfd_link_hash_entry
*base
;
2736 if (!info
->executable
)
2739 htab
= elf_i386_hash_table (info
);
2743 base
= htab
->tls_module_base
;
2747 base
->u
.def
.value
= htab
->elf
.tls_size
;
2750 /* Return the base VMA address which should be subtracted from real addresses
2751 when resolving @dtpoff relocation.
2752 This is PT_TLS segment p_vaddr. */
2755 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2757 /* If tls_sec is NULL, we should have signalled an error already. */
2758 if (elf_hash_table (info
)->tls_sec
== NULL
)
2760 return elf_hash_table (info
)->tls_sec
->vma
;
2763 /* Return the relocation value for @tpoff relocation
2764 if STT_TLS virtual address is ADDRESS. */
2767 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2769 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2771 /* If tls_sec is NULL, we should have signalled an error already. */
2772 if (htab
->tls_sec
== NULL
)
2774 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2777 /* Relocate an i386 ELF section. */
2780 elf_i386_relocate_section (bfd
*output_bfd
,
2781 struct bfd_link_info
*info
,
2783 asection
*input_section
,
2785 Elf_Internal_Rela
*relocs
,
2786 Elf_Internal_Sym
*local_syms
,
2787 asection
**local_sections
)
2789 struct elf_i386_link_hash_table
*htab
;
2790 Elf_Internal_Shdr
*symtab_hdr
;
2791 struct elf_link_hash_entry
**sym_hashes
;
2792 bfd_vma
*local_got_offsets
;
2793 bfd_vma
*local_tlsdesc_gotents
;
2794 Elf_Internal_Rela
*rel
;
2795 Elf_Internal_Rela
*relend
;
2796 bfd_boolean is_vxworks_tls
;
2798 BFD_ASSERT (is_i386_elf (input_bfd
));
2800 htab
= elf_i386_hash_table (info
);
2803 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2804 sym_hashes
= elf_sym_hashes (input_bfd
);
2805 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2806 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2807 /* We have to handle relocations in vxworks .tls_vars sections
2808 specially, because the dynamic loader is 'weird'. */
2809 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
2810 && !strcmp (input_section
->output_section
->name
,
2813 elf_i386_set_tls_module_base (info
);
2816 relend
= relocs
+ input_section
->reloc_count
;
2817 for (; rel
< relend
; rel
++)
2819 unsigned int r_type
;
2820 reloc_howto_type
*howto
;
2821 unsigned long r_symndx
;
2822 struct elf_link_hash_entry
*h
;
2823 Elf_Internal_Sym
*sym
;
2825 bfd_vma off
, offplt
;
2827 bfd_boolean unresolved_reloc
;
2828 bfd_reloc_status_type r
;
2832 r_type
= ELF32_R_TYPE (rel
->r_info
);
2833 if (r_type
== R_386_GNU_VTINHERIT
2834 || r_type
== R_386_GNU_VTENTRY
)
2837 if ((indx
= r_type
) >= R_386_standard
2838 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2839 >= R_386_ext
- R_386_standard
)
2840 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2841 >= R_386_irelative
- R_386_ext
))
2843 (*_bfd_error_handler
)
2844 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2845 input_bfd
, input_section
, r_type
);
2846 bfd_set_error (bfd_error_bad_value
);
2849 howto
= elf_howto_table
+ indx
;
2851 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2855 unresolved_reloc
= FALSE
;
2856 if (r_symndx
< symtab_hdr
->sh_info
)
2858 sym
= local_syms
+ r_symndx
;
2859 sec
= local_sections
[r_symndx
];
2860 relocation
= (sec
->output_section
->vma
2861 + sec
->output_offset
2864 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2865 && ((sec
->flags
& SEC_MERGE
) != 0
2866 || (info
->relocatable
2867 && sec
->output_offset
!= 0)))
2870 bfd_byte
*where
= contents
+ rel
->r_offset
;
2872 switch (howto
->size
)
2875 addend
= bfd_get_8 (input_bfd
, where
);
2876 if (howto
->pc_relative
)
2878 addend
= (addend
^ 0x80) - 0x80;
2883 addend
= bfd_get_16 (input_bfd
, where
);
2884 if (howto
->pc_relative
)
2886 addend
= (addend
^ 0x8000) - 0x8000;
2891 addend
= bfd_get_32 (input_bfd
, where
);
2892 if (howto
->pc_relative
)
2894 addend
= (addend
^ 0x80000000) - 0x80000000;
2902 if (info
->relocatable
)
2903 addend
+= sec
->output_offset
;
2906 asection
*msec
= sec
;
2907 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2909 addend
-= relocation
;
2910 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2913 switch (howto
->size
)
2916 /* FIXME: overflow checks. */
2917 if (howto
->pc_relative
)
2919 bfd_put_8 (input_bfd
, addend
, where
);
2922 if (howto
->pc_relative
)
2924 bfd_put_16 (input_bfd
, addend
, where
);
2927 if (howto
->pc_relative
)
2929 bfd_put_32 (input_bfd
, addend
, where
);
2933 else if (!info
->relocatable
2934 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2936 /* Relocate against local STT_GNU_IFUNC symbol. */
2937 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
,
2942 /* Set STT_GNU_IFUNC symbol value. */
2943 h
->root
.u
.def
.value
= sym
->st_value
;
2944 h
->root
.u
.def
.section
= sec
;
2949 bfd_boolean warned ATTRIBUTE_UNUSED
;
2951 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2952 r_symndx
, symtab_hdr
, sym_hashes
,
2954 unresolved_reloc
, warned
);
2957 if (sec
!= NULL
&& elf_discarded_section (sec
))
2959 /* For relocs against symbols from removed linkonce sections,
2960 or sections discarded by a linker script, we just want the
2961 section contents zeroed. Avoid any special processing. */
2962 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2968 if (info
->relocatable
)
2971 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2972 it here if it is defined in a non-shared object. */
2974 && h
->type
== STT_GNU_IFUNC
2977 asection
*plt
, *gotplt
, *base_got
;
2981 if ((input_section
->flags
& SEC_ALLOC
) == 0
2982 || h
->plt
.offset
== (bfd_vma
) -1)
2985 /* STT_GNU_IFUNC symbol must go through PLT. */
2986 if (htab
->elf
.splt
!= NULL
)
2988 plt
= htab
->elf
.splt
;
2989 gotplt
= htab
->elf
.sgotplt
;
2993 plt
= htab
->elf
.iplt
;
2994 gotplt
= htab
->elf
.igotplt
;
2997 relocation
= (plt
->output_section
->vma
2998 + plt
->output_offset
+ h
->plt
.offset
);
3003 if (h
->root
.root
.string
)
3004 name
= h
->root
.root
.string
;
3006 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3008 (*_bfd_error_handler
)
3009 (_("%B: relocation %s against STT_GNU_IFUNC "
3010 "symbol `%s' isn't handled by %s"), input_bfd
,
3011 elf_howto_table
[r_type
].name
,
3012 name
, __FUNCTION__
);
3013 bfd_set_error (bfd_error_bad_value
);
3017 /* Generate dynamic relcoation only when there is a
3018 non-GOF reference in a shared object. */
3019 if (info
->shared
&& h
->non_got_ref
)
3021 Elf_Internal_Rela outrel
;
3026 /* Need a dynamic relocation to get the real function
3028 offset
= _bfd_elf_section_offset (output_bfd
,
3032 if (offset
== (bfd_vma
) -1
3033 || offset
== (bfd_vma
) -2)
3036 outrel
.r_offset
= (input_section
->output_section
->vma
3037 + input_section
->output_offset
3040 if (h
->dynindx
== -1
3042 || info
->executable
)
3044 /* This symbol is resolved locally. */
3045 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3046 bfd_put_32 (output_bfd
,
3047 (h
->root
.u
.def
.value
3048 + h
->root
.u
.def
.section
->output_section
->vma
3049 + h
->root
.u
.def
.section
->output_offset
),
3053 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3055 sreloc
= htab
->elf
.irelifunc
;
3056 loc
= sreloc
->contents
;
3057 loc
+= (sreloc
->reloc_count
++
3058 * sizeof (Elf32_External_Rel
));
3059 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3061 /* If this reloc is against an external symbol, we
3062 do not want to fiddle with the addend. Otherwise,
3063 we need to include the symbol value so that it
3064 becomes an addend for the dynamic reloc. For an
3065 internal symbol, we have updated addend. */
3074 base_got
= htab
->elf
.sgot
;
3075 off
= h
->got
.offset
;
3077 if (base_got
== NULL
)
3080 if (off
== (bfd_vma
) -1)
3082 /* We can't use h->got.offset here to save state, or
3083 even just remember the offset, as finish_dynamic_symbol
3084 would use that as offset into .got. */
3086 if (htab
->elf
.splt
!= NULL
)
3088 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3089 off
= (plt_index
+ 3) * 4;
3090 base_got
= htab
->elf
.sgotplt
;
3094 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3095 off
= plt_index
* 4;
3096 base_got
= htab
->elf
.igotplt
;
3099 if (h
->dynindx
== -1
3103 /* This references the local defitionion. We must
3104 initialize this entry in the global offset table.
3105 Since the offset must always be a multiple of 8,
3106 we use the least significant bit to record
3107 whether we have initialized it already.
3109 When doing a dynamic link, we create a .rela.got
3110 relocation entry to initialize the value. This
3111 is done in the finish_dynamic_symbol routine. */
3116 bfd_put_32 (output_bfd
, relocation
,
3117 base_got
->contents
+ off
);
3124 /* Adjust for static executables. */
3125 if (htab
->elf
.splt
== NULL
)
3126 relocation
+= gotplt
->output_offset
;
3130 relocation
= (base_got
->output_section
->vma
3131 + base_got
->output_offset
+ off
3132 - gotplt
->output_section
->vma
3133 - gotplt
->output_offset
);
3134 /* Adjust for static executables. */
3135 if (htab
->elf
.splt
== NULL
)
3136 relocation
+= gotplt
->output_offset
;
3142 relocation
-= (gotplt
->output_section
->vma
3143 + gotplt
->output_offset
);
3151 /* Relocation is to the entry for this symbol in the global
3153 if (htab
->elf
.sgot
== NULL
)
3160 off
= h
->got
.offset
;
3161 dyn
= htab
->elf
.dynamic_sections_created
;
3162 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3164 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3165 || (ELF_ST_VISIBILITY (h
->other
)
3166 && h
->root
.type
== bfd_link_hash_undefweak
))
3168 /* This is actually a static link, or it is a
3169 -Bsymbolic link and the symbol is defined
3170 locally, or the symbol was forced to be local
3171 because of a version file. We must initialize
3172 this entry in the global offset table. Since the
3173 offset must always be a multiple of 4, we use the
3174 least significant bit to record whether we have
3175 initialized it already.
3177 When doing a dynamic link, we create a .rel.got
3178 relocation entry to initialize the value. This
3179 is done in the finish_dynamic_symbol routine. */
3184 bfd_put_32 (output_bfd
, relocation
,
3185 htab
->elf
.sgot
->contents
+ off
);
3190 unresolved_reloc
= FALSE
;
3194 if (local_got_offsets
== NULL
)
3197 off
= local_got_offsets
[r_symndx
];
3199 /* The offset must always be a multiple of 4. We use
3200 the least significant bit to record whether we have
3201 already generated the necessary reloc. */
3206 bfd_put_32 (output_bfd
, relocation
,
3207 htab
->elf
.sgot
->contents
+ off
);
3212 Elf_Internal_Rela outrel
;
3215 s
= htab
->elf
.srelgot
;
3219 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3220 + htab
->elf
.sgot
->output_offset
3222 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3224 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3225 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3228 local_got_offsets
[r_symndx
] |= 1;
3232 if (off
>= (bfd_vma
) -2)
3235 relocation
= htab
->elf
.sgot
->output_section
->vma
3236 + htab
->elf
.sgot
->output_offset
+ off
3237 - htab
->elf
.sgotplt
->output_section
->vma
3238 - htab
->elf
.sgotplt
->output_offset
;
3242 /* Relocation is relative to the start of the global offset
3245 /* Check to make sure it isn't a protected function symbol
3246 for shared library since it may not be local when used
3247 as function address. We also need to make sure that a
3248 symbol is defined locally. */
3249 if (info
->shared
&& h
)
3251 if (!h
->def_regular
)
3255 switch (ELF_ST_VISIBILITY (h
->other
))
3258 v
= _("hidden symbol");
3261 v
= _("internal symbol");
3264 v
= _("protected symbol");
3271 (*_bfd_error_handler
)
3272 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3273 input_bfd
, v
, h
->root
.root
.string
);
3274 bfd_set_error (bfd_error_bad_value
);
3277 else if (!info
->executable
3278 && h
->type
== STT_FUNC
3279 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3281 (*_bfd_error_handler
)
3282 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3283 input_bfd
, h
->root
.root
.string
);
3284 bfd_set_error (bfd_error_bad_value
);
3289 /* Note that sgot is not involved in this
3290 calculation. We always want the start of .got.plt. If we
3291 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3292 permitted by the ABI, we might have to change this
3294 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3295 + htab
->elf
.sgotplt
->output_offset
;
3299 /* Use global offset table as symbol value. */
3300 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3301 + htab
->elf
.sgotplt
->output_offset
;
3302 unresolved_reloc
= FALSE
;
3306 /* Relocation is to the entry for this symbol in the
3307 procedure linkage table. */
3309 /* Resolve a PLT32 reloc against a local symbol directly,
3310 without using the procedure linkage table. */
3314 if (h
->plt
.offset
== (bfd_vma
) -1
3315 || htab
->elf
.splt
== NULL
)
3317 /* We didn't make a PLT entry for this symbol. This
3318 happens when statically linking PIC code, or when
3319 using -Bsymbolic. */
3323 relocation
= (htab
->elf
.splt
->output_section
->vma
3324 + htab
->elf
.splt
->output_offset
3326 unresolved_reloc
= FALSE
;
3331 if ((input_section
->flags
& SEC_ALLOC
) == 0
3337 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3338 || h
->root
.type
!= bfd_link_hash_undefweak
)
3339 && (r_type
!= R_386_PC32
3340 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3341 || (ELIMINATE_COPY_RELOCS
3348 || h
->root
.type
== bfd_link_hash_undefweak
3349 || h
->root
.type
== bfd_link_hash_undefined
)))
3351 Elf_Internal_Rela outrel
;
3353 bfd_boolean skip
, relocate
;
3356 /* When generating a shared object, these relocations
3357 are copied into the output file to be resolved at run
3364 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3366 if (outrel
.r_offset
== (bfd_vma
) -1)
3368 else if (outrel
.r_offset
== (bfd_vma
) -2)
3369 skip
= TRUE
, relocate
= TRUE
;
3370 outrel
.r_offset
+= (input_section
->output_section
->vma
3371 + input_section
->output_offset
);
3374 memset (&outrel
, 0, sizeof outrel
);
3377 && (r_type
== R_386_PC32
3379 || !SYMBOLIC_BIND (info
, h
)
3380 || !h
->def_regular
))
3381 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3384 /* This symbol is local, or marked to become local. */
3386 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3389 sreloc
= elf_section_data (input_section
)->sreloc
;
3391 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
3393 loc
= sreloc
->contents
;
3394 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3396 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3398 /* If this reloc is against an external symbol, we do
3399 not want to fiddle with the addend. Otherwise, we
3400 need to include the symbol value so that it becomes
3401 an addend for the dynamic reloc. */
3408 if (!info
->executable
)
3410 Elf_Internal_Rela outrel
;
3414 outrel
.r_offset
= rel
->r_offset
3415 + input_section
->output_section
->vma
3416 + input_section
->output_offset
;
3417 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3418 sreloc
= elf_section_data (input_section
)->sreloc
;
3421 loc
= sreloc
->contents
;
3422 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3423 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3428 case R_386_TLS_GOTDESC
:
3429 case R_386_TLS_DESC_CALL
:
3430 case R_386_TLS_IE_32
:
3431 case R_386_TLS_GOTIE
:
3432 tls_type
= GOT_UNKNOWN
;
3433 if (h
== NULL
&& local_got_offsets
)
3434 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3436 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3437 if (tls_type
== GOT_TLS_IE
)
3438 tls_type
= GOT_TLS_IE_NEG
;
3440 if (! elf_i386_tls_transition (info
, input_bfd
,
3441 input_section
, contents
,
3442 symtab_hdr
, sym_hashes
,
3443 &r_type
, tls_type
, rel
,
3444 relend
, h
, r_symndx
))
3447 if (r_type
== R_386_TLS_LE_32
)
3449 BFD_ASSERT (! unresolved_reloc
);
3450 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3455 /* GD->LE transition. */
3456 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3459 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3461 movl %gs:0, %eax; subl $foo@tpoff, %eax
3462 (6 byte form of subl). */
3463 memcpy (contents
+ rel
->r_offset
- 3,
3464 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3465 roff
= rel
->r_offset
+ 5;
3469 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3471 movl %gs:0, %eax; subl $foo@tpoff, %eax
3472 (6 byte form of subl). */
3473 memcpy (contents
+ rel
->r_offset
- 2,
3474 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3475 roff
= rel
->r_offset
+ 6;
3477 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3479 /* Skip R_386_PC32/R_386_PLT32. */
3483 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3485 /* GDesc -> LE transition.
3486 It's originally something like:
3487 leal x@tlsdesc(%ebx), %eax
3491 Registers other than %eax may be set up here. */
3496 roff
= rel
->r_offset
;
3497 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3499 /* Now modify the instruction as appropriate. */
3500 /* aoliva FIXME: remove the above and xor the byte
3502 bfd_put_8 (output_bfd
, val
^ 0x86,
3503 contents
+ roff
- 1);
3504 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3508 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3510 /* GDesc -> LE transition.
3518 roff
= rel
->r_offset
;
3519 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3520 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3523 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3527 /* IE->LE transition:
3528 Originally it can be one of:
3536 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3539 /* movl foo, %eax. */
3540 bfd_put_8 (output_bfd
, 0xb8,
3541 contents
+ rel
->r_offset
- 1);
3547 type
= bfd_get_8 (input_bfd
,
3548 contents
+ rel
->r_offset
- 2);
3553 bfd_put_8 (output_bfd
, 0xc7,
3554 contents
+ rel
->r_offset
- 2);
3555 bfd_put_8 (output_bfd
,
3556 0xc0 | ((val
>> 3) & 7),
3557 contents
+ rel
->r_offset
- 1);
3561 bfd_put_8 (output_bfd
, 0x81,
3562 contents
+ rel
->r_offset
- 2);
3563 bfd_put_8 (output_bfd
,
3564 0xc0 | ((val
>> 3) & 7),
3565 contents
+ rel
->r_offset
- 1);
3572 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3573 contents
+ rel
->r_offset
);
3578 unsigned int val
, type
;
3580 /* {IE_32,GOTIE}->LE transition:
3581 Originally it can be one of:
3582 subl foo(%reg1), %reg2
3583 movl foo(%reg1), %reg2
3584 addl foo(%reg1), %reg2
3587 movl $foo, %reg2 (6 byte form)
3588 addl $foo, %reg2. */
3589 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3590 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3594 bfd_put_8 (output_bfd
, 0xc7,
3595 contents
+ rel
->r_offset
- 2);
3596 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3597 contents
+ rel
->r_offset
- 1);
3599 else if (type
== 0x2b)
3602 bfd_put_8 (output_bfd
, 0x81,
3603 contents
+ rel
->r_offset
- 2);
3604 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3605 contents
+ rel
->r_offset
- 1);
3607 else if (type
== 0x03)
3610 bfd_put_8 (output_bfd
, 0x81,
3611 contents
+ rel
->r_offset
- 2);
3612 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3613 contents
+ rel
->r_offset
- 1);
3617 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3618 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3619 contents
+ rel
->r_offset
);
3621 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3622 contents
+ rel
->r_offset
);
3627 if (htab
->elf
.sgot
== NULL
)
3632 off
= h
->got
.offset
;
3633 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3637 if (local_got_offsets
== NULL
)
3640 off
= local_got_offsets
[r_symndx
];
3641 offplt
= local_tlsdesc_gotents
[r_symndx
];
3648 Elf_Internal_Rela outrel
;
3653 if (htab
->elf
.srelgot
== NULL
)
3656 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3658 if (GOT_TLS_GDESC_P (tls_type
))
3660 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3661 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3662 <= htab
->elf
.sgotplt
->size
);
3663 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3664 + htab
->elf
.sgotplt
->output_offset
3666 + htab
->sgotplt_jump_table_size
);
3667 sreloc
= htab
->elf
.srelplt
;
3668 loc
= sreloc
->contents
;
3669 loc
+= (htab
->next_tls_desc_index
++
3670 * sizeof (Elf32_External_Rel
));
3671 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3672 <= sreloc
->contents
+ sreloc
->size
);
3673 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3676 BFD_ASSERT (! unresolved_reloc
);
3677 bfd_put_32 (output_bfd
,
3678 relocation
- elf_i386_dtpoff_base (info
),
3679 htab
->elf
.sgotplt
->contents
+ offplt
3680 + htab
->sgotplt_jump_table_size
+ 4);
3684 bfd_put_32 (output_bfd
, 0,
3685 htab
->elf
.sgotplt
->contents
+ offplt
3686 + htab
->sgotplt_jump_table_size
+ 4);
3690 sreloc
= htab
->elf
.srelgot
;
3692 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3693 + htab
->elf
.sgot
->output_offset
+ off
);
3695 if (GOT_TLS_GD_P (tls_type
))
3696 dr_type
= R_386_TLS_DTPMOD32
;
3697 else if (GOT_TLS_GDESC_P (tls_type
))
3699 else if (tls_type
== GOT_TLS_IE_POS
)
3700 dr_type
= R_386_TLS_TPOFF
;
3702 dr_type
= R_386_TLS_TPOFF32
;
3704 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3705 bfd_put_32 (output_bfd
,
3706 relocation
- elf_i386_dtpoff_base (info
),
3707 htab
->elf
.sgot
->contents
+ off
);
3708 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3709 bfd_put_32 (output_bfd
,
3710 elf_i386_dtpoff_base (info
) - relocation
,
3711 htab
->elf
.sgot
->contents
+ off
);
3712 else if (dr_type
!= R_386_TLS_DESC
)
3713 bfd_put_32 (output_bfd
, 0,
3714 htab
->elf
.sgot
->contents
+ off
);
3715 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3717 loc
= sreloc
->contents
;
3718 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3719 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3720 <= sreloc
->contents
+ sreloc
->size
);
3721 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3723 if (GOT_TLS_GD_P (tls_type
))
3727 BFD_ASSERT (! unresolved_reloc
);
3728 bfd_put_32 (output_bfd
,
3729 relocation
- elf_i386_dtpoff_base (info
),
3730 htab
->elf
.sgot
->contents
+ off
+ 4);
3734 bfd_put_32 (output_bfd
, 0,
3735 htab
->elf
.sgot
->contents
+ off
+ 4);
3736 outrel
.r_info
= ELF32_R_INFO (indx
,
3737 R_386_TLS_DTPOFF32
);
3738 outrel
.r_offset
+= 4;
3739 sreloc
->reloc_count
++;
3740 loc
+= sizeof (Elf32_External_Rel
);
3741 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3742 <= sreloc
->contents
+ sreloc
->size
);
3743 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3746 else if (tls_type
== GOT_TLS_IE_BOTH
)
3748 bfd_put_32 (output_bfd
,
3750 ? relocation
- elf_i386_dtpoff_base (info
)
3752 htab
->elf
.sgot
->contents
+ off
+ 4);
3753 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3754 outrel
.r_offset
+= 4;
3755 sreloc
->reloc_count
++;
3756 loc
+= sizeof (Elf32_External_Rel
);
3757 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3764 local_got_offsets
[r_symndx
] |= 1;
3767 if (off
>= (bfd_vma
) -2
3768 && ! GOT_TLS_GDESC_P (tls_type
))
3770 if (r_type
== R_386_TLS_GOTDESC
3771 || r_type
== R_386_TLS_DESC_CALL
)
3773 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3774 unresolved_reloc
= FALSE
;
3776 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3778 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3779 + htab
->elf
.sgotplt
->output_offset
;
3780 relocation
= htab
->elf
.sgot
->output_section
->vma
3781 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3782 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3783 && tls_type
== GOT_TLS_IE_BOTH
)
3785 if (r_type
== R_386_TLS_IE
)
3786 relocation
+= g_o_t
;
3787 unresolved_reloc
= FALSE
;
3789 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3791 unsigned int val
, type
;
3794 /* GD->IE transition. */
3795 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3796 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3799 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3801 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3803 roff
= rel
->r_offset
- 3;
3807 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3809 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3810 roff
= rel
->r_offset
- 2;
3812 memcpy (contents
+ roff
,
3813 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3814 contents
[roff
+ 7] = 0x80 | (val
& 7);
3815 /* If foo is used only with foo@gotntpoff(%reg) and
3816 foo@indntpoff, but not with foo@gottpoff(%reg), change
3817 subl $foo@gottpoff(%reg), %eax
3819 addl $foo@gotntpoff(%reg), %eax. */
3820 if (tls_type
== GOT_TLS_IE_POS
)
3821 contents
[roff
+ 6] = 0x03;
3822 bfd_put_32 (output_bfd
,
3823 htab
->elf
.sgot
->output_section
->vma
3824 + htab
->elf
.sgot
->output_offset
+ off
3825 - htab
->elf
.sgotplt
->output_section
->vma
3826 - htab
->elf
.sgotplt
->output_offset
,
3827 contents
+ roff
+ 8);
3828 /* Skip R_386_PLT32. */
3832 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3834 /* GDesc -> IE transition.
3835 It's originally something like:
3836 leal x@tlsdesc(%ebx), %eax
3839 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3841 movl x@gottpoff(%ebx), %eax # before negl %eax
3843 Registers other than %eax may be set up here. */
3847 /* First, make sure it's a leal adding ebx to a 32-bit
3848 offset into any register, although it's probably
3849 almost always going to be eax. */
3850 roff
= rel
->r_offset
;
3852 /* Now modify the instruction as appropriate. */
3853 /* To turn a leal into a movl in the form we use it, it
3854 suffices to change the first byte from 0x8d to 0x8b.
3855 aoliva FIXME: should we decide to keep the leal, all
3856 we have to do is remove the statement below, and
3857 adjust the relaxation of R_386_TLS_DESC_CALL. */
3858 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3860 if (tls_type
== GOT_TLS_IE_BOTH
)
3863 bfd_put_32 (output_bfd
,
3864 htab
->elf
.sgot
->output_section
->vma
3865 + htab
->elf
.sgot
->output_offset
+ off
3866 - htab
->elf
.sgotplt
->output_section
->vma
3867 - htab
->elf
.sgotplt
->output_offset
,
3871 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3873 /* GDesc -> IE transition.
3881 depending on how we transformed the TLS_GOTDESC above.
3886 roff
= rel
->r_offset
;
3888 /* Now modify the instruction as appropriate. */
3889 if (tls_type
!= GOT_TLS_IE_NEG
)
3892 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3893 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3898 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3899 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3909 if (! elf_i386_tls_transition (info
, input_bfd
,
3910 input_section
, contents
,
3911 symtab_hdr
, sym_hashes
,
3912 &r_type
, GOT_UNKNOWN
, rel
,
3913 relend
, h
, r_symndx
))
3916 if (r_type
!= R_386_TLS_LDM
)
3918 /* LD->LE transition:
3919 leal foo(%reg), %eax; call ___tls_get_addr.
3921 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3922 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3923 memcpy (contents
+ rel
->r_offset
- 2,
3924 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3925 /* Skip R_386_PC32/R_386_PLT32. */
3930 if (htab
->elf
.sgot
== NULL
)
3933 off
= htab
->tls_ldm_got
.offset
;
3938 Elf_Internal_Rela outrel
;
3941 if (htab
->elf
.srelgot
== NULL
)
3944 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3945 + htab
->elf
.sgot
->output_offset
+ off
);
3947 bfd_put_32 (output_bfd
, 0,
3948 htab
->elf
.sgot
->contents
+ off
);
3949 bfd_put_32 (output_bfd
, 0,
3950 htab
->elf
.sgot
->contents
+ off
+ 4);
3951 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3952 loc
= htab
->elf
.srelgot
->contents
;
3953 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3954 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3955 htab
->tls_ldm_got
.offset
|= 1;
3957 relocation
= htab
->elf
.sgot
->output_section
->vma
3958 + htab
->elf
.sgot
->output_offset
+ off
3959 - htab
->elf
.sgotplt
->output_section
->vma
3960 - htab
->elf
.sgotplt
->output_offset
;
3961 unresolved_reloc
= FALSE
;
3964 case R_386_TLS_LDO_32
:
3965 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3966 relocation
-= elf_i386_dtpoff_base (info
);
3968 /* When converting LDO to LE, we must negate. */
3969 relocation
= -elf_i386_tpoff (info
, relocation
);
3972 case R_386_TLS_LE_32
:
3974 if (!info
->executable
)
3976 Elf_Internal_Rela outrel
;
3980 outrel
.r_offset
= rel
->r_offset
3981 + input_section
->output_section
->vma
3982 + input_section
->output_offset
;
3983 if (h
!= NULL
&& h
->dynindx
!= -1)
3987 if (r_type
== R_386_TLS_LE_32
)
3988 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3990 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3991 sreloc
= elf_section_data (input_section
)->sreloc
;
3994 loc
= sreloc
->contents
;
3995 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3996 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3999 else if (r_type
== R_386_TLS_LE_32
)
4000 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4002 relocation
-= elf_i386_dtpoff_base (info
);
4004 else if (r_type
== R_386_TLS_LE_32
)
4005 relocation
= elf_i386_tpoff (info
, relocation
);
4007 relocation
= -elf_i386_tpoff (info
, relocation
);
4014 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4015 because such sections are not SEC_ALLOC and thus ld.so will
4016 not process them. */
4017 if (unresolved_reloc
4018 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4021 (*_bfd_error_handler
)
4022 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4025 (long) rel
->r_offset
,
4027 h
->root
.root
.string
);
4032 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4033 contents
, rel
->r_offset
,
4036 if (r
!= bfd_reloc_ok
)
4041 name
= h
->root
.root
.string
;
4044 name
= bfd_elf_string_from_elf_section (input_bfd
,
4045 symtab_hdr
->sh_link
,
4050 name
= bfd_section_name (input_bfd
, sec
);
4053 if (r
== bfd_reloc_overflow
)
4055 if (! ((*info
->callbacks
->reloc_overflow
)
4056 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4057 (bfd_vma
) 0, input_bfd
, input_section
,
4063 (*_bfd_error_handler
)
4064 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4065 input_bfd
, input_section
,
4066 (long) rel
->r_offset
, name
, (int) r
);
4075 /* Finish up dynamic symbol handling. We set the contents of various
4076 dynamic sections here. */
4079 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4080 struct bfd_link_info
*info
,
4081 struct elf_link_hash_entry
*h
,
4082 Elf_Internal_Sym
*sym
)
4084 struct elf_i386_link_hash_table
*htab
;
4086 htab
= elf_i386_hash_table (info
);
4090 if (h
->plt
.offset
!= (bfd_vma
) -1)
4094 Elf_Internal_Rela rel
;
4096 asection
*plt
, *gotplt
, *relplt
;
4098 /* When building a static executable, use .iplt, .igot.plt and
4099 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4100 if (htab
->elf
.splt
!= NULL
)
4102 plt
= htab
->elf
.splt
;
4103 gotplt
= htab
->elf
.sgotplt
;
4104 relplt
= htab
->elf
.srelplt
;
4108 plt
= htab
->elf
.iplt
;
4109 gotplt
= htab
->elf
.igotplt
;
4110 relplt
= htab
->elf
.irelplt
;
4113 /* This symbol has an entry in the procedure linkage table. Set
4116 if ((h
->dynindx
== -1
4117 && !((h
->forced_local
|| info
->executable
)
4119 && h
->type
== STT_GNU_IFUNC
))
4125 /* Get the index in the procedure linkage table which
4126 corresponds to this symbol. This is the index of this symbol
4127 in all the symbols for which we are making plt entries. The
4128 first entry in the procedure linkage table is reserved.
4130 Get the offset into the .got table of the entry that
4131 corresponds to this function. Each .got entry is 4 bytes.
4132 The first three are reserved.
4134 For static executables, we don't reserve anything. */
4136 if (plt
== htab
->elf
.splt
)
4138 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
4139 got_offset
= (plt_index
+ 3) * 4;
4143 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4144 got_offset
= plt_index
* 4;
4147 /* Fill in the entry in the procedure linkage table. */
4150 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
4152 bfd_put_32 (output_bfd
,
4153 (gotplt
->output_section
->vma
4154 + gotplt
->output_offset
4156 plt
->contents
+ h
->plt
.offset
+ 2);
4158 if (htab
->is_vxworks
)
4160 int s
, k
, reloc_index
;
4162 /* Create the R_386_32 relocation referencing the GOT
4163 for this PLT entry. */
4165 /* S: Current slot number (zero-based). */
4166 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
4167 /* K: Number of relocations for PLTResolve. */
4169 k
= PLTRESOLVE_RELOCS_SHLIB
;
4171 k
= PLTRESOLVE_RELOCS
;
4172 /* Skip the PLTresolve relocations, and the relocations for
4173 the other PLT slots. */
4174 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4175 loc
= (htab
->srelplt2
->contents
+ reloc_index
4176 * sizeof (Elf32_External_Rel
));
4178 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4179 + htab
->elf
.splt
->output_offset
4180 + h
->plt
.offset
+ 2),
4181 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4182 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4184 /* Create the R_386_32 relocation referencing the beginning of
4185 the PLT for this GOT entry. */
4186 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4187 + htab
->elf
.sgotplt
->output_offset
4189 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4190 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4191 loc
+ sizeof (Elf32_External_Rel
));
4196 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
4198 bfd_put_32 (output_bfd
, got_offset
,
4199 plt
->contents
+ h
->plt
.offset
+ 2);
4202 /* Don't fill PLT entry for static executables. */
4203 if (plt
== htab
->elf
.splt
)
4205 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4206 plt
->contents
+ h
->plt
.offset
+ 7);
4207 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4208 plt
->contents
+ h
->plt
.offset
+ 12);
4211 /* Fill in the entry in the global offset table. */
4212 bfd_put_32 (output_bfd
,
4213 (plt
->output_section
->vma
4214 + plt
->output_offset
4217 gotplt
->contents
+ got_offset
);
4219 /* Fill in the entry in the .rel.plt section. */
4220 rel
.r_offset
= (gotplt
->output_section
->vma
4221 + gotplt
->output_offset
4223 if (h
->dynindx
== -1
4224 || ((info
->executable
4225 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4227 && h
->type
== STT_GNU_IFUNC
))
4229 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4230 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4231 in the .got.plt section. */
4232 bfd_put_32 (output_bfd
,
4233 (h
->root
.u
.def
.value
4234 + h
->root
.u
.def
.section
->output_section
->vma
4235 + h
->root
.u
.def
.section
->output_offset
),
4236 gotplt
->contents
+ got_offset
);
4237 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4240 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4241 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4242 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4244 if (!h
->def_regular
)
4246 /* Mark the symbol as undefined, rather than as defined in
4247 the .plt section. Leave the value if there were any
4248 relocations where pointer equality matters (this is a clue
4249 for the dynamic linker, to make function pointer
4250 comparisons work between an application and shared
4251 library), otherwise set it to zero. If a function is only
4252 called from a binary, there is no need to slow down
4253 shared libraries because of that. */
4254 sym
->st_shndx
= SHN_UNDEF
;
4255 if (!h
->pointer_equality_needed
)
4260 if (h
->got
.offset
!= (bfd_vma
) -1
4261 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4262 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4264 Elf_Internal_Rela rel
;
4267 /* This symbol has an entry in the global offset table. Set it
4270 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4273 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4274 + htab
->elf
.sgot
->output_offset
4275 + (h
->got
.offset
& ~(bfd_vma
) 1));
4277 /* If this is a static link, or it is a -Bsymbolic link and the
4278 symbol is defined locally or was forced to be local because
4279 of a version file, we just want to emit a RELATIVE reloc.
4280 The entry in the global offset table will already have been
4281 initialized in the relocate_section function. */
4283 && h
->type
== STT_GNU_IFUNC
)
4287 /* Generate R_386_GLOB_DAT. */
4294 if (!h
->pointer_equality_needed
)
4297 /* For non-shared object, we can't use .got.plt, which
4298 contains the real function addres if we need pointer
4299 equality. We load the GOT entry with the PLT entry. */
4300 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4301 bfd_put_32 (output_bfd
,
4302 (plt
->output_section
->vma
4303 + plt
->output_offset
+ h
->plt
.offset
),
4304 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4308 else if (info
->shared
4309 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4311 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4312 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4316 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4318 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4319 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4320 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4323 loc
= htab
->elf
.srelgot
->contents
;
4324 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4325 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4330 Elf_Internal_Rela rel
;
4333 /* This symbol needs a copy reloc. Set it up. */
4335 if (h
->dynindx
== -1
4336 || (h
->root
.type
!= bfd_link_hash_defined
4337 && h
->root
.type
!= bfd_link_hash_defweak
)
4338 || htab
->srelbss
== NULL
)
4341 rel
.r_offset
= (h
->root
.u
.def
.value
4342 + h
->root
.u
.def
.section
->output_section
->vma
4343 + h
->root
.u
.def
.section
->output_offset
);
4344 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4345 loc
= htab
->srelbss
->contents
;
4346 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4347 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4350 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4351 be NULL for local symbols.
4353 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
4354 is relative to the ".got" section. */
4356 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4357 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
)))
4358 sym
->st_shndx
= SHN_ABS
;
4363 /* Finish up local dynamic symbol handling. We set the contents of
4364 various dynamic sections here. */
4367 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4369 struct elf_link_hash_entry
*h
4370 = (struct elf_link_hash_entry
*) *slot
;
4371 struct bfd_link_info
*info
4372 = (struct bfd_link_info
*) inf
;
4374 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4378 /* Used to decide how to sort relocs in an optimal manner for the
4379 dynamic linker, before writing them out. */
4381 static enum elf_reloc_type_class
4382 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4384 switch (ELF32_R_TYPE (rela
->r_info
))
4386 case R_386_RELATIVE
:
4387 return reloc_class_relative
;
4388 case R_386_JUMP_SLOT
:
4389 return reloc_class_plt
;
4391 return reloc_class_copy
;
4393 return reloc_class_normal
;
4397 /* Finish up the dynamic sections. */
4400 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4401 struct bfd_link_info
*info
)
4403 struct elf_i386_link_hash_table
*htab
;
4407 htab
= elf_i386_hash_table (info
);
4411 dynobj
= htab
->elf
.dynobj
;
4412 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4414 if (htab
->elf
.dynamic_sections_created
)
4416 Elf32_External_Dyn
*dyncon
, *dynconend
;
4418 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4421 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4422 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4423 for (; dyncon
< dynconend
; dyncon
++)
4425 Elf_Internal_Dyn dyn
;
4428 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4433 if (htab
->is_vxworks
4434 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4439 s
= htab
->elf
.sgotplt
;
4440 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4444 s
= htab
->elf
.srelplt
;
4445 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4449 s
= htab
->elf
.srelplt
;
4450 dyn
.d_un
.d_val
= s
->size
;
4454 /* My reading of the SVR4 ABI indicates that the
4455 procedure linkage table relocs (DT_JMPREL) should be
4456 included in the overall relocs (DT_REL). This is
4457 what Solaris does. However, UnixWare can not handle
4458 that case. Therefore, we override the DT_RELSZ entry
4459 here to make it not include the JMPREL relocs. */
4460 s
= htab
->elf
.srelplt
;
4463 dyn
.d_un
.d_val
-= s
->size
;
4467 /* We may not be using the standard ELF linker script.
4468 If .rel.plt is the first .rel section, we adjust
4469 DT_REL to not include it. */
4470 s
= htab
->elf
.srelplt
;
4473 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4475 dyn
.d_un
.d_ptr
+= s
->size
;
4479 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4482 /* Fill in the first entry in the procedure linkage table. */
4483 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4487 memcpy (htab
->elf
.splt
->contents
, elf_i386_pic_plt0_entry
,
4488 sizeof (elf_i386_pic_plt0_entry
));
4489 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
4490 htab
->plt0_pad_byte
,
4491 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
4495 memcpy (htab
->elf
.splt
->contents
, elf_i386_plt0_entry
,
4496 sizeof(elf_i386_plt0_entry
));
4497 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_plt0_entry
),
4498 htab
->plt0_pad_byte
,
4499 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
4500 bfd_put_32 (output_bfd
,
4501 (htab
->elf
.sgotplt
->output_section
->vma
4502 + htab
->elf
.sgotplt
->output_offset
4504 htab
->elf
.splt
->contents
+ 2);
4505 bfd_put_32 (output_bfd
,
4506 (htab
->elf
.sgotplt
->output_section
->vma
4507 + htab
->elf
.sgotplt
->output_offset
4509 htab
->elf
.splt
->contents
+ 8);
4511 if (htab
->is_vxworks
)
4513 Elf_Internal_Rela rel
;
4515 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4516 On IA32 we use REL relocations so the addend goes in
4517 the PLT directly. */
4518 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4519 + htab
->elf
.splt
->output_offset
4521 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4522 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4523 htab
->srelplt2
->contents
);
4524 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4525 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4526 + htab
->elf
.splt
->output_offset
4528 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4529 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4530 htab
->srelplt2
->contents
+
4531 sizeof (Elf32_External_Rel
));
4535 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4536 really seem like the right value. */
4537 elf_section_data (htab
->elf
.splt
->output_section
)
4538 ->this_hdr
.sh_entsize
= 4;
4540 /* Correct the .rel.plt.unloaded relocations. */
4541 if (htab
->is_vxworks
&& !info
->shared
)
4543 int num_plts
= (htab
->elf
.splt
->size
/ PLT_ENTRY_SIZE
) - 1;
4546 p
= htab
->srelplt2
->contents
;
4548 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4550 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4552 for (; num_plts
; num_plts
--)
4554 Elf_Internal_Rela rel
;
4555 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4556 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4557 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4558 p
+= sizeof (Elf32_External_Rel
);
4560 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4561 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4562 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4563 p
+= sizeof (Elf32_External_Rel
);
4569 if (htab
->elf
.sgotplt
)
4571 /* Fill in the first three entries in the global offset table. */
4572 if (htab
->elf
.sgotplt
->size
> 0)
4574 bfd_put_32 (output_bfd
,
4576 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4577 htab
->elf
.sgotplt
->contents
);
4578 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4579 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4582 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4585 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4586 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4588 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4589 htab_traverse (htab
->loc_hash_table
,
4590 elf_i386_finish_local_dynamic_symbol
,
4596 /* Return address for Ith PLT stub in section PLT, for relocation REL
4597 or (bfd_vma) -1 if it should not be included. */
4600 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4601 const arelent
*rel ATTRIBUTE_UNUSED
)
4603 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4606 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4609 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4611 if (h
->plt
.offset
!= (bfd_vma
) -1
4613 && !h
->pointer_equality_needed
)
4616 return _bfd_elf_hash_symbol (h
);
4619 /* Hook called by the linker routine which adds symbols from an object
4623 elf_i386_add_symbol_hook (bfd
* abfd
,
4624 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4625 Elf_Internal_Sym
* sym
,
4626 const char ** namep ATTRIBUTE_UNUSED
,
4627 flagword
* flagsp ATTRIBUTE_UNUSED
,
4628 asection
** secp ATTRIBUTE_UNUSED
,
4629 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4631 if ((abfd
->flags
& DYNAMIC
) == 0
4632 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4633 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
4638 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4639 #define TARGET_LITTLE_NAME "elf32-i386"
4640 #define ELF_ARCH bfd_arch_i386
4641 #define ELF_MACHINE_CODE EM_386
4642 #define ELF_MAXPAGESIZE 0x1000
4644 #define elf_backend_can_gc_sections 1
4645 #define elf_backend_can_refcount 1
4646 #define elf_backend_want_got_plt 1
4647 #define elf_backend_plt_readonly 1
4648 #define elf_backend_want_plt_sym 0
4649 #define elf_backend_got_header_size 12
4651 /* Support RELA for objdump of prelink objects. */
4652 #define elf_info_to_howto elf_i386_info_to_howto_rel
4653 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4655 #define bfd_elf32_mkobject elf_i386_mkobject
4657 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4658 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4659 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4660 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4661 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4663 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4664 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4665 #define elf_backend_check_relocs elf_i386_check_relocs
4666 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4667 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4668 #define elf_backend_fake_sections elf_i386_fake_sections
4669 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4670 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4671 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4672 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4673 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4674 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4675 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4676 #define elf_backend_relocate_section elf_i386_relocate_section
4677 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4678 #define elf_backend_always_size_sections elf_i386_always_size_sections
4679 #define elf_backend_omit_section_dynsym \
4680 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4681 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4682 #define elf_backend_hash_symbol elf_i386_hash_symbol
4683 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4684 #undef elf_backend_post_process_headers
4685 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4687 #include "elf32-target.h"
4689 /* FreeBSD support. */
4691 #undef TARGET_LITTLE_SYM
4692 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4693 #undef TARGET_LITTLE_NAME
4694 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4696 #define ELF_OSABI ELFOSABI_FREEBSD
4698 /* The kernel recognizes executables as valid only if they carry a
4699 "FreeBSD" label in the ELF header. So we put this label on all
4700 executables and (for simplicity) also all other object files. */
4703 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4705 _bfd_elf_set_osabi (abfd
, info
);
4707 #ifdef OLD_FREEBSD_ABI_LABEL
4708 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4709 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4713 #undef elf_backend_post_process_headers
4714 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4716 #define elf32_bed elf32_i386_fbsd_bed
4718 #undef elf_backend_add_symbol_hook
4720 #include "elf32-target.h"
4724 #undef TARGET_LITTLE_SYM
4725 #define TARGET_LITTLE_SYM bfd_elf32_i386_sol2_vec
4726 #undef TARGET_LITTLE_NAME
4727 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
4729 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4730 objects won't be recognized. */
4734 #define elf32_bed elf32_i386_sol2_bed
4736 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4738 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4740 #undef elf_backend_want_plt_sym
4741 #define elf_backend_want_plt_sym 1
4743 #include "elf32-target.h"
4745 /* VxWorks support. */
4747 #undef TARGET_LITTLE_SYM
4748 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
4749 #undef TARGET_LITTLE_NAME
4750 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4753 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
4755 static struct bfd_link_hash_table
*
4756 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
4758 struct bfd_link_hash_table
*ret
;
4759 struct elf_i386_link_hash_table
*htab
;
4761 ret
= elf_i386_link_hash_table_create (abfd
);
4764 htab
= (struct elf_i386_link_hash_table
*) ret
;
4765 htab
->is_vxworks
= 1;
4766 htab
->plt0_pad_byte
= 0x90;
4773 #undef elf_backend_relocs_compatible
4774 #undef elf_backend_post_process_headers
4775 #undef bfd_elf32_bfd_link_hash_table_create
4776 #define bfd_elf32_bfd_link_hash_table_create \
4777 elf_i386_vxworks_link_hash_table_create
4778 #undef elf_backend_add_symbol_hook
4779 #define elf_backend_add_symbol_hook \
4780 elf_vxworks_add_symbol_hook
4781 #undef elf_backend_link_output_symbol_hook
4782 #define elf_backend_link_output_symbol_hook \
4783 elf_vxworks_link_output_symbol_hook
4784 #undef elf_backend_emit_relocs
4785 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
4786 #undef elf_backend_final_write_processing
4787 #define elf_backend_final_write_processing \
4788 elf_vxworks_final_write_processing
4790 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
4792 #undef elf_backend_want_plt_sym
4793 #define elf_backend_want_plt_sym 1
4796 #define elf32_bed elf32_i386_vxworks_bed
4798 #include "elf32-target.h"