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
, int is_local
)
905 case R_386_TLS_GOTDESC
:
906 case R_386_TLS_DESC_CALL
:
907 case R_386_TLS_IE_32
:
909 return R_386_TLS_LE_32
;
910 return R_386_TLS_IE_32
;
912 case R_386_TLS_GOTIE
:
914 return R_386_TLS_LE_32
;
917 return R_386_TLS_LE_32
;
923 /* Look through the relocs for a section during the first phase, and
924 calculate needed space in the global offset table, procedure linkage
925 table, and dynamic reloc sections. */
928 elf_i386_check_relocs (bfd
*abfd
,
929 struct bfd_link_info
*info
,
931 const Elf_Internal_Rela
*relocs
)
933 struct elf_i386_link_hash_table
*htab
;
934 Elf_Internal_Shdr
*symtab_hdr
;
935 struct elf_link_hash_entry
**sym_hashes
;
936 const Elf_Internal_Rela
*rel
;
937 const Elf_Internal_Rela
*rel_end
;
940 if (info
->relocatable
)
943 htab
= elf_i386_hash_table (info
);
944 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
945 sym_hashes
= elf_sym_hashes (abfd
);
949 rel_end
= relocs
+ sec
->reloc_count
;
950 for (rel
= relocs
; rel
< rel_end
; rel
++)
953 unsigned long r_symndx
;
954 struct elf_link_hash_entry
*h
;
956 r_symndx
= ELF32_R_SYM (rel
->r_info
);
957 r_type
= ELF32_R_TYPE (rel
->r_info
);
959 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
961 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
967 if (r_symndx
< symtab_hdr
->sh_info
)
971 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
972 while (h
->root
.type
== bfd_link_hash_indirect
973 || h
->root
.type
== bfd_link_hash_warning
)
974 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
977 r_type
= elf_i386_tls_transition (info
, r_type
, h
== NULL
);
982 htab
->tls_ldm_got
.refcount
+= 1;
986 /* This symbol requires a procedure linkage table entry. We
987 actually build the entry in adjust_dynamic_symbol,
988 because this might be a case of linking PIC code which is
989 never referenced by a dynamic object, in which case we
990 don't need to generate a procedure linkage table entry
993 /* If this is a local symbol, we resolve it directly without
994 creating a procedure linkage table entry. */
999 h
->plt
.refcount
+= 1;
1002 case R_386_TLS_IE_32
:
1004 case R_386_TLS_GOTIE
:
1006 info
->flags
|= DF_STATIC_TLS
;
1011 case R_386_TLS_GOTDESC
:
1012 case R_386_TLS_DESC_CALL
:
1013 /* This symbol requires a global offset table entry. */
1015 int tls_type
, old_tls_type
;
1020 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1021 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1022 case R_386_TLS_GOTDESC
:
1023 case R_386_TLS_DESC_CALL
:
1024 tls_type
= GOT_TLS_GDESC
; break;
1025 case R_386_TLS_IE_32
:
1026 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1027 tls_type
= GOT_TLS_IE_NEG
;
1029 /* If this is a GD->IE transition, we may use either of
1030 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1031 tls_type
= GOT_TLS_IE
;
1034 case R_386_TLS_GOTIE
:
1035 tls_type
= GOT_TLS_IE_POS
; break;
1040 h
->got
.refcount
+= 1;
1041 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1045 bfd_signed_vma
*local_got_refcounts
;
1047 /* This is a global offset table entry for a local symbol. */
1048 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1049 if (local_got_refcounts
== NULL
)
1053 size
= symtab_hdr
->sh_info
;
1054 size
*= (sizeof (bfd_signed_vma
)
1055 + sizeof (bfd_vma
) + sizeof(char));
1056 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1057 if (local_got_refcounts
== NULL
)
1059 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1060 elf_i386_local_tlsdesc_gotent (abfd
)
1061 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1062 elf_i386_local_got_tls_type (abfd
)
1063 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1065 local_got_refcounts
[r_symndx
] += 1;
1066 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1069 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1070 tls_type
|= old_tls_type
;
1071 /* If a TLS symbol is accessed using IE at least once,
1072 there is no point to use dynamic model for it. */
1073 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1074 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1075 || (tls_type
& GOT_TLS_IE
) == 0))
1077 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1078 tls_type
= old_tls_type
;
1079 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1080 && GOT_TLS_GD_ANY_P (tls_type
))
1081 tls_type
|= old_tls_type
;
1084 (*_bfd_error_handler
)
1085 (_("%B: `%s' accessed both as normal and "
1086 "thread local symbol"),
1088 h
? h
->root
.root
.string
: "<local>");
1093 if (old_tls_type
!= tls_type
)
1096 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1098 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1106 if (htab
->sgot
== NULL
)
1108 if (htab
->elf
.dynobj
== NULL
)
1109 htab
->elf
.dynobj
= abfd
;
1110 if (!create_got_section (htab
->elf
.dynobj
, info
))
1113 if (r_type
!= R_386_TLS_IE
)
1117 case R_386_TLS_LE_32
:
1121 info
->flags
|= DF_STATIC_TLS
;
1126 if (h
!= NULL
&& !info
->shared
)
1128 /* If this reloc is in a read-only section, we might
1129 need a copy reloc. We can't check reliably at this
1130 stage whether the section is read-only, as input
1131 sections have not yet been mapped to output sections.
1132 Tentatively set the flag for now, and correct in
1133 adjust_dynamic_symbol. */
1136 /* We may need a .plt entry if the function this reloc
1137 refers to is in a shared lib. */
1138 h
->plt
.refcount
+= 1;
1139 if (r_type
!= R_386_PC32
)
1140 h
->pointer_equality_needed
= 1;
1143 /* If we are creating a shared library, and this is a reloc
1144 against a global symbol, or a non PC relative reloc
1145 against a local symbol, then we need to copy the reloc
1146 into the shared library. However, if we are linking with
1147 -Bsymbolic, we do not need to copy a reloc against a
1148 global symbol which is defined in an object we are
1149 including in the link (i.e., DEF_REGULAR is set). At
1150 this point we have not seen all the input files, so it is
1151 possible that DEF_REGULAR is not set now but will be set
1152 later (it is never cleared). In case of a weak definition,
1153 DEF_REGULAR may be cleared later by a strong definition in
1154 a shared library. We account for that possibility below by
1155 storing information in the relocs_copied field of the hash
1156 table entry. A similar situation occurs when creating
1157 shared libraries and symbol visibility changes render the
1160 If on the other hand, we are creating an executable, we
1161 may need to keep relocations for symbols satisfied by a
1162 dynamic library if we manage to avoid copy relocs for the
1165 && (sec
->flags
& SEC_ALLOC
) != 0
1166 && (r_type
!= R_386_PC32
1168 && (! SYMBOLIC_BIND (info
, h
)
1169 || h
->root
.type
== bfd_link_hash_defweak
1170 || !h
->def_regular
))))
1171 || (ELIMINATE_COPY_RELOCS
1173 && (sec
->flags
& SEC_ALLOC
) != 0
1175 && (h
->root
.type
== bfd_link_hash_defweak
1176 || !h
->def_regular
)))
1178 struct elf_i386_dyn_relocs
*p
;
1179 struct elf_i386_dyn_relocs
**head
;
1181 /* We must copy these reloc types into the output file.
1182 Create a reloc section in dynobj and make room for
1188 unsigned int strndx
= elf_elfheader (abfd
)->e_shstrndx
;
1189 unsigned int shnam
= elf_section_data (sec
)->rel_hdr
.sh_name
;
1191 name
= bfd_elf_string_from_elf_section (abfd
, strndx
, shnam
);
1195 if (! CONST_STRNEQ (name
, ".rel")
1196 || strcmp (bfd_get_section_name (abfd
, sec
),
1199 (*_bfd_error_handler
)
1200 (_("%B: bad relocation section name `%s\'"),
1204 if (htab
->elf
.dynobj
== NULL
)
1205 htab
->elf
.dynobj
= abfd
;
1207 dynobj
= htab
->elf
.dynobj
;
1208 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1213 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1214 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1215 if ((sec
->flags
& SEC_ALLOC
) != 0)
1216 flags
|= SEC_ALLOC
| SEC_LOAD
;
1217 sreloc
= bfd_make_section_with_flags (dynobj
,
1221 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1224 elf_section_data (sec
)->sreloc
= sreloc
;
1227 /* If this is a global symbol, we count the number of
1228 relocations we need for this symbol. */
1231 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1236 /* Track dynamic relocs needed for local syms too.
1237 We really need local syms available to do this
1241 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1246 vpp
= &elf_section_data (s
)->local_dynrel
;
1247 head
= (struct elf_i386_dyn_relocs
**)vpp
;
1251 if (p
== NULL
|| p
->sec
!= sec
)
1253 bfd_size_type amt
= sizeof *p
;
1254 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
1265 if (r_type
== R_386_PC32
)
1270 /* This relocation describes the C++ object vtable hierarchy.
1271 Reconstruct it for later use during GC. */
1272 case R_386_GNU_VTINHERIT
:
1273 BFD_ASSERT (h
!= NULL
);
1275 && !bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1279 /* This relocation describes which C++ vtable entries are actually
1280 used. Record for later use during GC. */
1281 case R_386_GNU_VTENTRY
:
1282 BFD_ASSERT (h
!= NULL
);
1284 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1296 /* Return the section that should be marked against GC for a given
1300 elf_i386_gc_mark_hook (asection
*sec
,
1301 struct bfd_link_info
*info
,
1302 Elf_Internal_Rela
*rel
,
1303 struct elf_link_hash_entry
*h
,
1304 Elf_Internal_Sym
*sym
)
1307 switch (ELF32_R_TYPE (rel
->r_info
))
1309 case R_386_GNU_VTINHERIT
:
1310 case R_386_GNU_VTENTRY
:
1314 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1317 /* Update the got entry reference counts for the section being removed. */
1320 elf_i386_gc_sweep_hook (bfd
*abfd
,
1321 struct bfd_link_info
*info
,
1323 const Elf_Internal_Rela
*relocs
)
1325 Elf_Internal_Shdr
*symtab_hdr
;
1326 struct elf_link_hash_entry
**sym_hashes
;
1327 bfd_signed_vma
*local_got_refcounts
;
1328 const Elf_Internal_Rela
*rel
, *relend
;
1330 elf_section_data (sec
)->local_dynrel
= NULL
;
1332 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1333 sym_hashes
= elf_sym_hashes (abfd
);
1334 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1336 relend
= relocs
+ sec
->reloc_count
;
1337 for (rel
= relocs
; rel
< relend
; rel
++)
1339 unsigned long r_symndx
;
1340 unsigned int r_type
;
1341 struct elf_link_hash_entry
*h
= NULL
;
1343 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1344 if (r_symndx
>= symtab_hdr
->sh_info
)
1346 struct elf_i386_link_hash_entry
*eh
;
1347 struct elf_i386_dyn_relocs
**pp
;
1348 struct elf_i386_dyn_relocs
*p
;
1350 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1351 while (h
->root
.type
== bfd_link_hash_indirect
1352 || h
->root
.type
== bfd_link_hash_warning
)
1353 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1354 eh
= (struct elf_i386_link_hash_entry
*) h
;
1356 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1359 /* Everything must go for SEC. */
1365 r_type
= ELF32_R_TYPE (rel
->r_info
);
1366 r_type
= elf_i386_tls_transition (info
, r_type
, h
!= NULL
);
1370 if (elf_i386_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1371 elf_i386_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1375 case R_386_TLS_GOTDESC
:
1376 case R_386_TLS_DESC_CALL
:
1377 case R_386_TLS_IE_32
:
1379 case R_386_TLS_GOTIE
:
1383 if (h
->got
.refcount
> 0)
1384 h
->got
.refcount
-= 1;
1386 else if (local_got_refcounts
!= NULL
)
1388 if (local_got_refcounts
[r_symndx
] > 0)
1389 local_got_refcounts
[r_symndx
] -= 1;
1402 if (h
->plt
.refcount
> 0)
1403 h
->plt
.refcount
-= 1;
1415 /* Adjust a symbol defined by a dynamic object and referenced by a
1416 regular object. The current definition is in some section of the
1417 dynamic object, but we're not including those sections. We have to
1418 change the definition to something the rest of the link can
1422 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1423 struct elf_link_hash_entry
*h
)
1425 struct elf_i386_link_hash_table
*htab
;
1428 /* If this is a function, put it in the procedure linkage table. We
1429 will fill in the contents of the procedure linkage table later,
1430 when we know the address of the .got section. */
1431 if (h
->type
== STT_FUNC
1434 if (h
->plt
.refcount
<= 0
1435 || SYMBOL_CALLS_LOCAL (info
, h
)
1436 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1437 && h
->root
.type
== bfd_link_hash_undefweak
))
1439 /* This case can occur if we saw a PLT32 reloc in an input
1440 file, but the symbol was never referred to by a dynamic
1441 object, or if all references were garbage collected. In
1442 such a case, we don't actually need to build a procedure
1443 linkage table, and we can just do a PC32 reloc instead. */
1444 h
->plt
.offset
= (bfd_vma
) -1;
1451 /* It's possible that we incorrectly decided a .plt reloc was
1452 needed for an R_386_PC32 reloc to a non-function sym in
1453 check_relocs. We can't decide accurately between function and
1454 non-function syms in check-relocs; Objects loaded later in
1455 the link may change h->type. So fix it now. */
1456 h
->plt
.offset
= (bfd_vma
) -1;
1458 /* If this is a weak symbol, and there is a real definition, the
1459 processor independent code will have arranged for us to see the
1460 real definition first, and we can just use the same value. */
1461 if (h
->u
.weakdef
!= NULL
)
1463 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1464 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1465 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1466 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1467 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1468 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1472 /* This is a reference to a symbol defined by a dynamic object which
1473 is not a function. */
1475 /* If we are creating a shared library, we must presume that the
1476 only references to the symbol are via the global offset table.
1477 For such cases we need not do anything here; the relocations will
1478 be handled correctly by relocate_section. */
1482 /* If there are no references to this symbol that do not use the
1483 GOT, we don't need to generate a copy reloc. */
1484 if (!h
->non_got_ref
)
1487 /* If -z nocopyreloc was given, we won't generate them either. */
1488 if (info
->nocopyreloc
)
1494 htab
= elf_i386_hash_table (info
);
1496 /* If there aren't any dynamic relocs in read-only sections, then
1497 we can keep the dynamic relocs and avoid the copy reloc. This
1498 doesn't work on VxWorks, where we can not have dynamic relocations
1499 (other than copy and jump slot relocations) in an executable. */
1500 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
1502 struct elf_i386_link_hash_entry
* eh
;
1503 struct elf_i386_dyn_relocs
*p
;
1505 eh
= (struct elf_i386_link_hash_entry
*) h
;
1506 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1508 s
= p
->sec
->output_section
;
1509 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1522 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1523 h
->root
.root
.string
);
1527 /* We must allocate the symbol in our .dynbss section, which will
1528 become part of the .bss section of the executable. There will be
1529 an entry for this symbol in the .dynsym section. The dynamic
1530 object will contain position independent code, so all references
1531 from the dynamic object to this symbol will go through the global
1532 offset table. The dynamic linker will use the .dynsym entry to
1533 determine the address it must put in the global offset table, so
1534 both the dynamic object and the regular object will refer to the
1535 same memory location for the variable. */
1537 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
1538 copy the initial value out of the dynamic object and into the
1539 runtime process image. */
1540 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1542 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
1548 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1551 /* Allocate space in .plt, .got and associated reloc sections for
1555 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1557 struct bfd_link_info
*info
;
1558 struct elf_i386_link_hash_table
*htab
;
1559 struct elf_i386_link_hash_entry
*eh
;
1560 struct elf_i386_dyn_relocs
*p
;
1562 if (h
->root
.type
== bfd_link_hash_indirect
)
1565 if (h
->root
.type
== bfd_link_hash_warning
)
1566 /* When warning symbols are created, they **replace** the "real"
1567 entry in the hash table, thus we never get to see the real
1568 symbol in a hash traversal. So look at it now. */
1569 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1571 info
= (struct bfd_link_info
*) inf
;
1572 htab
= elf_i386_hash_table (info
);
1574 if (htab
->elf
.dynamic_sections_created
1575 && h
->plt
.refcount
> 0)
1577 /* Make sure this symbol is output as a dynamic symbol.
1578 Undefined weak syms won't yet be marked as dynamic. */
1579 if (h
->dynindx
== -1
1580 && !h
->forced_local
)
1582 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1587 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1589 asection
*s
= htab
->splt
;
1591 /* If this is the first .plt entry, make room for the special
1594 s
->size
+= PLT_ENTRY_SIZE
;
1596 h
->plt
.offset
= s
->size
;
1598 /* If this symbol is not defined in a regular file, and we are
1599 not generating a shared library, then set the symbol to this
1600 location in the .plt. This is required to make function
1601 pointers compare as equal between the normal executable and
1602 the shared library. */
1606 h
->root
.u
.def
.section
= s
;
1607 h
->root
.u
.def
.value
= h
->plt
.offset
;
1610 /* Make room for this entry. */
1611 s
->size
+= PLT_ENTRY_SIZE
;
1613 /* We also need to make an entry in the .got.plt section, which
1614 will be placed in the .got section by the linker script. */
1615 htab
->sgotplt
->size
+= 4;
1617 /* We also need to make an entry in the .rel.plt section. */
1618 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1619 htab
->next_tls_desc_index
++;
1621 if (htab
->is_vxworks
&& !info
->shared
)
1623 /* VxWorks has a second set of relocations for each PLT entry
1624 in executables. They go in a separate relocation section,
1625 which is processed by the kernel loader. */
1627 /* There are two relocations for the initial PLT entry: an
1628 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
1629 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
1631 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
1632 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1634 /* There are two extra relocations for each subsequent PLT entry:
1635 an R_386_32 relocation for the GOT entry, and an R_386_32
1636 relocation for the PLT entry. */
1638 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1643 h
->plt
.offset
= (bfd_vma
) -1;
1649 h
->plt
.offset
= (bfd_vma
) -1;
1653 eh
= (struct elf_i386_link_hash_entry
*) h
;
1654 eh
->tlsdesc_got
= (bfd_vma
) -1;
1656 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
1657 make it a R_386_TLS_LE_32 requiring no TLS entry. */
1658 if (h
->got
.refcount
> 0
1661 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
1662 h
->got
.offset
= (bfd_vma
) -1;
1663 else if (h
->got
.refcount
> 0)
1667 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1669 /* Make sure this symbol is output as a dynamic symbol.
1670 Undefined weak syms won't yet be marked as dynamic. */
1671 if (h
->dynindx
== -1
1672 && !h
->forced_local
)
1674 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1679 if (GOT_TLS_GDESC_P (tls_type
))
1681 eh
->tlsdesc_got
= htab
->sgotplt
->size
1682 - elf_i386_compute_jump_table_size (htab
);
1683 htab
->sgotplt
->size
+= 8;
1684 h
->got
.offset
= (bfd_vma
) -2;
1686 if (! GOT_TLS_GDESC_P (tls_type
)
1687 || GOT_TLS_GD_P (tls_type
))
1689 h
->got
.offset
= s
->size
;
1691 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
1692 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
1695 dyn
= htab
->elf
.dynamic_sections_created
;
1696 /* R_386_TLS_IE_32 needs one dynamic relocation,
1697 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
1698 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
1699 need two), R_386_TLS_GD needs one if local symbol and two if
1701 if (tls_type
== GOT_TLS_IE_BOTH
)
1702 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1703 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
1704 || (tls_type
& GOT_TLS_IE
))
1705 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1706 else if (GOT_TLS_GD_P (tls_type
))
1707 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1708 else if (! GOT_TLS_GDESC_P (tls_type
)
1709 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1710 || h
->root
.type
!= bfd_link_hash_undefweak
)
1712 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1713 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1714 if (GOT_TLS_GDESC_P (tls_type
))
1715 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1718 h
->got
.offset
= (bfd_vma
) -1;
1720 if (eh
->dyn_relocs
== NULL
)
1723 /* In the shared -Bsymbolic case, discard space allocated for
1724 dynamic pc-relative relocs against symbols which turn out to be
1725 defined in regular objects. For the normal shared case, discard
1726 space for pc-relative relocs that have become local due to symbol
1727 visibility changes. */
1731 /* The only reloc that uses pc_count is R_386_PC32, which will
1732 appear on a call or on something like ".long foo - .". We
1733 want calls to protected symbols to resolve directly to the
1734 function rather than going via the plt. If people want
1735 function pointer comparisons to work as expected then they
1736 should avoid writing assembly like ".long foo - .". */
1737 if (SYMBOL_CALLS_LOCAL (info
, h
))
1739 struct elf_i386_dyn_relocs
**pp
;
1741 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1743 p
->count
-= p
->pc_count
;
1752 /* Also discard relocs on undefined weak syms with non-default
1754 if (eh
->dyn_relocs
!= NULL
1755 && h
->root
.type
== bfd_link_hash_undefweak
)
1757 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
1758 eh
->dyn_relocs
= NULL
;
1760 /* Make sure undefined weak symbols are output as a dynamic
1762 else if (h
->dynindx
== -1
1763 && !h
->forced_local
)
1765 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1770 else if (ELIMINATE_COPY_RELOCS
)
1772 /* For the non-shared case, discard space for relocs against
1773 symbols which turn out to need copy relocs or are not
1779 || (htab
->elf
.dynamic_sections_created
1780 && (h
->root
.type
== bfd_link_hash_undefweak
1781 || h
->root
.type
== bfd_link_hash_undefined
))))
1783 /* Make sure this symbol is output as a dynamic symbol.
1784 Undefined weak syms won't yet be marked as dynamic. */
1785 if (h
->dynindx
== -1
1786 && !h
->forced_local
)
1788 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1792 /* If that succeeded, we know we'll be keeping all the
1794 if (h
->dynindx
!= -1)
1798 eh
->dyn_relocs
= NULL
;
1803 /* Finally, allocate space. */
1804 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1806 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1807 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
1813 /* Find any dynamic relocs that apply to read-only sections. */
1816 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1818 struct elf_i386_link_hash_entry
*eh
;
1819 struct elf_i386_dyn_relocs
*p
;
1821 if (h
->root
.type
== bfd_link_hash_warning
)
1822 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1824 eh
= (struct elf_i386_link_hash_entry
*) h
;
1825 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1827 asection
*s
= p
->sec
->output_section
;
1829 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1831 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1833 info
->flags
|= DF_TEXTREL
;
1835 /* Not an error, just cut short the traversal. */
1842 /* Set the sizes of the dynamic sections. */
1845 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1846 struct bfd_link_info
*info
)
1848 struct elf_i386_link_hash_table
*htab
;
1854 htab
= elf_i386_hash_table (info
);
1855 dynobj
= htab
->elf
.dynobj
;
1859 if (htab
->elf
.dynamic_sections_created
)
1861 /* Set the contents of the .interp section to the interpreter. */
1862 if (info
->executable
)
1864 s
= bfd_get_section_by_name (dynobj
, ".interp");
1867 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1868 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1872 /* Set up .got offsets for local syms, and space for local dynamic
1874 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1876 bfd_signed_vma
*local_got
;
1877 bfd_signed_vma
*end_local_got
;
1878 char *local_tls_type
;
1879 bfd_vma
*local_tlsdesc_gotent
;
1880 bfd_size_type locsymcount
;
1881 Elf_Internal_Shdr
*symtab_hdr
;
1884 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1887 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1889 struct elf_i386_dyn_relocs
*p
;
1891 for (p
= ((struct elf_i386_dyn_relocs
*)
1892 elf_section_data (s
)->local_dynrel
);
1896 if (!bfd_is_abs_section (p
->sec
)
1897 && bfd_is_abs_section (p
->sec
->output_section
))
1899 /* Input section has been discarded, either because
1900 it is a copy of a linkonce section or due to
1901 linker script /DISCARD/, so we'll be discarding
1904 else if (p
->count
!= 0)
1906 srel
= elf_section_data (p
->sec
)->sreloc
;
1907 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
1908 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1909 info
->flags
|= DF_TEXTREL
;
1914 local_got
= elf_local_got_refcounts (ibfd
);
1918 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1919 locsymcount
= symtab_hdr
->sh_info
;
1920 end_local_got
= local_got
+ locsymcount
;
1921 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
1922 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
1924 srel
= htab
->srelgot
;
1925 for (; local_got
< end_local_got
;
1926 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
1928 *local_tlsdesc_gotent
= (bfd_vma
) -1;
1931 if (GOT_TLS_GDESC_P (*local_tls_type
))
1933 *local_tlsdesc_gotent
= htab
->sgotplt
->size
1934 - elf_i386_compute_jump_table_size (htab
);
1935 htab
->sgotplt
->size
+= 8;
1936 *local_got
= (bfd_vma
) -2;
1938 if (! GOT_TLS_GDESC_P (*local_tls_type
)
1939 || GOT_TLS_GD_P (*local_tls_type
))
1941 *local_got
= s
->size
;
1943 if (GOT_TLS_GD_P (*local_tls_type
)
1944 || *local_tls_type
== GOT_TLS_IE_BOTH
)
1948 || GOT_TLS_GD_ANY_P (*local_tls_type
)
1949 || (*local_tls_type
& GOT_TLS_IE
))
1951 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
1952 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
1953 else if (GOT_TLS_GD_P (*local_tls_type
)
1954 || ! GOT_TLS_GDESC_P (*local_tls_type
))
1955 srel
->size
+= sizeof (Elf32_External_Rel
);
1956 if (GOT_TLS_GDESC_P (*local_tls_type
))
1957 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1961 *local_got
= (bfd_vma
) -1;
1965 if (htab
->tls_ldm_got
.refcount
> 0)
1967 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
1969 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
1970 htab
->sgot
->size
+= 8;
1971 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1974 htab
->tls_ldm_got
.offset
= -1;
1976 /* Allocate global sym .plt and .got entries, and space for global
1977 sym dynamic relocs. */
1978 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1980 /* For every jump slot reserved in the sgotplt, reloc_count is
1981 incremented. However, when we reserve space for TLS descriptors,
1982 it's not incremented, so in order to compute the space reserved
1983 for them, it suffices to multiply the reloc count by the jump
1986 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
1988 /* We now have determined the sizes of the various dynamic sections.
1989 Allocate memory for them. */
1991 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1993 bfd_boolean strip_section
= TRUE
;
1995 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2000 || s
== htab
->sgotplt
2001 || s
== htab
->sdynbss
)
2003 /* Strip this section if we don't need it; see the
2005 /* We'd like to strip these sections if they aren't needed, but if
2006 we've exported dynamic symbols from them we must leave them.
2007 It's too late to tell BFD to get rid of the symbols. */
2009 if (htab
->elf
.hplt
!= NULL
)
2010 strip_section
= FALSE
;
2012 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2014 if (s
->size
!= 0 && s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
2017 /* We use the reloc_count field as a counter if we need
2018 to copy relocs into the output file. */
2023 /* It's not one of our sections, so don't allocate space. */
2029 /* If we don't need this section, strip it from the
2030 output file. This is mostly to handle .rel.bss and
2031 .rel.plt. We must create both sections in
2032 create_dynamic_sections, because they must be created
2033 before the linker maps input sections to output
2034 sections. The linker does that before
2035 adjust_dynamic_symbol is called, and it is that
2036 function which decides whether anything needs to go
2037 into these sections. */
2039 s
->flags
|= SEC_EXCLUDE
;
2043 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2046 /* Allocate memory for the section contents. We use bfd_zalloc
2047 here in case unused entries are not reclaimed before the
2048 section's contents are written out. This should not happen,
2049 but this way if it does, we get a R_386_NONE reloc instead
2051 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
2052 if (s
->contents
== NULL
)
2056 if (htab
->elf
.dynamic_sections_created
)
2058 /* Add some entries to the .dynamic section. We fill in the
2059 values later, in elf_i386_finish_dynamic_sections, but we
2060 must add the entries now so that we get the correct size for
2061 the .dynamic section. The DT_DEBUG entry is filled in by the
2062 dynamic linker and used by the debugger. */
2063 #define add_dynamic_entry(TAG, VAL) \
2064 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2066 if (info
->executable
)
2068 if (!add_dynamic_entry (DT_DEBUG
, 0))
2072 if (htab
->splt
->size
!= 0)
2074 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2075 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2076 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2077 || !add_dynamic_entry (DT_JMPREL
, 0))
2083 if (!add_dynamic_entry (DT_REL
, 0)
2084 || !add_dynamic_entry (DT_RELSZ
, 0)
2085 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2088 /* If any dynamic relocs apply to a read-only section,
2089 then we need a DT_TEXTREL entry. */
2090 if ((info
->flags
& DF_TEXTREL
) == 0)
2091 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2094 if ((info
->flags
& DF_TEXTREL
) != 0)
2096 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2101 #undef add_dynamic_entry
2107 elf_i386_always_size_sections (bfd
*output_bfd
,
2108 struct bfd_link_info
*info
)
2110 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2114 struct elf_link_hash_entry
*tlsbase
;
2116 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2117 "_TLS_MODULE_BASE_",
2118 FALSE
, FALSE
, FALSE
);
2120 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2122 struct bfd_link_hash_entry
*bh
= NULL
;
2123 const struct elf_backend_data
*bed
2124 = get_elf_backend_data (output_bfd
);
2126 if (!(_bfd_generic_link_add_one_symbol
2127 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2128 tls_sec
, 0, NULL
, FALSE
,
2129 bed
->collect
, &bh
)))
2131 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2132 tlsbase
->def_regular
= 1;
2133 tlsbase
->other
= STV_HIDDEN
;
2134 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2141 /* Set the correct type for an x86 ELF section. We do this by the
2142 section name, which is a hack, but ought to work. */
2145 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2146 Elf_Internal_Shdr
*hdr
,
2149 register const char *name
;
2151 name
= bfd_get_section_name (abfd
, sec
);
2153 /* This is an ugly, but unfortunately necessary hack that is
2154 needed when producing EFI binaries on x86. It tells
2155 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2156 containing ELF relocation info. We need this hack in order to
2157 be able to generate ELF binaries that can be translated into
2158 EFI applications (which are essentially COFF objects). Those
2159 files contain a COFF ".reloc" section inside an ELFNN object,
2160 which would normally cause BFD to segfault because it would
2161 attempt to interpret this section as containing relocation
2162 entries for section "oc". With this hack enabled, ".reloc"
2163 will be treated as a normal data section, which will avoid the
2164 segfault. However, you won't be able to create an ELFNN binary
2165 with a section named "oc" that needs relocations, but that's
2166 the kind of ugly side-effects you get when detecting section
2167 types based on their names... In practice, this limitation is
2168 unlikely to bite. */
2169 if (strcmp (name
, ".reloc") == 0)
2170 hdr
->sh_type
= SHT_PROGBITS
;
2175 /* Return the base VMA address which should be subtracted from real addresses
2176 when resolving @dtpoff relocation.
2177 This is PT_TLS segment p_vaddr. */
2180 dtpoff_base (struct bfd_link_info
*info
)
2182 /* If tls_sec is NULL, we should have signalled an error already. */
2183 if (elf_hash_table (info
)->tls_sec
== NULL
)
2185 return elf_hash_table (info
)->tls_sec
->vma
;
2188 /* Return the relocation value for @tpoff relocation
2189 if STT_TLS virtual address is ADDRESS. */
2192 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2194 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2196 /* If tls_sec is NULL, we should have signalled an error already. */
2197 if (htab
->tls_sec
== NULL
)
2199 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2202 /* Relocate an i386 ELF section. */
2205 elf_i386_relocate_section (bfd
*output_bfd
,
2206 struct bfd_link_info
*info
,
2208 asection
*input_section
,
2210 Elf_Internal_Rela
*relocs
,
2211 Elf_Internal_Sym
*local_syms
,
2212 asection
**local_sections
)
2214 struct elf_i386_link_hash_table
*htab
;
2215 Elf_Internal_Shdr
*symtab_hdr
;
2216 struct elf_link_hash_entry
**sym_hashes
;
2217 bfd_vma
*local_got_offsets
;
2218 bfd_vma
*local_tlsdesc_gotents
;
2219 Elf_Internal_Rela
*rel
;
2220 Elf_Internal_Rela
*relend
;
2222 htab
= elf_i386_hash_table (info
);
2223 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2224 sym_hashes
= elf_sym_hashes (input_bfd
);
2225 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2226 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2229 relend
= relocs
+ input_section
->reloc_count
;
2230 for (; rel
< relend
; rel
++)
2232 unsigned int r_type
;
2233 reloc_howto_type
*howto
;
2234 unsigned long r_symndx
;
2235 struct elf_link_hash_entry
*h
;
2236 Elf_Internal_Sym
*sym
;
2238 bfd_vma off
, offplt
;
2240 bfd_boolean unresolved_reloc
;
2241 bfd_reloc_status_type r
;
2245 r_type
= ELF32_R_TYPE (rel
->r_info
);
2246 if (r_type
== R_386_GNU_VTINHERIT
2247 || r_type
== R_386_GNU_VTENTRY
)
2250 if ((indx
= r_type
) >= R_386_standard
2251 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2252 >= R_386_ext
- R_386_standard
)
2253 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2254 >= R_386_tls
- R_386_ext
))
2256 (*_bfd_error_handler
)
2257 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2258 input_bfd
, input_section
, r_type
);
2259 bfd_set_error (bfd_error_bad_value
);
2262 howto
= elf_howto_table
+ indx
;
2264 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2268 unresolved_reloc
= FALSE
;
2269 if (r_symndx
< symtab_hdr
->sh_info
)
2271 sym
= local_syms
+ r_symndx
;
2272 sec
= local_sections
[r_symndx
];
2273 relocation
= (sec
->output_section
->vma
2274 + sec
->output_offset
2277 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2278 && ((sec
->flags
& SEC_MERGE
) != 0
2279 || (info
->relocatable
2280 && sec
->output_offset
!= 0)))
2283 bfd_byte
*where
= contents
+ rel
->r_offset
;
2285 switch (howto
->size
)
2288 addend
= bfd_get_8 (input_bfd
, where
);
2289 if (howto
->pc_relative
)
2291 addend
= (addend
^ 0x80) - 0x80;
2296 addend
= bfd_get_16 (input_bfd
, where
);
2297 if (howto
->pc_relative
)
2299 addend
= (addend
^ 0x8000) - 0x8000;
2304 addend
= bfd_get_32 (input_bfd
, where
);
2305 if (howto
->pc_relative
)
2307 addend
= (addend
^ 0x80000000) - 0x80000000;
2315 if (info
->relocatable
)
2316 addend
+= sec
->output_offset
;
2319 asection
*msec
= sec
;
2320 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2322 addend
-= relocation
;
2323 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2326 switch (howto
->size
)
2329 /* FIXME: overflow checks. */
2330 if (howto
->pc_relative
)
2332 bfd_put_8 (input_bfd
, addend
, where
);
2335 if (howto
->pc_relative
)
2337 bfd_put_16 (input_bfd
, addend
, where
);
2340 if (howto
->pc_relative
)
2342 bfd_put_32 (input_bfd
, addend
, where
);
2351 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2352 r_symndx
, symtab_hdr
, sym_hashes
,
2354 unresolved_reloc
, warned
);
2357 if (sec
!= NULL
&& elf_discarded_section (sec
))
2359 /* For relocs against symbols from removed linkonce sections,
2360 or sections discarded by a linker script, we just want the
2361 section contents zeroed. Avoid any special processing. */
2362 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2368 if (info
->relocatable
)
2374 /* Relocation is to the entry for this symbol in the global
2376 if (htab
->sgot
== NULL
)
2383 off
= h
->got
.offset
;
2384 dyn
= htab
->elf
.dynamic_sections_created
;
2385 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2387 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2388 || (ELF_ST_VISIBILITY (h
->other
)
2389 && h
->root
.type
== bfd_link_hash_undefweak
))
2391 /* This is actually a static link, or it is a
2392 -Bsymbolic link and the symbol is defined
2393 locally, or the symbol was forced to be local
2394 because of a version file. We must initialize
2395 this entry in the global offset table. Since the
2396 offset must always be a multiple of 4, we use the
2397 least significant bit to record whether we have
2398 initialized it already.
2400 When doing a dynamic link, we create a .rel.got
2401 relocation entry to initialize the value. This
2402 is done in the finish_dynamic_symbol routine. */
2407 bfd_put_32 (output_bfd
, relocation
,
2408 htab
->sgot
->contents
+ off
);
2413 unresolved_reloc
= FALSE
;
2417 if (local_got_offsets
== NULL
)
2420 off
= local_got_offsets
[r_symndx
];
2422 /* The offset must always be a multiple of 4. We use
2423 the least significant bit to record whether we have
2424 already generated the necessary reloc. */
2429 bfd_put_32 (output_bfd
, relocation
,
2430 htab
->sgot
->contents
+ off
);
2435 Elf_Internal_Rela outrel
;
2442 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2443 + htab
->sgot
->output_offset
2445 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2447 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2448 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2451 local_got_offsets
[r_symndx
] |= 1;
2455 if (off
>= (bfd_vma
) -2)
2458 relocation
= htab
->sgot
->output_section
->vma
2459 + htab
->sgot
->output_offset
+ off
2460 - htab
->sgotplt
->output_section
->vma
2461 - htab
->sgotplt
->output_offset
;
2465 /* Relocation is relative to the start of the global offset
2468 /* Check to make sure it isn't a protected function symbol
2469 for shared library since it may not be local when used
2470 as function address. */
2472 && !info
->executable
2475 && h
->type
== STT_FUNC
2476 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2478 (*_bfd_error_handler
)
2479 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
2480 input_bfd
, h
->root
.root
.string
);
2481 bfd_set_error (bfd_error_bad_value
);
2485 /* Note that sgot is not involved in this
2486 calculation. We always want the start of .got.plt. If we
2487 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2488 permitted by the ABI, we might have to change this
2490 relocation
-= htab
->sgotplt
->output_section
->vma
2491 + htab
->sgotplt
->output_offset
;
2495 /* Use global offset table as symbol value. */
2496 relocation
= htab
->sgotplt
->output_section
->vma
2497 + htab
->sgotplt
->output_offset
;
2498 unresolved_reloc
= FALSE
;
2502 /* Relocation is to the entry for this symbol in the
2503 procedure linkage table. */
2505 /* Resolve a PLT32 reloc against a local symbol directly,
2506 without using the procedure linkage table. */
2510 if (h
->plt
.offset
== (bfd_vma
) -1
2511 || htab
->splt
== NULL
)
2513 /* We didn't make a PLT entry for this symbol. This
2514 happens when statically linking PIC code, or when
2515 using -Bsymbolic. */
2519 relocation
= (htab
->splt
->output_section
->vma
2520 + htab
->splt
->output_offset
2522 unresolved_reloc
= FALSE
;
2527 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2532 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2533 || h
->root
.type
!= bfd_link_hash_undefweak
)
2534 && (r_type
!= R_386_PC32
2535 || !SYMBOL_CALLS_LOCAL (info
, h
)))
2536 || (ELIMINATE_COPY_RELOCS
2543 || h
->root
.type
== bfd_link_hash_undefweak
2544 || h
->root
.type
== bfd_link_hash_undefined
)))
2546 Elf_Internal_Rela outrel
;
2548 bfd_boolean skip
, relocate
;
2551 /* When generating a shared object, these relocations
2552 are copied into the output file to be resolved at run
2559 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2561 if (outrel
.r_offset
== (bfd_vma
) -1)
2563 else if (outrel
.r_offset
== (bfd_vma
) -2)
2564 skip
= TRUE
, relocate
= TRUE
;
2565 outrel
.r_offset
+= (input_section
->output_section
->vma
2566 + input_section
->output_offset
);
2569 memset (&outrel
, 0, sizeof outrel
);
2572 && (r_type
== R_386_PC32
2574 || !SYMBOLIC_BIND (info
, h
)
2575 || !h
->def_regular
))
2576 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2579 /* This symbol is local, or marked to become local. */
2581 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2584 sreloc
= elf_section_data (input_section
)->sreloc
;
2588 loc
= sreloc
->contents
;
2589 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2590 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2592 /* If this reloc is against an external symbol, we do
2593 not want to fiddle with the addend. Otherwise, we
2594 need to include the symbol value so that it becomes
2595 an addend for the dynamic reloc. */
2604 Elf_Internal_Rela outrel
;
2608 outrel
.r_offset
= rel
->r_offset
2609 + input_section
->output_section
->vma
2610 + input_section
->output_offset
;
2611 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2612 sreloc
= elf_section_data (input_section
)->sreloc
;
2615 loc
= sreloc
->contents
;
2616 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2617 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2622 case R_386_TLS_GOTDESC
:
2623 case R_386_TLS_DESC_CALL
:
2624 case R_386_TLS_IE_32
:
2625 case R_386_TLS_GOTIE
:
2626 r_type
= elf_i386_tls_transition (info
, r_type
, h
== NULL
);
2627 tls_type
= GOT_UNKNOWN
;
2628 if (h
== NULL
&& local_got_offsets
)
2629 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
2632 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2633 if (!info
->shared
&& h
->dynindx
== -1 && (tls_type
& GOT_TLS_IE
))
2634 r_type
= R_386_TLS_LE_32
;
2636 if (tls_type
== GOT_TLS_IE
)
2637 tls_type
= GOT_TLS_IE_NEG
;
2638 if (r_type
== R_386_TLS_GD
2639 || r_type
== R_386_TLS_GOTDESC
2640 || r_type
== R_386_TLS_DESC_CALL
)
2642 if (tls_type
== GOT_TLS_IE_POS
)
2643 r_type
= R_386_TLS_GOTIE
;
2644 else if (tls_type
& GOT_TLS_IE
)
2645 r_type
= R_386_TLS_IE_32
;
2648 if (r_type
== R_386_TLS_LE_32
)
2650 BFD_ASSERT (! unresolved_reloc
);
2651 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
2653 unsigned int val
, type
;
2656 /* GD->LE transition. */
2657 BFD_ASSERT (rel
->r_offset
>= 2);
2658 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2659 BFD_ASSERT (type
== 0x8d || type
== 0x04);
2660 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
2661 BFD_ASSERT (bfd_get_8 (input_bfd
,
2662 contents
+ rel
->r_offset
+ 4)
2664 BFD_ASSERT (rel
+ 1 < relend
);
2665 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
2666 roff
= rel
->r_offset
+ 5;
2667 val
= bfd_get_8 (input_bfd
,
2668 contents
+ rel
->r_offset
- 1);
2671 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
2673 movl %gs:0, %eax; subl $foo@tpoff, %eax
2674 (6 byte form of subl). */
2675 BFD_ASSERT (rel
->r_offset
>= 3);
2676 BFD_ASSERT (bfd_get_8 (input_bfd
,
2677 contents
+ rel
->r_offset
- 3)
2679 BFD_ASSERT ((val
& 0xc7) == 0x05 && val
!= (4 << 3));
2680 memcpy (contents
+ rel
->r_offset
- 3,
2681 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2685 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
2686 if (rel
->r_offset
+ 10 <= input_section
->size
2687 && bfd_get_8 (input_bfd
,
2688 contents
+ rel
->r_offset
+ 9) == 0x90)
2690 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
2692 movl %gs:0, %eax; subl $foo@tpoff, %eax
2693 (6 byte form of subl). */
2694 memcpy (contents
+ rel
->r_offset
- 2,
2695 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2696 roff
= rel
->r_offset
+ 6;
2700 /* leal foo(%reg), %eax; call ___tls_get_addr
2702 movl %gs:0, %eax; subl $foo@tpoff, %eax
2703 (5 byte form of subl). */
2704 memcpy (contents
+ rel
->r_offset
- 2,
2705 "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2708 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2710 /* Skip R_386_PLT32. */
2714 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
2716 /* GDesc -> LE transition.
2717 It's originally something like:
2718 leal x@tlsdesc(%ebx), %eax
2722 Registers other than %eax may be set up here. */
2724 unsigned int val
, type
;
2727 /* First, make sure it's a leal adding ebx to a
2728 32-bit offset into any register, although it's
2729 probably almost always going to be eax. */
2730 roff
= rel
->r_offset
;
2731 BFD_ASSERT (roff
>= 2);
2732 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
2733 BFD_ASSERT (type
== 0x8d);
2734 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2735 BFD_ASSERT ((val
& 0xc7) == 0x83);
2736 BFD_ASSERT (roff
+ 4 <= input_section
->size
);
2738 /* Now modify the instruction as appropriate. */
2739 /* aoliva FIXME: remove the above and xor the byte
2741 bfd_put_8 (output_bfd
, val
^ 0x86,
2742 contents
+ roff
- 1);
2743 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2747 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
2749 /* GDesc -> LE transition.
2755 unsigned int val
, type
;
2758 /* First, make sure it's a call *(%eax). */
2759 roff
= rel
->r_offset
;
2760 BFD_ASSERT (roff
+ 2 <= input_section
->size
);
2761 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
2762 BFD_ASSERT (type
== 0xff);
2763 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
2764 BFD_ASSERT (val
== 0x10);
2766 /* Now modify the instruction as appropriate. Use
2767 xchg %ax,%ax instead of 2 nops. */
2768 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
2769 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
2772 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
2774 unsigned int val
, type
;
2776 /* IE->LE transition:
2777 Originally it can be one of:
2785 BFD_ASSERT (rel
->r_offset
>= 1);
2786 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2787 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->size
);
2790 /* movl foo, %eax. */
2791 bfd_put_8 (output_bfd
, 0xb8,
2792 contents
+ rel
->r_offset
- 1);
2796 BFD_ASSERT (rel
->r_offset
>= 2);
2797 type
= bfd_get_8 (input_bfd
,
2798 contents
+ rel
->r_offset
- 2);
2803 BFD_ASSERT ((val
& 0xc7) == 0x05);
2804 bfd_put_8 (output_bfd
, 0xc7,
2805 contents
+ rel
->r_offset
- 2);
2806 bfd_put_8 (output_bfd
,
2807 0xc0 | ((val
>> 3) & 7),
2808 contents
+ rel
->r_offset
- 1);
2812 BFD_ASSERT ((val
& 0xc7) == 0x05);
2813 bfd_put_8 (output_bfd
, 0x81,
2814 contents
+ rel
->r_offset
- 2);
2815 bfd_put_8 (output_bfd
,
2816 0xc0 | ((val
>> 3) & 7),
2817 contents
+ rel
->r_offset
- 1);
2824 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2825 contents
+ rel
->r_offset
);
2830 unsigned int val
, type
;
2832 /* {IE_32,GOTIE}->LE transition:
2833 Originally it can be one of:
2834 subl foo(%reg1), %reg2
2835 movl foo(%reg1), %reg2
2836 addl foo(%reg1), %reg2
2839 movl $foo, %reg2 (6 byte form)
2840 addl $foo, %reg2. */
2841 BFD_ASSERT (rel
->r_offset
>= 2);
2842 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2843 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2844 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->size
);
2845 BFD_ASSERT ((val
& 0xc0) == 0x80 && (val
& 7) != 4);
2849 bfd_put_8 (output_bfd
, 0xc7,
2850 contents
+ rel
->r_offset
- 2);
2851 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
2852 contents
+ rel
->r_offset
- 1);
2854 else if (type
== 0x2b)
2857 bfd_put_8 (output_bfd
, 0x81,
2858 contents
+ rel
->r_offset
- 2);
2859 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
2860 contents
+ rel
->r_offset
- 1);
2862 else if (type
== 0x03)
2865 bfd_put_8 (output_bfd
, 0x81,
2866 contents
+ rel
->r_offset
- 2);
2867 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
2868 contents
+ rel
->r_offset
- 1);
2872 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
2873 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2874 contents
+ rel
->r_offset
);
2876 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2877 contents
+ rel
->r_offset
);
2882 if (htab
->sgot
== NULL
)
2887 off
= h
->got
.offset
;
2888 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
2892 if (local_got_offsets
== NULL
)
2895 off
= local_got_offsets
[r_symndx
];
2896 offplt
= local_tlsdesc_gotents
[r_symndx
];
2903 Elf_Internal_Rela outrel
;
2908 if (htab
->srelgot
== NULL
)
2911 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2913 if (GOT_TLS_GDESC_P (tls_type
))
2915 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
2916 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
2917 <= htab
->sgotplt
->size
);
2918 outrel
.r_offset
= (htab
->sgotplt
->output_section
->vma
2919 + htab
->sgotplt
->output_offset
2921 + htab
->sgotplt_jump_table_size
);
2922 sreloc
= htab
->srelplt
;
2923 loc
= sreloc
->contents
;
2924 loc
+= (htab
->next_tls_desc_index
++
2925 * sizeof (Elf32_External_Rel
));
2926 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
2927 <= sreloc
->contents
+ sreloc
->size
);
2928 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2931 BFD_ASSERT (! unresolved_reloc
);
2932 bfd_put_32 (output_bfd
,
2933 relocation
- dtpoff_base (info
),
2934 htab
->sgotplt
->contents
+ offplt
2935 + htab
->sgotplt_jump_table_size
+ 4);
2939 bfd_put_32 (output_bfd
, 0,
2940 htab
->sgotplt
->contents
+ offplt
2941 + htab
->sgotplt_jump_table_size
+ 4);
2945 sreloc
= htab
->srelgot
;
2947 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2948 + htab
->sgot
->output_offset
+ off
);
2950 if (GOT_TLS_GD_P (tls_type
))
2951 dr_type
= R_386_TLS_DTPMOD32
;
2952 else if (GOT_TLS_GDESC_P (tls_type
))
2954 else if (tls_type
== GOT_TLS_IE_POS
)
2955 dr_type
= R_386_TLS_TPOFF
;
2957 dr_type
= R_386_TLS_TPOFF32
;
2959 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
2960 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
2961 htab
->sgot
->contents
+ off
);
2962 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
2963 bfd_put_32 (output_bfd
, dtpoff_base (info
) - relocation
,
2964 htab
->sgot
->contents
+ off
);
2965 else if (dr_type
!= R_386_TLS_DESC
)
2966 bfd_put_32 (output_bfd
, 0,
2967 htab
->sgot
->contents
+ off
);
2968 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
2970 loc
= sreloc
->contents
;
2971 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2972 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
2973 <= sreloc
->contents
+ sreloc
->size
);
2974 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2976 if (GOT_TLS_GD_P (tls_type
))
2980 BFD_ASSERT (! unresolved_reloc
);
2981 bfd_put_32 (output_bfd
,
2982 relocation
- dtpoff_base (info
),
2983 htab
->sgot
->contents
+ off
+ 4);
2987 bfd_put_32 (output_bfd
, 0,
2988 htab
->sgot
->contents
+ off
+ 4);
2989 outrel
.r_info
= ELF32_R_INFO (indx
,
2990 R_386_TLS_DTPOFF32
);
2991 outrel
.r_offset
+= 4;
2992 sreloc
->reloc_count
++;
2993 loc
+= sizeof (Elf32_External_Rel
);
2994 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
2995 <= sreloc
->contents
+ sreloc
->size
);
2996 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2999 else if (tls_type
== GOT_TLS_IE_BOTH
)
3001 bfd_put_32 (output_bfd
,
3002 indx
== 0 ? relocation
- dtpoff_base (info
) : 0,
3003 htab
->sgot
->contents
+ off
+ 4);
3004 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3005 outrel
.r_offset
+= 4;
3006 sreloc
->reloc_count
++;
3007 loc
+= sizeof (Elf32_External_Rel
);
3008 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3015 local_got_offsets
[r_symndx
] |= 1;
3018 if (off
>= (bfd_vma
) -2
3019 && ! GOT_TLS_GDESC_P (tls_type
))
3021 if (r_type
== R_386_TLS_GOTDESC
3022 || r_type
== R_386_TLS_DESC_CALL
)
3024 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3025 unresolved_reloc
= FALSE
;
3027 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3029 bfd_vma g_o_t
= htab
->sgotplt
->output_section
->vma
3030 + htab
->sgotplt
->output_offset
;
3031 relocation
= htab
->sgot
->output_section
->vma
3032 + htab
->sgot
->output_offset
+ off
- g_o_t
;
3033 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3034 && tls_type
== GOT_TLS_IE_BOTH
)
3036 if (r_type
== R_386_TLS_IE
)
3037 relocation
+= g_o_t
;
3038 unresolved_reloc
= FALSE
;
3040 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3042 unsigned int val
, type
;
3045 /* GD->IE transition. */
3046 BFD_ASSERT (rel
->r_offset
>= 2);
3047 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3048 BFD_ASSERT (type
== 0x8d || type
== 0x04);
3049 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
3050 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
3052 BFD_ASSERT (rel
+ 1 < relend
);
3053 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
3054 roff
= rel
->r_offset
- 3;
3055 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3058 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3060 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3061 BFD_ASSERT (rel
->r_offset
>= 3);
3062 BFD_ASSERT (bfd_get_8 (input_bfd
,
3063 contents
+ rel
->r_offset
- 3)
3065 BFD_ASSERT ((val
& 0xc7) == 0x05 && val
!= (4 << 3));
3070 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3072 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3073 BFD_ASSERT (rel
->r_offset
+ 10 <= input_section
->size
);
3074 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
3075 BFD_ASSERT (bfd_get_8 (input_bfd
,
3076 contents
+ rel
->r_offset
+ 9)
3078 roff
= rel
->r_offset
- 2;
3080 memcpy (contents
+ roff
,
3081 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3082 contents
[roff
+ 7] = 0x80 | (val
& 7);
3083 /* If foo is used only with foo@gotntpoff(%reg) and
3084 foo@indntpoff, but not with foo@gottpoff(%reg), change
3085 subl $foo@gottpoff(%reg), %eax
3087 addl $foo@gotntpoff(%reg), %eax. */
3088 if (tls_type
== GOT_TLS_IE_POS
)
3089 contents
[roff
+ 6] = 0x03;
3090 bfd_put_32 (output_bfd
,
3091 htab
->sgot
->output_section
->vma
3092 + htab
->sgot
->output_offset
+ off
3093 - htab
->sgotplt
->output_section
->vma
3094 - htab
->sgotplt
->output_offset
,
3095 contents
+ roff
+ 8);
3096 /* Skip R_386_PLT32. */
3100 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3102 /* GDesc -> IE transition.
3103 It's originally something like:
3104 leal x@tlsdesc(%ebx), %eax
3107 movl x@gotntpoff(%ebx), %eax # before nop; nop
3109 movl x@gottpoff(%ebx), %eax # before negl %eax
3111 Registers other than %eax may be set up here. */
3113 unsigned int val
, type
;
3116 /* First, make sure it's a leal adding ebx to a 32-bit
3117 offset into any register, although it's probably
3118 almost always going to be eax. */
3119 roff
= rel
->r_offset
;
3120 BFD_ASSERT (roff
>= 2);
3121 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3122 BFD_ASSERT (type
== 0x8d);
3123 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3124 BFD_ASSERT ((val
& 0xc7) == 0x83);
3125 BFD_ASSERT (roff
+ 4 <= input_section
->size
);
3127 /* Now modify the instruction as appropriate. */
3128 /* To turn a leal into a movl in the form we use it, it
3129 suffices to change the first byte from 0x8d to 0x8b.
3130 aoliva FIXME: should we decide to keep the leal, all
3131 we have to do is remove the statement below, and
3132 adjust the relaxation of R_386_TLS_DESC_CALL. */
3133 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3135 if (tls_type
== GOT_TLS_IE_BOTH
)
3138 bfd_put_32 (output_bfd
,
3139 htab
->sgot
->output_section
->vma
3140 + htab
->sgot
->output_offset
+ off
3141 - htab
->sgotplt
->output_section
->vma
3142 - htab
->sgotplt
->output_offset
,
3146 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3148 /* GDesc -> IE transition.
3156 depending on how we transformed the TLS_GOTDESC above.
3159 unsigned int val
, type
;
3162 /* First, make sure it's a call *(%eax). */
3163 roff
= rel
->r_offset
;
3164 BFD_ASSERT (roff
+ 2 <= input_section
->size
);
3165 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
3166 BFD_ASSERT (type
== 0xff);
3167 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
3168 BFD_ASSERT (val
== 0x10);
3170 /* Now modify the instruction as appropriate. */
3171 if (tls_type
!= GOT_TLS_IE_NEG
)
3174 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3175 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3180 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3181 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3195 /* LD->LE transition:
3197 leal foo(%reg), %eax; call ___tls_get_addr.
3199 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3200 BFD_ASSERT (rel
->r_offset
>= 2);
3201 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2)
3203 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3204 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
3205 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
3206 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
3208 BFD_ASSERT (rel
+ 1 < relend
);
3209 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
3210 memcpy (contents
+ rel
->r_offset
- 2,
3211 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3212 /* Skip R_386_PLT32. */
3217 if (htab
->sgot
== NULL
)
3220 off
= htab
->tls_ldm_got
.offset
;
3225 Elf_Internal_Rela outrel
;
3228 if (htab
->srelgot
== NULL
)
3231 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3232 + htab
->sgot
->output_offset
+ off
);
3234 bfd_put_32 (output_bfd
, 0,
3235 htab
->sgot
->contents
+ off
);
3236 bfd_put_32 (output_bfd
, 0,
3237 htab
->sgot
->contents
+ off
+ 4);
3238 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3239 loc
= htab
->srelgot
->contents
;
3240 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3241 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3242 htab
->tls_ldm_got
.offset
|= 1;
3244 relocation
= htab
->sgot
->output_section
->vma
3245 + htab
->sgot
->output_offset
+ off
3246 - htab
->sgotplt
->output_section
->vma
3247 - htab
->sgotplt
->output_offset
;
3248 unresolved_reloc
= FALSE
;
3251 case R_386_TLS_LDO_32
:
3252 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3253 relocation
-= dtpoff_base (info
);
3255 /* When converting LDO to LE, we must negate. */
3256 relocation
= -tpoff (info
, relocation
);
3259 case R_386_TLS_LE_32
:
3263 Elf_Internal_Rela outrel
;
3268 outrel
.r_offset
= rel
->r_offset
3269 + input_section
->output_section
->vma
3270 + input_section
->output_offset
;
3271 if (h
!= NULL
&& h
->dynindx
!= -1)
3275 if (r_type
== R_386_TLS_LE_32
)
3276 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3278 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3279 sreloc
= elf_section_data (input_section
)->sreloc
;
3282 loc
= sreloc
->contents
;
3283 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3284 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3287 else if (r_type
== R_386_TLS_LE_32
)
3288 relocation
= dtpoff_base (info
) - relocation
;
3290 relocation
-= dtpoff_base (info
);
3292 else if (r_type
== R_386_TLS_LE_32
)
3293 relocation
= tpoff (info
, relocation
);
3295 relocation
= -tpoff (info
, relocation
);
3302 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3303 because such sections are not SEC_ALLOC and thus ld.so will
3304 not process them. */
3305 if (unresolved_reloc
3306 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3309 (*_bfd_error_handler
)
3310 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3313 (long) rel
->r_offset
,
3315 h
->root
.root
.string
);
3319 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3320 contents
, rel
->r_offset
,
3323 if (r
!= bfd_reloc_ok
)
3328 name
= h
->root
.root
.string
;
3331 name
= bfd_elf_string_from_elf_section (input_bfd
,
3332 symtab_hdr
->sh_link
,
3337 name
= bfd_section_name (input_bfd
, sec
);
3340 if (r
== bfd_reloc_overflow
)
3342 if (! ((*info
->callbacks
->reloc_overflow
)
3343 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3344 (bfd_vma
) 0, input_bfd
, input_section
,
3350 (*_bfd_error_handler
)
3351 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3352 input_bfd
, input_section
,
3353 (long) rel
->r_offset
, name
, (int) r
);
3362 /* Finish up dynamic symbol handling. We set the contents of various
3363 dynamic sections here. */
3366 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3367 struct bfd_link_info
*info
,
3368 struct elf_link_hash_entry
*h
,
3369 Elf_Internal_Sym
*sym
)
3371 struct elf_i386_link_hash_table
*htab
;
3373 htab
= elf_i386_hash_table (info
);
3375 if (h
->plt
.offset
!= (bfd_vma
) -1)
3379 Elf_Internal_Rela rel
;
3382 /* This symbol has an entry in the procedure linkage table. Set
3385 if (h
->dynindx
== -1
3386 || htab
->splt
== NULL
3387 || htab
->sgotplt
== NULL
3388 || htab
->srelplt
== NULL
)
3391 /* Get the index in the procedure linkage table which
3392 corresponds to this symbol. This is the index of this symbol
3393 in all the symbols for which we are making plt entries. The
3394 first entry in the procedure linkage table is reserved. */
3395 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3397 /* Get the offset into the .got table of the entry that
3398 corresponds to this function. Each .got entry is 4 bytes.
3399 The first three are reserved. */
3400 got_offset
= (plt_index
+ 3) * 4;
3402 /* Fill in the entry in the procedure linkage table. */
3405 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
3407 bfd_put_32 (output_bfd
,
3408 (htab
->sgotplt
->output_section
->vma
3409 + htab
->sgotplt
->output_offset
3411 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3413 if (htab
->is_vxworks
)
3415 int s
, k
, reloc_index
;
3417 /* Create the R_386_32 relocation referencing the GOT
3418 for this PLT entry. */
3420 /* S: Current slot number (zero-based). */
3421 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3422 /* K: Number of relocations for PLTResolve. */
3424 k
= PLTRESOLVE_RELOCS_SHLIB
;
3426 k
= PLTRESOLVE_RELOCS
;
3427 /* Skip the PLTresolve relocations, and the relocations for
3428 the other PLT slots. */
3429 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3430 loc
= (htab
->srelplt2
->contents
+ reloc_index
3431 * sizeof (Elf32_External_Rel
));
3433 rel
.r_offset
= (htab
->splt
->output_section
->vma
3434 + htab
->splt
->output_offset
3435 + h
->plt
.offset
+ 2),
3436 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3437 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3439 /* Create the R_386_32 relocation referencing the beginning of
3440 the PLT for this GOT entry. */
3441 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3442 + htab
->sgotplt
->output_offset
3444 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3445 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3446 loc
+ sizeof (Elf32_External_Rel
));
3451 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
3453 bfd_put_32 (output_bfd
, got_offset
,
3454 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3457 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
3458 htab
->splt
->contents
+ h
->plt
.offset
+ 7);
3459 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
3460 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3462 /* Fill in the entry in the global offset table. */
3463 bfd_put_32 (output_bfd
,
3464 (htab
->splt
->output_section
->vma
3465 + htab
->splt
->output_offset
3468 htab
->sgotplt
->contents
+ got_offset
);
3470 /* Fill in the entry in the .rel.plt section. */
3471 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3472 + htab
->sgotplt
->output_offset
3474 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3475 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3476 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3478 if (!h
->def_regular
)
3480 /* Mark the symbol as undefined, rather than as defined in
3481 the .plt section. Leave the value if there were any
3482 relocations where pointer equality matters (this is a clue
3483 for the dynamic linker, to make function pointer
3484 comparisons work between an application and shared
3485 library), otherwise set it to zero. If a function is only
3486 called from a binary, there is no need to slow down
3487 shared libraries because of that. */
3488 sym
->st_shndx
= SHN_UNDEF
;
3489 if (!h
->pointer_equality_needed
)
3494 if (h
->got
.offset
!= (bfd_vma
) -1
3495 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
3496 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
3498 Elf_Internal_Rela rel
;
3501 /* This symbol has an entry in the global offset table. Set it
3504 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3507 rel
.r_offset
= (htab
->sgot
->output_section
->vma
3508 + htab
->sgot
->output_offset
3509 + (h
->got
.offset
& ~(bfd_vma
) 1));
3511 /* If this is a static link, or it is a -Bsymbolic link and the
3512 symbol is defined locally or was forced to be local because
3513 of a version file, we just want to emit a RELATIVE reloc.
3514 The entry in the global offset table will already have been
3515 initialized in the relocate_section function. */
3517 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3519 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3520 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3524 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3525 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3526 htab
->sgot
->contents
+ h
->got
.offset
);
3527 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3530 loc
= htab
->srelgot
->contents
;
3531 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3532 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3537 Elf_Internal_Rela rel
;
3540 /* This symbol needs a copy reloc. Set it up. */
3542 if (h
->dynindx
== -1
3543 || (h
->root
.type
!= bfd_link_hash_defined
3544 && h
->root
.type
!= bfd_link_hash_defweak
)
3545 || htab
->srelbss
== NULL
)
3548 rel
.r_offset
= (h
->root
.u
.def
.value
3549 + h
->root
.u
.def
.section
->output_section
->vma
3550 + h
->root
.u
.def
.section
->output_offset
);
3551 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
3552 loc
= htab
->srelbss
->contents
;
3553 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3554 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3557 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.
3558 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
3559 is relative to the ".got" section. */
3560 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3561 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
))
3562 sym
->st_shndx
= SHN_ABS
;
3567 /* Used to decide how to sort relocs in an optimal manner for the
3568 dynamic linker, before writing them out. */
3570 static enum elf_reloc_type_class
3571 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
3573 switch (ELF32_R_TYPE (rela
->r_info
))
3575 case R_386_RELATIVE
:
3576 return reloc_class_relative
;
3577 case R_386_JUMP_SLOT
:
3578 return reloc_class_plt
;
3580 return reloc_class_copy
;
3582 return reloc_class_normal
;
3586 /* Finish up the dynamic sections. */
3589 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
3590 struct bfd_link_info
*info
)
3592 struct elf_i386_link_hash_table
*htab
;
3596 htab
= elf_i386_hash_table (info
);
3597 dynobj
= htab
->elf
.dynobj
;
3598 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3600 if (htab
->elf
.dynamic_sections_created
)
3602 Elf32_External_Dyn
*dyncon
, *dynconend
;
3604 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3607 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3608 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3609 for (; dyncon
< dynconend
; dyncon
++)
3611 Elf_Internal_Dyn dyn
;
3614 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3623 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3628 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3633 dyn
.d_un
.d_val
= s
->size
;
3637 /* My reading of the SVR4 ABI indicates that the
3638 procedure linkage table relocs (DT_JMPREL) should be
3639 included in the overall relocs (DT_REL). This is
3640 what Solaris does. However, UnixWare can not handle
3641 that case. Therefore, we override the DT_RELSZ entry
3642 here to make it not include the JMPREL relocs. */
3646 dyn
.d_un
.d_val
-= s
->size
;
3650 /* We may not be using the standard ELF linker script.
3651 If .rel.plt is the first .rel section, we adjust
3652 DT_REL to not include it. */
3656 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
3658 dyn
.d_un
.d_ptr
+= s
->size
;
3662 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3665 /* Fill in the first entry in the procedure linkage table. */
3666 if (htab
->splt
&& htab
->splt
->size
> 0)
3670 memcpy (htab
->splt
->contents
, elf_i386_pic_plt0_entry
,
3671 sizeof (elf_i386_pic_plt0_entry
));
3672 memset (htab
->splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
3673 htab
->plt0_pad_byte
,
3674 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
3678 memcpy (htab
->splt
->contents
, elf_i386_plt0_entry
,
3679 sizeof(elf_i386_plt0_entry
));
3680 memset (htab
->splt
->contents
+ sizeof (elf_i386_plt0_entry
),
3681 htab
->plt0_pad_byte
,
3682 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
3683 bfd_put_32 (output_bfd
,
3684 (htab
->sgotplt
->output_section
->vma
3685 + htab
->sgotplt
->output_offset
3687 htab
->splt
->contents
+ 2);
3688 bfd_put_32 (output_bfd
,
3689 (htab
->sgotplt
->output_section
->vma
3690 + htab
->sgotplt
->output_offset
3692 htab
->splt
->contents
+ 8);
3694 if (htab
->is_vxworks
)
3696 Elf_Internal_Rela rel
;
3698 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
3699 On IA32 we use REL relocations so the addend goes in
3700 the PLT directly. */
3701 rel
.r_offset
= (htab
->splt
->output_section
->vma
3702 + htab
->splt
->output_offset
3704 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3705 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3706 htab
->srelplt2
->contents
);
3707 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
3708 rel
.r_offset
= (htab
->splt
->output_section
->vma
3709 + htab
->splt
->output_offset
3711 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3712 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3713 htab
->srelplt2
->contents
+
3714 sizeof (Elf32_External_Rel
));
3718 /* UnixWare sets the entsize of .plt to 4, although that doesn't
3719 really seem like the right value. */
3720 elf_section_data (htab
->splt
->output_section
)
3721 ->this_hdr
.sh_entsize
= 4;
3723 /* Correct the .rel.plt.unloaded relocations. */
3724 if (htab
->is_vxworks
&& !info
->shared
)
3726 int num_plts
= (htab
->splt
->size
/ PLT_ENTRY_SIZE
) - 1;
3729 p
= htab
->srelplt2
->contents
;
3731 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
3733 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
3735 for (; num_plts
; num_plts
--)
3737 Elf_Internal_Rela rel
;
3738 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3739 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3740 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3741 p
+= sizeof (Elf32_External_Rel
);
3743 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3744 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3745 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3746 p
+= sizeof (Elf32_External_Rel
);
3754 /* Fill in the first three entries in the global offset table. */
3755 if (htab
->sgotplt
->size
> 0)
3757 bfd_put_32 (output_bfd
,
3759 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
3760 htab
->sgotplt
->contents
);
3761 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 4);
3762 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 8);
3765 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
3768 if (htab
->sgot
&& htab
->sgot
->size
> 0)
3769 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
3774 /* Return address for Ith PLT stub in section PLT, for relocation REL
3775 or (bfd_vma) -1 if it should not be included. */
3778 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
3779 const arelent
*rel ATTRIBUTE_UNUSED
)
3781 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3784 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3787 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
3789 if (h
->plt
.offset
!= (bfd_vma
) -1
3791 && !h
->pointer_equality_needed
)
3794 return _bfd_elf_hash_symbol (h
);
3797 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
3798 #define TARGET_LITTLE_NAME "elf32-i386"
3799 #define ELF_ARCH bfd_arch_i386
3800 #define ELF_MACHINE_CODE EM_386
3801 #define ELF_MAXPAGESIZE 0x1000
3803 #define elf_backend_can_gc_sections 1
3804 #define elf_backend_can_refcount 1
3805 #define elf_backend_want_got_plt 1
3806 #define elf_backend_plt_readonly 1
3807 #define elf_backend_want_plt_sym 0
3808 #define elf_backend_got_header_size 12
3810 /* Support RELA for objdump of prelink objects. */
3811 #define elf_info_to_howto elf_i386_info_to_howto_rel
3812 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
3814 #define bfd_elf32_mkobject elf_i386_mkobject
3816 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
3817 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
3818 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
3819 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
3821 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
3822 #define elf_backend_check_relocs elf_i386_check_relocs
3823 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
3824 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
3825 #define elf_backend_fake_sections elf_i386_fake_sections
3826 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
3827 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
3828 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
3829 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
3830 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
3831 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
3832 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
3833 #define elf_backend_relocate_section elf_i386_relocate_section
3834 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
3835 #define elf_backend_always_size_sections elf_i386_always_size_sections
3836 #define elf_backend_omit_section_dynsym \
3837 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
3838 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
3839 #define elf_backend_hash_symbol elf_i386_hash_symbol
3841 #include "elf32-target.h"
3843 /* FreeBSD support. */
3845 #undef TARGET_LITTLE_SYM
3846 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
3847 #undef TARGET_LITTLE_NAME
3848 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
3850 #define ELF_OSABI ELFOSABI_FREEBSD
3852 /* The kernel recognizes executables as valid only if they carry a
3853 "FreeBSD" label in the ELF header. So we put this label on all
3854 executables and (for simplicity) also all other object files. */
3857 elf_i386_post_process_headers (bfd
*abfd
,
3858 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3860 Elf_Internal_Ehdr
*i_ehdrp
;
3862 i_ehdrp
= elf_elfheader (abfd
);
3864 /* Put an ABI label supported by FreeBSD >= 4.1. */
3865 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
3866 #ifdef OLD_FREEBSD_ABI_LABEL
3867 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
3868 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
3872 #undef elf_backend_post_process_headers
3873 #define elf_backend_post_process_headers elf_i386_post_process_headers
3875 #define elf32_bed elf32_i386_fbsd_bed
3877 #include "elf32-target.h"
3879 /* VxWorks support. */
3881 #undef TARGET_LITTLE_SYM
3882 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
3883 #undef TARGET_LITTLE_NAME
3884 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
3887 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
3889 static struct bfd_link_hash_table
*
3890 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
3892 struct bfd_link_hash_table
*ret
;
3893 struct elf_i386_link_hash_table
*htab
;
3895 ret
= elf_i386_link_hash_table_create (abfd
);
3898 htab
= (struct elf_i386_link_hash_table
*) ret
;
3899 htab
->is_vxworks
= 1;
3900 htab
->plt0_pad_byte
= 0x90;
3907 #undef elf_backend_post_process_headers
3908 #undef bfd_elf32_bfd_link_hash_table_create
3909 #define bfd_elf32_bfd_link_hash_table_create \
3910 elf_i386_vxworks_link_hash_table_create
3911 #undef elf_backend_add_symbol_hook
3912 #define elf_backend_add_symbol_hook \
3913 elf_vxworks_add_symbol_hook
3914 #undef elf_backend_link_output_symbol_hook
3915 #define elf_backend_link_output_symbol_hook \
3916 elf_vxworks_link_output_symbol_hook
3917 #undef elf_backend_emit_relocs
3918 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
3919 #undef elf_backend_final_write_processing
3920 #define elf_backend_final_write_processing \
3921 elf_vxworks_final_write_processing
3923 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
3925 #undef elf_backend_want_plt_sym
3926 #define elf_backend_want_plt_sym 1
3929 #define elf32_bed elf32_i386_vxworks_bed
3931 #include "elf32-target.h"