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"
28 #include "bfd_stdint.h"
30 /* 386 uses REL relocations instead of RELA. */
35 static reloc_howto_type elf_howto_table
[]=
37 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
38 bfd_elf_generic_reloc
, "R_386_NONE",
39 TRUE
, 0x00000000, 0x00000000, FALSE
),
40 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
41 bfd_elf_generic_reloc
, "R_386_32",
42 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
43 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
44 bfd_elf_generic_reloc
, "R_386_PC32",
45 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
46 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
47 bfd_elf_generic_reloc
, "R_386_GOT32",
48 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
49 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
50 bfd_elf_generic_reloc
, "R_386_PLT32",
51 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
52 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
53 bfd_elf_generic_reloc
, "R_386_COPY",
54 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
55 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
56 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
57 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
58 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
59 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
60 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
61 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_386_RELATIVE",
63 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
64 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
65 bfd_elf_generic_reloc
, "R_386_GOTOFF",
66 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
67 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
68 bfd_elf_generic_reloc
, "R_386_GOTPC",
69 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
71 /* We have a gap in the reloc numbers here.
72 R_386_standard counts the number up to this point, and
73 R_386_ext_offset is the value to subtract from a reloc type of
74 R_386_16 thru R_386_PC8 to form an index into this table. */
75 #define R_386_standard (R_386_GOTPC + 1)
76 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
78 /* These relocs are a GNU extension. */
79 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
80 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
81 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
82 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_386_TLS_IE",
84 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
85 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
86 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
87 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
88 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_386_TLS_LE",
90 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
91 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
92 bfd_elf_generic_reloc
, "R_386_TLS_GD",
93 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
94 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
96 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
97 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
98 bfd_elf_generic_reloc
, "R_386_16",
99 TRUE
, 0xffff, 0xffff, FALSE
),
100 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
101 bfd_elf_generic_reloc
, "R_386_PC16",
102 TRUE
, 0xffff, 0xffff, TRUE
),
103 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
104 bfd_elf_generic_reloc
, "R_386_8",
105 TRUE
, 0xff, 0xff, FALSE
),
106 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
107 bfd_elf_generic_reloc
, "R_386_PC8",
108 TRUE
, 0xff, 0xff, TRUE
),
110 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
111 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
112 /* These are common with Solaris TLS implementation. */
113 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
114 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
115 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
116 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
118 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
119 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
121 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
122 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
123 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
124 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
125 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
126 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
127 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
128 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
129 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
130 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
132 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
133 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
134 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
135 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
136 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
138 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
139 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
140 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
143 #define R_386_tls (R_386_TLS_DESC + 1 - R_386_tls_offset)
144 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_tls)
146 /* GNU extension to record C++ vtable hierarchy. */
147 HOWTO (R_386_GNU_VTINHERIT
, /* type */
149 2, /* size (0 = byte, 1 = short, 2 = long) */
151 FALSE
, /* pc_relative */
153 complain_overflow_dont
, /* complain_on_overflow */
154 NULL
, /* special_function */
155 "R_386_GNU_VTINHERIT", /* name */
156 FALSE
, /* partial_inplace */
159 FALSE
), /* pcrel_offset */
161 /* GNU extension to record C++ vtable member usage. */
162 HOWTO (R_386_GNU_VTENTRY
, /* type */
164 2, /* size (0 = byte, 1 = short, 2 = long) */
166 FALSE
, /* pc_relative */
168 complain_overflow_dont
, /* complain_on_overflow */
169 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
170 "R_386_GNU_VTENTRY", /* name */
171 FALSE
, /* partial_inplace */
174 FALSE
) /* pcrel_offset */
176 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
180 #ifdef DEBUG_GEN_RELOC
182 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
187 static reloc_howto_type
*
188 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
189 bfd_reloc_code_real_type code
)
194 TRACE ("BFD_RELOC_NONE");
195 return &elf_howto_table
[R_386_NONE
];
198 TRACE ("BFD_RELOC_32");
199 return &elf_howto_table
[R_386_32
];
202 TRACE ("BFD_RELOC_CTOR");
203 return &elf_howto_table
[R_386_32
];
205 case BFD_RELOC_32_PCREL
:
206 TRACE ("BFD_RELOC_PC32");
207 return &elf_howto_table
[R_386_PC32
];
209 case BFD_RELOC_386_GOT32
:
210 TRACE ("BFD_RELOC_386_GOT32");
211 return &elf_howto_table
[R_386_GOT32
];
213 case BFD_RELOC_386_PLT32
:
214 TRACE ("BFD_RELOC_386_PLT32");
215 return &elf_howto_table
[R_386_PLT32
];
217 case BFD_RELOC_386_COPY
:
218 TRACE ("BFD_RELOC_386_COPY");
219 return &elf_howto_table
[R_386_COPY
];
221 case BFD_RELOC_386_GLOB_DAT
:
222 TRACE ("BFD_RELOC_386_GLOB_DAT");
223 return &elf_howto_table
[R_386_GLOB_DAT
];
225 case BFD_RELOC_386_JUMP_SLOT
:
226 TRACE ("BFD_RELOC_386_JUMP_SLOT");
227 return &elf_howto_table
[R_386_JUMP_SLOT
];
229 case BFD_RELOC_386_RELATIVE
:
230 TRACE ("BFD_RELOC_386_RELATIVE");
231 return &elf_howto_table
[R_386_RELATIVE
];
233 case BFD_RELOC_386_GOTOFF
:
234 TRACE ("BFD_RELOC_386_GOTOFF");
235 return &elf_howto_table
[R_386_GOTOFF
];
237 case BFD_RELOC_386_GOTPC
:
238 TRACE ("BFD_RELOC_386_GOTPC");
239 return &elf_howto_table
[R_386_GOTPC
];
241 /* These relocs are a GNU extension. */
242 case BFD_RELOC_386_TLS_TPOFF
:
243 TRACE ("BFD_RELOC_386_TLS_TPOFF");
244 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
246 case BFD_RELOC_386_TLS_IE
:
247 TRACE ("BFD_RELOC_386_TLS_IE");
248 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
250 case BFD_RELOC_386_TLS_GOTIE
:
251 TRACE ("BFD_RELOC_386_TLS_GOTIE");
252 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
254 case BFD_RELOC_386_TLS_LE
:
255 TRACE ("BFD_RELOC_386_TLS_LE");
256 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
258 case BFD_RELOC_386_TLS_GD
:
259 TRACE ("BFD_RELOC_386_TLS_GD");
260 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
262 case BFD_RELOC_386_TLS_LDM
:
263 TRACE ("BFD_RELOC_386_TLS_LDM");
264 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
267 TRACE ("BFD_RELOC_16");
268 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
270 case BFD_RELOC_16_PCREL
:
271 TRACE ("BFD_RELOC_16_PCREL");
272 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
275 TRACE ("BFD_RELOC_8");
276 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
278 case BFD_RELOC_8_PCREL
:
279 TRACE ("BFD_RELOC_8_PCREL");
280 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
282 /* Common with Sun TLS implementation. */
283 case BFD_RELOC_386_TLS_LDO_32
:
284 TRACE ("BFD_RELOC_386_TLS_LDO_32");
285 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
287 case BFD_RELOC_386_TLS_IE_32
:
288 TRACE ("BFD_RELOC_386_TLS_IE_32");
289 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
291 case BFD_RELOC_386_TLS_LE_32
:
292 TRACE ("BFD_RELOC_386_TLS_LE_32");
293 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
295 case BFD_RELOC_386_TLS_DTPMOD32
:
296 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
297 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
299 case BFD_RELOC_386_TLS_DTPOFF32
:
300 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
301 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
303 case BFD_RELOC_386_TLS_TPOFF32
:
304 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
305 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
307 case BFD_RELOC_386_TLS_GOTDESC
:
308 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
309 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
311 case BFD_RELOC_386_TLS_DESC_CALL
:
312 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
313 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
315 case BFD_RELOC_386_TLS_DESC
:
316 TRACE ("BFD_RELOC_386_TLS_DESC");
317 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
319 case BFD_RELOC_VTABLE_INHERIT
:
320 TRACE ("BFD_RELOC_VTABLE_INHERIT");
321 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
323 case BFD_RELOC_VTABLE_ENTRY
:
324 TRACE ("BFD_RELOC_VTABLE_ENTRY");
325 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
335 static reloc_howto_type
*
336 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
341 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
342 if (elf_howto_table
[i
].name
!= NULL
343 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
344 return &elf_howto_table
[i
];
349 static reloc_howto_type
*
350 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
354 if ((indx
= r_type
) >= R_386_standard
355 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
356 >= R_386_ext
- R_386_standard
)
357 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
358 >= R_386_tls
- R_386_ext
)
359 && ((indx
= r_type
- R_386_vt_offset
) - R_386_tls
360 >= R_386_vt
- R_386_tls
))
362 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
366 BFD_ASSERT (elf_howto_table
[indx
].type
== r_type
);
367 return &elf_howto_table
[indx
];
371 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
373 Elf_Internal_Rela
*dst
)
375 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
376 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
379 /* Return whether a symbol name implies a local label. The UnixWare
380 2.1 cc generates temporary symbols that start with .X, so we
381 recognize them here. FIXME: do other SVR4 compilers also use .X?.
382 If so, we should move the .X recognition into
383 _bfd_elf_is_local_label_name. */
386 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
388 if (name
[0] == '.' && name
[1] == 'X')
391 return _bfd_elf_is_local_label_name (abfd
, name
);
394 /* Support for core dump NOTE sections. */
397 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
402 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
404 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
410 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
413 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
417 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
421 switch (note
->descsz
)
426 case 144: /* Linux/i386 */
428 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
431 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
441 /* Make a ".reg/999" section. */
442 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
443 size
, note
->descpos
+ offset
);
447 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
449 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
451 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
456 elf_tdata (abfd
)->core_program
457 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
458 elf_tdata (abfd
)->core_command
459 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
463 switch (note
->descsz
)
468 case 124: /* Linux/i386 elf_prpsinfo. */
469 elf_tdata (abfd
)->core_program
470 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
471 elf_tdata (abfd
)->core_command
472 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
476 /* Note that for some reason, a spurious space is tacked
477 onto the end of the args in some (at least one anyway)
478 implementations, so strip it off if it exists. */
480 char *command
= elf_tdata (abfd
)->core_command
;
481 int n
= strlen (command
);
483 if (0 < n
&& command
[n
- 1] == ' ')
484 command
[n
- 1] = '\0';
490 /* Functions for the i386 ELF linker.
492 In order to gain some understanding of code in this file without
493 knowing all the intricate details of the linker, note the
496 Functions named elf_i386_* are called by external routines, other
497 functions are only called locally. elf_i386_* functions appear
498 in this file more or less in the order in which they are called
499 from external routines. eg. elf_i386_check_relocs is called
500 early in the link process, elf_i386_finish_dynamic_sections is
501 one of the last functions. */
504 /* The name of the dynamic interpreter. This is put in the .interp
507 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
509 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
510 copying dynamic variables from a shared lib into an app's dynbss
511 section, and instead use a dynamic relocation to point into the
513 #define ELIMINATE_COPY_RELOCS 1
515 /* The size in bytes of an entry in the procedure linkage table. */
517 #define PLT_ENTRY_SIZE 16
519 /* The first entry in an absolute procedure linkage table looks like
520 this. See the SVR4 ABI i386 supplement to see how this works.
521 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
523 static const bfd_byte elf_i386_plt0_entry
[12] =
525 0xff, 0x35, /* pushl contents of address */
526 0, 0, 0, 0, /* replaced with address of .got + 4. */
527 0xff, 0x25, /* jmp indirect */
528 0, 0, 0, 0 /* replaced with address of .got + 8. */
531 /* Subsequent entries in an absolute procedure linkage table look like
534 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
536 0xff, 0x25, /* jmp indirect */
537 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
538 0x68, /* pushl immediate */
539 0, 0, 0, 0, /* replaced with offset into relocation table. */
540 0xe9, /* jmp relative */
541 0, 0, 0, 0 /* replaced with offset to start of .plt. */
544 /* The first entry in a PIC procedure linkage table look like this.
545 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
547 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
549 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
550 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
553 /* Subsequent entries in a PIC procedure linkage table look like this. */
555 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
557 0xff, 0xa3, /* jmp *offset(%ebx) */
558 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
559 0x68, /* pushl immediate */
560 0, 0, 0, 0, /* replaced with offset into relocation table. */
561 0xe9, /* jmp relative */
562 0, 0, 0, 0 /* replaced with offset to start of .plt. */
565 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
566 for the PLTResolve stub and then for each PLT entry. */
567 #define PLTRESOLVE_RELOCS_SHLIB 0
568 #define PLTRESOLVE_RELOCS 2
569 #define PLT_NON_JUMP_SLOT_RELOCS 2
571 /* The i386 linker needs to keep track of the number of relocs that it
572 decides to copy as dynamic relocs in check_relocs for each symbol.
573 This is so that it can later discard them if they are found to be
574 unnecessary. We store the information in a field extending the
575 regular ELF linker hash table. */
577 struct elf_i386_dyn_relocs
579 struct elf_i386_dyn_relocs
*next
;
581 /* The input section of the reloc. */
584 /* Total number of relocs copied for the input section. */
587 /* Number of pc-relative relocs copied for the input section. */
588 bfd_size_type pc_count
;
591 /* i386 ELF linker hash entry. */
593 struct elf_i386_link_hash_entry
595 struct elf_link_hash_entry elf
;
597 /* Track dynamic relocs copied for this symbol. */
598 struct elf_i386_dyn_relocs
*dyn_relocs
;
600 #define GOT_UNKNOWN 0
604 #define GOT_TLS_IE_POS 5
605 #define GOT_TLS_IE_NEG 6
606 #define GOT_TLS_IE_BOTH 7
607 #define GOT_TLS_GDESC 8
608 #define GOT_TLS_GD_BOTH_P(type) \
609 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
610 #define GOT_TLS_GD_P(type) \
611 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
612 #define GOT_TLS_GDESC_P(type) \
613 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
614 #define GOT_TLS_GD_ANY_P(type) \
615 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
616 unsigned char tls_type
;
618 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
619 starting at the end of the jump table. */
623 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
625 struct elf_i386_obj_tdata
627 struct elf_obj_tdata root
;
629 /* tls_type for each local got entry. */
630 char *local_got_tls_type
;
632 /* GOTPLT entries for TLS descriptors. */
633 bfd_vma
*local_tlsdesc_gotent
;
636 #define elf_i386_tdata(abfd) \
637 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
639 #define elf_i386_local_got_tls_type(abfd) \
640 (elf_i386_tdata (abfd)->local_got_tls_type)
642 #define elf_i386_local_tlsdesc_gotent(abfd) \
643 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
646 elf_i386_mkobject (bfd
*abfd
)
648 if (abfd
->tdata
.any
== NULL
)
650 bfd_size_type amt
= sizeof (struct elf_i386_obj_tdata
);
651 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
652 if (abfd
->tdata
.any
== NULL
)
655 return bfd_elf_mkobject (abfd
);
658 /* i386 ELF linker hash table. */
660 struct elf_i386_link_hash_table
662 struct elf_link_hash_table elf
;
664 /* Short-cuts to get to dynamic linker sections. */
673 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
676 /* True if the target system is VxWorks. */
679 /* Value used to fill the last word of the first plt entry. */
680 bfd_byte plt0_pad_byte
;
682 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
683 bfd_vma next_tls_desc_index
;
686 bfd_signed_vma refcount
;
690 /* The amount of space used by the reserved portion of the sgotplt
691 section, plus whatever space is used by the jump slots. */
692 bfd_vma sgotplt_jump_table_size
;
694 /* Small local sym to section mapping cache. */
695 struct sym_sec_cache sym_sec
;
698 /* Get the i386 ELF linker hash table from a link_info structure. */
700 #define elf_i386_hash_table(p) \
701 ((struct elf_i386_link_hash_table *) ((p)->hash))
703 #define elf_i386_compute_jump_table_size(htab) \
704 ((htab)->next_tls_desc_index * 4)
706 /* Create an entry in an i386 ELF linker hash table. */
708 static struct bfd_hash_entry
*
709 link_hash_newfunc (struct bfd_hash_entry
*entry
,
710 struct bfd_hash_table
*table
,
713 /* Allocate the structure if it has not already been allocated by a
717 entry
= bfd_hash_allocate (table
,
718 sizeof (struct elf_i386_link_hash_entry
));
723 /* Call the allocation method of the superclass. */
724 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
727 struct elf_i386_link_hash_entry
*eh
;
729 eh
= (struct elf_i386_link_hash_entry
*) entry
;
730 eh
->dyn_relocs
= NULL
;
731 eh
->tls_type
= GOT_UNKNOWN
;
732 eh
->tlsdesc_got
= (bfd_vma
) -1;
738 /* Create an i386 ELF linker hash table. */
740 static struct bfd_link_hash_table
*
741 elf_i386_link_hash_table_create (bfd
*abfd
)
743 struct elf_i386_link_hash_table
*ret
;
744 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
746 ret
= bfd_malloc (amt
);
750 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
,
751 sizeof (struct elf_i386_link_hash_entry
)))
764 ret
->tls_ldm_got
.refcount
= 0;
765 ret
->next_tls_desc_index
= 0;
766 ret
->sgotplt_jump_table_size
= 0;
767 ret
->sym_sec
.abfd
= NULL
;
769 ret
->srelplt2
= NULL
;
770 ret
->plt0_pad_byte
= 0;
772 return &ret
->elf
.root
;
775 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
776 shortcuts to them in our hash table. */
779 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
781 struct elf_i386_link_hash_table
*htab
;
783 if (! _bfd_elf_create_got_section (dynobj
, info
))
786 htab
= elf_i386_hash_table (info
);
787 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
788 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
789 if (!htab
->sgot
|| !htab
->sgotplt
)
792 htab
->srelgot
= bfd_make_section_with_flags (dynobj
, ".rel.got",
793 (SEC_ALLOC
| SEC_LOAD
798 if (htab
->srelgot
== NULL
799 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
804 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
805 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
809 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
811 struct elf_i386_link_hash_table
*htab
;
813 htab
= elf_i386_hash_table (info
);
814 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
817 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
820 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
821 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
822 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
824 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
826 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
827 || (!info
->shared
&& !htab
->srelbss
))
831 && !elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
837 /* Copy the extra info we tack onto an elf_link_hash_entry. */
840 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
841 struct elf_link_hash_entry
*dir
,
842 struct elf_link_hash_entry
*ind
)
844 struct elf_i386_link_hash_entry
*edir
, *eind
;
846 edir
= (struct elf_i386_link_hash_entry
*) dir
;
847 eind
= (struct elf_i386_link_hash_entry
*) ind
;
849 if (eind
->dyn_relocs
!= NULL
)
851 if (edir
->dyn_relocs
!= NULL
)
853 struct elf_i386_dyn_relocs
**pp
;
854 struct elf_i386_dyn_relocs
*p
;
856 /* Add reloc counts against the indirect sym to the direct sym
857 list. Merge any entries against the same section. */
858 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
860 struct elf_i386_dyn_relocs
*q
;
862 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
863 if (q
->sec
== p
->sec
)
865 q
->pc_count
+= p
->pc_count
;
866 q
->count
+= p
->count
;
873 *pp
= edir
->dyn_relocs
;
876 edir
->dyn_relocs
= eind
->dyn_relocs
;
877 eind
->dyn_relocs
= NULL
;
880 if (ind
->root
.type
== bfd_link_hash_indirect
881 && dir
->got
.refcount
<= 0)
883 edir
->tls_type
= eind
->tls_type
;
884 eind
->tls_type
= GOT_UNKNOWN
;
887 if (ELIMINATE_COPY_RELOCS
888 && ind
->root
.type
!= bfd_link_hash_indirect
889 && dir
->dynamic_adjusted
)
891 /* If called to transfer flags for a weakdef during processing
892 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
893 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
894 dir
->ref_dynamic
|= ind
->ref_dynamic
;
895 dir
->ref_regular
|= ind
->ref_regular
;
896 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
897 dir
->needs_plt
|= ind
->needs_plt
;
898 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
901 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
911 /* Return TRUE if the TLS access code sequence support transition
915 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
917 Elf_Internal_Shdr
*symtab_hdr
,
918 struct elf_link_hash_entry
**sym_hashes
,
920 const Elf_Internal_Rela
*rel
,
921 const Elf_Internal_Rela
*relend
)
923 unsigned int val
, type
;
924 unsigned long r_symndx
;
925 struct elf_link_hash_entry
*h
;
928 /* Get the section contents. */
929 if (contents
== NULL
)
931 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
932 contents
= elf_section_data (sec
)->this_hdr
.contents
;
935 /* FIXME: How to better handle error condition? */
936 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
939 /* Cache the section contents for elf_link_input_bfd. */
940 elf_section_data (sec
)->this_hdr
.contents
= contents
;
944 offset
= rel
->r_offset
;
949 if (offset
< 2 || (rel
+ 1) >= relend
)
952 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
953 if (r_type
== R_386_TLS_GD
)
955 /* Check transition from LD access model. Only
956 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
957 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
958 can transit to different access model. */
959 if ((offset
+ 10) > sec
->size
||
960 (type
!= 0x8d && type
!= 0x04))
963 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
966 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
970 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
973 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
978 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
979 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
982 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
988 /* Check transition from LD access model. Only
989 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
990 can transit to different access model. */
991 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
994 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
995 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
999 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1002 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1003 if (r_symndx
< symtab_hdr
->sh_info
)
1006 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1008 && h
->root
.root
.string
!= NULL
1009 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1010 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1011 && (strcmp (h
->root
.root
.string
, "___tls_get_addr") == 0));
1014 /* Check transition from IE access model:
1015 movl foo@indntpoff(%rip), %eax
1016 movl foo@indntpoff(%rip), %reg
1017 addl foo@indntpoff(%rip), %reg
1020 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1023 /* Check "movl foo@tpoff(%rip), %eax" first. */
1024 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1031 /* Check movl|addl foo@tpoff(%rip), %reg. */
1032 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1033 return ((type
== 0x8b || type
== 0x03)
1034 && (val
& 0xc7) == 0x05);
1036 case R_386_TLS_GOTIE
:
1037 case R_386_TLS_IE_32
:
1038 /* Check transition from {IE_32,GOTIE} access model:
1039 subl foo@{tpoff,gontoff}(%reg1), %reg2
1040 movl foo@{tpoff,gontoff}(%reg1), %reg2
1041 addl foo@{tpoff,gontoff}(%reg1), %reg2
1044 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1047 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1048 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1051 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1052 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1054 case R_386_TLS_GOTDESC
:
1055 /* Check transition from GDesc access model:
1056 leal x@tlsdesc(%ebx), %eax
1058 Make sure it's a leal adding ebx to a 32-bit offset
1059 into any register, although it's probably almost always
1062 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1065 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1068 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1069 return (val
& 0xc7) == 0x83;
1071 case R_386_TLS_DESC_CALL
:
1072 /* Check transition from GDesc access model:
1073 call *x@tlsdesc(%rax)
1075 if (offset
+ 2 <= sec
->size
)
1077 /* Make sure that it's a call *x@tlsdesc(%rax). */
1078 static i386_opcode16 call
= { { 0xff, 0x10 } };
1079 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1089 /* Return TRUE if the TLS access transition is OK or no transition
1090 will be performed. Update R_TYPE if there is a transition. */
1093 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1094 asection
*sec
, bfd_byte
*contents
,
1095 Elf_Internal_Shdr
*symtab_hdr
,
1096 struct elf_link_hash_entry
**sym_hashes
,
1097 unsigned int *r_type
, int tls_type
,
1098 const Elf_Internal_Rela
*rel
,
1099 const Elf_Internal_Rela
*relend
,
1100 struct elf_link_hash_entry
*h
)
1102 unsigned int from_type
= *r_type
;
1103 unsigned int to_type
= from_type
;
1104 bfd_boolean check
= TRUE
;
1109 case R_386_TLS_GOTDESC
:
1110 case R_386_TLS_DESC_CALL
:
1111 case R_386_TLS_IE_32
:
1113 case R_386_TLS_GOTIE
:
1117 to_type
= R_386_TLS_LE_32
;
1118 else if (from_type
!= R_386_TLS_IE
1119 && from_type
!= R_386_TLS_GOTIE
)
1120 to_type
= R_386_TLS_IE_32
;
1123 /* When we are called from elf_i386_relocate_section, CONTENTS
1124 isn't NULL and there may be additional transitions based on
1126 if (contents
!= NULL
)
1128 unsigned int new_to_type
= to_type
;
1133 && (tls_type
& GOT_TLS_IE
))
1134 new_to_type
= R_386_TLS_LE_32
;
1136 if (to_type
== R_386_TLS_GD
1137 || to_type
== R_386_TLS_GOTDESC
1138 || to_type
== R_386_TLS_DESC_CALL
)
1140 if (tls_type
== GOT_TLS_IE_POS
)
1141 new_to_type
= R_386_TLS_GOTIE
;
1142 else if (tls_type
& GOT_TLS_IE
)
1143 new_to_type
= R_386_TLS_IE_32
;
1146 /* We checked the transition before when we were called from
1147 elf_i386_check_relocs. We only want to check the new
1148 transition which hasn't been checked before. */
1149 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1150 to_type
= new_to_type
;
1157 to_type
= R_386_TLS_LE_32
;
1164 /* Return TRUE if there is no transition. */
1165 if (from_type
== to_type
)
1168 /* Check if the transition can be performed. */
1170 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1171 symtab_hdr
, sym_hashes
,
1172 from_type
, rel
, relend
))
1174 reloc_howto_type
*from
, *to
;
1176 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1177 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1179 (*_bfd_error_handler
)
1180 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1181 "in section `%A' failed"),
1182 abfd
, sec
, from
->name
, to
->name
,
1183 h
? h
->root
.root
.string
: "a local symbol",
1184 (unsigned long) rel
->r_offset
);
1185 bfd_set_error (bfd_error_bad_value
);
1193 /* Look through the relocs for a section during the first phase, and
1194 calculate needed space in the global offset table, procedure linkage
1195 table, and dynamic reloc sections. */
1198 elf_i386_check_relocs (bfd
*abfd
,
1199 struct bfd_link_info
*info
,
1201 const Elf_Internal_Rela
*relocs
)
1203 struct elf_i386_link_hash_table
*htab
;
1204 Elf_Internal_Shdr
*symtab_hdr
;
1205 struct elf_link_hash_entry
**sym_hashes
;
1206 const Elf_Internal_Rela
*rel
;
1207 const Elf_Internal_Rela
*rel_end
;
1210 if (info
->relocatable
)
1213 htab
= elf_i386_hash_table (info
);
1214 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1215 sym_hashes
= elf_sym_hashes (abfd
);
1219 rel_end
= relocs
+ sec
->reloc_count
;
1220 for (rel
= relocs
; rel
< rel_end
; rel
++)
1222 unsigned int r_type
;
1223 unsigned long r_symndx
;
1224 struct elf_link_hash_entry
*h
;
1226 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1227 r_type
= ELF32_R_TYPE (rel
->r_info
);
1229 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1231 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1237 if (r_symndx
< symtab_hdr
->sh_info
)
1241 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1242 while (h
->root
.type
== bfd_link_hash_indirect
1243 || h
->root
.type
== bfd_link_hash_warning
)
1244 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1247 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1248 symtab_hdr
, sym_hashes
,
1249 &r_type
, GOT_UNKNOWN
,
1256 htab
->tls_ldm_got
.refcount
+= 1;
1260 /* This symbol requires a procedure linkage table entry. We
1261 actually build the entry in adjust_dynamic_symbol,
1262 because this might be a case of linking PIC code which is
1263 never referenced by a dynamic object, in which case we
1264 don't need to generate a procedure linkage table entry
1267 /* If this is a local symbol, we resolve it directly without
1268 creating a procedure linkage table entry. */
1273 h
->plt
.refcount
+= 1;
1276 case R_386_TLS_IE_32
:
1278 case R_386_TLS_GOTIE
:
1280 info
->flags
|= DF_STATIC_TLS
;
1285 case R_386_TLS_GOTDESC
:
1286 case R_386_TLS_DESC_CALL
:
1287 /* This symbol requires a global offset table entry. */
1289 int tls_type
, old_tls_type
;
1294 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1295 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1296 case R_386_TLS_GOTDESC
:
1297 case R_386_TLS_DESC_CALL
:
1298 tls_type
= GOT_TLS_GDESC
; break;
1299 case R_386_TLS_IE_32
:
1300 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1301 tls_type
= GOT_TLS_IE_NEG
;
1303 /* If this is a GD->IE transition, we may use either of
1304 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1305 tls_type
= GOT_TLS_IE
;
1308 case R_386_TLS_GOTIE
:
1309 tls_type
= GOT_TLS_IE_POS
; break;
1314 h
->got
.refcount
+= 1;
1315 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1319 bfd_signed_vma
*local_got_refcounts
;
1321 /* This is a global offset table entry for a local symbol. */
1322 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1323 if (local_got_refcounts
== NULL
)
1327 size
= symtab_hdr
->sh_info
;
1328 size
*= (sizeof (bfd_signed_vma
)
1329 + sizeof (bfd_vma
) + sizeof(char));
1330 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1331 if (local_got_refcounts
== NULL
)
1333 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1334 elf_i386_local_tlsdesc_gotent (abfd
)
1335 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1336 elf_i386_local_got_tls_type (abfd
)
1337 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1339 local_got_refcounts
[r_symndx
] += 1;
1340 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1343 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1344 tls_type
|= old_tls_type
;
1345 /* If a TLS symbol is accessed using IE at least once,
1346 there is no point to use dynamic model for it. */
1347 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1348 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1349 || (tls_type
& GOT_TLS_IE
) == 0))
1351 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1352 tls_type
= old_tls_type
;
1353 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1354 && GOT_TLS_GD_ANY_P (tls_type
))
1355 tls_type
|= old_tls_type
;
1358 (*_bfd_error_handler
)
1359 (_("%B: `%s' accessed both as normal and "
1360 "thread local symbol"),
1362 h
? h
->root
.root
.string
: "<local>");
1367 if (old_tls_type
!= tls_type
)
1370 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1372 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1380 if (htab
->sgot
== NULL
)
1382 if (htab
->elf
.dynobj
== NULL
)
1383 htab
->elf
.dynobj
= abfd
;
1384 if (!create_got_section (htab
->elf
.dynobj
, info
))
1387 if (r_type
!= R_386_TLS_IE
)
1391 case R_386_TLS_LE_32
:
1395 info
->flags
|= DF_STATIC_TLS
;
1400 if (h
!= NULL
&& !info
->shared
)
1402 /* If this reloc is in a read-only section, we might
1403 need a copy reloc. We can't check reliably at this
1404 stage whether the section is read-only, as input
1405 sections have not yet been mapped to output sections.
1406 Tentatively set the flag for now, and correct in
1407 adjust_dynamic_symbol. */
1410 /* We may need a .plt entry if the function this reloc
1411 refers to is in a shared lib. */
1412 h
->plt
.refcount
+= 1;
1413 if (r_type
!= R_386_PC32
)
1414 h
->pointer_equality_needed
= 1;
1417 /* If we are creating a shared library, and this is a reloc
1418 against a global symbol, or a non PC relative reloc
1419 against a local symbol, then we need to copy the reloc
1420 into the shared library. However, if we are linking with
1421 -Bsymbolic, we do not need to copy a reloc against a
1422 global symbol which is defined in an object we are
1423 including in the link (i.e., DEF_REGULAR is set). At
1424 this point we have not seen all the input files, so it is
1425 possible that DEF_REGULAR is not set now but will be set
1426 later (it is never cleared). In case of a weak definition,
1427 DEF_REGULAR may be cleared later by a strong definition in
1428 a shared library. We account for that possibility below by
1429 storing information in the relocs_copied field of the hash
1430 table entry. A similar situation occurs when creating
1431 shared libraries and symbol visibility changes render the
1434 If on the other hand, we are creating an executable, we
1435 may need to keep relocations for symbols satisfied by a
1436 dynamic library if we manage to avoid copy relocs for the
1439 && (sec
->flags
& SEC_ALLOC
) != 0
1440 && (r_type
!= R_386_PC32
1442 && (! SYMBOLIC_BIND (info
, h
)
1443 || h
->root
.type
== bfd_link_hash_defweak
1444 || !h
->def_regular
))))
1445 || (ELIMINATE_COPY_RELOCS
1447 && (sec
->flags
& SEC_ALLOC
) != 0
1449 && (h
->root
.type
== bfd_link_hash_defweak
1450 || !h
->def_regular
)))
1452 struct elf_i386_dyn_relocs
*p
;
1453 struct elf_i386_dyn_relocs
**head
;
1455 /* We must copy these reloc types into the output file.
1456 Create a reloc section in dynobj and make room for
1462 unsigned int strndx
= elf_elfheader (abfd
)->e_shstrndx
;
1463 unsigned int shnam
= elf_section_data (sec
)->rel_hdr
.sh_name
;
1465 name
= bfd_elf_string_from_elf_section (abfd
, strndx
, shnam
);
1469 if (! CONST_STRNEQ (name
, ".rel")
1470 || strcmp (bfd_get_section_name (abfd
, sec
),
1473 (*_bfd_error_handler
)
1474 (_("%B: bad relocation section name `%s\'"),
1478 if (htab
->elf
.dynobj
== NULL
)
1479 htab
->elf
.dynobj
= abfd
;
1481 dynobj
= htab
->elf
.dynobj
;
1482 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1487 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1488 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1489 if ((sec
->flags
& SEC_ALLOC
) != 0)
1490 flags
|= SEC_ALLOC
| SEC_LOAD
;
1491 sreloc
= bfd_make_section_with_flags (dynobj
,
1495 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1498 elf_section_data (sec
)->sreloc
= sreloc
;
1501 /* If this is a global symbol, we count the number of
1502 relocations we need for this symbol. */
1505 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1510 /* Track dynamic relocs needed for local syms too.
1511 We really need local syms available to do this
1515 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1520 vpp
= &elf_section_data (s
)->local_dynrel
;
1521 head
= (struct elf_i386_dyn_relocs
**)vpp
;
1525 if (p
== NULL
|| p
->sec
!= sec
)
1527 bfd_size_type amt
= sizeof *p
;
1528 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
1539 if (r_type
== R_386_PC32
)
1544 /* This relocation describes the C++ object vtable hierarchy.
1545 Reconstruct it for later use during GC. */
1546 case R_386_GNU_VTINHERIT
:
1547 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1551 /* This relocation describes which C++ vtable entries are actually
1552 used. Record for later use during GC. */
1553 case R_386_GNU_VTENTRY
:
1554 BFD_ASSERT (h
!= NULL
);
1556 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1568 /* Return the section that should be marked against GC for a given
1572 elf_i386_gc_mark_hook (asection
*sec
,
1573 struct bfd_link_info
*info
,
1574 Elf_Internal_Rela
*rel
,
1575 struct elf_link_hash_entry
*h
,
1576 Elf_Internal_Sym
*sym
)
1579 switch (ELF32_R_TYPE (rel
->r_info
))
1581 case R_386_GNU_VTINHERIT
:
1582 case R_386_GNU_VTENTRY
:
1586 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1589 /* Update the got entry reference counts for the section being removed. */
1592 elf_i386_gc_sweep_hook (bfd
*abfd
,
1593 struct bfd_link_info
*info
,
1595 const Elf_Internal_Rela
*relocs
)
1597 Elf_Internal_Shdr
*symtab_hdr
;
1598 struct elf_link_hash_entry
**sym_hashes
;
1599 bfd_signed_vma
*local_got_refcounts
;
1600 const Elf_Internal_Rela
*rel
, *relend
;
1602 if (info
->relocatable
)
1605 elf_section_data (sec
)->local_dynrel
= NULL
;
1607 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1608 sym_hashes
= elf_sym_hashes (abfd
);
1609 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1611 relend
= relocs
+ sec
->reloc_count
;
1612 for (rel
= relocs
; rel
< relend
; rel
++)
1614 unsigned long r_symndx
;
1615 unsigned int r_type
;
1616 struct elf_link_hash_entry
*h
= NULL
;
1618 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1619 if (r_symndx
>= symtab_hdr
->sh_info
)
1621 struct elf_i386_link_hash_entry
*eh
;
1622 struct elf_i386_dyn_relocs
**pp
;
1623 struct elf_i386_dyn_relocs
*p
;
1625 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1626 while (h
->root
.type
== bfd_link_hash_indirect
1627 || h
->root
.type
== bfd_link_hash_warning
)
1628 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1629 eh
= (struct elf_i386_link_hash_entry
*) h
;
1631 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1634 /* Everything must go for SEC. */
1640 r_type
= ELF32_R_TYPE (rel
->r_info
);
1641 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1642 symtab_hdr
, sym_hashes
,
1643 &r_type
, GOT_UNKNOWN
,
1650 if (elf_i386_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1651 elf_i386_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1655 case R_386_TLS_GOTDESC
:
1656 case R_386_TLS_DESC_CALL
:
1657 case R_386_TLS_IE_32
:
1659 case R_386_TLS_GOTIE
:
1663 if (h
->got
.refcount
> 0)
1664 h
->got
.refcount
-= 1;
1666 else if (local_got_refcounts
!= NULL
)
1668 if (local_got_refcounts
[r_symndx
] > 0)
1669 local_got_refcounts
[r_symndx
] -= 1;
1682 if (h
->plt
.refcount
> 0)
1683 h
->plt
.refcount
-= 1;
1695 /* Adjust a symbol defined by a dynamic object and referenced by a
1696 regular object. The current definition is in some section of the
1697 dynamic object, but we're not including those sections. We have to
1698 change the definition to something the rest of the link can
1702 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1703 struct elf_link_hash_entry
*h
)
1705 struct elf_i386_link_hash_table
*htab
;
1708 /* If this is a function, put it in the procedure linkage table. We
1709 will fill in the contents of the procedure linkage table later,
1710 when we know the address of the .got section. */
1711 if (h
->type
== STT_FUNC
1714 if (h
->plt
.refcount
<= 0
1715 || SYMBOL_CALLS_LOCAL (info
, h
)
1716 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1717 && h
->root
.type
== bfd_link_hash_undefweak
))
1719 /* This case can occur if we saw a PLT32 reloc in an input
1720 file, but the symbol was never referred to by a dynamic
1721 object, or if all references were garbage collected. In
1722 such a case, we don't actually need to build a procedure
1723 linkage table, and we can just do a PC32 reloc instead. */
1724 h
->plt
.offset
= (bfd_vma
) -1;
1731 /* It's possible that we incorrectly decided a .plt reloc was
1732 needed for an R_386_PC32 reloc to a non-function sym in
1733 check_relocs. We can't decide accurately between function and
1734 non-function syms in check-relocs; Objects loaded later in
1735 the link may change h->type. So fix it now. */
1736 h
->plt
.offset
= (bfd_vma
) -1;
1738 /* If this is a weak symbol, and there is a real definition, the
1739 processor independent code will have arranged for us to see the
1740 real definition first, and we can just use the same value. */
1741 if (h
->u
.weakdef
!= NULL
)
1743 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1744 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1745 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1746 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1747 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1748 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1752 /* This is a reference to a symbol defined by a dynamic object which
1753 is not a function. */
1755 /* If we are creating a shared library, we must presume that the
1756 only references to the symbol are via the global offset table.
1757 For such cases we need not do anything here; the relocations will
1758 be handled correctly by relocate_section. */
1762 /* If there are no references to this symbol that do not use the
1763 GOT, we don't need to generate a copy reloc. */
1764 if (!h
->non_got_ref
)
1767 /* If -z nocopyreloc was given, we won't generate them either. */
1768 if (info
->nocopyreloc
)
1774 htab
= elf_i386_hash_table (info
);
1776 /* If there aren't any dynamic relocs in read-only sections, then
1777 we can keep the dynamic relocs and avoid the copy reloc. This
1778 doesn't work on VxWorks, where we can not have dynamic relocations
1779 (other than copy and jump slot relocations) in an executable. */
1780 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
1782 struct elf_i386_link_hash_entry
* eh
;
1783 struct elf_i386_dyn_relocs
*p
;
1785 eh
= (struct elf_i386_link_hash_entry
*) h
;
1786 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1788 s
= p
->sec
->output_section
;
1789 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1802 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1803 h
->root
.root
.string
);
1807 /* We must allocate the symbol in our .dynbss section, which will
1808 become part of the .bss section of the executable. There will be
1809 an entry for this symbol in the .dynsym section. The dynamic
1810 object will contain position independent code, so all references
1811 from the dynamic object to this symbol will go through the global
1812 offset table. The dynamic linker will use the .dynsym entry to
1813 determine the address it must put in the global offset table, so
1814 both the dynamic object and the regular object will refer to the
1815 same memory location for the variable. */
1817 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
1818 copy the initial value out of the dynamic object and into the
1819 runtime process image. */
1820 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1822 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
1828 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1831 /* Allocate space in .plt, .got and associated reloc sections for
1835 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1837 struct bfd_link_info
*info
;
1838 struct elf_i386_link_hash_table
*htab
;
1839 struct elf_i386_link_hash_entry
*eh
;
1840 struct elf_i386_dyn_relocs
*p
;
1842 if (h
->root
.type
== bfd_link_hash_indirect
)
1845 if (h
->root
.type
== bfd_link_hash_warning
)
1846 /* When warning symbols are created, they **replace** the "real"
1847 entry in the hash table, thus we never get to see the real
1848 symbol in a hash traversal. So look at it now. */
1849 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1851 info
= (struct bfd_link_info
*) inf
;
1852 htab
= elf_i386_hash_table (info
);
1854 if (htab
->elf
.dynamic_sections_created
1855 && h
->plt
.refcount
> 0)
1857 /* Make sure this symbol is output as a dynamic symbol.
1858 Undefined weak syms won't yet be marked as dynamic. */
1859 if (h
->dynindx
== -1
1860 && !h
->forced_local
)
1862 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1867 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1869 asection
*s
= htab
->splt
;
1871 /* If this is the first .plt entry, make room for the special
1874 s
->size
+= PLT_ENTRY_SIZE
;
1876 h
->plt
.offset
= s
->size
;
1878 /* If this symbol is not defined in a regular file, and we are
1879 not generating a shared library, then set the symbol to this
1880 location in the .plt. This is required to make function
1881 pointers compare as equal between the normal executable and
1882 the shared library. */
1886 h
->root
.u
.def
.section
= s
;
1887 h
->root
.u
.def
.value
= h
->plt
.offset
;
1890 /* Make room for this entry. */
1891 s
->size
+= PLT_ENTRY_SIZE
;
1893 /* We also need to make an entry in the .got.plt section, which
1894 will be placed in the .got section by the linker script. */
1895 htab
->sgotplt
->size
+= 4;
1897 /* We also need to make an entry in the .rel.plt section. */
1898 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1899 htab
->next_tls_desc_index
++;
1901 if (htab
->is_vxworks
&& !info
->shared
)
1903 /* VxWorks has a second set of relocations for each PLT entry
1904 in executables. They go in a separate relocation section,
1905 which is processed by the kernel loader. */
1907 /* There are two relocations for the initial PLT entry: an
1908 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
1909 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
1911 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
1912 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1914 /* There are two extra relocations for each subsequent PLT entry:
1915 an R_386_32 relocation for the GOT entry, and an R_386_32
1916 relocation for the PLT entry. */
1918 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1923 h
->plt
.offset
= (bfd_vma
) -1;
1929 h
->plt
.offset
= (bfd_vma
) -1;
1933 eh
= (struct elf_i386_link_hash_entry
*) h
;
1934 eh
->tlsdesc_got
= (bfd_vma
) -1;
1936 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
1937 make it a R_386_TLS_LE_32 requiring no TLS entry. */
1938 if (h
->got
.refcount
> 0
1941 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
1942 h
->got
.offset
= (bfd_vma
) -1;
1943 else if (h
->got
.refcount
> 0)
1947 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1949 /* Make sure this symbol is output as a dynamic symbol.
1950 Undefined weak syms won't yet be marked as dynamic. */
1951 if (h
->dynindx
== -1
1952 && !h
->forced_local
)
1954 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1959 if (GOT_TLS_GDESC_P (tls_type
))
1961 eh
->tlsdesc_got
= htab
->sgotplt
->size
1962 - elf_i386_compute_jump_table_size (htab
);
1963 htab
->sgotplt
->size
+= 8;
1964 h
->got
.offset
= (bfd_vma
) -2;
1966 if (! GOT_TLS_GDESC_P (tls_type
)
1967 || GOT_TLS_GD_P (tls_type
))
1969 h
->got
.offset
= s
->size
;
1971 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
1972 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
1975 dyn
= htab
->elf
.dynamic_sections_created
;
1976 /* R_386_TLS_IE_32 needs one dynamic relocation,
1977 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
1978 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
1979 need two), R_386_TLS_GD needs one if local symbol and two if
1981 if (tls_type
== GOT_TLS_IE_BOTH
)
1982 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1983 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
1984 || (tls_type
& GOT_TLS_IE
))
1985 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1986 else if (GOT_TLS_GD_P (tls_type
))
1987 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1988 else if (! GOT_TLS_GDESC_P (tls_type
)
1989 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1990 || h
->root
.type
!= bfd_link_hash_undefweak
)
1992 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1993 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1994 if (GOT_TLS_GDESC_P (tls_type
))
1995 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1998 h
->got
.offset
= (bfd_vma
) -1;
2000 if (eh
->dyn_relocs
== NULL
)
2003 /* In the shared -Bsymbolic case, discard space allocated for
2004 dynamic pc-relative relocs against symbols which turn out to be
2005 defined in regular objects. For the normal shared case, discard
2006 space for pc-relative relocs that have become local due to symbol
2007 visibility changes. */
2011 /* The only reloc that uses pc_count is R_386_PC32, which will
2012 appear on a call or on something like ".long foo - .". We
2013 want calls to protected symbols to resolve directly to the
2014 function rather than going via the plt. If people want
2015 function pointer comparisons to work as expected then they
2016 should avoid writing assembly like ".long foo - .". */
2017 if (SYMBOL_CALLS_LOCAL (info
, h
))
2019 struct elf_i386_dyn_relocs
**pp
;
2021 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2023 p
->count
-= p
->pc_count
;
2032 /* Also discard relocs on undefined weak syms with non-default
2034 if (eh
->dyn_relocs
!= NULL
2035 && h
->root
.type
== bfd_link_hash_undefweak
)
2037 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2038 eh
->dyn_relocs
= NULL
;
2040 /* Make sure undefined weak symbols are output as a dynamic
2042 else if (h
->dynindx
== -1
2043 && !h
->forced_local
)
2045 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2050 else if (ELIMINATE_COPY_RELOCS
)
2052 /* For the non-shared case, discard space for relocs against
2053 symbols which turn out to need copy relocs or are not
2059 || (htab
->elf
.dynamic_sections_created
2060 && (h
->root
.type
== bfd_link_hash_undefweak
2061 || h
->root
.type
== bfd_link_hash_undefined
))))
2063 /* Make sure this symbol is output as a dynamic symbol.
2064 Undefined weak syms won't yet be marked as dynamic. */
2065 if (h
->dynindx
== -1
2066 && !h
->forced_local
)
2068 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2072 /* If that succeeded, we know we'll be keeping all the
2074 if (h
->dynindx
!= -1)
2078 eh
->dyn_relocs
= NULL
;
2083 /* Finally, allocate space. */
2084 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2086 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2087 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2093 /* Find any dynamic relocs that apply to read-only sections. */
2096 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2098 struct elf_i386_link_hash_entry
*eh
;
2099 struct elf_i386_dyn_relocs
*p
;
2101 if (h
->root
.type
== bfd_link_hash_warning
)
2102 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2104 eh
= (struct elf_i386_link_hash_entry
*) h
;
2105 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2107 asection
*s
= p
->sec
->output_section
;
2109 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2111 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2113 info
->flags
|= DF_TEXTREL
;
2115 /* Not an error, just cut short the traversal. */
2122 /* Set the sizes of the dynamic sections. */
2125 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2126 struct bfd_link_info
*info
)
2128 struct elf_i386_link_hash_table
*htab
;
2134 htab
= elf_i386_hash_table (info
);
2135 dynobj
= htab
->elf
.dynobj
;
2139 if (htab
->elf
.dynamic_sections_created
)
2141 /* Set the contents of the .interp section to the interpreter. */
2142 if (info
->executable
)
2144 s
= bfd_get_section_by_name (dynobj
, ".interp");
2147 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2148 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2152 /* Set up .got offsets for local syms, and space for local dynamic
2154 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2156 bfd_signed_vma
*local_got
;
2157 bfd_signed_vma
*end_local_got
;
2158 char *local_tls_type
;
2159 bfd_vma
*local_tlsdesc_gotent
;
2160 bfd_size_type locsymcount
;
2161 Elf_Internal_Shdr
*symtab_hdr
;
2164 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2167 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2169 struct elf_i386_dyn_relocs
*p
;
2171 for (p
= ((struct elf_i386_dyn_relocs
*)
2172 elf_section_data (s
)->local_dynrel
);
2176 if (!bfd_is_abs_section (p
->sec
)
2177 && bfd_is_abs_section (p
->sec
->output_section
))
2179 /* Input section has been discarded, either because
2180 it is a copy of a linkonce section or due to
2181 linker script /DISCARD/, so we'll be discarding
2184 else if (p
->count
!= 0)
2186 srel
= elf_section_data (p
->sec
)->sreloc
;
2187 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2188 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2189 info
->flags
|= DF_TEXTREL
;
2194 local_got
= elf_local_got_refcounts (ibfd
);
2198 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2199 locsymcount
= symtab_hdr
->sh_info
;
2200 end_local_got
= local_got
+ locsymcount
;
2201 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2202 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2204 srel
= htab
->srelgot
;
2205 for (; local_got
< end_local_got
;
2206 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2208 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2211 if (GOT_TLS_GDESC_P (*local_tls_type
))
2213 *local_tlsdesc_gotent
= htab
->sgotplt
->size
2214 - elf_i386_compute_jump_table_size (htab
);
2215 htab
->sgotplt
->size
+= 8;
2216 *local_got
= (bfd_vma
) -2;
2218 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2219 || GOT_TLS_GD_P (*local_tls_type
))
2221 *local_got
= s
->size
;
2223 if (GOT_TLS_GD_P (*local_tls_type
)
2224 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2228 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2229 || (*local_tls_type
& GOT_TLS_IE
))
2231 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2232 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2233 else if (GOT_TLS_GD_P (*local_tls_type
)
2234 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2235 srel
->size
+= sizeof (Elf32_External_Rel
);
2236 if (GOT_TLS_GDESC_P (*local_tls_type
))
2237 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
2241 *local_got
= (bfd_vma
) -1;
2245 if (htab
->tls_ldm_got
.refcount
> 0)
2247 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2249 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
2250 htab
->sgot
->size
+= 8;
2251 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
2254 htab
->tls_ldm_got
.offset
= -1;
2256 /* Allocate global sym .plt and .got entries, and space for global
2257 sym dynamic relocs. */
2258 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
2260 /* For every jump slot reserved in the sgotplt, reloc_count is
2261 incremented. However, when we reserve space for TLS descriptors,
2262 it's not incremented, so in order to compute the space reserved
2263 for them, it suffices to multiply the reloc count by the jump
2266 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2268 /* We now have determined the sizes of the various dynamic sections.
2269 Allocate memory for them. */
2271 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2273 bfd_boolean strip_section
= TRUE
;
2275 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2280 || s
== htab
->sgotplt
2281 || s
== htab
->sdynbss
)
2283 /* Strip this section if we don't need it; see the
2285 /* We'd like to strip these sections if they aren't needed, but if
2286 we've exported dynamic symbols from them we must leave them.
2287 It's too late to tell BFD to get rid of the symbols. */
2289 if (htab
->elf
.hplt
!= NULL
)
2290 strip_section
= FALSE
;
2292 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2294 if (s
->size
!= 0 && s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
2297 /* We use the reloc_count field as a counter if we need
2298 to copy relocs into the output file. */
2303 /* It's not one of our sections, so don't allocate space. */
2309 /* If we don't need this section, strip it from the
2310 output file. This is mostly to handle .rel.bss and
2311 .rel.plt. We must create both sections in
2312 create_dynamic_sections, because they must be created
2313 before the linker maps input sections to output
2314 sections. The linker does that before
2315 adjust_dynamic_symbol is called, and it is that
2316 function which decides whether anything needs to go
2317 into these sections. */
2319 s
->flags
|= SEC_EXCLUDE
;
2323 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2326 /* Allocate memory for the section contents. We use bfd_zalloc
2327 here in case unused entries are not reclaimed before the
2328 section's contents are written out. This should not happen,
2329 but this way if it does, we get a R_386_NONE reloc instead
2331 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
2332 if (s
->contents
== NULL
)
2336 if (htab
->elf
.dynamic_sections_created
)
2338 /* Add some entries to the .dynamic section. We fill in the
2339 values later, in elf_i386_finish_dynamic_sections, but we
2340 must add the entries now so that we get the correct size for
2341 the .dynamic section. The DT_DEBUG entry is filled in by the
2342 dynamic linker and used by the debugger. */
2343 #define add_dynamic_entry(TAG, VAL) \
2344 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2346 if (info
->executable
)
2348 if (!add_dynamic_entry (DT_DEBUG
, 0))
2352 if (htab
->splt
->size
!= 0)
2354 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2355 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2356 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2357 || !add_dynamic_entry (DT_JMPREL
, 0))
2363 if (!add_dynamic_entry (DT_REL
, 0)
2364 || !add_dynamic_entry (DT_RELSZ
, 0)
2365 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2368 /* If any dynamic relocs apply to a read-only section,
2369 then we need a DT_TEXTREL entry. */
2370 if ((info
->flags
& DF_TEXTREL
) == 0)
2371 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2374 if ((info
->flags
& DF_TEXTREL
) != 0)
2376 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2380 if (htab
->is_vxworks
2381 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2384 #undef add_dynamic_entry
2390 elf_i386_always_size_sections (bfd
*output_bfd
,
2391 struct bfd_link_info
*info
)
2393 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2397 struct elf_link_hash_entry
*tlsbase
;
2399 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2400 "_TLS_MODULE_BASE_",
2401 FALSE
, FALSE
, FALSE
);
2403 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2405 struct bfd_link_hash_entry
*bh
= NULL
;
2406 const struct elf_backend_data
*bed
2407 = get_elf_backend_data (output_bfd
);
2409 if (!(_bfd_generic_link_add_one_symbol
2410 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2411 tls_sec
, 0, NULL
, FALSE
,
2412 bed
->collect
, &bh
)))
2414 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2415 tlsbase
->def_regular
= 1;
2416 tlsbase
->other
= STV_HIDDEN
;
2417 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2424 /* Set the correct type for an x86 ELF section. We do this by the
2425 section name, which is a hack, but ought to work. */
2428 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2429 Elf_Internal_Shdr
*hdr
,
2432 register const char *name
;
2434 name
= bfd_get_section_name (abfd
, sec
);
2436 /* This is an ugly, but unfortunately necessary hack that is
2437 needed when producing EFI binaries on x86. It tells
2438 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2439 containing ELF relocation info. We need this hack in order to
2440 be able to generate ELF binaries that can be translated into
2441 EFI applications (which are essentially COFF objects). Those
2442 files contain a COFF ".reloc" section inside an ELFNN object,
2443 which would normally cause BFD to segfault because it would
2444 attempt to interpret this section as containing relocation
2445 entries for section "oc". With this hack enabled, ".reloc"
2446 will be treated as a normal data section, which will avoid the
2447 segfault. However, you won't be able to create an ELFNN binary
2448 with a section named "oc" that needs relocations, but that's
2449 the kind of ugly side-effects you get when detecting section
2450 types based on their names... In practice, this limitation is
2451 unlikely to bite. */
2452 if (strcmp (name
, ".reloc") == 0)
2453 hdr
->sh_type
= SHT_PROGBITS
;
2458 /* Return the base VMA address which should be subtracted from real addresses
2459 when resolving @dtpoff relocation.
2460 This is PT_TLS segment p_vaddr. */
2463 dtpoff_base (struct bfd_link_info
*info
)
2465 /* If tls_sec is NULL, we should have signalled an error already. */
2466 if (elf_hash_table (info
)->tls_sec
== NULL
)
2468 return elf_hash_table (info
)->tls_sec
->vma
;
2471 /* Return the relocation value for @tpoff relocation
2472 if STT_TLS virtual address is ADDRESS. */
2475 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2477 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2479 /* If tls_sec is NULL, we should have signalled an error already. */
2480 if (htab
->tls_sec
== NULL
)
2482 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2485 /* Relocate an i386 ELF section. */
2488 elf_i386_relocate_section (bfd
*output_bfd
,
2489 struct bfd_link_info
*info
,
2491 asection
*input_section
,
2493 Elf_Internal_Rela
*relocs
,
2494 Elf_Internal_Sym
*local_syms
,
2495 asection
**local_sections
)
2497 struct elf_i386_link_hash_table
*htab
;
2498 Elf_Internal_Shdr
*symtab_hdr
;
2499 struct elf_link_hash_entry
**sym_hashes
;
2500 bfd_vma
*local_got_offsets
;
2501 bfd_vma
*local_tlsdesc_gotents
;
2502 Elf_Internal_Rela
*rel
;
2503 Elf_Internal_Rela
*relend
;
2505 htab
= elf_i386_hash_table (info
);
2506 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2507 sym_hashes
= elf_sym_hashes (input_bfd
);
2508 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2509 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2512 relend
= relocs
+ input_section
->reloc_count
;
2513 for (; rel
< relend
; rel
++)
2515 unsigned int r_type
;
2516 reloc_howto_type
*howto
;
2517 unsigned long r_symndx
;
2518 struct elf_link_hash_entry
*h
;
2519 Elf_Internal_Sym
*sym
;
2521 bfd_vma off
, offplt
;
2523 bfd_boolean unresolved_reloc
;
2524 bfd_reloc_status_type r
;
2528 r_type
= ELF32_R_TYPE (rel
->r_info
);
2529 if (r_type
== R_386_GNU_VTINHERIT
2530 || r_type
== R_386_GNU_VTENTRY
)
2533 if ((indx
= r_type
) >= R_386_standard
2534 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2535 >= R_386_ext
- R_386_standard
)
2536 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2537 >= R_386_tls
- R_386_ext
))
2539 (*_bfd_error_handler
)
2540 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2541 input_bfd
, input_section
, r_type
);
2542 bfd_set_error (bfd_error_bad_value
);
2545 howto
= elf_howto_table
+ indx
;
2547 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2551 unresolved_reloc
= FALSE
;
2552 if (r_symndx
< symtab_hdr
->sh_info
)
2554 sym
= local_syms
+ r_symndx
;
2555 sec
= local_sections
[r_symndx
];
2556 relocation
= (sec
->output_section
->vma
2557 + sec
->output_offset
2560 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2561 && ((sec
->flags
& SEC_MERGE
) != 0
2562 || (info
->relocatable
2563 && sec
->output_offset
!= 0)))
2566 bfd_byte
*where
= contents
+ rel
->r_offset
;
2568 switch (howto
->size
)
2571 addend
= bfd_get_8 (input_bfd
, where
);
2572 if (howto
->pc_relative
)
2574 addend
= (addend
^ 0x80) - 0x80;
2579 addend
= bfd_get_16 (input_bfd
, where
);
2580 if (howto
->pc_relative
)
2582 addend
= (addend
^ 0x8000) - 0x8000;
2587 addend
= bfd_get_32 (input_bfd
, where
);
2588 if (howto
->pc_relative
)
2590 addend
= (addend
^ 0x80000000) - 0x80000000;
2598 if (info
->relocatable
)
2599 addend
+= sec
->output_offset
;
2602 asection
*msec
= sec
;
2603 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2605 addend
-= relocation
;
2606 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2609 switch (howto
->size
)
2612 /* FIXME: overflow checks. */
2613 if (howto
->pc_relative
)
2615 bfd_put_8 (input_bfd
, addend
, where
);
2618 if (howto
->pc_relative
)
2620 bfd_put_16 (input_bfd
, addend
, where
);
2623 if (howto
->pc_relative
)
2625 bfd_put_32 (input_bfd
, addend
, where
);
2634 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2635 r_symndx
, symtab_hdr
, sym_hashes
,
2637 unresolved_reloc
, warned
);
2640 if (sec
!= NULL
&& elf_discarded_section (sec
))
2642 /* For relocs against symbols from removed linkonce sections,
2643 or sections discarded by a linker script, we just want the
2644 section contents zeroed. Avoid any special processing. */
2645 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2651 if (info
->relocatable
)
2657 /* Relocation is to the entry for this symbol in the global
2659 if (htab
->sgot
== NULL
)
2666 off
= h
->got
.offset
;
2667 dyn
= htab
->elf
.dynamic_sections_created
;
2668 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2670 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2671 || (ELF_ST_VISIBILITY (h
->other
)
2672 && h
->root
.type
== bfd_link_hash_undefweak
))
2674 /* This is actually a static link, or it is a
2675 -Bsymbolic link and the symbol is defined
2676 locally, or the symbol was forced to be local
2677 because of a version file. We must initialize
2678 this entry in the global offset table. Since the
2679 offset must always be a multiple of 4, we use the
2680 least significant bit to record whether we have
2681 initialized it already.
2683 When doing a dynamic link, we create a .rel.got
2684 relocation entry to initialize the value. This
2685 is done in the finish_dynamic_symbol routine. */
2690 bfd_put_32 (output_bfd
, relocation
,
2691 htab
->sgot
->contents
+ off
);
2696 unresolved_reloc
= FALSE
;
2700 if (local_got_offsets
== NULL
)
2703 off
= local_got_offsets
[r_symndx
];
2705 /* The offset must always be a multiple of 4. We use
2706 the least significant bit to record whether we have
2707 already generated the necessary reloc. */
2712 bfd_put_32 (output_bfd
, relocation
,
2713 htab
->sgot
->contents
+ off
);
2718 Elf_Internal_Rela outrel
;
2725 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2726 + htab
->sgot
->output_offset
2728 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2730 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2731 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2734 local_got_offsets
[r_symndx
] |= 1;
2738 if (off
>= (bfd_vma
) -2)
2741 relocation
= htab
->sgot
->output_section
->vma
2742 + htab
->sgot
->output_offset
+ off
2743 - htab
->sgotplt
->output_section
->vma
2744 - htab
->sgotplt
->output_offset
;
2748 /* Relocation is relative to the start of the global offset
2751 /* Check to make sure it isn't a protected function symbol
2752 for shared library since it may not be local when used
2753 as function address. */
2755 && !info
->executable
2758 && h
->type
== STT_FUNC
2759 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2761 (*_bfd_error_handler
)
2762 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
2763 input_bfd
, h
->root
.root
.string
);
2764 bfd_set_error (bfd_error_bad_value
);
2768 /* Note that sgot is not involved in this
2769 calculation. We always want the start of .got.plt. If we
2770 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2771 permitted by the ABI, we might have to change this
2773 relocation
-= htab
->sgotplt
->output_section
->vma
2774 + htab
->sgotplt
->output_offset
;
2778 /* Use global offset table as symbol value. */
2779 relocation
= htab
->sgotplt
->output_section
->vma
2780 + htab
->sgotplt
->output_offset
;
2781 unresolved_reloc
= FALSE
;
2785 /* Relocation is to the entry for this symbol in the
2786 procedure linkage table. */
2788 /* Resolve a PLT32 reloc against a local symbol directly,
2789 without using the procedure linkage table. */
2793 if (h
->plt
.offset
== (bfd_vma
) -1
2794 || htab
->splt
== NULL
)
2796 /* We didn't make a PLT entry for this symbol. This
2797 happens when statically linking PIC code, or when
2798 using -Bsymbolic. */
2802 relocation
= (htab
->splt
->output_section
->vma
2803 + htab
->splt
->output_offset
2805 unresolved_reloc
= FALSE
;
2810 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2815 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2816 || h
->root
.type
!= bfd_link_hash_undefweak
)
2817 && (r_type
!= R_386_PC32
2818 || !SYMBOL_CALLS_LOCAL (info
, h
)))
2819 || (ELIMINATE_COPY_RELOCS
2826 || h
->root
.type
== bfd_link_hash_undefweak
2827 || h
->root
.type
== bfd_link_hash_undefined
)))
2829 Elf_Internal_Rela outrel
;
2831 bfd_boolean skip
, relocate
;
2834 /* When generating a shared object, these relocations
2835 are copied into the output file to be resolved at run
2842 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2844 if (outrel
.r_offset
== (bfd_vma
) -1)
2846 else if (outrel
.r_offset
== (bfd_vma
) -2)
2847 skip
= TRUE
, relocate
= TRUE
;
2848 outrel
.r_offset
+= (input_section
->output_section
->vma
2849 + input_section
->output_offset
);
2852 memset (&outrel
, 0, sizeof outrel
);
2855 && (r_type
== R_386_PC32
2857 || !SYMBOLIC_BIND (info
, h
)
2858 || !h
->def_regular
))
2859 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2862 /* This symbol is local, or marked to become local. */
2864 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2867 sreloc
= elf_section_data (input_section
)->sreloc
;
2871 loc
= sreloc
->contents
;
2872 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2873 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2875 /* If this reloc is against an external symbol, we do
2876 not want to fiddle with the addend. Otherwise, we
2877 need to include the symbol value so that it becomes
2878 an addend for the dynamic reloc. */
2887 Elf_Internal_Rela outrel
;
2891 outrel
.r_offset
= rel
->r_offset
2892 + input_section
->output_section
->vma
2893 + input_section
->output_offset
;
2894 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2895 sreloc
= elf_section_data (input_section
)->sreloc
;
2898 loc
= sreloc
->contents
;
2899 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2900 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2905 case R_386_TLS_GOTDESC
:
2906 case R_386_TLS_DESC_CALL
:
2907 case R_386_TLS_IE_32
:
2908 case R_386_TLS_GOTIE
:
2909 tls_type
= GOT_UNKNOWN
;
2910 if (h
== NULL
&& local_got_offsets
)
2911 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
2913 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2914 if (tls_type
== GOT_TLS_IE
)
2915 tls_type
= GOT_TLS_IE_NEG
;
2917 if (! elf_i386_tls_transition (info
, input_bfd
,
2918 input_section
, contents
,
2919 symtab_hdr
, sym_hashes
,
2920 &r_type
, tls_type
, rel
,
2924 if (r_type
== R_386_TLS_LE_32
)
2926 BFD_ASSERT (! unresolved_reloc
);
2927 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
2932 /* GD->LE transition. */
2933 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2936 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
2938 movl %gs:0, %eax; subl $foo@tpoff, %eax
2939 (6 byte form of subl). */
2940 memcpy (contents
+ rel
->r_offset
- 3,
2941 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2942 roff
= rel
->r_offset
+ 5;
2946 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
2948 movl %gs:0, %eax; subl $foo@tpoff, %eax
2949 (6 byte form of subl). */
2950 memcpy (contents
+ rel
->r_offset
- 2,
2951 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2952 roff
= rel
->r_offset
+ 6;
2954 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2956 /* Skip R_386_PC32/R_386_PLT32. */
2960 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
2962 /* GDesc -> LE transition.
2963 It's originally something like:
2964 leal x@tlsdesc(%ebx), %eax
2968 Registers other than %eax may be set up here. */
2973 roff
= rel
->r_offset
;
2974 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2976 /* Now modify the instruction as appropriate. */
2977 /* aoliva FIXME: remove the above and xor the byte
2979 bfd_put_8 (output_bfd
, val
^ 0x86,
2980 contents
+ roff
- 1);
2981 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2985 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
2987 /* GDesc -> LE transition.
2995 roff
= rel
->r_offset
;
2996 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
2997 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3000 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3004 /* IE->LE transition:
3005 Originally it can be one of:
3013 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3016 /* movl foo, %eax. */
3017 bfd_put_8 (output_bfd
, 0xb8,
3018 contents
+ rel
->r_offset
- 1);
3024 type
= bfd_get_8 (input_bfd
,
3025 contents
+ rel
->r_offset
- 2);
3030 bfd_put_8 (output_bfd
, 0xc7,
3031 contents
+ rel
->r_offset
- 2);
3032 bfd_put_8 (output_bfd
,
3033 0xc0 | ((val
>> 3) & 7),
3034 contents
+ rel
->r_offset
- 1);
3038 bfd_put_8 (output_bfd
, 0x81,
3039 contents
+ rel
->r_offset
- 2);
3040 bfd_put_8 (output_bfd
,
3041 0xc0 | ((val
>> 3) & 7),
3042 contents
+ rel
->r_offset
- 1);
3049 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
3050 contents
+ rel
->r_offset
);
3055 unsigned int val
, type
;
3057 /* {IE_32,GOTIE}->LE transition:
3058 Originally it can be one of:
3059 subl foo(%reg1), %reg2
3060 movl foo(%reg1), %reg2
3061 addl foo(%reg1), %reg2
3064 movl $foo, %reg2 (6 byte form)
3065 addl $foo, %reg2. */
3066 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3067 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3071 bfd_put_8 (output_bfd
, 0xc7,
3072 contents
+ rel
->r_offset
- 2);
3073 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3074 contents
+ rel
->r_offset
- 1);
3076 else if (type
== 0x2b)
3079 bfd_put_8 (output_bfd
, 0x81,
3080 contents
+ rel
->r_offset
- 2);
3081 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3082 contents
+ rel
->r_offset
- 1);
3084 else if (type
== 0x03)
3087 bfd_put_8 (output_bfd
, 0x81,
3088 contents
+ rel
->r_offset
- 2);
3089 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3090 contents
+ rel
->r_offset
- 1);
3094 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3095 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
3096 contents
+ rel
->r_offset
);
3098 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
3099 contents
+ rel
->r_offset
);
3104 if (htab
->sgot
== NULL
)
3109 off
= h
->got
.offset
;
3110 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3114 if (local_got_offsets
== NULL
)
3117 off
= local_got_offsets
[r_symndx
];
3118 offplt
= local_tlsdesc_gotents
[r_symndx
];
3125 Elf_Internal_Rela outrel
;
3130 if (htab
->srelgot
== NULL
)
3133 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3135 if (GOT_TLS_GDESC_P (tls_type
))
3137 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3138 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3139 <= htab
->sgotplt
->size
);
3140 outrel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3141 + htab
->sgotplt
->output_offset
3143 + htab
->sgotplt_jump_table_size
);
3144 sreloc
= htab
->srelplt
;
3145 loc
= sreloc
->contents
;
3146 loc
+= (htab
->next_tls_desc_index
++
3147 * sizeof (Elf32_External_Rel
));
3148 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3149 <= sreloc
->contents
+ sreloc
->size
);
3150 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3153 BFD_ASSERT (! unresolved_reloc
);
3154 bfd_put_32 (output_bfd
,
3155 relocation
- dtpoff_base (info
),
3156 htab
->sgotplt
->contents
+ offplt
3157 + htab
->sgotplt_jump_table_size
+ 4);
3161 bfd_put_32 (output_bfd
, 0,
3162 htab
->sgotplt
->contents
+ offplt
3163 + htab
->sgotplt_jump_table_size
+ 4);
3167 sreloc
= htab
->srelgot
;
3169 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3170 + htab
->sgot
->output_offset
+ off
);
3172 if (GOT_TLS_GD_P (tls_type
))
3173 dr_type
= R_386_TLS_DTPMOD32
;
3174 else if (GOT_TLS_GDESC_P (tls_type
))
3176 else if (tls_type
== GOT_TLS_IE_POS
)
3177 dr_type
= R_386_TLS_TPOFF
;
3179 dr_type
= R_386_TLS_TPOFF32
;
3181 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3182 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3183 htab
->sgot
->contents
+ off
);
3184 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3185 bfd_put_32 (output_bfd
, dtpoff_base (info
) - relocation
,
3186 htab
->sgot
->contents
+ off
);
3187 else if (dr_type
!= R_386_TLS_DESC
)
3188 bfd_put_32 (output_bfd
, 0,
3189 htab
->sgot
->contents
+ off
);
3190 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3192 loc
= sreloc
->contents
;
3193 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3194 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3195 <= sreloc
->contents
+ sreloc
->size
);
3196 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3198 if (GOT_TLS_GD_P (tls_type
))
3202 BFD_ASSERT (! unresolved_reloc
);
3203 bfd_put_32 (output_bfd
,
3204 relocation
- dtpoff_base (info
),
3205 htab
->sgot
->contents
+ off
+ 4);
3209 bfd_put_32 (output_bfd
, 0,
3210 htab
->sgot
->contents
+ off
+ 4);
3211 outrel
.r_info
= ELF32_R_INFO (indx
,
3212 R_386_TLS_DTPOFF32
);
3213 outrel
.r_offset
+= 4;
3214 sreloc
->reloc_count
++;
3215 loc
+= sizeof (Elf32_External_Rel
);
3216 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3217 <= sreloc
->contents
+ sreloc
->size
);
3218 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3221 else if (tls_type
== GOT_TLS_IE_BOTH
)
3223 bfd_put_32 (output_bfd
,
3224 indx
== 0 ? relocation
- dtpoff_base (info
) : 0,
3225 htab
->sgot
->contents
+ off
+ 4);
3226 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3227 outrel
.r_offset
+= 4;
3228 sreloc
->reloc_count
++;
3229 loc
+= sizeof (Elf32_External_Rel
);
3230 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3237 local_got_offsets
[r_symndx
] |= 1;
3240 if (off
>= (bfd_vma
) -2
3241 && ! GOT_TLS_GDESC_P (tls_type
))
3243 if (r_type
== R_386_TLS_GOTDESC
3244 || r_type
== R_386_TLS_DESC_CALL
)
3246 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3247 unresolved_reloc
= FALSE
;
3249 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3251 bfd_vma g_o_t
= htab
->sgotplt
->output_section
->vma
3252 + htab
->sgotplt
->output_offset
;
3253 relocation
= htab
->sgot
->output_section
->vma
3254 + htab
->sgot
->output_offset
+ off
- g_o_t
;
3255 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3256 && tls_type
== GOT_TLS_IE_BOTH
)
3258 if (r_type
== R_386_TLS_IE
)
3259 relocation
+= g_o_t
;
3260 unresolved_reloc
= FALSE
;
3262 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3264 unsigned int val
, type
;
3267 /* GD->IE transition. */
3268 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3269 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3272 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3274 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3276 roff
= rel
->r_offset
- 3;
3280 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3282 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3283 roff
= rel
->r_offset
- 2;
3285 memcpy (contents
+ roff
,
3286 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3287 contents
[roff
+ 7] = 0x80 | (val
& 7);
3288 /* If foo is used only with foo@gotntpoff(%reg) and
3289 foo@indntpoff, but not with foo@gottpoff(%reg), change
3290 subl $foo@gottpoff(%reg), %eax
3292 addl $foo@gotntpoff(%reg), %eax. */
3293 if (tls_type
== GOT_TLS_IE_POS
)
3294 contents
[roff
+ 6] = 0x03;
3295 bfd_put_32 (output_bfd
,
3296 htab
->sgot
->output_section
->vma
3297 + htab
->sgot
->output_offset
+ off
3298 - htab
->sgotplt
->output_section
->vma
3299 - htab
->sgotplt
->output_offset
,
3300 contents
+ roff
+ 8);
3301 /* Skip R_386_PLT32. */
3305 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3307 /* GDesc -> IE transition.
3308 It's originally something like:
3309 leal x@tlsdesc(%ebx), %eax
3312 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3314 movl x@gottpoff(%ebx), %eax # before negl %eax
3316 Registers other than %eax may be set up here. */
3320 /* First, make sure it's a leal adding ebx to a 32-bit
3321 offset into any register, although it's probably
3322 almost always going to be eax. */
3323 roff
= rel
->r_offset
;
3325 /* Now modify the instruction as appropriate. */
3326 /* To turn a leal into a movl in the form we use it, it
3327 suffices to change the first byte from 0x8d to 0x8b.
3328 aoliva FIXME: should we decide to keep the leal, all
3329 we have to do is remove the statement below, and
3330 adjust the relaxation of R_386_TLS_DESC_CALL. */
3331 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3333 if (tls_type
== GOT_TLS_IE_BOTH
)
3336 bfd_put_32 (output_bfd
,
3337 htab
->sgot
->output_section
->vma
3338 + htab
->sgot
->output_offset
+ off
3339 - htab
->sgotplt
->output_section
->vma
3340 - htab
->sgotplt
->output_offset
,
3344 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3346 /* GDesc -> IE transition.
3354 depending on how we transformed the TLS_GOTDESC above.
3359 roff
= rel
->r_offset
;
3361 /* Now modify the instruction as appropriate. */
3362 if (tls_type
!= GOT_TLS_IE_NEG
)
3365 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3366 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3371 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3372 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3382 if (! elf_i386_tls_transition (info
, input_bfd
,
3383 input_section
, contents
,
3384 symtab_hdr
, sym_hashes
,
3385 &r_type
, GOT_UNKNOWN
, rel
,
3389 if (r_type
!= R_386_TLS_LDM
)
3391 /* LD->LE transition:
3392 leal foo(%reg), %eax; call ___tls_get_addr.
3394 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3395 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3396 memcpy (contents
+ rel
->r_offset
- 2,
3397 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3398 /* Skip R_386_PC32/R_386_PLT32. */
3403 if (htab
->sgot
== NULL
)
3406 off
= htab
->tls_ldm_got
.offset
;
3411 Elf_Internal_Rela outrel
;
3414 if (htab
->srelgot
== NULL
)
3417 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3418 + htab
->sgot
->output_offset
+ off
);
3420 bfd_put_32 (output_bfd
, 0,
3421 htab
->sgot
->contents
+ off
);
3422 bfd_put_32 (output_bfd
, 0,
3423 htab
->sgot
->contents
+ off
+ 4);
3424 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3425 loc
= htab
->srelgot
->contents
;
3426 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3427 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3428 htab
->tls_ldm_got
.offset
|= 1;
3430 relocation
= htab
->sgot
->output_section
->vma
3431 + htab
->sgot
->output_offset
+ off
3432 - htab
->sgotplt
->output_section
->vma
3433 - htab
->sgotplt
->output_offset
;
3434 unresolved_reloc
= FALSE
;
3437 case R_386_TLS_LDO_32
:
3438 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3439 relocation
-= dtpoff_base (info
);
3441 /* When converting LDO to LE, we must negate. */
3442 relocation
= -tpoff (info
, relocation
);
3445 case R_386_TLS_LE_32
:
3449 Elf_Internal_Rela outrel
;
3454 outrel
.r_offset
= rel
->r_offset
3455 + input_section
->output_section
->vma
3456 + input_section
->output_offset
;
3457 if (h
!= NULL
&& h
->dynindx
!= -1)
3461 if (r_type
== R_386_TLS_LE_32
)
3462 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3464 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3465 sreloc
= elf_section_data (input_section
)->sreloc
;
3468 loc
= sreloc
->contents
;
3469 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3470 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3473 else if (r_type
== R_386_TLS_LE_32
)
3474 relocation
= dtpoff_base (info
) - relocation
;
3476 relocation
-= dtpoff_base (info
);
3478 else if (r_type
== R_386_TLS_LE_32
)
3479 relocation
= tpoff (info
, relocation
);
3481 relocation
= -tpoff (info
, relocation
);
3488 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3489 because such sections are not SEC_ALLOC and thus ld.so will
3490 not process them. */
3491 if (unresolved_reloc
3492 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3495 (*_bfd_error_handler
)
3496 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3499 (long) rel
->r_offset
,
3501 h
->root
.root
.string
);
3505 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3506 contents
, rel
->r_offset
,
3509 if (r
!= bfd_reloc_ok
)
3514 name
= h
->root
.root
.string
;
3517 name
= bfd_elf_string_from_elf_section (input_bfd
,
3518 symtab_hdr
->sh_link
,
3523 name
= bfd_section_name (input_bfd
, sec
);
3526 if (r
== bfd_reloc_overflow
)
3528 if (! ((*info
->callbacks
->reloc_overflow
)
3529 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3530 (bfd_vma
) 0, input_bfd
, input_section
,
3536 (*_bfd_error_handler
)
3537 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3538 input_bfd
, input_section
,
3539 (long) rel
->r_offset
, name
, (int) r
);
3548 /* Finish up dynamic symbol handling. We set the contents of various
3549 dynamic sections here. */
3552 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3553 struct bfd_link_info
*info
,
3554 struct elf_link_hash_entry
*h
,
3555 Elf_Internal_Sym
*sym
)
3557 struct elf_i386_link_hash_table
*htab
;
3559 htab
= elf_i386_hash_table (info
);
3561 if (h
->plt
.offset
!= (bfd_vma
) -1)
3565 Elf_Internal_Rela rel
;
3568 /* This symbol has an entry in the procedure linkage table. Set
3571 if (h
->dynindx
== -1
3572 || htab
->splt
== NULL
3573 || htab
->sgotplt
== NULL
3574 || htab
->srelplt
== NULL
)
3577 /* Get the index in the procedure linkage table which
3578 corresponds to this symbol. This is the index of this symbol
3579 in all the symbols for which we are making plt entries. The
3580 first entry in the procedure linkage table is reserved. */
3581 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3583 /* Get the offset into the .got table of the entry that
3584 corresponds to this function. Each .got entry is 4 bytes.
3585 The first three are reserved. */
3586 got_offset
= (plt_index
+ 3) * 4;
3588 /* Fill in the entry in the procedure linkage table. */
3591 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
3593 bfd_put_32 (output_bfd
,
3594 (htab
->sgotplt
->output_section
->vma
3595 + htab
->sgotplt
->output_offset
3597 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3599 if (htab
->is_vxworks
)
3601 int s
, k
, reloc_index
;
3603 /* Create the R_386_32 relocation referencing the GOT
3604 for this PLT entry. */
3606 /* S: Current slot number (zero-based). */
3607 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3608 /* K: Number of relocations for PLTResolve. */
3610 k
= PLTRESOLVE_RELOCS_SHLIB
;
3612 k
= PLTRESOLVE_RELOCS
;
3613 /* Skip the PLTresolve relocations, and the relocations for
3614 the other PLT slots. */
3615 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3616 loc
= (htab
->srelplt2
->contents
+ reloc_index
3617 * sizeof (Elf32_External_Rel
));
3619 rel
.r_offset
= (htab
->splt
->output_section
->vma
3620 + htab
->splt
->output_offset
3621 + h
->plt
.offset
+ 2),
3622 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3623 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3625 /* Create the R_386_32 relocation referencing the beginning of
3626 the PLT for this GOT entry. */
3627 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3628 + htab
->sgotplt
->output_offset
3630 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3631 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3632 loc
+ sizeof (Elf32_External_Rel
));
3637 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
3639 bfd_put_32 (output_bfd
, got_offset
,
3640 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3643 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
3644 htab
->splt
->contents
+ h
->plt
.offset
+ 7);
3645 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
3646 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3648 /* Fill in the entry in the global offset table. */
3649 bfd_put_32 (output_bfd
,
3650 (htab
->splt
->output_section
->vma
3651 + htab
->splt
->output_offset
3654 htab
->sgotplt
->contents
+ got_offset
);
3656 /* Fill in the entry in the .rel.plt section. */
3657 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3658 + htab
->sgotplt
->output_offset
3660 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3661 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3662 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3664 if (!h
->def_regular
)
3666 /* Mark the symbol as undefined, rather than as defined in
3667 the .plt section. Leave the value if there were any
3668 relocations where pointer equality matters (this is a clue
3669 for the dynamic linker, to make function pointer
3670 comparisons work between an application and shared
3671 library), otherwise set it to zero. If a function is only
3672 called from a binary, there is no need to slow down
3673 shared libraries because of that. */
3674 sym
->st_shndx
= SHN_UNDEF
;
3675 if (!h
->pointer_equality_needed
)
3680 if (h
->got
.offset
!= (bfd_vma
) -1
3681 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
3682 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
3684 Elf_Internal_Rela rel
;
3687 /* This symbol has an entry in the global offset table. Set it
3690 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3693 rel
.r_offset
= (htab
->sgot
->output_section
->vma
3694 + htab
->sgot
->output_offset
3695 + (h
->got
.offset
& ~(bfd_vma
) 1));
3697 /* If this is a static link, or it is a -Bsymbolic link and the
3698 symbol is defined locally or was forced to be local because
3699 of a version file, we just want to emit a RELATIVE reloc.
3700 The entry in the global offset table will already have been
3701 initialized in the relocate_section function. */
3703 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3705 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3706 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3710 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3711 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3712 htab
->sgot
->contents
+ h
->got
.offset
);
3713 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3716 loc
= htab
->srelgot
->contents
;
3717 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3718 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3723 Elf_Internal_Rela rel
;
3726 /* This symbol needs a copy reloc. Set it up. */
3728 if (h
->dynindx
== -1
3729 || (h
->root
.type
!= bfd_link_hash_defined
3730 && h
->root
.type
!= bfd_link_hash_defweak
)
3731 || htab
->srelbss
== NULL
)
3734 rel
.r_offset
= (h
->root
.u
.def
.value
3735 + h
->root
.u
.def
.section
->output_section
->vma
3736 + h
->root
.u
.def
.section
->output_offset
);
3737 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
3738 loc
= htab
->srelbss
->contents
;
3739 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3740 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3743 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.
3744 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
3745 is relative to the ".got" section. */
3746 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3747 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
))
3748 sym
->st_shndx
= SHN_ABS
;
3753 /* Used to decide how to sort relocs in an optimal manner for the
3754 dynamic linker, before writing them out. */
3756 static enum elf_reloc_type_class
3757 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
3759 switch (ELF32_R_TYPE (rela
->r_info
))
3761 case R_386_RELATIVE
:
3762 return reloc_class_relative
;
3763 case R_386_JUMP_SLOT
:
3764 return reloc_class_plt
;
3766 return reloc_class_copy
;
3768 return reloc_class_normal
;
3772 /* Finish up the dynamic sections. */
3775 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
3776 struct bfd_link_info
*info
)
3778 struct elf_i386_link_hash_table
*htab
;
3782 htab
= elf_i386_hash_table (info
);
3783 dynobj
= htab
->elf
.dynobj
;
3784 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3786 if (htab
->elf
.dynamic_sections_created
)
3788 Elf32_External_Dyn
*dyncon
, *dynconend
;
3790 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3793 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3794 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3795 for (; dyncon
< dynconend
; dyncon
++)
3797 Elf_Internal_Dyn dyn
;
3800 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3805 if (htab
->is_vxworks
3806 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
3812 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3817 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3822 dyn
.d_un
.d_val
= s
->size
;
3826 /* My reading of the SVR4 ABI indicates that the
3827 procedure linkage table relocs (DT_JMPREL) should be
3828 included in the overall relocs (DT_REL). This is
3829 what Solaris does. However, UnixWare can not handle
3830 that case. Therefore, we override the DT_RELSZ entry
3831 here to make it not include the JMPREL relocs. */
3835 dyn
.d_un
.d_val
-= s
->size
;
3839 /* We may not be using the standard ELF linker script.
3840 If .rel.plt is the first .rel section, we adjust
3841 DT_REL to not include it. */
3845 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
3847 dyn
.d_un
.d_ptr
+= s
->size
;
3851 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3854 /* Fill in the first entry in the procedure linkage table. */
3855 if (htab
->splt
&& htab
->splt
->size
> 0)
3859 memcpy (htab
->splt
->contents
, elf_i386_pic_plt0_entry
,
3860 sizeof (elf_i386_pic_plt0_entry
));
3861 memset (htab
->splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
3862 htab
->plt0_pad_byte
,
3863 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
3867 memcpy (htab
->splt
->contents
, elf_i386_plt0_entry
,
3868 sizeof(elf_i386_plt0_entry
));
3869 memset (htab
->splt
->contents
+ sizeof (elf_i386_plt0_entry
),
3870 htab
->plt0_pad_byte
,
3871 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
3872 bfd_put_32 (output_bfd
,
3873 (htab
->sgotplt
->output_section
->vma
3874 + htab
->sgotplt
->output_offset
3876 htab
->splt
->contents
+ 2);
3877 bfd_put_32 (output_bfd
,
3878 (htab
->sgotplt
->output_section
->vma
3879 + htab
->sgotplt
->output_offset
3881 htab
->splt
->contents
+ 8);
3883 if (htab
->is_vxworks
)
3885 Elf_Internal_Rela rel
;
3887 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
3888 On IA32 we use REL relocations so the addend goes in
3889 the PLT directly. */
3890 rel
.r_offset
= (htab
->splt
->output_section
->vma
3891 + htab
->splt
->output_offset
3893 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3894 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3895 htab
->srelplt2
->contents
);
3896 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
3897 rel
.r_offset
= (htab
->splt
->output_section
->vma
3898 + htab
->splt
->output_offset
3900 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3901 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3902 htab
->srelplt2
->contents
+
3903 sizeof (Elf32_External_Rel
));
3907 /* UnixWare sets the entsize of .plt to 4, although that doesn't
3908 really seem like the right value. */
3909 elf_section_data (htab
->splt
->output_section
)
3910 ->this_hdr
.sh_entsize
= 4;
3912 /* Correct the .rel.plt.unloaded relocations. */
3913 if (htab
->is_vxworks
&& !info
->shared
)
3915 int num_plts
= (htab
->splt
->size
/ PLT_ENTRY_SIZE
) - 1;
3918 p
= htab
->srelplt2
->contents
;
3920 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
3922 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
3924 for (; num_plts
; num_plts
--)
3926 Elf_Internal_Rela rel
;
3927 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3928 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3929 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3930 p
+= sizeof (Elf32_External_Rel
);
3932 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3933 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3934 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3935 p
+= sizeof (Elf32_External_Rel
);
3943 /* Fill in the first three entries in the global offset table. */
3944 if (htab
->sgotplt
->size
> 0)
3946 bfd_put_32 (output_bfd
,
3948 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
3949 htab
->sgotplt
->contents
);
3950 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 4);
3951 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 8);
3954 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
3957 if (htab
->sgot
&& htab
->sgot
->size
> 0)
3958 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
3963 /* Return address for Ith PLT stub in section PLT, for relocation REL
3964 or (bfd_vma) -1 if it should not be included. */
3967 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
3968 const arelent
*rel ATTRIBUTE_UNUSED
)
3970 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3973 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3976 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
3978 if (h
->plt
.offset
!= (bfd_vma
) -1
3980 && !h
->pointer_equality_needed
)
3983 return _bfd_elf_hash_symbol (h
);
3986 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
3987 #define TARGET_LITTLE_NAME "elf32-i386"
3988 #define ELF_ARCH bfd_arch_i386
3989 #define ELF_MACHINE_CODE EM_386
3990 #define ELF_MAXPAGESIZE 0x1000
3992 #define elf_backend_can_gc_sections 1
3993 #define elf_backend_can_refcount 1
3994 #define elf_backend_want_got_plt 1
3995 #define elf_backend_plt_readonly 1
3996 #define elf_backend_want_plt_sym 0
3997 #define elf_backend_got_header_size 12
3999 /* Support RELA for objdump of prelink objects. */
4000 #define elf_info_to_howto elf_i386_info_to_howto_rel
4001 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4003 #define bfd_elf32_mkobject elf_i386_mkobject
4005 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4006 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4007 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4008 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4010 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4011 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4012 #define elf_backend_check_relocs elf_i386_check_relocs
4013 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4014 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4015 #define elf_backend_fake_sections elf_i386_fake_sections
4016 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4017 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4018 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4019 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4020 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4021 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4022 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4023 #define elf_backend_relocate_section elf_i386_relocate_section
4024 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4025 #define elf_backend_always_size_sections elf_i386_always_size_sections
4026 #define elf_backend_omit_section_dynsym \
4027 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4028 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4029 #define elf_backend_hash_symbol elf_i386_hash_symbol
4031 #include "elf32-target.h"
4033 /* FreeBSD support. */
4035 #undef TARGET_LITTLE_SYM
4036 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4037 #undef TARGET_LITTLE_NAME
4038 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4040 #define ELF_OSABI ELFOSABI_FREEBSD
4042 /* The kernel recognizes executables as valid only if they carry a
4043 "FreeBSD" label in the ELF header. So we put this label on all
4044 executables and (for simplicity) also all other object files. */
4047 elf_i386_post_process_headers (bfd
*abfd
,
4048 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4050 Elf_Internal_Ehdr
*i_ehdrp
;
4052 i_ehdrp
= elf_elfheader (abfd
);
4054 /* Put an ABI label supported by FreeBSD >= 4.1. */
4055 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
4056 #ifdef OLD_FREEBSD_ABI_LABEL
4057 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4058 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4062 #undef elf_backend_post_process_headers
4063 #define elf_backend_post_process_headers elf_i386_post_process_headers
4065 #define elf32_bed elf32_i386_fbsd_bed
4067 #include "elf32-target.h"
4069 /* VxWorks support. */
4071 #undef TARGET_LITTLE_SYM
4072 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
4073 #undef TARGET_LITTLE_NAME
4074 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4077 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
4079 static struct bfd_link_hash_table
*
4080 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
4082 struct bfd_link_hash_table
*ret
;
4083 struct elf_i386_link_hash_table
*htab
;
4085 ret
= elf_i386_link_hash_table_create (abfd
);
4088 htab
= (struct elf_i386_link_hash_table
*) ret
;
4089 htab
->is_vxworks
= 1;
4090 htab
->plt0_pad_byte
= 0x90;
4097 #undef elf_backend_relocs_compatible
4098 #undef elf_backend_post_process_headers
4099 #undef bfd_elf32_bfd_link_hash_table_create
4100 #define bfd_elf32_bfd_link_hash_table_create \
4101 elf_i386_vxworks_link_hash_table_create
4102 #undef elf_backend_add_symbol_hook
4103 #define elf_backend_add_symbol_hook \
4104 elf_vxworks_add_symbol_hook
4105 #undef elf_backend_link_output_symbol_hook
4106 #define elf_backend_link_output_symbol_hook \
4107 elf_vxworks_link_output_symbol_hook
4108 #undef elf_backend_emit_relocs
4109 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
4110 #undef elf_backend_final_write_processing
4111 #define elf_backend_final_write_processing \
4112 elf_vxworks_final_write_processing
4114 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
4116 #undef elf_backend_want_plt_sym
4117 #define elf_backend_want_plt_sym 1
4120 #define elf32_bed elf32_i386_vxworks_bed
4122 #include "elf32-target.h"