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 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"
29 /* 386 uses REL relocations instead of RELA. */
34 static reloc_howto_type elf_howto_table[]=
36 HOWTO(R_386_NONE, 0, 0, 0, FALSE, 0, complain_overflow_bitfield,
37 bfd_elf_generic_reloc, "R_386_NONE",
38 TRUE, 0x00000000, 0x00000000, FALSE),
39 HOWTO(R_386_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
40 bfd_elf_generic_reloc, "R_386_32",
41 TRUE, 0xffffffff, 0xffffffff, FALSE),
42 HOWTO(R_386_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
43 bfd_elf_generic_reloc, "R_386_PC32",
44 TRUE, 0xffffffff, 0xffffffff, TRUE),
45 HOWTO(R_386_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
46 bfd_elf_generic_reloc, "R_386_GOT32",
47 TRUE, 0xffffffff, 0xffffffff, FALSE),
48 HOWTO(R_386_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
49 bfd_elf_generic_reloc, "R_386_PLT32",
50 TRUE, 0xffffffff, 0xffffffff, TRUE),
51 HOWTO(R_386_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
52 bfd_elf_generic_reloc, "R_386_COPY",
53 TRUE, 0xffffffff, 0xffffffff, FALSE),
54 HOWTO(R_386_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
55 bfd_elf_generic_reloc, "R_386_GLOB_DAT",
56 TRUE, 0xffffffff, 0xffffffff, FALSE),
57 HOWTO(R_386_JUMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
58 bfd_elf_generic_reloc, "R_386_JUMP_SLOT",
59 TRUE, 0xffffffff, 0xffffffff, FALSE),
60 HOWTO(R_386_RELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
61 bfd_elf_generic_reloc, "R_386_RELATIVE",
62 TRUE, 0xffffffff, 0xffffffff, FALSE),
63 HOWTO(R_386_GOTOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
64 bfd_elf_generic_reloc, "R_386_GOTOFF",
65 TRUE, 0xffffffff, 0xffffffff, FALSE),
66 HOWTO(R_386_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
67 bfd_elf_generic_reloc, "R_386_GOTPC",
68 TRUE, 0xffffffff, 0xffffffff, TRUE),
70 /* We have a gap in the reloc numbers here.
71 R_386_standard counts the number up to this point, and
72 R_386_ext_offset is the value to subtract from a reloc type of
73 R_386_16 thru R_386_PC8 to form an index into this table. */
74 #define R_386_standard (R_386_GOTPC + 1)
75 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
77 /* These relocs are a GNU extension. */
78 HOWTO(R_386_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
79 bfd_elf_generic_reloc, "R_386_TLS_TPOFF",
80 TRUE, 0xffffffff, 0xffffffff, FALSE),
81 HOWTO(R_386_TLS_IE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
82 bfd_elf_generic_reloc, "R_386_TLS_IE",
83 TRUE, 0xffffffff, 0xffffffff, FALSE),
84 HOWTO(R_386_TLS_GOTIE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
85 bfd_elf_generic_reloc, "R_386_TLS_GOTIE",
86 TRUE, 0xffffffff, 0xffffffff, FALSE),
87 HOWTO(R_386_TLS_LE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
88 bfd_elf_generic_reloc, "R_386_TLS_LE",
89 TRUE, 0xffffffff, 0xffffffff, FALSE),
90 HOWTO(R_386_TLS_GD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
91 bfd_elf_generic_reloc, "R_386_TLS_GD",
92 TRUE, 0xffffffff, 0xffffffff, FALSE),
93 HOWTO(R_386_TLS_LDM, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
94 bfd_elf_generic_reloc, "R_386_TLS_LDM",
95 TRUE, 0xffffffff, 0xffffffff, FALSE),
96 HOWTO(R_386_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
97 bfd_elf_generic_reloc, "R_386_16",
98 TRUE, 0xffff, 0xffff, FALSE),
99 HOWTO(R_386_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
100 bfd_elf_generic_reloc, "R_386_PC16",
101 TRUE, 0xffff, 0xffff, TRUE),
102 HOWTO(R_386_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
103 bfd_elf_generic_reloc, "R_386_8",
104 TRUE, 0xff, 0xff, FALSE),
105 HOWTO(R_386_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
106 bfd_elf_generic_reloc, "R_386_PC8",
107 TRUE, 0xff, 0xff, TRUE),
109 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
110 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
111 /* These are common with Solaris TLS implementation. */
112 HOWTO(R_386_TLS_LDO_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
113 bfd_elf_generic_reloc, "R_386_TLS_LDO_32",
114 TRUE, 0xffffffff, 0xffffffff, FALSE),
115 HOWTO(R_386_TLS_IE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
116 bfd_elf_generic_reloc, "R_386_TLS_IE_32",
117 TRUE, 0xffffffff, 0xffffffff, FALSE),
118 HOWTO(R_386_TLS_LE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
119 bfd_elf_generic_reloc, "R_386_TLS_LE_32",
120 TRUE, 0xffffffff, 0xffffffff, FALSE),
121 HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
122 bfd_elf_generic_reloc, "R_386_TLS_DTPMOD32",
123 TRUE, 0xffffffff, 0xffffffff, FALSE),
124 HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
125 bfd_elf_generic_reloc, "R_386_TLS_DTPOFF32",
126 TRUE, 0xffffffff, 0xffffffff, FALSE),
127 HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
128 bfd_elf_generic_reloc, "R_386_TLS_TPOFF32",
129 TRUE, 0xffffffff, 0xffffffff, FALSE),
131 HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
132 bfd_elf_generic_reloc, "R_386_TLS_GOTDESC",
133 TRUE, 0xffffffff, 0xffffffff, FALSE),
134 HOWTO(R_386_TLS_DESC_CALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
135 bfd_elf_generic_reloc, "R_386_TLS_DESC_CALL",
137 HOWTO(R_386_TLS_DESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
138 bfd_elf_generic_reloc, "R_386_TLS_DESC",
139 TRUE, 0xffffffff, 0xffffffff, FALSE),
142 #define R_386_tls (R_386_TLS_DESC + 1 - R_386_tls_offset)
143 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_tls)
145 /* GNU extension to record C++ vtable hierarchy. */
146 HOWTO (R_386_GNU_VTINHERIT, /* type */
148 2, /* size (0 = byte, 1 = short, 2 = long) */
150 FALSE, /* pc_relative */
152 complain_overflow_dont, /* complain_on_overflow */
153 NULL, /* special_function */
154 "R_386_GNU_VTINHERIT", /* name */
155 FALSE, /* partial_inplace */
158 FALSE), /* pcrel_offset */
160 /* GNU extension to record C++ vtable member usage. */
161 HOWTO (R_386_GNU_VTENTRY, /* type */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
165 FALSE, /* pc_relative */
167 complain_overflow_dont, /* complain_on_overflow */
168 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
169 "R_386_GNU_VTENTRY", /* name */
170 FALSE, /* partial_inplace */
173 FALSE) /* pcrel_offset */
175 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
179 #ifdef DEBUG_GEN_RELOC
181 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
186 static reloc_howto_type *
187 elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
188 bfd_reloc_code_real_type code)
193 TRACE ("BFD_RELOC_NONE");
194 return &elf_howto_table[R_386_NONE];
197 TRACE ("BFD_RELOC_32");
198 return &elf_howto_table[R_386_32];
201 TRACE ("BFD_RELOC_CTOR");
202 return &elf_howto_table[R_386_32];
204 case BFD_RELOC_32_PCREL:
205 TRACE ("BFD_RELOC_PC32");
206 return &elf_howto_table[R_386_PC32];
208 case BFD_RELOC_386_GOT32:
209 TRACE ("BFD_RELOC_386_GOT32");
210 return &elf_howto_table[R_386_GOT32];
212 case BFD_RELOC_386_PLT32:
213 TRACE ("BFD_RELOC_386_PLT32");
214 return &elf_howto_table[R_386_PLT32];
216 case BFD_RELOC_386_COPY:
217 TRACE ("BFD_RELOC_386_COPY");
218 return &elf_howto_table[R_386_COPY];
220 case BFD_RELOC_386_GLOB_DAT:
221 TRACE ("BFD_RELOC_386_GLOB_DAT");
222 return &elf_howto_table[R_386_GLOB_DAT];
224 case BFD_RELOC_386_JUMP_SLOT:
225 TRACE ("BFD_RELOC_386_JUMP_SLOT");
226 return &elf_howto_table[R_386_JUMP_SLOT];
228 case BFD_RELOC_386_RELATIVE:
229 TRACE ("BFD_RELOC_386_RELATIVE");
230 return &elf_howto_table[R_386_RELATIVE];
232 case BFD_RELOC_386_GOTOFF:
233 TRACE ("BFD_RELOC_386_GOTOFF");
234 return &elf_howto_table[R_386_GOTOFF];
236 case BFD_RELOC_386_GOTPC:
237 TRACE ("BFD_RELOC_386_GOTPC");
238 return &elf_howto_table[R_386_GOTPC];
240 /* These relocs are a GNU extension. */
241 case BFD_RELOC_386_TLS_TPOFF:
242 TRACE ("BFD_RELOC_386_TLS_TPOFF");
243 return &elf_howto_table[R_386_TLS_TPOFF - R_386_ext_offset];
245 case BFD_RELOC_386_TLS_IE:
246 TRACE ("BFD_RELOC_386_TLS_IE");
247 return &elf_howto_table[R_386_TLS_IE - R_386_ext_offset];
249 case BFD_RELOC_386_TLS_GOTIE:
250 TRACE ("BFD_RELOC_386_TLS_GOTIE");
251 return &elf_howto_table[R_386_TLS_GOTIE - R_386_ext_offset];
253 case BFD_RELOC_386_TLS_LE:
254 TRACE ("BFD_RELOC_386_TLS_LE");
255 return &elf_howto_table[R_386_TLS_LE - R_386_ext_offset];
257 case BFD_RELOC_386_TLS_GD:
258 TRACE ("BFD_RELOC_386_TLS_GD");
259 return &elf_howto_table[R_386_TLS_GD - R_386_ext_offset];
261 case BFD_RELOC_386_TLS_LDM:
262 TRACE ("BFD_RELOC_386_TLS_LDM");
263 return &elf_howto_table[R_386_TLS_LDM - R_386_ext_offset];
266 TRACE ("BFD_RELOC_16");
267 return &elf_howto_table[R_386_16 - R_386_ext_offset];
269 case BFD_RELOC_16_PCREL:
270 TRACE ("BFD_RELOC_16_PCREL");
271 return &elf_howto_table[R_386_PC16 - R_386_ext_offset];
274 TRACE ("BFD_RELOC_8");
275 return &elf_howto_table[R_386_8 - R_386_ext_offset];
277 case BFD_RELOC_8_PCREL:
278 TRACE ("BFD_RELOC_8_PCREL");
279 return &elf_howto_table[R_386_PC8 - R_386_ext_offset];
281 /* Common with Sun TLS implementation. */
282 case BFD_RELOC_386_TLS_LDO_32:
283 TRACE ("BFD_RELOC_386_TLS_LDO_32");
284 return &elf_howto_table[R_386_TLS_LDO_32 - R_386_tls_offset];
286 case BFD_RELOC_386_TLS_IE_32:
287 TRACE ("BFD_RELOC_386_TLS_IE_32");
288 return &elf_howto_table[R_386_TLS_IE_32 - R_386_tls_offset];
290 case BFD_RELOC_386_TLS_LE_32:
291 TRACE ("BFD_RELOC_386_TLS_LE_32");
292 return &elf_howto_table[R_386_TLS_LE_32 - R_386_tls_offset];
294 case BFD_RELOC_386_TLS_DTPMOD32:
295 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
296 return &elf_howto_table[R_386_TLS_DTPMOD32 - R_386_tls_offset];
298 case BFD_RELOC_386_TLS_DTPOFF32:
299 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
300 return &elf_howto_table[R_386_TLS_DTPOFF32 - R_386_tls_offset];
302 case BFD_RELOC_386_TLS_TPOFF32:
303 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
304 return &elf_howto_table[R_386_TLS_TPOFF32 - R_386_tls_offset];
306 case BFD_RELOC_386_TLS_GOTDESC:
307 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
308 return &elf_howto_table[R_386_TLS_GOTDESC - R_386_tls_offset];
310 case BFD_RELOC_386_TLS_DESC_CALL:
311 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
312 return &elf_howto_table[R_386_TLS_DESC_CALL - R_386_tls_offset];
314 case BFD_RELOC_386_TLS_DESC:
315 TRACE ("BFD_RELOC_386_TLS_DESC");
316 return &elf_howto_table[R_386_TLS_DESC - R_386_tls_offset];
318 case BFD_RELOC_VTABLE_INHERIT:
319 TRACE ("BFD_RELOC_VTABLE_INHERIT");
320 return &elf_howto_table[R_386_GNU_VTINHERIT - R_386_vt_offset];
322 case BFD_RELOC_VTABLE_ENTRY:
323 TRACE ("BFD_RELOC_VTABLE_ENTRY");
324 return &elf_howto_table[R_386_GNU_VTENTRY - R_386_vt_offset];
334 static reloc_howto_type *
335 elf_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
340 for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++)
341 if (elf_howto_table[i].name != NULL
342 && strcasecmp (elf_howto_table[i].name, r_name) == 0)
343 return &elf_howto_table[i];
349 elf_i386_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
351 Elf_Internal_Rela *dst)
353 unsigned int r_type = ELF32_R_TYPE (dst->r_info);
356 if ((indx = r_type) >= R_386_standard
357 && ((indx = r_type - R_386_ext_offset) - R_386_standard
358 >= R_386_ext - R_386_standard)
359 && ((indx = r_type - R_386_tls_offset) - R_386_ext
360 >= R_386_tls - R_386_ext)
361 && ((indx = r_type - R_386_vt_offset) - R_386_tls
362 >= R_386_vt - R_386_tls))
364 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
368 cache_ptr->howto = &elf_howto_table[indx];
371 /* Return whether a symbol name implies a local label. The UnixWare
372 2.1 cc generates temporary symbols that start with .X, so we
373 recognize them here. FIXME: do other SVR4 compilers also use .X?.
374 If so, we should move the .X recognition into
375 _bfd_elf_is_local_label_name. */
378 elf_i386_is_local_label_name (bfd *abfd, const char *name)
380 if (name[0] == '.' && name[1] == 'X')
383 return _bfd_elf_is_local_label_name (abfd, name);
386 /* Support for core dump NOTE sections. */
389 elf_i386_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
394 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
396 int pr_version = bfd_get_32 (abfd, note->descdata);
402 elf_tdata (abfd)->core_signal = bfd_get_32 (abfd, note->descdata + 20);
405 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
409 size = bfd_get_32 (abfd, note->descdata + 8);
413 switch (note->descsz)
418 case 144: /* Linux/i386 */
420 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
423 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
433 /* Make a ".reg/999" section. */
434 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
435 size, note->descpos + offset);
439 elf_i386_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
441 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
443 int pr_version = bfd_get_32 (abfd, note->descdata);
448 elf_tdata (abfd)->core_program
449 = _bfd_elfcore_strndup (abfd, note->descdata + 8, 17);
450 elf_tdata (abfd)->core_command
451 = _bfd_elfcore_strndup (abfd, note->descdata + 25, 81);
455 switch (note->descsz)
460 case 124: /* Linux/i386 elf_prpsinfo. */
461 elf_tdata (abfd)->core_program
462 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
463 elf_tdata (abfd)->core_command
464 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
468 /* Note that for some reason, a spurious space is tacked
469 onto the end of the args in some (at least one anyway)
470 implementations, so strip it off if it exists. */
472 char *command = elf_tdata (abfd)->core_command;
473 int n = strlen (command);
475 if (0 < n && command[n - 1] == ' ')
476 command[n - 1] = '\0';
482 /* Functions for the i386 ELF linker.
484 In order to gain some understanding of code in this file without
485 knowing all the intricate details of the linker, note the
488 Functions named elf_i386_* are called by external routines, other
489 functions are only called locally. elf_i386_* functions appear
490 in this file more or less in the order in which they are called
491 from external routines. eg. elf_i386_check_relocs is called
492 early in the link process, elf_i386_finish_dynamic_sections is
493 one of the last functions. */
496 /* The name of the dynamic interpreter. This is put in the .interp
499 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
501 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
502 copying dynamic variables from a shared lib into an app's dynbss
503 section, and instead use a dynamic relocation to point into the
505 #define ELIMINATE_COPY_RELOCS 1
507 /* The size in bytes of an entry in the procedure linkage table. */
509 #define PLT_ENTRY_SIZE 16
511 /* The first entry in an absolute procedure linkage table looks like
512 this. See the SVR4 ABI i386 supplement to see how this works.
513 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
515 static const bfd_byte elf_i386_plt0_entry[12] =
517 0xff, 0x35, /* pushl contents of address */
518 0, 0, 0, 0, /* replaced with address of .got + 4. */
519 0xff, 0x25, /* jmp indirect */
520 0, 0, 0, 0 /* replaced with address of .got + 8. */
523 /* Subsequent entries in an absolute procedure linkage table look like
526 static const bfd_byte elf_i386_plt_entry[PLT_ENTRY_SIZE] =
528 0xff, 0x25, /* jmp indirect */
529 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
530 0x68, /* pushl immediate */
531 0, 0, 0, 0, /* replaced with offset into relocation table. */
532 0xe9, /* jmp relative */
533 0, 0, 0, 0 /* replaced with offset to start of .plt. */
536 /* The first entry in a PIC procedure linkage table look like this.
537 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
539 static const bfd_byte elf_i386_pic_plt0_entry[12] =
541 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
542 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
545 /* Subsequent entries in a PIC procedure linkage table look like this. */
547 static const bfd_byte elf_i386_pic_plt_entry[PLT_ENTRY_SIZE] =
549 0xff, 0xa3, /* jmp *offset(%ebx) */
550 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
551 0x68, /* pushl immediate */
552 0, 0, 0, 0, /* replaced with offset into relocation table. */
553 0xe9, /* jmp relative */
554 0, 0, 0, 0 /* replaced with offset to start of .plt. */
557 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
558 for the PLTResolve stub and then for each PLT entry. */
559 #define PLTRESOLVE_RELOCS_SHLIB 0
560 #define PLTRESOLVE_RELOCS 2
561 #define PLT_NON_JUMP_SLOT_RELOCS 2
563 /* The i386 linker needs to keep track of the number of relocs that it
564 decides to copy as dynamic relocs in check_relocs for each symbol.
565 This is so that it can later discard them if they are found to be
566 unnecessary. We store the information in a field extending the
567 regular ELF linker hash table. */
569 struct elf_i386_dyn_relocs
571 struct elf_i386_dyn_relocs *next;
573 /* The input section of the reloc. */
576 /* Total number of relocs copied for the input section. */
579 /* Number of pc-relative relocs copied for the input section. */
580 bfd_size_type pc_count;
583 /* i386 ELF linker hash entry. */
585 struct elf_i386_link_hash_entry
587 struct elf_link_hash_entry elf;
589 /* Track dynamic relocs copied for this symbol. */
590 struct elf_i386_dyn_relocs *dyn_relocs;
592 #define GOT_UNKNOWN 0
596 #define GOT_TLS_IE_POS 5
597 #define GOT_TLS_IE_NEG 6
598 #define GOT_TLS_IE_BOTH 7
599 #define GOT_TLS_GDESC 8
600 #define GOT_TLS_GD_BOTH_P(type) \
601 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
602 #define GOT_TLS_GD_P(type) \
603 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
604 #define GOT_TLS_GDESC_P(type) \
605 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
606 #define GOT_TLS_GD_ANY_P(type) \
607 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
608 unsigned char tls_type;
610 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
611 starting at the end of the jump table. */
615 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
617 struct elf_i386_obj_tdata
619 struct elf_obj_tdata root;
621 /* tls_type for each local got entry. */
622 char *local_got_tls_type;
624 /* GOTPLT entries for TLS descriptors. */
625 bfd_vma *local_tlsdesc_gotent;
628 #define elf_i386_tdata(abfd) \
629 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
631 #define elf_i386_local_got_tls_type(abfd) \
632 (elf_i386_tdata (abfd)->local_got_tls_type)
634 #define elf_i386_local_tlsdesc_gotent(abfd) \
635 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
638 elf_i386_mkobject (bfd *abfd)
640 if (abfd->tdata.any == NULL)
642 bfd_size_type amt = sizeof (struct elf_i386_obj_tdata);
643 abfd->tdata.any = bfd_zalloc (abfd, amt);
644 if (abfd->tdata.any == NULL)
647 return bfd_elf_mkobject (abfd);
650 /* i386 ELF linker hash table. */
652 struct elf_i386_link_hash_table
654 struct elf_link_hash_table elf;
656 /* Short-cuts to get to dynamic linker sections. */
665 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
668 /* True if the target system is VxWorks. */
671 /* Value used to fill the last word of the first plt entry. */
672 bfd_byte plt0_pad_byte;
674 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
675 bfd_vma next_tls_desc_index;
678 bfd_signed_vma refcount;
682 /* The amount of space used by the reserved portion of the sgotplt
683 section, plus whatever space is used by the jump slots. */
684 bfd_vma sgotplt_jump_table_size;
686 /* Small local sym to section mapping cache. */
687 struct sym_sec_cache sym_sec;
690 /* Get the i386 ELF linker hash table from a link_info structure. */
692 #define elf_i386_hash_table(p) \
693 ((struct elf_i386_link_hash_table *) ((p)->hash))
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 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 = bfd_hash_allocate (table,
710 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 /* Create an i386 ELF linker hash table. */
732 static struct bfd_link_hash_table *
733 elf_i386_link_hash_table_create (bfd *abfd)
735 struct elf_i386_link_hash_table *ret;
736 bfd_size_type amt = sizeof (struct elf_i386_link_hash_table);
738 ret = bfd_malloc (amt);
742 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
743 sizeof (struct elf_i386_link_hash_entry)))
756 ret->tls_ldm_got.refcount = 0;
757 ret->next_tls_desc_index = 0;
758 ret->sgotplt_jump_table_size = 0;
759 ret->sym_sec.abfd = NULL;
761 ret->srelplt2 = NULL;
762 ret->plt0_pad_byte = 0;
764 return &ret->elf.root;
767 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
768 shortcuts to them in our hash table. */
771 create_got_section (bfd *dynobj, struct bfd_link_info *info)
773 struct elf_i386_link_hash_table *htab;
775 if (! _bfd_elf_create_got_section (dynobj, info))
778 htab = elf_i386_hash_table (info);
779 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
780 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
781 if (!htab->sgot || !htab->sgotplt)
784 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rel.got",
785 (SEC_ALLOC | SEC_LOAD
790 if (htab->srelgot == NULL
791 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
796 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
797 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
801 elf_i386_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
803 struct elf_i386_link_hash_table *htab;
805 htab = elf_i386_hash_table (info);
806 if (!htab->sgot && !create_got_section (dynobj, info))
809 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
812 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
813 htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt");
814 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
816 htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss");
818 if (!htab->splt || !htab->srelplt || !htab->sdynbss
819 || (!info->shared && !htab->srelbss))
823 && !elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
829 /* Copy the extra info we tack onto an elf_link_hash_entry. */
832 elf_i386_copy_indirect_symbol (struct bfd_link_info *info,
833 struct elf_link_hash_entry *dir,
834 struct elf_link_hash_entry *ind)
836 struct elf_i386_link_hash_entry *edir, *eind;
838 edir = (struct elf_i386_link_hash_entry *) dir;
839 eind = (struct elf_i386_link_hash_entry *) ind;
841 if (eind->dyn_relocs != NULL)
843 if (edir->dyn_relocs != NULL)
845 struct elf_i386_dyn_relocs **pp;
846 struct elf_i386_dyn_relocs *p;
848 /* Add reloc counts against the indirect sym to the direct sym
849 list. Merge any entries against the same section. */
850 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
852 struct elf_i386_dyn_relocs *q;
854 for (q = edir->dyn_relocs; q != NULL; q = q->next)
855 if (q->sec == p->sec)
857 q->pc_count += p->pc_count;
858 q->count += p->count;
865 *pp = edir->dyn_relocs;
868 edir->dyn_relocs = eind->dyn_relocs;
869 eind->dyn_relocs = NULL;
872 if (ind->root.type == bfd_link_hash_indirect
873 && dir->got.refcount <= 0)
875 edir->tls_type = eind->tls_type;
876 eind->tls_type = GOT_UNKNOWN;
879 if (ELIMINATE_COPY_RELOCS
880 && ind->root.type != bfd_link_hash_indirect
881 && dir->dynamic_adjusted)
883 /* If called to transfer flags for a weakdef during processing
884 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
885 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
886 dir->ref_dynamic |= ind->ref_dynamic;
887 dir->ref_regular |= ind->ref_regular;
888 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
889 dir->needs_plt |= ind->needs_plt;
890 dir->pointer_equality_needed |= ind->pointer_equality_needed;
893 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
897 elf_i386_tls_transition (struct bfd_link_info *info, int r_type,
906 case R_386_TLS_GOTDESC:
907 case R_386_TLS_DESC_CALL:
908 case R_386_TLS_IE_32:
910 return R_386_TLS_LE_32;
911 return R_386_TLS_IE_32;
913 case R_386_TLS_GOTIE:
915 return R_386_TLS_LE_32;
918 return R_386_TLS_LE_32;
924 /* Look through the relocs for a section during the first phase, and
925 calculate needed space in the global offset table, procedure linkage
926 table, and dynamic reloc sections. */
929 elf_i386_check_relocs (bfd *abfd,
930 struct bfd_link_info *info,
932 const Elf_Internal_Rela *relocs)
934 struct elf_i386_link_hash_table *htab;
935 Elf_Internal_Shdr *symtab_hdr;
936 struct elf_link_hash_entry **sym_hashes;
937 const Elf_Internal_Rela *rel;
938 const Elf_Internal_Rela *rel_end;
941 if (info->relocatable)
944 htab = elf_i386_hash_table (info);
945 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
946 sym_hashes = elf_sym_hashes (abfd);
950 rel_end = relocs + sec->reloc_count;
951 for (rel = relocs; rel < rel_end; rel++)
954 unsigned long r_symndx;
955 struct elf_link_hash_entry *h;
957 r_symndx = ELF32_R_SYM (rel->r_info);
958 r_type = ELF32_R_TYPE (rel->r_info);
960 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
962 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
968 if (r_symndx < symtab_hdr->sh_info)
972 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
973 while (h->root.type == bfd_link_hash_indirect
974 || h->root.type == bfd_link_hash_warning)
975 h = (struct elf_link_hash_entry *) h->root.u.i.link;
978 r_type = elf_i386_tls_transition (info, r_type, h == NULL);
983 htab->tls_ldm_got.refcount += 1;
987 /* This symbol requires a procedure linkage table entry. We
988 actually build the entry in adjust_dynamic_symbol,
989 because this might be a case of linking PIC code which is
990 never referenced by a dynamic object, in which case we
991 don't need to generate a procedure linkage table entry
994 /* If this is a local symbol, we resolve it directly without
995 creating a procedure linkage table entry. */
1000 h->plt.refcount += 1;
1003 case R_386_TLS_IE_32:
1005 case R_386_TLS_GOTIE:
1007 info->flags |= DF_STATIC_TLS;
1012 case R_386_TLS_GOTDESC:
1013 case R_386_TLS_DESC_CALL:
1014 /* This symbol requires a global offset table entry. */
1016 int tls_type, old_tls_type;
1021 case R_386_GOT32: tls_type = GOT_NORMAL; break;
1022 case R_386_TLS_GD: tls_type = GOT_TLS_GD; break;
1023 case R_386_TLS_GOTDESC:
1024 case R_386_TLS_DESC_CALL:
1025 tls_type = GOT_TLS_GDESC; break;
1026 case R_386_TLS_IE_32:
1027 if (ELF32_R_TYPE (rel->r_info) == r_type)
1028 tls_type = GOT_TLS_IE_NEG;
1030 /* If this is a GD->IE transition, we may use either of
1031 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1032 tls_type = GOT_TLS_IE;
1035 case R_386_TLS_GOTIE:
1036 tls_type = GOT_TLS_IE_POS; break;
1041 h->got.refcount += 1;
1042 old_tls_type = elf_i386_hash_entry(h)->tls_type;
1046 bfd_signed_vma *local_got_refcounts;
1048 /* This is a global offset table entry for a local symbol. */
1049 local_got_refcounts = elf_local_got_refcounts (abfd);
1050 if (local_got_refcounts == NULL)
1054 size = symtab_hdr->sh_info;
1055 size *= (sizeof (bfd_signed_vma)
1056 + sizeof (bfd_vma) + sizeof(char));
1057 local_got_refcounts = bfd_zalloc (abfd, size);
1058 if (local_got_refcounts == NULL)
1060 elf_local_got_refcounts (abfd) = local_got_refcounts;
1061 elf_i386_local_tlsdesc_gotent (abfd)
1062 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1063 elf_i386_local_got_tls_type (abfd)
1064 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1066 local_got_refcounts[r_symndx] += 1;
1067 old_tls_type = elf_i386_local_got_tls_type (abfd) [r_symndx];
1070 if ((old_tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_IE))
1071 tls_type |= old_tls_type;
1072 /* If a TLS symbol is accessed using IE at least once,
1073 there is no point to use dynamic model for it. */
1074 else if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1075 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1076 || (tls_type & GOT_TLS_IE) == 0))
1078 if ((old_tls_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (tls_type))
1079 tls_type = old_tls_type;
1080 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1081 && GOT_TLS_GD_ANY_P (tls_type))
1082 tls_type |= old_tls_type;
1085 (*_bfd_error_handler)
1086 (_("%B: `%s' accessed both as normal and "
1087 "thread local symbol"),
1089 h ? h->root.root.string : "<local>");
1094 if (old_tls_type != tls_type)
1097 elf_i386_hash_entry (h)->tls_type = tls_type;
1099 elf_i386_local_got_tls_type (abfd) [r_symndx] = tls_type;
1107 if (htab->sgot == NULL)
1109 if (htab->elf.dynobj == NULL)
1110 htab->elf.dynobj = abfd;
1111 if (!create_got_section (htab->elf.dynobj, info))
1114 if (r_type != R_386_TLS_IE)
1118 case R_386_TLS_LE_32:
1122 info->flags |= DF_STATIC_TLS;
1127 if (h != NULL && !info->shared)
1129 /* If this reloc is in a read-only section, we might
1130 need a copy reloc. We can't check reliably at this
1131 stage whether the section is read-only, as input
1132 sections have not yet been mapped to output sections.
1133 Tentatively set the flag for now, and correct in
1134 adjust_dynamic_symbol. */
1137 /* We may need a .plt entry if the function this reloc
1138 refers to is in a shared lib. */
1139 h->plt.refcount += 1;
1140 if (r_type != R_386_PC32)
1141 h->pointer_equality_needed = 1;
1144 /* If we are creating a shared library, and this is a reloc
1145 against a global symbol, or a non PC relative reloc
1146 against a local symbol, then we need to copy the reloc
1147 into the shared library. However, if we are linking with
1148 -Bsymbolic, we do not need to copy a reloc against a
1149 global symbol which is defined in an object we are
1150 including in the link (i.e., DEF_REGULAR is set). At
1151 this point we have not seen all the input files, so it is
1152 possible that DEF_REGULAR is not set now but will be set
1153 later (it is never cleared). In case of a weak definition,
1154 DEF_REGULAR may be cleared later by a strong definition in
1155 a shared library. We account for that possibility below by
1156 storing information in the relocs_copied field of the hash
1157 table entry. A similar situation occurs when creating
1158 shared libraries and symbol visibility changes render the
1161 If on the other hand, we are creating an executable, we
1162 may need to keep relocations for symbols satisfied by a
1163 dynamic library if we manage to avoid copy relocs for the
1166 && (sec->flags & SEC_ALLOC) != 0
1167 && (r_type != R_386_PC32
1169 && (! SYMBOLIC_BIND (info, h)
1170 || h->root.type == bfd_link_hash_defweak
1171 || !h->def_regular))))
1172 || (ELIMINATE_COPY_RELOCS
1174 && (sec->flags & SEC_ALLOC) != 0
1176 && (h->root.type == bfd_link_hash_defweak
1177 || !h->def_regular)))
1179 struct elf_i386_dyn_relocs *p;
1180 struct elf_i386_dyn_relocs **head;
1182 /* We must copy these reloc types into the output file.
1183 Create a reloc section in dynobj and make room for
1189 unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
1190 unsigned int shnam = elf_section_data (sec)->rel_hdr.sh_name;
1192 name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
1196 if (! CONST_STRNEQ (name, ".rel")
1197 || strcmp (bfd_get_section_name (abfd, sec),
1200 (*_bfd_error_handler)
1201 (_("%B: bad relocation section name `%s\'"),
1205 if (htab->elf.dynobj == NULL)
1206 htab->elf.dynobj = abfd;
1208 dynobj = htab->elf.dynobj;
1209 sreloc = bfd_get_section_by_name (dynobj, name);
1214 flags = (SEC_HAS_CONTENTS | SEC_READONLY
1215 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1216 if ((sec->flags & SEC_ALLOC) != 0)
1217 flags |= SEC_ALLOC | SEC_LOAD;
1218 sreloc = bfd_make_section_with_flags (dynobj,
1222 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
1225 elf_section_data (sec)->sreloc = sreloc;
1228 /* If this is a global symbol, we count the number of
1229 relocations we need for this symbol. */
1232 head = &((struct elf_i386_link_hash_entry *) h)->dyn_relocs;
1237 /* Track dynamic relocs needed for local syms too.
1238 We really need local syms available to do this
1242 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
1247 vpp = &elf_section_data (s)->local_dynrel;
1248 head = (struct elf_i386_dyn_relocs **)vpp;
1252 if (p == NULL || p->sec != sec)
1254 bfd_size_type amt = sizeof *p;
1255 p = bfd_alloc (htab->elf.dynobj, amt);
1266 if (r_type == R_386_PC32)
1271 /* This relocation describes the C++ object vtable hierarchy.
1272 Reconstruct it for later use during GC. */
1273 case R_386_GNU_VTINHERIT:
1274 BFD_ASSERT (h != NULL);
1276 && !bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1280 /* This relocation describes which C++ vtable entries are actually
1281 used. Record for later use during GC. */
1282 case R_386_GNU_VTENTRY:
1283 BFD_ASSERT (h != NULL);
1285 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
1297 /* Return the section that should be marked against GC for a given
1301 elf_i386_gc_mark_hook (asection *sec,
1302 struct bfd_link_info *info,
1303 Elf_Internal_Rela *rel,
1304 struct elf_link_hash_entry *h,
1305 Elf_Internal_Sym *sym)
1308 switch (ELF32_R_TYPE (rel->r_info))
1310 case R_386_GNU_VTINHERIT:
1311 case R_386_GNU_VTENTRY:
1315 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1318 /* Update the got entry reference counts for the section being removed. */
1321 elf_i386_gc_sweep_hook (bfd *abfd,
1322 struct bfd_link_info *info,
1324 const Elf_Internal_Rela *relocs)
1326 Elf_Internal_Shdr *symtab_hdr;
1327 struct elf_link_hash_entry **sym_hashes;
1328 bfd_signed_vma *local_got_refcounts;
1329 const Elf_Internal_Rela *rel, *relend;
1331 elf_section_data (sec)->local_dynrel = NULL;
1333 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1334 sym_hashes = elf_sym_hashes (abfd);
1335 local_got_refcounts = elf_local_got_refcounts (abfd);
1337 relend = relocs + sec->reloc_count;
1338 for (rel = relocs; rel < relend; rel++)
1340 unsigned long r_symndx;
1341 unsigned int r_type;
1342 struct elf_link_hash_entry *h = NULL;
1344 r_symndx = ELF32_R_SYM (rel->r_info);
1345 if (r_symndx >= symtab_hdr->sh_info)
1347 struct elf_i386_link_hash_entry *eh;
1348 struct elf_i386_dyn_relocs **pp;
1349 struct elf_i386_dyn_relocs *p;
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;
1355 eh = (struct elf_i386_link_hash_entry *) h;
1357 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1360 /* Everything must go for SEC. */
1366 r_type = ELF32_R_TYPE (rel->r_info);
1367 r_type = elf_i386_tls_transition (info, r_type, h != NULL);
1371 if (elf_i386_hash_table (info)->tls_ldm_got.refcount > 0)
1372 elf_i386_hash_table (info)->tls_ldm_got.refcount -= 1;
1376 case R_386_TLS_GOTDESC:
1377 case R_386_TLS_DESC_CALL:
1378 case R_386_TLS_IE_32:
1380 case R_386_TLS_GOTIE:
1384 if (h->got.refcount > 0)
1385 h->got.refcount -= 1;
1387 else if (local_got_refcounts != NULL)
1389 if (local_got_refcounts[r_symndx] > 0)
1390 local_got_refcounts[r_symndx] -= 1;
1403 if (h->plt.refcount > 0)
1404 h->plt.refcount -= 1;
1416 /* Adjust a symbol defined by a dynamic object and referenced by a
1417 regular object. The current definition is in some section of the
1418 dynamic object, but we're not including those sections. We have to
1419 change the definition to something the rest of the link can
1423 elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
1424 struct elf_link_hash_entry *h)
1426 struct elf_i386_link_hash_table *htab;
1429 /* If this is a function, put it in the procedure linkage table. We
1430 will fill in the contents of the procedure linkage table later,
1431 when we know the address of the .got section. */
1432 if (h->type == STT_FUNC
1435 if (h->plt.refcount <= 0
1436 || SYMBOL_CALLS_LOCAL (info, h)
1437 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1438 && h->root.type == bfd_link_hash_undefweak))
1440 /* This case can occur if we saw a PLT32 reloc in an input
1441 file, but the symbol was never referred to by a dynamic
1442 object, or if all references were garbage collected. In
1443 such a case, we don't actually need to build a procedure
1444 linkage table, and we can just do a PC32 reloc instead. */
1445 h->plt.offset = (bfd_vma) -1;
1452 /* It's possible that we incorrectly decided a .plt reloc was
1453 needed for an R_386_PC32 reloc to a non-function sym in
1454 check_relocs. We can't decide accurately between function and
1455 non-function syms in check-relocs; Objects loaded later in
1456 the link may change h->type. So fix it now. */
1457 h->plt.offset = (bfd_vma) -1;
1459 /* If this is a weak symbol, and there is a real definition, the
1460 processor independent code will have arranged for us to see the
1461 real definition first, and we can just use the same value. */
1462 if (h->u.weakdef != NULL)
1464 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1465 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1466 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1467 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1468 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1469 h->non_got_ref = h->u.weakdef->non_got_ref;
1473 /* This is a reference to a symbol defined by a dynamic object which
1474 is not a function. */
1476 /* If we are creating a shared library, we must presume that the
1477 only references to the symbol are via the global offset table.
1478 For such cases we need not do anything here; the relocations will
1479 be handled correctly by relocate_section. */
1483 /* If there are no references to this symbol that do not use the
1484 GOT, we don't need to generate a copy reloc. */
1485 if (!h->non_got_ref)
1488 /* If -z nocopyreloc was given, we won't generate them either. */
1489 if (info->nocopyreloc)
1495 htab = elf_i386_hash_table (info);
1497 /* If there aren't any dynamic relocs in read-only sections, then
1498 we can keep the dynamic relocs and avoid the copy reloc. This
1499 doesn't work on VxWorks, where we can not have dynamic relocations
1500 (other than copy and jump slot relocations) in an executable. */
1501 if (ELIMINATE_COPY_RELOCS && !htab->is_vxworks)
1503 struct elf_i386_link_hash_entry * eh;
1504 struct elf_i386_dyn_relocs *p;
1506 eh = (struct elf_i386_link_hash_entry *) h;
1507 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1509 s = p->sec->output_section;
1510 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1523 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
1524 h->root.root.string);
1528 /* We must allocate the symbol in our .dynbss section, which will
1529 become part of the .bss section of the executable. There will be
1530 an entry for this symbol in the .dynsym section. The dynamic
1531 object will contain position independent code, so all references
1532 from the dynamic object to this symbol will go through the global
1533 offset table. The dynamic linker will use the .dynsym entry to
1534 determine the address it must put in the global offset table, so
1535 both the dynamic object and the regular object will refer to the
1536 same memory location for the variable. */
1538 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
1539 copy the initial value out of the dynamic object and into the
1540 runtime process image. */
1541 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1543 htab->srelbss->size += sizeof (Elf32_External_Rel);
1549 return _bfd_elf_adjust_dynamic_copy (h, s);
1552 /* Allocate space in .plt, .got and associated reloc sections for
1556 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
1558 struct bfd_link_info *info;
1559 struct elf_i386_link_hash_table *htab;
1560 struct elf_i386_link_hash_entry *eh;
1561 struct elf_i386_dyn_relocs *p;
1563 if (h->root.type == bfd_link_hash_indirect)
1566 if (h->root.type == bfd_link_hash_warning)
1567 /* When warning symbols are created, they **replace** the "real"
1568 entry in the hash table, thus we never get to see the real
1569 symbol in a hash traversal. So look at it now. */
1570 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1572 info = (struct bfd_link_info *) inf;
1573 htab = elf_i386_hash_table (info);
1575 if (htab->elf.dynamic_sections_created
1576 && h->plt.refcount > 0)
1578 /* Make sure this symbol is output as a dynamic symbol.
1579 Undefined weak syms won't yet be marked as dynamic. */
1580 if (h->dynindx == -1
1581 && !h->forced_local)
1583 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1588 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
1590 asection *s = htab->splt;
1592 /* If this is the first .plt entry, make room for the special
1595 s->size += PLT_ENTRY_SIZE;
1597 h->plt.offset = s->size;
1599 /* If this symbol is not defined in a regular file, and we are
1600 not generating a shared library, then set the symbol to this
1601 location in the .plt. This is required to make function
1602 pointers compare as equal between the normal executable and
1603 the shared library. */
1607 h->root.u.def.section = s;
1608 h->root.u.def.value = h->plt.offset;
1611 /* Make room for this entry. */
1612 s->size += PLT_ENTRY_SIZE;
1614 /* We also need to make an entry in the .got.plt section, which
1615 will be placed in the .got section by the linker script. */
1616 htab->sgotplt->size += 4;
1618 /* We also need to make an entry in the .rel.plt section. */
1619 htab->srelplt->size += sizeof (Elf32_External_Rel);
1620 htab->next_tls_desc_index++;
1622 if (htab->is_vxworks && !info->shared)
1624 /* VxWorks has a second set of relocations for each PLT entry
1625 in executables. They go in a separate relocation section,
1626 which is processed by the kernel loader. */
1628 /* There are two relocations for the initial PLT entry: an
1629 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
1630 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
1632 if (h->plt.offset == PLT_ENTRY_SIZE)
1633 htab->srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
1635 /* There are two extra relocations for each subsequent PLT entry:
1636 an R_386_32 relocation for the GOT entry, and an R_386_32
1637 relocation for the PLT entry. */
1639 htab->srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
1644 h->plt.offset = (bfd_vma) -1;
1650 h->plt.offset = (bfd_vma) -1;
1654 eh = (struct elf_i386_link_hash_entry *) h;
1655 eh->tlsdesc_got = (bfd_vma) -1;
1657 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
1658 make it a R_386_TLS_LE_32 requiring no TLS entry. */
1659 if (h->got.refcount > 0
1662 && (elf_i386_hash_entry(h)->tls_type & GOT_TLS_IE))
1663 h->got.offset = (bfd_vma) -1;
1664 else if (h->got.refcount > 0)
1668 int tls_type = elf_i386_hash_entry(h)->tls_type;
1670 /* Make sure this symbol is output as a dynamic symbol.
1671 Undefined weak syms won't yet be marked as dynamic. */
1672 if (h->dynindx == -1
1673 && !h->forced_local)
1675 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1680 if (GOT_TLS_GDESC_P (tls_type))
1682 eh->tlsdesc_got = htab->sgotplt->size
1683 - elf_i386_compute_jump_table_size (htab);
1684 htab->sgotplt->size += 8;
1685 h->got.offset = (bfd_vma) -2;
1687 if (! GOT_TLS_GDESC_P (tls_type)
1688 || GOT_TLS_GD_P (tls_type))
1690 h->got.offset = s->size;
1692 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
1693 if (GOT_TLS_GD_P (tls_type) || tls_type == GOT_TLS_IE_BOTH)
1696 dyn = htab->elf.dynamic_sections_created;
1697 /* R_386_TLS_IE_32 needs one dynamic relocation,
1698 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
1699 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
1700 need two), R_386_TLS_GD needs one if local symbol and two if
1702 if (tls_type == GOT_TLS_IE_BOTH)
1703 htab->srelgot->size += 2 * sizeof (Elf32_External_Rel);
1704 else if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
1705 || (tls_type & GOT_TLS_IE))
1706 htab->srelgot->size += sizeof (Elf32_External_Rel);
1707 else if (GOT_TLS_GD_P (tls_type))
1708 htab->srelgot->size += 2 * sizeof (Elf32_External_Rel);
1709 else if (! GOT_TLS_GDESC_P (tls_type)
1710 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1711 || h->root.type != bfd_link_hash_undefweak)
1713 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
1714 htab->srelgot->size += sizeof (Elf32_External_Rel);
1715 if (GOT_TLS_GDESC_P (tls_type))
1716 htab->srelplt->size += sizeof (Elf32_External_Rel);
1719 h->got.offset = (bfd_vma) -1;
1721 if (eh->dyn_relocs == NULL)
1724 /* In the shared -Bsymbolic case, discard space allocated for
1725 dynamic pc-relative relocs against symbols which turn out to be
1726 defined in regular objects. For the normal shared case, discard
1727 space for pc-relative relocs that have become local due to symbol
1728 visibility changes. */
1732 /* The only reloc that uses pc_count is R_386_PC32, which will
1733 appear on a call or on something like ".long foo - .". We
1734 want calls to protected symbols to resolve directly to the
1735 function rather than going via the plt. If people want
1736 function pointer comparisons to work as expected then they
1737 should avoid writing assembly like ".long foo - .". */
1738 if (SYMBOL_CALLS_LOCAL (info, h))
1740 struct elf_i386_dyn_relocs **pp;
1742 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1744 p->count -= p->pc_count;
1753 /* Also discard relocs on undefined weak syms with non-default
1755 if (eh->dyn_relocs != NULL
1756 && h->root.type == bfd_link_hash_undefweak)
1758 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
1759 eh->dyn_relocs = NULL;
1761 /* Make sure undefined weak symbols are output as a dynamic
1763 else if (h->dynindx == -1
1764 && !h->forced_local)
1766 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1771 else if (ELIMINATE_COPY_RELOCS)
1773 /* For the non-shared case, discard space for relocs against
1774 symbols which turn out to need copy relocs or are not
1780 || (htab->elf.dynamic_sections_created
1781 && (h->root.type == bfd_link_hash_undefweak
1782 || h->root.type == bfd_link_hash_undefined))))
1784 /* Make sure this symbol is output as a dynamic symbol.
1785 Undefined weak syms won't yet be marked as dynamic. */
1786 if (h->dynindx == -1
1787 && !h->forced_local)
1789 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1793 /* If that succeeded, we know we'll be keeping all the
1795 if (h->dynindx != -1)
1799 eh->dyn_relocs = NULL;
1804 /* Finally, allocate space. */
1805 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1807 asection *sreloc = elf_section_data (p->sec)->sreloc;
1808 sreloc->size += p->count * sizeof (Elf32_External_Rel);
1814 /* Find any dynamic relocs that apply to read-only sections. */
1817 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
1819 struct elf_i386_link_hash_entry *eh;
1820 struct elf_i386_dyn_relocs *p;
1822 if (h->root.type == bfd_link_hash_warning)
1823 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1825 eh = (struct elf_i386_link_hash_entry *) h;
1826 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1828 asection *s = p->sec->output_section;
1830 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1832 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1834 info->flags |= DF_TEXTREL;
1836 /* Not an error, just cut short the traversal. */
1843 /* Set the sizes of the dynamic sections. */
1846 elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
1847 struct bfd_link_info *info)
1849 struct elf_i386_link_hash_table *htab;
1855 htab = elf_i386_hash_table (info);
1856 dynobj = htab->elf.dynobj;
1860 if (htab->elf.dynamic_sections_created)
1862 /* Set the contents of the .interp section to the interpreter. */
1863 if (info->executable)
1865 s = bfd_get_section_by_name (dynobj, ".interp");
1868 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1869 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1873 /* Set up .got offsets for local syms, and space for local dynamic
1875 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1877 bfd_signed_vma *local_got;
1878 bfd_signed_vma *end_local_got;
1879 char *local_tls_type;
1880 bfd_vma *local_tlsdesc_gotent;
1881 bfd_size_type locsymcount;
1882 Elf_Internal_Shdr *symtab_hdr;
1885 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
1888 for (s = ibfd->sections; s != NULL; s = s->next)
1890 struct elf_i386_dyn_relocs *p;
1892 for (p = ((struct elf_i386_dyn_relocs *)
1893 elf_section_data (s)->local_dynrel);
1897 if (!bfd_is_abs_section (p->sec)
1898 && bfd_is_abs_section (p->sec->output_section))
1900 /* Input section has been discarded, either because
1901 it is a copy of a linkonce section or due to
1902 linker script /DISCARD/, so we'll be discarding
1905 else if (p->count != 0)
1907 srel = elf_section_data (p->sec)->sreloc;
1908 srel->size += p->count * sizeof (Elf32_External_Rel);
1909 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
1910 info->flags |= DF_TEXTREL;
1915 local_got = elf_local_got_refcounts (ibfd);
1919 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
1920 locsymcount = symtab_hdr->sh_info;
1921 end_local_got = local_got + locsymcount;
1922 local_tls_type = elf_i386_local_got_tls_type (ibfd);
1923 local_tlsdesc_gotent = elf_i386_local_tlsdesc_gotent (ibfd);
1925 srel = htab->srelgot;
1926 for (; local_got < end_local_got;
1927 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
1929 *local_tlsdesc_gotent = (bfd_vma) -1;
1932 if (GOT_TLS_GDESC_P (*local_tls_type))
1934 *local_tlsdesc_gotent = htab->sgotplt->size
1935 - elf_i386_compute_jump_table_size (htab);
1936 htab->sgotplt->size += 8;
1937 *local_got = (bfd_vma) -2;
1939 if (! GOT_TLS_GDESC_P (*local_tls_type)
1940 || GOT_TLS_GD_P (*local_tls_type))
1942 *local_got = s->size;
1944 if (GOT_TLS_GD_P (*local_tls_type)
1945 || *local_tls_type == GOT_TLS_IE_BOTH)
1949 || GOT_TLS_GD_ANY_P (*local_tls_type)
1950 || (*local_tls_type & GOT_TLS_IE))
1952 if (*local_tls_type == GOT_TLS_IE_BOTH)
1953 srel->size += 2 * sizeof (Elf32_External_Rel);
1954 else if (GOT_TLS_GD_P (*local_tls_type)
1955 || ! GOT_TLS_GDESC_P (*local_tls_type))
1956 srel->size += sizeof (Elf32_External_Rel);
1957 if (GOT_TLS_GDESC_P (*local_tls_type))
1958 htab->srelplt->size += sizeof (Elf32_External_Rel);
1962 *local_got = (bfd_vma) -1;
1966 if (htab->tls_ldm_got.refcount > 0)
1968 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
1970 htab->tls_ldm_got.offset = htab->sgot->size;
1971 htab->sgot->size += 8;
1972 htab->srelgot->size += sizeof (Elf32_External_Rel);
1975 htab->tls_ldm_got.offset = -1;
1977 /* Allocate global sym .plt and .got entries, and space for global
1978 sym dynamic relocs. */
1979 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
1981 /* For every jump slot reserved in the sgotplt, reloc_count is
1982 incremented. However, when we reserve space for TLS descriptors,
1983 it's not incremented, so in order to compute the space reserved
1984 for them, it suffices to multiply the reloc count by the jump
1987 htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;
1989 /* We now have determined the sizes of the various dynamic sections.
1990 Allocate memory for them. */
1992 for (s = dynobj->sections; s != NULL; s = s->next)
1994 bfd_boolean strip_section = TRUE;
1996 if ((s->flags & SEC_LINKER_CREATED) == 0)
2001 || s == htab->sgotplt
2002 || s == htab->sdynbss)
2004 /* Strip this section if we don't need it; see the
2006 /* We'd like to strip these sections if they aren't needed, but if
2007 we've exported dynamic symbols from them we must leave them.
2008 It's too late to tell BFD to get rid of the symbols. */
2010 if (htab->elf.hplt != NULL)
2011 strip_section = FALSE;
2013 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rel"))
2015 if (s->size != 0 && s != htab->srelplt && s != htab->srelplt2)
2018 /* We use the reloc_count field as a counter if we need
2019 to copy relocs into the output file. */
2024 /* It's not one of our sections, so don't allocate space. */
2030 /* If we don't need this section, strip it from the
2031 output file. This is mostly to handle .rel.bss and
2032 .rel.plt. We must create both sections in
2033 create_dynamic_sections, because they must be created
2034 before the linker maps input sections to output
2035 sections. The linker does that before
2036 adjust_dynamic_symbol is called, and it is that
2037 function which decides whether anything needs to go
2038 into these sections. */
2040 s->flags |= SEC_EXCLUDE;
2044 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2047 /* Allocate memory for the section contents. We use bfd_zalloc
2048 here in case unused entries are not reclaimed before the
2049 section's contents are written out. This should not happen,
2050 but this way if it does, we get a R_386_NONE reloc instead
2052 s->contents = bfd_zalloc (dynobj, s->size);
2053 if (s->contents == NULL)
2057 if (htab->elf.dynamic_sections_created)
2059 /* Add some entries to the .dynamic section. We fill in the
2060 values later, in elf_i386_finish_dynamic_sections, but we
2061 must add the entries now so that we get the correct size for
2062 the .dynamic section. The DT_DEBUG entry is filled in by the
2063 dynamic linker and used by the debugger. */
2064 #define add_dynamic_entry(TAG, VAL) \
2065 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2067 if (info->executable)
2069 if (!add_dynamic_entry (DT_DEBUG, 0))
2073 if (htab->splt->size != 0)
2075 if (!add_dynamic_entry (DT_PLTGOT, 0)
2076 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2077 || !add_dynamic_entry (DT_PLTREL, DT_REL)
2078 || !add_dynamic_entry (DT_JMPREL, 0))
2084 if (!add_dynamic_entry (DT_REL, 0)
2085 || !add_dynamic_entry (DT_RELSZ, 0)
2086 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
2089 /* If any dynamic relocs apply to a read-only section,
2090 then we need a DT_TEXTREL entry. */
2091 if ((info->flags & DF_TEXTREL) == 0)
2092 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
2095 if ((info->flags & DF_TEXTREL) != 0)
2097 if (!add_dynamic_entry (DT_TEXTREL, 0))
2102 #undef add_dynamic_entry
2108 elf_i386_always_size_sections (bfd *output_bfd,
2109 struct bfd_link_info *info)
2111 asection *tls_sec = elf_hash_table (info)->tls_sec;
2115 struct elf_link_hash_entry *tlsbase;
2117 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2118 "_TLS_MODULE_BASE_",
2119 FALSE, FALSE, FALSE);
2121 if (tlsbase && tlsbase->type == STT_TLS)
2123 struct bfd_link_hash_entry *bh = NULL;
2124 const struct elf_backend_data *bed
2125 = get_elf_backend_data (output_bfd);
2127 if (!(_bfd_generic_link_add_one_symbol
2128 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2129 tls_sec, 0, NULL, FALSE,
2130 bed->collect, &bh)))
2132 tlsbase = (struct elf_link_hash_entry *)bh;
2133 tlsbase->def_regular = 1;
2134 tlsbase->other = STV_HIDDEN;
2135 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2142 /* Set the correct type for an x86 ELF section. We do this by the
2143 section name, which is a hack, but ought to work. */
2146 elf_i386_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
2147 Elf_Internal_Shdr *hdr,
2150 register const char *name;
2152 name = bfd_get_section_name (abfd, sec);
2154 /* This is an ugly, but unfortunately necessary hack that is
2155 needed when producing EFI binaries on x86. It tells
2156 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2157 containing ELF relocation info. We need this hack in order to
2158 be able to generate ELF binaries that can be translated into
2159 EFI applications (which are essentially COFF objects). Those
2160 files contain a COFF ".reloc" section inside an ELFNN object,
2161 which would normally cause BFD to segfault because it would
2162 attempt to interpret this section as containing relocation
2163 entries for section "oc". With this hack enabled, ".reloc"
2164 will be treated as a normal data section, which will avoid the
2165 segfault. However, you won't be able to create an ELFNN binary
2166 with a section named "oc" that needs relocations, but that's
2167 the kind of ugly side-effects you get when detecting section
2168 types based on their names... In practice, this limitation is
2169 unlikely to bite. */
2170 if (strcmp (name, ".reloc") == 0)
2171 hdr->sh_type = SHT_PROGBITS;
2176 /* Return the base VMA address which should be subtracted from real addresses
2177 when resolving @dtpoff relocation.
2178 This is PT_TLS segment p_vaddr. */
2181 dtpoff_base (struct bfd_link_info *info)
2183 /* If tls_sec is NULL, we should have signalled an error already. */
2184 if (elf_hash_table (info)->tls_sec == NULL)
2186 return elf_hash_table (info)->tls_sec->vma;
2189 /* Return the relocation value for @tpoff relocation
2190 if STT_TLS virtual address is ADDRESS. */
2193 tpoff (struct bfd_link_info *info, bfd_vma address)
2195 struct elf_link_hash_table *htab = elf_hash_table (info);
2197 /* If tls_sec is NULL, we should have signalled an error already. */
2198 if (htab->tls_sec == NULL)
2200 return htab->tls_size + htab->tls_sec->vma - address;
2203 /* Relocate an i386 ELF section. */
2206 elf_i386_relocate_section (bfd *output_bfd,
2207 struct bfd_link_info *info,
2209 asection *input_section,
2211 Elf_Internal_Rela *relocs,
2212 Elf_Internal_Sym *local_syms,
2213 asection **local_sections)
2215 struct elf_i386_link_hash_table *htab;
2216 Elf_Internal_Shdr *symtab_hdr;
2217 struct elf_link_hash_entry **sym_hashes;
2218 bfd_vma *local_got_offsets;
2219 bfd_vma *local_tlsdesc_gotents;
2220 Elf_Internal_Rela *rel;
2221 Elf_Internal_Rela *relend;
2223 htab = elf_i386_hash_table (info);
2224 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2225 sym_hashes = elf_sym_hashes (input_bfd);
2226 local_got_offsets = elf_local_got_offsets (input_bfd);
2227 local_tlsdesc_gotents = elf_i386_local_tlsdesc_gotent (input_bfd);
2230 relend = relocs + input_section->reloc_count;
2231 for (; rel < relend; rel++)
2233 unsigned int r_type;
2234 reloc_howto_type *howto;
2235 unsigned long r_symndx;
2236 struct elf_link_hash_entry *h;
2237 Elf_Internal_Sym *sym;
2239 bfd_vma off, offplt;
2241 bfd_boolean unresolved_reloc;
2242 bfd_reloc_status_type r;
2246 r_type = ELF32_R_TYPE (rel->r_info);
2247 if (r_type == R_386_GNU_VTINHERIT
2248 || r_type == R_386_GNU_VTENTRY)
2251 if ((indx = r_type) >= R_386_standard
2252 && ((indx = r_type - R_386_ext_offset) - R_386_standard
2253 >= R_386_ext - R_386_standard)
2254 && ((indx = r_type - R_386_tls_offset) - R_386_ext
2255 >= R_386_tls - R_386_ext))
2257 (*_bfd_error_handler)
2258 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2259 input_bfd, input_section, r_type);
2260 bfd_set_error (bfd_error_bad_value);
2263 howto = elf_howto_table + indx;
2265 r_symndx = ELF32_R_SYM (rel->r_info);
2269 unresolved_reloc = FALSE;
2270 if (r_symndx < symtab_hdr->sh_info)
2272 sym = local_syms + r_symndx;
2273 sec = local_sections[r_symndx];
2274 relocation = (sec->output_section->vma
2275 + sec->output_offset
2278 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION
2279 && ((sec->flags & SEC_MERGE) != 0
2280 || (info->relocatable
2281 && sec->output_offset != 0)))
2284 bfd_byte *where = contents + rel->r_offset;
2286 switch (howto->size)
2289 addend = bfd_get_8 (input_bfd, where);
2290 if (howto->pc_relative)
2292 addend = (addend ^ 0x80) - 0x80;
2297 addend = bfd_get_16 (input_bfd, where);
2298 if (howto->pc_relative)
2300 addend = (addend ^ 0x8000) - 0x8000;
2305 addend = bfd_get_32 (input_bfd, where);
2306 if (howto->pc_relative)
2308 addend = (addend ^ 0x80000000) - 0x80000000;
2316 if (info->relocatable)
2317 addend += sec->output_offset;
2320 asection *msec = sec;
2321 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec,
2323 addend -= relocation;
2324 addend += msec->output_section->vma + msec->output_offset;
2327 switch (howto->size)
2330 /* FIXME: overflow checks. */
2331 if (howto->pc_relative)
2333 bfd_put_8 (input_bfd, addend, where);
2336 if (howto->pc_relative)
2338 bfd_put_16 (input_bfd, addend, where);
2341 if (howto->pc_relative)
2343 bfd_put_32 (input_bfd, addend, where);
2352 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2353 r_symndx, symtab_hdr, sym_hashes,
2355 unresolved_reloc, warned);
2358 if (sec != NULL && elf_discarded_section (sec))
2360 /* For relocs against symbols from removed linkonce sections,
2361 or sections discarded by a linker script, we just want the
2362 section contents zeroed. Avoid any special processing. */
2363 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2369 if (info->relocatable)
2375 /* Relocation is to the entry for this symbol in the global
2377 if (htab->sgot == NULL)
2384 off = h->got.offset;
2385 dyn = htab->elf.dynamic_sections_created;
2386 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2388 && SYMBOL_REFERENCES_LOCAL (info, h))
2389 || (ELF_ST_VISIBILITY (h->other)
2390 && h->root.type == bfd_link_hash_undefweak))
2392 /* This is actually a static link, or it is a
2393 -Bsymbolic link and the symbol is defined
2394 locally, or the symbol was forced to be local
2395 because of a version file. We must initialize
2396 this entry in the global offset table. Since the
2397 offset must always be a multiple of 4, we use the
2398 least significant bit to record whether we have
2399 initialized it already.
2401 When doing a dynamic link, we create a .rel.got
2402 relocation entry to initialize the value. This
2403 is done in the finish_dynamic_symbol routine. */
2408 bfd_put_32 (output_bfd, relocation,
2409 htab->sgot->contents + off);
2414 unresolved_reloc = FALSE;
2418 if (local_got_offsets == NULL)
2421 off = local_got_offsets[r_symndx];
2423 /* The offset must always be a multiple of 4. We use
2424 the least significant bit to record whether we have
2425 already generated the necessary reloc. */
2430 bfd_put_32 (output_bfd, relocation,
2431 htab->sgot->contents + off);
2436 Elf_Internal_Rela outrel;
2443 outrel.r_offset = (htab->sgot->output_section->vma
2444 + htab->sgot->output_offset
2446 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
2448 loc += s->reloc_count++ * sizeof (Elf32_External_Rel);
2449 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2452 local_got_offsets[r_symndx] |= 1;
2456 if (off >= (bfd_vma) -2)
2459 relocation = htab->sgot->output_section->vma
2460 + htab->sgot->output_offset + off
2461 - htab->sgotplt->output_section->vma
2462 - htab->sgotplt->output_offset;
2466 /* Relocation is relative to the start of the global offset
2469 /* Check to make sure it isn't a protected function symbol
2470 for shared library since it may not be local when used
2471 as function address. */
2473 && !info->executable
2476 && h->type == STT_FUNC
2477 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
2479 (*_bfd_error_handler)
2480 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
2481 input_bfd, h->root.root.string);
2482 bfd_set_error (bfd_error_bad_value);
2486 /* Note that sgot is not involved in this
2487 calculation. We always want the start of .got.plt. If we
2488 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2489 permitted by the ABI, we might have to change this
2491 relocation -= htab->sgotplt->output_section->vma
2492 + htab->sgotplt->output_offset;
2496 /* Use global offset table as symbol value. */
2497 relocation = htab->sgotplt->output_section->vma
2498 + htab->sgotplt->output_offset;
2499 unresolved_reloc = FALSE;
2503 /* Relocation is to the entry for this symbol in the
2504 procedure linkage table. */
2506 /* Resolve a PLT32 reloc against a local symbol directly,
2507 without using the procedure linkage table. */
2511 if (h->plt.offset == (bfd_vma) -1
2512 || htab->splt == NULL)
2514 /* We didn't make a PLT entry for this symbol. This
2515 happens when statically linking PIC code, or when
2516 using -Bsymbolic. */
2520 relocation = (htab->splt->output_section->vma
2521 + htab->splt->output_offset
2523 unresolved_reloc = FALSE;
2528 if ((input_section->flags & SEC_ALLOC) == 0)
2533 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2534 || h->root.type != bfd_link_hash_undefweak)
2535 && (r_type != R_386_PC32
2536 || !SYMBOL_CALLS_LOCAL (info, h)))
2537 || (ELIMINATE_COPY_RELOCS
2544 || h->root.type == bfd_link_hash_undefweak
2545 || h->root.type == bfd_link_hash_undefined)))
2547 Elf_Internal_Rela outrel;
2549 bfd_boolean skip, relocate;
2552 /* When generating a shared object, these relocations
2553 are copied into the output file to be resolved at run
2560 _bfd_elf_section_offset (output_bfd, info, input_section,
2562 if (outrel.r_offset == (bfd_vma) -1)
2564 else if (outrel.r_offset == (bfd_vma) -2)
2565 skip = TRUE, relocate = TRUE;
2566 outrel.r_offset += (input_section->output_section->vma
2567 + input_section->output_offset);
2570 memset (&outrel, 0, sizeof outrel);
2573 && (r_type == R_386_PC32
2575 || !SYMBOLIC_BIND (info, h)
2576 || !h->def_regular))
2577 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2580 /* This symbol is local, or marked to become local. */
2582 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
2585 sreloc = elf_section_data (input_section)->sreloc;
2589 loc = sreloc->contents;
2590 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
2591 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2593 /* If this reloc is against an external symbol, we do
2594 not want to fiddle with the addend. Otherwise, we
2595 need to include the symbol value so that it becomes
2596 an addend for the dynamic reloc. */
2605 Elf_Internal_Rela outrel;
2609 outrel.r_offset = rel->r_offset
2610 + input_section->output_section->vma
2611 + input_section->output_offset;
2612 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
2613 sreloc = elf_section_data (input_section)->sreloc;
2616 loc = sreloc->contents;
2617 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
2618 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2623 case R_386_TLS_GOTDESC:
2624 case R_386_TLS_DESC_CALL:
2625 case R_386_TLS_IE_32:
2626 case R_386_TLS_GOTIE:
2627 r_type = elf_i386_tls_transition (info, r_type, h == NULL);
2628 tls_type = GOT_UNKNOWN;
2629 if (h == NULL && local_got_offsets)
2630 tls_type = elf_i386_local_got_tls_type (input_bfd) [r_symndx];
2633 tls_type = elf_i386_hash_entry(h)->tls_type;
2634 if (!info->shared && h->dynindx == -1 && (tls_type & GOT_TLS_IE))
2635 r_type = R_386_TLS_LE_32;
2637 if (tls_type == GOT_TLS_IE)
2638 tls_type = GOT_TLS_IE_NEG;
2639 if (r_type == R_386_TLS_GD
2640 || r_type == R_386_TLS_GOTDESC
2641 || r_type == R_386_TLS_DESC_CALL)
2643 if (tls_type == GOT_TLS_IE_POS)
2644 r_type = R_386_TLS_GOTIE;
2645 else if (tls_type & GOT_TLS_IE)
2646 r_type = R_386_TLS_IE_32;
2649 if (r_type == R_386_TLS_LE_32)
2651 BFD_ASSERT (! unresolved_reloc);
2652 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
2654 unsigned int val, type;
2656 unsigned long tls_r_symndx;
2657 struct elf_link_hash_entry *tls_h;
2659 /* GD->LE transition. */
2660 BFD_ASSERT (rel->r_offset >= 2);
2661 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
2662 BFD_ASSERT (type == 0x8d || type == 0x04);
2663 BFD_ASSERT (rel->r_offset + 9 <= input_section->size);
2664 BFD_ASSERT (bfd_get_8 (input_bfd,
2665 contents + rel->r_offset + 4)
2667 BFD_ASSERT (rel + 1 < relend);
2668 tls_r_symndx = ELF32_R_SYM (rel[1].r_info);
2669 BFD_ASSERT (tls_r_symndx >= symtab_hdr->sh_info);
2670 tls_h = sym_hashes[tls_r_symndx - symtab_hdr->sh_info];
2671 BFD_ASSERT (tls_h != NULL
2672 && tls_h->root.root.string != NULL
2673 && strcmp (tls_h->root.root.string,
2674 "___tls_get_addr") == 0);
2675 BFD_ASSERT ((! info->shared
2676 && ELF32_R_TYPE (rel[1].r_info) == R_386_PC32)
2677 || ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
2678 roff = rel->r_offset + 5;
2679 val = bfd_get_8 (input_bfd,
2680 contents + rel->r_offset - 1);
2683 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
2685 movl %gs:0, %eax; subl $foo@tpoff, %eax
2686 (6 byte form of subl). */
2687 BFD_ASSERT (rel->r_offset >= 3);
2688 BFD_ASSERT (bfd_get_8 (input_bfd,
2689 contents + rel->r_offset - 3)
2691 BFD_ASSERT ((val & 0xc7) == 0x05 && val != (4 << 3));
2692 memcpy (contents + rel->r_offset - 3,
2693 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2697 BFD_ASSERT ((val & 0xf8) == 0x80 && (val & 7) != 4);
2698 if (rel->r_offset + 10 <= input_section->size
2699 && bfd_get_8 (input_bfd,
2700 contents + rel->r_offset + 9) == 0x90)
2702 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
2704 movl %gs:0, %eax; subl $foo@tpoff, %eax
2705 (6 byte form of subl). */
2706 memcpy (contents + rel->r_offset - 2,
2707 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2708 roff = rel->r_offset + 6;
2712 /* leal foo(%reg), %eax; call ___tls_get_addr
2714 movl %gs:0, %eax; subl $foo@tpoff, %eax
2715 (5 byte form of subl). */
2716 memcpy (contents + rel->r_offset - 2,
2717 "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2720 bfd_put_32 (output_bfd, tpoff (info, relocation),
2722 /* Skip R_386_PC32/R_386_PLT32. */
2726 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
2728 /* GDesc -> LE transition.
2729 It's originally something like:
2730 leal x@tlsdesc(%ebx), %eax
2734 Registers other than %eax may be set up here. */
2736 unsigned int val, type;
2739 /* First, make sure it's a leal adding ebx to a
2740 32-bit offset into any register, although it's
2741 probably almost always going to be eax. */
2742 roff = rel->r_offset;
2743 BFD_ASSERT (roff >= 2);
2744 type = bfd_get_8 (input_bfd, contents + roff - 2);
2745 BFD_ASSERT (type == 0x8d);
2746 val = bfd_get_8 (input_bfd, contents + roff - 1);
2747 BFD_ASSERT ((val & 0xc7) == 0x83);
2748 BFD_ASSERT (roff + 4 <= input_section->size);
2750 /* Now modify the instruction as appropriate. */
2751 /* aoliva FIXME: remove the above and xor the byte
2753 bfd_put_8 (output_bfd, val ^ 0x86,
2754 contents + roff - 1);
2755 bfd_put_32 (output_bfd, -tpoff (info, relocation),
2759 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
2761 /* GDesc -> LE transition.
2767 unsigned int val, type;
2770 /* First, make sure it's a call *(%eax). */
2771 roff = rel->r_offset;
2772 BFD_ASSERT (roff + 2 <= input_section->size);
2773 type = bfd_get_8 (input_bfd, contents + roff);
2774 BFD_ASSERT (type == 0xff);
2775 val = bfd_get_8 (input_bfd, contents + roff + 1);
2776 BFD_ASSERT (val == 0x10);
2778 /* Now modify the instruction as appropriate. Use
2779 xchg %ax,%ax instead of 2 nops. */
2780 bfd_put_8 (output_bfd, 0x66, contents + roff);
2781 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
2784 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_IE)
2786 unsigned int val, type;
2788 /* IE->LE transition:
2789 Originally it can be one of:
2797 BFD_ASSERT (rel->r_offset >= 1);
2798 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
2799 BFD_ASSERT (rel->r_offset + 4 <= input_section->size);
2802 /* movl foo, %eax. */
2803 bfd_put_8 (output_bfd, 0xb8,
2804 contents + rel->r_offset - 1);
2808 BFD_ASSERT (rel->r_offset >= 2);
2809 type = bfd_get_8 (input_bfd,
2810 contents + rel->r_offset - 2);
2815 BFD_ASSERT ((val & 0xc7) == 0x05);
2816 bfd_put_8 (output_bfd, 0xc7,
2817 contents + rel->r_offset - 2);
2818 bfd_put_8 (output_bfd,
2819 0xc0 | ((val >> 3) & 7),
2820 contents + rel->r_offset - 1);
2824 BFD_ASSERT ((val & 0xc7) == 0x05);
2825 bfd_put_8 (output_bfd, 0x81,
2826 contents + rel->r_offset - 2);
2827 bfd_put_8 (output_bfd,
2828 0xc0 | ((val >> 3) & 7),
2829 contents + rel->r_offset - 1);
2836 bfd_put_32 (output_bfd, -tpoff (info, relocation),
2837 contents + rel->r_offset);
2842 unsigned int val, type;
2844 /* {IE_32,GOTIE}->LE transition:
2845 Originally it can be one of:
2846 subl foo(%reg1), %reg2
2847 movl foo(%reg1), %reg2
2848 addl foo(%reg1), %reg2
2851 movl $foo, %reg2 (6 byte form)
2852 addl $foo, %reg2. */
2853 BFD_ASSERT (rel->r_offset >= 2);
2854 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
2855 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
2856 BFD_ASSERT (rel->r_offset + 4 <= input_section->size);
2857 BFD_ASSERT ((val & 0xc0) == 0x80 && (val & 7) != 4);
2861 bfd_put_8 (output_bfd, 0xc7,
2862 contents + rel->r_offset - 2);
2863 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
2864 contents + rel->r_offset - 1);
2866 else if (type == 0x2b)
2869 bfd_put_8 (output_bfd, 0x81,
2870 contents + rel->r_offset - 2);
2871 bfd_put_8 (output_bfd, 0xe8 | ((val >> 3) & 7),
2872 contents + rel->r_offset - 1);
2874 else if (type == 0x03)
2877 bfd_put_8 (output_bfd, 0x81,
2878 contents + rel->r_offset - 2);
2879 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
2880 contents + rel->r_offset - 1);
2884 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTIE)
2885 bfd_put_32 (output_bfd, -tpoff (info, relocation),
2886 contents + rel->r_offset);
2888 bfd_put_32 (output_bfd, tpoff (info, relocation),
2889 contents + rel->r_offset);
2894 if (htab->sgot == NULL)
2899 off = h->got.offset;
2900 offplt = elf_i386_hash_entry (h)->tlsdesc_got;
2904 if (local_got_offsets == NULL)
2907 off = local_got_offsets[r_symndx];
2908 offplt = local_tlsdesc_gotents[r_symndx];
2915 Elf_Internal_Rela outrel;
2920 if (htab->srelgot == NULL)
2923 indx = h && h->dynindx != -1 ? h->dynindx : 0;
2925 if (GOT_TLS_GDESC_P (tls_type))
2927 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
2928 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
2929 <= htab->sgotplt->size);
2930 outrel.r_offset = (htab->sgotplt->output_section->vma
2931 + htab->sgotplt->output_offset
2933 + htab->sgotplt_jump_table_size);
2934 sreloc = htab->srelplt;
2935 loc = sreloc->contents;
2936 loc += (htab->next_tls_desc_index++
2937 * sizeof (Elf32_External_Rel));
2938 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
2939 <= sreloc->contents + sreloc->size);
2940 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2943 BFD_ASSERT (! unresolved_reloc);
2944 bfd_put_32 (output_bfd,
2945 relocation - dtpoff_base (info),
2946 htab->sgotplt->contents + offplt
2947 + htab->sgotplt_jump_table_size + 4);
2951 bfd_put_32 (output_bfd, 0,
2952 htab->sgotplt->contents + offplt
2953 + htab->sgotplt_jump_table_size + 4);
2957 sreloc = htab->srelgot;
2959 outrel.r_offset = (htab->sgot->output_section->vma
2960 + htab->sgot->output_offset + off);
2962 if (GOT_TLS_GD_P (tls_type))
2963 dr_type = R_386_TLS_DTPMOD32;
2964 else if (GOT_TLS_GDESC_P (tls_type))
2966 else if (tls_type == GOT_TLS_IE_POS)
2967 dr_type = R_386_TLS_TPOFF;
2969 dr_type = R_386_TLS_TPOFF32;
2971 if (dr_type == R_386_TLS_TPOFF && indx == 0)
2972 bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
2973 htab->sgot->contents + off);
2974 else if (dr_type == R_386_TLS_TPOFF32 && indx == 0)
2975 bfd_put_32 (output_bfd, dtpoff_base (info) - relocation,
2976 htab->sgot->contents + off);
2977 else if (dr_type != R_386_TLS_DESC)
2978 bfd_put_32 (output_bfd, 0,
2979 htab->sgot->contents + off);
2980 outrel.r_info = ELF32_R_INFO (indx, dr_type);
2982 loc = sreloc->contents;
2983 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
2984 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
2985 <= sreloc->contents + sreloc->size);
2986 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2988 if (GOT_TLS_GD_P (tls_type))
2992 BFD_ASSERT (! unresolved_reloc);
2993 bfd_put_32 (output_bfd,
2994 relocation - dtpoff_base (info),
2995 htab->sgot->contents + off + 4);
2999 bfd_put_32 (output_bfd, 0,
3000 htab->sgot->contents + off + 4);
3001 outrel.r_info = ELF32_R_INFO (indx,
3002 R_386_TLS_DTPOFF32);
3003 outrel.r_offset += 4;
3004 sreloc->reloc_count++;
3005 loc += sizeof (Elf32_External_Rel);
3006 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
3007 <= sreloc->contents + sreloc->size);
3008 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3011 else if (tls_type == GOT_TLS_IE_BOTH)
3013 bfd_put_32 (output_bfd,
3014 indx == 0 ? relocation - dtpoff_base (info) : 0,
3015 htab->sgot->contents + off + 4);
3016 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
3017 outrel.r_offset += 4;
3018 sreloc->reloc_count++;
3019 loc += sizeof (Elf32_External_Rel);
3020 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3027 local_got_offsets[r_symndx] |= 1;
3030 if (off >= (bfd_vma) -2
3031 && ! GOT_TLS_GDESC_P (tls_type))
3033 if (r_type == R_386_TLS_GOTDESC
3034 || r_type == R_386_TLS_DESC_CALL)
3036 relocation = htab->sgotplt_jump_table_size + offplt;
3037 unresolved_reloc = FALSE;
3039 else if (r_type == ELF32_R_TYPE (rel->r_info))
3041 bfd_vma g_o_t = htab->sgotplt->output_section->vma
3042 + htab->sgotplt->output_offset;
3043 relocation = htab->sgot->output_section->vma
3044 + htab->sgot->output_offset + off - g_o_t;
3045 if ((r_type == R_386_TLS_IE || r_type == R_386_TLS_GOTIE)
3046 && tls_type == GOT_TLS_IE_BOTH)
3048 if (r_type == R_386_TLS_IE)
3049 relocation += g_o_t;
3050 unresolved_reloc = FALSE;
3052 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
3054 unsigned int val, type;
3057 /* GD->IE transition. */
3058 BFD_ASSERT (rel->r_offset >= 2);
3059 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
3060 BFD_ASSERT (type == 0x8d || type == 0x04);
3061 BFD_ASSERT (rel->r_offset + 9 <= input_section->size);
3062 BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4)
3064 BFD_ASSERT (rel + 1 < relend);
3065 BFD_ASSERT (ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
3066 roff = rel->r_offset - 3;
3067 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
3070 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3072 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3073 BFD_ASSERT (rel->r_offset >= 3);
3074 BFD_ASSERT (bfd_get_8 (input_bfd,
3075 contents + rel->r_offset - 3)
3077 BFD_ASSERT ((val & 0xc7) == 0x05 && val != (4 << 3));
3082 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3084 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3085 BFD_ASSERT (rel->r_offset + 10 <= input_section->size);
3086 BFD_ASSERT ((val & 0xf8) == 0x80 && (val & 7) != 4);
3087 BFD_ASSERT (bfd_get_8 (input_bfd,
3088 contents + rel->r_offset + 9)
3090 roff = rel->r_offset - 2;
3092 memcpy (contents + roff,
3093 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3094 contents[roff + 7] = 0x80 | (val & 7);
3095 /* If foo is used only with foo@gotntpoff(%reg) and
3096 foo@indntpoff, but not with foo@gottpoff(%reg), change
3097 subl $foo@gottpoff(%reg), %eax
3099 addl $foo@gotntpoff(%reg), %eax. */
3100 if (tls_type == GOT_TLS_IE_POS)
3101 contents[roff + 6] = 0x03;
3102 bfd_put_32 (output_bfd,
3103 htab->sgot->output_section->vma
3104 + htab->sgot->output_offset + off
3105 - htab->sgotplt->output_section->vma
3106 - htab->sgotplt->output_offset,
3107 contents + roff + 8);
3108 /* Skip R_386_PLT32. */
3112 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
3114 /* GDesc -> IE transition.
3115 It's originally something like:
3116 leal x@tlsdesc(%ebx), %eax
3119 movl x@gotntpoff(%ebx), %eax # before nop; nop
3121 movl x@gottpoff(%ebx), %eax # before negl %eax
3123 Registers other than %eax may be set up here. */
3125 unsigned int val, type;
3128 /* First, make sure it's a leal adding ebx to a 32-bit
3129 offset into any register, although it's probably
3130 almost always going to be eax. */
3131 roff = rel->r_offset;
3132 BFD_ASSERT (roff >= 2);
3133 type = bfd_get_8 (input_bfd, contents + roff - 2);
3134 BFD_ASSERT (type == 0x8d);
3135 val = bfd_get_8 (input_bfd, contents + roff - 1);
3136 BFD_ASSERT ((val & 0xc7) == 0x83);
3137 BFD_ASSERT (roff + 4 <= input_section->size);
3139 /* Now modify the instruction as appropriate. */
3140 /* To turn a leal into a movl in the form we use it, it
3141 suffices to change the first byte from 0x8d to 0x8b.
3142 aoliva FIXME: should we decide to keep the leal, all
3143 we have to do is remove the statement below, and
3144 adjust the relaxation of R_386_TLS_DESC_CALL. */
3145 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
3147 if (tls_type == GOT_TLS_IE_BOTH)
3150 bfd_put_32 (output_bfd,
3151 htab->sgot->output_section->vma
3152 + htab->sgot->output_offset + off
3153 - htab->sgotplt->output_section->vma
3154 - htab->sgotplt->output_offset,
3158 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
3160 /* GDesc -> IE transition.
3168 depending on how we transformed the TLS_GOTDESC above.
3171 unsigned int val, type;
3174 /* First, make sure it's a call *(%eax). */
3175 roff = rel->r_offset;
3176 BFD_ASSERT (roff + 2 <= input_section->size);
3177 type = bfd_get_8 (input_bfd, contents + roff);
3178 BFD_ASSERT (type == 0xff);
3179 val = bfd_get_8 (input_bfd, contents + roff + 1);
3180 BFD_ASSERT (val == 0x10);
3182 /* Now modify the instruction as appropriate. */
3183 if (tls_type != GOT_TLS_IE_NEG)
3186 bfd_put_8 (output_bfd, 0x66, contents + roff);
3187 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3192 bfd_put_8 (output_bfd, 0xf7, contents + roff);
3193 bfd_put_8 (output_bfd, 0xd8, contents + roff + 1);
3206 unsigned long tls_r_symndx;
3207 struct elf_link_hash_entry *tls_h;
3209 /* LD->LE transition:
3211 leal foo(%reg), %eax; call ___tls_get_addr.
3213 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3214 BFD_ASSERT (rel->r_offset >= 2);
3215 BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 2)
3217 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
3218 BFD_ASSERT ((val & 0xf8) == 0x80 && (val & 7) != 4);
3219 BFD_ASSERT (rel->r_offset + 9 <= input_section->size);
3220 BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4)
3222 BFD_ASSERT (rel + 1 < relend);
3223 tls_r_symndx = ELF32_R_SYM (rel[1].r_info);
3224 BFD_ASSERT (tls_r_symndx >= symtab_hdr->sh_info);
3225 tls_h = sym_hashes[tls_r_symndx - symtab_hdr->sh_info];
3226 BFD_ASSERT (tls_h != NULL
3227 && tls_h->root.root.string != NULL
3228 && strcmp (tls_h->root.root.string,
3229 "___tls_get_addr") == 0);
3230 BFD_ASSERT (ELF32_R_TYPE (rel[1].r_info) == R_386_PC32
3231 || ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
3232 memcpy (contents + rel->r_offset - 2,
3233 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3234 /* Skip R_386_PC32/R_386_PLT32. */
3239 if (htab->sgot == NULL)
3242 off = htab->tls_ldm_got.offset;
3247 Elf_Internal_Rela outrel;
3250 if (htab->srelgot == NULL)
3253 outrel.r_offset = (htab->sgot->output_section->vma
3254 + htab->sgot->output_offset + off);
3256 bfd_put_32 (output_bfd, 0,
3257 htab->sgot->contents + off);
3258 bfd_put_32 (output_bfd, 0,
3259 htab->sgot->contents + off + 4);
3260 outrel.r_info = ELF32_R_INFO (0, R_386_TLS_DTPMOD32);
3261 loc = htab->srelgot->contents;
3262 loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3263 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3264 htab->tls_ldm_got.offset |= 1;
3266 relocation = htab->sgot->output_section->vma
3267 + htab->sgot->output_offset + off
3268 - htab->sgotplt->output_section->vma
3269 - htab->sgotplt->output_offset;
3270 unresolved_reloc = FALSE;
3273 case R_386_TLS_LDO_32:
3274 if (info->shared || (input_section->flags & SEC_CODE) == 0)
3275 relocation -= dtpoff_base (info);
3277 /* When converting LDO to LE, we must negate. */
3278 relocation = -tpoff (info, relocation);
3281 case R_386_TLS_LE_32:
3285 Elf_Internal_Rela outrel;
3290 outrel.r_offset = rel->r_offset
3291 + input_section->output_section->vma
3292 + input_section->output_offset;
3293 if (h != NULL && h->dynindx != -1)
3297 if (r_type == R_386_TLS_LE_32)
3298 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF32);
3300 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
3301 sreloc = elf_section_data (input_section)->sreloc;
3304 loc = sreloc->contents;
3305 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
3306 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3309 else if (r_type == R_386_TLS_LE_32)
3310 relocation = dtpoff_base (info) - relocation;
3312 relocation -= dtpoff_base (info);
3314 else if (r_type == R_386_TLS_LE_32)
3315 relocation = tpoff (info, relocation);
3317 relocation = -tpoff (info, relocation);
3324 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3325 because such sections are not SEC_ALLOC and thus ld.so will
3326 not process them. */
3327 if (unresolved_reloc
3328 && !((input_section->flags & SEC_DEBUGGING) != 0
3331 (*_bfd_error_handler)
3332 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3335 (long) rel->r_offset,
3337 h->root.root.string);
3341 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3342 contents, rel->r_offset,
3345 if (r != bfd_reloc_ok)
3350 name = h->root.root.string;
3353 name = bfd_elf_string_from_elf_section (input_bfd,
3354 symtab_hdr->sh_link,
3359 name = bfd_section_name (input_bfd, sec);
3362 if (r == bfd_reloc_overflow)
3364 if (! ((*info->callbacks->reloc_overflow)
3365 (info, (h ? &h->root : NULL), name, howto->name,
3366 (bfd_vma) 0, input_bfd, input_section,
3372 (*_bfd_error_handler)
3373 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3374 input_bfd, input_section,
3375 (long) rel->r_offset, name, (int) r);
3384 /* Finish up dynamic symbol handling. We set the contents of various
3385 dynamic sections here. */
3388 elf_i386_finish_dynamic_symbol (bfd *output_bfd,
3389 struct bfd_link_info *info,
3390 struct elf_link_hash_entry *h,
3391 Elf_Internal_Sym *sym)
3393 struct elf_i386_link_hash_table *htab;
3395 htab = elf_i386_hash_table (info);
3397 if (h->plt.offset != (bfd_vma) -1)
3401 Elf_Internal_Rela rel;
3404 /* This symbol has an entry in the procedure linkage table. Set
3407 if (h->dynindx == -1
3408 || htab->splt == NULL
3409 || htab->sgotplt == NULL
3410 || htab->srelplt == NULL)
3413 /* Get the index in the procedure linkage table which
3414 corresponds to this symbol. This is the index of this symbol
3415 in all the symbols for which we are making plt entries. The
3416 first entry in the procedure linkage table is reserved. */
3417 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3419 /* Get the offset into the .got table of the entry that
3420 corresponds to this function. Each .got entry is 4 bytes.
3421 The first three are reserved. */
3422 got_offset = (plt_index + 3) * 4;
3424 /* Fill in the entry in the procedure linkage table. */
3427 memcpy (htab->splt->contents + h->plt.offset, elf_i386_plt_entry,
3429 bfd_put_32 (output_bfd,
3430 (htab->sgotplt->output_section->vma
3431 + htab->sgotplt->output_offset
3433 htab->splt->contents + h->plt.offset + 2);
3435 if (htab->is_vxworks)
3437 int s, k, reloc_index;
3439 /* Create the R_386_32 relocation referencing the GOT
3440 for this PLT entry. */
3442 /* S: Current slot number (zero-based). */
3443 s = (h->plt.offset - PLT_ENTRY_SIZE) / PLT_ENTRY_SIZE;
3444 /* K: Number of relocations for PLTResolve. */
3446 k = PLTRESOLVE_RELOCS_SHLIB;
3448 k = PLTRESOLVE_RELOCS;
3449 /* Skip the PLTresolve relocations, and the relocations for
3450 the other PLT slots. */
3451 reloc_index = k + s * PLT_NON_JUMP_SLOT_RELOCS;
3452 loc = (htab->srelplt2->contents + reloc_index
3453 * sizeof (Elf32_External_Rel));
3455 rel.r_offset = (htab->splt->output_section->vma
3456 + htab->splt->output_offset
3457 + h->plt.offset + 2),
3458 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
3459 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
3461 /* Create the R_386_32 relocation referencing the beginning of
3462 the PLT for this GOT entry. */
3463 rel.r_offset = (htab->sgotplt->output_section->vma
3464 + htab->sgotplt->output_offset
3466 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32);
3467 bfd_elf32_swap_reloc_out (output_bfd, &rel,
3468 loc + sizeof (Elf32_External_Rel));
3473 memcpy (htab->splt->contents + h->plt.offset, elf_i386_pic_plt_entry,
3475 bfd_put_32 (output_bfd, got_offset,
3476 htab->splt->contents + h->plt.offset + 2);
3479 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rel),
3480 htab->splt->contents + h->plt.offset + 7);
3481 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
3482 htab->splt->contents + h->plt.offset + 12);
3484 /* Fill in the entry in the global offset table. */
3485 bfd_put_32 (output_bfd,
3486 (htab->splt->output_section->vma
3487 + htab->splt->output_offset
3490 htab->sgotplt->contents + got_offset);
3492 /* Fill in the entry in the .rel.plt section. */
3493 rel.r_offset = (htab->sgotplt->output_section->vma
3494 + htab->sgotplt->output_offset
3496 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
3497 loc = htab->srelplt->contents + plt_index * sizeof (Elf32_External_Rel);
3498 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
3500 if (!h->def_regular)
3502 /* Mark the symbol as undefined, rather than as defined in
3503 the .plt section. Leave the value if there were any
3504 relocations where pointer equality matters (this is a clue
3505 for the dynamic linker, to make function pointer
3506 comparisons work between an application and shared
3507 library), otherwise set it to zero. If a function is only
3508 called from a binary, there is no need to slow down
3509 shared libraries because of that. */
3510 sym->st_shndx = SHN_UNDEF;
3511 if (!h->pointer_equality_needed)
3516 if (h->got.offset != (bfd_vma) -1
3517 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h)->tls_type)
3518 && (elf_i386_hash_entry(h)->tls_type & GOT_TLS_IE) == 0)
3520 Elf_Internal_Rela rel;
3523 /* This symbol has an entry in the global offset table. Set it
3526 if (htab->sgot == NULL || htab->srelgot == NULL)
3529 rel.r_offset = (htab->sgot->output_section->vma
3530 + htab->sgot->output_offset
3531 + (h->got.offset & ~(bfd_vma) 1));
3533 /* If this is a static link, or it is a -Bsymbolic link and the
3534 symbol is defined locally or was forced to be local because
3535 of a version file, we just want to emit a RELATIVE reloc.
3536 The entry in the global offset table will already have been
3537 initialized in the relocate_section function. */
3539 && SYMBOL_REFERENCES_LOCAL (info, h))
3541 BFD_ASSERT((h->got.offset & 1) != 0);
3542 rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
3546 BFD_ASSERT((h->got.offset & 1) == 0);
3547 bfd_put_32 (output_bfd, (bfd_vma) 0,
3548 htab->sgot->contents + h->got.offset);
3549 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
3552 loc = htab->srelgot->contents;
3553 loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3554 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
3559 Elf_Internal_Rela rel;
3562 /* This symbol needs a copy reloc. Set it up. */
3564 if (h->dynindx == -1
3565 || (h->root.type != bfd_link_hash_defined
3566 && h->root.type != bfd_link_hash_defweak)
3567 || htab->srelbss == NULL)
3570 rel.r_offset = (h->root.u.def.value
3571 + h->root.u.def.section->output_section->vma
3572 + h->root.u.def.section->output_offset);
3573 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
3574 loc = htab->srelbss->contents;
3575 loc += htab->srelbss->reloc_count++ * sizeof (Elf32_External_Rel);
3576 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
3579 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.
3580 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
3581 is relative to the ".got" section. */
3582 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3583 || (!htab->is_vxworks && h == htab->elf.hgot))
3584 sym->st_shndx = SHN_ABS;
3589 /* Used to decide how to sort relocs in an optimal manner for the
3590 dynamic linker, before writing them out. */
3592 static enum elf_reloc_type_class
3593 elf_i386_reloc_type_class (const Elf_Internal_Rela *rela)
3595 switch (ELF32_R_TYPE (rela->r_info))
3597 case R_386_RELATIVE:
3598 return reloc_class_relative;
3599 case R_386_JUMP_SLOT:
3600 return reloc_class_plt;
3602 return reloc_class_copy;
3604 return reloc_class_normal;
3608 /* Finish up the dynamic sections. */
3611 elf_i386_finish_dynamic_sections (bfd *output_bfd,
3612 struct bfd_link_info *info)
3614 struct elf_i386_link_hash_table *htab;
3618 htab = elf_i386_hash_table (info);
3619 dynobj = htab->elf.dynobj;
3620 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3622 if (htab->elf.dynamic_sections_created)
3624 Elf32_External_Dyn *dyncon, *dynconend;
3626 if (sdyn == NULL || htab->sgot == NULL)
3629 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3630 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3631 for (; dyncon < dynconend; dyncon++)
3633 Elf_Internal_Dyn dyn;
3636 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3645 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3650 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3655 dyn.d_un.d_val = s->size;
3659 /* My reading of the SVR4 ABI indicates that the
3660 procedure linkage table relocs (DT_JMPREL) should be
3661 included in the overall relocs (DT_REL). This is
3662 what Solaris does. However, UnixWare can not handle
3663 that case. Therefore, we override the DT_RELSZ entry
3664 here to make it not include the JMPREL relocs. */
3668 dyn.d_un.d_val -= s->size;
3672 /* We may not be using the standard ELF linker script.
3673 If .rel.plt is the first .rel section, we adjust
3674 DT_REL to not include it. */
3678 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
3680 dyn.d_un.d_ptr += s->size;
3684 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3687 /* Fill in the first entry in the procedure linkage table. */
3688 if (htab->splt && htab->splt->size > 0)
3692 memcpy (htab->splt->contents, elf_i386_pic_plt0_entry,
3693 sizeof (elf_i386_pic_plt0_entry));
3694 memset (htab->splt->contents + sizeof (elf_i386_pic_plt0_entry),
3695 htab->plt0_pad_byte,
3696 PLT_ENTRY_SIZE - sizeof (elf_i386_pic_plt0_entry));
3700 memcpy (htab->splt->contents, elf_i386_plt0_entry,
3701 sizeof(elf_i386_plt0_entry));
3702 memset (htab->splt->contents + sizeof (elf_i386_plt0_entry),
3703 htab->plt0_pad_byte,
3704 PLT_ENTRY_SIZE - sizeof (elf_i386_plt0_entry));
3705 bfd_put_32 (output_bfd,
3706 (htab->sgotplt->output_section->vma
3707 + htab->sgotplt->output_offset
3709 htab->splt->contents + 2);
3710 bfd_put_32 (output_bfd,
3711 (htab->sgotplt->output_section->vma
3712 + htab->sgotplt->output_offset
3714 htab->splt->contents + 8);
3716 if (htab->is_vxworks)
3718 Elf_Internal_Rela rel;
3720 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
3721 On IA32 we use REL relocations so the addend goes in
3722 the PLT directly. */
3723 rel.r_offset = (htab->splt->output_section->vma
3724 + htab->splt->output_offset
3726 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
3727 bfd_elf32_swap_reloc_out (output_bfd, &rel,
3728 htab->srelplt2->contents);
3729 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
3730 rel.r_offset = (htab->splt->output_section->vma
3731 + htab->splt->output_offset
3733 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
3734 bfd_elf32_swap_reloc_out (output_bfd, &rel,
3735 htab->srelplt2->contents +
3736 sizeof (Elf32_External_Rel));
3740 /* UnixWare sets the entsize of .plt to 4, although that doesn't
3741 really seem like the right value. */
3742 elf_section_data (htab->splt->output_section)
3743 ->this_hdr.sh_entsize = 4;
3745 /* Correct the .rel.plt.unloaded relocations. */
3746 if (htab->is_vxworks && !info->shared)
3748 int num_plts = (htab->splt->size / PLT_ENTRY_SIZE) - 1;
3751 p = htab->srelplt2->contents;
3753 p += PLTRESOLVE_RELOCS_SHLIB * sizeof (Elf32_External_Rel);
3755 p += PLTRESOLVE_RELOCS * sizeof (Elf32_External_Rel);
3757 for (; num_plts; num_plts--)
3759 Elf_Internal_Rela rel;
3760 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
3761 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
3762 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
3763 p += sizeof (Elf32_External_Rel);
3765 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
3766 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32);
3767 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
3768 p += sizeof (Elf32_External_Rel);
3776 /* Fill in the first three entries in the global offset table. */
3777 if (htab->sgotplt->size > 0)
3779 bfd_put_32 (output_bfd,
3781 : sdyn->output_section->vma + sdyn->output_offset),
3782 htab->sgotplt->contents);
3783 bfd_put_32 (output_bfd, 0, htab->sgotplt->contents + 4);
3784 bfd_put_32 (output_bfd, 0, htab->sgotplt->contents + 8);
3787 elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize = 4;
3790 if (htab->sgot && htab->sgot->size > 0)
3791 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 4;
3796 /* Return address for Ith PLT stub in section PLT, for relocation REL
3797 or (bfd_vma) -1 if it should not be included. */
3800 elf_i386_plt_sym_val (bfd_vma i, const asection *plt,
3801 const arelent *rel ATTRIBUTE_UNUSED)
3803 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
3806 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3809 elf_i386_hash_symbol (struct elf_link_hash_entry *h)
3811 if (h->plt.offset != (bfd_vma) -1
3813 && !h->pointer_equality_needed)
3816 return _bfd_elf_hash_symbol (h);
3819 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
3820 #define TARGET_LITTLE_NAME "elf32-i386"
3821 #define ELF_ARCH bfd_arch_i386
3822 #define ELF_MACHINE_CODE EM_386
3823 #define ELF_MAXPAGESIZE 0x1000
3825 #define elf_backend_can_gc_sections 1
3826 #define elf_backend_can_refcount 1
3827 #define elf_backend_want_got_plt 1
3828 #define elf_backend_plt_readonly 1
3829 #define elf_backend_want_plt_sym 0
3830 #define elf_backend_got_header_size 12
3832 /* Support RELA for objdump of prelink objects. */
3833 #define elf_info_to_howto elf_i386_info_to_howto_rel
3834 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
3836 #define bfd_elf32_mkobject elf_i386_mkobject
3838 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
3839 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
3840 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
3841 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
3843 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
3844 #define elf_backend_check_relocs elf_i386_check_relocs
3845 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
3846 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
3847 #define elf_backend_fake_sections elf_i386_fake_sections
3848 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
3849 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
3850 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
3851 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
3852 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
3853 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
3854 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
3855 #define elf_backend_relocate_section elf_i386_relocate_section
3856 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
3857 #define elf_backend_always_size_sections elf_i386_always_size_sections
3858 #define elf_backend_omit_section_dynsym \
3859 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
3860 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
3861 #define elf_backend_hash_symbol elf_i386_hash_symbol
3863 #include "elf32-target.h"
3865 /* FreeBSD support. */
3867 #undef TARGET_LITTLE_SYM
3868 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
3869 #undef TARGET_LITTLE_NAME
3870 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
3872 #define ELF_OSABI ELFOSABI_FREEBSD
3874 /* The kernel recognizes executables as valid only if they carry a
3875 "FreeBSD" label in the ELF header. So we put this label on all
3876 executables and (for simplicity) also all other object files. */
3879 elf_i386_post_process_headers (bfd *abfd,
3880 struct bfd_link_info *info ATTRIBUTE_UNUSED)
3882 Elf_Internal_Ehdr *i_ehdrp;
3884 i_ehdrp = elf_elfheader (abfd);
3886 /* Put an ABI label supported by FreeBSD >= 4.1. */
3887 i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
3888 #ifdef OLD_FREEBSD_ABI_LABEL
3889 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
3890 memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
3894 #undef elf_backend_post_process_headers
3895 #define elf_backend_post_process_headers elf_i386_post_process_headers
3897 #define elf32_bed elf32_i386_fbsd_bed
3899 #include "elf32-target.h"
3901 /* VxWorks support. */
3903 #undef TARGET_LITTLE_SYM
3904 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
3905 #undef TARGET_LITTLE_NAME
3906 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
3909 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
3911 static struct bfd_link_hash_table *
3912 elf_i386_vxworks_link_hash_table_create (bfd *abfd)
3914 struct bfd_link_hash_table *ret;
3915 struct elf_i386_link_hash_table *htab;
3917 ret = elf_i386_link_hash_table_create (abfd);
3920 htab = (struct elf_i386_link_hash_table *) ret;
3921 htab->is_vxworks = 1;
3922 htab->plt0_pad_byte = 0x90;
3929 #undef elf_backend_post_process_headers
3930 #undef bfd_elf32_bfd_link_hash_table_create
3931 #define bfd_elf32_bfd_link_hash_table_create \
3932 elf_i386_vxworks_link_hash_table_create
3933 #undef elf_backend_add_symbol_hook
3934 #define elf_backend_add_symbol_hook \
3935 elf_vxworks_add_symbol_hook
3936 #undef elf_backend_link_output_symbol_hook
3937 #define elf_backend_link_output_symbol_hook \
3938 elf_vxworks_link_output_symbol_hook
3939 #undef elf_backend_emit_relocs
3940 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
3941 #undef elf_backend_final_write_processing
3942 #define elf_backend_final_write_processing \
3943 elf_vxworks_final_write_processing
3945 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
3947 #undef elf_backend_want_plt_sym
3948 #define elf_backend_want_plt_sym 1
3951 #define elf32_bed elf32_i386_vxworks_bed
3953 #include "elf32-target.h"