1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
28 #include "bfd_stdint.h"
32 /* 386 uses REL relocations instead of RELA. */
37 static reloc_howto_type elf_howto_table
[]=
39 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
40 bfd_elf_generic_reloc
, "R_386_NONE",
41 TRUE
, 0x00000000, 0x00000000, FALSE
),
42 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
43 bfd_elf_generic_reloc
, "R_386_32",
44 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
45 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
46 bfd_elf_generic_reloc
, "R_386_PC32",
47 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
48 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
49 bfd_elf_generic_reloc
, "R_386_GOT32",
50 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
51 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
52 bfd_elf_generic_reloc
, "R_386_PLT32",
53 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
54 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
55 bfd_elf_generic_reloc
, "R_386_COPY",
56 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
57 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
58 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
59 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
60 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
61 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
62 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
63 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_386_RELATIVE",
65 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
66 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_386_GOTOFF",
68 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
69 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
70 bfd_elf_generic_reloc
, "R_386_GOTPC",
71 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
73 /* We have a gap in the reloc numbers here.
74 R_386_standard counts the number up to this point, and
75 R_386_ext_offset is the value to subtract from a reloc type of
76 R_386_16 thru R_386_PC8 to form an index into this table. */
77 #define R_386_standard (R_386_GOTPC + 1)
78 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
80 /* These relocs are a GNU extension. */
81 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
82 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
83 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
84 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_386_TLS_IE",
86 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
87 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
89 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
90 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
91 bfd_elf_generic_reloc
, "R_386_TLS_LE",
92 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
93 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
94 bfd_elf_generic_reloc
, "R_386_TLS_GD",
95 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
96 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
98 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
99 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
100 bfd_elf_generic_reloc
, "R_386_16",
101 TRUE
, 0xffff, 0xffff, FALSE
),
102 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_386_PC16",
104 TRUE
, 0xffff, 0xffff, TRUE
),
105 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_386_8",
107 TRUE
, 0xff, 0xff, FALSE
),
108 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
109 bfd_elf_generic_reloc
, "R_386_PC8",
110 TRUE
, 0xff, 0xff, TRUE
),
112 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
113 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
114 /* These are common with Solaris TLS implementation. */
115 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
116 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
117 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
118 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
119 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
120 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
121 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
122 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
123 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
124 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
125 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
126 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
127 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
129 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
130 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
131 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
132 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
135 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
136 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
137 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
138 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
140 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
141 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
142 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
143 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
148 #define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
149 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
151 /* GNU extension to record C++ vtable hierarchy. */
152 HOWTO (R_386_GNU_VTINHERIT
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_dont
, /* complain_on_overflow */
159 NULL
, /* special_function */
160 "R_386_GNU_VTINHERIT", /* name */
161 FALSE
, /* partial_inplace */
164 FALSE
), /* pcrel_offset */
166 /* GNU extension to record C++ vtable member usage. */
167 HOWTO (R_386_GNU_VTENTRY
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE
, /* pc_relative */
173 complain_overflow_dont
, /* complain_on_overflow */
174 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
175 "R_386_GNU_VTENTRY", /* name */
176 FALSE
, /* partial_inplace */
179 FALSE
) /* pcrel_offset */
181 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
185 #ifdef DEBUG_GEN_RELOC
187 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
192 static reloc_howto_type
*
193 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
194 bfd_reloc_code_real_type code
)
199 TRACE ("BFD_RELOC_NONE");
200 return &elf_howto_table
[R_386_NONE
];
203 TRACE ("BFD_RELOC_32");
204 return &elf_howto_table
[R_386_32
];
207 TRACE ("BFD_RELOC_CTOR");
208 return &elf_howto_table
[R_386_32
];
210 case BFD_RELOC_32_PCREL
:
211 TRACE ("BFD_RELOC_PC32");
212 return &elf_howto_table
[R_386_PC32
];
214 case BFD_RELOC_386_GOT32
:
215 TRACE ("BFD_RELOC_386_GOT32");
216 return &elf_howto_table
[R_386_GOT32
];
218 case BFD_RELOC_386_PLT32
:
219 TRACE ("BFD_RELOC_386_PLT32");
220 return &elf_howto_table
[R_386_PLT32
];
222 case BFD_RELOC_386_COPY
:
223 TRACE ("BFD_RELOC_386_COPY");
224 return &elf_howto_table
[R_386_COPY
];
226 case BFD_RELOC_386_GLOB_DAT
:
227 TRACE ("BFD_RELOC_386_GLOB_DAT");
228 return &elf_howto_table
[R_386_GLOB_DAT
];
230 case BFD_RELOC_386_JUMP_SLOT
:
231 TRACE ("BFD_RELOC_386_JUMP_SLOT");
232 return &elf_howto_table
[R_386_JUMP_SLOT
];
234 case BFD_RELOC_386_RELATIVE
:
235 TRACE ("BFD_RELOC_386_RELATIVE");
236 return &elf_howto_table
[R_386_RELATIVE
];
238 case BFD_RELOC_386_GOTOFF
:
239 TRACE ("BFD_RELOC_386_GOTOFF");
240 return &elf_howto_table
[R_386_GOTOFF
];
242 case BFD_RELOC_386_GOTPC
:
243 TRACE ("BFD_RELOC_386_GOTPC");
244 return &elf_howto_table
[R_386_GOTPC
];
246 /* These relocs are a GNU extension. */
247 case BFD_RELOC_386_TLS_TPOFF
:
248 TRACE ("BFD_RELOC_386_TLS_TPOFF");
249 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
251 case BFD_RELOC_386_TLS_IE
:
252 TRACE ("BFD_RELOC_386_TLS_IE");
253 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
255 case BFD_RELOC_386_TLS_GOTIE
:
256 TRACE ("BFD_RELOC_386_TLS_GOTIE");
257 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
259 case BFD_RELOC_386_TLS_LE
:
260 TRACE ("BFD_RELOC_386_TLS_LE");
261 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
263 case BFD_RELOC_386_TLS_GD
:
264 TRACE ("BFD_RELOC_386_TLS_GD");
265 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
267 case BFD_RELOC_386_TLS_LDM
:
268 TRACE ("BFD_RELOC_386_TLS_LDM");
269 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
272 TRACE ("BFD_RELOC_16");
273 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
275 case BFD_RELOC_16_PCREL
:
276 TRACE ("BFD_RELOC_16_PCREL");
277 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
280 TRACE ("BFD_RELOC_8");
281 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
283 case BFD_RELOC_8_PCREL
:
284 TRACE ("BFD_RELOC_8_PCREL");
285 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
287 /* Common with Sun TLS implementation. */
288 case BFD_RELOC_386_TLS_LDO_32
:
289 TRACE ("BFD_RELOC_386_TLS_LDO_32");
290 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
292 case BFD_RELOC_386_TLS_IE_32
:
293 TRACE ("BFD_RELOC_386_TLS_IE_32");
294 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
296 case BFD_RELOC_386_TLS_LE_32
:
297 TRACE ("BFD_RELOC_386_TLS_LE_32");
298 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
300 case BFD_RELOC_386_TLS_DTPMOD32
:
301 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
302 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
304 case BFD_RELOC_386_TLS_DTPOFF32
:
305 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
306 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
308 case BFD_RELOC_386_TLS_TPOFF32
:
309 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
310 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
312 case BFD_RELOC_386_TLS_GOTDESC
:
313 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
314 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
316 case BFD_RELOC_386_TLS_DESC_CALL
:
317 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
318 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
320 case BFD_RELOC_386_TLS_DESC
:
321 TRACE ("BFD_RELOC_386_TLS_DESC");
322 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
324 case BFD_RELOC_386_IRELATIVE
:
325 TRACE ("BFD_RELOC_386_IRELATIVE");
326 return &elf_howto_table
[R_386_IRELATIVE
];
328 case BFD_RELOC_VTABLE_INHERIT
:
329 TRACE ("BFD_RELOC_VTABLE_INHERIT");
330 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
332 case BFD_RELOC_VTABLE_ENTRY
:
333 TRACE ("BFD_RELOC_VTABLE_ENTRY");
334 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
344 static reloc_howto_type
*
345 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
350 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
351 if (elf_howto_table
[i
].name
!= NULL
352 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
353 return &elf_howto_table
[i
];
358 static reloc_howto_type
*
359 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
363 if ((indx
= r_type
) >= R_386_standard
364 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
365 >= R_386_ext
- R_386_standard
)
366 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
367 >= R_386_irelative
- R_386_ext
)
368 && ((indx
= r_type
- R_386_vt_offset
) - R_386_irelative
369 >= R_386_vt
- R_386_irelative
))
371 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
375 BFD_ASSERT (elf_howto_table
[indx
].type
== r_type
);
376 return &elf_howto_table
[indx
];
380 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
382 Elf_Internal_Rela
*dst
)
384 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
385 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
388 /* Return whether a symbol name implies a local label. The UnixWare
389 2.1 cc generates temporary symbols that start with .X, so we
390 recognize them here. FIXME: do other SVR4 compilers also use .X?.
391 If so, we should move the .X recognition into
392 _bfd_elf_is_local_label_name. */
395 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
397 if (name
[0] == '.' && name
[1] == 'X')
400 return _bfd_elf_is_local_label_name (abfd
, name
);
403 /* Support for core dump NOTE sections. */
406 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
411 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
413 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
419 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
422 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
426 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
430 switch (note
->descsz
)
435 case 144: /* Linux/i386 */
437 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
440 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
450 /* Make a ".reg/999" section. */
451 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
452 size
, note
->descpos
+ offset
);
456 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
458 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
460 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
465 elf_tdata (abfd
)->core_program
466 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
467 elf_tdata (abfd
)->core_command
468 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
472 switch (note
->descsz
)
477 case 124: /* Linux/i386 elf_prpsinfo. */
478 elf_tdata (abfd
)->core_pid
479 = bfd_get_32 (abfd
, note
->descdata
+ 12);
480 elf_tdata (abfd
)->core_program
481 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
482 elf_tdata (abfd
)->core_command
483 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
487 /* Note that for some reason, a spurious space is tacked
488 onto the end of the args in some (at least one anyway)
489 implementations, so strip it off if it exists. */
491 char *command
= elf_tdata (abfd
)->core_command
;
492 int n
= strlen (command
);
494 if (0 < n
&& command
[n
- 1] == ' ')
495 command
[n
- 1] = '\0';
501 /* Functions for the i386 ELF linker.
503 In order to gain some understanding of code in this file without
504 knowing all the intricate details of the linker, note the
507 Functions named elf_i386_* are called by external routines, other
508 functions are only called locally. elf_i386_* functions appear
509 in this file more or less in the order in which they are called
510 from external routines. eg. elf_i386_check_relocs is called
511 early in the link process, elf_i386_finish_dynamic_sections is
512 one of the last functions. */
515 /* The name of the dynamic interpreter. This is put in the .interp
518 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
520 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
521 copying dynamic variables from a shared lib into an app's dynbss
522 section, and instead use a dynamic relocation to point into the
524 #define ELIMINATE_COPY_RELOCS 1
526 /* The size in bytes of an entry in the procedure linkage table. */
528 #define PLT_ENTRY_SIZE 16
530 /* The first entry in an absolute procedure linkage table looks like
531 this. See the SVR4 ABI i386 supplement to see how this works.
532 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
534 static const bfd_byte elf_i386_plt0_entry
[12] =
536 0xff, 0x35, /* pushl contents of address */
537 0, 0, 0, 0, /* replaced with address of .got + 4. */
538 0xff, 0x25, /* jmp indirect */
539 0, 0, 0, 0 /* replaced with address of .got + 8. */
542 /* Subsequent entries in an absolute procedure linkage table look like
545 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
547 0xff, 0x25, /* jmp indirect */
548 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
549 0x68, /* pushl immediate */
550 0, 0, 0, 0, /* replaced with offset into relocation table. */
551 0xe9, /* jmp relative */
552 0, 0, 0, 0 /* replaced with offset to start of .plt. */
555 /* The first entry in a PIC procedure linkage table look like this.
556 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
558 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
560 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
561 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
564 /* Subsequent entries in a PIC procedure linkage table look like this. */
566 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
568 0xff, 0xa3, /* jmp *offset(%ebx) */
569 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
570 0x68, /* pushl immediate */
571 0, 0, 0, 0, /* replaced with offset into relocation table. */
572 0xe9, /* jmp relative */
573 0, 0, 0, 0 /* replaced with offset to start of .plt. */
576 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
577 for the PLTResolve stub and then for each PLT entry. */
578 #define PLTRESOLVE_RELOCS_SHLIB 0
579 #define PLTRESOLVE_RELOCS 2
580 #define PLT_NON_JUMP_SLOT_RELOCS 2
582 /* i386 ELF linker hash entry. */
584 struct elf_i386_link_hash_entry
586 struct elf_link_hash_entry elf
;
588 /* Track dynamic relocs copied for this symbol. */
589 struct elf_dyn_relocs
*dyn_relocs
;
591 #define GOT_UNKNOWN 0
595 #define GOT_TLS_IE_POS 5
596 #define GOT_TLS_IE_NEG 6
597 #define GOT_TLS_IE_BOTH 7
598 #define GOT_TLS_GDESC 8
599 #define GOT_TLS_GD_BOTH_P(type) \
600 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
601 #define GOT_TLS_GD_P(type) \
602 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
603 #define GOT_TLS_GDESC_P(type) \
604 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
605 #define GOT_TLS_GD_ANY_P(type) \
606 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
607 unsigned char tls_type
;
609 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
610 starting at the end of the jump table. */
614 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
616 struct elf_i386_obj_tdata
618 struct elf_obj_tdata root
;
620 /* tls_type for each local got entry. */
621 char *local_got_tls_type
;
623 /* GOTPLT entries for TLS descriptors. */
624 bfd_vma
*local_tlsdesc_gotent
;
627 #define elf_i386_tdata(abfd) \
628 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
630 #define elf_i386_local_got_tls_type(abfd) \
631 (elf_i386_tdata (abfd)->local_got_tls_type)
633 #define elf_i386_local_tlsdesc_gotent(abfd) \
634 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
636 #define is_i386_elf(bfd) \
637 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
638 && elf_tdata (bfd) != NULL \
639 && elf_object_id (bfd) == I386_ELF_DATA)
642 elf_i386_mkobject (bfd
*abfd
)
644 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
648 /* i386 ELF linker hash table. */
650 struct elf_i386_link_hash_table
652 struct elf_link_hash_table elf
;
654 /* Short-cuts to get to dynamic linker sections. */
660 bfd_signed_vma refcount
;
664 /* The amount of space used by the reserved portion of the sgotplt
665 section, plus whatever space is used by the jump slots. */
666 bfd_vma sgotplt_jump_table_size
;
668 /* Small local sym cache. */
669 struct sym_cache sym_cache
;
671 /* _TLS_MODULE_BASE_ symbol. */
672 struct bfd_link_hash_entry
*tls_module_base
;
674 /* Used by local STT_GNU_IFUNC symbols. */
675 htab_t loc_hash_table
;
676 void * loc_hash_memory
;
678 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
681 /* True if the target system is VxWorks. */
684 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
685 bfd_vma next_tls_desc_index
;
687 /* Value used to fill the last word of the first plt entry. */
688 bfd_byte plt0_pad_byte
;
691 /* Get the i386 ELF linker hash table from a link_info structure. */
693 #define elf_i386_hash_table(p) \
694 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
695 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
697 #define elf_i386_compute_jump_table_size(htab) \
698 ((htab)->next_tls_desc_index * 4)
700 /* Create an entry in an i386 ELF linker hash table. */
702 static struct bfd_hash_entry
*
703 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
704 struct bfd_hash_table
*table
,
707 /* Allocate the structure if it has not already been allocated by a
711 entry
= (struct bfd_hash_entry
*)
712 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
717 /* Call the allocation method of the superclass. */
718 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
721 struct elf_i386_link_hash_entry
*eh
;
723 eh
= (struct elf_i386_link_hash_entry
*) entry
;
724 eh
->dyn_relocs
= NULL
;
725 eh
->tls_type
= GOT_UNKNOWN
;
726 eh
->tlsdesc_got
= (bfd_vma
) -1;
732 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
733 for local symbol so that we can handle local STT_GNU_IFUNC symbols
734 as global symbol. We reuse indx and dynstr_index for local symbol
735 hash since they aren't used by global symbols in this backend. */
738 elf_i386_local_htab_hash (const void *ptr
)
740 struct elf_link_hash_entry
*h
741 = (struct elf_link_hash_entry
*) ptr
;
742 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
745 /* Compare local hash entries. */
748 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
750 struct elf_link_hash_entry
*h1
751 = (struct elf_link_hash_entry
*) ptr1
;
752 struct elf_link_hash_entry
*h2
753 = (struct elf_link_hash_entry
*) ptr2
;
755 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
758 /* Find and/or create a hash entry for local symbol. */
760 static struct elf_link_hash_entry
*
761 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
762 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
765 struct elf_i386_link_hash_entry e
, *ret
;
766 asection
*sec
= abfd
->sections
;
767 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
768 ELF32_R_SYM (rel
->r_info
));
771 e
.elf
.indx
= sec
->id
;
772 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
773 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
774 create
? INSERT
: NO_INSERT
);
781 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
785 ret
= (struct elf_i386_link_hash_entry
*)
786 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
787 sizeof (struct elf_i386_link_hash_entry
));
790 memset (ret
, 0, sizeof (*ret
));
791 ret
->elf
.indx
= sec
->id
;
792 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
793 ret
->elf
.dynindx
= -1;
799 /* Create an i386 ELF linker hash table. */
801 static struct bfd_link_hash_table
*
802 elf_i386_link_hash_table_create (bfd
*abfd
)
804 struct elf_i386_link_hash_table
*ret
;
805 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
807 ret
= (struct elf_i386_link_hash_table
*) bfd_malloc (amt
);
811 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
812 elf_i386_link_hash_newfunc
,
813 sizeof (struct elf_i386_link_hash_entry
),
822 ret
->tls_ldm_got
.refcount
= 0;
823 ret
->next_tls_desc_index
= 0;
824 ret
->sgotplt_jump_table_size
= 0;
825 ret
->sym_cache
.abfd
= NULL
;
827 ret
->srelplt2
= NULL
;
828 ret
->plt0_pad_byte
= 0;
829 ret
->tls_module_base
= NULL
;
831 ret
->loc_hash_table
= htab_try_create (1024,
832 elf_i386_local_htab_hash
,
833 elf_i386_local_htab_eq
,
835 ret
->loc_hash_memory
= objalloc_create ();
836 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
842 return &ret
->elf
.root
;
845 /* Destroy an i386 ELF linker hash table. */
848 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
850 struct elf_i386_link_hash_table
*htab
851 = (struct elf_i386_link_hash_table
*) hash
;
853 if (htab
->loc_hash_table
)
854 htab_delete (htab
->loc_hash_table
);
855 if (htab
->loc_hash_memory
)
856 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
857 _bfd_generic_link_hash_table_free (hash
);
860 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
861 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
865 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
867 struct elf_i386_link_hash_table
*htab
;
869 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
872 htab
= elf_i386_hash_table (info
);
876 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
878 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
881 || (!info
->shared
&& !htab
->srelbss
))
885 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
892 /* Copy the extra info we tack onto an elf_link_hash_entry. */
895 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
896 struct elf_link_hash_entry
*dir
,
897 struct elf_link_hash_entry
*ind
)
899 struct elf_i386_link_hash_entry
*edir
, *eind
;
901 edir
= (struct elf_i386_link_hash_entry
*) dir
;
902 eind
= (struct elf_i386_link_hash_entry
*) ind
;
904 if (eind
->dyn_relocs
!= NULL
)
906 if (edir
->dyn_relocs
!= NULL
)
908 struct elf_dyn_relocs
**pp
;
909 struct elf_dyn_relocs
*p
;
911 /* Add reloc counts against the indirect sym to the direct sym
912 list. Merge any entries against the same section. */
913 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
915 struct elf_dyn_relocs
*q
;
917 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
918 if (q
->sec
== p
->sec
)
920 q
->pc_count
+= p
->pc_count
;
921 q
->count
+= p
->count
;
928 *pp
= edir
->dyn_relocs
;
931 edir
->dyn_relocs
= eind
->dyn_relocs
;
932 eind
->dyn_relocs
= NULL
;
935 if (ind
->root
.type
== bfd_link_hash_indirect
936 && dir
->got
.refcount
<= 0)
938 edir
->tls_type
= eind
->tls_type
;
939 eind
->tls_type
= GOT_UNKNOWN
;
942 if (ELIMINATE_COPY_RELOCS
943 && ind
->root
.type
!= bfd_link_hash_indirect
944 && dir
->dynamic_adjusted
)
946 /* If called to transfer flags for a weakdef during processing
947 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
948 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
949 dir
->ref_dynamic
|= ind
->ref_dynamic
;
950 dir
->ref_regular
|= ind
->ref_regular
;
951 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
952 dir
->needs_plt
|= ind
->needs_plt
;
953 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
956 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
966 /* Return TRUE if the TLS access code sequence support transition
970 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
972 Elf_Internal_Shdr
*symtab_hdr
,
973 struct elf_link_hash_entry
**sym_hashes
,
975 const Elf_Internal_Rela
*rel
,
976 const Elf_Internal_Rela
*relend
)
978 unsigned int val
, type
;
979 unsigned long r_symndx
;
980 struct elf_link_hash_entry
*h
;
983 /* Get the section contents. */
984 if (contents
== NULL
)
986 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
987 contents
= elf_section_data (sec
)->this_hdr
.contents
;
990 /* FIXME: How to better handle error condition? */
991 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
994 /* Cache the section contents for elf_link_input_bfd. */
995 elf_section_data (sec
)->this_hdr
.contents
= contents
;
999 offset
= rel
->r_offset
;
1004 if (offset
< 2 || (rel
+ 1) >= relend
)
1007 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1008 if (r_type
== R_386_TLS_GD
)
1010 /* Check transition from GD access model. Only
1011 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1012 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1013 can transit to different access model. */
1014 if ((offset
+ 10) > sec
->size
||
1015 (type
!= 0x8d && type
!= 0x04))
1018 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1021 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1025 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1028 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1033 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1034 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1037 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1043 /* Check transition from LD access model. Only
1044 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1045 can transit to different access model. */
1046 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1049 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1050 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1054 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1057 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1058 if (r_symndx
< symtab_hdr
->sh_info
)
1061 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1062 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1063 may be versioned. */
1065 && h
->root
.root
.string
!= NULL
1066 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1067 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1068 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1072 /* Check transition from IE access model:
1073 movl foo@indntpoff(%rip), %eax
1074 movl foo@indntpoff(%rip), %reg
1075 addl foo@indntpoff(%rip), %reg
1078 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1081 /* Check "movl foo@tpoff(%rip), %eax" first. */
1082 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1089 /* Check movl|addl foo@tpoff(%rip), %reg. */
1090 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1091 return ((type
== 0x8b || type
== 0x03)
1092 && (val
& 0xc7) == 0x05);
1094 case R_386_TLS_GOTIE
:
1095 case R_386_TLS_IE_32
:
1096 /* Check transition from {IE_32,GOTIE} access model:
1097 subl foo@{tpoff,gontoff}(%reg1), %reg2
1098 movl foo@{tpoff,gontoff}(%reg1), %reg2
1099 addl foo@{tpoff,gontoff}(%reg1), %reg2
1102 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1105 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1106 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1109 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1110 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1112 case R_386_TLS_GOTDESC
:
1113 /* Check transition from GDesc access model:
1114 leal x@tlsdesc(%ebx), %eax
1116 Make sure it's a leal adding ebx to a 32-bit offset
1117 into any register, although it's probably almost always
1120 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1123 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1126 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1127 return (val
& 0xc7) == 0x83;
1129 case R_386_TLS_DESC_CALL
:
1130 /* Check transition from GDesc access model:
1131 call *x@tlsdesc(%rax)
1133 if (offset
+ 2 <= sec
->size
)
1135 /* Make sure that it's a call *x@tlsdesc(%rax). */
1136 static i386_opcode16 call
= { { 0xff, 0x10 } };
1137 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1147 /* Return TRUE if the TLS access transition is OK or no transition
1148 will be performed. Update R_TYPE if there is a transition. */
1151 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1152 asection
*sec
, bfd_byte
*contents
,
1153 Elf_Internal_Shdr
*symtab_hdr
,
1154 struct elf_link_hash_entry
**sym_hashes
,
1155 unsigned int *r_type
, int tls_type
,
1156 const Elf_Internal_Rela
*rel
,
1157 const Elf_Internal_Rela
*relend
,
1158 struct elf_link_hash_entry
*h
,
1159 unsigned long r_symndx
)
1161 unsigned int from_type
= *r_type
;
1162 unsigned int to_type
= from_type
;
1163 bfd_boolean check
= TRUE
;
1165 /* Skip TLS transition for functions. */
1167 && (h
->type
== STT_FUNC
1168 || h
->type
== STT_GNU_IFUNC
))
1174 case R_386_TLS_GOTDESC
:
1175 case R_386_TLS_DESC_CALL
:
1176 case R_386_TLS_IE_32
:
1178 case R_386_TLS_GOTIE
:
1179 if (info
->executable
)
1182 to_type
= R_386_TLS_LE_32
;
1183 else if (from_type
!= R_386_TLS_IE
1184 && from_type
!= R_386_TLS_GOTIE
)
1185 to_type
= R_386_TLS_IE_32
;
1188 /* When we are called from elf_i386_relocate_section, CONTENTS
1189 isn't NULL and there may be additional transitions based on
1191 if (contents
!= NULL
)
1193 unsigned int new_to_type
= to_type
;
1195 if (info
->executable
1198 && (tls_type
& GOT_TLS_IE
))
1199 new_to_type
= R_386_TLS_LE_32
;
1201 if (to_type
== R_386_TLS_GD
1202 || to_type
== R_386_TLS_GOTDESC
1203 || to_type
== R_386_TLS_DESC_CALL
)
1205 if (tls_type
== GOT_TLS_IE_POS
)
1206 new_to_type
= R_386_TLS_GOTIE
;
1207 else if (tls_type
& GOT_TLS_IE
)
1208 new_to_type
= R_386_TLS_IE_32
;
1211 /* We checked the transition before when we were called from
1212 elf_i386_check_relocs. We only want to check the new
1213 transition which hasn't been checked before. */
1214 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1215 to_type
= new_to_type
;
1221 if (info
->executable
)
1222 to_type
= R_386_TLS_LE_32
;
1229 /* Return TRUE if there is no transition. */
1230 if (from_type
== to_type
)
1233 /* Check if the transition can be performed. */
1235 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1236 symtab_hdr
, sym_hashes
,
1237 from_type
, rel
, relend
))
1239 reloc_howto_type
*from
, *to
;
1242 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1243 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1246 name
= h
->root
.root
.string
;
1249 struct elf_i386_link_hash_table
*htab
;
1251 htab
= elf_i386_hash_table (info
);
1256 Elf_Internal_Sym
*isym
;
1258 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1260 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1264 (*_bfd_error_handler
)
1265 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1266 "in section `%A' failed"),
1267 abfd
, sec
, from
->name
, to
->name
, name
,
1268 (unsigned long) rel
->r_offset
);
1269 bfd_set_error (bfd_error_bad_value
);
1277 /* Look through the relocs for a section during the first phase, and
1278 calculate needed space in the global offset table, procedure linkage
1279 table, and dynamic reloc sections. */
1282 elf_i386_check_relocs (bfd
*abfd
,
1283 struct bfd_link_info
*info
,
1285 const Elf_Internal_Rela
*relocs
)
1287 struct elf_i386_link_hash_table
*htab
;
1288 Elf_Internal_Shdr
*symtab_hdr
;
1289 struct elf_link_hash_entry
**sym_hashes
;
1290 const Elf_Internal_Rela
*rel
;
1291 const Elf_Internal_Rela
*rel_end
;
1294 if (info
->relocatable
)
1297 BFD_ASSERT (is_i386_elf (abfd
));
1299 htab
= elf_i386_hash_table (info
);
1303 symtab_hdr
= &elf_symtab_hdr (abfd
);
1304 sym_hashes
= elf_sym_hashes (abfd
);
1308 rel_end
= relocs
+ sec
->reloc_count
;
1309 for (rel
= relocs
; rel
< rel_end
; rel
++)
1311 unsigned int r_type
;
1312 unsigned long r_symndx
;
1313 struct elf_link_hash_entry
*h
;
1314 Elf_Internal_Sym
*isym
;
1317 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1318 r_type
= ELF32_R_TYPE (rel
->r_info
);
1320 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1322 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1328 if (r_symndx
< symtab_hdr
->sh_info
)
1330 /* A local symbol. */
1331 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1336 /* Check relocation against local STT_GNU_IFUNC symbol. */
1337 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1339 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1343 /* Fake a STT_GNU_IFUNC symbol. */
1344 h
->type
= STT_GNU_IFUNC
;
1347 h
->forced_local
= 1;
1348 h
->root
.type
= bfd_link_hash_defined
;
1356 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1357 while (h
->root
.type
== bfd_link_hash_indirect
1358 || h
->root
.type
== bfd_link_hash_warning
)
1359 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1364 /* Create the ifunc sections for static executables. If we
1365 never see an indirect function symbol nor we are building
1366 a static executable, those sections will be empty and
1367 won't appear in output. */
1378 if (!_bfd_elf_create_ifunc_sections (abfd
, info
))
1383 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1384 it here if it is defined in a non-shared object. */
1385 if (h
->type
== STT_GNU_IFUNC
1388 /* It is referenced by a non-shared object. */
1392 /* STT_GNU_IFUNC symbol must go through PLT. */
1393 h
->plt
.refcount
+= 1;
1395 /* STT_GNU_IFUNC needs dynamic sections. */
1396 if (htab
->elf
.dynobj
== NULL
)
1397 htab
->elf
.dynobj
= abfd
;
1402 if (h
->root
.root
.string
)
1403 name
= h
->root
.root
.string
;
1405 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1407 (*_bfd_error_handler
)
1408 (_("%B: relocation %s against STT_GNU_IFUNC "
1409 "symbol `%s' isn't handled by %s"), abfd
,
1410 elf_howto_table
[r_type
].name
,
1411 name
, __FUNCTION__
);
1412 bfd_set_error (bfd_error_bad_value
);
1417 h
->pointer_equality_needed
= 1;
1420 /* We must copy these reloc types into the
1421 output file. Create a reloc section in
1422 dynobj and make room for this reloc. */
1423 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1424 (abfd
, info
, sec
, sreloc
,
1425 &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
);
1440 h
->got
.refcount
+= 1;
1441 if (htab
->elf
.sgot
== NULL
1442 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1452 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1453 symtab_hdr
, sym_hashes
,
1454 &r_type
, GOT_UNKNOWN
,
1455 rel
, rel_end
, h
, r_symndx
))
1461 htab
->tls_ldm_got
.refcount
+= 1;
1465 /* This symbol requires a procedure linkage table entry. We
1466 actually build the entry in adjust_dynamic_symbol,
1467 because this might be a case of linking PIC code which is
1468 never referenced by a dynamic object, in which case we
1469 don't need to generate a procedure linkage table entry
1472 /* If this is a local symbol, we resolve it directly without
1473 creating a procedure linkage table entry. */
1478 h
->plt
.refcount
+= 1;
1481 case R_386_TLS_IE_32
:
1483 case R_386_TLS_GOTIE
:
1484 if (!info
->executable
)
1485 info
->flags
|= DF_STATIC_TLS
;
1490 case R_386_TLS_GOTDESC
:
1491 case R_386_TLS_DESC_CALL
:
1492 /* This symbol requires a global offset table entry. */
1494 int tls_type
, old_tls_type
;
1499 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1500 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1501 case R_386_TLS_GOTDESC
:
1502 case R_386_TLS_DESC_CALL
:
1503 tls_type
= GOT_TLS_GDESC
; break;
1504 case R_386_TLS_IE_32
:
1505 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1506 tls_type
= GOT_TLS_IE_NEG
;
1508 /* If this is a GD->IE transition, we may use either of
1509 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1510 tls_type
= GOT_TLS_IE
;
1513 case R_386_TLS_GOTIE
:
1514 tls_type
= GOT_TLS_IE_POS
; break;
1519 h
->got
.refcount
+= 1;
1520 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1524 bfd_signed_vma
*local_got_refcounts
;
1526 /* This is a global offset table entry for a local symbol. */
1527 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1528 if (local_got_refcounts
== NULL
)
1532 size
= symtab_hdr
->sh_info
;
1533 size
*= (sizeof (bfd_signed_vma
)
1534 + sizeof (bfd_vma
) + sizeof(char));
1535 local_got_refcounts
= (bfd_signed_vma
*)
1536 bfd_zalloc (abfd
, size
);
1537 if (local_got_refcounts
== NULL
)
1539 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1540 elf_i386_local_tlsdesc_gotent (abfd
)
1541 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1542 elf_i386_local_got_tls_type (abfd
)
1543 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1545 local_got_refcounts
[r_symndx
] += 1;
1546 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1549 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1550 tls_type
|= old_tls_type
;
1551 /* If a TLS symbol is accessed using IE at least once,
1552 there is no point to use dynamic model for it. */
1553 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1554 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1555 || (tls_type
& GOT_TLS_IE
) == 0))
1557 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1558 tls_type
= old_tls_type
;
1559 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1560 && GOT_TLS_GD_ANY_P (tls_type
))
1561 tls_type
|= old_tls_type
;
1565 name
= h
->root
.root
.string
;
1567 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1569 (*_bfd_error_handler
)
1570 (_("%B: `%s' accessed both as normal and "
1571 "thread local symbol"),
1577 if (old_tls_type
!= tls_type
)
1580 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1582 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1590 if (htab
->elf
.sgot
== NULL
)
1592 if (htab
->elf
.dynobj
== NULL
)
1593 htab
->elf
.dynobj
= abfd
;
1594 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1597 if (r_type
!= R_386_TLS_IE
)
1601 case R_386_TLS_LE_32
:
1603 if (info
->executable
)
1605 info
->flags
|= DF_STATIC_TLS
;
1610 if (h
!= NULL
&& info
->executable
)
1612 /* If this reloc is in a read-only section, we might
1613 need a copy reloc. We can't check reliably at this
1614 stage whether the section is read-only, as input
1615 sections have not yet been mapped to output sections.
1616 Tentatively set the flag for now, and correct in
1617 adjust_dynamic_symbol. */
1620 /* We may need a .plt entry if the function this reloc
1621 refers to is in a shared lib. */
1622 h
->plt
.refcount
+= 1;
1623 if (r_type
!= R_386_PC32
)
1624 h
->pointer_equality_needed
= 1;
1627 /* If we are creating a shared library, and this is a reloc
1628 against a global symbol, or a non PC relative reloc
1629 against a local symbol, then we need to copy the reloc
1630 into the shared library. However, if we are linking with
1631 -Bsymbolic, we do not need to copy a reloc against a
1632 global symbol which is defined in an object we are
1633 including in the link (i.e., DEF_REGULAR is set). At
1634 this point we have not seen all the input files, so it is
1635 possible that DEF_REGULAR is not set now but will be set
1636 later (it is never cleared). In case of a weak definition,
1637 DEF_REGULAR may be cleared later by a strong definition in
1638 a shared library. We account for that possibility below by
1639 storing information in the relocs_copied field of the hash
1640 table entry. A similar situation occurs when creating
1641 shared libraries and symbol visibility changes render the
1644 If on the other hand, we are creating an executable, we
1645 may need to keep relocations for symbols satisfied by a
1646 dynamic library if we manage to avoid copy relocs for the
1649 && (sec
->flags
& SEC_ALLOC
) != 0
1650 && (r_type
!= R_386_PC32
1652 && (! SYMBOLIC_BIND (info
, h
)
1653 || h
->root
.type
== bfd_link_hash_defweak
1654 || !h
->def_regular
))))
1655 || (ELIMINATE_COPY_RELOCS
1657 && (sec
->flags
& SEC_ALLOC
) != 0
1659 && (h
->root
.type
== bfd_link_hash_defweak
1660 || !h
->def_regular
)))
1662 struct elf_dyn_relocs
*p
;
1663 struct elf_dyn_relocs
**head
;
1665 /* We must copy these reloc types into the output file.
1666 Create a reloc section in dynobj and make room for
1670 if (htab
->elf
.dynobj
== NULL
)
1671 htab
->elf
.dynobj
= abfd
;
1673 sreloc
= _bfd_elf_make_dynamic_reloc_section
1674 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1680 /* If this is a global symbol, we count the number of
1681 relocations we need for this symbol. */
1684 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1688 /* Track dynamic relocs needed for local syms too.
1689 We really need local syms available to do this
1694 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1699 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1703 vpp
= &elf_section_data (s
)->local_dynrel
;
1704 head
= (struct elf_dyn_relocs
**)vpp
;
1708 if (p
== NULL
|| p
->sec
!= sec
)
1710 bfd_size_type amt
= sizeof *p
;
1711 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1723 if (r_type
== R_386_PC32
)
1728 /* This relocation describes the C++ object vtable hierarchy.
1729 Reconstruct it for later use during GC. */
1730 case R_386_GNU_VTINHERIT
:
1731 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1735 /* This relocation describes which C++ vtable entries are actually
1736 used. Record for later use during GC. */
1737 case R_386_GNU_VTENTRY
:
1738 BFD_ASSERT (h
!= NULL
);
1740 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1752 /* Return the section that should be marked against GC for a given
1756 elf_i386_gc_mark_hook (asection
*sec
,
1757 struct bfd_link_info
*info
,
1758 Elf_Internal_Rela
*rel
,
1759 struct elf_link_hash_entry
*h
,
1760 Elf_Internal_Sym
*sym
)
1763 switch (ELF32_R_TYPE (rel
->r_info
))
1765 case R_386_GNU_VTINHERIT
:
1766 case R_386_GNU_VTENTRY
:
1770 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1773 /* Update the got entry reference counts for the section being removed. */
1776 elf_i386_gc_sweep_hook (bfd
*abfd
,
1777 struct bfd_link_info
*info
,
1779 const Elf_Internal_Rela
*relocs
)
1781 struct elf_i386_link_hash_table
*htab
;
1782 Elf_Internal_Shdr
*symtab_hdr
;
1783 struct elf_link_hash_entry
**sym_hashes
;
1784 bfd_signed_vma
*local_got_refcounts
;
1785 const Elf_Internal_Rela
*rel
, *relend
;
1787 if (info
->relocatable
)
1790 htab
= elf_i386_hash_table (info
);
1794 elf_section_data (sec
)->local_dynrel
= NULL
;
1796 symtab_hdr
= &elf_symtab_hdr (abfd
);
1797 sym_hashes
= elf_sym_hashes (abfd
);
1798 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1800 relend
= relocs
+ sec
->reloc_count
;
1801 for (rel
= relocs
; rel
< relend
; rel
++)
1803 unsigned long r_symndx
;
1804 unsigned int r_type
;
1805 struct elf_link_hash_entry
*h
= NULL
;
1807 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1808 if (r_symndx
>= symtab_hdr
->sh_info
)
1810 struct elf_i386_link_hash_entry
*eh
;
1811 struct elf_dyn_relocs
**pp
;
1812 struct elf_dyn_relocs
*p
;
1814 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1815 while (h
->root
.type
== bfd_link_hash_indirect
1816 || h
->root
.type
== bfd_link_hash_warning
)
1817 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1818 eh
= (struct elf_i386_link_hash_entry
*) h
;
1820 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1823 /* Everything must go for SEC. */
1830 /* A local symbol. */
1831 Elf_Internal_Sym
*isym
;
1833 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1836 /* Check relocation against local STT_GNU_IFUNC symbol. */
1838 && ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1840 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1846 r_type
= ELF32_R_TYPE (rel
->r_info
);
1847 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1848 symtab_hdr
, sym_hashes
,
1849 &r_type
, GOT_UNKNOWN
,
1850 rel
, relend
, h
, r_symndx
))
1856 if (htab
->tls_ldm_got
.refcount
> 0)
1857 htab
->tls_ldm_got
.refcount
-= 1;
1861 case R_386_TLS_GOTDESC
:
1862 case R_386_TLS_DESC_CALL
:
1863 case R_386_TLS_IE_32
:
1865 case R_386_TLS_GOTIE
:
1869 if (h
->got
.refcount
> 0)
1870 h
->got
.refcount
-= 1;
1871 if (h
->type
== STT_GNU_IFUNC
)
1873 if (h
->plt
.refcount
> 0)
1874 h
->plt
.refcount
-= 1;
1877 else if (local_got_refcounts
!= NULL
)
1879 if (local_got_refcounts
[r_symndx
] > 0)
1880 local_got_refcounts
[r_symndx
] -= 1;
1893 if (h
->plt
.refcount
> 0)
1894 h
->plt
.refcount
-= 1;
1899 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
1901 if (h
->got
.refcount
> 0)
1902 h
->got
.refcount
-= 1;
1903 if (h
->plt
.refcount
> 0)
1904 h
->plt
.refcount
-= 1;
1916 /* Adjust a symbol defined by a dynamic object and referenced by a
1917 regular object. The current definition is in some section of the
1918 dynamic object, but we're not including those sections. We have to
1919 change the definition to something the rest of the link can
1923 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1924 struct elf_link_hash_entry
*h
)
1926 struct elf_i386_link_hash_table
*htab
;
1929 /* STT_GNU_IFUNC symbol must go through PLT. */
1930 if (h
->type
== STT_GNU_IFUNC
)
1932 if (h
->plt
.refcount
<= 0)
1934 h
->plt
.offset
= (bfd_vma
) -1;
1940 /* If this is a function, put it in the procedure linkage table. We
1941 will fill in the contents of the procedure linkage table later,
1942 when we know the address of the .got section. */
1943 if (h
->type
== STT_FUNC
1946 if (h
->plt
.refcount
<= 0
1947 || SYMBOL_CALLS_LOCAL (info
, h
)
1948 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1949 && h
->root
.type
== bfd_link_hash_undefweak
))
1951 /* This case can occur if we saw a PLT32 reloc in an input
1952 file, but the symbol was never referred to by a dynamic
1953 object, or if all references were garbage collected. In
1954 such a case, we don't actually need to build a procedure
1955 linkage table, and we can just do a PC32 reloc instead. */
1956 h
->plt
.offset
= (bfd_vma
) -1;
1963 /* It's possible that we incorrectly decided a .plt reloc was
1964 needed for an R_386_PC32 reloc to a non-function sym in
1965 check_relocs. We can't decide accurately between function and
1966 non-function syms in check-relocs; Objects loaded later in
1967 the link may change h->type. So fix it now. */
1968 h
->plt
.offset
= (bfd_vma
) -1;
1970 /* If this is a weak symbol, and there is a real definition, the
1971 processor independent code will have arranged for us to see the
1972 real definition first, and we can just use the same value. */
1973 if (h
->u
.weakdef
!= NULL
)
1975 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1976 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1977 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1978 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1979 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1980 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1984 /* This is a reference to a symbol defined by a dynamic object which
1985 is not a function. */
1987 /* If we are creating a shared library, we must presume that the
1988 only references to the symbol are via the global offset table.
1989 For such cases we need not do anything here; the relocations will
1990 be handled correctly by relocate_section. */
1994 /* If there are no references to this symbol that do not use the
1995 GOT, we don't need to generate a copy reloc. */
1996 if (!h
->non_got_ref
)
1999 /* If -z nocopyreloc was given, we won't generate them either. */
2000 if (info
->nocopyreloc
)
2006 htab
= elf_i386_hash_table (info
);
2010 /* If there aren't any dynamic relocs in read-only sections, then
2011 we can keep the dynamic relocs and avoid the copy reloc. This
2012 doesn't work on VxWorks, where we can not have dynamic relocations
2013 (other than copy and jump slot relocations) in an executable. */
2014 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
2016 struct elf_i386_link_hash_entry
* eh
;
2017 struct elf_dyn_relocs
*p
;
2019 eh
= (struct elf_i386_link_hash_entry
*) h
;
2020 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2022 s
= p
->sec
->output_section
;
2023 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2036 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2037 h
->root
.root
.string
);
2041 /* We must allocate the symbol in our .dynbss section, which will
2042 become part of the .bss section of the executable. There will be
2043 an entry for this symbol in the .dynsym section. The dynamic
2044 object will contain position independent code, so all references
2045 from the dynamic object to this symbol will go through the global
2046 offset table. The dynamic linker will use the .dynsym entry to
2047 determine the address it must put in the global offset table, so
2048 both the dynamic object and the regular object will refer to the
2049 same memory location for the variable. */
2051 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2052 copy the initial value out of the dynamic object and into the
2053 runtime process image. */
2054 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2056 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2062 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2065 /* Allocate space in .plt, .got and associated reloc sections for
2069 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2071 struct bfd_link_info
*info
;
2072 struct elf_i386_link_hash_table
*htab
;
2073 struct elf_i386_link_hash_entry
*eh
;
2074 struct elf_dyn_relocs
*p
;
2076 if (h
->root
.type
== bfd_link_hash_indirect
)
2079 if (h
->root
.type
== bfd_link_hash_warning
)
2080 /* When warning symbols are created, they **replace** the "real"
2081 entry in the hash table, thus we never get to see the real
2082 symbol in a hash traversal. So look at it now. */
2083 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2084 eh
= (struct elf_i386_link_hash_entry
*) h
;
2086 info
= (struct bfd_link_info
*) inf
;
2087 htab
= elf_i386_hash_table (info
);
2091 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2092 here if it is defined and referenced in a non-shared object. */
2093 if (h
->type
== STT_GNU_IFUNC
2095 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2098 else if (htab
->elf
.dynamic_sections_created
2099 && h
->plt
.refcount
> 0)
2101 /* Make sure this symbol is output as a dynamic symbol.
2102 Undefined weak syms won't yet be marked as dynamic. */
2103 if (h
->dynindx
== -1
2104 && !h
->forced_local
)
2106 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2111 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2113 asection
*s
= htab
->elf
.splt
;
2115 /* If this is the first .plt entry, make room for the special
2118 s
->size
+= PLT_ENTRY_SIZE
;
2120 h
->plt
.offset
= s
->size
;
2122 /* If this symbol is not defined in a regular file, and we are
2123 not generating a shared library, then set the symbol to this
2124 location in the .plt. This is required to make function
2125 pointers compare as equal between the normal executable and
2126 the shared library. */
2130 h
->root
.u
.def
.section
= s
;
2131 h
->root
.u
.def
.value
= h
->plt
.offset
;
2134 /* Make room for this entry. */
2135 s
->size
+= PLT_ENTRY_SIZE
;
2137 /* We also need to make an entry in the .got.plt section, which
2138 will be placed in the .got section by the linker script. */
2139 htab
->elf
.sgotplt
->size
+= 4;
2141 /* We also need to make an entry in the .rel.plt section. */
2142 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2143 htab
->next_tls_desc_index
++;
2145 if (htab
->is_vxworks
&& !info
->shared
)
2147 /* VxWorks has a second set of relocations for each PLT entry
2148 in executables. They go in a separate relocation section,
2149 which is processed by the kernel loader. */
2151 /* There are two relocations for the initial PLT entry: an
2152 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2153 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2155 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
2156 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2158 /* There are two extra relocations for each subsequent PLT entry:
2159 an R_386_32 relocation for the GOT entry, and an R_386_32
2160 relocation for the PLT entry. */
2162 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2167 h
->plt
.offset
= (bfd_vma
) -1;
2173 h
->plt
.offset
= (bfd_vma
) -1;
2177 eh
->tlsdesc_got
= (bfd_vma
) -1;
2179 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2180 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2181 if (h
->got
.refcount
> 0
2184 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2185 h
->got
.offset
= (bfd_vma
) -1;
2186 else if (h
->got
.refcount
> 0)
2190 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2192 /* Make sure this symbol is output as a dynamic symbol.
2193 Undefined weak syms won't yet be marked as dynamic. */
2194 if (h
->dynindx
== -1
2195 && !h
->forced_local
)
2197 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2202 if (GOT_TLS_GDESC_P (tls_type
))
2204 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2205 - elf_i386_compute_jump_table_size (htab
);
2206 htab
->elf
.sgotplt
->size
+= 8;
2207 h
->got
.offset
= (bfd_vma
) -2;
2209 if (! GOT_TLS_GDESC_P (tls_type
)
2210 || GOT_TLS_GD_P (tls_type
))
2212 h
->got
.offset
= s
->size
;
2214 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2215 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2218 dyn
= htab
->elf
.dynamic_sections_created
;
2219 /* R_386_TLS_IE_32 needs one dynamic relocation,
2220 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2221 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2222 need two), R_386_TLS_GD needs one if local symbol and two if
2224 if (tls_type
== GOT_TLS_IE_BOTH
)
2225 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2226 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2227 || (tls_type
& GOT_TLS_IE
))
2228 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2229 else if (GOT_TLS_GD_P (tls_type
))
2230 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2231 else if (! GOT_TLS_GDESC_P (tls_type
)
2232 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2233 || h
->root
.type
!= bfd_link_hash_undefweak
)
2235 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2236 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2237 if (GOT_TLS_GDESC_P (tls_type
))
2238 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2241 h
->got
.offset
= (bfd_vma
) -1;
2243 if (eh
->dyn_relocs
== NULL
)
2246 /* In the shared -Bsymbolic case, discard space allocated for
2247 dynamic pc-relative relocs against symbols which turn out to be
2248 defined in regular objects. For the normal shared case, discard
2249 space for pc-relative relocs that have become local due to symbol
2250 visibility changes. */
2254 /* The only reloc that uses pc_count is R_386_PC32, which will
2255 appear on a call or on something like ".long foo - .". We
2256 want calls to protected symbols to resolve directly to the
2257 function rather than going via the plt. If people want
2258 function pointer comparisons to work as expected then they
2259 should avoid writing assembly like ".long foo - .". */
2260 if (SYMBOL_CALLS_LOCAL (info
, h
))
2262 struct elf_dyn_relocs
**pp
;
2264 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2266 p
->count
-= p
->pc_count
;
2275 if (htab
->is_vxworks
)
2277 struct elf_dyn_relocs
**pp
;
2278 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2280 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2287 /* Also discard relocs on undefined weak syms with non-default
2289 if (eh
->dyn_relocs
!= NULL
2290 && h
->root
.type
== bfd_link_hash_undefweak
)
2292 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2293 eh
->dyn_relocs
= NULL
;
2295 /* Make sure undefined weak symbols are output as a dynamic
2297 else if (h
->dynindx
== -1
2298 && !h
->forced_local
)
2300 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2305 else if (ELIMINATE_COPY_RELOCS
)
2307 /* For the non-shared case, discard space for relocs against
2308 symbols which turn out to need copy relocs or are not
2314 || (htab
->elf
.dynamic_sections_created
2315 && (h
->root
.type
== bfd_link_hash_undefweak
2316 || h
->root
.type
== bfd_link_hash_undefined
))))
2318 /* Make sure this symbol is output as a dynamic symbol.
2319 Undefined weak syms won't yet be marked as dynamic. */
2320 if (h
->dynindx
== -1
2321 && !h
->forced_local
)
2323 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2327 /* If that succeeded, we know we'll be keeping all the
2329 if (h
->dynindx
!= -1)
2333 eh
->dyn_relocs
= NULL
;
2338 /* Finally, allocate space. */
2339 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2343 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2345 BFD_ASSERT (sreloc
!= NULL
);
2346 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2352 /* Allocate space in .plt, .got and associated reloc sections for
2353 local dynamic relocs. */
2356 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2358 struct elf_link_hash_entry
*h
2359 = (struct elf_link_hash_entry
*) *slot
;
2361 if (h
->type
!= STT_GNU_IFUNC
2365 || h
->root
.type
!= bfd_link_hash_defined
)
2368 return elf_i386_allocate_dynrelocs (h
, inf
);
2371 /* Find any dynamic relocs that apply to read-only sections. */
2374 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2376 struct elf_i386_link_hash_entry
*eh
;
2377 struct elf_dyn_relocs
*p
;
2379 if (h
->root
.type
== bfd_link_hash_warning
)
2380 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2382 eh
= (struct elf_i386_link_hash_entry
*) h
;
2383 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2385 asection
*s
= p
->sec
->output_section
;
2387 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2389 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2391 info
->flags
|= DF_TEXTREL
;
2393 /* Not an error, just cut short the traversal. */
2400 /* Set the sizes of the dynamic sections. */
2403 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2404 struct bfd_link_info
*info
)
2406 struct elf_i386_link_hash_table
*htab
;
2412 htab
= elf_i386_hash_table (info
);
2415 dynobj
= htab
->elf
.dynobj
;
2419 if (htab
->elf
.dynamic_sections_created
)
2421 /* Set the contents of the .interp section to the interpreter. */
2422 if (info
->executable
)
2424 s
= bfd_get_section_by_name (dynobj
, ".interp");
2427 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2428 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2432 /* Set up .got offsets for local syms, and space for local dynamic
2434 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2436 bfd_signed_vma
*local_got
;
2437 bfd_signed_vma
*end_local_got
;
2438 char *local_tls_type
;
2439 bfd_vma
*local_tlsdesc_gotent
;
2440 bfd_size_type locsymcount
;
2441 Elf_Internal_Shdr
*symtab_hdr
;
2444 if (! is_i386_elf (ibfd
))
2447 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2449 struct elf_dyn_relocs
*p
;
2451 for (p
= ((struct elf_dyn_relocs
*)
2452 elf_section_data (s
)->local_dynrel
);
2456 if (!bfd_is_abs_section (p
->sec
)
2457 && bfd_is_abs_section (p
->sec
->output_section
))
2459 /* Input section has been discarded, either because
2460 it is a copy of a linkonce section or due to
2461 linker script /DISCARD/, so we'll be discarding
2464 else if (htab
->is_vxworks
2465 && strcmp (p
->sec
->output_section
->name
,
2468 /* Relocations in vxworks .tls_vars sections are
2469 handled specially by the loader. */
2471 else if (p
->count
!= 0)
2473 srel
= elf_section_data (p
->sec
)->sreloc
;
2474 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2475 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2476 info
->flags
|= DF_TEXTREL
;
2481 local_got
= elf_local_got_refcounts (ibfd
);
2485 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2486 locsymcount
= symtab_hdr
->sh_info
;
2487 end_local_got
= local_got
+ locsymcount
;
2488 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2489 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2491 srel
= htab
->elf
.srelgot
;
2492 for (; local_got
< end_local_got
;
2493 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2495 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2498 if (GOT_TLS_GDESC_P (*local_tls_type
))
2500 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2501 - elf_i386_compute_jump_table_size (htab
);
2502 htab
->elf
.sgotplt
->size
+= 8;
2503 *local_got
= (bfd_vma
) -2;
2505 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2506 || GOT_TLS_GD_P (*local_tls_type
))
2508 *local_got
= s
->size
;
2510 if (GOT_TLS_GD_P (*local_tls_type
)
2511 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2515 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2516 || (*local_tls_type
& GOT_TLS_IE
))
2518 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2519 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2520 else if (GOT_TLS_GD_P (*local_tls_type
)
2521 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2522 srel
->size
+= sizeof (Elf32_External_Rel
);
2523 if (GOT_TLS_GDESC_P (*local_tls_type
))
2524 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2528 *local_got
= (bfd_vma
) -1;
2532 if (htab
->tls_ldm_got
.refcount
> 0)
2534 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2536 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2537 htab
->elf
.sgot
->size
+= 8;
2538 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2541 htab
->tls_ldm_got
.offset
= -1;
2543 /* Allocate global sym .plt and .got entries, and space for global
2544 sym dynamic relocs. */
2545 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2547 /* Allocate .plt and .got entries, and space for local symbols. */
2548 htab_traverse (htab
->loc_hash_table
,
2549 elf_i386_allocate_local_dynrelocs
,
2552 /* For every jump slot reserved in the sgotplt, reloc_count is
2553 incremented. However, when we reserve space for TLS descriptors,
2554 it's not incremented, so in order to compute the space reserved
2555 for them, it suffices to multiply the reloc count by the jump
2557 if (htab
->elf
.srelplt
)
2558 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2560 if (htab
->elf
.sgotplt
)
2562 struct elf_link_hash_entry
*got
;
2563 got
= elf_link_hash_lookup (elf_hash_table (info
),
2564 "_GLOBAL_OFFSET_TABLE_",
2565 FALSE
, FALSE
, FALSE
);
2567 /* Don't allocate .got.plt section if there are no GOT nor PLT
2568 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2570 || !got
->ref_regular_nonweak
)
2571 && (htab
->elf
.sgotplt
->size
2572 == get_elf_backend_data (output_bfd
)->got_header_size
)
2573 && (htab
->elf
.splt
== NULL
2574 || htab
->elf
.splt
->size
== 0)
2575 && (htab
->elf
.sgot
== NULL
2576 || htab
->elf
.sgot
->size
== 0)
2577 && (htab
->elf
.iplt
== NULL
2578 || htab
->elf
.iplt
->size
== 0)
2579 && (htab
->elf
.igotplt
== NULL
2580 || htab
->elf
.igotplt
->size
== 0))
2581 htab
->elf
.sgotplt
->size
= 0;
2584 /* We now have determined the sizes of the various dynamic sections.
2585 Allocate memory for them. */
2587 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2589 bfd_boolean strip_section
= TRUE
;
2591 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2594 if (s
== htab
->elf
.splt
2595 || s
== htab
->elf
.sgot
2596 || s
== htab
->elf
.sgotplt
2597 || s
== htab
->elf
.iplt
2598 || s
== htab
->elf
.igotplt
2599 || s
== htab
->sdynbss
)
2601 /* Strip this section if we don't need it; see the
2603 /* We'd like to strip these sections if they aren't needed, but if
2604 we've exported dynamic symbols from them we must leave them.
2605 It's too late to tell BFD to get rid of the symbols. */
2607 if (htab
->elf
.hplt
!= NULL
)
2608 strip_section
= FALSE
;
2610 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2613 && s
!= htab
->elf
.srelplt
2614 && s
!= htab
->srelplt2
)
2617 /* We use the reloc_count field as a counter if we need
2618 to copy relocs into the output file. */
2623 /* It's not one of our sections, so don't allocate space. */
2629 /* If we don't need this section, strip it from the
2630 output file. This is mostly to handle .rel.bss and
2631 .rel.plt. We must create both sections in
2632 create_dynamic_sections, because they must be created
2633 before the linker maps input sections to output
2634 sections. The linker does that before
2635 adjust_dynamic_symbol is called, and it is that
2636 function which decides whether anything needs to go
2637 into these sections. */
2639 s
->flags
|= SEC_EXCLUDE
;
2643 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2646 /* Allocate memory for the section contents. We use bfd_zalloc
2647 here in case unused entries are not reclaimed before the
2648 section's contents are written out. This should not happen,
2649 but this way if it does, we get a R_386_NONE reloc instead
2651 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2652 if (s
->contents
== NULL
)
2656 if (htab
->elf
.dynamic_sections_created
)
2658 /* Add some entries to the .dynamic section. We fill in the
2659 values later, in elf_i386_finish_dynamic_sections, but we
2660 must add the entries now so that we get the correct size for
2661 the .dynamic section. The DT_DEBUG entry is filled in by the
2662 dynamic linker and used by the debugger. */
2663 #define add_dynamic_entry(TAG, VAL) \
2664 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2666 if (info
->executable
)
2668 if (!add_dynamic_entry (DT_DEBUG
, 0))
2672 if (htab
->elf
.splt
->size
!= 0)
2674 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2675 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2676 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2677 || !add_dynamic_entry (DT_JMPREL
, 0))
2683 if (!add_dynamic_entry (DT_REL
, 0)
2684 || !add_dynamic_entry (DT_RELSZ
, 0)
2685 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2688 /* If any dynamic relocs apply to a read-only section,
2689 then we need a DT_TEXTREL entry. */
2690 if ((info
->flags
& DF_TEXTREL
) == 0)
2691 elf_link_hash_traverse (&htab
->elf
,
2692 elf_i386_readonly_dynrelocs
, info
);
2694 if ((info
->flags
& DF_TEXTREL
) != 0)
2696 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2700 if (htab
->is_vxworks
2701 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2704 #undef add_dynamic_entry
2710 elf_i386_always_size_sections (bfd
*output_bfd
,
2711 struct bfd_link_info
*info
)
2713 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2717 struct elf_link_hash_entry
*tlsbase
;
2719 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2720 "_TLS_MODULE_BASE_",
2721 FALSE
, FALSE
, FALSE
);
2723 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2725 struct elf_i386_link_hash_table
*htab
;
2726 struct bfd_link_hash_entry
*bh
= NULL
;
2727 const struct elf_backend_data
*bed
2728 = get_elf_backend_data (output_bfd
);
2730 htab
= elf_i386_hash_table (info
);
2734 if (!(_bfd_generic_link_add_one_symbol
2735 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2736 tls_sec
, 0, NULL
, FALSE
,
2737 bed
->collect
, &bh
)))
2740 htab
->tls_module_base
= bh
;
2742 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2743 tlsbase
->def_regular
= 1;
2744 tlsbase
->other
= STV_HIDDEN
;
2745 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2752 /* Set the correct type for an x86 ELF section. We do this by the
2753 section name, which is a hack, but ought to work. */
2756 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2757 Elf_Internal_Shdr
*hdr
,
2762 name
= bfd_get_section_name (abfd
, sec
);
2764 /* This is an ugly, but unfortunately necessary hack that is
2765 needed when producing EFI binaries on x86. It tells
2766 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2767 containing ELF relocation info. We need this hack in order to
2768 be able to generate ELF binaries that can be translated into
2769 EFI applications (which are essentially COFF objects). Those
2770 files contain a COFF ".reloc" section inside an ELFNN object,
2771 which would normally cause BFD to segfault because it would
2772 attempt to interpret this section as containing relocation
2773 entries for section "oc". With this hack enabled, ".reloc"
2774 will be treated as a normal data section, which will avoid the
2775 segfault. However, you won't be able to create an ELFNN binary
2776 with a section named "oc" that needs relocations, but that's
2777 the kind of ugly side-effects you get when detecting section
2778 types based on their names... In practice, this limitation is
2779 unlikely to bite. */
2780 if (strcmp (name
, ".reloc") == 0)
2781 hdr
->sh_type
= SHT_PROGBITS
;
2786 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2787 executables. Rather than setting it to the beginning of the TLS
2788 section, we have to set it to the end. This function may be called
2789 multiple times, it is idempotent. */
2792 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2794 struct elf_i386_link_hash_table
*htab
;
2795 struct bfd_link_hash_entry
*base
;
2797 if (!info
->executable
)
2800 htab
= elf_i386_hash_table (info
);
2804 base
= htab
->tls_module_base
;
2808 base
->u
.def
.value
= htab
->elf
.tls_size
;
2811 /* Return the base VMA address which should be subtracted from real addresses
2812 when resolving @dtpoff relocation.
2813 This is PT_TLS segment p_vaddr. */
2816 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2818 /* If tls_sec is NULL, we should have signalled an error already. */
2819 if (elf_hash_table (info
)->tls_sec
== NULL
)
2821 return elf_hash_table (info
)->tls_sec
->vma
;
2824 /* Return the relocation value for @tpoff relocation
2825 if STT_TLS virtual address is ADDRESS. */
2828 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2830 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2832 /* If tls_sec is NULL, we should have signalled an error already. */
2833 if (htab
->tls_sec
== NULL
)
2835 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2838 /* Relocate an i386 ELF section. */
2841 elf_i386_relocate_section (bfd
*output_bfd
,
2842 struct bfd_link_info
*info
,
2844 asection
*input_section
,
2846 Elf_Internal_Rela
*relocs
,
2847 Elf_Internal_Sym
*local_syms
,
2848 asection
**local_sections
)
2850 struct elf_i386_link_hash_table
*htab
;
2851 Elf_Internal_Shdr
*symtab_hdr
;
2852 struct elf_link_hash_entry
**sym_hashes
;
2853 bfd_vma
*local_got_offsets
;
2854 bfd_vma
*local_tlsdesc_gotents
;
2855 Elf_Internal_Rela
*rel
;
2856 Elf_Internal_Rela
*relend
;
2857 bfd_boolean is_vxworks_tls
;
2859 BFD_ASSERT (is_i386_elf (input_bfd
));
2861 htab
= elf_i386_hash_table (info
);
2864 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2865 sym_hashes
= elf_sym_hashes (input_bfd
);
2866 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2867 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2868 /* We have to handle relocations in vxworks .tls_vars sections
2869 specially, because the dynamic loader is 'weird'. */
2870 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
2871 && !strcmp (input_section
->output_section
->name
,
2874 elf_i386_set_tls_module_base (info
);
2877 relend
= relocs
+ input_section
->reloc_count
;
2878 for (; rel
< relend
; rel
++)
2880 unsigned int r_type
;
2881 reloc_howto_type
*howto
;
2882 unsigned long r_symndx
;
2883 struct elf_link_hash_entry
*h
;
2884 Elf_Internal_Sym
*sym
;
2886 bfd_vma off
, offplt
;
2888 bfd_boolean unresolved_reloc
;
2889 bfd_reloc_status_type r
;
2893 r_type
= ELF32_R_TYPE (rel
->r_info
);
2894 if (r_type
== R_386_GNU_VTINHERIT
2895 || r_type
== R_386_GNU_VTENTRY
)
2898 if ((indx
= r_type
) >= R_386_standard
2899 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2900 >= R_386_ext
- R_386_standard
)
2901 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2902 >= R_386_irelative
- R_386_ext
))
2904 (*_bfd_error_handler
)
2905 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2906 input_bfd
, input_section
, r_type
);
2907 bfd_set_error (bfd_error_bad_value
);
2910 howto
= elf_howto_table
+ indx
;
2912 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2916 unresolved_reloc
= FALSE
;
2917 if (r_symndx
< symtab_hdr
->sh_info
)
2919 sym
= local_syms
+ r_symndx
;
2920 sec
= local_sections
[r_symndx
];
2921 relocation
= (sec
->output_section
->vma
2922 + sec
->output_offset
2925 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2926 && ((sec
->flags
& SEC_MERGE
) != 0
2927 || (info
->relocatable
2928 && sec
->output_offset
!= 0)))
2931 bfd_byte
*where
= contents
+ rel
->r_offset
;
2933 switch (howto
->size
)
2936 addend
= bfd_get_8 (input_bfd
, where
);
2937 if (howto
->pc_relative
)
2939 addend
= (addend
^ 0x80) - 0x80;
2944 addend
= bfd_get_16 (input_bfd
, where
);
2945 if (howto
->pc_relative
)
2947 addend
= (addend
^ 0x8000) - 0x8000;
2952 addend
= bfd_get_32 (input_bfd
, where
);
2953 if (howto
->pc_relative
)
2955 addend
= (addend
^ 0x80000000) - 0x80000000;
2963 if (info
->relocatable
)
2964 addend
+= sec
->output_offset
;
2967 asection
*msec
= sec
;
2968 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2970 addend
-= relocation
;
2971 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2974 switch (howto
->size
)
2977 /* FIXME: overflow checks. */
2978 if (howto
->pc_relative
)
2980 bfd_put_8 (input_bfd
, addend
, where
);
2983 if (howto
->pc_relative
)
2985 bfd_put_16 (input_bfd
, addend
, where
);
2988 if (howto
->pc_relative
)
2990 bfd_put_32 (input_bfd
, addend
, where
);
2994 else if (!info
->relocatable
2995 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2997 /* Relocate against local STT_GNU_IFUNC symbol. */
2998 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3003 /* Set STT_GNU_IFUNC symbol value. */
3004 h
->root
.u
.def
.value
= sym
->st_value
;
3005 h
->root
.u
.def
.section
= sec
;
3010 bfd_boolean warned ATTRIBUTE_UNUSED
;
3012 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3013 r_symndx
, symtab_hdr
, sym_hashes
,
3015 unresolved_reloc
, warned
);
3018 if (sec
!= NULL
&& elf_discarded_section (sec
))
3019 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3020 rel
, relend
, howto
, contents
);
3022 if (info
->relocatable
)
3025 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3026 it here if it is defined in a non-shared object. */
3028 && h
->type
== STT_GNU_IFUNC
3031 asection
*plt
, *gotplt
, *base_got
;
3035 if ((input_section
->flags
& SEC_ALLOC
) == 0
3036 || h
->plt
.offset
== (bfd_vma
) -1)
3039 /* STT_GNU_IFUNC symbol must go through PLT. */
3040 if (htab
->elf
.splt
!= NULL
)
3042 plt
= htab
->elf
.splt
;
3043 gotplt
= htab
->elf
.sgotplt
;
3047 plt
= htab
->elf
.iplt
;
3048 gotplt
= htab
->elf
.igotplt
;
3051 relocation
= (plt
->output_section
->vma
3052 + plt
->output_offset
+ h
->plt
.offset
);
3057 if (h
->root
.root
.string
)
3058 name
= h
->root
.root
.string
;
3060 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3062 (*_bfd_error_handler
)
3063 (_("%B: relocation %s against STT_GNU_IFUNC "
3064 "symbol `%s' isn't handled by %s"), input_bfd
,
3065 elf_howto_table
[r_type
].name
,
3066 name
, __FUNCTION__
);
3067 bfd_set_error (bfd_error_bad_value
);
3071 /* Generate dynamic relcoation only when there is a
3072 non-GOF reference in a shared object. */
3073 if (info
->shared
&& h
->non_got_ref
)
3075 Elf_Internal_Rela outrel
;
3080 /* Need a dynamic relocation to get the real function
3082 offset
= _bfd_elf_section_offset (output_bfd
,
3086 if (offset
== (bfd_vma
) -1
3087 || offset
== (bfd_vma
) -2)
3090 outrel
.r_offset
= (input_section
->output_section
->vma
3091 + input_section
->output_offset
3094 if (h
->dynindx
== -1
3096 || info
->executable
)
3098 /* This symbol is resolved locally. */
3099 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3100 bfd_put_32 (output_bfd
,
3101 (h
->root
.u
.def
.value
3102 + h
->root
.u
.def
.section
->output_section
->vma
3103 + h
->root
.u
.def
.section
->output_offset
),
3107 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3109 sreloc
= htab
->elf
.irelifunc
;
3110 loc
= sreloc
->contents
;
3111 loc
+= (sreloc
->reloc_count
++
3112 * sizeof (Elf32_External_Rel
));
3113 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3115 /* If this reloc is against an external symbol, we
3116 do not want to fiddle with the addend. Otherwise,
3117 we need to include the symbol value so that it
3118 becomes an addend for the dynamic reloc. For an
3119 internal symbol, we have updated addend. */
3128 base_got
= htab
->elf
.sgot
;
3129 off
= h
->got
.offset
;
3131 if (base_got
== NULL
)
3134 if (off
== (bfd_vma
) -1)
3136 /* We can't use h->got.offset here to save state, or
3137 even just remember the offset, as finish_dynamic_symbol
3138 would use that as offset into .got. */
3140 if (htab
->elf
.splt
!= NULL
)
3142 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3143 off
= (plt_index
+ 3) * 4;
3144 base_got
= htab
->elf
.sgotplt
;
3148 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3149 off
= plt_index
* 4;
3150 base_got
= htab
->elf
.igotplt
;
3153 if (h
->dynindx
== -1
3157 /* This references the local defitionion. We must
3158 initialize this entry in the global offset table.
3159 Since the offset must always be a multiple of 8,
3160 we use the least significant bit to record
3161 whether we have initialized it already.
3163 When doing a dynamic link, we create a .rela.got
3164 relocation entry to initialize the value. This
3165 is done in the finish_dynamic_symbol routine. */
3170 bfd_put_32 (output_bfd
, relocation
,
3171 base_got
->contents
+ off
);
3178 /* Adjust for static executables. */
3179 if (htab
->elf
.splt
== NULL
)
3180 relocation
+= gotplt
->output_offset
;
3184 relocation
= (base_got
->output_section
->vma
3185 + base_got
->output_offset
+ off
3186 - gotplt
->output_section
->vma
3187 - gotplt
->output_offset
);
3188 /* Adjust for static executables. */
3189 if (htab
->elf
.splt
== NULL
)
3190 relocation
+= gotplt
->output_offset
;
3196 relocation
-= (gotplt
->output_section
->vma
3197 + gotplt
->output_offset
);
3205 /* Relocation is to the entry for this symbol in the global
3207 if (htab
->elf
.sgot
== NULL
)
3214 off
= h
->got
.offset
;
3215 dyn
= htab
->elf
.dynamic_sections_created
;
3216 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3218 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3219 || (ELF_ST_VISIBILITY (h
->other
)
3220 && h
->root
.type
== bfd_link_hash_undefweak
))
3222 /* This is actually a static link, or it is a
3223 -Bsymbolic link and the symbol is defined
3224 locally, or the symbol was forced to be local
3225 because of a version file. We must initialize
3226 this entry in the global offset table. Since the
3227 offset must always be a multiple of 4, we use the
3228 least significant bit to record whether we have
3229 initialized it already.
3231 When doing a dynamic link, we create a .rel.got
3232 relocation entry to initialize the value. This
3233 is done in the finish_dynamic_symbol routine. */
3238 bfd_put_32 (output_bfd
, relocation
,
3239 htab
->elf
.sgot
->contents
+ off
);
3244 unresolved_reloc
= FALSE
;
3248 if (local_got_offsets
== NULL
)
3251 off
= local_got_offsets
[r_symndx
];
3253 /* The offset must always be a multiple of 4. We use
3254 the least significant bit to record whether we have
3255 already generated the necessary reloc. */
3260 bfd_put_32 (output_bfd
, relocation
,
3261 htab
->elf
.sgot
->contents
+ off
);
3266 Elf_Internal_Rela outrel
;
3269 s
= htab
->elf
.srelgot
;
3273 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3274 + htab
->elf
.sgot
->output_offset
3276 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3278 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3279 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3282 local_got_offsets
[r_symndx
] |= 1;
3286 if (off
>= (bfd_vma
) -2)
3289 relocation
= htab
->elf
.sgot
->output_section
->vma
3290 + htab
->elf
.sgot
->output_offset
+ off
3291 - htab
->elf
.sgotplt
->output_section
->vma
3292 - htab
->elf
.sgotplt
->output_offset
;
3296 /* Relocation is relative to the start of the global offset
3299 /* Check to make sure it isn't a protected function symbol
3300 for shared library since it may not be local when used
3301 as function address. We also need to make sure that a
3302 symbol is defined locally. */
3303 if (info
->shared
&& h
)
3305 if (!h
->def_regular
)
3309 switch (ELF_ST_VISIBILITY (h
->other
))
3312 v
= _("hidden symbol");
3315 v
= _("internal symbol");
3318 v
= _("protected symbol");
3325 (*_bfd_error_handler
)
3326 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3327 input_bfd
, v
, h
->root
.root
.string
);
3328 bfd_set_error (bfd_error_bad_value
);
3331 else if (!info
->executable
3332 && h
->type
== STT_FUNC
3333 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3335 (*_bfd_error_handler
)
3336 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3337 input_bfd
, h
->root
.root
.string
);
3338 bfd_set_error (bfd_error_bad_value
);
3343 /* Note that sgot is not involved in this
3344 calculation. We always want the start of .got.plt. If we
3345 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3346 permitted by the ABI, we might have to change this
3348 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3349 + htab
->elf
.sgotplt
->output_offset
;
3353 /* Use global offset table as symbol value. */
3354 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3355 + htab
->elf
.sgotplt
->output_offset
;
3356 unresolved_reloc
= FALSE
;
3360 /* Relocation is to the entry for this symbol in the
3361 procedure linkage table. */
3363 /* Resolve a PLT32 reloc against a local symbol directly,
3364 without using the procedure linkage table. */
3368 if (h
->plt
.offset
== (bfd_vma
) -1
3369 || htab
->elf
.splt
== NULL
)
3371 /* We didn't make a PLT entry for this symbol. This
3372 happens when statically linking PIC code, or when
3373 using -Bsymbolic. */
3377 relocation
= (htab
->elf
.splt
->output_section
->vma
3378 + htab
->elf
.splt
->output_offset
3380 unresolved_reloc
= FALSE
;
3385 if ((input_section
->flags
& SEC_ALLOC
) == 0
3391 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3392 || h
->root
.type
!= bfd_link_hash_undefweak
)
3393 && (r_type
!= R_386_PC32
3394 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3395 || (ELIMINATE_COPY_RELOCS
3402 || h
->root
.type
== bfd_link_hash_undefweak
3403 || h
->root
.type
== bfd_link_hash_undefined
)))
3405 Elf_Internal_Rela outrel
;
3407 bfd_boolean skip
, relocate
;
3410 /* When generating a shared object, these relocations
3411 are copied into the output file to be resolved at run
3418 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3420 if (outrel
.r_offset
== (bfd_vma
) -1)
3422 else if (outrel
.r_offset
== (bfd_vma
) -2)
3423 skip
= TRUE
, relocate
= TRUE
;
3424 outrel
.r_offset
+= (input_section
->output_section
->vma
3425 + input_section
->output_offset
);
3428 memset (&outrel
, 0, sizeof outrel
);
3431 && (r_type
== R_386_PC32
3433 || !SYMBOLIC_BIND (info
, h
)
3434 || !h
->def_regular
))
3435 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3438 /* This symbol is local, or marked to become local. */
3440 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3443 sreloc
= elf_section_data (input_section
)->sreloc
;
3445 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
3447 loc
= sreloc
->contents
;
3448 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3450 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3452 /* If this reloc is against an external symbol, we do
3453 not want to fiddle with the addend. Otherwise, we
3454 need to include the symbol value so that it becomes
3455 an addend for the dynamic reloc. */
3462 if (!info
->executable
)
3464 Elf_Internal_Rela outrel
;
3468 outrel
.r_offset
= rel
->r_offset
3469 + input_section
->output_section
->vma
3470 + input_section
->output_offset
;
3471 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3472 sreloc
= elf_section_data (input_section
)->sreloc
;
3475 loc
= sreloc
->contents
;
3476 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3477 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3482 case R_386_TLS_GOTDESC
:
3483 case R_386_TLS_DESC_CALL
:
3484 case R_386_TLS_IE_32
:
3485 case R_386_TLS_GOTIE
:
3486 tls_type
= GOT_UNKNOWN
;
3487 if (h
== NULL
&& local_got_offsets
)
3488 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3490 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3491 if (tls_type
== GOT_TLS_IE
)
3492 tls_type
= GOT_TLS_IE_NEG
;
3494 if (! elf_i386_tls_transition (info
, input_bfd
,
3495 input_section
, contents
,
3496 symtab_hdr
, sym_hashes
,
3497 &r_type
, tls_type
, rel
,
3498 relend
, h
, r_symndx
))
3501 if (r_type
== R_386_TLS_LE_32
)
3503 BFD_ASSERT (! unresolved_reloc
);
3504 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3509 /* GD->LE transition. */
3510 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3513 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3515 movl %gs:0, %eax; subl $foo@tpoff, %eax
3516 (6 byte form of subl). */
3517 memcpy (contents
+ rel
->r_offset
- 3,
3518 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3519 roff
= rel
->r_offset
+ 5;
3523 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3525 movl %gs:0, %eax; subl $foo@tpoff, %eax
3526 (6 byte form of subl). */
3527 memcpy (contents
+ rel
->r_offset
- 2,
3528 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3529 roff
= rel
->r_offset
+ 6;
3531 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3533 /* Skip R_386_PC32/R_386_PLT32. */
3537 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3539 /* GDesc -> LE transition.
3540 It's originally something like:
3541 leal x@tlsdesc(%ebx), %eax
3545 Registers other than %eax may be set up here. */
3550 roff
= rel
->r_offset
;
3551 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3553 /* Now modify the instruction as appropriate. */
3554 /* aoliva FIXME: remove the above and xor the byte
3556 bfd_put_8 (output_bfd
, val
^ 0x86,
3557 contents
+ roff
- 1);
3558 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3562 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3564 /* GDesc -> LE transition.
3572 roff
= rel
->r_offset
;
3573 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3574 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3577 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3581 /* IE->LE transition:
3582 Originally it can be one of:
3590 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3593 /* movl foo, %eax. */
3594 bfd_put_8 (output_bfd
, 0xb8,
3595 contents
+ rel
->r_offset
- 1);
3601 type
= bfd_get_8 (input_bfd
,
3602 contents
+ rel
->r_offset
- 2);
3607 bfd_put_8 (output_bfd
, 0xc7,
3608 contents
+ rel
->r_offset
- 2);
3609 bfd_put_8 (output_bfd
,
3610 0xc0 | ((val
>> 3) & 7),
3611 contents
+ rel
->r_offset
- 1);
3615 bfd_put_8 (output_bfd
, 0x81,
3616 contents
+ rel
->r_offset
- 2);
3617 bfd_put_8 (output_bfd
,
3618 0xc0 | ((val
>> 3) & 7),
3619 contents
+ rel
->r_offset
- 1);
3626 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3627 contents
+ rel
->r_offset
);
3632 unsigned int val
, type
;
3634 /* {IE_32,GOTIE}->LE transition:
3635 Originally it can be one of:
3636 subl foo(%reg1), %reg2
3637 movl foo(%reg1), %reg2
3638 addl foo(%reg1), %reg2
3641 movl $foo, %reg2 (6 byte form)
3642 addl $foo, %reg2. */
3643 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3644 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3648 bfd_put_8 (output_bfd
, 0xc7,
3649 contents
+ rel
->r_offset
- 2);
3650 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3651 contents
+ rel
->r_offset
- 1);
3653 else if (type
== 0x2b)
3656 bfd_put_8 (output_bfd
, 0x81,
3657 contents
+ rel
->r_offset
- 2);
3658 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3659 contents
+ rel
->r_offset
- 1);
3661 else if (type
== 0x03)
3664 bfd_put_8 (output_bfd
, 0x81,
3665 contents
+ rel
->r_offset
- 2);
3666 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3667 contents
+ rel
->r_offset
- 1);
3671 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3672 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3673 contents
+ rel
->r_offset
);
3675 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3676 contents
+ rel
->r_offset
);
3681 if (htab
->elf
.sgot
== NULL
)
3686 off
= h
->got
.offset
;
3687 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3691 if (local_got_offsets
== NULL
)
3694 off
= local_got_offsets
[r_symndx
];
3695 offplt
= local_tlsdesc_gotents
[r_symndx
];
3702 Elf_Internal_Rela outrel
;
3707 if (htab
->elf
.srelgot
== NULL
)
3710 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3712 if (GOT_TLS_GDESC_P (tls_type
))
3714 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3715 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3716 <= htab
->elf
.sgotplt
->size
);
3717 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3718 + htab
->elf
.sgotplt
->output_offset
3720 + htab
->sgotplt_jump_table_size
);
3721 sreloc
= htab
->elf
.srelplt
;
3722 loc
= sreloc
->contents
;
3723 loc
+= (htab
->next_tls_desc_index
++
3724 * sizeof (Elf32_External_Rel
));
3725 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3726 <= sreloc
->contents
+ sreloc
->size
);
3727 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3730 BFD_ASSERT (! unresolved_reloc
);
3731 bfd_put_32 (output_bfd
,
3732 relocation
- elf_i386_dtpoff_base (info
),
3733 htab
->elf
.sgotplt
->contents
+ offplt
3734 + htab
->sgotplt_jump_table_size
+ 4);
3738 bfd_put_32 (output_bfd
, 0,
3739 htab
->elf
.sgotplt
->contents
+ offplt
3740 + htab
->sgotplt_jump_table_size
+ 4);
3744 sreloc
= htab
->elf
.srelgot
;
3746 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3747 + htab
->elf
.sgot
->output_offset
+ off
);
3749 if (GOT_TLS_GD_P (tls_type
))
3750 dr_type
= R_386_TLS_DTPMOD32
;
3751 else if (GOT_TLS_GDESC_P (tls_type
))
3753 else if (tls_type
== GOT_TLS_IE_POS
)
3754 dr_type
= R_386_TLS_TPOFF
;
3756 dr_type
= R_386_TLS_TPOFF32
;
3758 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3759 bfd_put_32 (output_bfd
,
3760 relocation
- elf_i386_dtpoff_base (info
),
3761 htab
->elf
.sgot
->contents
+ off
);
3762 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3763 bfd_put_32 (output_bfd
,
3764 elf_i386_dtpoff_base (info
) - relocation
,
3765 htab
->elf
.sgot
->contents
+ off
);
3766 else if (dr_type
!= R_386_TLS_DESC
)
3767 bfd_put_32 (output_bfd
, 0,
3768 htab
->elf
.sgot
->contents
+ off
);
3769 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3771 loc
= sreloc
->contents
;
3772 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3773 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3774 <= sreloc
->contents
+ sreloc
->size
);
3775 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3777 if (GOT_TLS_GD_P (tls_type
))
3781 BFD_ASSERT (! unresolved_reloc
);
3782 bfd_put_32 (output_bfd
,
3783 relocation
- elf_i386_dtpoff_base (info
),
3784 htab
->elf
.sgot
->contents
+ off
+ 4);
3788 bfd_put_32 (output_bfd
, 0,
3789 htab
->elf
.sgot
->contents
+ off
+ 4);
3790 outrel
.r_info
= ELF32_R_INFO (indx
,
3791 R_386_TLS_DTPOFF32
);
3792 outrel
.r_offset
+= 4;
3793 sreloc
->reloc_count
++;
3794 loc
+= sizeof (Elf32_External_Rel
);
3795 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3796 <= sreloc
->contents
+ sreloc
->size
);
3797 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3800 else if (tls_type
== GOT_TLS_IE_BOTH
)
3802 bfd_put_32 (output_bfd
,
3804 ? relocation
- elf_i386_dtpoff_base (info
)
3806 htab
->elf
.sgot
->contents
+ off
+ 4);
3807 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3808 outrel
.r_offset
+= 4;
3809 sreloc
->reloc_count
++;
3810 loc
+= sizeof (Elf32_External_Rel
);
3811 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3818 local_got_offsets
[r_symndx
] |= 1;
3821 if (off
>= (bfd_vma
) -2
3822 && ! GOT_TLS_GDESC_P (tls_type
))
3824 if (r_type
== R_386_TLS_GOTDESC
3825 || r_type
== R_386_TLS_DESC_CALL
)
3827 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3828 unresolved_reloc
= FALSE
;
3830 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3832 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3833 + htab
->elf
.sgotplt
->output_offset
;
3834 relocation
= htab
->elf
.sgot
->output_section
->vma
3835 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3836 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3837 && tls_type
== GOT_TLS_IE_BOTH
)
3839 if (r_type
== R_386_TLS_IE
)
3840 relocation
+= g_o_t
;
3841 unresolved_reloc
= FALSE
;
3843 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3845 unsigned int val
, type
;
3848 /* GD->IE transition. */
3849 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3850 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3853 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3855 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3857 roff
= rel
->r_offset
- 3;
3861 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3863 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3864 roff
= rel
->r_offset
- 2;
3866 memcpy (contents
+ roff
,
3867 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3868 contents
[roff
+ 7] = 0x80 | (val
& 7);
3869 /* If foo is used only with foo@gotntpoff(%reg) and
3870 foo@indntpoff, but not with foo@gottpoff(%reg), change
3871 subl $foo@gottpoff(%reg), %eax
3873 addl $foo@gotntpoff(%reg), %eax. */
3874 if (tls_type
== GOT_TLS_IE_POS
)
3875 contents
[roff
+ 6] = 0x03;
3876 bfd_put_32 (output_bfd
,
3877 htab
->elf
.sgot
->output_section
->vma
3878 + htab
->elf
.sgot
->output_offset
+ off
3879 - htab
->elf
.sgotplt
->output_section
->vma
3880 - htab
->elf
.sgotplt
->output_offset
,
3881 contents
+ roff
+ 8);
3882 /* Skip R_386_PLT32. */
3886 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3888 /* GDesc -> IE transition.
3889 It's originally something like:
3890 leal x@tlsdesc(%ebx), %eax
3893 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3895 movl x@gottpoff(%ebx), %eax # before negl %eax
3897 Registers other than %eax may be set up here. */
3901 /* First, make sure it's a leal adding ebx to a 32-bit
3902 offset into any register, although it's probably
3903 almost always going to be eax. */
3904 roff
= rel
->r_offset
;
3906 /* Now modify the instruction as appropriate. */
3907 /* To turn a leal into a movl in the form we use it, it
3908 suffices to change the first byte from 0x8d to 0x8b.
3909 aoliva FIXME: should we decide to keep the leal, all
3910 we have to do is remove the statement below, and
3911 adjust the relaxation of R_386_TLS_DESC_CALL. */
3912 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3914 if (tls_type
== GOT_TLS_IE_BOTH
)
3917 bfd_put_32 (output_bfd
,
3918 htab
->elf
.sgot
->output_section
->vma
3919 + htab
->elf
.sgot
->output_offset
+ off
3920 - htab
->elf
.sgotplt
->output_section
->vma
3921 - htab
->elf
.sgotplt
->output_offset
,
3925 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3927 /* GDesc -> IE transition.
3935 depending on how we transformed the TLS_GOTDESC above.
3940 roff
= rel
->r_offset
;
3942 /* Now modify the instruction as appropriate. */
3943 if (tls_type
!= GOT_TLS_IE_NEG
)
3946 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3947 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3952 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3953 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3963 if (! elf_i386_tls_transition (info
, input_bfd
,
3964 input_section
, contents
,
3965 symtab_hdr
, sym_hashes
,
3966 &r_type
, GOT_UNKNOWN
, rel
,
3967 relend
, h
, r_symndx
))
3970 if (r_type
!= R_386_TLS_LDM
)
3972 /* LD->LE transition:
3973 leal foo(%reg), %eax; call ___tls_get_addr.
3975 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3976 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3977 memcpy (contents
+ rel
->r_offset
- 2,
3978 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3979 /* Skip R_386_PC32/R_386_PLT32. */
3984 if (htab
->elf
.sgot
== NULL
)
3987 off
= htab
->tls_ldm_got
.offset
;
3992 Elf_Internal_Rela outrel
;
3995 if (htab
->elf
.srelgot
== NULL
)
3998 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3999 + htab
->elf
.sgot
->output_offset
+ off
);
4001 bfd_put_32 (output_bfd
, 0,
4002 htab
->elf
.sgot
->contents
+ off
);
4003 bfd_put_32 (output_bfd
, 0,
4004 htab
->elf
.sgot
->contents
+ off
+ 4);
4005 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4006 loc
= htab
->elf
.srelgot
->contents
;
4007 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4008 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4009 htab
->tls_ldm_got
.offset
|= 1;
4011 relocation
= htab
->elf
.sgot
->output_section
->vma
4012 + htab
->elf
.sgot
->output_offset
+ off
4013 - htab
->elf
.sgotplt
->output_section
->vma
4014 - htab
->elf
.sgotplt
->output_offset
;
4015 unresolved_reloc
= FALSE
;
4018 case R_386_TLS_LDO_32
:
4019 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
4020 relocation
-= elf_i386_dtpoff_base (info
);
4022 /* When converting LDO to LE, we must negate. */
4023 relocation
= -elf_i386_tpoff (info
, relocation
);
4026 case R_386_TLS_LE_32
:
4028 if (!info
->executable
)
4030 Elf_Internal_Rela outrel
;
4034 outrel
.r_offset
= rel
->r_offset
4035 + input_section
->output_section
->vma
4036 + input_section
->output_offset
;
4037 if (h
!= NULL
&& h
->dynindx
!= -1)
4041 if (r_type
== R_386_TLS_LE_32
)
4042 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4044 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4045 sreloc
= elf_section_data (input_section
)->sreloc
;
4048 loc
= sreloc
->contents
;
4049 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4050 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4053 else if (r_type
== R_386_TLS_LE_32
)
4054 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4056 relocation
-= elf_i386_dtpoff_base (info
);
4058 else if (r_type
== R_386_TLS_LE_32
)
4059 relocation
= elf_i386_tpoff (info
, relocation
);
4061 relocation
= -elf_i386_tpoff (info
, relocation
);
4068 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4069 because such sections are not SEC_ALLOC and thus ld.so will
4070 not process them. */
4071 if (unresolved_reloc
4072 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4075 (*_bfd_error_handler
)
4076 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4079 (long) rel
->r_offset
,
4081 h
->root
.root
.string
);
4086 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4087 contents
, rel
->r_offset
,
4090 if (r
!= bfd_reloc_ok
)
4095 name
= h
->root
.root
.string
;
4098 name
= bfd_elf_string_from_elf_section (input_bfd
,
4099 symtab_hdr
->sh_link
,
4104 name
= bfd_section_name (input_bfd
, sec
);
4107 if (r
== bfd_reloc_overflow
)
4109 if (! ((*info
->callbacks
->reloc_overflow
)
4110 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4111 (bfd_vma
) 0, input_bfd
, input_section
,
4117 (*_bfd_error_handler
)
4118 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4119 input_bfd
, input_section
,
4120 (long) rel
->r_offset
, name
, (int) r
);
4129 /* Finish up dynamic symbol handling. We set the contents of various
4130 dynamic sections here. */
4133 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4134 struct bfd_link_info
*info
,
4135 struct elf_link_hash_entry
*h
,
4136 Elf_Internal_Sym
*sym
)
4138 struct elf_i386_link_hash_table
*htab
;
4140 htab
= elf_i386_hash_table (info
);
4144 if (h
->plt
.offset
!= (bfd_vma
) -1)
4148 Elf_Internal_Rela rel
;
4150 asection
*plt
, *gotplt
, *relplt
;
4152 /* When building a static executable, use .iplt, .igot.plt and
4153 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4154 if (htab
->elf
.splt
!= NULL
)
4156 plt
= htab
->elf
.splt
;
4157 gotplt
= htab
->elf
.sgotplt
;
4158 relplt
= htab
->elf
.srelplt
;
4162 plt
= htab
->elf
.iplt
;
4163 gotplt
= htab
->elf
.igotplt
;
4164 relplt
= htab
->elf
.irelplt
;
4167 /* This symbol has an entry in the procedure linkage table. Set
4170 if ((h
->dynindx
== -1
4171 && !((h
->forced_local
|| info
->executable
)
4173 && h
->type
== STT_GNU_IFUNC
))
4179 /* Get the index in the procedure linkage table which
4180 corresponds to this symbol. This is the index of this symbol
4181 in all the symbols for which we are making plt entries. The
4182 first entry in the procedure linkage table is reserved.
4184 Get the offset into the .got table of the entry that
4185 corresponds to this function. Each .got entry is 4 bytes.
4186 The first three are reserved.
4188 For static executables, we don't reserve anything. */
4190 if (plt
== htab
->elf
.splt
)
4192 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
4193 got_offset
= (plt_index
+ 3) * 4;
4197 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4198 got_offset
= plt_index
* 4;
4201 /* Fill in the entry in the procedure linkage table. */
4204 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
4206 bfd_put_32 (output_bfd
,
4207 (gotplt
->output_section
->vma
4208 + gotplt
->output_offset
4210 plt
->contents
+ h
->plt
.offset
+ 2);
4212 if (htab
->is_vxworks
)
4214 int s
, k
, reloc_index
;
4216 /* Create the R_386_32 relocation referencing the GOT
4217 for this PLT entry. */
4219 /* S: Current slot number (zero-based). */
4220 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
4221 /* K: Number of relocations for PLTResolve. */
4223 k
= PLTRESOLVE_RELOCS_SHLIB
;
4225 k
= PLTRESOLVE_RELOCS
;
4226 /* Skip the PLTresolve relocations, and the relocations for
4227 the other PLT slots. */
4228 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4229 loc
= (htab
->srelplt2
->contents
+ reloc_index
4230 * sizeof (Elf32_External_Rel
));
4232 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4233 + htab
->elf
.splt
->output_offset
4234 + h
->plt
.offset
+ 2),
4235 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4236 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4238 /* Create the R_386_32 relocation referencing the beginning of
4239 the PLT for this GOT entry. */
4240 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4241 + htab
->elf
.sgotplt
->output_offset
4243 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4244 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4245 loc
+ sizeof (Elf32_External_Rel
));
4250 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
4252 bfd_put_32 (output_bfd
, got_offset
,
4253 plt
->contents
+ h
->plt
.offset
+ 2);
4256 /* Don't fill PLT entry for static executables. */
4257 if (plt
== htab
->elf
.splt
)
4259 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4260 plt
->contents
+ h
->plt
.offset
+ 7);
4261 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4262 plt
->contents
+ h
->plt
.offset
+ 12);
4265 /* Fill in the entry in the global offset table. */
4266 bfd_put_32 (output_bfd
,
4267 (plt
->output_section
->vma
4268 + plt
->output_offset
4271 gotplt
->contents
+ got_offset
);
4273 /* Fill in the entry in the .rel.plt section. */
4274 rel
.r_offset
= (gotplt
->output_section
->vma
4275 + gotplt
->output_offset
4277 if (h
->dynindx
== -1
4278 || ((info
->executable
4279 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4281 && h
->type
== STT_GNU_IFUNC
))
4283 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4284 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4285 in the .got.plt section. */
4286 bfd_put_32 (output_bfd
,
4287 (h
->root
.u
.def
.value
4288 + h
->root
.u
.def
.section
->output_section
->vma
4289 + h
->root
.u
.def
.section
->output_offset
),
4290 gotplt
->contents
+ got_offset
);
4291 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4294 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4295 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4296 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4298 if (!h
->def_regular
)
4300 /* Mark the symbol as undefined, rather than as defined in
4301 the .plt section. Leave the value if there were any
4302 relocations where pointer equality matters (this is a clue
4303 for the dynamic linker, to make function pointer
4304 comparisons work between an application and shared
4305 library), otherwise set it to zero. If a function is only
4306 called from a binary, there is no need to slow down
4307 shared libraries because of that. */
4308 sym
->st_shndx
= SHN_UNDEF
;
4309 if (!h
->pointer_equality_needed
)
4314 if (h
->got
.offset
!= (bfd_vma
) -1
4315 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4316 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4318 Elf_Internal_Rela rel
;
4321 /* This symbol has an entry in the global offset table. Set it
4324 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4327 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4328 + htab
->elf
.sgot
->output_offset
4329 + (h
->got
.offset
& ~(bfd_vma
) 1));
4331 /* If this is a static link, or it is a -Bsymbolic link and the
4332 symbol is defined locally or was forced to be local because
4333 of a version file, we just want to emit a RELATIVE reloc.
4334 The entry in the global offset table will already have been
4335 initialized in the relocate_section function. */
4337 && h
->type
== STT_GNU_IFUNC
)
4341 /* Generate R_386_GLOB_DAT. */
4348 if (!h
->pointer_equality_needed
)
4351 /* For non-shared object, we can't use .got.plt, which
4352 contains the real function addres if we need pointer
4353 equality. We load the GOT entry with the PLT entry. */
4354 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4355 bfd_put_32 (output_bfd
,
4356 (plt
->output_section
->vma
4357 + plt
->output_offset
+ h
->plt
.offset
),
4358 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4362 else if (info
->shared
4363 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4365 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4366 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4370 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4372 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4373 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4374 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4377 loc
= htab
->elf
.srelgot
->contents
;
4378 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4379 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4384 Elf_Internal_Rela rel
;
4387 /* This symbol needs a copy reloc. Set it up. */
4389 if (h
->dynindx
== -1
4390 || (h
->root
.type
!= bfd_link_hash_defined
4391 && h
->root
.type
!= bfd_link_hash_defweak
)
4392 || htab
->srelbss
== NULL
)
4395 rel
.r_offset
= (h
->root
.u
.def
.value
4396 + h
->root
.u
.def
.section
->output_section
->vma
4397 + h
->root
.u
.def
.section
->output_offset
);
4398 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4399 loc
= htab
->srelbss
->contents
;
4400 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4401 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4404 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4405 be NULL for local symbols.
4407 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
4408 is relative to the ".got" section. */
4410 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4411 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
)))
4412 sym
->st_shndx
= SHN_ABS
;
4417 /* Finish up local dynamic symbol handling. We set the contents of
4418 various dynamic sections here. */
4421 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4423 struct elf_link_hash_entry
*h
4424 = (struct elf_link_hash_entry
*) *slot
;
4425 struct bfd_link_info
*info
4426 = (struct bfd_link_info
*) inf
;
4428 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4432 /* Used to decide how to sort relocs in an optimal manner for the
4433 dynamic linker, before writing them out. */
4435 static enum elf_reloc_type_class
4436 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4438 switch (ELF32_R_TYPE (rela
->r_info
))
4440 case R_386_RELATIVE
:
4441 return reloc_class_relative
;
4442 case R_386_JUMP_SLOT
:
4443 return reloc_class_plt
;
4445 return reloc_class_copy
;
4447 return reloc_class_normal
;
4451 /* Finish up the dynamic sections. */
4454 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4455 struct bfd_link_info
*info
)
4457 struct elf_i386_link_hash_table
*htab
;
4461 htab
= elf_i386_hash_table (info
);
4465 dynobj
= htab
->elf
.dynobj
;
4466 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4468 if (htab
->elf
.dynamic_sections_created
)
4470 Elf32_External_Dyn
*dyncon
, *dynconend
;
4472 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4475 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4476 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4477 for (; dyncon
< dynconend
; dyncon
++)
4479 Elf_Internal_Dyn dyn
;
4482 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4487 if (htab
->is_vxworks
4488 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4493 s
= htab
->elf
.sgotplt
;
4494 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4498 s
= htab
->elf
.srelplt
;
4499 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4503 s
= htab
->elf
.srelplt
;
4504 dyn
.d_un
.d_val
= s
->size
;
4508 /* My reading of the SVR4 ABI indicates that the
4509 procedure linkage table relocs (DT_JMPREL) should be
4510 included in the overall relocs (DT_REL). This is
4511 what Solaris does. However, UnixWare can not handle
4512 that case. Therefore, we override the DT_RELSZ entry
4513 here to make it not include the JMPREL relocs. */
4514 s
= htab
->elf
.srelplt
;
4517 dyn
.d_un
.d_val
-= s
->size
;
4521 /* We may not be using the standard ELF linker script.
4522 If .rel.plt is the first .rel section, we adjust
4523 DT_REL to not include it. */
4524 s
= htab
->elf
.srelplt
;
4527 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4529 dyn
.d_un
.d_ptr
+= s
->size
;
4533 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4536 /* Fill in the first entry in the procedure linkage table. */
4537 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4541 memcpy (htab
->elf
.splt
->contents
, elf_i386_pic_plt0_entry
,
4542 sizeof (elf_i386_pic_plt0_entry
));
4543 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
4544 htab
->plt0_pad_byte
,
4545 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
4549 memcpy (htab
->elf
.splt
->contents
, elf_i386_plt0_entry
,
4550 sizeof(elf_i386_plt0_entry
));
4551 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_plt0_entry
),
4552 htab
->plt0_pad_byte
,
4553 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
4554 bfd_put_32 (output_bfd
,
4555 (htab
->elf
.sgotplt
->output_section
->vma
4556 + htab
->elf
.sgotplt
->output_offset
4558 htab
->elf
.splt
->contents
+ 2);
4559 bfd_put_32 (output_bfd
,
4560 (htab
->elf
.sgotplt
->output_section
->vma
4561 + htab
->elf
.sgotplt
->output_offset
4563 htab
->elf
.splt
->contents
+ 8);
4565 if (htab
->is_vxworks
)
4567 Elf_Internal_Rela rel
;
4569 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4570 On IA32 we use REL relocations so the addend goes in
4571 the PLT directly. */
4572 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4573 + htab
->elf
.splt
->output_offset
4575 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4576 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4577 htab
->srelplt2
->contents
);
4578 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4579 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4580 + htab
->elf
.splt
->output_offset
4582 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4583 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4584 htab
->srelplt2
->contents
+
4585 sizeof (Elf32_External_Rel
));
4589 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4590 really seem like the right value. */
4591 elf_section_data (htab
->elf
.splt
->output_section
)
4592 ->this_hdr
.sh_entsize
= 4;
4594 /* Correct the .rel.plt.unloaded relocations. */
4595 if (htab
->is_vxworks
&& !info
->shared
)
4597 int num_plts
= (htab
->elf
.splt
->size
/ PLT_ENTRY_SIZE
) - 1;
4600 p
= htab
->srelplt2
->contents
;
4602 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4604 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4606 for (; num_plts
; num_plts
--)
4608 Elf_Internal_Rela rel
;
4609 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4610 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4611 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4612 p
+= sizeof (Elf32_External_Rel
);
4614 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4615 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4616 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4617 p
+= sizeof (Elf32_External_Rel
);
4623 if (htab
->elf
.sgotplt
)
4625 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4627 (*_bfd_error_handler
)
4628 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4632 /* Fill in the first three entries in the global offset table. */
4633 if (htab
->elf
.sgotplt
->size
> 0)
4635 bfd_put_32 (output_bfd
,
4637 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4638 htab
->elf
.sgotplt
->contents
);
4639 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4640 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4643 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4646 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4647 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4649 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4650 htab_traverse (htab
->loc_hash_table
,
4651 elf_i386_finish_local_dynamic_symbol
,
4657 /* Return address for Ith PLT stub in section PLT, for relocation REL
4658 or (bfd_vma) -1 if it should not be included. */
4661 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4662 const arelent
*rel ATTRIBUTE_UNUSED
)
4664 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4667 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4670 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4672 if (h
->plt
.offset
!= (bfd_vma
) -1
4674 && !h
->pointer_equality_needed
)
4677 return _bfd_elf_hash_symbol (h
);
4680 /* Hook called by the linker routine which adds symbols from an object
4684 elf_i386_add_symbol_hook (bfd
* abfd
,
4685 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4686 Elf_Internal_Sym
* sym
,
4687 const char ** namep ATTRIBUTE_UNUSED
,
4688 flagword
* flagsp ATTRIBUTE_UNUSED
,
4689 asection
** secp ATTRIBUTE_UNUSED
,
4690 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4692 if ((abfd
->flags
& DYNAMIC
) == 0
4693 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4694 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
4699 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4700 #define TARGET_LITTLE_NAME "elf32-i386"
4701 #define ELF_ARCH bfd_arch_i386
4702 #define ELF_TARGET_ID I386_ELF_DATA
4703 #define ELF_MACHINE_CODE EM_386
4704 #define ELF_MAXPAGESIZE 0x1000
4706 #define elf_backend_can_gc_sections 1
4707 #define elf_backend_can_refcount 1
4708 #define elf_backend_want_got_plt 1
4709 #define elf_backend_plt_readonly 1
4710 #define elf_backend_want_plt_sym 0
4711 #define elf_backend_got_header_size 12
4713 /* Support RELA for objdump of prelink objects. */
4714 #define elf_info_to_howto elf_i386_info_to_howto_rel
4715 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4717 #define bfd_elf32_mkobject elf_i386_mkobject
4719 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4720 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4721 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4722 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4723 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4725 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4726 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4727 #define elf_backend_check_relocs elf_i386_check_relocs
4728 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4729 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4730 #define elf_backend_fake_sections elf_i386_fake_sections
4731 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4732 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4733 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4734 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4735 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4736 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4737 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4738 #define elf_backend_relocate_section elf_i386_relocate_section
4739 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4740 #define elf_backend_always_size_sections elf_i386_always_size_sections
4741 #define elf_backend_omit_section_dynsym \
4742 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4743 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4744 #define elf_backend_hash_symbol elf_i386_hash_symbol
4745 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4746 #undef elf_backend_post_process_headers
4747 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4749 #include "elf32-target.h"
4751 /* FreeBSD support. */
4753 #undef TARGET_LITTLE_SYM
4754 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4755 #undef TARGET_LITTLE_NAME
4756 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4758 #define ELF_OSABI ELFOSABI_FREEBSD
4760 /* The kernel recognizes executables as valid only if they carry a
4761 "FreeBSD" label in the ELF header. So we put this label on all
4762 executables and (for simplicity) also all other object files. */
4765 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4767 _bfd_elf_set_osabi (abfd
, info
);
4769 #ifdef OLD_FREEBSD_ABI_LABEL
4770 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4771 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4775 #undef elf_backend_post_process_headers
4776 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4778 #define elf32_bed elf32_i386_fbsd_bed
4780 #undef elf_backend_add_symbol_hook
4782 #include "elf32-target.h"
4786 #undef TARGET_LITTLE_SYM
4787 #define TARGET_LITTLE_SYM bfd_elf32_i386_sol2_vec
4788 #undef TARGET_LITTLE_NAME
4789 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
4791 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4792 objects won't be recognized. */
4796 #define elf32_bed elf32_i386_sol2_bed
4798 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4800 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4802 #undef elf_backend_want_plt_sym
4803 #define elf_backend_want_plt_sym 1
4805 #include "elf32-target.h"
4807 /* VxWorks support. */
4809 #undef TARGET_LITTLE_SYM
4810 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
4811 #undef TARGET_LITTLE_NAME
4812 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4815 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
4817 static struct bfd_link_hash_table
*
4818 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
4820 struct bfd_link_hash_table
*ret
;
4821 struct elf_i386_link_hash_table
*htab
;
4823 ret
= elf_i386_link_hash_table_create (abfd
);
4826 htab
= (struct elf_i386_link_hash_table
*) ret
;
4827 htab
->is_vxworks
= 1;
4828 htab
->plt0_pad_byte
= 0x90;
4835 #undef elf_backend_relocs_compatible
4836 #undef elf_backend_post_process_headers
4837 #undef bfd_elf32_bfd_link_hash_table_create
4838 #define bfd_elf32_bfd_link_hash_table_create \
4839 elf_i386_vxworks_link_hash_table_create
4840 #undef elf_backend_add_symbol_hook
4841 #define elf_backend_add_symbol_hook \
4842 elf_vxworks_add_symbol_hook
4843 #undef elf_backend_link_output_symbol_hook
4844 #define elf_backend_link_output_symbol_hook \
4845 elf_vxworks_link_output_symbol_hook
4846 #undef elf_backend_emit_relocs
4847 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
4848 #undef elf_backend_final_write_processing
4849 #define elf_backend_final_write_processing \
4850 elf_vxworks_final_write_processing
4852 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
4854 #undef elf_backend_want_plt_sym
4855 #define elf_backend_want_plt_sym 1
4858 #define elf32_bed elf32_i386_vxworks_bed
4860 #include "elf32-target.h"