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 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
28 #include "bfd_stdint.h"
32 /* 386 uses REL relocations instead of RELA. */
37 static reloc_howto_type elf_howto_table
[]=
39 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
40 bfd_elf_generic_reloc
, "R_386_NONE",
41 TRUE
, 0x00000000, 0x00000000, FALSE
),
42 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
43 bfd_elf_generic_reloc
, "R_386_32",
44 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
45 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
46 bfd_elf_generic_reloc
, "R_386_PC32",
47 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
48 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
49 bfd_elf_generic_reloc
, "R_386_GOT32",
50 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
51 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
52 bfd_elf_generic_reloc
, "R_386_PLT32",
53 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
54 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
55 bfd_elf_generic_reloc
, "R_386_COPY",
56 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
57 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
58 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
59 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
60 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
61 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
62 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
63 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_386_RELATIVE",
65 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
66 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_386_GOTOFF",
68 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
69 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
70 bfd_elf_generic_reloc
, "R_386_GOTPC",
71 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
73 /* We have a gap in the reloc numbers here.
74 R_386_standard counts the number up to this point, and
75 R_386_ext_offset is the value to subtract from a reloc type of
76 R_386_16 thru R_386_PC8 to form an index into this table. */
77 #define R_386_standard (R_386_GOTPC + 1)
78 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
80 /* These relocs are a GNU extension. */
81 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
82 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
83 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
84 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_386_TLS_IE",
86 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
87 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
89 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
90 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
91 bfd_elf_generic_reloc
, "R_386_TLS_LE",
92 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
93 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
94 bfd_elf_generic_reloc
, "R_386_TLS_GD",
95 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
96 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
98 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
99 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
100 bfd_elf_generic_reloc
, "R_386_16",
101 TRUE
, 0xffff, 0xffff, FALSE
),
102 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_386_PC16",
104 TRUE
, 0xffff, 0xffff, TRUE
),
105 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_386_8",
107 TRUE
, 0xff, 0xff, FALSE
),
108 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
109 bfd_elf_generic_reloc
, "R_386_PC8",
110 TRUE
, 0xff, 0xff, TRUE
),
112 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
113 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
114 /* These are common with Solaris TLS implementation. */
115 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
116 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
117 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
118 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
119 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
120 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
121 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
122 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
123 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
124 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
125 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
126 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
127 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
129 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
130 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
131 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
132 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
135 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
136 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
137 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
138 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
140 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
141 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
142 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
143 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
148 #define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
149 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
151 /* GNU extension to record C++ vtable hierarchy. */
152 HOWTO (R_386_GNU_VTINHERIT
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_dont
, /* complain_on_overflow */
159 NULL
, /* special_function */
160 "R_386_GNU_VTINHERIT", /* name */
161 FALSE
, /* partial_inplace */
164 FALSE
), /* pcrel_offset */
166 /* GNU extension to record C++ vtable member usage. */
167 HOWTO (R_386_GNU_VTENTRY
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE
, /* pc_relative */
173 complain_overflow_dont
, /* complain_on_overflow */
174 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
175 "R_386_GNU_VTENTRY", /* name */
176 FALSE
, /* partial_inplace */
179 FALSE
) /* pcrel_offset */
181 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
185 #ifdef DEBUG_GEN_RELOC
187 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
192 static reloc_howto_type
*
193 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
194 bfd_reloc_code_real_type code
)
199 TRACE ("BFD_RELOC_NONE");
200 return &elf_howto_table
[R_386_NONE
];
203 TRACE ("BFD_RELOC_32");
204 return &elf_howto_table
[R_386_32
];
207 TRACE ("BFD_RELOC_CTOR");
208 return &elf_howto_table
[R_386_32
];
210 case BFD_RELOC_32_PCREL
:
211 TRACE ("BFD_RELOC_PC32");
212 return &elf_howto_table
[R_386_PC32
];
214 case BFD_RELOC_386_GOT32
:
215 TRACE ("BFD_RELOC_386_GOT32");
216 return &elf_howto_table
[R_386_GOT32
];
218 case BFD_RELOC_386_PLT32
:
219 TRACE ("BFD_RELOC_386_PLT32");
220 return &elf_howto_table
[R_386_PLT32
];
222 case BFD_RELOC_386_COPY
:
223 TRACE ("BFD_RELOC_386_COPY");
224 return &elf_howto_table
[R_386_COPY
];
226 case BFD_RELOC_386_GLOB_DAT
:
227 TRACE ("BFD_RELOC_386_GLOB_DAT");
228 return &elf_howto_table
[R_386_GLOB_DAT
];
230 case BFD_RELOC_386_JUMP_SLOT
:
231 TRACE ("BFD_RELOC_386_JUMP_SLOT");
232 return &elf_howto_table
[R_386_JUMP_SLOT
];
234 case BFD_RELOC_386_RELATIVE
:
235 TRACE ("BFD_RELOC_386_RELATIVE");
236 return &elf_howto_table
[R_386_RELATIVE
];
238 case BFD_RELOC_386_GOTOFF
:
239 TRACE ("BFD_RELOC_386_GOTOFF");
240 return &elf_howto_table
[R_386_GOTOFF
];
242 case BFD_RELOC_386_GOTPC
:
243 TRACE ("BFD_RELOC_386_GOTPC");
244 return &elf_howto_table
[R_386_GOTPC
];
246 /* These relocs are a GNU extension. */
247 case BFD_RELOC_386_TLS_TPOFF
:
248 TRACE ("BFD_RELOC_386_TLS_TPOFF");
249 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
251 case BFD_RELOC_386_TLS_IE
:
252 TRACE ("BFD_RELOC_386_TLS_IE");
253 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
255 case BFD_RELOC_386_TLS_GOTIE
:
256 TRACE ("BFD_RELOC_386_TLS_GOTIE");
257 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
259 case BFD_RELOC_386_TLS_LE
:
260 TRACE ("BFD_RELOC_386_TLS_LE");
261 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
263 case BFD_RELOC_386_TLS_GD
:
264 TRACE ("BFD_RELOC_386_TLS_GD");
265 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
267 case BFD_RELOC_386_TLS_LDM
:
268 TRACE ("BFD_RELOC_386_TLS_LDM");
269 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
272 TRACE ("BFD_RELOC_16");
273 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
275 case BFD_RELOC_16_PCREL
:
276 TRACE ("BFD_RELOC_16_PCREL");
277 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
280 TRACE ("BFD_RELOC_8");
281 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
283 case BFD_RELOC_8_PCREL
:
284 TRACE ("BFD_RELOC_8_PCREL");
285 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
287 /* Common with Sun TLS implementation. */
288 case BFD_RELOC_386_TLS_LDO_32
:
289 TRACE ("BFD_RELOC_386_TLS_LDO_32");
290 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
292 case BFD_RELOC_386_TLS_IE_32
:
293 TRACE ("BFD_RELOC_386_TLS_IE_32");
294 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
296 case BFD_RELOC_386_TLS_LE_32
:
297 TRACE ("BFD_RELOC_386_TLS_LE_32");
298 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
300 case BFD_RELOC_386_TLS_DTPMOD32
:
301 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
302 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
304 case BFD_RELOC_386_TLS_DTPOFF32
:
305 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
306 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
308 case BFD_RELOC_386_TLS_TPOFF32
:
309 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
310 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
312 case BFD_RELOC_386_TLS_GOTDESC
:
313 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
314 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
316 case BFD_RELOC_386_TLS_DESC_CALL
:
317 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
318 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
320 case BFD_RELOC_386_TLS_DESC
:
321 TRACE ("BFD_RELOC_386_TLS_DESC");
322 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
324 case BFD_RELOC_386_IRELATIVE
:
325 TRACE ("BFD_RELOC_386_IRELATIVE");
326 return &elf_howto_table
[R_386_IRELATIVE
];
328 case BFD_RELOC_VTABLE_INHERIT
:
329 TRACE ("BFD_RELOC_VTABLE_INHERIT");
330 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
332 case BFD_RELOC_VTABLE_ENTRY
:
333 TRACE ("BFD_RELOC_VTABLE_ENTRY");
334 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
344 static reloc_howto_type
*
345 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
350 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
351 if (elf_howto_table
[i
].name
!= NULL
352 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
353 return &elf_howto_table
[i
];
358 static reloc_howto_type
*
359 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
363 if ((indx
= r_type
) >= R_386_standard
364 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
365 >= R_386_ext
- R_386_standard
)
366 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
367 >= R_386_irelative
- R_386_ext
)
368 && ((indx
= r_type
- R_386_vt_offset
) - R_386_irelative
369 >= R_386_vt
- R_386_irelative
))
371 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
375 BFD_ASSERT (elf_howto_table
[indx
].type
== r_type
);
376 return &elf_howto_table
[indx
];
380 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
382 Elf_Internal_Rela
*dst
)
384 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
385 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
388 /* Return whether a symbol name implies a local label. The UnixWare
389 2.1 cc generates temporary symbols that start with .X, so we
390 recognize them here. FIXME: do other SVR4 compilers also use .X?.
391 If so, we should move the .X recognition into
392 _bfd_elf_is_local_label_name. */
395 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
397 if (name
[0] == '.' && name
[1] == 'X')
400 return _bfd_elf_is_local_label_name (abfd
, name
);
403 /* Support for core dump NOTE sections. */
406 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
411 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
413 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
419 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
422 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
426 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
430 switch (note
->descsz
)
435 case 144: /* Linux/i386 */
437 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
440 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
450 /* Make a ".reg/999" section. */
451 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
452 size
, note
->descpos
+ offset
);
456 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
458 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
460 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
465 elf_tdata (abfd
)->core_program
466 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
467 elf_tdata (abfd
)->core_command
468 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
472 switch (note
->descsz
)
477 case 124: /* Linux/i386 elf_prpsinfo. */
478 elf_tdata (abfd
)->core_program
479 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
480 elf_tdata (abfd
)->core_command
481 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
485 /* Note that for some reason, a spurious space is tacked
486 onto the end of the args in some (at least one anyway)
487 implementations, so strip it off if it exists. */
489 char *command
= elf_tdata (abfd
)->core_command
;
490 int n
= strlen (command
);
492 if (0 < n
&& command
[n
- 1] == ' ')
493 command
[n
- 1] = '\0';
499 /* Functions for the i386 ELF linker.
501 In order to gain some understanding of code in this file without
502 knowing all the intricate details of the linker, note the
505 Functions named elf_i386_* are called by external routines, other
506 functions are only called locally. elf_i386_* functions appear
507 in this file more or less in the order in which they are called
508 from external routines. eg. elf_i386_check_relocs is called
509 early in the link process, elf_i386_finish_dynamic_sections is
510 one of the last functions. */
513 /* The name of the dynamic interpreter. This is put in the .interp
516 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
518 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
519 copying dynamic variables from a shared lib into an app's dynbss
520 section, and instead use a dynamic relocation to point into the
522 #define ELIMINATE_COPY_RELOCS 1
524 /* The size in bytes of an entry in the procedure linkage table. */
526 #define PLT_ENTRY_SIZE 16
528 /* The first entry in an absolute procedure linkage table looks like
529 this. See the SVR4 ABI i386 supplement to see how this works.
530 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
532 static const bfd_byte elf_i386_plt0_entry
[12] =
534 0xff, 0x35, /* pushl contents of address */
535 0, 0, 0, 0, /* replaced with address of .got + 4. */
536 0xff, 0x25, /* jmp indirect */
537 0, 0, 0, 0 /* replaced with address of .got + 8. */
540 /* Subsequent entries in an absolute procedure linkage table look like
543 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
545 0xff, 0x25, /* jmp indirect */
546 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
547 0x68, /* pushl immediate */
548 0, 0, 0, 0, /* replaced with offset into relocation table. */
549 0xe9, /* jmp relative */
550 0, 0, 0, 0 /* replaced with offset to start of .plt. */
553 /* The first entry in a PIC procedure linkage table look like this.
554 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
556 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
558 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
559 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
562 /* Subsequent entries in a PIC procedure linkage table look like this. */
564 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
566 0xff, 0xa3, /* jmp *offset(%ebx) */
567 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
568 0x68, /* pushl immediate */
569 0, 0, 0, 0, /* replaced with offset into relocation table. */
570 0xe9, /* jmp relative */
571 0, 0, 0, 0 /* replaced with offset to start of .plt. */
574 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
575 for the PLTResolve stub and then for each PLT entry. */
576 #define PLTRESOLVE_RELOCS_SHLIB 0
577 #define PLTRESOLVE_RELOCS 2
578 #define PLT_NON_JUMP_SLOT_RELOCS 2
580 /* i386 ELF linker hash entry. */
582 struct elf_i386_link_hash_entry
584 struct elf_link_hash_entry elf
;
586 /* Track dynamic relocs copied for this symbol. */
587 struct elf_dyn_relocs
*dyn_relocs
;
589 #define GOT_UNKNOWN 0
593 #define GOT_TLS_IE_POS 5
594 #define GOT_TLS_IE_NEG 6
595 #define GOT_TLS_IE_BOTH 7
596 #define GOT_TLS_GDESC 8
597 #define GOT_TLS_GD_BOTH_P(type) \
598 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
599 #define GOT_TLS_GD_P(type) \
600 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
601 #define GOT_TLS_GDESC_P(type) \
602 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
603 #define GOT_TLS_GD_ANY_P(type) \
604 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
605 unsigned char tls_type
;
607 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
608 starting at the end of the jump table. */
612 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
614 struct elf_i386_obj_tdata
616 struct elf_obj_tdata root
;
618 /* tls_type for each local got entry. */
619 char *local_got_tls_type
;
621 /* GOTPLT entries for TLS descriptors. */
622 bfd_vma
*local_tlsdesc_gotent
;
625 #define elf_i386_tdata(abfd) \
626 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
628 #define elf_i386_local_got_tls_type(abfd) \
629 (elf_i386_tdata (abfd)->local_got_tls_type)
631 #define elf_i386_local_tlsdesc_gotent(abfd) \
632 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
634 #define is_i386_elf(bfd) \
635 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
636 && elf_tdata (bfd) != NULL \
637 && elf_object_id (bfd) == I386_ELF_TDATA)
640 elf_i386_mkobject (bfd
*abfd
)
642 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
646 /* i386 ELF linker hash table. */
648 struct elf_i386_link_hash_table
650 struct elf_link_hash_table elf
;
652 /* Short-cuts to get to dynamic linker sections. */
656 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
659 /* True if the target system is VxWorks. */
662 /* Value used to fill the last word of the first plt entry. */
663 bfd_byte plt0_pad_byte
;
665 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
666 bfd_vma next_tls_desc_index
;
669 bfd_signed_vma refcount
;
673 /* The amount of space used by the reserved portion of the sgotplt
674 section, plus whatever space is used by the jump slots. */
675 bfd_vma sgotplt_jump_table_size
;
677 /* Small local sym cache. */
678 struct sym_cache sym_cache
;
680 /* _TLS_MODULE_BASE_ symbol. */
681 struct bfd_link_hash_entry
*tls_module_base
;
683 /* Used by local STT_GNU_IFUNC symbols. */
684 htab_t loc_hash_table
;
685 void *loc_hash_memory
;
688 /* Get the i386 ELF linker hash table from a link_info structure. */
690 #define elf_i386_hash_table(p) \
691 ((struct elf_i386_link_hash_table *) ((p)->hash))
693 #define elf_i386_compute_jump_table_size(htab) \
694 ((htab)->next_tls_desc_index * 4)
696 /* Create an entry in an i386 ELF linker hash table. */
698 static struct bfd_hash_entry
*
699 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
700 struct bfd_hash_table
*table
,
703 /* Allocate the structure if it has not already been allocated by a
707 entry
= bfd_hash_allocate (table
,
708 sizeof (struct elf_i386_link_hash_entry
));
713 /* Call the allocation method of the superclass. */
714 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
717 struct elf_i386_link_hash_entry
*eh
;
719 eh
= (struct elf_i386_link_hash_entry
*) entry
;
720 eh
->dyn_relocs
= NULL
;
721 eh
->tls_type
= GOT_UNKNOWN
;
722 eh
->tlsdesc_got
= (bfd_vma
) -1;
728 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
729 for local symbol so that we can handle local STT_GNU_IFUNC symbols
730 as global symbol. We reuse indx and dynstr_index for local symbol
731 hash since they aren't used by global symbols in this backend. */
734 elf_i386_local_htab_hash (const void *ptr
)
736 struct elf_link_hash_entry
*h
737 = (struct elf_link_hash_entry
*) ptr
;
738 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
741 /* Compare local hash entries. */
744 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
746 struct elf_link_hash_entry
*h1
747 = (struct elf_link_hash_entry
*) ptr1
;
748 struct elf_link_hash_entry
*h2
749 = (struct elf_link_hash_entry
*) ptr2
;
751 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
754 /* Find and/or create a hash entry for local symbol. */
756 static struct elf_link_hash_entry
*
757 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
758 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
761 struct elf_i386_link_hash_entry e
, *ret
;
762 asection
*sec
= abfd
->sections
;
763 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
764 ELF32_R_SYM (rel
->r_info
));
767 e
.elf
.indx
= sec
->id
;
768 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
769 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
770 create
? INSERT
: NO_INSERT
);
777 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
781 ret
= (struct elf_i386_link_hash_entry
*)
782 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
783 sizeof (struct elf_i386_link_hash_entry
));
786 memset (ret
, 0, sizeof (*ret
));
787 ret
->elf
.indx
= sec
->id
;
788 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
789 ret
->elf
.dynindx
= -1;
790 ret
->elf
.plt
.offset
= (bfd_vma
) -1;
791 ret
->elf
.got
.offset
= (bfd_vma
) -1;
797 /* Create an i386 ELF linker hash table. */
799 static struct bfd_link_hash_table
*
800 elf_i386_link_hash_table_create (bfd
*abfd
)
802 struct elf_i386_link_hash_table
*ret
;
803 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
805 ret
= bfd_malloc (amt
);
809 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
810 elf_i386_link_hash_newfunc
,
811 sizeof (struct elf_i386_link_hash_entry
)))
819 ret
->tls_ldm_got
.refcount
= 0;
820 ret
->next_tls_desc_index
= 0;
821 ret
->sgotplt_jump_table_size
= 0;
822 ret
->sym_cache
.abfd
= NULL
;
824 ret
->srelplt2
= NULL
;
825 ret
->plt0_pad_byte
= 0;
826 ret
->tls_module_base
= NULL
;
828 ret
->loc_hash_table
= htab_try_create (1024,
829 elf_i386_local_htab_hash
,
830 elf_i386_local_htab_eq
,
832 ret
->loc_hash_memory
= objalloc_create ();
833 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
839 return &ret
->elf
.root
;
842 /* Destroy an i386 ELF linker hash table. */
845 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
847 struct elf_i386_link_hash_table
*htab
848 = (struct elf_i386_link_hash_table
*) hash
;
850 if (htab
->loc_hash_table
)
851 htab_delete (htab
->loc_hash_table
);
852 if (htab
->loc_hash_memory
)
853 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
854 _bfd_generic_link_hash_table_free (hash
);
857 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
858 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
862 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
864 struct elf_i386_link_hash_table
*htab
;
866 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
869 htab
= elf_i386_hash_table (info
);
870 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
872 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
875 || (!info
->shared
&& !htab
->srelbss
))
879 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
886 /* Copy the extra info we tack onto an elf_link_hash_entry. */
889 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
890 struct elf_link_hash_entry
*dir
,
891 struct elf_link_hash_entry
*ind
)
893 struct elf_i386_link_hash_entry
*edir
, *eind
;
895 edir
= (struct elf_i386_link_hash_entry
*) dir
;
896 eind
= (struct elf_i386_link_hash_entry
*) ind
;
898 if (eind
->dyn_relocs
!= NULL
)
900 if (edir
->dyn_relocs
!= NULL
)
902 struct elf_dyn_relocs
**pp
;
903 struct elf_dyn_relocs
*p
;
905 /* Add reloc counts against the indirect sym to the direct sym
906 list. Merge any entries against the same section. */
907 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
909 struct elf_dyn_relocs
*q
;
911 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
912 if (q
->sec
== p
->sec
)
914 q
->pc_count
+= p
->pc_count
;
915 q
->count
+= p
->count
;
922 *pp
= edir
->dyn_relocs
;
925 edir
->dyn_relocs
= eind
->dyn_relocs
;
926 eind
->dyn_relocs
= NULL
;
929 if (ind
->root
.type
== bfd_link_hash_indirect
930 && dir
->got
.refcount
<= 0)
932 edir
->tls_type
= eind
->tls_type
;
933 eind
->tls_type
= GOT_UNKNOWN
;
936 if (ELIMINATE_COPY_RELOCS
937 && ind
->root
.type
!= bfd_link_hash_indirect
938 && dir
->dynamic_adjusted
)
940 /* If called to transfer flags for a weakdef during processing
941 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
942 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
943 dir
->ref_dynamic
|= ind
->ref_dynamic
;
944 dir
->ref_regular
|= ind
->ref_regular
;
945 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
946 dir
->needs_plt
|= ind
->needs_plt
;
947 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
950 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
960 /* Return TRUE if the TLS access code sequence support transition
964 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
966 Elf_Internal_Shdr
*symtab_hdr
,
967 struct elf_link_hash_entry
**sym_hashes
,
969 const Elf_Internal_Rela
*rel
,
970 const Elf_Internal_Rela
*relend
)
972 unsigned int val
, type
;
973 unsigned long r_symndx
;
974 struct elf_link_hash_entry
*h
;
977 /* Get the section contents. */
978 if (contents
== NULL
)
980 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
981 contents
= elf_section_data (sec
)->this_hdr
.contents
;
984 /* FIXME: How to better handle error condition? */
985 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
988 /* Cache the section contents for elf_link_input_bfd. */
989 elf_section_data (sec
)->this_hdr
.contents
= contents
;
993 offset
= rel
->r_offset
;
998 if (offset
< 2 || (rel
+ 1) >= relend
)
1001 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1002 if (r_type
== R_386_TLS_GD
)
1004 /* Check transition from GD access model. Only
1005 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1006 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1007 can transit to different access model. */
1008 if ((offset
+ 10) > sec
->size
||
1009 (type
!= 0x8d && type
!= 0x04))
1012 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1015 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1019 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1022 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1027 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1028 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1031 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1037 /* Check transition from LD access model. Only
1038 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1039 can transit to different access model. */
1040 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1043 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1044 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1048 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1051 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1052 if (r_symndx
< symtab_hdr
->sh_info
)
1055 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1056 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1057 may be versioned. */
1059 && h
->root
.root
.string
!= NULL
1060 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1061 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1062 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1066 /* Check transition from IE access model:
1067 movl foo@indntpoff(%rip), %eax
1068 movl foo@indntpoff(%rip), %reg
1069 addl foo@indntpoff(%rip), %reg
1072 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1075 /* Check "movl foo@tpoff(%rip), %eax" first. */
1076 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1083 /* Check movl|addl foo@tpoff(%rip), %reg. */
1084 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1085 return ((type
== 0x8b || type
== 0x03)
1086 && (val
& 0xc7) == 0x05);
1088 case R_386_TLS_GOTIE
:
1089 case R_386_TLS_IE_32
:
1090 /* Check transition from {IE_32,GOTIE} access model:
1091 subl foo@{tpoff,gontoff}(%reg1), %reg2
1092 movl foo@{tpoff,gontoff}(%reg1), %reg2
1093 addl foo@{tpoff,gontoff}(%reg1), %reg2
1096 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1099 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1100 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1103 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1104 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1106 case R_386_TLS_GOTDESC
:
1107 /* Check transition from GDesc access model:
1108 leal x@tlsdesc(%ebx), %eax
1110 Make sure it's a leal adding ebx to a 32-bit offset
1111 into any register, although it's probably almost always
1114 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1117 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1120 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1121 return (val
& 0xc7) == 0x83;
1123 case R_386_TLS_DESC_CALL
:
1124 /* Check transition from GDesc access model:
1125 call *x@tlsdesc(%rax)
1127 if (offset
+ 2 <= sec
->size
)
1129 /* Make sure that it's a call *x@tlsdesc(%rax). */
1130 static i386_opcode16 call
= { { 0xff, 0x10 } };
1131 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1141 /* Return TRUE if the TLS access transition is OK or no transition
1142 will be performed. Update R_TYPE if there is a transition. */
1145 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1146 asection
*sec
, bfd_byte
*contents
,
1147 Elf_Internal_Shdr
*symtab_hdr
,
1148 struct elf_link_hash_entry
**sym_hashes
,
1149 unsigned int *r_type
, int tls_type
,
1150 const Elf_Internal_Rela
*rel
,
1151 const Elf_Internal_Rela
*relend
,
1152 struct elf_link_hash_entry
*h
)
1154 unsigned int from_type
= *r_type
;
1155 unsigned int to_type
= from_type
;
1156 bfd_boolean check
= TRUE
;
1161 case R_386_TLS_GOTDESC
:
1162 case R_386_TLS_DESC_CALL
:
1163 case R_386_TLS_IE_32
:
1165 case R_386_TLS_GOTIE
:
1169 to_type
= R_386_TLS_LE_32
;
1170 else if (from_type
!= R_386_TLS_IE
1171 && from_type
!= R_386_TLS_GOTIE
)
1172 to_type
= R_386_TLS_IE_32
;
1175 /* When we are called from elf_i386_relocate_section, CONTENTS
1176 isn't NULL and there may be additional transitions based on
1178 if (contents
!= NULL
)
1180 unsigned int new_to_type
= to_type
;
1185 && (tls_type
& GOT_TLS_IE
))
1186 new_to_type
= R_386_TLS_LE_32
;
1188 if (to_type
== R_386_TLS_GD
1189 || to_type
== R_386_TLS_GOTDESC
1190 || to_type
== R_386_TLS_DESC_CALL
)
1192 if (tls_type
== GOT_TLS_IE_POS
)
1193 new_to_type
= R_386_TLS_GOTIE
;
1194 else if (tls_type
& GOT_TLS_IE
)
1195 new_to_type
= R_386_TLS_IE_32
;
1198 /* We checked the transition before when we were called from
1199 elf_i386_check_relocs. We only want to check the new
1200 transition which hasn't been checked before. */
1201 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1202 to_type
= new_to_type
;
1209 to_type
= R_386_TLS_LE_32
;
1216 /* Return TRUE if there is no transition. */
1217 if (from_type
== to_type
)
1220 /* Check if the transition can be performed. */
1222 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1223 symtab_hdr
, sym_hashes
,
1224 from_type
, rel
, relend
))
1226 reloc_howto_type
*from
, *to
;
1228 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1229 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1231 (*_bfd_error_handler
)
1232 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1233 "in section `%A' failed"),
1234 abfd
, sec
, from
->name
, to
->name
,
1235 h
? h
->root
.root
.string
: "a local symbol",
1236 (unsigned long) rel
->r_offset
);
1237 bfd_set_error (bfd_error_bad_value
);
1245 /* Look through the relocs for a section during the first phase, and
1246 calculate needed space in the global offset table, procedure linkage
1247 table, and dynamic reloc sections. */
1250 elf_i386_check_relocs (bfd
*abfd
,
1251 struct bfd_link_info
*info
,
1253 const Elf_Internal_Rela
*relocs
)
1255 struct elf_i386_link_hash_table
*htab
;
1256 Elf_Internal_Shdr
*symtab_hdr
;
1257 struct elf_link_hash_entry
**sym_hashes
;
1258 const Elf_Internal_Rela
*rel
;
1259 const Elf_Internal_Rela
*rel_end
;
1261 Elf_Internal_Sym
*isymbuf
;
1263 if (info
->relocatable
)
1266 BFD_ASSERT (is_i386_elf (abfd
));
1268 htab
= elf_i386_hash_table (info
);
1269 symtab_hdr
= &elf_symtab_hdr (abfd
);
1270 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1271 sym_hashes
= elf_sym_hashes (abfd
);
1275 rel_end
= relocs
+ sec
->reloc_count
;
1276 for (rel
= relocs
; rel
< rel_end
; rel
++)
1278 unsigned int r_type
;
1279 unsigned long r_symndx
;
1280 struct elf_link_hash_entry
*h
;
1282 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1283 r_type
= ELF32_R_TYPE (rel
->r_info
);
1285 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1287 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1293 if (r_symndx
< symtab_hdr
->sh_info
)
1295 /* A local symbol. */
1296 Elf_Internal_Sym
*isym
;
1298 /* Read this BFD's local symbols. */
1299 if (isymbuf
== NULL
)
1301 if (isymbuf
== NULL
)
1302 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1303 symtab_hdr
->sh_info
, 0,
1305 if (isymbuf
== NULL
)
1309 /* Check relocation against local STT_GNU_IFUNC symbol. */
1310 isym
= isymbuf
+ r_symndx
;
1311 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1313 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
,
1318 /* Fake a STT_GNU_IFUNC symbol. */
1319 h
->type
= STT_GNU_IFUNC
;
1322 h
->forced_local
= 1;
1323 h
->root
.type
= bfd_link_hash_defined
;
1330 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1331 while (h
->root
.type
== bfd_link_hash_indirect
1332 || h
->root
.type
== bfd_link_hash_warning
)
1333 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1338 /* Create the ifunc sections for static executables. If we
1339 never see an indirect function symbol nor we are building
1340 a static executable, those sections will be empty and
1341 won't appear in output. */
1352 if (!_bfd_elf_create_ifunc_sections (abfd
, info
))
1357 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1358 it here if it is defined in a non-shared object. */
1359 if (h
->type
== STT_GNU_IFUNC
1362 /* It is referenced by a non-shared object. */
1365 /* STT_GNU_IFUNC symbol must go through PLT. */
1366 h
->plt
.refcount
+= 1;
1368 /* STT_GNU_IFUNC needs dynamic sections. */
1369 if (htab
->elf
.dynobj
== NULL
)
1370 htab
->elf
.dynobj
= abfd
;
1375 (*_bfd_error_handler
)
1376 (_("%B: relocation %s against STT_GNU_IFUNC "
1377 "symbol `%s' isn't handled by %s"), abfd
,
1378 elf_howto_table
[r_type
].name
,
1379 (h
->root
.root
.string
1380 ? h
->root
.root
.string
: "a local symbol"),
1382 bfd_set_error (bfd_error_bad_value
);
1387 h
->pointer_equality_needed
= 1;
1390 /* We must copy these reloc types into the
1391 output file. Create a reloc section in
1392 dynobj and make room for this reloc. */
1393 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1394 (abfd
, info
, sec
, sreloc
,
1395 &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
);
1410 h
->got
.refcount
+= 1;
1411 if (htab
->elf
.sgot
== NULL
1412 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1422 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1423 symtab_hdr
, sym_hashes
,
1424 &r_type
, GOT_UNKNOWN
,
1431 htab
->tls_ldm_got
.refcount
+= 1;
1435 /* This symbol requires a procedure linkage table entry. We
1436 actually build the entry in adjust_dynamic_symbol,
1437 because this might be a case of linking PIC code which is
1438 never referenced by a dynamic object, in which case we
1439 don't need to generate a procedure linkage table entry
1442 /* If this is a local symbol, we resolve it directly without
1443 creating a procedure linkage table entry. */
1448 h
->plt
.refcount
+= 1;
1451 case R_386_TLS_IE_32
:
1453 case R_386_TLS_GOTIE
:
1455 info
->flags
|= DF_STATIC_TLS
;
1460 case R_386_TLS_GOTDESC
:
1461 case R_386_TLS_DESC_CALL
:
1462 /* This symbol requires a global offset table entry. */
1464 int tls_type
, old_tls_type
;
1469 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1470 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1471 case R_386_TLS_GOTDESC
:
1472 case R_386_TLS_DESC_CALL
:
1473 tls_type
= GOT_TLS_GDESC
; break;
1474 case R_386_TLS_IE_32
:
1475 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1476 tls_type
= GOT_TLS_IE_NEG
;
1478 /* If this is a GD->IE transition, we may use either of
1479 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1480 tls_type
= GOT_TLS_IE
;
1483 case R_386_TLS_GOTIE
:
1484 tls_type
= GOT_TLS_IE_POS
; break;
1489 h
->got
.refcount
+= 1;
1490 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1494 bfd_signed_vma
*local_got_refcounts
;
1496 /* This is a global offset table entry for a local symbol. */
1497 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1498 if (local_got_refcounts
== NULL
)
1502 size
= symtab_hdr
->sh_info
;
1503 size
*= (sizeof (bfd_signed_vma
)
1504 + sizeof (bfd_vma
) + sizeof(char));
1505 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1506 if (local_got_refcounts
== NULL
)
1508 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1509 elf_i386_local_tlsdesc_gotent (abfd
)
1510 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1511 elf_i386_local_got_tls_type (abfd
)
1512 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1514 local_got_refcounts
[r_symndx
] += 1;
1515 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1518 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1519 tls_type
|= old_tls_type
;
1520 /* If a TLS symbol is accessed using IE at least once,
1521 there is no point to use dynamic model for it. */
1522 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1523 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1524 || (tls_type
& GOT_TLS_IE
) == 0))
1526 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1527 tls_type
= old_tls_type
;
1528 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1529 && GOT_TLS_GD_ANY_P (tls_type
))
1530 tls_type
|= old_tls_type
;
1533 (*_bfd_error_handler
)
1534 (_("%B: `%s' accessed both as normal and "
1535 "thread local symbol"),
1537 h
? h
->root
.root
.string
: "<local>");
1542 if (old_tls_type
!= tls_type
)
1545 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1547 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1555 if (htab
->elf
.sgot
== NULL
)
1557 if (htab
->elf
.dynobj
== NULL
)
1558 htab
->elf
.dynobj
= abfd
;
1559 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1562 if (r_type
!= R_386_TLS_IE
)
1566 case R_386_TLS_LE_32
:
1570 info
->flags
|= DF_STATIC_TLS
;
1575 if (h
!= NULL
&& info
->executable
)
1577 /* If this reloc is in a read-only section, we might
1578 need a copy reloc. We can't check reliably at this
1579 stage whether the section is read-only, as input
1580 sections have not yet been mapped to output sections.
1581 Tentatively set the flag for now, and correct in
1582 adjust_dynamic_symbol. */
1585 /* We may need a .plt entry if the function this reloc
1586 refers to is in a shared lib. */
1587 h
->plt
.refcount
+= 1;
1588 if (r_type
!= R_386_PC32
)
1589 h
->pointer_equality_needed
= 1;
1592 /* If we are creating a shared library, and this is a reloc
1593 against a global symbol, or a non PC relative reloc
1594 against a local symbol, then we need to copy the reloc
1595 into the shared library. However, if we are linking with
1596 -Bsymbolic, we do not need to copy a reloc against a
1597 global symbol which is defined in an object we are
1598 including in the link (i.e., DEF_REGULAR is set). At
1599 this point we have not seen all the input files, so it is
1600 possible that DEF_REGULAR is not set now but will be set
1601 later (it is never cleared). In case of a weak definition,
1602 DEF_REGULAR may be cleared later by a strong definition in
1603 a shared library. We account for that possibility below by
1604 storing information in the relocs_copied field of the hash
1605 table entry. A similar situation occurs when creating
1606 shared libraries and symbol visibility changes render the
1609 If on the other hand, we are creating an executable, we
1610 may need to keep relocations for symbols satisfied by a
1611 dynamic library if we manage to avoid copy relocs for the
1614 && (sec
->flags
& SEC_ALLOC
) != 0
1615 && (r_type
!= R_386_PC32
1617 && (! SYMBOLIC_BIND (info
, h
)
1618 || h
->root
.type
== bfd_link_hash_defweak
1619 || !h
->def_regular
))))
1620 || (ELIMINATE_COPY_RELOCS
1622 && (sec
->flags
& SEC_ALLOC
) != 0
1624 && (h
->root
.type
== bfd_link_hash_defweak
1625 || !h
->def_regular
)))
1627 struct elf_dyn_relocs
*p
;
1628 struct elf_dyn_relocs
**head
;
1630 /* We must copy these reloc types into the output file.
1631 Create a reloc section in dynobj and make room for
1635 if (htab
->elf
.dynobj
== NULL
)
1636 htab
->elf
.dynobj
= abfd
;
1638 sreloc
= _bfd_elf_make_dynamic_reloc_section
1639 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1645 /* If this is a global symbol, we count the number of
1646 relocations we need for this symbol. */
1649 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1653 /* Track dynamic relocs needed for local syms too.
1654 We really need local syms available to do this
1658 Elf_Internal_Sym
*isym
;
1660 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1665 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1669 vpp
= &elf_section_data (s
)->local_dynrel
;
1670 head
= (struct elf_dyn_relocs
**)vpp
;
1674 if (p
== NULL
|| p
->sec
!= sec
)
1676 bfd_size_type amt
= sizeof *p
;
1677 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
1688 if (r_type
== R_386_PC32
)
1693 /* This relocation describes the C++ object vtable hierarchy.
1694 Reconstruct it for later use during GC. */
1695 case R_386_GNU_VTINHERIT
:
1696 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1700 /* This relocation describes which C++ vtable entries are actually
1701 used. Record for later use during GC. */
1702 case R_386_GNU_VTENTRY
:
1703 BFD_ASSERT (h
!= NULL
);
1705 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1715 && (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
1717 if (!info
->keep_memory
)
1721 /* Cache the symbols for elf_link_input_bfd. */
1722 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
1730 && (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
1735 /* Return the section that should be marked against GC for a given
1739 elf_i386_gc_mark_hook (asection
*sec
,
1740 struct bfd_link_info
*info
,
1741 Elf_Internal_Rela
*rel
,
1742 struct elf_link_hash_entry
*h
,
1743 Elf_Internal_Sym
*sym
)
1746 switch (ELF32_R_TYPE (rel
->r_info
))
1748 case R_386_GNU_VTINHERIT
:
1749 case R_386_GNU_VTENTRY
:
1753 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1756 /* Update the got entry reference counts for the section being removed. */
1759 elf_i386_gc_sweep_hook (bfd
*abfd
,
1760 struct bfd_link_info
*info
,
1762 const Elf_Internal_Rela
*relocs
)
1764 Elf_Internal_Shdr
*symtab_hdr
;
1765 struct elf_link_hash_entry
**sym_hashes
;
1766 bfd_signed_vma
*local_got_refcounts
;
1767 const Elf_Internal_Rela
*rel
, *relend
;
1769 if (info
->relocatable
)
1772 elf_section_data (sec
)->local_dynrel
= NULL
;
1774 symtab_hdr
= &elf_symtab_hdr (abfd
);
1775 sym_hashes
= elf_sym_hashes (abfd
);
1776 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1778 relend
= relocs
+ sec
->reloc_count
;
1779 for (rel
= relocs
; rel
< relend
; rel
++)
1781 unsigned long r_symndx
;
1782 unsigned int r_type
;
1783 struct elf_link_hash_entry
*h
= NULL
;
1785 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1786 if (r_symndx
>= symtab_hdr
->sh_info
)
1788 struct elf_i386_link_hash_entry
*eh
;
1789 struct elf_dyn_relocs
**pp
;
1790 struct elf_dyn_relocs
*p
;
1792 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1793 while (h
->root
.type
== bfd_link_hash_indirect
1794 || h
->root
.type
== bfd_link_hash_warning
)
1795 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1796 eh
= (struct elf_i386_link_hash_entry
*) h
;
1798 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1801 /* Everything must go for SEC. */
1807 r_type
= ELF32_R_TYPE (rel
->r_info
);
1808 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1809 symtab_hdr
, sym_hashes
,
1810 &r_type
, GOT_UNKNOWN
,
1817 if (elf_i386_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1818 elf_i386_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1822 case R_386_TLS_GOTDESC
:
1823 case R_386_TLS_DESC_CALL
:
1824 case R_386_TLS_IE_32
:
1826 case R_386_TLS_GOTIE
:
1830 if (h
->got
.refcount
> 0)
1831 h
->got
.refcount
-= 1;
1833 else if (local_got_refcounts
!= NULL
)
1835 if (local_got_refcounts
[r_symndx
] > 0)
1836 local_got_refcounts
[r_symndx
] -= 1;
1849 if (h
->plt
.refcount
> 0)
1850 h
->plt
.refcount
-= 1;
1862 /* Adjust a symbol defined by a dynamic object and referenced by a
1863 regular object. The current definition is in some section of the
1864 dynamic object, but we're not including those sections. We have to
1865 change the definition to something the rest of the link can
1869 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1870 struct elf_link_hash_entry
*h
)
1872 struct elf_i386_link_hash_table
*htab
;
1875 /* STT_GNU_IFUNC symbol must go through PLT. */
1876 if (h
->type
== STT_GNU_IFUNC
)
1878 if (h
->plt
.refcount
<= 0)
1880 h
->plt
.offset
= (bfd_vma
) -1;
1886 /* If this is a function, put it in the procedure linkage table. We
1887 will fill in the contents of the procedure linkage table later,
1888 when we know the address of the .got section. */
1889 if (h
->type
== STT_FUNC
1892 if (h
->plt
.refcount
<= 0
1893 || SYMBOL_CALLS_LOCAL (info
, h
)
1894 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1895 && h
->root
.type
== bfd_link_hash_undefweak
))
1897 /* This case can occur if we saw a PLT32 reloc in an input
1898 file, but the symbol was never referred to by a dynamic
1899 object, or if all references were garbage collected. In
1900 such a case, we don't actually need to build a procedure
1901 linkage table, and we can just do a PC32 reloc instead. */
1902 h
->plt
.offset
= (bfd_vma
) -1;
1909 /* It's possible that we incorrectly decided a .plt reloc was
1910 needed for an R_386_PC32 reloc to a non-function sym in
1911 check_relocs. We can't decide accurately between function and
1912 non-function syms in check-relocs; Objects loaded later in
1913 the link may change h->type. So fix it now. */
1914 h
->plt
.offset
= (bfd_vma
) -1;
1916 /* If this is a weak symbol, and there is a real definition, the
1917 processor independent code will have arranged for us to see the
1918 real definition first, and we can just use the same value. */
1919 if (h
->u
.weakdef
!= NULL
)
1921 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1922 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1923 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1924 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1925 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1926 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1930 /* This is a reference to a symbol defined by a dynamic object which
1931 is not a function. */
1933 /* If we are creating a shared library, we must presume that the
1934 only references to the symbol are via the global offset table.
1935 For such cases we need not do anything here; the relocations will
1936 be handled correctly by relocate_section. */
1940 /* If there are no references to this symbol that do not use the
1941 GOT, we don't need to generate a copy reloc. */
1942 if (!h
->non_got_ref
)
1945 /* If -z nocopyreloc was given, we won't generate them either. */
1946 if (info
->nocopyreloc
)
1952 htab
= elf_i386_hash_table (info
);
1954 /* If there aren't any dynamic relocs in read-only sections, then
1955 we can keep the dynamic relocs and avoid the copy reloc. This
1956 doesn't work on VxWorks, where we can not have dynamic relocations
1957 (other than copy and jump slot relocations) in an executable. */
1958 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
1960 struct elf_i386_link_hash_entry
* eh
;
1961 struct elf_dyn_relocs
*p
;
1963 eh
= (struct elf_i386_link_hash_entry
*) h
;
1964 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1966 s
= p
->sec
->output_section
;
1967 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1980 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1981 h
->root
.root
.string
);
1985 /* We must allocate the symbol in our .dynbss section, which will
1986 become part of the .bss section of the executable. There will be
1987 an entry for this symbol in the .dynsym section. The dynamic
1988 object will contain position independent code, so all references
1989 from the dynamic object to this symbol will go through the global
1990 offset table. The dynamic linker will use the .dynsym entry to
1991 determine the address it must put in the global offset table, so
1992 both the dynamic object and the regular object will refer to the
1993 same memory location for the variable. */
1995 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
1996 copy the initial value out of the dynamic object and into the
1997 runtime process image. */
1998 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2000 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2006 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2009 /* Allocate space in .plt, .got and associated reloc sections for
2013 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2015 struct bfd_link_info
*info
;
2016 struct elf_i386_link_hash_table
*htab
;
2017 struct elf_i386_link_hash_entry
*eh
;
2018 struct elf_dyn_relocs
*p
;
2020 if (h
->root
.type
== bfd_link_hash_indirect
)
2023 if (h
->root
.type
== bfd_link_hash_warning
)
2024 /* When warning symbols are created, they **replace** the "real"
2025 entry in the hash table, thus we never get to see the real
2026 symbol in a hash traversal. So look at it now. */
2027 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2028 eh
= (struct elf_i386_link_hash_entry
*) h
;
2030 info
= (struct bfd_link_info
*) inf
;
2031 htab
= elf_i386_hash_table (info
);
2033 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2034 here if it is defined and referenced in a non-shared object. */
2035 if (h
->type
== STT_GNU_IFUNC
2037 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2040 else if (htab
->elf
.dynamic_sections_created
2041 && h
->plt
.refcount
> 0)
2043 /* Make sure this symbol is output as a dynamic symbol.
2044 Undefined weak syms won't yet be marked as dynamic. */
2045 if (h
->dynindx
== -1
2046 && !h
->forced_local
)
2048 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2053 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2055 asection
*s
= htab
->elf
.splt
;
2057 /* If this is the first .plt entry, make room for the special
2060 s
->size
+= PLT_ENTRY_SIZE
;
2062 h
->plt
.offset
= s
->size
;
2064 /* If this symbol is not defined in a regular file, and we are
2065 not generating a shared library, then set the symbol to this
2066 location in the .plt. This is required to make function
2067 pointers compare as equal between the normal executable and
2068 the shared library. */
2072 h
->root
.u
.def
.section
= s
;
2073 h
->root
.u
.def
.value
= h
->plt
.offset
;
2076 /* Make room for this entry. */
2077 s
->size
+= PLT_ENTRY_SIZE
;
2079 /* We also need to make an entry in the .got.plt section, which
2080 will be placed in the .got section by the linker script. */
2081 htab
->elf
.sgotplt
->size
+= 4;
2083 /* We also need to make an entry in the .rel.plt section. */
2084 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2085 htab
->next_tls_desc_index
++;
2087 if (htab
->is_vxworks
&& !info
->shared
)
2089 /* VxWorks has a second set of relocations for each PLT entry
2090 in executables. They go in a separate relocation section,
2091 which is processed by the kernel loader. */
2093 /* There are two relocations for the initial PLT entry: an
2094 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2095 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2097 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
2098 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2100 /* There are two extra relocations for each subsequent PLT entry:
2101 an R_386_32 relocation for the GOT entry, and an R_386_32
2102 relocation for the PLT entry. */
2104 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2109 h
->plt
.offset
= (bfd_vma
) -1;
2115 h
->plt
.offset
= (bfd_vma
) -1;
2119 eh
->tlsdesc_got
= (bfd_vma
) -1;
2121 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2122 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2123 if (h
->got
.refcount
> 0
2126 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2127 h
->got
.offset
= (bfd_vma
) -1;
2128 else if (h
->got
.refcount
> 0)
2132 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2134 /* Make sure this symbol is output as a dynamic symbol.
2135 Undefined weak syms won't yet be marked as dynamic. */
2136 if (h
->dynindx
== -1
2137 && !h
->forced_local
)
2139 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2144 if (GOT_TLS_GDESC_P (tls_type
))
2146 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2147 - elf_i386_compute_jump_table_size (htab
);
2148 htab
->elf
.sgotplt
->size
+= 8;
2149 h
->got
.offset
= (bfd_vma
) -2;
2151 if (! GOT_TLS_GDESC_P (tls_type
)
2152 || GOT_TLS_GD_P (tls_type
))
2154 h
->got
.offset
= s
->size
;
2156 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2157 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2160 dyn
= htab
->elf
.dynamic_sections_created
;
2161 /* R_386_TLS_IE_32 needs one dynamic relocation,
2162 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2163 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2164 need two), R_386_TLS_GD needs one if local symbol and two if
2166 if (tls_type
== GOT_TLS_IE_BOTH
)
2167 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2168 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2169 || (tls_type
& GOT_TLS_IE
))
2170 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2171 else if (GOT_TLS_GD_P (tls_type
))
2172 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2173 else if (! GOT_TLS_GDESC_P (tls_type
)
2174 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2175 || h
->root
.type
!= bfd_link_hash_undefweak
)
2177 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2178 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2179 if (GOT_TLS_GDESC_P (tls_type
))
2180 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2183 h
->got
.offset
= (bfd_vma
) -1;
2185 if (eh
->dyn_relocs
== NULL
)
2188 /* In the shared -Bsymbolic case, discard space allocated for
2189 dynamic pc-relative relocs against symbols which turn out to be
2190 defined in regular objects. For the normal shared case, discard
2191 space for pc-relative relocs that have become local due to symbol
2192 visibility changes. */
2196 /* The only reloc that uses pc_count is R_386_PC32, which will
2197 appear on a call or on something like ".long foo - .". We
2198 want calls to protected symbols to resolve directly to the
2199 function rather than going via the plt. If people want
2200 function pointer comparisons to work as expected then they
2201 should avoid writing assembly like ".long foo - .". */
2202 if (SYMBOL_CALLS_LOCAL (info
, h
))
2204 struct elf_dyn_relocs
**pp
;
2206 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2208 p
->count
-= p
->pc_count
;
2217 if (htab
->is_vxworks
)
2219 struct elf_dyn_relocs
**pp
;
2220 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2222 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2229 /* Also discard relocs on undefined weak syms with non-default
2231 if (eh
->dyn_relocs
!= NULL
2232 && h
->root
.type
== bfd_link_hash_undefweak
)
2234 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2235 eh
->dyn_relocs
= NULL
;
2237 /* Make sure undefined weak symbols are output as a dynamic
2239 else if (h
->dynindx
== -1
2240 && !h
->forced_local
)
2242 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2247 else if (ELIMINATE_COPY_RELOCS
)
2249 /* For the non-shared case, discard space for relocs against
2250 symbols which turn out to need copy relocs or are not
2256 || (htab
->elf
.dynamic_sections_created
2257 && (h
->root
.type
== bfd_link_hash_undefweak
2258 || h
->root
.type
== bfd_link_hash_undefined
))))
2260 /* Make sure this symbol is output as a dynamic symbol.
2261 Undefined weak syms won't yet be marked as dynamic. */
2262 if (h
->dynindx
== -1
2263 && !h
->forced_local
)
2265 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2269 /* If that succeeded, we know we'll be keeping all the
2271 if (h
->dynindx
!= -1)
2275 eh
->dyn_relocs
= NULL
;
2280 /* Finally, allocate space. */
2281 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2285 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2287 BFD_ASSERT (sreloc
!= NULL
);
2288 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2294 /* Allocate space in .plt, .got and associated reloc sections for
2295 local dynamic relocs. */
2298 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2300 struct elf_link_hash_entry
*h
2301 = (struct elf_link_hash_entry
*) *slot
;
2303 if (h
->type
!= STT_GNU_IFUNC
2307 || h
->root
.type
!= bfd_link_hash_defined
)
2310 return elf_i386_allocate_dynrelocs (h
, inf
);
2313 /* Find any dynamic relocs that apply to read-only sections. */
2316 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2318 struct elf_i386_link_hash_entry
*eh
;
2319 struct elf_dyn_relocs
*p
;
2321 if (h
->root
.type
== bfd_link_hash_warning
)
2322 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2324 eh
= (struct elf_i386_link_hash_entry
*) h
;
2325 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2327 asection
*s
= p
->sec
->output_section
;
2329 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2331 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2333 info
->flags
|= DF_TEXTREL
;
2335 /* Not an error, just cut short the traversal. */
2342 /* Set the sizes of the dynamic sections. */
2345 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2346 struct bfd_link_info
*info
)
2348 struct elf_i386_link_hash_table
*htab
;
2354 htab
= elf_i386_hash_table (info
);
2355 dynobj
= htab
->elf
.dynobj
;
2359 if (htab
->elf
.dynamic_sections_created
)
2361 /* Set the contents of the .interp section to the interpreter. */
2362 if (info
->executable
)
2364 s
= bfd_get_section_by_name (dynobj
, ".interp");
2367 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2368 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2372 /* Set up .got offsets for local syms, and space for local dynamic
2374 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2376 bfd_signed_vma
*local_got
;
2377 bfd_signed_vma
*end_local_got
;
2378 char *local_tls_type
;
2379 bfd_vma
*local_tlsdesc_gotent
;
2380 bfd_size_type locsymcount
;
2381 Elf_Internal_Shdr
*symtab_hdr
;
2384 if (! is_i386_elf (ibfd
))
2387 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2389 struct elf_dyn_relocs
*p
;
2391 for (p
= ((struct elf_dyn_relocs
*)
2392 elf_section_data (s
)->local_dynrel
);
2396 if (!bfd_is_abs_section (p
->sec
)
2397 && bfd_is_abs_section (p
->sec
->output_section
))
2399 /* Input section has been discarded, either because
2400 it is a copy of a linkonce section or due to
2401 linker script /DISCARD/, so we'll be discarding
2404 else if (htab
->is_vxworks
2405 && strcmp (p
->sec
->output_section
->name
,
2408 /* Relocations in vxworks .tls_vars sections are
2409 handled specially by the loader. */
2411 else if (p
->count
!= 0)
2413 srel
= elf_section_data (p
->sec
)->sreloc
;
2414 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2415 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2416 info
->flags
|= DF_TEXTREL
;
2421 local_got
= elf_local_got_refcounts (ibfd
);
2425 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2426 locsymcount
= symtab_hdr
->sh_info
;
2427 end_local_got
= local_got
+ locsymcount
;
2428 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2429 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2431 srel
= htab
->elf
.srelgot
;
2432 for (; local_got
< end_local_got
;
2433 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2435 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2438 if (GOT_TLS_GDESC_P (*local_tls_type
))
2440 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2441 - elf_i386_compute_jump_table_size (htab
);
2442 htab
->elf
.sgotplt
->size
+= 8;
2443 *local_got
= (bfd_vma
) -2;
2445 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2446 || GOT_TLS_GD_P (*local_tls_type
))
2448 *local_got
= s
->size
;
2450 if (GOT_TLS_GD_P (*local_tls_type
)
2451 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2455 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2456 || (*local_tls_type
& GOT_TLS_IE
))
2458 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2459 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2460 else if (GOT_TLS_GD_P (*local_tls_type
)
2461 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2462 srel
->size
+= sizeof (Elf32_External_Rel
);
2463 if (GOT_TLS_GDESC_P (*local_tls_type
))
2464 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2468 *local_got
= (bfd_vma
) -1;
2472 if (htab
->tls_ldm_got
.refcount
> 0)
2474 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2476 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2477 htab
->elf
.sgot
->size
+= 8;
2478 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2481 htab
->tls_ldm_got
.offset
= -1;
2483 /* Allocate global sym .plt and .got entries, and space for global
2484 sym dynamic relocs. */
2485 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2487 /* Allocate .plt and .got entries, and space for local symbols. */
2488 htab_traverse (htab
->loc_hash_table
,
2489 elf_i386_allocate_local_dynrelocs
,
2492 /* For every jump slot reserved in the sgotplt, reloc_count is
2493 incremented. However, when we reserve space for TLS descriptors,
2494 it's not incremented, so in order to compute the space reserved
2495 for them, it suffices to multiply the reloc count by the jump
2497 if (htab
->elf
.srelplt
)
2498 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2500 /* We now have determined the sizes of the various dynamic sections.
2501 Allocate memory for them. */
2503 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2505 bfd_boolean strip_section
= TRUE
;
2507 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2510 if (s
== htab
->elf
.splt
2511 || s
== htab
->elf
.sgot
2512 || s
== htab
->elf
.sgotplt
2513 || s
== htab
->elf
.iplt
2514 || s
== htab
->elf
.igotplt
2515 || s
== htab
->sdynbss
)
2517 /* Strip this section if we don't need it; see the
2519 /* We'd like to strip these sections if they aren't needed, but if
2520 we've exported dynamic symbols from them we must leave them.
2521 It's too late to tell BFD to get rid of the symbols. */
2523 if (htab
->elf
.hplt
!= NULL
)
2524 strip_section
= FALSE
;
2526 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2529 && s
!= htab
->elf
.srelplt
2530 && s
!= htab
->srelplt2
)
2533 /* We use the reloc_count field as a counter if we need
2534 to copy relocs into the output file. */
2539 /* It's not one of our sections, so don't allocate space. */
2545 /* If we don't need this section, strip it from the
2546 output file. This is mostly to handle .rel.bss and
2547 .rel.plt. We must create both sections in
2548 create_dynamic_sections, because they must be created
2549 before the linker maps input sections to output
2550 sections. The linker does that before
2551 adjust_dynamic_symbol is called, and it is that
2552 function which decides whether anything needs to go
2553 into these sections. */
2555 s
->flags
|= SEC_EXCLUDE
;
2559 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2562 /* Allocate memory for the section contents. We use bfd_zalloc
2563 here in case unused entries are not reclaimed before the
2564 section's contents are written out. This should not happen,
2565 but this way if it does, we get a R_386_NONE reloc instead
2567 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
2568 if (s
->contents
== NULL
)
2572 if (htab
->elf
.dynamic_sections_created
)
2574 /* Add some entries to the .dynamic section. We fill in the
2575 values later, in elf_i386_finish_dynamic_sections, but we
2576 must add the entries now so that we get the correct size for
2577 the .dynamic section. The DT_DEBUG entry is filled in by the
2578 dynamic linker and used by the debugger. */
2579 #define add_dynamic_entry(TAG, VAL) \
2580 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2582 if (info
->executable
)
2584 if (!add_dynamic_entry (DT_DEBUG
, 0))
2588 if (htab
->elf
.splt
->size
!= 0)
2590 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2591 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2592 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2593 || !add_dynamic_entry (DT_JMPREL
, 0))
2599 if (!add_dynamic_entry (DT_REL
, 0)
2600 || !add_dynamic_entry (DT_RELSZ
, 0)
2601 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2604 /* If any dynamic relocs apply to a read-only section,
2605 then we need a DT_TEXTREL entry. */
2606 if ((info
->flags
& DF_TEXTREL
) == 0)
2607 elf_link_hash_traverse (&htab
->elf
,
2608 elf_i386_readonly_dynrelocs
, info
);
2610 if ((info
->flags
& DF_TEXTREL
) != 0)
2612 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2616 if (htab
->is_vxworks
2617 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2620 #undef add_dynamic_entry
2626 elf_i386_always_size_sections (bfd
*output_bfd
,
2627 struct bfd_link_info
*info
)
2629 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2633 struct elf_link_hash_entry
*tlsbase
;
2635 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2636 "_TLS_MODULE_BASE_",
2637 FALSE
, FALSE
, FALSE
);
2639 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2641 struct bfd_link_hash_entry
*bh
= NULL
;
2642 const struct elf_backend_data
*bed
2643 = get_elf_backend_data (output_bfd
);
2645 if (!(_bfd_generic_link_add_one_symbol
2646 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2647 tls_sec
, 0, NULL
, FALSE
,
2648 bed
->collect
, &bh
)))
2651 elf_i386_hash_table (info
)->tls_module_base
= bh
;
2653 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2654 tlsbase
->def_regular
= 1;
2655 tlsbase
->other
= STV_HIDDEN
;
2656 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2663 /* Set the correct type for an x86 ELF section. We do this by the
2664 section name, which is a hack, but ought to work. */
2667 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2668 Elf_Internal_Shdr
*hdr
,
2671 register const char *name
;
2673 name
= bfd_get_section_name (abfd
, sec
);
2675 /* This is an ugly, but unfortunately necessary hack that is
2676 needed when producing EFI binaries on x86. It tells
2677 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2678 containing ELF relocation info. We need this hack in order to
2679 be able to generate ELF binaries that can be translated into
2680 EFI applications (which are essentially COFF objects). Those
2681 files contain a COFF ".reloc" section inside an ELFNN object,
2682 which would normally cause BFD to segfault because it would
2683 attempt to interpret this section as containing relocation
2684 entries for section "oc". With this hack enabled, ".reloc"
2685 will be treated as a normal data section, which will avoid the
2686 segfault. However, you won't be able to create an ELFNN binary
2687 with a section named "oc" that needs relocations, but that's
2688 the kind of ugly side-effects you get when detecting section
2689 types based on their names... In practice, this limitation is
2690 unlikely to bite. */
2691 if (strcmp (name
, ".reloc") == 0)
2692 hdr
->sh_type
= SHT_PROGBITS
;
2697 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2698 executables. Rather than setting it to the beginning of the TLS
2699 section, we have to set it to the end. This function may be called
2700 multiple times, it is idempotent. */
2703 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2705 struct bfd_link_hash_entry
*base
;
2707 if (!info
->executable
)
2710 base
= elf_i386_hash_table (info
)->tls_module_base
;
2715 base
->u
.def
.value
= elf_hash_table (info
)->tls_size
;
2718 /* Return the base VMA address which should be subtracted from real addresses
2719 when resolving @dtpoff relocation.
2720 This is PT_TLS segment p_vaddr. */
2723 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2725 /* If tls_sec is NULL, we should have signalled an error already. */
2726 if (elf_hash_table (info
)->tls_sec
== NULL
)
2728 return elf_hash_table (info
)->tls_sec
->vma
;
2731 /* Return the relocation value for @tpoff relocation
2732 if STT_TLS virtual address is ADDRESS. */
2735 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2737 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2739 /* If tls_sec is NULL, we should have signalled an error already. */
2740 if (htab
->tls_sec
== NULL
)
2742 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2745 /* Relocate an i386 ELF section. */
2748 elf_i386_relocate_section (bfd
*output_bfd
,
2749 struct bfd_link_info
*info
,
2751 asection
*input_section
,
2753 Elf_Internal_Rela
*relocs
,
2754 Elf_Internal_Sym
*local_syms
,
2755 asection
**local_sections
)
2757 struct elf_i386_link_hash_table
*htab
;
2758 Elf_Internal_Shdr
*symtab_hdr
;
2759 struct elf_link_hash_entry
**sym_hashes
;
2760 bfd_vma
*local_got_offsets
;
2761 bfd_vma
*local_tlsdesc_gotents
;
2762 Elf_Internal_Rela
*rel
;
2763 Elf_Internal_Rela
*relend
;
2764 bfd_boolean is_vxworks_tls
;
2766 BFD_ASSERT (is_i386_elf (input_bfd
));
2768 htab
= elf_i386_hash_table (info
);
2769 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2770 sym_hashes
= elf_sym_hashes (input_bfd
);
2771 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2772 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2773 /* We have to handle relocations in vxworks .tls_vars sections
2774 specially, because the dynamic loader is 'weird'. */
2775 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
2776 && !strcmp (input_section
->output_section
->name
,
2779 elf_i386_set_tls_module_base (info
);
2782 relend
= relocs
+ input_section
->reloc_count
;
2783 for (; rel
< relend
; rel
++)
2785 unsigned int r_type
;
2786 reloc_howto_type
*howto
;
2787 unsigned long r_symndx
;
2788 struct elf_link_hash_entry
*h
;
2789 Elf_Internal_Sym
*sym
;
2791 bfd_vma off
, offplt
;
2793 bfd_boolean unresolved_reloc
;
2794 bfd_reloc_status_type r
;
2798 r_type
= ELF32_R_TYPE (rel
->r_info
);
2799 if (r_type
== R_386_GNU_VTINHERIT
2800 || r_type
== R_386_GNU_VTENTRY
)
2803 if ((indx
= r_type
) >= R_386_standard
2804 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2805 >= R_386_ext
- R_386_standard
)
2806 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2807 >= R_386_irelative
- R_386_ext
))
2809 (*_bfd_error_handler
)
2810 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2811 input_bfd
, input_section
, r_type
);
2812 bfd_set_error (bfd_error_bad_value
);
2815 howto
= elf_howto_table
+ indx
;
2817 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2821 unresolved_reloc
= FALSE
;
2822 if (r_symndx
< symtab_hdr
->sh_info
)
2824 sym
= local_syms
+ r_symndx
;
2825 sec
= local_sections
[r_symndx
];
2826 relocation
= (sec
->output_section
->vma
2827 + sec
->output_offset
2830 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2831 && ((sec
->flags
& SEC_MERGE
) != 0
2832 || (info
->relocatable
2833 && sec
->output_offset
!= 0)))
2836 bfd_byte
*where
= contents
+ rel
->r_offset
;
2838 switch (howto
->size
)
2841 addend
= bfd_get_8 (input_bfd
, where
);
2842 if (howto
->pc_relative
)
2844 addend
= (addend
^ 0x80) - 0x80;
2849 addend
= bfd_get_16 (input_bfd
, where
);
2850 if (howto
->pc_relative
)
2852 addend
= (addend
^ 0x8000) - 0x8000;
2857 addend
= bfd_get_32 (input_bfd
, where
);
2858 if (howto
->pc_relative
)
2860 addend
= (addend
^ 0x80000000) - 0x80000000;
2868 if (info
->relocatable
)
2869 addend
+= sec
->output_offset
;
2872 asection
*msec
= sec
;
2873 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2875 addend
-= relocation
;
2876 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2879 switch (howto
->size
)
2882 /* FIXME: overflow checks. */
2883 if (howto
->pc_relative
)
2885 bfd_put_8 (input_bfd
, addend
, where
);
2888 if (howto
->pc_relative
)
2890 bfd_put_16 (input_bfd
, addend
, where
);
2893 if (howto
->pc_relative
)
2895 bfd_put_32 (input_bfd
, addend
, where
);
2899 else if (ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2901 /* Relocate against local STT_GNU_IFUNC symbol. */
2902 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
,
2907 /* Set STT_GNU_IFUNC symbol value. */
2908 h
->root
.u
.def
.value
= sym
->st_value
;
2909 h
->root
.u
.def
.section
= sec
;
2916 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2917 r_symndx
, symtab_hdr
, sym_hashes
,
2919 unresolved_reloc
, warned
);
2922 if (sec
!= NULL
&& elf_discarded_section (sec
))
2924 /* For relocs against symbols from removed linkonce sections,
2925 or sections discarded by a linker script, we just want the
2926 section contents zeroed. Avoid any special processing. */
2927 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2933 if (info
->relocatable
)
2936 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2937 it here if it is defined in a non-shared object. */
2939 && h
->type
== STT_GNU_IFUNC
2942 asection
*plt
, *gotplt
, *base_got
;
2945 if ((input_section
->flags
& SEC_ALLOC
) == 0
2946 || h
->plt
.offset
== (bfd_vma
) -1)
2949 /* STT_GNU_IFUNC symbol must go through PLT. */
2950 if (htab
->elf
.splt
!= NULL
)
2952 plt
= htab
->elf
.splt
;
2953 gotplt
= htab
->elf
.sgotplt
;
2957 plt
= htab
->elf
.iplt
;
2958 gotplt
= htab
->elf
.igotplt
;
2961 relocation
= (plt
->output_section
->vma
2962 + plt
->output_offset
+ h
->plt
.offset
);
2967 (*_bfd_error_handler
)
2968 (_("%B: relocation %s against STT_GNU_IFUNC "
2969 "symbol `%s' isn't handled by %s"), input_bfd
,
2970 elf_howto_table
[r_type
].name
,
2971 (h
->root
.root
.string
2972 ? h
->root
.root
.string
: "a local symbol"),
2974 bfd_set_error (bfd_error_bad_value
);
2978 /* Generate dynamic relcoation only when there is a
2979 non-GOF reference in a shared object. */
2980 if (info
->shared
&& h
->non_got_ref
)
2982 Elf_Internal_Rela outrel
;
2987 /* Need a dynamic relocation to get the real function
2989 offset
= _bfd_elf_section_offset (output_bfd
,
2993 if (offset
== (bfd_vma
) -1
2994 || offset
== (bfd_vma
) -2)
2997 outrel
.r_offset
= (input_section
->output_section
->vma
2998 + input_section
->output_offset
3001 if (h
->dynindx
== -1
3003 || info
->executable
)
3005 /* This symbol is resolved locally. */
3006 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3007 bfd_put_32 (output_bfd
,
3008 (h
->root
.u
.def
.value
3009 + h
->root
.u
.def
.section
->output_section
->vma
3010 + h
->root
.u
.def
.section
->output_offset
),
3014 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3016 sreloc
= htab
->elf
.irelifunc
;
3017 loc
= sreloc
->contents
;
3018 loc
+= (sreloc
->reloc_count
++
3019 * sizeof (Elf32_External_Rel
));
3020 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3022 /* If this reloc is against an external symbol, we
3023 do not want to fiddle with the addend. Otherwise,
3024 we need to include the symbol value so that it
3025 becomes an addend for the dynamic reloc. For an
3026 internal symbol, we have updated addend. */
3035 base_got
= htab
->elf
.sgot
;
3036 off
= h
->got
.offset
;
3038 if (base_got
== NULL
)
3041 if (off
== (bfd_vma
) -1)
3043 /* We can't use h->got.offset here to save state, or
3044 even just remember the offset, as finish_dynamic_symbol
3045 would use that as offset into .got. */
3047 if (htab
->elf
.splt
!= NULL
)
3049 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3050 off
= (plt_index
+ 3) * 4;
3051 base_got
= htab
->elf
.sgotplt
;
3055 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3056 off
= plt_index
* 4;
3057 base_got
= htab
->elf
.igotplt
;
3060 if (h
->dynindx
== -1
3064 /* This references the local defitionion. We must
3065 initialize this entry in the global offset table.
3066 Since the offset must always be a multiple of 8,
3067 we use the least significant bit to record
3068 whether we have initialized it already.
3070 When doing a dynamic link, we create a .rela.got
3071 relocation entry to initialize the value. This
3072 is done in the finish_dynamic_symbol routine. */
3077 bfd_put_32 (output_bfd
, relocation
,
3078 base_got
->contents
+ off
);
3085 /* Adjust for static executables. */
3086 if (htab
->elf
.splt
== NULL
)
3087 relocation
+= gotplt
->output_offset
;
3091 relocation
= (base_got
->output_section
->vma
3092 + base_got
->output_offset
+ off
3093 - gotplt
->output_section
->vma
3094 - gotplt
->output_offset
);
3095 /* Adjust for static executables. */
3096 if (htab
->elf
.splt
== NULL
)
3097 relocation
+= gotplt
->output_offset
;
3103 relocation
-= (gotplt
->output_section
->vma
3104 + gotplt
->output_offset
);
3112 /* Relocation is to the entry for this symbol in the global
3114 if (htab
->elf
.sgot
== NULL
)
3121 off
= h
->got
.offset
;
3122 dyn
= htab
->elf
.dynamic_sections_created
;
3123 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3125 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3126 || (ELF_ST_VISIBILITY (h
->other
)
3127 && h
->root
.type
== bfd_link_hash_undefweak
))
3129 /* This is actually a static link, or it is a
3130 -Bsymbolic link and the symbol is defined
3131 locally, or the symbol was forced to be local
3132 because of a version file. We must initialize
3133 this entry in the global offset table. Since the
3134 offset must always be a multiple of 4, we use the
3135 least significant bit to record whether we have
3136 initialized it already.
3138 When doing a dynamic link, we create a .rel.got
3139 relocation entry to initialize the value. This
3140 is done in the finish_dynamic_symbol routine. */
3145 bfd_put_32 (output_bfd
, relocation
,
3146 htab
->elf
.sgot
->contents
+ off
);
3151 unresolved_reloc
= FALSE
;
3155 if (local_got_offsets
== NULL
)
3158 off
= local_got_offsets
[r_symndx
];
3160 /* The offset must always be a multiple of 4. We use
3161 the least significant bit to record whether we have
3162 already generated the necessary reloc. */
3167 bfd_put_32 (output_bfd
, relocation
,
3168 htab
->elf
.sgot
->contents
+ off
);
3173 Elf_Internal_Rela outrel
;
3176 s
= htab
->elf
.srelgot
;
3180 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3181 + htab
->elf
.sgot
->output_offset
3183 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3185 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3186 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3189 local_got_offsets
[r_symndx
] |= 1;
3193 if (off
>= (bfd_vma
) -2)
3196 relocation
= htab
->elf
.sgot
->output_section
->vma
3197 + htab
->elf
.sgot
->output_offset
+ off
3198 - htab
->elf
.sgotplt
->output_section
->vma
3199 - htab
->elf
.sgotplt
->output_offset
;
3203 /* Relocation is relative to the start of the global offset
3206 /* Check to make sure it isn't a protected function symbol
3207 for shared library since it may not be local when used
3208 as function address. We also need to make sure that a
3209 symbol is defined locally. */
3210 if (info
->shared
&& h
)
3212 if (!h
->def_regular
)
3216 switch (ELF_ST_VISIBILITY (h
->other
))
3219 v
= _("hidden symbol");
3222 v
= _("internal symbol");
3225 v
= _("protected symbol");
3232 (*_bfd_error_handler
)
3233 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3234 input_bfd
, v
, h
->root
.root
.string
);
3235 bfd_set_error (bfd_error_bad_value
);
3238 else if (!info
->executable
3239 && h
->type
== STT_FUNC
3240 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3242 (*_bfd_error_handler
)
3243 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3244 input_bfd
, h
->root
.root
.string
);
3245 bfd_set_error (bfd_error_bad_value
);
3250 /* Note that sgot is not involved in this
3251 calculation. We always want the start of .got.plt. If we
3252 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3253 permitted by the ABI, we might have to change this
3255 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3256 + htab
->elf
.sgotplt
->output_offset
;
3260 /* Use global offset table as symbol value. */
3261 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3262 + htab
->elf
.sgotplt
->output_offset
;
3263 unresolved_reloc
= FALSE
;
3267 /* Relocation is to the entry for this symbol in the
3268 procedure linkage table. */
3270 /* Resolve a PLT32 reloc against a local symbol directly,
3271 without using the procedure linkage table. */
3275 if (h
->plt
.offset
== (bfd_vma
) -1
3276 || htab
->elf
.splt
== NULL
)
3278 /* We didn't make a PLT entry for this symbol. This
3279 happens when statically linking PIC code, or when
3280 using -Bsymbolic. */
3284 relocation
= (htab
->elf
.splt
->output_section
->vma
3285 + htab
->elf
.splt
->output_offset
3287 unresolved_reloc
= FALSE
;
3292 if ((input_section
->flags
& SEC_ALLOC
) == 0
3298 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3299 || h
->root
.type
!= bfd_link_hash_undefweak
)
3300 && (r_type
!= R_386_PC32
3301 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3302 || (ELIMINATE_COPY_RELOCS
3309 || h
->root
.type
== bfd_link_hash_undefweak
3310 || h
->root
.type
== bfd_link_hash_undefined
)))
3312 Elf_Internal_Rela outrel
;
3314 bfd_boolean skip
, relocate
;
3317 /* When generating a shared object, these relocations
3318 are copied into the output file to be resolved at run
3325 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3327 if (outrel
.r_offset
== (bfd_vma
) -1)
3329 else if (outrel
.r_offset
== (bfd_vma
) -2)
3330 skip
= TRUE
, relocate
= TRUE
;
3331 outrel
.r_offset
+= (input_section
->output_section
->vma
3332 + input_section
->output_offset
);
3335 memset (&outrel
, 0, sizeof outrel
);
3338 && (r_type
== R_386_PC32
3340 || !SYMBOLIC_BIND (info
, h
)
3341 || !h
->def_regular
))
3342 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3345 /* This symbol is local, or marked to become local. */
3347 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3350 sreloc
= elf_section_data (input_section
)->sreloc
;
3352 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
3354 loc
= sreloc
->contents
;
3355 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3357 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3359 /* If this reloc is against an external symbol, we do
3360 not want to fiddle with the addend. Otherwise, we
3361 need to include the symbol value so that it becomes
3362 an addend for the dynamic reloc. */
3371 Elf_Internal_Rela outrel
;
3375 outrel
.r_offset
= rel
->r_offset
3376 + input_section
->output_section
->vma
3377 + input_section
->output_offset
;
3378 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3379 sreloc
= elf_section_data (input_section
)->sreloc
;
3382 loc
= sreloc
->contents
;
3383 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3384 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3389 case R_386_TLS_GOTDESC
:
3390 case R_386_TLS_DESC_CALL
:
3391 case R_386_TLS_IE_32
:
3392 case R_386_TLS_GOTIE
:
3393 tls_type
= GOT_UNKNOWN
;
3394 if (h
== NULL
&& local_got_offsets
)
3395 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3397 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3398 if (tls_type
== GOT_TLS_IE
)
3399 tls_type
= GOT_TLS_IE_NEG
;
3401 if (! elf_i386_tls_transition (info
, input_bfd
,
3402 input_section
, contents
,
3403 symtab_hdr
, sym_hashes
,
3404 &r_type
, tls_type
, rel
,
3408 if (r_type
== R_386_TLS_LE_32
)
3410 BFD_ASSERT (! unresolved_reloc
);
3411 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3416 /* GD->LE transition. */
3417 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3420 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3422 movl %gs:0, %eax; subl $foo@tpoff, %eax
3423 (6 byte form of subl). */
3424 memcpy (contents
+ rel
->r_offset
- 3,
3425 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3426 roff
= rel
->r_offset
+ 5;
3430 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3432 movl %gs:0, %eax; subl $foo@tpoff, %eax
3433 (6 byte form of subl). */
3434 memcpy (contents
+ rel
->r_offset
- 2,
3435 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3436 roff
= rel
->r_offset
+ 6;
3438 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3440 /* Skip R_386_PC32/R_386_PLT32. */
3444 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3446 /* GDesc -> LE transition.
3447 It's originally something like:
3448 leal x@tlsdesc(%ebx), %eax
3452 Registers other than %eax may be set up here. */
3457 roff
= rel
->r_offset
;
3458 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3460 /* Now modify the instruction as appropriate. */
3461 /* aoliva FIXME: remove the above and xor the byte
3463 bfd_put_8 (output_bfd
, val
^ 0x86,
3464 contents
+ roff
- 1);
3465 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3469 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3471 /* GDesc -> LE transition.
3479 roff
= rel
->r_offset
;
3480 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3481 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3484 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3488 /* IE->LE transition:
3489 Originally it can be one of:
3497 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3500 /* movl foo, %eax. */
3501 bfd_put_8 (output_bfd
, 0xb8,
3502 contents
+ rel
->r_offset
- 1);
3508 type
= bfd_get_8 (input_bfd
,
3509 contents
+ rel
->r_offset
- 2);
3514 bfd_put_8 (output_bfd
, 0xc7,
3515 contents
+ rel
->r_offset
- 2);
3516 bfd_put_8 (output_bfd
,
3517 0xc0 | ((val
>> 3) & 7),
3518 contents
+ rel
->r_offset
- 1);
3522 bfd_put_8 (output_bfd
, 0x81,
3523 contents
+ rel
->r_offset
- 2);
3524 bfd_put_8 (output_bfd
,
3525 0xc0 | ((val
>> 3) & 7),
3526 contents
+ rel
->r_offset
- 1);
3533 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3534 contents
+ rel
->r_offset
);
3539 unsigned int val
, type
;
3541 /* {IE_32,GOTIE}->LE transition:
3542 Originally it can be one of:
3543 subl foo(%reg1), %reg2
3544 movl foo(%reg1), %reg2
3545 addl foo(%reg1), %reg2
3548 movl $foo, %reg2 (6 byte form)
3549 addl $foo, %reg2. */
3550 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3551 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3555 bfd_put_8 (output_bfd
, 0xc7,
3556 contents
+ rel
->r_offset
- 2);
3557 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3558 contents
+ rel
->r_offset
- 1);
3560 else if (type
== 0x2b)
3563 bfd_put_8 (output_bfd
, 0x81,
3564 contents
+ rel
->r_offset
- 2);
3565 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3566 contents
+ rel
->r_offset
- 1);
3568 else if (type
== 0x03)
3571 bfd_put_8 (output_bfd
, 0x81,
3572 contents
+ rel
->r_offset
- 2);
3573 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3574 contents
+ rel
->r_offset
- 1);
3578 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3579 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3580 contents
+ rel
->r_offset
);
3582 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3583 contents
+ rel
->r_offset
);
3588 if (htab
->elf
.sgot
== NULL
)
3593 off
= h
->got
.offset
;
3594 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3598 if (local_got_offsets
== NULL
)
3601 off
= local_got_offsets
[r_symndx
];
3602 offplt
= local_tlsdesc_gotents
[r_symndx
];
3609 Elf_Internal_Rela outrel
;
3614 if (htab
->elf
.srelgot
== NULL
)
3617 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3619 if (GOT_TLS_GDESC_P (tls_type
))
3621 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3622 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3623 <= htab
->elf
.sgotplt
->size
);
3624 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3625 + htab
->elf
.sgotplt
->output_offset
3627 + htab
->sgotplt_jump_table_size
);
3628 sreloc
= htab
->elf
.srelplt
;
3629 loc
= sreloc
->contents
;
3630 loc
+= (htab
->next_tls_desc_index
++
3631 * sizeof (Elf32_External_Rel
));
3632 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3633 <= sreloc
->contents
+ sreloc
->size
);
3634 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3637 BFD_ASSERT (! unresolved_reloc
);
3638 bfd_put_32 (output_bfd
,
3639 relocation
- elf_i386_dtpoff_base (info
),
3640 htab
->elf
.sgotplt
->contents
+ offplt
3641 + htab
->sgotplt_jump_table_size
+ 4);
3645 bfd_put_32 (output_bfd
, 0,
3646 htab
->elf
.sgotplt
->contents
+ offplt
3647 + htab
->sgotplt_jump_table_size
+ 4);
3651 sreloc
= htab
->elf
.srelgot
;
3653 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3654 + htab
->elf
.sgot
->output_offset
+ off
);
3656 if (GOT_TLS_GD_P (tls_type
))
3657 dr_type
= R_386_TLS_DTPMOD32
;
3658 else if (GOT_TLS_GDESC_P (tls_type
))
3660 else if (tls_type
== GOT_TLS_IE_POS
)
3661 dr_type
= R_386_TLS_TPOFF
;
3663 dr_type
= R_386_TLS_TPOFF32
;
3665 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3666 bfd_put_32 (output_bfd
,
3667 relocation
- elf_i386_dtpoff_base (info
),
3668 htab
->elf
.sgot
->contents
+ off
);
3669 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3670 bfd_put_32 (output_bfd
,
3671 elf_i386_dtpoff_base (info
) - relocation
,
3672 htab
->elf
.sgot
->contents
+ off
);
3673 else if (dr_type
!= R_386_TLS_DESC
)
3674 bfd_put_32 (output_bfd
, 0,
3675 htab
->elf
.sgot
->contents
+ off
);
3676 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3678 loc
= sreloc
->contents
;
3679 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3680 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3681 <= sreloc
->contents
+ sreloc
->size
);
3682 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3684 if (GOT_TLS_GD_P (tls_type
))
3688 BFD_ASSERT (! unresolved_reloc
);
3689 bfd_put_32 (output_bfd
,
3690 relocation
- elf_i386_dtpoff_base (info
),
3691 htab
->elf
.sgot
->contents
+ off
+ 4);
3695 bfd_put_32 (output_bfd
, 0,
3696 htab
->elf
.sgot
->contents
+ off
+ 4);
3697 outrel
.r_info
= ELF32_R_INFO (indx
,
3698 R_386_TLS_DTPOFF32
);
3699 outrel
.r_offset
+= 4;
3700 sreloc
->reloc_count
++;
3701 loc
+= sizeof (Elf32_External_Rel
);
3702 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3703 <= sreloc
->contents
+ sreloc
->size
);
3704 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3707 else if (tls_type
== GOT_TLS_IE_BOTH
)
3709 bfd_put_32 (output_bfd
,
3711 ? relocation
- elf_i386_dtpoff_base (info
)
3713 htab
->elf
.sgot
->contents
+ off
+ 4);
3714 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3715 outrel
.r_offset
+= 4;
3716 sreloc
->reloc_count
++;
3717 loc
+= sizeof (Elf32_External_Rel
);
3718 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3725 local_got_offsets
[r_symndx
] |= 1;
3728 if (off
>= (bfd_vma
) -2
3729 && ! GOT_TLS_GDESC_P (tls_type
))
3731 if (r_type
== R_386_TLS_GOTDESC
3732 || r_type
== R_386_TLS_DESC_CALL
)
3734 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3735 unresolved_reloc
= FALSE
;
3737 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3739 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
3740 + htab
->elf
.sgotplt
->output_offset
;
3741 relocation
= htab
->elf
.sgot
->output_section
->vma
3742 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
3743 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3744 && tls_type
== GOT_TLS_IE_BOTH
)
3746 if (r_type
== R_386_TLS_IE
)
3747 relocation
+= g_o_t
;
3748 unresolved_reloc
= FALSE
;
3750 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3752 unsigned int val
, type
;
3755 /* GD->IE transition. */
3756 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3757 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3760 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3762 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3764 roff
= rel
->r_offset
- 3;
3768 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3770 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3771 roff
= rel
->r_offset
- 2;
3773 memcpy (contents
+ roff
,
3774 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3775 contents
[roff
+ 7] = 0x80 | (val
& 7);
3776 /* If foo is used only with foo@gotntpoff(%reg) and
3777 foo@indntpoff, but not with foo@gottpoff(%reg), change
3778 subl $foo@gottpoff(%reg), %eax
3780 addl $foo@gotntpoff(%reg), %eax. */
3781 if (tls_type
== GOT_TLS_IE_POS
)
3782 contents
[roff
+ 6] = 0x03;
3783 bfd_put_32 (output_bfd
,
3784 htab
->elf
.sgot
->output_section
->vma
3785 + htab
->elf
.sgot
->output_offset
+ off
3786 - htab
->elf
.sgotplt
->output_section
->vma
3787 - htab
->elf
.sgotplt
->output_offset
,
3788 contents
+ roff
+ 8);
3789 /* Skip R_386_PLT32. */
3793 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3795 /* GDesc -> IE transition.
3796 It's originally something like:
3797 leal x@tlsdesc(%ebx), %eax
3800 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
3802 movl x@gottpoff(%ebx), %eax # before negl %eax
3804 Registers other than %eax may be set up here. */
3808 /* First, make sure it's a leal adding ebx to a 32-bit
3809 offset into any register, although it's probably
3810 almost always going to be eax. */
3811 roff
= rel
->r_offset
;
3813 /* Now modify the instruction as appropriate. */
3814 /* To turn a leal into a movl in the form we use it, it
3815 suffices to change the first byte from 0x8d to 0x8b.
3816 aoliva FIXME: should we decide to keep the leal, all
3817 we have to do is remove the statement below, and
3818 adjust the relaxation of R_386_TLS_DESC_CALL. */
3819 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3821 if (tls_type
== GOT_TLS_IE_BOTH
)
3824 bfd_put_32 (output_bfd
,
3825 htab
->elf
.sgot
->output_section
->vma
3826 + htab
->elf
.sgot
->output_offset
+ off
3827 - htab
->elf
.sgotplt
->output_section
->vma
3828 - htab
->elf
.sgotplt
->output_offset
,
3832 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3834 /* GDesc -> IE transition.
3842 depending on how we transformed the TLS_GOTDESC above.
3847 roff
= rel
->r_offset
;
3849 /* Now modify the instruction as appropriate. */
3850 if (tls_type
!= GOT_TLS_IE_NEG
)
3853 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3854 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3859 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3860 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3870 if (! elf_i386_tls_transition (info
, input_bfd
,
3871 input_section
, contents
,
3872 symtab_hdr
, sym_hashes
,
3873 &r_type
, GOT_UNKNOWN
, rel
,
3877 if (r_type
!= R_386_TLS_LDM
)
3879 /* LD->LE transition:
3880 leal foo(%reg), %eax; call ___tls_get_addr.
3882 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3883 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
3884 memcpy (contents
+ rel
->r_offset
- 2,
3885 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3886 /* Skip R_386_PC32/R_386_PLT32. */
3891 if (htab
->elf
.sgot
== NULL
)
3894 off
= htab
->tls_ldm_got
.offset
;
3899 Elf_Internal_Rela outrel
;
3902 if (htab
->elf
.srelgot
== NULL
)
3905 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3906 + htab
->elf
.sgot
->output_offset
+ off
);
3908 bfd_put_32 (output_bfd
, 0,
3909 htab
->elf
.sgot
->contents
+ off
);
3910 bfd_put_32 (output_bfd
, 0,
3911 htab
->elf
.sgot
->contents
+ off
+ 4);
3912 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3913 loc
= htab
->elf
.srelgot
->contents
;
3914 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3915 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3916 htab
->tls_ldm_got
.offset
|= 1;
3918 relocation
= 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
;
3922 unresolved_reloc
= FALSE
;
3925 case R_386_TLS_LDO_32
:
3926 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3927 relocation
-= elf_i386_dtpoff_base (info
);
3929 /* When converting LDO to LE, we must negate. */
3930 relocation
= -elf_i386_tpoff (info
, relocation
);
3933 case R_386_TLS_LE_32
:
3937 Elf_Internal_Rela outrel
;
3942 outrel
.r_offset
= rel
->r_offset
3943 + input_section
->output_section
->vma
3944 + input_section
->output_offset
;
3945 if (h
!= NULL
&& h
->dynindx
!= -1)
3949 if (r_type
== R_386_TLS_LE_32
)
3950 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3952 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3953 sreloc
= elf_section_data (input_section
)->sreloc
;
3956 loc
= sreloc
->contents
;
3957 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3958 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3961 else if (r_type
== R_386_TLS_LE_32
)
3962 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
3964 relocation
-= elf_i386_dtpoff_base (info
);
3966 else if (r_type
== R_386_TLS_LE_32
)
3967 relocation
= elf_i386_tpoff (info
, relocation
);
3969 relocation
= -elf_i386_tpoff (info
, relocation
);
3976 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3977 because such sections are not SEC_ALLOC and thus ld.so will
3978 not process them. */
3979 if (unresolved_reloc
3980 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3983 (*_bfd_error_handler
)
3984 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3987 (long) rel
->r_offset
,
3989 h
->root
.root
.string
);
3994 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3995 contents
, rel
->r_offset
,
3998 if (r
!= bfd_reloc_ok
)
4003 name
= h
->root
.root
.string
;
4006 name
= bfd_elf_string_from_elf_section (input_bfd
,
4007 symtab_hdr
->sh_link
,
4012 name
= bfd_section_name (input_bfd
, sec
);
4015 if (r
== bfd_reloc_overflow
)
4017 if (! ((*info
->callbacks
->reloc_overflow
)
4018 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4019 (bfd_vma
) 0, input_bfd
, input_section
,
4025 (*_bfd_error_handler
)
4026 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4027 input_bfd
, input_section
,
4028 (long) rel
->r_offset
, name
, (int) r
);
4037 /* Finish up dynamic symbol handling. We set the contents of various
4038 dynamic sections here. */
4041 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4042 struct bfd_link_info
*info
,
4043 struct elf_link_hash_entry
*h
,
4044 Elf_Internal_Sym
*sym
)
4046 struct elf_i386_link_hash_table
*htab
;
4048 htab
= elf_i386_hash_table (info
);
4050 if (h
->plt
.offset
!= (bfd_vma
) -1)
4054 Elf_Internal_Rela rel
;
4056 asection
*plt
, *gotplt
, *relplt
;
4058 /* When building a static executable, use .iplt, .igot.plt and
4059 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4060 if (htab
->elf
.splt
!= NULL
)
4062 plt
= htab
->elf
.splt
;
4063 gotplt
= htab
->elf
.sgotplt
;
4064 relplt
= htab
->elf
.srelplt
;
4068 plt
= htab
->elf
.iplt
;
4069 gotplt
= htab
->elf
.igotplt
;
4070 relplt
= htab
->elf
.irelplt
;
4073 /* This symbol has an entry in the procedure linkage table. Set
4076 if ((h
->dynindx
== -1
4077 && !((h
->forced_local
|| info
->executable
)
4079 && h
->type
== STT_GNU_IFUNC
))
4085 /* Get the index in the procedure linkage table which
4086 corresponds to this symbol. This is the index of this symbol
4087 in all the symbols for which we are making plt entries. The
4088 first entry in the procedure linkage table is reserved.
4090 Get the offset into the .got table of the entry that
4091 corresponds to this function. Each .got entry is 4 bytes.
4092 The first three are reserved.
4094 For static executables, we don't reserve anything. */
4096 if (plt
== htab
->elf
.splt
)
4098 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
4099 got_offset
= (plt_index
+ 3) * 4;
4103 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4104 got_offset
= plt_index
* 4;
4107 /* Fill in the entry in the procedure linkage table. */
4110 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
4112 bfd_put_32 (output_bfd
,
4113 (gotplt
->output_section
->vma
4114 + gotplt
->output_offset
4116 plt
->contents
+ h
->plt
.offset
+ 2);
4118 if (htab
->is_vxworks
)
4120 int s
, k
, reloc_index
;
4122 /* Create the R_386_32 relocation referencing the GOT
4123 for this PLT entry. */
4125 /* S: Current slot number (zero-based). */
4126 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
4127 /* K: Number of relocations for PLTResolve. */
4129 k
= PLTRESOLVE_RELOCS_SHLIB
;
4131 k
= PLTRESOLVE_RELOCS
;
4132 /* Skip the PLTresolve relocations, and the relocations for
4133 the other PLT slots. */
4134 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4135 loc
= (htab
->srelplt2
->contents
+ reloc_index
4136 * sizeof (Elf32_External_Rel
));
4138 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4139 + htab
->elf
.splt
->output_offset
4140 + h
->plt
.offset
+ 2),
4141 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4142 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4144 /* Create the R_386_32 relocation referencing the beginning of
4145 the PLT for this GOT entry. */
4146 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4147 + htab
->elf
.sgotplt
->output_offset
4149 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4150 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4151 loc
+ sizeof (Elf32_External_Rel
));
4156 memcpy (plt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
4158 bfd_put_32 (output_bfd
, got_offset
,
4159 plt
->contents
+ h
->plt
.offset
+ 2);
4162 /* Don't fill PLT entry for static executables. */
4163 if (plt
== htab
->elf
.splt
)
4165 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4166 plt
->contents
+ h
->plt
.offset
+ 7);
4167 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4168 plt
->contents
+ h
->plt
.offset
+ 12);
4171 /* Fill in the entry in the global offset table. */
4172 bfd_put_32 (output_bfd
,
4173 (plt
->output_section
->vma
4174 + plt
->output_offset
4177 gotplt
->contents
+ got_offset
);
4179 /* Fill in the entry in the .rel.plt section. */
4180 rel
.r_offset
= (gotplt
->output_section
->vma
4181 + gotplt
->output_offset
4183 if (h
->dynindx
== -1
4184 || ((info
->executable
4185 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4187 && h
->type
== STT_GNU_IFUNC
))
4189 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4190 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4191 in the .got.plt section. */
4192 bfd_put_32 (output_bfd
,
4193 (h
->root
.u
.def
.value
4194 + h
->root
.u
.def
.section
->output_section
->vma
4195 + h
->root
.u
.def
.section
->output_offset
),
4196 gotplt
->contents
+ got_offset
);
4197 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4200 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4201 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4202 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4204 if (!h
->def_regular
)
4206 /* Mark the symbol as undefined, rather than as defined in
4207 the .plt section. Leave the value if there were any
4208 relocations where pointer equality matters (this is a clue
4209 for the dynamic linker, to make function pointer
4210 comparisons work between an application and shared
4211 library), otherwise set it to zero. If a function is only
4212 called from a binary, there is no need to slow down
4213 shared libraries because of that. */
4214 sym
->st_shndx
= SHN_UNDEF
;
4215 if (!h
->pointer_equality_needed
)
4220 if (h
->got
.offset
!= (bfd_vma
) -1
4221 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4222 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4224 Elf_Internal_Rela rel
;
4227 /* This symbol has an entry in the global offset table. Set it
4230 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4233 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4234 + htab
->elf
.sgot
->output_offset
4235 + (h
->got
.offset
& ~(bfd_vma
) 1));
4237 /* If this is a static link, or it is a -Bsymbolic link and the
4238 symbol is defined locally or was forced to be local because
4239 of a version file, we just want to emit a RELATIVE reloc.
4240 The entry in the global offset table will already have been
4241 initialized in the relocate_section function. */
4243 && h
->type
== STT_GNU_IFUNC
)
4247 /* Generate R_386_GLOB_DAT. */
4252 if (!h
->pointer_equality_needed
)
4255 /* For non-shared object, we can't use .got.plt, which
4256 contains the real function addres if we need pointer
4257 equality. We load the GOT entry with the PLT entry. */
4258 asection
*plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4259 bfd_put_32 (output_bfd
,
4260 (plt
->output_section
->vma
4261 + plt
->output_offset
+ h
->plt
.offset
),
4262 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4266 else if (info
->shared
4267 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4269 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4270 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4274 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4276 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4277 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4278 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4281 loc
= htab
->elf
.srelgot
->contents
;
4282 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4283 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4288 Elf_Internal_Rela rel
;
4291 /* This symbol needs a copy reloc. Set it up. */
4293 if (h
->dynindx
== -1
4294 || (h
->root
.type
!= bfd_link_hash_defined
4295 && h
->root
.type
!= bfd_link_hash_defweak
)
4296 || htab
->srelbss
== NULL
)
4299 rel
.r_offset
= (h
->root
.u
.def
.value
4300 + h
->root
.u
.def
.section
->output_section
->vma
4301 + h
->root
.u
.def
.section
->output_offset
);
4302 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4303 loc
= htab
->srelbss
->contents
;
4304 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4305 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4308 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4309 be NULL for local symbols.
4311 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
4312 is relative to the ".got" section. */
4314 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4315 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
)))
4316 sym
->st_shndx
= SHN_ABS
;
4321 /* Finish up local dynamic symbol handling. We set the contents of
4322 various dynamic sections here. */
4325 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4327 struct elf_link_hash_entry
*h
4328 = (struct elf_link_hash_entry
*) *slot
;
4329 struct bfd_link_info
*info
4330 = (struct bfd_link_info
*) inf
;
4332 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4336 /* Used to decide how to sort relocs in an optimal manner for the
4337 dynamic linker, before writing them out. */
4339 static enum elf_reloc_type_class
4340 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4342 switch (ELF32_R_TYPE (rela
->r_info
))
4344 case R_386_RELATIVE
:
4345 return reloc_class_relative
;
4346 case R_386_JUMP_SLOT
:
4347 return reloc_class_plt
;
4349 return reloc_class_copy
;
4351 return reloc_class_normal
;
4355 /* Finish up the dynamic sections. */
4358 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4359 struct bfd_link_info
*info
)
4361 struct elf_i386_link_hash_table
*htab
;
4365 htab
= elf_i386_hash_table (info
);
4366 dynobj
= htab
->elf
.dynobj
;
4367 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4369 if (htab
->elf
.dynamic_sections_created
)
4371 Elf32_External_Dyn
*dyncon
, *dynconend
;
4373 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4376 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4377 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4378 for (; dyncon
< dynconend
; dyncon
++)
4380 Elf_Internal_Dyn dyn
;
4383 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4388 if (htab
->is_vxworks
4389 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4394 s
= htab
->elf
.sgotplt
;
4395 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4399 s
= htab
->elf
.srelplt
;
4400 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4404 s
= htab
->elf
.srelplt
;
4405 dyn
.d_un
.d_val
= s
->size
;
4409 /* My reading of the SVR4 ABI indicates that the
4410 procedure linkage table relocs (DT_JMPREL) should be
4411 included in the overall relocs (DT_REL). This is
4412 what Solaris does. However, UnixWare can not handle
4413 that case. Therefore, we override the DT_RELSZ entry
4414 here to make it not include the JMPREL relocs. */
4415 s
= htab
->elf
.srelplt
;
4418 dyn
.d_un
.d_val
-= s
->size
;
4422 /* We may not be using the standard ELF linker script.
4423 If .rel.plt is the first .rel section, we adjust
4424 DT_REL to not include it. */
4425 s
= htab
->elf
.srelplt
;
4428 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4430 dyn
.d_un
.d_ptr
+= s
->size
;
4434 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4437 /* Fill in the first entry in the procedure linkage table. */
4438 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4442 memcpy (htab
->elf
.splt
->contents
, elf_i386_pic_plt0_entry
,
4443 sizeof (elf_i386_pic_plt0_entry
));
4444 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
4445 htab
->plt0_pad_byte
,
4446 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
4450 memcpy (htab
->elf
.splt
->contents
, elf_i386_plt0_entry
,
4451 sizeof(elf_i386_plt0_entry
));
4452 memset (htab
->elf
.splt
->contents
+ sizeof (elf_i386_plt0_entry
),
4453 htab
->plt0_pad_byte
,
4454 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
4455 bfd_put_32 (output_bfd
,
4456 (htab
->elf
.sgotplt
->output_section
->vma
4457 + htab
->elf
.sgotplt
->output_offset
4459 htab
->elf
.splt
->contents
+ 2);
4460 bfd_put_32 (output_bfd
,
4461 (htab
->elf
.sgotplt
->output_section
->vma
4462 + htab
->elf
.sgotplt
->output_offset
4464 htab
->elf
.splt
->contents
+ 8);
4466 if (htab
->is_vxworks
)
4468 Elf_Internal_Rela rel
;
4470 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4471 On IA32 we use REL relocations so the addend goes in
4472 the PLT directly. */
4473 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4474 + htab
->elf
.splt
->output_offset
4476 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4477 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4478 htab
->srelplt2
->contents
);
4479 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4480 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4481 + htab
->elf
.splt
->output_offset
4483 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4484 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4485 htab
->srelplt2
->contents
+
4486 sizeof (Elf32_External_Rel
));
4490 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4491 really seem like the right value. */
4492 elf_section_data (htab
->elf
.splt
->output_section
)
4493 ->this_hdr
.sh_entsize
= 4;
4495 /* Correct the .rel.plt.unloaded relocations. */
4496 if (htab
->is_vxworks
&& !info
->shared
)
4498 int num_plts
= (htab
->elf
.splt
->size
/ PLT_ENTRY_SIZE
) - 1;
4501 p
= htab
->srelplt2
->contents
;
4503 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4505 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4507 for (; num_plts
; num_plts
--)
4509 Elf_Internal_Rela rel
;
4510 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4511 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4512 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4513 p
+= sizeof (Elf32_External_Rel
);
4515 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4516 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4517 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4518 p
+= sizeof (Elf32_External_Rel
);
4524 if (htab
->elf
.sgotplt
)
4526 /* Fill in the first three entries in the global offset table. */
4527 if (htab
->elf
.sgotplt
->size
> 0)
4529 bfd_put_32 (output_bfd
,
4531 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4532 htab
->elf
.sgotplt
->contents
);
4533 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4534 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4537 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4540 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4541 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4543 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4544 htab_traverse (htab
->loc_hash_table
,
4545 elf_i386_finish_local_dynamic_symbol
,
4551 /* Return address for Ith PLT stub in section PLT, for relocation REL
4552 or (bfd_vma) -1 if it should not be included. */
4555 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4556 const arelent
*rel ATTRIBUTE_UNUSED
)
4558 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4561 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4564 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4566 if (h
->plt
.offset
!= (bfd_vma
) -1
4568 && !h
->pointer_equality_needed
)
4571 return _bfd_elf_hash_symbol (h
);
4574 /* Hook called by the linker routine which adds symbols from an object
4578 elf_i386_add_symbol_hook (bfd
* abfd ATTRIBUTE_UNUSED
,
4579 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4580 Elf_Internal_Sym
* sym
,
4581 const char ** namep ATTRIBUTE_UNUSED
,
4582 flagword
* flagsp ATTRIBUTE_UNUSED
,
4583 asection
** secp ATTRIBUTE_UNUSED
,
4584 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4586 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4587 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
4592 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4593 #define TARGET_LITTLE_NAME "elf32-i386"
4594 #define ELF_ARCH bfd_arch_i386
4595 #define ELF_MACHINE_CODE EM_386
4596 #define ELF_MAXPAGESIZE 0x1000
4598 #define elf_backend_can_gc_sections 1
4599 #define elf_backend_can_refcount 1
4600 #define elf_backend_want_got_plt 1
4601 #define elf_backend_plt_readonly 1
4602 #define elf_backend_want_plt_sym 0
4603 #define elf_backend_got_header_size 12
4605 /* Support RELA for objdump of prelink objects. */
4606 #define elf_info_to_howto elf_i386_info_to_howto_rel
4607 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4609 #define bfd_elf32_mkobject elf_i386_mkobject
4611 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4612 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4613 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4614 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4615 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4617 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4618 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4619 #define elf_backend_check_relocs elf_i386_check_relocs
4620 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4621 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4622 #define elf_backend_fake_sections elf_i386_fake_sections
4623 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4624 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4625 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4626 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4627 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4628 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4629 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4630 #define elf_backend_relocate_section elf_i386_relocate_section
4631 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4632 #define elf_backend_always_size_sections elf_i386_always_size_sections
4633 #define elf_backend_omit_section_dynsym \
4634 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4635 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4636 #define elf_backend_hash_symbol elf_i386_hash_symbol
4637 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4638 #undef elf_backend_post_process_headers
4639 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4641 #include "elf32-target.h"
4643 /* FreeBSD support. */
4645 #undef TARGET_LITTLE_SYM
4646 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4647 #undef TARGET_LITTLE_NAME
4648 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4650 #define ELF_OSABI ELFOSABI_FREEBSD
4652 /* The kernel recognizes executables as valid only if they carry a
4653 "FreeBSD" label in the ELF header. So we put this label on all
4654 executables and (for simplicity) also all other object files. */
4657 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4659 _bfd_elf_set_osabi (abfd
, info
);
4661 #ifdef OLD_FREEBSD_ABI_LABEL
4662 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4663 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4667 #undef elf_backend_post_process_headers
4668 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4670 #define elf32_bed elf32_i386_fbsd_bed
4672 #undef elf_backend_add_symbol_hook
4674 #include "elf32-target.h"
4676 /* VxWorks support. */
4678 #undef TARGET_LITTLE_SYM
4679 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
4680 #undef TARGET_LITTLE_NAME
4681 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
4684 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
4686 static struct bfd_link_hash_table
*
4687 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
4689 struct bfd_link_hash_table
*ret
;
4690 struct elf_i386_link_hash_table
*htab
;
4692 ret
= elf_i386_link_hash_table_create (abfd
);
4695 htab
= (struct elf_i386_link_hash_table
*) ret
;
4696 htab
->is_vxworks
= 1;
4697 htab
->plt0_pad_byte
= 0x90;
4704 #undef elf_backend_relocs_compatible
4705 #undef elf_backend_post_process_headers
4706 #undef bfd_elf32_bfd_link_hash_table_create
4707 #define bfd_elf32_bfd_link_hash_table_create \
4708 elf_i386_vxworks_link_hash_table_create
4709 #undef elf_backend_add_symbol_hook
4710 #define elf_backend_add_symbol_hook \
4711 elf_vxworks_add_symbol_hook
4712 #undef elf_backend_link_output_symbol_hook
4713 #define elf_backend_link_output_symbol_hook \
4714 elf_vxworks_link_output_symbol_hook
4715 #undef elf_backend_emit_relocs
4716 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
4717 #undef elf_backend_final_write_processing
4718 #define elf_backend_final_write_processing \
4719 elf_vxworks_final_write_processing
4721 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
4723 #undef elf_backend_want_plt_sym
4724 #define elf_backend_want_plt_sym 1
4727 #define elf32_bed elf32_i386_vxworks_bed
4729 #include "elf32-target.h"