1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
29 #include "elf-vxworks.h"
30 #include "bfd_stdint.h"
35 /* 386 uses REL relocations instead of RELA. */
40 static reloc_howto_type elf_howto_table
[]=
42 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
43 bfd_elf_generic_reloc
, "R_386_NONE",
44 TRUE
, 0x00000000, 0x00000000, FALSE
),
45 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
46 bfd_elf_generic_reloc
, "R_386_32",
47 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
48 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
49 bfd_elf_generic_reloc
, "R_386_PC32",
50 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
51 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
52 bfd_elf_generic_reloc
, "R_386_GOT32",
53 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
54 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
55 bfd_elf_generic_reloc
, "R_386_PLT32",
56 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
57 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
58 bfd_elf_generic_reloc
, "R_386_COPY",
59 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
60 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
61 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
62 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
63 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
65 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
66 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_386_RELATIVE",
68 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
69 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
70 bfd_elf_generic_reloc
, "R_386_GOTOFF",
71 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
72 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
73 bfd_elf_generic_reloc
, "R_386_GOTPC",
74 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
76 /* We have a gap in the reloc numbers here.
77 R_386_standard counts the number up to this point, and
78 R_386_ext_offset is the value to subtract from a reloc type of
79 R_386_16 thru R_386_PC8 to form an index into this table. */
80 #define R_386_standard (R_386_GOTPC + 1)
81 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
83 /* These relocs are a GNU extension. */
84 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
86 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
87 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_386_TLS_IE",
89 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
90 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
91 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
92 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
93 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
94 bfd_elf_generic_reloc
, "R_386_TLS_LE",
95 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
96 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_386_TLS_GD",
98 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
99 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
100 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
101 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
102 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_386_16",
104 TRUE
, 0xffff, 0xffff, FALSE
),
105 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_386_PC16",
107 TRUE
, 0xffff, 0xffff, TRUE
),
108 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
109 bfd_elf_generic_reloc
, "R_386_8",
110 TRUE
, 0xff, 0xff, FALSE
),
111 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
112 bfd_elf_generic_reloc
, "R_386_PC8",
113 TRUE
, 0xff, 0xff, TRUE
),
115 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
116 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
117 /* These are common with Solaris TLS implementation. */
118 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
119 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
120 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
121 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
122 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
123 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
124 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
125 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
126 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
127 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
129 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
130 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
131 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
132 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
133 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
134 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
135 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
137 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
139 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
140 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
141 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
143 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
146 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
147 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
148 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
151 #define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
152 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
154 /* GNU extension to record C++ vtable hierarchy. */
155 HOWTO (R_386_GNU_VTINHERIT
, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 FALSE
, /* pc_relative */
161 complain_overflow_dont
, /* complain_on_overflow */
162 NULL
, /* special_function */
163 "R_386_GNU_VTINHERIT", /* name */
164 FALSE
, /* partial_inplace */
167 FALSE
), /* pcrel_offset */
169 /* GNU extension to record C++ vtable member usage. */
170 HOWTO (R_386_GNU_VTENTRY
, /* type */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
174 FALSE
, /* pc_relative */
176 complain_overflow_dont
, /* complain_on_overflow */
177 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
178 "R_386_GNU_VTENTRY", /* name */
179 FALSE
, /* partial_inplace */
182 FALSE
) /* pcrel_offset */
184 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
188 #ifdef DEBUG_GEN_RELOC
190 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
195 static reloc_howto_type
*
196 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
197 bfd_reloc_code_real_type code
)
202 TRACE ("BFD_RELOC_NONE");
203 return &elf_howto_table
[R_386_NONE
];
206 TRACE ("BFD_RELOC_32");
207 return &elf_howto_table
[R_386_32
];
210 TRACE ("BFD_RELOC_CTOR");
211 return &elf_howto_table
[R_386_32
];
213 case BFD_RELOC_32_PCREL
:
214 TRACE ("BFD_RELOC_PC32");
215 return &elf_howto_table
[R_386_PC32
];
217 case BFD_RELOC_386_GOT32
:
218 TRACE ("BFD_RELOC_386_GOT32");
219 return &elf_howto_table
[R_386_GOT32
];
221 case BFD_RELOC_386_PLT32
:
222 TRACE ("BFD_RELOC_386_PLT32");
223 return &elf_howto_table
[R_386_PLT32
];
225 case BFD_RELOC_386_COPY
:
226 TRACE ("BFD_RELOC_386_COPY");
227 return &elf_howto_table
[R_386_COPY
];
229 case BFD_RELOC_386_GLOB_DAT
:
230 TRACE ("BFD_RELOC_386_GLOB_DAT");
231 return &elf_howto_table
[R_386_GLOB_DAT
];
233 case BFD_RELOC_386_JUMP_SLOT
:
234 TRACE ("BFD_RELOC_386_JUMP_SLOT");
235 return &elf_howto_table
[R_386_JUMP_SLOT
];
237 case BFD_RELOC_386_RELATIVE
:
238 TRACE ("BFD_RELOC_386_RELATIVE");
239 return &elf_howto_table
[R_386_RELATIVE
];
241 case BFD_RELOC_386_GOTOFF
:
242 TRACE ("BFD_RELOC_386_GOTOFF");
243 return &elf_howto_table
[R_386_GOTOFF
];
245 case BFD_RELOC_386_GOTPC
:
246 TRACE ("BFD_RELOC_386_GOTPC");
247 return &elf_howto_table
[R_386_GOTPC
];
249 /* These relocs are a GNU extension. */
250 case BFD_RELOC_386_TLS_TPOFF
:
251 TRACE ("BFD_RELOC_386_TLS_TPOFF");
252 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
254 case BFD_RELOC_386_TLS_IE
:
255 TRACE ("BFD_RELOC_386_TLS_IE");
256 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
258 case BFD_RELOC_386_TLS_GOTIE
:
259 TRACE ("BFD_RELOC_386_TLS_GOTIE");
260 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
262 case BFD_RELOC_386_TLS_LE
:
263 TRACE ("BFD_RELOC_386_TLS_LE");
264 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
266 case BFD_RELOC_386_TLS_GD
:
267 TRACE ("BFD_RELOC_386_TLS_GD");
268 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
270 case BFD_RELOC_386_TLS_LDM
:
271 TRACE ("BFD_RELOC_386_TLS_LDM");
272 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
275 TRACE ("BFD_RELOC_16");
276 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
278 case BFD_RELOC_16_PCREL
:
279 TRACE ("BFD_RELOC_16_PCREL");
280 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
283 TRACE ("BFD_RELOC_8");
284 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
286 case BFD_RELOC_8_PCREL
:
287 TRACE ("BFD_RELOC_8_PCREL");
288 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
290 /* Common with Sun TLS implementation. */
291 case BFD_RELOC_386_TLS_LDO_32
:
292 TRACE ("BFD_RELOC_386_TLS_LDO_32");
293 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
295 case BFD_RELOC_386_TLS_IE_32
:
296 TRACE ("BFD_RELOC_386_TLS_IE_32");
297 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
299 case BFD_RELOC_386_TLS_LE_32
:
300 TRACE ("BFD_RELOC_386_TLS_LE_32");
301 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
303 case BFD_RELOC_386_TLS_DTPMOD32
:
304 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
305 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
307 case BFD_RELOC_386_TLS_DTPOFF32
:
308 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
309 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
311 case BFD_RELOC_386_TLS_TPOFF32
:
312 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
313 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
315 case BFD_RELOC_386_TLS_GOTDESC
:
316 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
317 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
319 case BFD_RELOC_386_TLS_DESC_CALL
:
320 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
321 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
323 case BFD_RELOC_386_TLS_DESC
:
324 TRACE ("BFD_RELOC_386_TLS_DESC");
325 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
327 case BFD_RELOC_386_IRELATIVE
:
328 TRACE ("BFD_RELOC_386_IRELATIVE");
329 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
331 case BFD_RELOC_VTABLE_INHERIT
:
332 TRACE ("BFD_RELOC_VTABLE_INHERIT");
333 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
335 case BFD_RELOC_VTABLE_ENTRY
:
336 TRACE ("BFD_RELOC_VTABLE_ENTRY");
337 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
347 static reloc_howto_type
*
348 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
353 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
354 if (elf_howto_table
[i
].name
!= NULL
355 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
356 return &elf_howto_table
[i
];
361 static reloc_howto_type
*
362 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
366 if ((indx
= r_type
) >= R_386_standard
367 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
368 >= R_386_ext
- R_386_standard
)
369 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
370 >= R_386_irelative
- R_386_ext
)
371 && ((indx
= r_type
- R_386_vt_offset
) - R_386_irelative
372 >= R_386_vt
- R_386_irelative
))
374 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
378 BFD_ASSERT (elf_howto_table
[indx
].type
== r_type
);
379 return &elf_howto_table
[indx
];
383 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
385 Elf_Internal_Rela
*dst
)
387 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
388 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
391 /* Return whether a symbol name implies a local label. The UnixWare
392 2.1 cc generates temporary symbols that start with .X, so we
393 recognize them here. FIXME: do other SVR4 compilers also use .X?.
394 If so, we should move the .X recognition into
395 _bfd_elf_is_local_label_name. */
398 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
400 if (name
[0] == '.' && name
[1] == 'X')
403 return _bfd_elf_is_local_label_name (abfd
, name
);
406 /* Support for core dump NOTE sections. */
409 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
414 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
416 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
422 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
425 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
429 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
433 switch (note
->descsz
)
438 case 144: /* Linux/i386 */
440 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
443 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
453 /* Make a ".reg/999" section. */
454 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
455 size
, note
->descpos
+ offset
);
459 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
461 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
463 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
468 elf_tdata (abfd
)->core_program
469 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
470 elf_tdata (abfd
)->core_command
471 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
475 switch (note
->descsz
)
480 case 124: /* Linux/i386 elf_prpsinfo. */
481 elf_tdata (abfd
)->core_pid
482 = bfd_get_32 (abfd
, note
->descdata
+ 12);
483 elf_tdata (abfd
)->core_program
484 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
485 elf_tdata (abfd
)->core_command
486 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
490 /* Note that for some reason, a spurious space is tacked
491 onto the end of the args in some (at least one anyway)
492 implementations, so strip it off if it exists. */
494 char *command
= elf_tdata (abfd
)->core_command
;
495 int n
= strlen (command
);
497 if (0 < n
&& command
[n
- 1] == ' ')
498 command
[n
- 1] = '\0';
504 /* Functions for the i386 ELF linker.
506 In order to gain some understanding of code in this file without
507 knowing all the intricate details of the linker, note the
510 Functions named elf_i386_* are called by external routines, other
511 functions are only called locally. elf_i386_* functions appear
512 in this file more or less in the order in which they are called
513 from external routines. eg. elf_i386_check_relocs is called
514 early in the link process, elf_i386_finish_dynamic_sections is
515 one of the last functions. */
518 /* The name of the dynamic interpreter. This is put in the .interp
521 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
523 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
524 copying dynamic variables from a shared lib into an app's dynbss
525 section, and instead use a dynamic relocation to point into the
527 #define ELIMINATE_COPY_RELOCS 1
529 /* The size in bytes of an entry in the procedure linkage table. */
531 #define PLT_ENTRY_SIZE 16
533 /* The first entry in an absolute procedure linkage table looks like
534 this. See the SVR4 ABI i386 supplement to see how this works.
535 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
537 static const bfd_byte elf_i386_plt0_entry
[12] =
539 0xff, 0x35, /* pushl contents of address */
540 0, 0, 0, 0, /* replaced with address of .got + 4. */
541 0xff, 0x25, /* jmp indirect */
542 0, 0, 0, 0 /* replaced with address of .got + 8. */
545 /* Subsequent entries in an absolute procedure linkage table look like
548 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
550 0xff, 0x25, /* jmp indirect */
551 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
552 0x68, /* pushl immediate */
553 0, 0, 0, 0, /* replaced with offset into relocation table. */
554 0xe9, /* jmp relative */
555 0, 0, 0, 0 /* replaced with offset to start of .plt. */
558 /* The first entry in a PIC procedure linkage table look like this.
559 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
561 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
563 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
564 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
567 /* Subsequent entries in a PIC procedure linkage table look like this. */
569 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
571 0xff, 0xa3, /* jmp *offset(%ebx) */
572 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
573 0x68, /* pushl immediate */
574 0, 0, 0, 0, /* replaced with offset into relocation table. */
575 0xe9, /* jmp relative */
576 0, 0, 0, 0 /* replaced with offset to start of .plt. */
579 /* .eh_frame covering the .plt section. */
581 static const bfd_byte elf_i386_eh_frame_plt
[] =
583 #define PLT_CIE_LENGTH 20
584 #define PLT_FDE_LENGTH 36
585 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
586 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
587 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
588 0, 0, 0, 0, /* CIE ID */
590 'z', 'R', 0, /* Augmentation string */
591 1, /* Code alignment factor */
592 0x7c, /* Data alignment factor */
593 8, /* Return address column */
594 1, /* Augmentation size */
595 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
596 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
597 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
598 DW_CFA_nop
, DW_CFA_nop
,
600 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
601 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
602 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
603 0, 0, 0, 0, /* .plt size goes here */
604 0, /* Augmentation size */
605 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
606 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
607 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
608 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
609 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
610 11, /* Block length */
611 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
612 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
613 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
614 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
615 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
618 struct elf_i386_plt_layout
620 /* The first entry in an absolute procedure linkage table looks like this. */
621 const bfd_byte
*plt0_entry
;
622 unsigned int plt0_entry_size
;
624 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
625 unsigned int plt0_got1_offset
;
626 unsigned int plt0_got2_offset
;
628 /* Later entries in an absolute procedure linkage table look like this. */
629 const bfd_byte
*plt_entry
;
630 unsigned int plt_entry_size
;
632 /* Offsets into plt_entry that are to be replaced with... */
633 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
634 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
635 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
637 /* Offset into plt_entry where the initial value of the GOT entry points. */
638 unsigned int plt_lazy_offset
;
640 /* The first entry in a PIC procedure linkage table looks like this. */
641 const bfd_byte
*pic_plt0_entry
;
643 /* Subsequent entries in a PIC procedure linkage table look like this. */
644 const bfd_byte
*pic_plt_entry
;
646 /* .eh_frame covering the .plt section. */
647 const bfd_byte
*eh_frame_plt
;
648 unsigned int eh_frame_plt_size
;
651 #define GET_PLT_ENTRY_SIZE(abfd) \
652 get_elf_i386_backend_data (abfd)->plt->plt_entry_size
654 /* These are the standard parameters. */
655 static const struct elf_i386_plt_layout elf_i386_plt
=
657 elf_i386_plt0_entry
, /* plt0_entry */
658 sizeof (elf_i386_plt0_entry
), /* plt0_entry_size */
659 2, /* plt0_got1_offset */
660 8, /* plt0_got2_offset */
661 elf_i386_plt_entry
, /* plt_entry */
662 PLT_ENTRY_SIZE
, /* plt_entry_size */
663 2, /* plt_got_offset */
664 7, /* plt_reloc_offset */
665 12, /* plt_plt_offset */
666 6, /* plt_lazy_offset */
667 elf_i386_pic_plt0_entry
, /* pic_plt0_entry */
668 elf_i386_pic_plt_entry
, /* pic_plt_entry */
669 elf_i386_eh_frame_plt
, /* eh_frame_plt */
670 sizeof (elf_i386_eh_frame_plt
), /* eh_frame_plt_size */
674 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
675 for the PLTResolve stub and then for each PLT entry. */
676 #define PLTRESOLVE_RELOCS_SHLIB 0
677 #define PLTRESOLVE_RELOCS 2
678 #define PLT_NON_JUMP_SLOT_RELOCS 2
680 /* Architecture-specific backend data for i386. */
682 struct elf_i386_backend_data
684 /* Parameters describing PLT generation. */
685 const struct elf_i386_plt_layout
*plt
;
687 /* Value used to fill the unused bytes of the first PLT entry. */
688 bfd_byte plt0_pad_byte
;
690 /* True if the target system is VxWorks. */
694 #define get_elf_i386_backend_data(abfd) \
695 ((const struct elf_i386_backend_data *) \
696 get_elf_backend_data (abfd)->arch_data)
698 /* These are the standard parameters. */
699 static const struct elf_i386_backend_data elf_i386_arch_bed
=
701 &elf_i386_plt
, /* plt */
702 0, /* plt0_pad_byte */
706 #define elf_backend_arch_data &elf_i386_arch_bed
708 /* i386 ELF linker hash entry. */
710 struct elf_i386_link_hash_entry
712 struct elf_link_hash_entry elf
;
714 /* Track dynamic relocs copied for this symbol. */
715 struct elf_dyn_relocs
*dyn_relocs
;
717 #define GOT_UNKNOWN 0
721 #define GOT_TLS_IE_POS 5
722 #define GOT_TLS_IE_NEG 6
723 #define GOT_TLS_IE_BOTH 7
724 #define GOT_TLS_GDESC 8
725 #define GOT_TLS_GD_BOTH_P(type) \
726 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
727 #define GOT_TLS_GD_P(type) \
728 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
729 #define GOT_TLS_GDESC_P(type) \
730 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
731 #define GOT_TLS_GD_ANY_P(type) \
732 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
733 unsigned char tls_type
;
735 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
736 starting at the end of the jump table. */
740 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
742 struct elf_i386_obj_tdata
744 struct elf_obj_tdata root
;
746 /* tls_type for each local got entry. */
747 char *local_got_tls_type
;
749 /* GOTPLT entries for TLS descriptors. */
750 bfd_vma
*local_tlsdesc_gotent
;
753 #define elf_i386_tdata(abfd) \
754 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
756 #define elf_i386_local_got_tls_type(abfd) \
757 (elf_i386_tdata (abfd)->local_got_tls_type)
759 #define elf_i386_local_tlsdesc_gotent(abfd) \
760 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
762 #define is_i386_elf(bfd) \
763 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
764 && elf_tdata (bfd) != NULL \
765 && elf_object_id (bfd) == I386_ELF_DATA)
768 elf_i386_mkobject (bfd
*abfd
)
770 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
774 /* i386 ELF linker hash table. */
776 struct elf_i386_link_hash_table
778 struct elf_link_hash_table elf
;
780 /* Short-cuts to get to dynamic linker sections. */
783 asection
*plt_eh_frame
;
787 bfd_signed_vma refcount
;
791 /* The amount of space used by the reserved portion of the sgotplt
792 section, plus whatever space is used by the jump slots. */
793 bfd_vma sgotplt_jump_table_size
;
795 /* Small local sym cache. */
796 struct sym_cache sym_cache
;
798 /* _TLS_MODULE_BASE_ symbol. */
799 struct bfd_link_hash_entry
*tls_module_base
;
801 /* Used by local STT_GNU_IFUNC symbols. */
802 htab_t loc_hash_table
;
803 void * loc_hash_memory
;
805 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
808 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
809 bfd_vma next_tls_desc_index
;
811 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
812 bfd_vma next_jump_slot_index
;
814 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
815 bfd_vma next_irelative_index
;
818 /* Get the i386 ELF linker hash table from a link_info structure. */
820 #define elf_i386_hash_table(p) \
821 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
822 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
824 #define elf_i386_compute_jump_table_size(htab) \
825 ((htab)->next_tls_desc_index * 4)
827 /* Create an entry in an i386 ELF linker hash table. */
829 static struct bfd_hash_entry
*
830 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
831 struct bfd_hash_table
*table
,
834 /* Allocate the structure if it has not already been allocated by a
838 entry
= (struct bfd_hash_entry
*)
839 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
844 /* Call the allocation method of the superclass. */
845 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
848 struct elf_i386_link_hash_entry
*eh
;
850 eh
= (struct elf_i386_link_hash_entry
*) entry
;
851 eh
->dyn_relocs
= NULL
;
852 eh
->tls_type
= GOT_UNKNOWN
;
853 eh
->tlsdesc_got
= (bfd_vma
) -1;
859 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
860 for local symbol so that we can handle local STT_GNU_IFUNC symbols
861 as global symbol. We reuse indx and dynstr_index for local symbol
862 hash since they aren't used by global symbols in this backend. */
865 elf_i386_local_htab_hash (const void *ptr
)
867 struct elf_link_hash_entry
*h
868 = (struct elf_link_hash_entry
*) ptr
;
869 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
872 /* Compare local hash entries. */
875 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
877 struct elf_link_hash_entry
*h1
878 = (struct elf_link_hash_entry
*) ptr1
;
879 struct elf_link_hash_entry
*h2
880 = (struct elf_link_hash_entry
*) ptr2
;
882 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
885 /* Find and/or create a hash entry for local symbol. */
887 static struct elf_link_hash_entry
*
888 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
889 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
892 struct elf_i386_link_hash_entry e
, *ret
;
893 asection
*sec
= abfd
->sections
;
894 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
895 ELF32_R_SYM (rel
->r_info
));
898 e
.elf
.indx
= sec
->id
;
899 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
900 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
901 create
? INSERT
: NO_INSERT
);
908 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
912 ret
= (struct elf_i386_link_hash_entry
*)
913 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
914 sizeof (struct elf_i386_link_hash_entry
));
917 memset (ret
, 0, sizeof (*ret
));
918 ret
->elf
.indx
= sec
->id
;
919 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
920 ret
->elf
.dynindx
= -1;
926 /* Create an i386 ELF linker hash table. */
928 static struct bfd_link_hash_table
*
929 elf_i386_link_hash_table_create (bfd
*abfd
)
931 struct elf_i386_link_hash_table
*ret
;
932 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
934 ret
= (struct elf_i386_link_hash_table
*) bfd_malloc (amt
);
938 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
939 elf_i386_link_hash_newfunc
,
940 sizeof (struct elf_i386_link_hash_entry
),
949 ret
->plt_eh_frame
= NULL
;
950 ret
->tls_ldm_got
.refcount
= 0;
951 ret
->next_tls_desc_index
= 0;
952 ret
->sgotplt_jump_table_size
= 0;
953 ret
->sym_cache
.abfd
= NULL
;
954 ret
->srelplt2
= NULL
;
955 ret
->tls_module_base
= NULL
;
956 ret
->next_jump_slot_index
= 0;
957 ret
->next_irelative_index
= 0;
959 ret
->loc_hash_table
= htab_try_create (1024,
960 elf_i386_local_htab_hash
,
961 elf_i386_local_htab_eq
,
963 ret
->loc_hash_memory
= objalloc_create ();
964 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
970 return &ret
->elf
.root
;
973 /* Destroy an i386 ELF linker hash table. */
976 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
978 struct elf_i386_link_hash_table
*htab
979 = (struct elf_i386_link_hash_table
*) hash
;
981 if (htab
->loc_hash_table
)
982 htab_delete (htab
->loc_hash_table
);
983 if (htab
->loc_hash_memory
)
984 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
985 _bfd_generic_link_hash_table_free (hash
);
988 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
989 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
993 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
995 struct elf_i386_link_hash_table
*htab
;
997 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1000 htab
= elf_i386_hash_table (info
);
1004 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1006 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
1009 || (!info
->shared
&& !htab
->srelbss
))
1012 if (get_elf_i386_backend_data (dynobj
)->is_vxworks
1013 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
1017 if (!info
->no_ld_generated_unwind_info
1018 && htab
->plt_eh_frame
== NULL
1019 && htab
->elf
.splt
!= NULL
)
1021 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
1023 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame",
1025 | SEC_LINKER_CREATED
1027 if (htab
->plt_eh_frame
== NULL
1028 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 2))
1035 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1038 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1039 struct elf_link_hash_entry
*dir
,
1040 struct elf_link_hash_entry
*ind
)
1042 struct elf_i386_link_hash_entry
*edir
, *eind
;
1044 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1045 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1047 if (eind
->dyn_relocs
!= NULL
)
1049 if (edir
->dyn_relocs
!= NULL
)
1051 struct elf_dyn_relocs
**pp
;
1052 struct elf_dyn_relocs
*p
;
1054 /* Add reloc counts against the indirect sym to the direct sym
1055 list. Merge any entries against the same section. */
1056 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1058 struct elf_dyn_relocs
*q
;
1060 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1061 if (q
->sec
== p
->sec
)
1063 q
->pc_count
+= p
->pc_count
;
1064 q
->count
+= p
->count
;
1071 *pp
= edir
->dyn_relocs
;
1074 edir
->dyn_relocs
= eind
->dyn_relocs
;
1075 eind
->dyn_relocs
= NULL
;
1078 if (ind
->root
.type
== bfd_link_hash_indirect
1079 && dir
->got
.refcount
<= 0)
1081 edir
->tls_type
= eind
->tls_type
;
1082 eind
->tls_type
= GOT_UNKNOWN
;
1085 if (ELIMINATE_COPY_RELOCS
1086 && ind
->root
.type
!= bfd_link_hash_indirect
1087 && dir
->dynamic_adjusted
)
1089 /* If called to transfer flags for a weakdef during processing
1090 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1091 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1092 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1093 dir
->ref_regular
|= ind
->ref_regular
;
1094 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1095 dir
->needs_plt
|= ind
->needs_plt
;
1096 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1099 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1102 /* Return TRUE if the TLS access code sequence support transition
1106 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
1108 Elf_Internal_Shdr
*symtab_hdr
,
1109 struct elf_link_hash_entry
**sym_hashes
,
1110 unsigned int r_type
,
1111 const Elf_Internal_Rela
*rel
,
1112 const Elf_Internal_Rela
*relend
)
1114 unsigned int val
, type
;
1115 unsigned long r_symndx
;
1116 struct elf_link_hash_entry
*h
;
1119 /* Get the section contents. */
1120 if (contents
== NULL
)
1122 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1123 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1126 /* FIXME: How to better handle error condition? */
1127 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1130 /* Cache the section contents for elf_link_input_bfd. */
1131 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1135 offset
= rel
->r_offset
;
1140 if (offset
< 2 || (rel
+ 1) >= relend
)
1143 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1144 if (r_type
== R_386_TLS_GD
)
1146 /* Check transition from GD access model. Only
1147 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1148 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1149 can transit to different access model. */
1150 if ((offset
+ 10) > sec
->size
||
1151 (type
!= 0x8d && type
!= 0x04))
1154 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1157 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1161 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1164 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1169 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1170 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1173 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1179 /* Check transition from LD access model. Only
1180 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1181 can transit to different access model. */
1182 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1185 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1186 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1190 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1193 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1194 if (r_symndx
< symtab_hdr
->sh_info
)
1197 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1198 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1199 may be versioned. */
1201 && h
->root
.root
.string
!= NULL
1202 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1203 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1204 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1208 /* Check transition from IE access model:
1209 movl foo@indntpoff(%rip), %eax
1210 movl foo@indntpoff(%rip), %reg
1211 addl foo@indntpoff(%rip), %reg
1214 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1217 /* Check "movl foo@tpoff(%rip), %eax" first. */
1218 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1225 /* Check movl|addl foo@tpoff(%rip), %reg. */
1226 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1227 return ((type
== 0x8b || type
== 0x03)
1228 && (val
& 0xc7) == 0x05);
1230 case R_386_TLS_GOTIE
:
1231 case R_386_TLS_IE_32
:
1232 /* Check transition from {IE_32,GOTIE} access model:
1233 subl foo@{tpoff,gontoff}(%reg1), %reg2
1234 movl foo@{tpoff,gontoff}(%reg1), %reg2
1235 addl foo@{tpoff,gontoff}(%reg1), %reg2
1238 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1241 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1242 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1245 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1246 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1248 case R_386_TLS_GOTDESC
:
1249 /* Check transition from GDesc access model:
1250 leal x@tlsdesc(%ebx), %eax
1252 Make sure it's a leal adding ebx to a 32-bit offset
1253 into any register, although it's probably almost always
1256 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1259 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1262 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1263 return (val
& 0xc7) == 0x83;
1265 case R_386_TLS_DESC_CALL
:
1266 /* Check transition from GDesc access model:
1267 call *x@tlsdesc(%rax)
1269 if (offset
+ 2 <= sec
->size
)
1271 /* Make sure that it's a call *x@tlsdesc(%rax). */
1272 static const unsigned char call
[] = { 0xff, 0x10 };
1273 return memcmp (contents
+ offset
, call
, 2) == 0;
1283 /* Return TRUE if the TLS access transition is OK or no transition
1284 will be performed. Update R_TYPE if there is a transition. */
1287 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1288 asection
*sec
, bfd_byte
*contents
,
1289 Elf_Internal_Shdr
*symtab_hdr
,
1290 struct elf_link_hash_entry
**sym_hashes
,
1291 unsigned int *r_type
, int tls_type
,
1292 const Elf_Internal_Rela
*rel
,
1293 const Elf_Internal_Rela
*relend
,
1294 struct elf_link_hash_entry
*h
,
1295 unsigned long r_symndx
)
1297 unsigned int from_type
= *r_type
;
1298 unsigned int to_type
= from_type
;
1299 bfd_boolean check
= TRUE
;
1301 /* Skip TLS transition for functions. */
1303 && (h
->type
== STT_FUNC
1304 || h
->type
== STT_GNU_IFUNC
))
1310 case R_386_TLS_GOTDESC
:
1311 case R_386_TLS_DESC_CALL
:
1312 case R_386_TLS_IE_32
:
1314 case R_386_TLS_GOTIE
:
1315 if (info
->executable
)
1318 to_type
= R_386_TLS_LE_32
;
1319 else if (from_type
!= R_386_TLS_IE
1320 && from_type
!= R_386_TLS_GOTIE
)
1321 to_type
= R_386_TLS_IE_32
;
1324 /* When we are called from elf_i386_relocate_section, CONTENTS
1325 isn't NULL and there may be additional transitions based on
1327 if (contents
!= NULL
)
1329 unsigned int new_to_type
= to_type
;
1331 if (info
->executable
1334 && (tls_type
& GOT_TLS_IE
))
1335 new_to_type
= R_386_TLS_LE_32
;
1337 if (to_type
== R_386_TLS_GD
1338 || to_type
== R_386_TLS_GOTDESC
1339 || to_type
== R_386_TLS_DESC_CALL
)
1341 if (tls_type
== GOT_TLS_IE_POS
)
1342 new_to_type
= R_386_TLS_GOTIE
;
1343 else if (tls_type
& GOT_TLS_IE
)
1344 new_to_type
= R_386_TLS_IE_32
;
1347 /* We checked the transition before when we were called from
1348 elf_i386_check_relocs. We only want to check the new
1349 transition which hasn't been checked before. */
1350 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1351 to_type
= new_to_type
;
1357 if (info
->executable
)
1358 to_type
= R_386_TLS_LE_32
;
1365 /* Return TRUE if there is no transition. */
1366 if (from_type
== to_type
)
1369 /* Check if the transition can be performed. */
1371 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1372 symtab_hdr
, sym_hashes
,
1373 from_type
, rel
, relend
))
1375 reloc_howto_type
*from
, *to
;
1378 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1379 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1382 name
= h
->root
.root
.string
;
1385 struct elf_i386_link_hash_table
*htab
;
1387 htab
= elf_i386_hash_table (info
);
1392 Elf_Internal_Sym
*isym
;
1394 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1396 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1400 (*_bfd_error_handler
)
1401 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1402 "in section `%A' failed"),
1403 abfd
, sec
, from
->name
, to
->name
, name
,
1404 (unsigned long) rel
->r_offset
);
1405 bfd_set_error (bfd_error_bad_value
);
1413 /* Look through the relocs for a section during the first phase, and
1414 calculate needed space in the global offset table, procedure linkage
1415 table, and dynamic reloc sections. */
1418 elf_i386_check_relocs (bfd
*abfd
,
1419 struct bfd_link_info
*info
,
1421 const Elf_Internal_Rela
*relocs
)
1423 struct elf_i386_link_hash_table
*htab
;
1424 Elf_Internal_Shdr
*symtab_hdr
;
1425 struct elf_link_hash_entry
**sym_hashes
;
1426 const Elf_Internal_Rela
*rel
;
1427 const Elf_Internal_Rela
*rel_end
;
1430 if (info
->relocatable
)
1433 BFD_ASSERT (is_i386_elf (abfd
));
1435 htab
= elf_i386_hash_table (info
);
1439 symtab_hdr
= &elf_symtab_hdr (abfd
);
1440 sym_hashes
= elf_sym_hashes (abfd
);
1444 rel_end
= relocs
+ sec
->reloc_count
;
1445 for (rel
= relocs
; rel
< rel_end
; rel
++)
1447 unsigned int r_type
;
1448 unsigned long r_symndx
;
1449 struct elf_link_hash_entry
*h
;
1450 Elf_Internal_Sym
*isym
;
1453 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1454 r_type
= ELF32_R_TYPE (rel
->r_info
);
1456 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1458 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1464 if (r_symndx
< symtab_hdr
->sh_info
)
1466 /* A local symbol. */
1467 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1472 /* Check relocation against local STT_GNU_IFUNC symbol. */
1473 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1475 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1479 /* Fake a STT_GNU_IFUNC symbol. */
1480 h
->type
= STT_GNU_IFUNC
;
1483 h
->forced_local
= 1;
1484 h
->root
.type
= bfd_link_hash_defined
;
1492 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1493 while (h
->root
.type
== bfd_link_hash_indirect
1494 || h
->root
.type
== bfd_link_hash_warning
)
1495 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1500 /* Create the ifunc sections for static executables. If we
1501 never see an indirect function symbol nor we are building
1502 a static executable, those sections will be empty and
1503 won't appear in output. */
1514 if (htab
->elf
.dynobj
== NULL
)
1515 htab
->elf
.dynobj
= abfd
;
1516 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1521 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1522 it here if it is defined in a non-shared object. */
1523 if (h
->type
== STT_GNU_IFUNC
1526 /* It is referenced by a non-shared object. */
1530 /* STT_GNU_IFUNC symbol must go through PLT. */
1531 h
->plt
.refcount
+= 1;
1533 /* STT_GNU_IFUNC needs dynamic sections. */
1534 if (htab
->elf
.dynobj
== NULL
)
1535 htab
->elf
.dynobj
= abfd
;
1540 if (h
->root
.root
.string
)
1541 name
= h
->root
.root
.string
;
1543 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1545 (*_bfd_error_handler
)
1546 (_("%B: relocation %s against STT_GNU_IFUNC "
1547 "symbol `%s' isn't handled by %s"), abfd
,
1548 elf_howto_table
[r_type
].name
,
1549 name
, __FUNCTION__
);
1550 bfd_set_error (bfd_error_bad_value
);
1555 h
->pointer_equality_needed
= 1;
1558 /* We must copy these reloc types into the
1559 output file. Create a reloc section in
1560 dynobj and make room for this reloc. */
1561 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1562 (abfd
, info
, sec
, sreloc
,
1563 &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
);
1578 h
->got
.refcount
+= 1;
1579 if (htab
->elf
.sgot
== NULL
1580 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1590 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1591 symtab_hdr
, sym_hashes
,
1592 &r_type
, GOT_UNKNOWN
,
1593 rel
, rel_end
, h
, r_symndx
))
1599 htab
->tls_ldm_got
.refcount
+= 1;
1603 /* This symbol requires a procedure linkage table entry. We
1604 actually build the entry in adjust_dynamic_symbol,
1605 because this might be a case of linking PIC code which is
1606 never referenced by a dynamic object, in which case we
1607 don't need to generate a procedure linkage table entry
1610 /* If this is a local symbol, we resolve it directly without
1611 creating a procedure linkage table entry. */
1616 h
->plt
.refcount
+= 1;
1619 case R_386_TLS_IE_32
:
1621 case R_386_TLS_GOTIE
:
1622 if (!info
->executable
)
1623 info
->flags
|= DF_STATIC_TLS
;
1628 case R_386_TLS_GOTDESC
:
1629 case R_386_TLS_DESC_CALL
:
1630 /* This symbol requires a global offset table entry. */
1632 int tls_type
, old_tls_type
;
1637 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1638 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1639 case R_386_TLS_GOTDESC
:
1640 case R_386_TLS_DESC_CALL
:
1641 tls_type
= GOT_TLS_GDESC
; break;
1642 case R_386_TLS_IE_32
:
1643 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1644 tls_type
= GOT_TLS_IE_NEG
;
1646 /* If this is a GD->IE transition, we may use either of
1647 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1648 tls_type
= GOT_TLS_IE
;
1651 case R_386_TLS_GOTIE
:
1652 tls_type
= GOT_TLS_IE_POS
; break;
1657 h
->got
.refcount
+= 1;
1658 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1662 bfd_signed_vma
*local_got_refcounts
;
1664 /* This is a global offset table entry for a local symbol. */
1665 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1666 if (local_got_refcounts
== NULL
)
1670 size
= symtab_hdr
->sh_info
;
1671 size
*= (sizeof (bfd_signed_vma
)
1672 + sizeof (bfd_vma
) + sizeof(char));
1673 local_got_refcounts
= (bfd_signed_vma
*)
1674 bfd_zalloc (abfd
, size
);
1675 if (local_got_refcounts
== NULL
)
1677 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1678 elf_i386_local_tlsdesc_gotent (abfd
)
1679 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1680 elf_i386_local_got_tls_type (abfd
)
1681 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1683 local_got_refcounts
[r_symndx
] += 1;
1684 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1687 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1688 tls_type
|= old_tls_type
;
1689 /* If a TLS symbol is accessed using IE at least once,
1690 there is no point to use dynamic model for it. */
1691 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1692 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1693 || (tls_type
& GOT_TLS_IE
) == 0))
1695 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1696 tls_type
= old_tls_type
;
1697 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1698 && GOT_TLS_GD_ANY_P (tls_type
))
1699 tls_type
|= old_tls_type
;
1703 name
= h
->root
.root
.string
;
1705 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1707 (*_bfd_error_handler
)
1708 (_("%B: `%s' accessed both as normal and "
1709 "thread local symbol"),
1715 if (old_tls_type
!= tls_type
)
1718 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1720 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1728 if (htab
->elf
.sgot
== NULL
)
1730 if (htab
->elf
.dynobj
== NULL
)
1731 htab
->elf
.dynobj
= abfd
;
1732 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1735 if (r_type
!= R_386_TLS_IE
)
1739 case R_386_TLS_LE_32
:
1741 if (info
->executable
)
1743 info
->flags
|= DF_STATIC_TLS
;
1748 if (h
!= NULL
&& info
->executable
)
1750 /* If this reloc is in a read-only section, we might
1751 need a copy reloc. We can't check reliably at this
1752 stage whether the section is read-only, as input
1753 sections have not yet been mapped to output sections.
1754 Tentatively set the flag for now, and correct in
1755 adjust_dynamic_symbol. */
1758 /* We may need a .plt entry if the function this reloc
1759 refers to is in a shared lib. */
1760 h
->plt
.refcount
+= 1;
1761 if (r_type
!= R_386_PC32
)
1762 h
->pointer_equality_needed
= 1;
1765 /* If we are creating a shared library, and this is a reloc
1766 against a global symbol, or a non PC relative reloc
1767 against a local symbol, then we need to copy the reloc
1768 into the shared library. However, if we are linking with
1769 -Bsymbolic, we do not need to copy a reloc against a
1770 global symbol which is defined in an object we are
1771 including in the link (i.e., DEF_REGULAR is set). At
1772 this point we have not seen all the input files, so it is
1773 possible that DEF_REGULAR is not set now but will be set
1774 later (it is never cleared). In case of a weak definition,
1775 DEF_REGULAR may be cleared later by a strong definition in
1776 a shared library. We account for that possibility below by
1777 storing information in the relocs_copied field of the hash
1778 table entry. A similar situation occurs when creating
1779 shared libraries and symbol visibility changes render the
1782 If on the other hand, we are creating an executable, we
1783 may need to keep relocations for symbols satisfied by a
1784 dynamic library if we manage to avoid copy relocs for the
1787 && (sec
->flags
& SEC_ALLOC
) != 0
1788 && (r_type
!= R_386_PC32
1790 && (! SYMBOLIC_BIND (info
, h
)
1791 || h
->root
.type
== bfd_link_hash_defweak
1792 || !h
->def_regular
))))
1793 || (ELIMINATE_COPY_RELOCS
1795 && (sec
->flags
& SEC_ALLOC
) != 0
1797 && (h
->root
.type
== bfd_link_hash_defweak
1798 || !h
->def_regular
)))
1800 struct elf_dyn_relocs
*p
;
1801 struct elf_dyn_relocs
**head
;
1803 /* We must copy these reloc types into the output file.
1804 Create a reloc section in dynobj and make room for
1808 if (htab
->elf
.dynobj
== NULL
)
1809 htab
->elf
.dynobj
= abfd
;
1811 sreloc
= _bfd_elf_make_dynamic_reloc_section
1812 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1818 /* If this is a global symbol, we count the number of
1819 relocations we need for this symbol. */
1822 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1826 /* Track dynamic relocs needed for local syms too.
1827 We really need local syms available to do this
1832 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1837 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1841 vpp
= &elf_section_data (s
)->local_dynrel
;
1842 head
= (struct elf_dyn_relocs
**)vpp
;
1846 if (p
== NULL
|| p
->sec
!= sec
)
1848 bfd_size_type amt
= sizeof *p
;
1849 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1861 if (r_type
== R_386_PC32
)
1866 /* This relocation describes the C++ object vtable hierarchy.
1867 Reconstruct it for later use during GC. */
1868 case R_386_GNU_VTINHERIT
:
1869 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1873 /* This relocation describes which C++ vtable entries are actually
1874 used. Record for later use during GC. */
1875 case R_386_GNU_VTENTRY
:
1876 BFD_ASSERT (h
!= NULL
);
1878 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1890 /* Return the section that should be marked against GC for a given
1894 elf_i386_gc_mark_hook (asection
*sec
,
1895 struct bfd_link_info
*info
,
1896 Elf_Internal_Rela
*rel
,
1897 struct elf_link_hash_entry
*h
,
1898 Elf_Internal_Sym
*sym
)
1901 switch (ELF32_R_TYPE (rel
->r_info
))
1903 case R_386_GNU_VTINHERIT
:
1904 case R_386_GNU_VTENTRY
:
1908 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1911 /* Update the got entry reference counts for the section being removed. */
1914 elf_i386_gc_sweep_hook (bfd
*abfd
,
1915 struct bfd_link_info
*info
,
1917 const Elf_Internal_Rela
*relocs
)
1919 struct elf_i386_link_hash_table
*htab
;
1920 Elf_Internal_Shdr
*symtab_hdr
;
1921 struct elf_link_hash_entry
**sym_hashes
;
1922 bfd_signed_vma
*local_got_refcounts
;
1923 const Elf_Internal_Rela
*rel
, *relend
;
1925 if (info
->relocatable
)
1928 htab
= elf_i386_hash_table (info
);
1932 elf_section_data (sec
)->local_dynrel
= NULL
;
1934 symtab_hdr
= &elf_symtab_hdr (abfd
);
1935 sym_hashes
= elf_sym_hashes (abfd
);
1936 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1938 relend
= relocs
+ sec
->reloc_count
;
1939 for (rel
= relocs
; rel
< relend
; rel
++)
1941 unsigned long r_symndx
;
1942 unsigned int r_type
;
1943 struct elf_link_hash_entry
*h
= NULL
;
1945 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1946 if (r_symndx
>= symtab_hdr
->sh_info
)
1948 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1949 while (h
->root
.type
== bfd_link_hash_indirect
1950 || h
->root
.type
== bfd_link_hash_warning
)
1951 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1955 /* A local symbol. */
1956 Elf_Internal_Sym
*isym
;
1958 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1961 /* Check relocation against local STT_GNU_IFUNC symbol. */
1963 && ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1965 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1973 struct elf_i386_link_hash_entry
*eh
;
1974 struct elf_dyn_relocs
**pp
;
1975 struct elf_dyn_relocs
*p
;
1977 eh
= (struct elf_i386_link_hash_entry
*) h
;
1978 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1981 /* Everything must go for SEC. */
1987 r_type
= ELF32_R_TYPE (rel
->r_info
);
1988 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1989 symtab_hdr
, sym_hashes
,
1990 &r_type
, GOT_UNKNOWN
,
1991 rel
, relend
, h
, r_symndx
))
1997 if (htab
->tls_ldm_got
.refcount
> 0)
1998 htab
->tls_ldm_got
.refcount
-= 1;
2002 case R_386_TLS_GOTDESC
:
2003 case R_386_TLS_DESC_CALL
:
2004 case R_386_TLS_IE_32
:
2006 case R_386_TLS_GOTIE
:
2010 if (h
->got
.refcount
> 0)
2011 h
->got
.refcount
-= 1;
2012 if (h
->type
== STT_GNU_IFUNC
)
2014 if (h
->plt
.refcount
> 0)
2015 h
->plt
.refcount
-= 1;
2018 else if (local_got_refcounts
!= NULL
)
2020 if (local_got_refcounts
[r_symndx
] > 0)
2021 local_got_refcounts
[r_symndx
] -= 1;
2028 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2035 if (h
->plt
.refcount
> 0)
2036 h
->plt
.refcount
-= 1;
2041 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2043 if (h
->got
.refcount
> 0)
2044 h
->got
.refcount
-= 1;
2045 if (h
->plt
.refcount
> 0)
2046 h
->plt
.refcount
-= 1;
2058 /* Adjust a symbol defined by a dynamic object and referenced by a
2059 regular object. The current definition is in some section of the
2060 dynamic object, but we're not including those sections. We have to
2061 change the definition to something the rest of the link can
2065 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2066 struct elf_link_hash_entry
*h
)
2068 struct elf_i386_link_hash_table
*htab
;
2071 /* STT_GNU_IFUNC symbol must go through PLT. */
2072 if (h
->type
== STT_GNU_IFUNC
)
2074 if (h
->plt
.refcount
<= 0)
2076 h
->plt
.offset
= (bfd_vma
) -1;
2082 /* If this is a function, put it in the procedure linkage table. We
2083 will fill in the contents of the procedure linkage table later,
2084 when we know the address of the .got section. */
2085 if (h
->type
== STT_FUNC
2088 if (h
->plt
.refcount
<= 0
2089 || SYMBOL_CALLS_LOCAL (info
, h
)
2090 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2091 && h
->root
.type
== bfd_link_hash_undefweak
))
2093 /* This case can occur if we saw a PLT32 reloc in an input
2094 file, but the symbol was never referred to by a dynamic
2095 object, or if all references were garbage collected. In
2096 such a case, we don't actually need to build a procedure
2097 linkage table, and we can just do a PC32 reloc instead. */
2098 h
->plt
.offset
= (bfd_vma
) -1;
2105 /* It's possible that we incorrectly decided a .plt reloc was
2106 needed for an R_386_PC32 reloc to a non-function sym in
2107 check_relocs. We can't decide accurately between function and
2108 non-function syms in check-relocs; Objects loaded later in
2109 the link may change h->type. So fix it now. */
2110 h
->plt
.offset
= (bfd_vma
) -1;
2112 /* If this is a weak symbol, and there is a real definition, the
2113 processor independent code will have arranged for us to see the
2114 real definition first, and we can just use the same value. */
2115 if (h
->u
.weakdef
!= NULL
)
2117 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2118 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2119 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2120 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2121 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2122 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2126 /* This is a reference to a symbol defined by a dynamic object which
2127 is not a function. */
2129 /* If we are creating a shared library, we must presume that the
2130 only references to the symbol are via the global offset table.
2131 For such cases we need not do anything here; the relocations will
2132 be handled correctly by relocate_section. */
2136 /* If there are no references to this symbol that do not use the
2137 GOT, we don't need to generate a copy reloc. */
2138 if (!h
->non_got_ref
)
2141 /* If -z nocopyreloc was given, we won't generate them either. */
2142 if (info
->nocopyreloc
)
2148 htab
= elf_i386_hash_table (info
);
2152 /* If there aren't any dynamic relocs in read-only sections, then
2153 we can keep the dynamic relocs and avoid the copy reloc. This
2154 doesn't work on VxWorks, where we can not have dynamic relocations
2155 (other than copy and jump slot relocations) in an executable. */
2156 if (ELIMINATE_COPY_RELOCS
2157 && !get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2159 struct elf_i386_link_hash_entry
* eh
;
2160 struct elf_dyn_relocs
*p
;
2162 eh
= (struct elf_i386_link_hash_entry
*) h
;
2163 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2165 s
= p
->sec
->output_section
;
2166 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2177 /* We must allocate the symbol in our .dynbss section, which will
2178 become part of the .bss section of the executable. There will be
2179 an entry for this symbol in the .dynsym section. The dynamic
2180 object will contain position independent code, so all references
2181 from the dynamic object to this symbol will go through the global
2182 offset table. The dynamic linker will use the .dynsym entry to
2183 determine the address it must put in the global offset table, so
2184 both the dynamic object and the regular object will refer to the
2185 same memory location for the variable. */
2187 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2188 copy the initial value out of the dynamic object and into the
2189 runtime process image. */
2190 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2192 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2198 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2201 /* Allocate space in .plt, .got and associated reloc sections for
2205 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2207 struct bfd_link_info
*info
;
2208 struct elf_i386_link_hash_table
*htab
;
2209 struct elf_i386_link_hash_entry
*eh
;
2210 struct elf_dyn_relocs
*p
;
2211 unsigned plt_entry_size
;
2213 if (h
->root
.type
== bfd_link_hash_indirect
)
2216 eh
= (struct elf_i386_link_hash_entry
*) h
;
2218 info
= (struct bfd_link_info
*) inf
;
2219 htab
= elf_i386_hash_table (info
);
2223 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2225 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2226 here if it is defined and referenced in a non-shared object. */
2227 if (h
->type
== STT_GNU_IFUNC
2229 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2231 else if (htab
->elf
.dynamic_sections_created
2232 && h
->plt
.refcount
> 0)
2234 /* Make sure this symbol is output as a dynamic symbol.
2235 Undefined weak syms won't yet be marked as dynamic. */
2236 if (h
->dynindx
== -1
2237 && !h
->forced_local
)
2239 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2244 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2246 asection
*s
= htab
->elf
.splt
;
2248 /* If this is the first .plt entry, make room for the special
2251 s
->size
+= plt_entry_size
;
2253 h
->plt
.offset
= s
->size
;
2255 /* If this symbol is not defined in a regular file, and we are
2256 not generating a shared library, then set the symbol to this
2257 location in the .plt. This is required to make function
2258 pointers compare as equal between the normal executable and
2259 the shared library. */
2263 h
->root
.u
.def
.section
= s
;
2264 h
->root
.u
.def
.value
= h
->plt
.offset
;
2267 /* Make room for this entry. */
2268 s
->size
+= plt_entry_size
;
2270 /* We also need to make an entry in the .got.plt section, which
2271 will be placed in the .got section by the linker script. */
2272 htab
->elf
.sgotplt
->size
+= 4;
2274 /* We also need to make an entry in the .rel.plt section. */
2275 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2276 htab
->elf
.srelplt
->reloc_count
++;
2278 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
2281 /* VxWorks has a second set of relocations for each PLT entry
2282 in executables. They go in a separate relocation section,
2283 which is processed by the kernel loader. */
2285 /* There are two relocations for the initial PLT entry: an
2286 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2287 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2289 if (h
->plt
.offset
== plt_entry_size
)
2290 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2292 /* There are two extra relocations for each subsequent PLT entry:
2293 an R_386_32 relocation for the GOT entry, and an R_386_32
2294 relocation for the PLT entry. */
2296 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2301 h
->plt
.offset
= (bfd_vma
) -1;
2307 h
->plt
.offset
= (bfd_vma
) -1;
2311 eh
->tlsdesc_got
= (bfd_vma
) -1;
2313 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2314 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2315 if (h
->got
.refcount
> 0
2318 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2319 h
->got
.offset
= (bfd_vma
) -1;
2320 else if (h
->got
.refcount
> 0)
2324 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2326 /* Make sure this symbol is output as a dynamic symbol.
2327 Undefined weak syms won't yet be marked as dynamic. */
2328 if (h
->dynindx
== -1
2329 && !h
->forced_local
)
2331 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2336 if (GOT_TLS_GDESC_P (tls_type
))
2338 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2339 - elf_i386_compute_jump_table_size (htab
);
2340 htab
->elf
.sgotplt
->size
+= 8;
2341 h
->got
.offset
= (bfd_vma
) -2;
2343 if (! GOT_TLS_GDESC_P (tls_type
)
2344 || GOT_TLS_GD_P (tls_type
))
2346 h
->got
.offset
= s
->size
;
2348 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2349 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2352 dyn
= htab
->elf
.dynamic_sections_created
;
2353 /* R_386_TLS_IE_32 needs one dynamic relocation,
2354 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2355 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2356 need two), R_386_TLS_GD needs one if local symbol and two if
2358 if (tls_type
== GOT_TLS_IE_BOTH
)
2359 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2360 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2361 || (tls_type
& GOT_TLS_IE
))
2362 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2363 else if (GOT_TLS_GD_P (tls_type
))
2364 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2365 else if (! GOT_TLS_GDESC_P (tls_type
)
2366 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2367 || h
->root
.type
!= bfd_link_hash_undefweak
)
2369 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2370 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2371 if (GOT_TLS_GDESC_P (tls_type
))
2372 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2375 h
->got
.offset
= (bfd_vma
) -1;
2377 if (eh
->dyn_relocs
== NULL
)
2380 /* In the shared -Bsymbolic case, discard space allocated for
2381 dynamic pc-relative relocs against symbols which turn out to be
2382 defined in regular objects. For the normal shared case, discard
2383 space for pc-relative relocs that have become local due to symbol
2384 visibility changes. */
2388 /* The only reloc that uses pc_count is R_386_PC32, which will
2389 appear on a call or on something like ".long foo - .". We
2390 want calls to protected symbols to resolve directly to the
2391 function rather than going via the plt. If people want
2392 function pointer comparisons to work as expected then they
2393 should avoid writing assembly like ".long foo - .". */
2394 if (SYMBOL_CALLS_LOCAL (info
, h
))
2396 struct elf_dyn_relocs
**pp
;
2398 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2400 p
->count
-= p
->pc_count
;
2409 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2411 struct elf_dyn_relocs
**pp
;
2412 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2414 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2421 /* Also discard relocs on undefined weak syms with non-default
2423 if (eh
->dyn_relocs
!= NULL
2424 && h
->root
.type
== bfd_link_hash_undefweak
)
2426 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2427 eh
->dyn_relocs
= NULL
;
2429 /* Make sure undefined weak symbols are output as a dynamic
2431 else if (h
->dynindx
== -1
2432 && !h
->forced_local
)
2434 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2439 else if (ELIMINATE_COPY_RELOCS
)
2441 /* For the non-shared case, discard space for relocs against
2442 symbols which turn out to need copy relocs or are not
2448 || (htab
->elf
.dynamic_sections_created
2449 && (h
->root
.type
== bfd_link_hash_undefweak
2450 || h
->root
.type
== bfd_link_hash_undefined
))))
2452 /* Make sure this symbol is output as a dynamic symbol.
2453 Undefined weak syms won't yet be marked as dynamic. */
2454 if (h
->dynindx
== -1
2455 && !h
->forced_local
)
2457 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2461 /* If that succeeded, we know we'll be keeping all the
2463 if (h
->dynindx
!= -1)
2467 eh
->dyn_relocs
= NULL
;
2472 /* Finally, allocate space. */
2473 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2477 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2479 BFD_ASSERT (sreloc
!= NULL
);
2480 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2486 /* Allocate space in .plt, .got and associated reloc sections for
2487 local dynamic relocs. */
2490 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2492 struct elf_link_hash_entry
*h
2493 = (struct elf_link_hash_entry
*) *slot
;
2495 if (h
->type
!= STT_GNU_IFUNC
2499 || h
->root
.type
!= bfd_link_hash_defined
)
2502 return elf_i386_allocate_dynrelocs (h
, inf
);
2505 /* Find any dynamic relocs that apply to read-only sections. */
2508 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2510 struct elf_i386_link_hash_entry
*eh
;
2511 struct elf_dyn_relocs
*p
;
2513 /* Skip local IFUNC symbols. */
2514 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2517 eh
= (struct elf_i386_link_hash_entry
*) h
;
2518 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2520 asection
*s
= p
->sec
->output_section
;
2522 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2524 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2526 info
->flags
|= DF_TEXTREL
;
2528 if (info
->warn_shared_textrel
&& info
->shared
)
2529 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2530 p
->sec
->owner
, h
->root
.root
.string
,
2533 /* Not an error, just cut short the traversal. */
2540 /* Set the sizes of the dynamic sections. */
2543 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2545 struct elf_i386_link_hash_table
*htab
;
2551 htab
= elf_i386_hash_table (info
);
2554 dynobj
= htab
->elf
.dynobj
;
2558 if (htab
->elf
.dynamic_sections_created
)
2560 /* Set the contents of the .interp section to the interpreter. */
2561 if (info
->executable
)
2563 s
= bfd_get_section_by_name (dynobj
, ".interp");
2566 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2567 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2571 /* Set up .got offsets for local syms, and space for local dynamic
2573 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2575 bfd_signed_vma
*local_got
;
2576 bfd_signed_vma
*end_local_got
;
2577 char *local_tls_type
;
2578 bfd_vma
*local_tlsdesc_gotent
;
2579 bfd_size_type locsymcount
;
2580 Elf_Internal_Shdr
*symtab_hdr
;
2583 if (! is_i386_elf (ibfd
))
2586 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2588 struct elf_dyn_relocs
*p
;
2590 for (p
= ((struct elf_dyn_relocs
*)
2591 elf_section_data (s
)->local_dynrel
);
2595 if (!bfd_is_abs_section (p
->sec
)
2596 && bfd_is_abs_section (p
->sec
->output_section
))
2598 /* Input section has been discarded, either because
2599 it is a copy of a linkonce section or due to
2600 linker script /DISCARD/, so we'll be discarding
2603 else if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2604 && strcmp (p
->sec
->output_section
->name
,
2607 /* Relocations in vxworks .tls_vars sections are
2608 handled specially by the loader. */
2610 else if (p
->count
!= 0)
2612 srel
= elf_section_data (p
->sec
)->sreloc
;
2613 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2614 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2615 && (info
->flags
& DF_TEXTREL
) == 0)
2617 info
->flags
|= DF_TEXTREL
;
2618 if (info
->warn_shared_textrel
&& info
->shared
)
2619 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2620 p
->sec
->owner
, p
->sec
);
2626 local_got
= elf_local_got_refcounts (ibfd
);
2630 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2631 locsymcount
= symtab_hdr
->sh_info
;
2632 end_local_got
= local_got
+ locsymcount
;
2633 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2634 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2636 srel
= htab
->elf
.srelgot
;
2637 for (; local_got
< end_local_got
;
2638 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2640 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2643 if (GOT_TLS_GDESC_P (*local_tls_type
))
2645 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2646 - elf_i386_compute_jump_table_size (htab
);
2647 htab
->elf
.sgotplt
->size
+= 8;
2648 *local_got
= (bfd_vma
) -2;
2650 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2651 || GOT_TLS_GD_P (*local_tls_type
))
2653 *local_got
= s
->size
;
2655 if (GOT_TLS_GD_P (*local_tls_type
)
2656 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2660 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2661 || (*local_tls_type
& GOT_TLS_IE
))
2663 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2664 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2665 else if (GOT_TLS_GD_P (*local_tls_type
)
2666 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2667 srel
->size
+= sizeof (Elf32_External_Rel
);
2668 if (GOT_TLS_GDESC_P (*local_tls_type
))
2669 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2673 *local_got
= (bfd_vma
) -1;
2677 if (htab
->tls_ldm_got
.refcount
> 0)
2679 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2681 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2682 htab
->elf
.sgot
->size
+= 8;
2683 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2686 htab
->tls_ldm_got
.offset
= -1;
2688 /* Allocate global sym .plt and .got entries, and space for global
2689 sym dynamic relocs. */
2690 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2692 /* Allocate .plt and .got entries, and space for local symbols. */
2693 htab_traverse (htab
->loc_hash_table
,
2694 elf_i386_allocate_local_dynrelocs
,
2697 /* For every jump slot reserved in the sgotplt, reloc_count is
2698 incremented. However, when we reserve space for TLS descriptors,
2699 it's not incremented, so in order to compute the space reserved
2700 for them, it suffices to multiply the reloc count by the jump
2703 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2704 so that R_386_IRELATIVE entries come last. */
2705 if (htab
->elf
.srelplt
)
2707 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
2708 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2709 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2711 else if (htab
->elf
.irelplt
)
2712 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2715 if (htab
->elf
.sgotplt
)
2717 struct elf_link_hash_entry
*got
;
2718 got
= elf_link_hash_lookup (elf_hash_table (info
),
2719 "_GLOBAL_OFFSET_TABLE_",
2720 FALSE
, FALSE
, FALSE
);
2722 /* Don't allocate .got.plt section if there are no GOT nor PLT
2723 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
2725 || !got
->ref_regular_nonweak
)
2726 && (htab
->elf
.sgotplt
->size
2727 == get_elf_backend_data (output_bfd
)->got_header_size
)
2728 && (htab
->elf
.splt
== NULL
2729 || htab
->elf
.splt
->size
== 0)
2730 && (htab
->elf
.sgot
== NULL
2731 || htab
->elf
.sgot
->size
== 0)
2732 && (htab
->elf
.iplt
== NULL
2733 || htab
->elf
.iplt
->size
== 0)
2734 && (htab
->elf
.igotplt
== NULL
2735 || htab
->elf
.igotplt
->size
== 0))
2736 htab
->elf
.sgotplt
->size
= 0;
2740 if (htab
->plt_eh_frame
!= NULL
2741 && htab
->elf
.splt
!= NULL
2742 && htab
->elf
.splt
->size
!= 0
2743 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
)
2744 && _bfd_elf_eh_frame_present (info
))
2745 htab
->plt_eh_frame
->size
= sizeof (elf_i386_eh_frame_plt
);
2747 /* We now have determined the sizes of the various dynamic sections.
2748 Allocate memory for them. */
2750 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2752 bfd_boolean strip_section
= TRUE
;
2754 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2757 if (s
== htab
->elf
.splt
2758 || s
== htab
->elf
.sgot
)
2760 /* Strip this section if we don't need it; see the
2762 /* We'd like to strip these sections if they aren't needed, but if
2763 we've exported dynamic symbols from them we must leave them.
2764 It's too late to tell BFD to get rid of the symbols. */
2766 if (htab
->elf
.hplt
!= NULL
)
2767 strip_section
= FALSE
;
2769 else if (s
== htab
->elf
.sgotplt
2770 || s
== htab
->elf
.iplt
2771 || s
== htab
->elf
.igotplt
2772 || s
== htab
->plt_eh_frame
2773 || s
== htab
->sdynbss
)
2775 /* Strip these too. */
2777 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2780 && s
!= htab
->elf
.srelplt
2781 && s
!= htab
->srelplt2
)
2784 /* We use the reloc_count field as a counter if we need
2785 to copy relocs into the output file. */
2790 /* It's not one of our sections, so don't allocate space. */
2796 /* If we don't need this section, strip it from the
2797 output file. This is mostly to handle .rel.bss and
2798 .rel.plt. We must create both sections in
2799 create_dynamic_sections, because they must be created
2800 before the linker maps input sections to output
2801 sections. The linker does that before
2802 adjust_dynamic_symbol is called, and it is that
2803 function which decides whether anything needs to go
2804 into these sections. */
2806 s
->flags
|= SEC_EXCLUDE
;
2810 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2813 /* Allocate memory for the section contents. We use bfd_zalloc
2814 here in case unused entries are not reclaimed before the
2815 section's contents are written out. This should not happen,
2816 but this way if it does, we get a R_386_NONE reloc instead
2818 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2819 if (s
->contents
== NULL
)
2823 if (htab
->plt_eh_frame
!= NULL
2824 && htab
->plt_eh_frame
->contents
!= NULL
)
2826 memcpy (htab
->plt_eh_frame
->contents
, elf_i386_eh_frame_plt
,
2827 sizeof (elf_i386_eh_frame_plt
));
2828 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2829 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2832 if (htab
->elf
.dynamic_sections_created
)
2834 /* Add some entries to the .dynamic section. We fill in the
2835 values later, in elf_i386_finish_dynamic_sections, but we
2836 must add the entries now so that we get the correct size for
2837 the .dynamic section. The DT_DEBUG entry is filled in by the
2838 dynamic linker and used by the debugger. */
2839 #define add_dynamic_entry(TAG, VAL) \
2840 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2842 if (info
->executable
)
2844 if (!add_dynamic_entry (DT_DEBUG
, 0))
2848 if (htab
->elf
.splt
->size
!= 0)
2850 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2851 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2852 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2853 || !add_dynamic_entry (DT_JMPREL
, 0))
2859 if (!add_dynamic_entry (DT_REL
, 0)
2860 || !add_dynamic_entry (DT_RELSZ
, 0)
2861 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2864 /* If any dynamic relocs apply to a read-only section,
2865 then we need a DT_TEXTREL entry. */
2866 if ((info
->flags
& DF_TEXTREL
) == 0)
2867 elf_link_hash_traverse (&htab
->elf
,
2868 elf_i386_readonly_dynrelocs
, info
);
2870 if ((info
->flags
& DF_TEXTREL
) != 0)
2872 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2876 if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2877 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2880 #undef add_dynamic_entry
2886 elf_i386_always_size_sections (bfd
*output_bfd
,
2887 struct bfd_link_info
*info
)
2889 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2893 struct elf_link_hash_entry
*tlsbase
;
2895 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2896 "_TLS_MODULE_BASE_",
2897 FALSE
, FALSE
, FALSE
);
2899 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2901 struct elf_i386_link_hash_table
*htab
;
2902 struct bfd_link_hash_entry
*bh
= NULL
;
2903 const struct elf_backend_data
*bed
2904 = get_elf_backend_data (output_bfd
);
2906 htab
= elf_i386_hash_table (info
);
2910 if (!(_bfd_generic_link_add_one_symbol
2911 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2912 tls_sec
, 0, NULL
, FALSE
,
2913 bed
->collect
, &bh
)))
2916 htab
->tls_module_base
= bh
;
2918 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2919 tlsbase
->def_regular
= 1;
2920 tlsbase
->other
= STV_HIDDEN
;
2921 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2928 /* Set the correct type for an x86 ELF section. We do this by the
2929 section name, which is a hack, but ought to work. */
2932 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2933 Elf_Internal_Shdr
*hdr
,
2938 name
= bfd_get_section_name (abfd
, sec
);
2940 /* This is an ugly, but unfortunately necessary hack that is
2941 needed when producing EFI binaries on x86. It tells
2942 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2943 containing ELF relocation info. We need this hack in order to
2944 be able to generate ELF binaries that can be translated into
2945 EFI applications (which are essentially COFF objects). Those
2946 files contain a COFF ".reloc" section inside an ELFNN object,
2947 which would normally cause BFD to segfault because it would
2948 attempt to interpret this section as containing relocation
2949 entries for section "oc". With this hack enabled, ".reloc"
2950 will be treated as a normal data section, which will avoid the
2951 segfault. However, you won't be able to create an ELFNN binary
2952 with a section named "oc" that needs relocations, but that's
2953 the kind of ugly side-effects you get when detecting section
2954 types based on their names... In practice, this limitation is
2955 unlikely to bite. */
2956 if (strcmp (name
, ".reloc") == 0)
2957 hdr
->sh_type
= SHT_PROGBITS
;
2962 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2963 executables. Rather than setting it to the beginning of the TLS
2964 section, we have to set it to the end. This function may be called
2965 multiple times, it is idempotent. */
2968 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2970 struct elf_i386_link_hash_table
*htab
;
2971 struct bfd_link_hash_entry
*base
;
2973 if (!info
->executable
)
2976 htab
= elf_i386_hash_table (info
);
2980 base
= htab
->tls_module_base
;
2984 base
->u
.def
.value
= htab
->elf
.tls_size
;
2987 /* Return the base VMA address which should be subtracted from real addresses
2988 when resolving @dtpoff relocation.
2989 This is PT_TLS segment p_vaddr. */
2992 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2994 /* If tls_sec is NULL, we should have signalled an error already. */
2995 if (elf_hash_table (info
)->tls_sec
== NULL
)
2997 return elf_hash_table (info
)->tls_sec
->vma
;
3000 /* Return the relocation value for @tpoff relocation
3001 if STT_TLS virtual address is ADDRESS. */
3004 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3006 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3007 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3008 bfd_vma static_tls_size
;
3010 /* If tls_sec is NULL, we should have signalled an error already. */
3011 if (htab
->tls_sec
== NULL
)
3014 /* Consider special static TLS alignment requirements. */
3015 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3016 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3019 /* Relocate an i386 ELF section. */
3022 elf_i386_relocate_section (bfd
*output_bfd
,
3023 struct bfd_link_info
*info
,
3025 asection
*input_section
,
3027 Elf_Internal_Rela
*relocs
,
3028 Elf_Internal_Sym
*local_syms
,
3029 asection
**local_sections
)
3031 struct elf_i386_link_hash_table
*htab
;
3032 Elf_Internal_Shdr
*symtab_hdr
;
3033 struct elf_link_hash_entry
**sym_hashes
;
3034 bfd_vma
*local_got_offsets
;
3035 bfd_vma
*local_tlsdesc_gotents
;
3036 Elf_Internal_Rela
*rel
;
3037 Elf_Internal_Rela
*relend
;
3038 bfd_boolean is_vxworks_tls
;
3039 unsigned plt_entry_size
;
3041 BFD_ASSERT (is_i386_elf (input_bfd
));
3043 htab
= elf_i386_hash_table (info
);
3046 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3047 sym_hashes
= elf_sym_hashes (input_bfd
);
3048 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3049 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3050 /* We have to handle relocations in vxworks .tls_vars sections
3051 specially, because the dynamic loader is 'weird'. */
3052 is_vxworks_tls
= (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3054 && !strcmp (input_section
->output_section
->name
,
3057 elf_i386_set_tls_module_base (info
);
3059 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
3062 relend
= relocs
+ input_section
->reloc_count
;
3063 for (; rel
< relend
; rel
++)
3065 unsigned int r_type
;
3066 reloc_howto_type
*howto
;
3067 unsigned long r_symndx
;
3068 struct elf_link_hash_entry
*h
;
3069 Elf_Internal_Sym
*sym
;
3071 bfd_vma off
, offplt
;
3073 bfd_boolean unresolved_reloc
;
3074 bfd_reloc_status_type r
;
3078 r_type
= ELF32_R_TYPE (rel
->r_info
);
3079 if (r_type
== R_386_GNU_VTINHERIT
3080 || r_type
== R_386_GNU_VTENTRY
)
3083 if ((indx
= r_type
) >= R_386_standard
3084 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3085 >= R_386_ext
- R_386_standard
)
3086 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3087 >= R_386_irelative
- R_386_ext
))
3089 (*_bfd_error_handler
)
3090 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3091 input_bfd
, input_section
, r_type
);
3092 bfd_set_error (bfd_error_bad_value
);
3095 howto
= elf_howto_table
+ indx
;
3097 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3101 unresolved_reloc
= FALSE
;
3102 if (r_symndx
< symtab_hdr
->sh_info
)
3104 sym
= local_syms
+ r_symndx
;
3105 sec
= local_sections
[r_symndx
];
3106 relocation
= (sec
->output_section
->vma
3107 + sec
->output_offset
3110 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3111 && ((sec
->flags
& SEC_MERGE
) != 0
3112 || (info
->relocatable
3113 && sec
->output_offset
!= 0)))
3116 bfd_byte
*where
= contents
+ rel
->r_offset
;
3118 switch (howto
->size
)
3121 addend
= bfd_get_8 (input_bfd
, where
);
3122 if (howto
->pc_relative
)
3124 addend
= (addend
^ 0x80) - 0x80;
3129 addend
= bfd_get_16 (input_bfd
, where
);
3130 if (howto
->pc_relative
)
3132 addend
= (addend
^ 0x8000) - 0x8000;
3137 addend
= bfd_get_32 (input_bfd
, where
);
3138 if (howto
->pc_relative
)
3140 addend
= (addend
^ 0x80000000) - 0x80000000;
3148 if (info
->relocatable
)
3149 addend
+= sec
->output_offset
;
3152 asection
*msec
= sec
;
3153 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3155 addend
-= relocation
;
3156 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3159 switch (howto
->size
)
3162 /* FIXME: overflow checks. */
3163 if (howto
->pc_relative
)
3165 bfd_put_8 (input_bfd
, addend
, where
);
3168 if (howto
->pc_relative
)
3170 bfd_put_16 (input_bfd
, addend
, where
);
3173 if (howto
->pc_relative
)
3175 bfd_put_32 (input_bfd
, addend
, where
);
3179 else if (!info
->relocatable
3180 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3182 /* Relocate against local STT_GNU_IFUNC symbol. */
3183 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3188 /* Set STT_GNU_IFUNC symbol value. */
3189 h
->root
.u
.def
.value
= sym
->st_value
;
3190 h
->root
.u
.def
.section
= sec
;
3195 bfd_boolean warned ATTRIBUTE_UNUSED
;
3197 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3198 r_symndx
, symtab_hdr
, sym_hashes
,
3200 unresolved_reloc
, warned
);
3203 if (sec
!= NULL
&& discarded_section (sec
))
3204 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3205 rel
, 1, relend
, howto
, 0, contents
);
3207 if (info
->relocatable
)
3210 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3211 it here if it is defined in a non-shared object. */
3213 && h
->type
== STT_GNU_IFUNC
3216 asection
*plt
, *gotplt
, *base_got
;
3220 if ((input_section
->flags
& SEC_ALLOC
) == 0
3221 || h
->plt
.offset
== (bfd_vma
) -1)
3224 /* STT_GNU_IFUNC symbol must go through PLT. */
3225 if (htab
->elf
.splt
!= NULL
)
3227 plt
= htab
->elf
.splt
;
3228 gotplt
= htab
->elf
.sgotplt
;
3232 plt
= htab
->elf
.iplt
;
3233 gotplt
= htab
->elf
.igotplt
;
3236 relocation
= (plt
->output_section
->vma
3237 + plt
->output_offset
+ h
->plt
.offset
);
3242 if (h
->root
.root
.string
)
3243 name
= h
->root
.root
.string
;
3245 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3247 (*_bfd_error_handler
)
3248 (_("%B: relocation %s against STT_GNU_IFUNC "
3249 "symbol `%s' isn't handled by %s"), input_bfd
,
3250 elf_howto_table
[r_type
].name
,
3251 name
, __FUNCTION__
);
3252 bfd_set_error (bfd_error_bad_value
);
3256 /* Generate dynamic relcoation only when there is a
3257 non-GOT reference in a shared object. */
3258 if (info
->shared
&& h
->non_got_ref
)
3260 Elf_Internal_Rela outrel
;
3265 /* Need a dynamic relocation to get the real function
3267 offset
= _bfd_elf_section_offset (output_bfd
,
3271 if (offset
== (bfd_vma
) -1
3272 || offset
== (bfd_vma
) -2)
3275 outrel
.r_offset
= (input_section
->output_section
->vma
3276 + input_section
->output_offset
3279 if (h
->dynindx
== -1
3281 || info
->executable
)
3283 /* This symbol is resolved locally. */
3284 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3285 bfd_put_32 (output_bfd
,
3286 (h
->root
.u
.def
.value
3287 + h
->root
.u
.def
.section
->output_section
->vma
3288 + h
->root
.u
.def
.section
->output_offset
),
3292 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3294 sreloc
= htab
->elf
.irelifunc
;
3295 loc
= sreloc
->contents
;
3296 loc
+= (sreloc
->reloc_count
++
3297 * sizeof (Elf32_External_Rel
));
3298 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3300 /* If this reloc is against an external symbol, we
3301 do not want to fiddle with the addend. Otherwise,
3302 we need to include the symbol value so that it
3303 becomes an addend for the dynamic reloc. For an
3304 internal symbol, we have updated addend. */
3313 base_got
= htab
->elf
.sgot
;
3314 off
= h
->got
.offset
;
3316 if (base_got
== NULL
)
3319 if (off
== (bfd_vma
) -1)
3321 /* We can't use h->got.offset here to save state, or
3322 even just remember the offset, as finish_dynamic_symbol
3323 would use that as offset into .got. */
3325 if (htab
->elf
.splt
!= NULL
)
3327 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3328 off
= (plt_index
+ 3) * 4;
3329 base_got
= htab
->elf
.sgotplt
;
3333 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3334 off
= plt_index
* 4;
3335 base_got
= htab
->elf
.igotplt
;
3338 if (h
->dynindx
== -1
3342 /* This references the local defitionion. We must
3343 initialize this entry in the global offset table.
3344 Since the offset must always be a multiple of 8,
3345 we use the least significant bit to record
3346 whether we have initialized it already.
3348 When doing a dynamic link, we create a .rela.got
3349 relocation entry to initialize the value. This
3350 is done in the finish_dynamic_symbol routine. */
3355 bfd_put_32 (output_bfd
, relocation
,
3356 base_got
->contents
+ off
);
3363 /* Adjust for static executables. */
3364 if (htab
->elf
.splt
== NULL
)
3365 relocation
+= gotplt
->output_offset
;
3369 relocation
= (base_got
->output_section
->vma
3370 + base_got
->output_offset
+ off
3371 - gotplt
->output_section
->vma
3372 - gotplt
->output_offset
);
3373 /* Adjust for static executables. */
3374 if (htab
->elf
.splt
== NULL
)
3375 relocation
+= gotplt
->output_offset
;
3381 relocation
-= (gotplt
->output_section
->vma
3382 + gotplt
->output_offset
);
3390 /* Relocation is to the entry for this symbol in the global
3392 if (htab
->elf
.sgot
== NULL
)
3399 off
= h
->got
.offset
;
3400 dyn
= htab
->elf
.dynamic_sections_created
;
3401 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3403 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3404 || (ELF_ST_VISIBILITY (h
->other
)
3405 && h
->root
.type
== bfd_link_hash_undefweak
))
3407 /* This is actually a static link, or it is a
3408 -Bsymbolic link and the symbol is defined
3409 locally, or the symbol was forced to be local
3410 because of a version file. We must initialize
3411 this entry in the global offset table. Since the
3412 offset must always be a multiple of 4, we use the
3413 least significant bit to record whether we have
3414 initialized it already.
3416 When doing a dynamic link, we create a .rel.got
3417 relocation entry to initialize the value. This
3418 is done in the finish_dynamic_symbol routine. */
3423 bfd_put_32 (output_bfd
, relocation
,
3424 htab
->elf
.sgot
->contents
+ off
);
3429 unresolved_reloc
= FALSE
;
3433 if (local_got_offsets
== NULL
)
3436 off
= local_got_offsets
[r_symndx
];
3438 /* The offset must always be a multiple of 4. We use
3439 the least significant bit to record whether we have
3440 already generated the necessary reloc. */
3445 bfd_put_32 (output_bfd
, relocation
,
3446 htab
->elf
.sgot
->contents
+ off
);
3451 Elf_Internal_Rela outrel
;
3454 s
= htab
->elf
.srelgot
;
3458 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3459 + htab
->elf
.sgot
->output_offset
3461 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3463 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3464 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3467 local_got_offsets
[r_symndx
] |= 1;
3471 if (off
>= (bfd_vma
) -2)
3474 relocation
= htab
->elf
.sgot
->output_section
->vma
3475 + htab
->elf
.sgot
->output_offset
+ off
3476 - htab
->elf
.sgotplt
->output_section
->vma
3477 - htab
->elf
.sgotplt
->output_offset
;
3481 /* Relocation is relative to the start of the global offset
3484 /* Check to make sure it isn't a protected function symbol
3485 for shared library since it may not be local when used
3486 as function address. We also need to make sure that a
3487 symbol is defined locally. */
3488 if (info
->shared
&& h
)
3490 if (!h
->def_regular
)
3494 switch (ELF_ST_VISIBILITY (h
->other
))
3497 v
= _("hidden symbol");
3500 v
= _("internal symbol");
3503 v
= _("protected symbol");
3510 (*_bfd_error_handler
)
3511 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3512 input_bfd
, v
, h
->root
.root
.string
);
3513 bfd_set_error (bfd_error_bad_value
);
3516 else if (!info
->executable
3517 && !SYMBOLIC_BIND (info
, h
)
3518 && h
->type
== STT_FUNC
3519 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3521 (*_bfd_error_handler
)
3522 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3523 input_bfd
, h
->root
.root
.string
);
3524 bfd_set_error (bfd_error_bad_value
);
3529 /* Note that sgot is not involved in this
3530 calculation. We always want the start of .got.plt. If we
3531 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3532 permitted by the ABI, we might have to change this
3534 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3535 + htab
->elf
.sgotplt
->output_offset
;
3539 /* Use global offset table as symbol value. */
3540 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3541 + htab
->elf
.sgotplt
->output_offset
;
3542 unresolved_reloc
= FALSE
;
3546 /* Relocation is to the entry for this symbol in the
3547 procedure linkage table. */
3549 /* Resolve a PLT32 reloc against a local symbol directly,
3550 without using the procedure linkage table. */
3554 if (h
->plt
.offset
== (bfd_vma
) -1
3555 || htab
->elf
.splt
== NULL
)
3557 /* We didn't make a PLT entry for this symbol. This
3558 happens when statically linking PIC code, or when
3559 using -Bsymbolic. */
3563 relocation
= (htab
->elf
.splt
->output_section
->vma
3564 + htab
->elf
.splt
->output_offset
3566 unresolved_reloc
= FALSE
;
3571 if ((input_section
->flags
& SEC_ALLOC
) == 0
3577 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3578 || h
->root
.type
!= bfd_link_hash_undefweak
)
3579 && (r_type
!= R_386_PC32
3580 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3581 || (ELIMINATE_COPY_RELOCS
3588 || h
->root
.type
== bfd_link_hash_undefweak
3589 || h
->root
.type
== bfd_link_hash_undefined
)))
3591 Elf_Internal_Rela outrel
;
3593 bfd_boolean skip
, relocate
;
3596 /* When generating a shared object, these relocations
3597 are copied into the output file to be resolved at run
3604 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3606 if (outrel
.r_offset
== (bfd_vma
) -1)
3608 else if (outrel
.r_offset
== (bfd_vma
) -2)
3609 skip
= TRUE
, relocate
= TRUE
;
3610 outrel
.r_offset
+= (input_section
->output_section
->vma
3611 + input_section
->output_offset
);
3614 memset (&outrel
, 0, sizeof outrel
);
3617 && (r_type
== R_386_PC32
3619 || !SYMBOLIC_BIND (info
, h
)
3620 || !h
->def_regular
))
3621 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3624 /* This symbol is local, or marked to become local. */
3626 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3629 sreloc
= elf_section_data (input_section
)->sreloc
;
3631 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3633 r
= bfd_reloc_notsupported
;
3634 goto check_relocation_error
;
3637 loc
= sreloc
->contents
;
3638 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3640 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3642 /* If this reloc is against an external symbol, we do
3643 not want to fiddle with the addend. Otherwise, we
3644 need to include the symbol value so that it becomes
3645 an addend for the dynamic reloc. */
3652 if (!info
->executable
)
3654 Elf_Internal_Rela outrel
;
3658 outrel
.r_offset
= rel
->r_offset
3659 + input_section
->output_section
->vma
3660 + input_section
->output_offset
;
3661 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3662 sreloc
= elf_section_data (input_section
)->sreloc
;
3665 loc
= sreloc
->contents
;
3666 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3667 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3672 case R_386_TLS_GOTDESC
:
3673 case R_386_TLS_DESC_CALL
:
3674 case R_386_TLS_IE_32
:
3675 case R_386_TLS_GOTIE
:
3676 tls_type
= GOT_UNKNOWN
;
3677 if (h
== NULL
&& local_got_offsets
)
3678 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3680 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3681 if (tls_type
== GOT_TLS_IE
)
3682 tls_type
= GOT_TLS_IE_NEG
;
3684 if (! elf_i386_tls_transition (info
, input_bfd
,
3685 input_section
, contents
,
3686 symtab_hdr
, sym_hashes
,
3687 &r_type
, tls_type
, rel
,
3688 relend
, h
, r_symndx
))
3691 if (r_type
== R_386_TLS_LE_32
)
3693 BFD_ASSERT (! unresolved_reloc
);
3694 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3699 /* GD->LE transition. */
3700 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3703 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3705 movl %gs:0, %eax; subl $foo@tpoff, %eax
3706 (6 byte form of subl). */
3707 memcpy (contents
+ rel
->r_offset
- 3,
3708 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3709 roff
= rel
->r_offset
+ 5;
3713 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3715 movl %gs:0, %eax; subl $foo@tpoff, %eax
3716 (6 byte form of subl). */
3717 memcpy (contents
+ rel
->r_offset
- 2,
3718 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3719 roff
= rel
->r_offset
+ 6;
3721 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3723 /* Skip R_386_PC32/R_386_PLT32. */
3727 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3729 /* GDesc -> LE transition.
3730 It's originally something like:
3731 leal x@tlsdesc(%ebx), %eax
3735 Registers other than %eax may be set up here. */
3740 roff
= rel
->r_offset
;
3741 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3743 /* Now modify the instruction as appropriate. */
3744 /* aoliva FIXME: remove the above and xor the byte
3746 bfd_put_8 (output_bfd
, val
^ 0x86,
3747 contents
+ roff
- 1);
3748 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3752 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3754 /* GDesc -> LE transition.
3762 roff
= rel
->r_offset
;
3763 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3764 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3767 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3771 /* IE->LE transition:
3772 Originally it can be one of:
3780 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3783 /* movl foo, %eax. */
3784 bfd_put_8 (output_bfd
, 0xb8,
3785 contents
+ rel
->r_offset
- 1);
3791 type
= bfd_get_8 (input_bfd
,
3792 contents
+ rel
->r_offset
- 2);
3797 bfd_put_8 (output_bfd
, 0xc7,
3798 contents
+ rel
->r_offset
- 2);
3799 bfd_put_8 (output_bfd
,
3800 0xc0 | ((val
>> 3) & 7),
3801 contents
+ rel
->r_offset
- 1);
3805 bfd_put_8 (output_bfd
, 0x81,
3806 contents
+ rel
->r_offset
- 2);
3807 bfd_put_8 (output_bfd
,
3808 0xc0 | ((val
>> 3) & 7),
3809 contents
+ rel
->r_offset
- 1);
3816 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3817 contents
+ rel
->r_offset
);
3822 unsigned int val
, type
;
3824 /* {IE_32,GOTIE}->LE transition:
3825 Originally it can be one of:
3826 subl foo(%reg1), %reg2
3827 movl foo(%reg1), %reg2
3828 addl foo(%reg1), %reg2
3831 movl $foo, %reg2 (6 byte form)
3832 addl $foo, %reg2. */
3833 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3834 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3838 bfd_put_8 (output_bfd
, 0xc7,
3839 contents
+ rel
->r_offset
- 2);
3840 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3841 contents
+ rel
->r_offset
- 1);
3843 else if (type
== 0x2b)
3846 bfd_put_8 (output_bfd
, 0x81,
3847 contents
+ rel
->r_offset
- 2);
3848 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3849 contents
+ rel
->r_offset
- 1);
3851 else if (type
== 0x03)
3854 bfd_put_8 (output_bfd
, 0x81,
3855 contents
+ rel
->r_offset
- 2);
3856 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3857 contents
+ rel
->r_offset
- 1);
3861 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3862 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3863 contents
+ rel
->r_offset
);
3865 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3866 contents
+ rel
->r_offset
);
3871 if (htab
->elf
.sgot
== NULL
)
3876 off
= h
->got
.offset
;
3877 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3881 if (local_got_offsets
== NULL
)
3884 off
= local_got_offsets
[r_symndx
];
3885 offplt
= local_tlsdesc_gotents
[r_symndx
];
3892 Elf_Internal_Rela outrel
;
3897 if (htab
->elf
.srelgot
== NULL
)
3900 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3902 if (GOT_TLS_GDESC_P (tls_type
))
3904 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3905 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3906 <= htab
->elf
.sgotplt
->size
);
3907 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3908 + htab
->elf
.sgotplt
->output_offset
3910 + htab
->sgotplt_jump_table_size
);
3911 sreloc
= htab
->elf
.srelplt
;
3912 loc
= sreloc
->contents
;
3913 loc
+= (htab
->next_tls_desc_index
++
3914 * sizeof (Elf32_External_Rel
));
3915 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3916 <= sreloc
->contents
+ sreloc
->size
);
3917 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3920 BFD_ASSERT (! unresolved_reloc
);
3921 bfd_put_32 (output_bfd
,
3922 relocation
- elf_i386_dtpoff_base (info
),
3923 htab
->elf
.sgotplt
->contents
+ offplt
3924 + htab
->sgotplt_jump_table_size
+ 4);
3928 bfd_put_32 (output_bfd
, 0,
3929 htab
->elf
.sgotplt
->contents
+ offplt
3930 + htab
->sgotplt_jump_table_size
+ 4);
3934 sreloc
= htab
->elf
.srelgot
;
3936 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3937 + htab
->elf
.sgot
->output_offset
+ off
);
3939 if (GOT_TLS_GD_P (tls_type
))
3940 dr_type
= R_386_TLS_DTPMOD32
;
3941 else if (GOT_TLS_GDESC_P (tls_type
))
3943 else if (tls_type
== GOT_TLS_IE_POS
)
3944 dr_type
= R_386_TLS_TPOFF
;
3946 dr_type
= R_386_TLS_TPOFF32
;
3948 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3949 bfd_put_32 (output_bfd
,
3950 relocation
- elf_i386_dtpoff_base (info
),
3951 htab
->elf
.sgot
->contents
+ off
);
3952 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3953 bfd_put_32 (output_bfd
,
3954 elf_i386_dtpoff_base (info
) - relocation
,
3955 htab
->elf
.sgot
->contents
+ off
);
3956 else if (dr_type
!= R_386_TLS_DESC
)
3957 bfd_put_32 (output_bfd
, 0,
3958 htab
->elf
.sgot
->contents
+ off
);
3959 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3961 loc
= sreloc
->contents
;
3962 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3963 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3964 <= sreloc
->contents
+ sreloc
->size
);
3965 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3967 if (GOT_TLS_GD_P (tls_type
))
3971 BFD_ASSERT (! unresolved_reloc
);
3972 bfd_put_32 (output_bfd
,
3973 relocation
- elf_i386_dtpoff_base (info
),
3974 htab
->elf
.sgot
->contents
+ off
+ 4);
3978 bfd_put_32 (output_bfd
, 0,
3979 htab
->elf
.sgot
->contents
+ off
+ 4);
3980 outrel
.r_info
= ELF32_R_INFO (indx
,
3981 R_386_TLS_DTPOFF32
);
3982 outrel
.r_offset
+= 4;
3983 sreloc
->reloc_count
++;
3984 loc
+= sizeof (Elf32_External_Rel
);
3985 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3986 <= sreloc
->contents
+ sreloc
->size
);
3987 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3990 else if (tls_type
== GOT_TLS_IE_BOTH
)
3992 bfd_put_32 (output_bfd
,
3994 ? relocation
- elf_i386_dtpoff_base (info
)
3996 htab
->elf
.sgot
->contents
+ off
+ 4);
3997 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3998 outrel
.r_offset
+= 4;
3999 sreloc
->reloc_count
++;
4000 loc
+= sizeof (Elf32_External_Rel
);
4001 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4008 local_got_offsets
[r_symndx
] |= 1;
4011 if (off
>= (bfd_vma
) -2
4012 && ! GOT_TLS_GDESC_P (tls_type
))
4014 if (r_type
== R_386_TLS_GOTDESC
4015 || r_type
== R_386_TLS_DESC_CALL
)
4017 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4018 unresolved_reloc
= FALSE
;
4020 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4022 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4023 + htab
->elf
.sgotplt
->output_offset
;
4024 relocation
= htab
->elf
.sgot
->output_section
->vma
4025 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4026 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4027 && tls_type
== GOT_TLS_IE_BOTH
)
4029 if (r_type
== R_386_TLS_IE
)
4030 relocation
+= g_o_t
;
4031 unresolved_reloc
= FALSE
;
4033 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4035 unsigned int val
, type
;
4038 /* GD->IE transition. */
4039 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4040 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4043 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
4045 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4047 roff
= rel
->r_offset
- 3;
4051 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
4053 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4054 roff
= rel
->r_offset
- 2;
4056 memcpy (contents
+ roff
,
4057 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4058 contents
[roff
+ 7] = 0x80 | (val
& 7);
4059 /* If foo is used only with foo@gotntpoff(%reg) and
4060 foo@indntpoff, but not with foo@gottpoff(%reg), change
4061 subl $foo@gottpoff(%reg), %eax
4063 addl $foo@gotntpoff(%reg), %eax. */
4064 if (tls_type
== GOT_TLS_IE_POS
)
4065 contents
[roff
+ 6] = 0x03;
4066 bfd_put_32 (output_bfd
,
4067 htab
->elf
.sgot
->output_section
->vma
4068 + htab
->elf
.sgot
->output_offset
+ off
4069 - htab
->elf
.sgotplt
->output_section
->vma
4070 - htab
->elf
.sgotplt
->output_offset
,
4071 contents
+ roff
+ 8);
4072 /* Skip R_386_PLT32. */
4076 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4078 /* GDesc -> IE transition.
4079 It's originally something like:
4080 leal x@tlsdesc(%ebx), %eax
4083 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4085 movl x@gottpoff(%ebx), %eax # before negl %eax
4087 Registers other than %eax may be set up here. */
4091 /* First, make sure it's a leal adding ebx to a 32-bit
4092 offset into any register, although it's probably
4093 almost always going to be eax. */
4094 roff
= rel
->r_offset
;
4096 /* Now modify the instruction as appropriate. */
4097 /* To turn a leal into a movl in the form we use it, it
4098 suffices to change the first byte from 0x8d to 0x8b.
4099 aoliva FIXME: should we decide to keep the leal, all
4100 we have to do is remove the statement below, and
4101 adjust the relaxation of R_386_TLS_DESC_CALL. */
4102 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4104 if (tls_type
== GOT_TLS_IE_BOTH
)
4107 bfd_put_32 (output_bfd
,
4108 htab
->elf
.sgot
->output_section
->vma
4109 + htab
->elf
.sgot
->output_offset
+ off
4110 - htab
->elf
.sgotplt
->output_section
->vma
4111 - htab
->elf
.sgotplt
->output_offset
,
4115 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4117 /* GDesc -> IE transition.
4125 depending on how we transformed the TLS_GOTDESC above.
4130 roff
= rel
->r_offset
;
4132 /* Now modify the instruction as appropriate. */
4133 if (tls_type
!= GOT_TLS_IE_NEG
)
4136 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4137 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4142 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4143 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4153 if (! elf_i386_tls_transition (info
, input_bfd
,
4154 input_section
, contents
,
4155 symtab_hdr
, sym_hashes
,
4156 &r_type
, GOT_UNKNOWN
, rel
,
4157 relend
, h
, r_symndx
))
4160 if (r_type
!= R_386_TLS_LDM
)
4162 /* LD->LE transition:
4163 leal foo(%reg), %eax; call ___tls_get_addr.
4165 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
4166 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4167 memcpy (contents
+ rel
->r_offset
- 2,
4168 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4169 /* Skip R_386_PC32/R_386_PLT32. */
4174 if (htab
->elf
.sgot
== NULL
)
4177 off
= htab
->tls_ldm_got
.offset
;
4182 Elf_Internal_Rela outrel
;
4185 if (htab
->elf
.srelgot
== NULL
)
4188 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4189 + htab
->elf
.sgot
->output_offset
+ off
);
4191 bfd_put_32 (output_bfd
, 0,
4192 htab
->elf
.sgot
->contents
+ off
);
4193 bfd_put_32 (output_bfd
, 0,
4194 htab
->elf
.sgot
->contents
+ off
+ 4);
4195 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4196 loc
= htab
->elf
.srelgot
->contents
;
4197 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4198 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4199 htab
->tls_ldm_got
.offset
|= 1;
4201 relocation
= htab
->elf
.sgot
->output_section
->vma
4202 + htab
->elf
.sgot
->output_offset
+ off
4203 - htab
->elf
.sgotplt
->output_section
->vma
4204 - htab
->elf
.sgotplt
->output_offset
;
4205 unresolved_reloc
= FALSE
;
4208 case R_386_TLS_LDO_32
:
4209 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4210 relocation
-= elf_i386_dtpoff_base (info
);
4212 /* When converting LDO to LE, we must negate. */
4213 relocation
= -elf_i386_tpoff (info
, relocation
);
4216 case R_386_TLS_LE_32
:
4218 if (!info
->executable
)
4220 Elf_Internal_Rela outrel
;
4224 outrel
.r_offset
= rel
->r_offset
4225 + input_section
->output_section
->vma
4226 + input_section
->output_offset
;
4227 if (h
!= NULL
&& h
->dynindx
!= -1)
4231 if (r_type
== R_386_TLS_LE_32
)
4232 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4234 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4235 sreloc
= elf_section_data (input_section
)->sreloc
;
4238 loc
= sreloc
->contents
;
4239 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4240 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4243 else if (r_type
== R_386_TLS_LE_32
)
4244 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4246 relocation
-= elf_i386_dtpoff_base (info
);
4248 else if (r_type
== R_386_TLS_LE_32
)
4249 relocation
= elf_i386_tpoff (info
, relocation
);
4251 relocation
= -elf_i386_tpoff (info
, relocation
);
4258 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4259 because such sections are not SEC_ALLOC and thus ld.so will
4260 not process them. */
4261 if (unresolved_reloc
4262 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4264 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4265 rel
->r_offset
) != (bfd_vma
) -1)
4267 (*_bfd_error_handler
)
4268 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4271 (long) rel
->r_offset
,
4273 h
->root
.root
.string
);
4278 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4279 contents
, rel
->r_offset
,
4282 check_relocation_error
:
4283 if (r
!= bfd_reloc_ok
)
4288 name
= h
->root
.root
.string
;
4291 name
= bfd_elf_string_from_elf_section (input_bfd
,
4292 symtab_hdr
->sh_link
,
4297 name
= bfd_section_name (input_bfd
, sec
);
4300 if (r
== bfd_reloc_overflow
)
4302 if (! ((*info
->callbacks
->reloc_overflow
)
4303 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4304 (bfd_vma
) 0, input_bfd
, input_section
,
4310 (*_bfd_error_handler
)
4311 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4312 input_bfd
, input_section
,
4313 (long) rel
->r_offset
, name
, (int) r
);
4322 /* Finish up dynamic symbol handling. We set the contents of various
4323 dynamic sections here. */
4326 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4327 struct bfd_link_info
*info
,
4328 struct elf_link_hash_entry
*h
,
4329 Elf_Internal_Sym
*sym
)
4331 struct elf_i386_link_hash_table
*htab
;
4332 unsigned plt_entry_size
;
4333 const struct elf_i386_backend_data
*abed
;
4335 htab
= elf_i386_hash_table (info
);
4339 abed
= get_elf_i386_backend_data (output_bfd
);
4340 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
4342 if (h
->plt
.offset
!= (bfd_vma
) -1)
4346 Elf_Internal_Rela rel
;
4348 asection
*plt
, *gotplt
, *relplt
;
4350 /* When building a static executable, use .iplt, .igot.plt and
4351 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4352 if (htab
->elf
.splt
!= NULL
)
4354 plt
= htab
->elf
.splt
;
4355 gotplt
= htab
->elf
.sgotplt
;
4356 relplt
= htab
->elf
.srelplt
;
4360 plt
= htab
->elf
.iplt
;
4361 gotplt
= htab
->elf
.igotplt
;
4362 relplt
= htab
->elf
.irelplt
;
4365 /* This symbol has an entry in the procedure linkage table. Set
4368 if ((h
->dynindx
== -1
4369 && !((h
->forced_local
|| info
->executable
)
4371 && h
->type
== STT_GNU_IFUNC
))
4377 /* Get the index in the procedure linkage table which
4378 corresponds to this symbol. This is the index of this symbol
4379 in all the symbols for which we are making plt entries. The
4380 first entry in the procedure linkage table is reserved.
4382 Get the offset into the .got table of the entry that
4383 corresponds to this function. Each .got entry is 4 bytes.
4384 The first three are reserved.
4386 For static executables, we don't reserve anything. */
4388 if (plt
== htab
->elf
.splt
)
4390 got_offset
= h
->plt
.offset
/ plt_entry_size
- 1;
4391 got_offset
= (got_offset
+ 3) * 4;
4395 got_offset
= h
->plt
.offset
/ plt_entry_size
;
4396 got_offset
= got_offset
* 4;
4399 /* Fill in the entry in the procedure linkage table. */
4402 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->plt_entry
,
4403 abed
->plt
->plt_entry_size
);
4404 bfd_put_32 (output_bfd
,
4405 (gotplt
->output_section
->vma
4406 + gotplt
->output_offset
4408 plt
->contents
+ h
->plt
.offset
4409 + abed
->plt
->plt_got_offset
);
4411 if (abed
->is_vxworks
)
4413 int s
, k
, reloc_index
;
4415 /* Create the R_386_32 relocation referencing the GOT
4416 for this PLT entry. */
4418 /* S: Current slot number (zero-based). */
4419 s
= ((h
->plt
.offset
- abed
->plt
->plt_entry_size
)
4420 / abed
->plt
->plt_entry_size
);
4421 /* K: Number of relocations for PLTResolve. */
4423 k
= PLTRESOLVE_RELOCS_SHLIB
;
4425 k
= PLTRESOLVE_RELOCS
;
4426 /* Skip the PLTresolve relocations, and the relocations for
4427 the other PLT slots. */
4428 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4429 loc
= (htab
->srelplt2
->contents
+ reloc_index
4430 * sizeof (Elf32_External_Rel
));
4432 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4433 + htab
->elf
.splt
->output_offset
4434 + h
->plt
.offset
+ 2),
4435 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4436 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4438 /* Create the R_386_32 relocation referencing the beginning of
4439 the PLT for this GOT entry. */
4440 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4441 + htab
->elf
.sgotplt
->output_offset
4443 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4444 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4445 loc
+ sizeof (Elf32_External_Rel
));
4450 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->pic_plt_entry
,
4451 abed
->plt
->plt_entry_size
);
4452 bfd_put_32 (output_bfd
, got_offset
,
4453 plt
->contents
+ h
->plt
.offset
4454 + abed
->plt
->plt_got_offset
);
4457 /* Fill in the entry in the global offset table. */
4458 bfd_put_32 (output_bfd
,
4459 (plt
->output_section
->vma
4460 + plt
->output_offset
4462 + abed
->plt
->plt_lazy_offset
),
4463 gotplt
->contents
+ got_offset
);
4465 /* Fill in the entry in the .rel.plt section. */
4466 rel
.r_offset
= (gotplt
->output_section
->vma
4467 + gotplt
->output_offset
4469 if (h
->dynindx
== -1
4470 || ((info
->executable
4471 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4473 && h
->type
== STT_GNU_IFUNC
))
4475 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4476 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4477 in the .got.plt section. */
4478 bfd_put_32 (output_bfd
,
4479 (h
->root
.u
.def
.value
4480 + h
->root
.u
.def
.section
->output_section
->vma
4481 + h
->root
.u
.def
.section
->output_offset
),
4482 gotplt
->contents
+ got_offset
);
4483 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4484 /* R_386_IRELATIVE comes last. */
4485 plt_index
= htab
->next_irelative_index
--;
4489 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4490 plt_index
= htab
->next_jump_slot_index
++;
4492 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4493 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4495 /* Don't fill PLT entry for static executables. */
4496 if (plt
== htab
->elf
.splt
)
4498 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4499 plt
->contents
+ h
->plt
.offset
4500 + abed
->plt
->plt_reloc_offset
);
4501 bfd_put_32 (output_bfd
, - (h
->plt
.offset
4502 + abed
->plt
->plt_plt_offset
+ 4),
4503 plt
->contents
+ h
->plt
.offset
4504 + abed
->plt
->plt_plt_offset
);
4507 if (!h
->def_regular
)
4509 /* Mark the symbol as undefined, rather than as defined in
4510 the .plt section. Leave the value if there were any
4511 relocations where pointer equality matters (this is a clue
4512 for the dynamic linker, to make function pointer
4513 comparisons work between an application and shared
4514 library), otherwise set it to zero. If a function is only
4515 called from a binary, there is no need to slow down
4516 shared libraries because of that. */
4517 sym
->st_shndx
= SHN_UNDEF
;
4518 if (!h
->pointer_equality_needed
)
4523 if (h
->got
.offset
!= (bfd_vma
) -1
4524 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4525 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4527 Elf_Internal_Rela rel
;
4530 /* This symbol has an entry in the global offset table. Set it
4533 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4536 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4537 + htab
->elf
.sgot
->output_offset
4538 + (h
->got
.offset
& ~(bfd_vma
) 1));
4540 /* If this is a static link, or it is a -Bsymbolic link and the
4541 symbol is defined locally or was forced to be local because
4542 of a version file, we just want to emit a RELATIVE reloc.
4543 The entry in the global offset table will already have been
4544 initialized in the relocate_section function. */
4546 && h
->type
== STT_GNU_IFUNC
)
4550 /* Generate R_386_GLOB_DAT. */
4557 if (!h
->pointer_equality_needed
)
4560 /* For non-shared object, we can't use .got.plt, which
4561 contains the real function addres if we need pointer
4562 equality. We load the GOT entry with the PLT entry. */
4563 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4564 bfd_put_32 (output_bfd
,
4565 (plt
->output_section
->vma
4566 + plt
->output_offset
+ h
->plt
.offset
),
4567 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4571 else if (info
->shared
4572 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4574 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4575 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4579 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4581 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4582 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4583 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4586 loc
= htab
->elf
.srelgot
->contents
;
4587 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4588 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4593 Elf_Internal_Rela rel
;
4596 /* This symbol needs a copy reloc. Set it up. */
4598 if (h
->dynindx
== -1
4599 || (h
->root
.type
!= bfd_link_hash_defined
4600 && h
->root
.type
!= bfd_link_hash_defweak
)
4601 || htab
->srelbss
== NULL
)
4604 rel
.r_offset
= (h
->root
.u
.def
.value
4605 + h
->root
.u
.def
.section
->output_section
->vma
4606 + h
->root
.u
.def
.section
->output_offset
);
4607 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4608 loc
= htab
->srelbss
->contents
;
4609 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4610 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4616 /* Finish up local dynamic symbol handling. We set the contents of
4617 various dynamic sections here. */
4620 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4622 struct elf_link_hash_entry
*h
4623 = (struct elf_link_hash_entry
*) *slot
;
4624 struct bfd_link_info
*info
4625 = (struct bfd_link_info
*) inf
;
4627 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4631 /* Used to decide how to sort relocs in an optimal manner for the
4632 dynamic linker, before writing them out. */
4634 static enum elf_reloc_type_class
4635 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4637 switch (ELF32_R_TYPE (rela
->r_info
))
4639 case R_386_RELATIVE
:
4640 return reloc_class_relative
;
4641 case R_386_JUMP_SLOT
:
4642 return reloc_class_plt
;
4644 return reloc_class_copy
;
4646 return reloc_class_normal
;
4650 /* Finish up the dynamic sections. */
4653 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4654 struct bfd_link_info
*info
)
4656 struct elf_i386_link_hash_table
*htab
;
4659 const struct elf_i386_backend_data
*abed
;
4661 htab
= elf_i386_hash_table (info
);
4665 dynobj
= htab
->elf
.dynobj
;
4666 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4667 abed
= get_elf_i386_backend_data (output_bfd
);
4669 if (htab
->elf
.dynamic_sections_created
)
4671 Elf32_External_Dyn
*dyncon
, *dynconend
;
4673 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4676 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4677 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4678 for (; dyncon
< dynconend
; dyncon
++)
4680 Elf_Internal_Dyn dyn
;
4683 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4688 if (abed
->is_vxworks
4689 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4694 s
= htab
->elf
.sgotplt
;
4695 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4699 s
= htab
->elf
.srelplt
;
4700 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4704 s
= htab
->elf
.srelplt
;
4705 dyn
.d_un
.d_val
= s
->size
;
4709 /* My reading of the SVR4 ABI indicates that the
4710 procedure linkage table relocs (DT_JMPREL) should be
4711 included in the overall relocs (DT_REL). This is
4712 what Solaris does. However, UnixWare can not handle
4713 that case. Therefore, we override the DT_RELSZ entry
4714 here to make it not include the JMPREL relocs. */
4715 s
= htab
->elf
.srelplt
;
4718 dyn
.d_un
.d_val
-= s
->size
;
4722 /* We may not be using the standard ELF linker script.
4723 If .rel.plt is the first .rel section, we adjust
4724 DT_REL to not include it. */
4725 s
= htab
->elf
.srelplt
;
4728 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4730 dyn
.d_un
.d_ptr
+= s
->size
;
4734 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4737 /* Fill in the first entry in the procedure linkage table. */
4738 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4742 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->pic_plt0_entry
,
4743 abed
->plt
->plt0_entry_size
);
4744 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
4745 abed
->plt0_pad_byte
,
4746 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
4750 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->plt0_entry
,
4751 abed
->plt
->plt0_entry_size
);
4752 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
4753 abed
->plt0_pad_byte
,
4754 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
4755 bfd_put_32 (output_bfd
,
4756 (htab
->elf
.sgotplt
->output_section
->vma
4757 + htab
->elf
.sgotplt
->output_offset
4759 htab
->elf
.splt
->contents
4760 + abed
->plt
->plt0_got1_offset
);
4761 bfd_put_32 (output_bfd
,
4762 (htab
->elf
.sgotplt
->output_section
->vma
4763 + htab
->elf
.sgotplt
->output_offset
4765 htab
->elf
.splt
->contents
4766 + abed
->plt
->plt0_got2_offset
);
4768 if (abed
->is_vxworks
)
4770 Elf_Internal_Rela rel
;
4772 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4773 On IA32 we use REL relocations so the addend goes in
4774 the PLT directly. */
4775 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4776 + htab
->elf
.splt
->output_offset
4777 + abed
->plt
->plt0_got1_offset
);
4778 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4779 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4780 htab
->srelplt2
->contents
);
4781 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4782 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4783 + htab
->elf
.splt
->output_offset
4784 + abed
->plt
->plt0_got2_offset
);
4785 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4786 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4787 htab
->srelplt2
->contents
+
4788 sizeof (Elf32_External_Rel
));
4792 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4793 really seem like the right value. */
4794 elf_section_data (htab
->elf
.splt
->output_section
)
4795 ->this_hdr
.sh_entsize
= 4;
4797 /* Correct the .rel.plt.unloaded relocations. */
4798 if (abed
->is_vxworks
&& !info
->shared
)
4800 int num_plts
= (htab
->elf
.splt
->size
4801 / abed
->plt
->plt_entry_size
) - 1;
4804 p
= htab
->srelplt2
->contents
;
4806 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4808 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4810 for (; num_plts
; num_plts
--)
4812 Elf_Internal_Rela rel
;
4813 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4814 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4815 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4816 p
+= sizeof (Elf32_External_Rel
);
4818 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4819 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4820 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4821 p
+= sizeof (Elf32_External_Rel
);
4827 if (htab
->elf
.sgotplt
)
4829 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4831 (*_bfd_error_handler
)
4832 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4836 /* Fill in the first three entries in the global offset table. */
4837 if (htab
->elf
.sgotplt
->size
> 0)
4839 bfd_put_32 (output_bfd
,
4841 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4842 htab
->elf
.sgotplt
->contents
);
4843 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4844 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4847 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4850 /* Adjust .eh_frame for .plt section. */
4851 if (htab
->plt_eh_frame
!= NULL
4852 && htab
->plt_eh_frame
->contents
!= NULL
)
4854 if (htab
->elf
.splt
!= NULL
4855 && htab
->elf
.splt
->size
!= 0
4856 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4857 && htab
->elf
.splt
->output_section
!= NULL
4858 && htab
->plt_eh_frame
->output_section
!= NULL
)
4860 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4861 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4862 + htab
->plt_eh_frame
->output_offset
4863 + PLT_FDE_START_OFFSET
;
4864 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4865 htab
->plt_eh_frame
->contents
4866 + PLT_FDE_START_OFFSET
);
4868 if (htab
->plt_eh_frame
->sec_info_type
4869 == SEC_INFO_TYPE_EH_FRAME
)
4871 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4873 htab
->plt_eh_frame
->contents
))
4878 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4879 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4881 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4882 htab_traverse (htab
->loc_hash_table
,
4883 elf_i386_finish_local_dynamic_symbol
,
4889 /* Return address for Ith PLT stub in section PLT, for relocation REL
4890 or (bfd_vma) -1 if it should not be included. */
4893 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4894 const arelent
*rel ATTRIBUTE_UNUSED
)
4896 return plt
->vma
+ (i
+ 1) * GET_PLT_ENTRY_SIZE (plt
->owner
);
4899 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4902 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4904 if (h
->plt
.offset
!= (bfd_vma
) -1
4906 && !h
->pointer_equality_needed
)
4909 return _bfd_elf_hash_symbol (h
);
4912 /* Hook called by the linker routine which adds symbols from an object
4916 elf_i386_add_symbol_hook (bfd
* abfd
,
4917 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4918 Elf_Internal_Sym
* sym
,
4919 const char ** namep ATTRIBUTE_UNUSED
,
4920 flagword
* flagsp ATTRIBUTE_UNUSED
,
4921 asection
** secp ATTRIBUTE_UNUSED
,
4922 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4924 if ((abfd
->flags
& DYNAMIC
) == 0
4925 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4926 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4927 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4932 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4933 #define TARGET_LITTLE_NAME "elf32-i386"
4934 #define ELF_ARCH bfd_arch_i386
4935 #define ELF_TARGET_ID I386_ELF_DATA
4936 #define ELF_MACHINE_CODE EM_386
4937 #define ELF_MAXPAGESIZE 0x1000
4939 #define elf_backend_can_gc_sections 1
4940 #define elf_backend_can_refcount 1
4941 #define elf_backend_want_got_plt 1
4942 #define elf_backend_plt_readonly 1
4943 #define elf_backend_want_plt_sym 0
4944 #define elf_backend_got_header_size 12
4945 #define elf_backend_plt_alignment 4
4947 /* Support RELA for objdump of prelink objects. */
4948 #define elf_info_to_howto elf_i386_info_to_howto_rel
4949 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4951 #define bfd_elf32_mkobject elf_i386_mkobject
4953 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4954 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4955 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4956 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4957 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4959 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4960 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4961 #define elf_backend_check_relocs elf_i386_check_relocs
4962 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4963 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4964 #define elf_backend_fake_sections elf_i386_fake_sections
4965 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4966 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4967 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4968 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4969 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4970 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4971 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4972 #define elf_backend_relocate_section elf_i386_relocate_section
4973 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4974 #define elf_backend_always_size_sections elf_i386_always_size_sections
4975 #define elf_backend_omit_section_dynsym \
4976 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4977 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4978 #define elf_backend_hash_symbol elf_i386_hash_symbol
4979 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4980 #undef elf_backend_post_process_headers
4981 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4983 #include "elf32-target.h"
4985 /* FreeBSD support. */
4987 #undef TARGET_LITTLE_SYM
4988 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4989 #undef TARGET_LITTLE_NAME
4990 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4992 #define ELF_OSABI ELFOSABI_FREEBSD
4994 /* The kernel recognizes executables as valid only if they carry a
4995 "FreeBSD" label in the ELF header. So we put this label on all
4996 executables and (for simplicity) also all other object files. */
4999 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
5001 _bfd_elf_set_osabi (abfd
, info
);
5003 #ifdef OLD_FREEBSD_ABI_LABEL
5004 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5005 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5009 #undef elf_backend_post_process_headers
5010 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
5012 #define elf32_bed elf32_i386_fbsd_bed
5014 #undef elf_backend_add_symbol_hook
5016 #include "elf32-target.h"
5020 #undef TARGET_LITTLE_SYM
5021 #define TARGET_LITTLE_SYM bfd_elf32_i386_sol2_vec
5022 #undef TARGET_LITTLE_NAME
5023 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
5025 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5026 objects won't be recognized. */
5030 #define elf32_bed elf32_i386_sol2_bed
5032 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5034 #undef elf_backend_static_tls_alignment
5035 #define elf_backend_static_tls_alignment 8
5037 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5039 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5041 #undef elf_backend_want_plt_sym
5042 #define elf_backend_want_plt_sym 1
5044 #include "elf32-target.h"
5046 /* Native Client support. */
5048 #undef TARGET_LITTLE_SYM
5049 #define TARGET_LITTLE_SYM bfd_elf32_i386_nacl_vec
5050 #undef TARGET_LITTLE_NAME
5051 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
5053 #define elf32_bed elf32_i386_nacl_bed
5055 #undef ELF_MAXPAGESIZE
5056 #define ELF_MAXPAGESIZE 0x10000
5058 /* Restore defaults. */
5060 #undef elf_backend_want_plt_sym
5061 #define elf_backend_want_plt_sym 0
5062 #undef elf_backend_post_process_headers
5063 #define elf_backend_post_process_headers _bfd_elf_set_osabi
5064 #undef elf_backend_static_tls_alignment
5066 /* NaCl uses substantially different PLT entries for the same effects. */
5068 #undef elf_backend_plt_alignment
5069 #define elf_backend_plt_alignment 5
5070 #define NACL_PLT_ENTRY_SIZE 64
5071 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5073 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
5075 0xff, 0x35, /* pushl contents of address */
5076 0, 0, 0, 0, /* replaced with address of .got + 4. */
5077 0x8b, 0x0d, /* movl contents of address, %ecx */
5078 0, 0, 0, 0, /* replaced with address of .got + 8. */
5079 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5080 0xff, 0xe1 /* jmp *%ecx */
5083 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5085 0x8b, 0x0d, /* movl contents of address, %ecx */
5086 0, 0, 0, 0, /* replaced with GOT slot address. */
5087 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5088 0xff, 0xe1, /* jmp *%ecx */
5090 /* Pad to the next 32-byte boundary with nop instructions. */
5092 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5093 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5095 /* Lazy GOT entries point here (32-byte aligned). */
5096 0x68, /* pushl immediate */
5097 0, 0, 0, 0, /* replaced with reloc offset. */
5098 0xe9, /* jmp relative */
5099 0, 0, 0, 0, /* replaced with offset to .plt. */
5101 /* Pad to the next 32-byte boundary with nop instructions. */
5102 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5103 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5107 static const bfd_byte
5108 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
5110 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5111 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5112 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5113 0xff, 0xe1, /* jmp *%ecx */
5115 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
5116 so pad to that size with nop instructions. */
5117 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
5120 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5122 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5123 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5124 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5125 0xff, 0xe1, /* jmp *%ecx */
5127 /* Pad to the next 32-byte boundary with nop instructions. */
5129 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5130 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5132 /* Lazy GOT entries point here (32-byte aligned). */
5133 0x68, /* pushl immediate */
5134 0, 0, 0, 0, /* replaced with offset into relocation table. */
5135 0xe9, /* jmp relative */
5136 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5138 /* Pad to the next 32-byte boundary with nop instructions. */
5139 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5140 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5144 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
5146 #if (PLT_CIE_LENGTH != 20 \
5147 || PLT_FDE_LENGTH != 36 \
5148 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5149 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5150 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5152 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5153 0, 0, 0, 0, /* CIE ID */
5154 1, /* CIE version */
5155 'z', 'R', 0, /* Augmentation string */
5156 1, /* Code alignment factor */
5157 0x7c, /* Data alignment factor: -4 */
5158 8, /* Return address column */
5159 1, /* Augmentation size */
5160 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5161 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5162 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5163 DW_CFA_nop
, DW_CFA_nop
,
5165 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5166 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
5167 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5168 0, 0, 0, 0, /* .plt size goes here */
5169 0, /* Augmentation size */
5170 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
5171 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5172 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
5173 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5174 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5175 13, /* Block length */
5176 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
5177 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
5178 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5179 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
5180 DW_CFA_nop
, DW_CFA_nop
5183 static const struct elf_i386_plt_layout elf_i386_nacl_plt
=
5185 elf_i386_nacl_plt0_entry
, /* plt0_entry */
5186 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
5187 2, /* plt0_got1_offset */
5188 8, /* plt0_got2_offset */
5189 elf_i386_nacl_plt_entry
, /* plt_entry */
5190 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5191 2, /* plt_got_offset */
5192 33, /* plt_reloc_offset */
5193 38, /* plt_plt_offset */
5194 32, /* plt_lazy_offset */
5195 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
5196 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
5197 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
5198 sizeof (elf_i386_nacl_eh_frame_plt
),/* eh_frame_plt_size */
5201 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
5203 &elf_i386_nacl_plt
, /* plt */
5204 0x90, /* plt0_pad_byte: nop insn */
5208 #undef elf_backend_arch_data
5209 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
5211 #undef elf_backend_modify_segment_map
5212 #define elf_backend_modify_segment_map nacl_modify_segment_map
5213 #undef elf_backend_modify_program_headers
5214 #define elf_backend_modify_program_headers nacl_modify_program_headers
5216 #include "elf32-target.h"
5218 /* Restore defaults. */
5219 #undef elf_backend_modify_segment_map
5220 #undef elf_backend_modify_program_headers
5222 /* VxWorks support. */
5224 #undef TARGET_LITTLE_SYM
5225 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
5226 #undef TARGET_LITTLE_NAME
5227 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
5229 #undef elf_backend_plt_alignment
5230 #define elf_backend_plt_alignment 4
5232 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
5234 &elf_i386_plt
, /* plt */
5235 0x90, /* plt0_pad_byte */
5239 #undef elf_backend_arch_data
5240 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
5242 #undef elf_backend_relocs_compatible
5243 #undef elf_backend_post_process_headers
5244 #undef elf_backend_add_symbol_hook
5245 #define elf_backend_add_symbol_hook \
5246 elf_vxworks_add_symbol_hook
5247 #undef elf_backend_link_output_symbol_hook
5248 #define elf_backend_link_output_symbol_hook \
5249 elf_vxworks_link_output_symbol_hook
5250 #undef elf_backend_emit_relocs
5251 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5252 #undef elf_backend_final_write_processing
5253 #define elf_backend_final_write_processing \
5254 elf_vxworks_final_write_processing
5255 #undef elf_backend_static_tls_alignment
5257 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5259 #undef elf_backend_want_plt_sym
5260 #define elf_backend_want_plt_sym 1
5263 #define elf32_bed elf32_i386_vxworks_bed
5265 #include "elf32-target.h"