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
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. */
28 #include "elf-vxworks.h"
29 #include "bfd_stdint.h"
34 /* 386 uses REL relocations instead of RELA. */
39 static reloc_howto_type elf_howto_table
[]=
41 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
42 bfd_elf_generic_reloc
, "R_386_NONE",
43 TRUE
, 0x00000000, 0x00000000, FALSE
),
44 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
45 bfd_elf_generic_reloc
, "R_386_32",
46 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
47 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
48 bfd_elf_generic_reloc
, "R_386_PC32",
49 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
50 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
51 bfd_elf_generic_reloc
, "R_386_GOT32",
52 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
53 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
54 bfd_elf_generic_reloc
, "R_386_PLT32",
55 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
56 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
57 bfd_elf_generic_reloc
, "R_386_COPY",
58 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
59 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
60 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
61 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
62 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
64 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
65 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
66 bfd_elf_generic_reloc
, "R_386_RELATIVE",
67 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
68 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
69 bfd_elf_generic_reloc
, "R_386_GOTOFF",
70 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
71 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
72 bfd_elf_generic_reloc
, "R_386_GOTPC",
73 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
75 /* We have a gap in the reloc numbers here.
76 R_386_standard counts the number up to this point, and
77 R_386_ext_offset is the value to subtract from a reloc type of
78 R_386_16 thru R_386_PC8 to form an index into this table. */
79 #define R_386_standard (R_386_GOTPC + 1)
80 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
82 /* These relocs are a GNU extension. */
83 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
84 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
85 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
86 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_386_TLS_IE",
88 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
89 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
90 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
91 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
92 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_386_TLS_LE",
94 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
95 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_386_TLS_GD",
97 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
98 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
100 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
101 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
102 bfd_elf_generic_reloc
, "R_386_16",
103 TRUE
, 0xffff, 0xffff, FALSE
),
104 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
105 bfd_elf_generic_reloc
, "R_386_PC16",
106 TRUE
, 0xffff, 0xffff, TRUE
),
107 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
108 bfd_elf_generic_reloc
, "R_386_8",
109 TRUE
, 0xff, 0xff, FALSE
),
110 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
111 bfd_elf_generic_reloc
, "R_386_PC8",
112 TRUE
, 0xff, 0xff, TRUE
),
114 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
115 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
116 /* These are common with Solaris TLS implementation. */
117 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
118 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
119 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
120 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
121 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
122 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
123 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
124 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
125 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
126 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
128 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
129 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
131 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
132 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
133 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
134 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
136 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
137 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
138 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
139 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
140 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
142 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
143 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
144 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
145 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
146 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
147 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
150 #define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
151 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
153 /* GNU extension to record C++ vtable hierarchy. */
154 HOWTO (R_386_GNU_VTINHERIT
, /* type */
156 2, /* size (0 = byte, 1 = short, 2 = long) */
158 FALSE
, /* pc_relative */
160 complain_overflow_dont
, /* complain_on_overflow */
161 NULL
, /* special_function */
162 "R_386_GNU_VTINHERIT", /* name */
163 FALSE
, /* partial_inplace */
166 FALSE
), /* pcrel_offset */
168 /* GNU extension to record C++ vtable member usage. */
169 HOWTO (R_386_GNU_VTENTRY
, /* type */
171 2, /* size (0 = byte, 1 = short, 2 = long) */
173 FALSE
, /* pc_relative */
175 complain_overflow_dont
, /* complain_on_overflow */
176 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
177 "R_386_GNU_VTENTRY", /* name */
178 FALSE
, /* partial_inplace */
181 FALSE
) /* pcrel_offset */
183 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
187 #ifdef DEBUG_GEN_RELOC
189 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
194 static reloc_howto_type
*
195 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
196 bfd_reloc_code_real_type code
)
201 TRACE ("BFD_RELOC_NONE");
202 return &elf_howto_table
[R_386_NONE
];
205 TRACE ("BFD_RELOC_32");
206 return &elf_howto_table
[R_386_32
];
209 TRACE ("BFD_RELOC_CTOR");
210 return &elf_howto_table
[R_386_32
];
212 case BFD_RELOC_32_PCREL
:
213 TRACE ("BFD_RELOC_PC32");
214 return &elf_howto_table
[R_386_PC32
];
216 case BFD_RELOC_386_GOT32
:
217 TRACE ("BFD_RELOC_386_GOT32");
218 return &elf_howto_table
[R_386_GOT32
];
220 case BFD_RELOC_386_PLT32
:
221 TRACE ("BFD_RELOC_386_PLT32");
222 return &elf_howto_table
[R_386_PLT32
];
224 case BFD_RELOC_386_COPY
:
225 TRACE ("BFD_RELOC_386_COPY");
226 return &elf_howto_table
[R_386_COPY
];
228 case BFD_RELOC_386_GLOB_DAT
:
229 TRACE ("BFD_RELOC_386_GLOB_DAT");
230 return &elf_howto_table
[R_386_GLOB_DAT
];
232 case BFD_RELOC_386_JUMP_SLOT
:
233 TRACE ("BFD_RELOC_386_JUMP_SLOT");
234 return &elf_howto_table
[R_386_JUMP_SLOT
];
236 case BFD_RELOC_386_RELATIVE
:
237 TRACE ("BFD_RELOC_386_RELATIVE");
238 return &elf_howto_table
[R_386_RELATIVE
];
240 case BFD_RELOC_386_GOTOFF
:
241 TRACE ("BFD_RELOC_386_GOTOFF");
242 return &elf_howto_table
[R_386_GOTOFF
];
244 case BFD_RELOC_386_GOTPC
:
245 TRACE ("BFD_RELOC_386_GOTPC");
246 return &elf_howto_table
[R_386_GOTPC
];
248 /* These relocs are a GNU extension. */
249 case BFD_RELOC_386_TLS_TPOFF
:
250 TRACE ("BFD_RELOC_386_TLS_TPOFF");
251 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
253 case BFD_RELOC_386_TLS_IE
:
254 TRACE ("BFD_RELOC_386_TLS_IE");
255 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
257 case BFD_RELOC_386_TLS_GOTIE
:
258 TRACE ("BFD_RELOC_386_TLS_GOTIE");
259 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
261 case BFD_RELOC_386_TLS_LE
:
262 TRACE ("BFD_RELOC_386_TLS_LE");
263 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
265 case BFD_RELOC_386_TLS_GD
:
266 TRACE ("BFD_RELOC_386_TLS_GD");
267 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
269 case BFD_RELOC_386_TLS_LDM
:
270 TRACE ("BFD_RELOC_386_TLS_LDM");
271 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
274 TRACE ("BFD_RELOC_16");
275 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
277 case BFD_RELOC_16_PCREL
:
278 TRACE ("BFD_RELOC_16_PCREL");
279 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
282 TRACE ("BFD_RELOC_8");
283 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
285 case BFD_RELOC_8_PCREL
:
286 TRACE ("BFD_RELOC_8_PCREL");
287 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
289 /* Common with Sun TLS implementation. */
290 case BFD_RELOC_386_TLS_LDO_32
:
291 TRACE ("BFD_RELOC_386_TLS_LDO_32");
292 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
294 case BFD_RELOC_386_TLS_IE_32
:
295 TRACE ("BFD_RELOC_386_TLS_IE_32");
296 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
298 case BFD_RELOC_386_TLS_LE_32
:
299 TRACE ("BFD_RELOC_386_TLS_LE_32");
300 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
302 case BFD_RELOC_386_TLS_DTPMOD32
:
303 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
304 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
306 case BFD_RELOC_386_TLS_DTPOFF32
:
307 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
308 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
310 case BFD_RELOC_386_TLS_TPOFF32
:
311 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
312 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
314 case BFD_RELOC_386_TLS_GOTDESC
:
315 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
316 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
318 case BFD_RELOC_386_TLS_DESC_CALL
:
319 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
320 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
322 case BFD_RELOC_386_TLS_DESC
:
323 TRACE ("BFD_RELOC_386_TLS_DESC");
324 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
326 case BFD_RELOC_386_IRELATIVE
:
327 TRACE ("BFD_RELOC_386_IRELATIVE");
328 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
330 case BFD_RELOC_VTABLE_INHERIT
:
331 TRACE ("BFD_RELOC_VTABLE_INHERIT");
332 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
334 case BFD_RELOC_VTABLE_ENTRY
:
335 TRACE ("BFD_RELOC_VTABLE_ENTRY");
336 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
346 static reloc_howto_type
*
347 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
352 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
353 if (elf_howto_table
[i
].name
!= NULL
354 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
355 return &elf_howto_table
[i
];
360 static reloc_howto_type
*
361 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
365 if ((indx
= r_type
) >= R_386_standard
366 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
367 >= R_386_ext
- R_386_standard
)
368 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
369 >= R_386_irelative
- R_386_ext
)
370 && ((indx
= r_type
- R_386_vt_offset
) - R_386_irelative
371 >= R_386_vt
- R_386_irelative
))
373 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
377 BFD_ASSERT (elf_howto_table
[indx
].type
== r_type
);
378 return &elf_howto_table
[indx
];
382 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
384 Elf_Internal_Rela
*dst
)
386 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
387 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
390 /* Return whether a symbol name implies a local label. The UnixWare
391 2.1 cc generates temporary symbols that start with .X, so we
392 recognize them here. FIXME: do other SVR4 compilers also use .X?.
393 If so, we should move the .X recognition into
394 _bfd_elf_is_local_label_name. */
397 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
399 if (name
[0] == '.' && name
[1] == 'X')
402 return _bfd_elf_is_local_label_name (abfd
, name
);
405 /* Support for core dump NOTE sections. */
408 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
413 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
415 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
421 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
424 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
428 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
432 switch (note
->descsz
)
437 case 144: /* Linux/i386 */
439 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
442 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
452 /* Make a ".reg/999" section. */
453 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
454 size
, note
->descpos
+ offset
);
458 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
460 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
462 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
467 elf_tdata (abfd
)->core_program
468 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
469 elf_tdata (abfd
)->core_command
470 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
474 switch (note
->descsz
)
479 case 124: /* Linux/i386 elf_prpsinfo. */
480 elf_tdata (abfd
)->core_pid
481 = bfd_get_32 (abfd
, note
->descdata
+ 12);
482 elf_tdata (abfd
)->core_program
483 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
484 elf_tdata (abfd
)->core_command
485 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
489 /* Note that for some reason, a spurious space is tacked
490 onto the end of the args in some (at least one anyway)
491 implementations, so strip it off if it exists. */
493 char *command
= elf_tdata (abfd
)->core_command
;
494 int n
= strlen (command
);
496 if (0 < n
&& command
[n
- 1] == ' ')
497 command
[n
- 1] = '\0';
503 /* Functions for the i386 ELF linker.
505 In order to gain some understanding of code in this file without
506 knowing all the intricate details of the linker, note the
509 Functions named elf_i386_* are called by external routines, other
510 functions are only called locally. elf_i386_* functions appear
511 in this file more or less in the order in which they are called
512 from external routines. eg. elf_i386_check_relocs is called
513 early in the link process, elf_i386_finish_dynamic_sections is
514 one of the last functions. */
517 /* The name of the dynamic interpreter. This is put in the .interp
520 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
522 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
523 copying dynamic variables from a shared lib into an app's dynbss
524 section, and instead use a dynamic relocation to point into the
526 #define ELIMINATE_COPY_RELOCS 1
528 /* The size in bytes of an entry in the procedure linkage table. */
530 #define PLT_ENTRY_SIZE 16
532 /* The first entry in an absolute procedure linkage table looks like
533 this. See the SVR4 ABI i386 supplement to see how this works.
534 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
536 static const bfd_byte elf_i386_plt0_entry
[12] =
538 0xff, 0x35, /* pushl contents of address */
539 0, 0, 0, 0, /* replaced with address of .got + 4. */
540 0xff, 0x25, /* jmp indirect */
541 0, 0, 0, 0 /* replaced with address of .got + 8. */
544 /* Subsequent entries in an absolute procedure linkage table look like
547 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
549 0xff, 0x25, /* jmp indirect */
550 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
551 0x68, /* pushl immediate */
552 0, 0, 0, 0, /* replaced with offset into relocation table. */
553 0xe9, /* jmp relative */
554 0, 0, 0, 0 /* replaced with offset to start of .plt. */
557 /* The first entry in a PIC procedure linkage table look like this.
558 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
560 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
562 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
563 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
566 /* Subsequent entries in a PIC procedure linkage table look like this. */
568 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
570 0xff, 0xa3, /* jmp *offset(%ebx) */
571 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
572 0x68, /* pushl immediate */
573 0, 0, 0, 0, /* replaced with offset into relocation table. */
574 0xe9, /* jmp relative */
575 0, 0, 0, 0 /* replaced with offset to start of .plt. */
578 /* .eh_frame covering the .plt section. */
580 static const bfd_byte elf_i386_eh_frame_plt
[] =
582 #define PLT_CIE_LENGTH 20
583 #define PLT_FDE_LENGTH 36
584 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
585 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
586 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
587 0, 0, 0, 0, /* CIE ID */
589 'z', 'R', 0, /* Augmentation string */
590 1, /* Code alignment factor */
591 0x7c, /* Data alignment factor */
592 8, /* Return address column */
593 1, /* Augmentation size */
594 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
595 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
596 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
597 DW_CFA_nop
, DW_CFA_nop
,
599 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
600 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
601 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
602 0, 0, 0, 0, /* .plt size goes here */
603 0, /* Augmentation size */
604 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
605 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
606 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
607 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
608 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
609 11, /* Block length */
610 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
611 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
612 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
613 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
614 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
617 struct elf_i386_plt_layout
619 /* The first entry in an absolute procedure linkage table looks like this. */
620 const bfd_byte
*plt0_entry
;
621 unsigned int plt0_entry_size
;
623 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
624 unsigned int plt0_got1_offset
;
625 unsigned int plt0_got2_offset
;
627 /* Later entries in an absolute procedure linkage table look like this. */
628 const bfd_byte
*plt_entry
;
629 unsigned int plt_entry_size
;
631 /* Offsets into plt_entry that are to be replaced with... */
632 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
633 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
634 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
636 /* Offset into plt_entry where the initial value of the GOT entry points. */
637 unsigned int plt_lazy_offset
;
639 /* The first entry in a PIC procedure linkage table looks like this. */
640 const bfd_byte
*pic_plt0_entry
;
642 /* Subsequent entries in a PIC procedure linkage table look like this. */
643 const bfd_byte
*pic_plt_entry
;
645 /* .eh_frame covering the .plt section. */
646 const bfd_byte
*eh_frame_plt
;
647 unsigned int eh_frame_plt_size
;
650 #define GET_PLT_ENTRY_SIZE(abfd) \
651 get_elf_i386_backend_data (abfd)->plt->plt_entry_size
653 /* These are the standard parameters. */
654 static const struct elf_i386_plt_layout elf_i386_plt
=
656 elf_i386_plt0_entry
, /* plt0_entry */
657 sizeof (elf_i386_plt0_entry
), /* plt0_entry_size */
658 2, /* plt0_got1_offset */
659 8, /* plt0_got2_offset */
660 elf_i386_plt_entry
, /* plt_entry */
661 PLT_ENTRY_SIZE
, /* plt_entry_size */
662 2, /* plt_got_offset */
663 7, /* plt_reloc_offset */
664 12, /* plt_plt_offset */
665 6, /* plt_lazy_offset */
666 elf_i386_pic_plt0_entry
, /* pic_plt0_entry */
667 elf_i386_pic_plt_entry
, /* pic_plt_entry */
668 elf_i386_eh_frame_plt
, /* eh_frame_plt */
669 sizeof (elf_i386_eh_frame_plt
), /* eh_frame_plt_size */
673 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
674 for the PLTResolve stub and then for each PLT entry. */
675 #define PLTRESOLVE_RELOCS_SHLIB 0
676 #define PLTRESOLVE_RELOCS 2
677 #define PLT_NON_JUMP_SLOT_RELOCS 2
679 /* Architecture-specific backend data for i386. */
681 struct elf_i386_backend_data
683 /* Parameters describing PLT generation. */
684 const struct elf_i386_plt_layout
*plt
;
686 /* Value used to fill the unused bytes of the first PLT entry. */
687 bfd_byte plt0_pad_byte
;
689 /* True if the target system is VxWorks. */
693 #define get_elf_i386_backend_data(abfd) \
694 ((const struct elf_i386_backend_data *) \
695 get_elf_backend_data (abfd)->arch_data)
697 /* These are the standard parameters. */
698 static const struct elf_i386_backend_data elf_i386_arch_bed
=
700 &elf_i386_plt
, /* plt */
701 0, /* plt0_pad_byte */
705 #define elf_backend_arch_data &elf_i386_arch_bed
707 /* i386 ELF linker hash entry. */
709 struct elf_i386_link_hash_entry
711 struct elf_link_hash_entry elf
;
713 /* Track dynamic relocs copied for this symbol. */
714 struct elf_dyn_relocs
*dyn_relocs
;
716 #define GOT_UNKNOWN 0
720 #define GOT_TLS_IE_POS 5
721 #define GOT_TLS_IE_NEG 6
722 #define GOT_TLS_IE_BOTH 7
723 #define GOT_TLS_GDESC 8
724 #define GOT_TLS_GD_BOTH_P(type) \
725 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
726 #define GOT_TLS_GD_P(type) \
727 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
728 #define GOT_TLS_GDESC_P(type) \
729 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
730 #define GOT_TLS_GD_ANY_P(type) \
731 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
732 unsigned char tls_type
;
734 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
735 starting at the end of the jump table. */
739 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
741 struct elf_i386_obj_tdata
743 struct elf_obj_tdata root
;
745 /* tls_type for each local got entry. */
746 char *local_got_tls_type
;
748 /* GOTPLT entries for TLS descriptors. */
749 bfd_vma
*local_tlsdesc_gotent
;
752 #define elf_i386_tdata(abfd) \
753 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
755 #define elf_i386_local_got_tls_type(abfd) \
756 (elf_i386_tdata (abfd)->local_got_tls_type)
758 #define elf_i386_local_tlsdesc_gotent(abfd) \
759 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
761 #define is_i386_elf(bfd) \
762 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
763 && elf_tdata (bfd) != NULL \
764 && elf_object_id (bfd) == I386_ELF_DATA)
767 elf_i386_mkobject (bfd
*abfd
)
769 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
773 /* i386 ELF linker hash table. */
775 struct elf_i386_link_hash_table
777 struct elf_link_hash_table elf
;
779 /* Short-cuts to get to dynamic linker sections. */
782 asection
*plt_eh_frame
;
786 bfd_signed_vma refcount
;
790 /* The amount of space used by the reserved portion of the sgotplt
791 section, plus whatever space is used by the jump slots. */
792 bfd_vma sgotplt_jump_table_size
;
794 /* Small local sym cache. */
795 struct sym_cache sym_cache
;
797 /* _TLS_MODULE_BASE_ symbol. */
798 struct bfd_link_hash_entry
*tls_module_base
;
800 /* Used by local STT_GNU_IFUNC symbols. */
801 htab_t loc_hash_table
;
802 void * loc_hash_memory
;
804 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
807 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
808 bfd_vma next_tls_desc_index
;
810 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
811 bfd_vma next_jump_slot_index
;
813 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
814 bfd_vma next_irelative_index
;
817 /* Get the i386 ELF linker hash table from a link_info structure. */
819 #define elf_i386_hash_table(p) \
820 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
821 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
823 #define elf_i386_compute_jump_table_size(htab) \
824 ((htab)->next_tls_desc_index * 4)
826 /* Create an entry in an i386 ELF linker hash table. */
828 static struct bfd_hash_entry
*
829 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
830 struct bfd_hash_table
*table
,
833 /* Allocate the structure if it has not already been allocated by a
837 entry
= (struct bfd_hash_entry
*)
838 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
843 /* Call the allocation method of the superclass. */
844 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
847 struct elf_i386_link_hash_entry
*eh
;
849 eh
= (struct elf_i386_link_hash_entry
*) entry
;
850 eh
->dyn_relocs
= NULL
;
851 eh
->tls_type
= GOT_UNKNOWN
;
852 eh
->tlsdesc_got
= (bfd_vma
) -1;
858 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
859 for local symbol so that we can handle local STT_GNU_IFUNC symbols
860 as global symbol. We reuse indx and dynstr_index for local symbol
861 hash since they aren't used by global symbols in this backend. */
864 elf_i386_local_htab_hash (const void *ptr
)
866 struct elf_link_hash_entry
*h
867 = (struct elf_link_hash_entry
*) ptr
;
868 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
871 /* Compare local hash entries. */
874 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
876 struct elf_link_hash_entry
*h1
877 = (struct elf_link_hash_entry
*) ptr1
;
878 struct elf_link_hash_entry
*h2
879 = (struct elf_link_hash_entry
*) ptr2
;
881 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
884 /* Find and/or create a hash entry for local symbol. */
886 static struct elf_link_hash_entry
*
887 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
888 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
891 struct elf_i386_link_hash_entry e
, *ret
;
892 asection
*sec
= abfd
->sections
;
893 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
894 ELF32_R_SYM (rel
->r_info
));
897 e
.elf
.indx
= sec
->id
;
898 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
899 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
900 create
? INSERT
: NO_INSERT
);
907 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
911 ret
= (struct elf_i386_link_hash_entry
*)
912 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
913 sizeof (struct elf_i386_link_hash_entry
));
916 memset (ret
, 0, sizeof (*ret
));
917 ret
->elf
.indx
= sec
->id
;
918 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
919 ret
->elf
.dynindx
= -1;
925 /* Create an i386 ELF linker hash table. */
927 static struct bfd_link_hash_table
*
928 elf_i386_link_hash_table_create (bfd
*abfd
)
930 struct elf_i386_link_hash_table
*ret
;
931 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
933 ret
= (struct elf_i386_link_hash_table
*) bfd_malloc (amt
);
937 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
938 elf_i386_link_hash_newfunc
,
939 sizeof (struct elf_i386_link_hash_entry
),
948 ret
->plt_eh_frame
= NULL
;
949 ret
->tls_ldm_got
.refcount
= 0;
950 ret
->next_tls_desc_index
= 0;
951 ret
->sgotplt_jump_table_size
= 0;
952 ret
->sym_cache
.abfd
= NULL
;
953 ret
->srelplt2
= NULL
;
954 ret
->tls_module_base
= NULL
;
955 ret
->next_jump_slot_index
= 0;
956 ret
->next_irelative_index
= 0;
958 ret
->loc_hash_table
= htab_try_create (1024,
959 elf_i386_local_htab_hash
,
960 elf_i386_local_htab_eq
,
962 ret
->loc_hash_memory
= objalloc_create ();
963 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
969 return &ret
->elf
.root
;
972 /* Destroy an i386 ELF linker hash table. */
975 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
977 struct elf_i386_link_hash_table
*htab
978 = (struct elf_i386_link_hash_table
*) hash
;
980 if (htab
->loc_hash_table
)
981 htab_delete (htab
->loc_hash_table
);
982 if (htab
->loc_hash_memory
)
983 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
984 _bfd_generic_link_hash_table_free (hash
);
987 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
988 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
992 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
994 struct elf_i386_link_hash_table
*htab
;
996 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
999 htab
= elf_i386_hash_table (info
);
1003 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1005 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
1008 || (!info
->shared
&& !htab
->srelbss
))
1011 if (get_elf_i386_backend_data (dynobj
)->is_vxworks
1012 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
1016 if (!info
->no_ld_generated_unwind_info
1017 && bfd_get_section_by_name (dynobj
, ".eh_frame") == NULL
1018 && htab
->elf
.splt
!= NULL
)
1020 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
1022 = bfd_make_section_with_flags (dynobj
, ".eh_frame",
1023 flags
| SEC_READONLY
);
1024 if (htab
->plt_eh_frame
== NULL
1025 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 2))
1028 htab
->plt_eh_frame
->size
= sizeof (elf_i386_eh_frame_plt
);
1029 htab
->plt_eh_frame
->contents
1030 = bfd_alloc (dynobj
, htab
->plt_eh_frame
->size
);
1031 memcpy (htab
->plt_eh_frame
->contents
, elf_i386_eh_frame_plt
,
1032 sizeof (elf_i386_eh_frame_plt
));
1038 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1041 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1042 struct elf_link_hash_entry
*dir
,
1043 struct elf_link_hash_entry
*ind
)
1045 struct elf_i386_link_hash_entry
*edir
, *eind
;
1047 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1048 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1050 if (eind
->dyn_relocs
!= NULL
)
1052 if (edir
->dyn_relocs
!= NULL
)
1054 struct elf_dyn_relocs
**pp
;
1055 struct elf_dyn_relocs
*p
;
1057 /* Add reloc counts against the indirect sym to the direct sym
1058 list. Merge any entries against the same section. */
1059 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1061 struct elf_dyn_relocs
*q
;
1063 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1064 if (q
->sec
== p
->sec
)
1066 q
->pc_count
+= p
->pc_count
;
1067 q
->count
+= p
->count
;
1074 *pp
= edir
->dyn_relocs
;
1077 edir
->dyn_relocs
= eind
->dyn_relocs
;
1078 eind
->dyn_relocs
= NULL
;
1081 if (ind
->root
.type
== bfd_link_hash_indirect
1082 && dir
->got
.refcount
<= 0)
1084 edir
->tls_type
= eind
->tls_type
;
1085 eind
->tls_type
= GOT_UNKNOWN
;
1088 if (ELIMINATE_COPY_RELOCS
1089 && ind
->root
.type
!= bfd_link_hash_indirect
1090 && dir
->dynamic_adjusted
)
1092 /* If called to transfer flags for a weakdef during processing
1093 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1094 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1095 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1096 dir
->ref_regular
|= ind
->ref_regular
;
1097 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1098 dir
->needs_plt
|= ind
->needs_plt
;
1099 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1102 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1105 /* Return TRUE if the TLS access code sequence support transition
1109 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
1111 Elf_Internal_Shdr
*symtab_hdr
,
1112 struct elf_link_hash_entry
**sym_hashes
,
1113 unsigned int r_type
,
1114 const Elf_Internal_Rela
*rel
,
1115 const Elf_Internal_Rela
*relend
)
1117 unsigned int val
, type
;
1118 unsigned long r_symndx
;
1119 struct elf_link_hash_entry
*h
;
1122 /* Get the section contents. */
1123 if (contents
== NULL
)
1125 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1126 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1129 /* FIXME: How to better handle error condition? */
1130 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1133 /* Cache the section contents for elf_link_input_bfd. */
1134 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1138 offset
= rel
->r_offset
;
1143 if (offset
< 2 || (rel
+ 1) >= relend
)
1146 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1147 if (r_type
== R_386_TLS_GD
)
1149 /* Check transition from GD access model. Only
1150 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1151 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1152 can transit to different access model. */
1153 if ((offset
+ 10) > sec
->size
||
1154 (type
!= 0x8d && type
!= 0x04))
1157 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1160 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1164 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1167 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1172 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1173 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1176 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1182 /* Check transition from LD access model. Only
1183 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1184 can transit to different access model. */
1185 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1188 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1189 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1193 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1196 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1197 if (r_symndx
< symtab_hdr
->sh_info
)
1200 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1201 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1202 may be versioned. */
1204 && h
->root
.root
.string
!= NULL
1205 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1206 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1207 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1211 /* Check transition from IE access model:
1212 movl foo@indntpoff(%rip), %eax
1213 movl foo@indntpoff(%rip), %reg
1214 addl foo@indntpoff(%rip), %reg
1217 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1220 /* Check "movl foo@tpoff(%rip), %eax" first. */
1221 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1228 /* Check movl|addl foo@tpoff(%rip), %reg. */
1229 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1230 return ((type
== 0x8b || type
== 0x03)
1231 && (val
& 0xc7) == 0x05);
1233 case R_386_TLS_GOTIE
:
1234 case R_386_TLS_IE_32
:
1235 /* Check transition from {IE_32,GOTIE} access model:
1236 subl foo@{tpoff,gontoff}(%reg1), %reg2
1237 movl foo@{tpoff,gontoff}(%reg1), %reg2
1238 addl foo@{tpoff,gontoff}(%reg1), %reg2
1241 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1244 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1245 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1248 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1249 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1251 case R_386_TLS_GOTDESC
:
1252 /* Check transition from GDesc access model:
1253 leal x@tlsdesc(%ebx), %eax
1255 Make sure it's a leal adding ebx to a 32-bit offset
1256 into any register, although it's probably almost always
1259 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1262 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1265 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1266 return (val
& 0xc7) == 0x83;
1268 case R_386_TLS_DESC_CALL
:
1269 /* Check transition from GDesc access model:
1270 call *x@tlsdesc(%rax)
1272 if (offset
+ 2 <= sec
->size
)
1274 /* Make sure that it's a call *x@tlsdesc(%rax). */
1275 static const unsigned char call
[] = { 0xff, 0x10 };
1276 return memcmp (contents
+ offset
, call
, 2) == 0;
1286 /* Return TRUE if the TLS access transition is OK or no transition
1287 will be performed. Update R_TYPE if there is a transition. */
1290 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1291 asection
*sec
, bfd_byte
*contents
,
1292 Elf_Internal_Shdr
*symtab_hdr
,
1293 struct elf_link_hash_entry
**sym_hashes
,
1294 unsigned int *r_type
, int tls_type
,
1295 const Elf_Internal_Rela
*rel
,
1296 const Elf_Internal_Rela
*relend
,
1297 struct elf_link_hash_entry
*h
,
1298 unsigned long r_symndx
)
1300 unsigned int from_type
= *r_type
;
1301 unsigned int to_type
= from_type
;
1302 bfd_boolean check
= TRUE
;
1304 /* Skip TLS transition for functions. */
1306 && (h
->type
== STT_FUNC
1307 || h
->type
== STT_GNU_IFUNC
))
1313 case R_386_TLS_GOTDESC
:
1314 case R_386_TLS_DESC_CALL
:
1315 case R_386_TLS_IE_32
:
1317 case R_386_TLS_GOTIE
:
1318 if (info
->executable
)
1321 to_type
= R_386_TLS_LE_32
;
1322 else if (from_type
!= R_386_TLS_IE
1323 && from_type
!= R_386_TLS_GOTIE
)
1324 to_type
= R_386_TLS_IE_32
;
1327 /* When we are called from elf_i386_relocate_section, CONTENTS
1328 isn't NULL and there may be additional transitions based on
1330 if (contents
!= NULL
)
1332 unsigned int new_to_type
= to_type
;
1334 if (info
->executable
1337 && (tls_type
& GOT_TLS_IE
))
1338 new_to_type
= R_386_TLS_LE_32
;
1340 if (to_type
== R_386_TLS_GD
1341 || to_type
== R_386_TLS_GOTDESC
1342 || to_type
== R_386_TLS_DESC_CALL
)
1344 if (tls_type
== GOT_TLS_IE_POS
)
1345 new_to_type
= R_386_TLS_GOTIE
;
1346 else if (tls_type
& GOT_TLS_IE
)
1347 new_to_type
= R_386_TLS_IE_32
;
1350 /* We checked the transition before when we were called from
1351 elf_i386_check_relocs. We only want to check the new
1352 transition which hasn't been checked before. */
1353 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1354 to_type
= new_to_type
;
1360 if (info
->executable
)
1361 to_type
= R_386_TLS_LE_32
;
1368 /* Return TRUE if there is no transition. */
1369 if (from_type
== to_type
)
1372 /* Check if the transition can be performed. */
1374 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1375 symtab_hdr
, sym_hashes
,
1376 from_type
, rel
, relend
))
1378 reloc_howto_type
*from
, *to
;
1381 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1382 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1385 name
= h
->root
.root
.string
;
1388 struct elf_i386_link_hash_table
*htab
;
1390 htab
= elf_i386_hash_table (info
);
1395 Elf_Internal_Sym
*isym
;
1397 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1399 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1403 (*_bfd_error_handler
)
1404 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1405 "in section `%A' failed"),
1406 abfd
, sec
, from
->name
, to
->name
, name
,
1407 (unsigned long) rel
->r_offset
);
1408 bfd_set_error (bfd_error_bad_value
);
1416 /* Look through the relocs for a section during the first phase, and
1417 calculate needed space in the global offset table, procedure linkage
1418 table, and dynamic reloc sections. */
1421 elf_i386_check_relocs (bfd
*abfd
,
1422 struct bfd_link_info
*info
,
1424 const Elf_Internal_Rela
*relocs
)
1426 struct elf_i386_link_hash_table
*htab
;
1427 Elf_Internal_Shdr
*symtab_hdr
;
1428 struct elf_link_hash_entry
**sym_hashes
;
1429 const Elf_Internal_Rela
*rel
;
1430 const Elf_Internal_Rela
*rel_end
;
1433 if (info
->relocatable
)
1436 BFD_ASSERT (is_i386_elf (abfd
));
1438 htab
= elf_i386_hash_table (info
);
1442 symtab_hdr
= &elf_symtab_hdr (abfd
);
1443 sym_hashes
= elf_sym_hashes (abfd
);
1447 rel_end
= relocs
+ sec
->reloc_count
;
1448 for (rel
= relocs
; rel
< rel_end
; rel
++)
1450 unsigned int r_type
;
1451 unsigned long r_symndx
;
1452 struct elf_link_hash_entry
*h
;
1453 Elf_Internal_Sym
*isym
;
1456 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1457 r_type
= ELF32_R_TYPE (rel
->r_info
);
1459 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1461 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1467 if (r_symndx
< symtab_hdr
->sh_info
)
1469 /* A local symbol. */
1470 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1475 /* Check relocation against local STT_GNU_IFUNC symbol. */
1476 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1478 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1482 /* Fake a STT_GNU_IFUNC symbol. */
1483 h
->type
= STT_GNU_IFUNC
;
1486 h
->forced_local
= 1;
1487 h
->root
.type
= bfd_link_hash_defined
;
1495 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1496 while (h
->root
.type
== bfd_link_hash_indirect
1497 || h
->root
.type
== bfd_link_hash_warning
)
1498 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1503 /* Create the ifunc sections for static executables. If we
1504 never see an indirect function symbol nor we are building
1505 a static executable, those sections will be empty and
1506 won't appear in output. */
1517 if (htab
->elf
.dynobj
== NULL
)
1518 htab
->elf
.dynobj
= abfd
;
1519 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1524 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1525 it here if it is defined in a non-shared object. */
1526 if (h
->type
== STT_GNU_IFUNC
1529 /* It is referenced by a non-shared object. */
1533 /* STT_GNU_IFUNC symbol must go through PLT. */
1534 h
->plt
.refcount
+= 1;
1536 /* STT_GNU_IFUNC needs dynamic sections. */
1537 if (htab
->elf
.dynobj
== NULL
)
1538 htab
->elf
.dynobj
= abfd
;
1543 if (h
->root
.root
.string
)
1544 name
= h
->root
.root
.string
;
1546 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1548 (*_bfd_error_handler
)
1549 (_("%B: relocation %s against STT_GNU_IFUNC "
1550 "symbol `%s' isn't handled by %s"), abfd
,
1551 elf_howto_table
[r_type
].name
,
1552 name
, __FUNCTION__
);
1553 bfd_set_error (bfd_error_bad_value
);
1558 h
->pointer_equality_needed
= 1;
1561 /* We must copy these reloc types into the
1562 output file. Create a reloc section in
1563 dynobj and make room for this reloc. */
1564 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1565 (abfd
, info
, sec
, sreloc
,
1566 &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
);
1581 h
->got
.refcount
+= 1;
1582 if (htab
->elf
.sgot
== NULL
1583 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1593 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1594 symtab_hdr
, sym_hashes
,
1595 &r_type
, GOT_UNKNOWN
,
1596 rel
, rel_end
, h
, r_symndx
))
1602 htab
->tls_ldm_got
.refcount
+= 1;
1606 /* This symbol requires a procedure linkage table entry. We
1607 actually build the entry in adjust_dynamic_symbol,
1608 because this might be a case of linking PIC code which is
1609 never referenced by a dynamic object, in which case we
1610 don't need to generate a procedure linkage table entry
1613 /* If this is a local symbol, we resolve it directly without
1614 creating a procedure linkage table entry. */
1619 h
->plt
.refcount
+= 1;
1622 case R_386_TLS_IE_32
:
1624 case R_386_TLS_GOTIE
:
1625 if (!info
->executable
)
1626 info
->flags
|= DF_STATIC_TLS
;
1631 case R_386_TLS_GOTDESC
:
1632 case R_386_TLS_DESC_CALL
:
1633 /* This symbol requires a global offset table entry. */
1635 int tls_type
, old_tls_type
;
1640 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1641 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1642 case R_386_TLS_GOTDESC
:
1643 case R_386_TLS_DESC_CALL
:
1644 tls_type
= GOT_TLS_GDESC
; break;
1645 case R_386_TLS_IE_32
:
1646 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1647 tls_type
= GOT_TLS_IE_NEG
;
1649 /* If this is a GD->IE transition, we may use either of
1650 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1651 tls_type
= GOT_TLS_IE
;
1654 case R_386_TLS_GOTIE
:
1655 tls_type
= GOT_TLS_IE_POS
; break;
1660 h
->got
.refcount
+= 1;
1661 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1665 bfd_signed_vma
*local_got_refcounts
;
1667 /* This is a global offset table entry for a local symbol. */
1668 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1669 if (local_got_refcounts
== NULL
)
1673 size
= symtab_hdr
->sh_info
;
1674 size
*= (sizeof (bfd_signed_vma
)
1675 + sizeof (bfd_vma
) + sizeof(char));
1676 local_got_refcounts
= (bfd_signed_vma
*)
1677 bfd_zalloc (abfd
, size
);
1678 if (local_got_refcounts
== NULL
)
1680 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1681 elf_i386_local_tlsdesc_gotent (abfd
)
1682 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1683 elf_i386_local_got_tls_type (abfd
)
1684 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1686 local_got_refcounts
[r_symndx
] += 1;
1687 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1690 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1691 tls_type
|= old_tls_type
;
1692 /* If a TLS symbol is accessed using IE at least once,
1693 there is no point to use dynamic model for it. */
1694 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1695 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1696 || (tls_type
& GOT_TLS_IE
) == 0))
1698 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1699 tls_type
= old_tls_type
;
1700 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1701 && GOT_TLS_GD_ANY_P (tls_type
))
1702 tls_type
|= old_tls_type
;
1706 name
= h
->root
.root
.string
;
1708 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1710 (*_bfd_error_handler
)
1711 (_("%B: `%s' accessed both as normal and "
1712 "thread local symbol"),
1718 if (old_tls_type
!= tls_type
)
1721 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1723 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1731 if (htab
->elf
.sgot
== NULL
)
1733 if (htab
->elf
.dynobj
== NULL
)
1734 htab
->elf
.dynobj
= abfd
;
1735 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1738 if (r_type
!= R_386_TLS_IE
)
1742 case R_386_TLS_LE_32
:
1744 if (info
->executable
)
1746 info
->flags
|= DF_STATIC_TLS
;
1751 if (h
!= NULL
&& info
->executable
)
1753 /* If this reloc is in a read-only section, we might
1754 need a copy reloc. We can't check reliably at this
1755 stage whether the section is read-only, as input
1756 sections have not yet been mapped to output sections.
1757 Tentatively set the flag for now, and correct in
1758 adjust_dynamic_symbol. */
1761 /* We may need a .plt entry if the function this reloc
1762 refers to is in a shared lib. */
1763 h
->plt
.refcount
+= 1;
1764 if (r_type
!= R_386_PC32
)
1765 h
->pointer_equality_needed
= 1;
1768 /* If we are creating a shared library, and this is a reloc
1769 against a global symbol, or a non PC relative reloc
1770 against a local symbol, then we need to copy the reloc
1771 into the shared library. However, if we are linking with
1772 -Bsymbolic, we do not need to copy a reloc against a
1773 global symbol which is defined in an object we are
1774 including in the link (i.e., DEF_REGULAR is set). At
1775 this point we have not seen all the input files, so it is
1776 possible that DEF_REGULAR is not set now but will be set
1777 later (it is never cleared). In case of a weak definition,
1778 DEF_REGULAR may be cleared later by a strong definition in
1779 a shared library. We account for that possibility below by
1780 storing information in the relocs_copied field of the hash
1781 table entry. A similar situation occurs when creating
1782 shared libraries and symbol visibility changes render the
1785 If on the other hand, we are creating an executable, we
1786 may need to keep relocations for symbols satisfied by a
1787 dynamic library if we manage to avoid copy relocs for the
1790 && (sec
->flags
& SEC_ALLOC
) != 0
1791 && (r_type
!= R_386_PC32
1793 && (! SYMBOLIC_BIND (info
, h
)
1794 || h
->root
.type
== bfd_link_hash_defweak
1795 || !h
->def_regular
))))
1796 || (ELIMINATE_COPY_RELOCS
1798 && (sec
->flags
& SEC_ALLOC
) != 0
1800 && (h
->root
.type
== bfd_link_hash_defweak
1801 || !h
->def_regular
)))
1803 struct elf_dyn_relocs
*p
;
1804 struct elf_dyn_relocs
**head
;
1806 /* We must copy these reloc types into the output file.
1807 Create a reloc section in dynobj and make room for
1811 if (htab
->elf
.dynobj
== NULL
)
1812 htab
->elf
.dynobj
= abfd
;
1814 sreloc
= _bfd_elf_make_dynamic_reloc_section
1815 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1821 /* If this is a global symbol, we count the number of
1822 relocations we need for this symbol. */
1825 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1829 /* Track dynamic relocs needed for local syms too.
1830 We really need local syms available to do this
1835 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1840 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1844 vpp
= &elf_section_data (s
)->local_dynrel
;
1845 head
= (struct elf_dyn_relocs
**)vpp
;
1849 if (p
== NULL
|| p
->sec
!= sec
)
1851 bfd_size_type amt
= sizeof *p
;
1852 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1864 if (r_type
== R_386_PC32
)
1869 /* This relocation describes the C++ object vtable hierarchy.
1870 Reconstruct it for later use during GC. */
1871 case R_386_GNU_VTINHERIT
:
1872 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1876 /* This relocation describes which C++ vtable entries are actually
1877 used. Record for later use during GC. */
1878 case R_386_GNU_VTENTRY
:
1879 BFD_ASSERT (h
!= NULL
);
1881 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1893 /* Return the section that should be marked against GC for a given
1897 elf_i386_gc_mark_hook (asection
*sec
,
1898 struct bfd_link_info
*info
,
1899 Elf_Internal_Rela
*rel
,
1900 struct elf_link_hash_entry
*h
,
1901 Elf_Internal_Sym
*sym
)
1904 switch (ELF32_R_TYPE (rel
->r_info
))
1906 case R_386_GNU_VTINHERIT
:
1907 case R_386_GNU_VTENTRY
:
1911 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1914 /* Update the got entry reference counts for the section being removed. */
1917 elf_i386_gc_sweep_hook (bfd
*abfd
,
1918 struct bfd_link_info
*info
,
1920 const Elf_Internal_Rela
*relocs
)
1922 struct elf_i386_link_hash_table
*htab
;
1923 Elf_Internal_Shdr
*symtab_hdr
;
1924 struct elf_link_hash_entry
**sym_hashes
;
1925 bfd_signed_vma
*local_got_refcounts
;
1926 const Elf_Internal_Rela
*rel
, *relend
;
1928 if (info
->relocatable
)
1931 htab
= elf_i386_hash_table (info
);
1935 elf_section_data (sec
)->local_dynrel
= NULL
;
1937 symtab_hdr
= &elf_symtab_hdr (abfd
);
1938 sym_hashes
= elf_sym_hashes (abfd
);
1939 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1941 relend
= relocs
+ sec
->reloc_count
;
1942 for (rel
= relocs
; rel
< relend
; rel
++)
1944 unsigned long r_symndx
;
1945 unsigned int r_type
;
1946 struct elf_link_hash_entry
*h
= NULL
;
1948 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1949 if (r_symndx
>= symtab_hdr
->sh_info
)
1951 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1952 while (h
->root
.type
== bfd_link_hash_indirect
1953 || h
->root
.type
== bfd_link_hash_warning
)
1954 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1958 /* A local symbol. */
1959 Elf_Internal_Sym
*isym
;
1961 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1964 /* Check relocation against local STT_GNU_IFUNC symbol. */
1966 && ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1968 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1976 struct elf_i386_link_hash_entry
*eh
;
1977 struct elf_dyn_relocs
**pp
;
1978 struct elf_dyn_relocs
*p
;
1980 eh
= (struct elf_i386_link_hash_entry
*) h
;
1981 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1984 /* Everything must go for SEC. */
1990 r_type
= ELF32_R_TYPE (rel
->r_info
);
1991 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1992 symtab_hdr
, sym_hashes
,
1993 &r_type
, GOT_UNKNOWN
,
1994 rel
, relend
, h
, r_symndx
))
2000 if (htab
->tls_ldm_got
.refcount
> 0)
2001 htab
->tls_ldm_got
.refcount
-= 1;
2005 case R_386_TLS_GOTDESC
:
2006 case R_386_TLS_DESC_CALL
:
2007 case R_386_TLS_IE_32
:
2009 case R_386_TLS_GOTIE
:
2013 if (h
->got
.refcount
> 0)
2014 h
->got
.refcount
-= 1;
2015 if (h
->type
== STT_GNU_IFUNC
)
2017 if (h
->plt
.refcount
> 0)
2018 h
->plt
.refcount
-= 1;
2021 else if (local_got_refcounts
!= NULL
)
2023 if (local_got_refcounts
[r_symndx
] > 0)
2024 local_got_refcounts
[r_symndx
] -= 1;
2031 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2038 if (h
->plt
.refcount
> 0)
2039 h
->plt
.refcount
-= 1;
2044 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2046 if (h
->got
.refcount
> 0)
2047 h
->got
.refcount
-= 1;
2048 if (h
->plt
.refcount
> 0)
2049 h
->plt
.refcount
-= 1;
2061 /* Adjust a symbol defined by a dynamic object and referenced by a
2062 regular object. The current definition is in some section of the
2063 dynamic object, but we're not including those sections. We have to
2064 change the definition to something the rest of the link can
2068 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2069 struct elf_link_hash_entry
*h
)
2071 struct elf_i386_link_hash_table
*htab
;
2074 /* STT_GNU_IFUNC symbol must go through PLT. */
2075 if (h
->type
== STT_GNU_IFUNC
)
2077 if (h
->plt
.refcount
<= 0)
2079 h
->plt
.offset
= (bfd_vma
) -1;
2085 /* If this is a function, put it in the procedure linkage table. We
2086 will fill in the contents of the procedure linkage table later,
2087 when we know the address of the .got section. */
2088 if (h
->type
== STT_FUNC
2091 if (h
->plt
.refcount
<= 0
2092 || SYMBOL_CALLS_LOCAL (info
, h
)
2093 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2094 && h
->root
.type
== bfd_link_hash_undefweak
))
2096 /* This case can occur if we saw a PLT32 reloc in an input
2097 file, but the symbol was never referred to by a dynamic
2098 object, or if all references were garbage collected. In
2099 such a case, we don't actually need to build a procedure
2100 linkage table, and we can just do a PC32 reloc instead. */
2101 h
->plt
.offset
= (bfd_vma
) -1;
2108 /* It's possible that we incorrectly decided a .plt reloc was
2109 needed for an R_386_PC32 reloc to a non-function sym in
2110 check_relocs. We can't decide accurately between function and
2111 non-function syms in check-relocs; Objects loaded later in
2112 the link may change h->type. So fix it now. */
2113 h
->plt
.offset
= (bfd_vma
) -1;
2115 /* If this is a weak symbol, and there is a real definition, the
2116 processor independent code will have arranged for us to see the
2117 real definition first, and we can just use the same value. */
2118 if (h
->u
.weakdef
!= NULL
)
2120 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2121 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2122 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2123 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2124 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2125 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2129 /* This is a reference to a symbol defined by a dynamic object which
2130 is not a function. */
2132 /* If we are creating a shared library, we must presume that the
2133 only references to the symbol are via the global offset table.
2134 For such cases we need not do anything here; the relocations will
2135 be handled correctly by relocate_section. */
2139 /* If there are no references to this symbol that do not use the
2140 GOT, we don't need to generate a copy reloc. */
2141 if (!h
->non_got_ref
)
2144 /* If -z nocopyreloc was given, we won't generate them either. */
2145 if (info
->nocopyreloc
)
2151 htab
= elf_i386_hash_table (info
);
2155 /* If there aren't any dynamic relocs in read-only sections, then
2156 we can keep the dynamic relocs and avoid the copy reloc. This
2157 doesn't work on VxWorks, where we can not have dynamic relocations
2158 (other than copy and jump slot relocations) in an executable. */
2159 if (ELIMINATE_COPY_RELOCS
2160 && !get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2162 struct elf_i386_link_hash_entry
* eh
;
2163 struct elf_dyn_relocs
*p
;
2165 eh
= (struct elf_i386_link_hash_entry
*) h
;
2166 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2168 s
= p
->sec
->output_section
;
2169 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2182 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2183 h
->root
.root
.string
);
2187 /* We must allocate the symbol in our .dynbss section, which will
2188 become part of the .bss section of the executable. There will be
2189 an entry for this symbol in the .dynsym section. The dynamic
2190 object will contain position independent code, so all references
2191 from the dynamic object to this symbol will go through the global
2192 offset table. The dynamic linker will use the .dynsym entry to
2193 determine the address it must put in the global offset table, so
2194 both the dynamic object and the regular object will refer to the
2195 same memory location for the variable. */
2197 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2198 copy the initial value out of the dynamic object and into the
2199 runtime process image. */
2200 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2202 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2208 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2211 /* Allocate space in .plt, .got and associated reloc sections for
2215 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2217 struct bfd_link_info
*info
;
2218 struct elf_i386_link_hash_table
*htab
;
2219 struct elf_i386_link_hash_entry
*eh
;
2220 struct elf_dyn_relocs
*p
;
2221 unsigned plt_entry_size
;
2223 if (h
->root
.type
== bfd_link_hash_indirect
)
2226 eh
= (struct elf_i386_link_hash_entry
*) h
;
2228 info
= (struct bfd_link_info
*) inf
;
2229 htab
= elf_i386_hash_table (info
);
2233 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2235 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2236 here if it is defined and referenced in a non-shared object. */
2237 if (h
->type
== STT_GNU_IFUNC
2239 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2241 else if (htab
->elf
.dynamic_sections_created
2242 && h
->plt
.refcount
> 0)
2244 /* Make sure this symbol is output as a dynamic symbol.
2245 Undefined weak syms won't yet be marked as dynamic. */
2246 if (h
->dynindx
== -1
2247 && !h
->forced_local
)
2249 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2254 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2256 asection
*s
= htab
->elf
.splt
;
2258 /* If this is the first .plt entry, make room for the special
2261 s
->size
+= plt_entry_size
;
2263 h
->plt
.offset
= s
->size
;
2265 /* If this symbol is not defined in a regular file, and we are
2266 not generating a shared library, then set the symbol to this
2267 location in the .plt. This is required to make function
2268 pointers compare as equal between the normal executable and
2269 the shared library. */
2273 h
->root
.u
.def
.section
= s
;
2274 h
->root
.u
.def
.value
= h
->plt
.offset
;
2277 /* Make room for this entry. */
2278 s
->size
+= plt_entry_size
;
2280 /* We also need to make an entry in the .got.plt section, which
2281 will be placed in the .got section by the linker script. */
2282 htab
->elf
.sgotplt
->size
+= 4;
2284 /* We also need to make an entry in the .rel.plt section. */
2285 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2286 htab
->elf
.srelplt
->reloc_count
++;
2288 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
2291 /* VxWorks has a second set of relocations for each PLT entry
2292 in executables. They go in a separate relocation section,
2293 which is processed by the kernel loader. */
2295 /* There are two relocations for the initial PLT entry: an
2296 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2297 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2299 if (h
->plt
.offset
== plt_entry_size
)
2300 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2302 /* There are two extra relocations for each subsequent PLT entry:
2303 an R_386_32 relocation for the GOT entry, and an R_386_32
2304 relocation for the PLT entry. */
2306 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2311 h
->plt
.offset
= (bfd_vma
) -1;
2317 h
->plt
.offset
= (bfd_vma
) -1;
2321 eh
->tlsdesc_got
= (bfd_vma
) -1;
2323 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2324 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2325 if (h
->got
.refcount
> 0
2328 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2329 h
->got
.offset
= (bfd_vma
) -1;
2330 else if (h
->got
.refcount
> 0)
2334 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2336 /* Make sure this symbol is output as a dynamic symbol.
2337 Undefined weak syms won't yet be marked as dynamic. */
2338 if (h
->dynindx
== -1
2339 && !h
->forced_local
)
2341 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2346 if (GOT_TLS_GDESC_P (tls_type
))
2348 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2349 - elf_i386_compute_jump_table_size (htab
);
2350 htab
->elf
.sgotplt
->size
+= 8;
2351 h
->got
.offset
= (bfd_vma
) -2;
2353 if (! GOT_TLS_GDESC_P (tls_type
)
2354 || GOT_TLS_GD_P (tls_type
))
2356 h
->got
.offset
= s
->size
;
2358 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2359 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2362 dyn
= htab
->elf
.dynamic_sections_created
;
2363 /* R_386_TLS_IE_32 needs one dynamic relocation,
2364 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2365 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2366 need two), R_386_TLS_GD needs one if local symbol and two if
2368 if (tls_type
== GOT_TLS_IE_BOTH
)
2369 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2370 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2371 || (tls_type
& GOT_TLS_IE
))
2372 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2373 else if (GOT_TLS_GD_P (tls_type
))
2374 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2375 else if (! GOT_TLS_GDESC_P (tls_type
)
2376 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2377 || h
->root
.type
!= bfd_link_hash_undefweak
)
2379 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2380 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2381 if (GOT_TLS_GDESC_P (tls_type
))
2382 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2385 h
->got
.offset
= (bfd_vma
) -1;
2387 if (eh
->dyn_relocs
== NULL
)
2390 /* In the shared -Bsymbolic case, discard space allocated for
2391 dynamic pc-relative relocs against symbols which turn out to be
2392 defined in regular objects. For the normal shared case, discard
2393 space for pc-relative relocs that have become local due to symbol
2394 visibility changes. */
2398 /* The only reloc that uses pc_count is R_386_PC32, which will
2399 appear on a call or on something like ".long foo - .". We
2400 want calls to protected symbols to resolve directly to the
2401 function rather than going via the plt. If people want
2402 function pointer comparisons to work as expected then they
2403 should avoid writing assembly like ".long foo - .". */
2404 if (SYMBOL_CALLS_LOCAL (info
, h
))
2406 struct elf_dyn_relocs
**pp
;
2408 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2410 p
->count
-= p
->pc_count
;
2419 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2421 struct elf_dyn_relocs
**pp
;
2422 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2424 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2431 /* Also discard relocs on undefined weak syms with non-default
2433 if (eh
->dyn_relocs
!= NULL
2434 && h
->root
.type
== bfd_link_hash_undefweak
)
2436 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2437 eh
->dyn_relocs
= NULL
;
2439 /* Make sure undefined weak symbols are output as a dynamic
2441 else if (h
->dynindx
== -1
2442 && !h
->forced_local
)
2444 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2449 else if (ELIMINATE_COPY_RELOCS
)
2451 /* For the non-shared case, discard space for relocs against
2452 symbols which turn out to need copy relocs or are not
2458 || (htab
->elf
.dynamic_sections_created
2459 && (h
->root
.type
== bfd_link_hash_undefweak
2460 || h
->root
.type
== bfd_link_hash_undefined
))))
2462 /* Make sure this symbol is output as a dynamic symbol.
2463 Undefined weak syms won't yet be marked as dynamic. */
2464 if (h
->dynindx
== -1
2465 && !h
->forced_local
)
2467 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2471 /* If that succeeded, we know we'll be keeping all the
2473 if (h
->dynindx
!= -1)
2477 eh
->dyn_relocs
= NULL
;
2482 /* Finally, allocate space. */
2483 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2487 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2489 BFD_ASSERT (sreloc
!= NULL
);
2490 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2496 /* Allocate space in .plt, .got and associated reloc sections for
2497 local dynamic relocs. */
2500 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2502 struct elf_link_hash_entry
*h
2503 = (struct elf_link_hash_entry
*) *slot
;
2505 if (h
->type
!= STT_GNU_IFUNC
2509 || h
->root
.type
!= bfd_link_hash_defined
)
2512 return elf_i386_allocate_dynrelocs (h
, inf
);
2515 /* Find any dynamic relocs that apply to read-only sections. */
2518 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2520 struct elf_i386_link_hash_entry
*eh
;
2521 struct elf_dyn_relocs
*p
;
2523 /* Skip local IFUNC symbols. */
2524 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2527 eh
= (struct elf_i386_link_hash_entry
*) h
;
2528 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2530 asection
*s
= p
->sec
->output_section
;
2532 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2534 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2536 info
->flags
|= DF_TEXTREL
;
2538 if (info
->warn_shared_textrel
&& info
->shared
)
2539 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2540 p
->sec
->owner
, h
->root
.root
.string
,
2543 /* Not an error, just cut short the traversal. */
2550 /* Set the sizes of the dynamic sections. */
2553 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2555 struct elf_i386_link_hash_table
*htab
;
2561 htab
= elf_i386_hash_table (info
);
2564 dynobj
= htab
->elf
.dynobj
;
2568 if (htab
->elf
.dynamic_sections_created
)
2570 /* Set the contents of the .interp section to the interpreter. */
2571 if (info
->executable
)
2573 s
= bfd_get_section_by_name (dynobj
, ".interp");
2576 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2577 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2581 /* Set up .got offsets for local syms, and space for local dynamic
2583 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2585 bfd_signed_vma
*local_got
;
2586 bfd_signed_vma
*end_local_got
;
2587 char *local_tls_type
;
2588 bfd_vma
*local_tlsdesc_gotent
;
2589 bfd_size_type locsymcount
;
2590 Elf_Internal_Shdr
*symtab_hdr
;
2593 if (! is_i386_elf (ibfd
))
2596 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2598 struct elf_dyn_relocs
*p
;
2600 for (p
= ((struct elf_dyn_relocs
*)
2601 elf_section_data (s
)->local_dynrel
);
2605 if (!bfd_is_abs_section (p
->sec
)
2606 && bfd_is_abs_section (p
->sec
->output_section
))
2608 /* Input section has been discarded, either because
2609 it is a copy of a linkonce section or due to
2610 linker script /DISCARD/, so we'll be discarding
2613 else if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2614 && strcmp (p
->sec
->output_section
->name
,
2617 /* Relocations in vxworks .tls_vars sections are
2618 handled specially by the loader. */
2620 else if (p
->count
!= 0)
2622 srel
= elf_section_data (p
->sec
)->sreloc
;
2623 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2624 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2625 && (info
->flags
& DF_TEXTREL
) == 0)
2627 info
->flags
|= DF_TEXTREL
;
2628 if (info
->warn_shared_textrel
&& info
->shared
)
2629 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2630 p
->sec
->owner
, p
->sec
);
2636 local_got
= elf_local_got_refcounts (ibfd
);
2640 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2641 locsymcount
= symtab_hdr
->sh_info
;
2642 end_local_got
= local_got
+ locsymcount
;
2643 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2644 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2646 srel
= htab
->elf
.srelgot
;
2647 for (; local_got
< end_local_got
;
2648 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2650 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2653 if (GOT_TLS_GDESC_P (*local_tls_type
))
2655 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2656 - elf_i386_compute_jump_table_size (htab
);
2657 htab
->elf
.sgotplt
->size
+= 8;
2658 *local_got
= (bfd_vma
) -2;
2660 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2661 || GOT_TLS_GD_P (*local_tls_type
))
2663 *local_got
= s
->size
;
2665 if (GOT_TLS_GD_P (*local_tls_type
)
2666 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2670 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2671 || (*local_tls_type
& GOT_TLS_IE
))
2673 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2674 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2675 else if (GOT_TLS_GD_P (*local_tls_type
)
2676 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2677 srel
->size
+= sizeof (Elf32_External_Rel
);
2678 if (GOT_TLS_GDESC_P (*local_tls_type
))
2679 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2683 *local_got
= (bfd_vma
) -1;
2687 if (htab
->tls_ldm_got
.refcount
> 0)
2689 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2691 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2692 htab
->elf
.sgot
->size
+= 8;
2693 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2696 htab
->tls_ldm_got
.offset
= -1;
2698 /* Allocate global sym .plt and .got entries, and space for global
2699 sym dynamic relocs. */
2700 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2702 /* Allocate .plt and .got entries, and space for local symbols. */
2703 htab_traverse (htab
->loc_hash_table
,
2704 elf_i386_allocate_local_dynrelocs
,
2707 /* For every jump slot reserved in the sgotplt, reloc_count is
2708 incremented. However, when we reserve space for TLS descriptors,
2709 it's not incremented, so in order to compute the space reserved
2710 for them, it suffices to multiply the reloc count by the jump
2713 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2714 so that R_386_IRELATIVE entries come last. */
2715 if (htab
->elf
.srelplt
)
2717 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
2718 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2719 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2721 else if (htab
->elf
.irelplt
)
2722 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2725 if (htab
->elf
.sgotplt
)
2727 struct elf_link_hash_entry
*got
;
2728 got
= elf_link_hash_lookup (elf_hash_table (info
),
2729 "_GLOBAL_OFFSET_TABLE_",
2730 FALSE
, FALSE
, FALSE
);
2732 /* Don't allocate .got.plt section if there are no GOT nor PLT
2733 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2735 || !got
->ref_regular_nonweak
)
2736 && (htab
->elf
.sgotplt
->size
2737 == get_elf_backend_data (output_bfd
)->got_header_size
)
2738 && (htab
->elf
.splt
== NULL
2739 || htab
->elf
.splt
->size
== 0)
2740 && (htab
->elf
.sgot
== NULL
2741 || htab
->elf
.sgot
->size
== 0)
2742 && (htab
->elf
.iplt
== NULL
2743 || htab
->elf
.iplt
->size
== 0)
2744 && (htab
->elf
.igotplt
== NULL
2745 || htab
->elf
.igotplt
->size
== 0))
2746 htab
->elf
.sgotplt
->size
= 0;
2749 /* We now have determined the sizes of the various dynamic sections.
2750 Allocate memory for them. */
2752 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2754 bfd_boolean strip_section
= TRUE
;
2756 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2759 if (s
== htab
->elf
.splt
2760 || s
== htab
->elf
.sgot
2761 || s
== htab
->elf
.sgotplt
2762 || s
== htab
->elf
.iplt
2763 || s
== htab
->elf
.igotplt
2764 || s
== htab
->sdynbss
)
2766 /* Strip this section if we don't need it; see the
2768 /* We'd like to strip these sections if they aren't needed, but if
2769 we've exported dynamic symbols from them we must leave them.
2770 It's too late to tell BFD to get rid of the symbols. */
2772 if (htab
->elf
.hplt
!= NULL
)
2773 strip_section
= FALSE
;
2775 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2778 && s
!= htab
->elf
.srelplt
2779 && s
!= htab
->srelplt2
)
2782 /* We use the reloc_count field as a counter if we need
2783 to copy relocs into the output file. */
2788 /* It's not one of our sections, so don't allocate space. */
2794 /* If we don't need this section, strip it from the
2795 output file. This is mostly to handle .rel.bss and
2796 .rel.plt. We must create both sections in
2797 create_dynamic_sections, because they must be created
2798 before the linker maps input sections to output
2799 sections. The linker does that before
2800 adjust_dynamic_symbol is called, and it is that
2801 function which decides whether anything needs to go
2802 into these sections. */
2804 s
->flags
|= SEC_EXCLUDE
;
2808 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2811 /* Allocate memory for the section contents. We use bfd_zalloc
2812 here in case unused entries are not reclaimed before the
2813 section's contents are written out. This should not happen,
2814 but this way if it does, we get a R_386_NONE reloc instead
2816 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2817 if (s
->contents
== NULL
)
2821 if (htab
->plt_eh_frame
!= NULL
2822 && htab
->elf
.splt
!= NULL
2823 && htab
->elf
.splt
->size
!= 0
2824 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0)
2825 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2826 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2828 if (htab
->elf
.dynamic_sections_created
)
2830 /* Add some entries to the .dynamic section. We fill in the
2831 values later, in elf_i386_finish_dynamic_sections, but we
2832 must add the entries now so that we get the correct size for
2833 the .dynamic section. The DT_DEBUG entry is filled in by the
2834 dynamic linker and used by the debugger. */
2835 #define add_dynamic_entry(TAG, VAL) \
2836 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2838 if (info
->executable
)
2840 if (!add_dynamic_entry (DT_DEBUG
, 0))
2844 if (htab
->elf
.splt
->size
!= 0)
2846 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2847 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2848 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2849 || !add_dynamic_entry (DT_JMPREL
, 0))
2855 if (!add_dynamic_entry (DT_REL
, 0)
2856 || !add_dynamic_entry (DT_RELSZ
, 0)
2857 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2860 /* If any dynamic relocs apply to a read-only section,
2861 then we need a DT_TEXTREL entry. */
2862 if ((info
->flags
& DF_TEXTREL
) == 0)
2863 elf_link_hash_traverse (&htab
->elf
,
2864 elf_i386_readonly_dynrelocs
, info
);
2866 if ((info
->flags
& DF_TEXTREL
) != 0)
2868 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2872 if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2873 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2876 #undef add_dynamic_entry
2882 elf_i386_always_size_sections (bfd
*output_bfd
,
2883 struct bfd_link_info
*info
)
2885 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2889 struct elf_link_hash_entry
*tlsbase
;
2891 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2892 "_TLS_MODULE_BASE_",
2893 FALSE
, FALSE
, FALSE
);
2895 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2897 struct elf_i386_link_hash_table
*htab
;
2898 struct bfd_link_hash_entry
*bh
= NULL
;
2899 const struct elf_backend_data
*bed
2900 = get_elf_backend_data (output_bfd
);
2902 htab
= elf_i386_hash_table (info
);
2906 if (!(_bfd_generic_link_add_one_symbol
2907 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2908 tls_sec
, 0, NULL
, FALSE
,
2909 bed
->collect
, &bh
)))
2912 htab
->tls_module_base
= bh
;
2914 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2915 tlsbase
->def_regular
= 1;
2916 tlsbase
->other
= STV_HIDDEN
;
2917 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2924 /* Set the correct type for an x86 ELF section. We do this by the
2925 section name, which is a hack, but ought to work. */
2928 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2929 Elf_Internal_Shdr
*hdr
,
2934 name
= bfd_get_section_name (abfd
, sec
);
2936 /* This is an ugly, but unfortunately necessary hack that is
2937 needed when producing EFI binaries on x86. It tells
2938 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2939 containing ELF relocation info. We need this hack in order to
2940 be able to generate ELF binaries that can be translated into
2941 EFI applications (which are essentially COFF objects). Those
2942 files contain a COFF ".reloc" section inside an ELFNN object,
2943 which would normally cause BFD to segfault because it would
2944 attempt to interpret this section as containing relocation
2945 entries for section "oc". With this hack enabled, ".reloc"
2946 will be treated as a normal data section, which will avoid the
2947 segfault. However, you won't be able to create an ELFNN binary
2948 with a section named "oc" that needs relocations, but that's
2949 the kind of ugly side-effects you get when detecting section
2950 types based on their names... In practice, this limitation is
2951 unlikely to bite. */
2952 if (strcmp (name
, ".reloc") == 0)
2953 hdr
->sh_type
= SHT_PROGBITS
;
2958 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2959 executables. Rather than setting it to the beginning of the TLS
2960 section, we have to set it to the end. This function may be called
2961 multiple times, it is idempotent. */
2964 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2966 struct elf_i386_link_hash_table
*htab
;
2967 struct bfd_link_hash_entry
*base
;
2969 if (!info
->executable
)
2972 htab
= elf_i386_hash_table (info
);
2976 base
= htab
->tls_module_base
;
2980 base
->u
.def
.value
= htab
->elf
.tls_size
;
2983 /* Return the base VMA address which should be subtracted from real addresses
2984 when resolving @dtpoff relocation.
2985 This is PT_TLS segment p_vaddr. */
2988 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2990 /* If tls_sec is NULL, we should have signalled an error already. */
2991 if (elf_hash_table (info
)->tls_sec
== NULL
)
2993 return elf_hash_table (info
)->tls_sec
->vma
;
2996 /* Return the relocation value for @tpoff relocation
2997 if STT_TLS virtual address is ADDRESS. */
3000 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3002 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3003 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3004 bfd_vma static_tls_size
;
3006 /* If tls_sec is NULL, we should have signalled an error already. */
3007 if (htab
->tls_sec
== NULL
)
3010 /* Consider special static TLS alignment requirements. */
3011 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3012 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3015 /* Relocate an i386 ELF section. */
3018 elf_i386_relocate_section (bfd
*output_bfd
,
3019 struct bfd_link_info
*info
,
3021 asection
*input_section
,
3023 Elf_Internal_Rela
*relocs
,
3024 Elf_Internal_Sym
*local_syms
,
3025 asection
**local_sections
)
3027 struct elf_i386_link_hash_table
*htab
;
3028 Elf_Internal_Shdr
*symtab_hdr
;
3029 struct elf_link_hash_entry
**sym_hashes
;
3030 bfd_vma
*local_got_offsets
;
3031 bfd_vma
*local_tlsdesc_gotents
;
3032 Elf_Internal_Rela
*rel
;
3033 Elf_Internal_Rela
*relend
;
3034 bfd_boolean is_vxworks_tls
;
3035 unsigned plt_entry_size
;
3037 BFD_ASSERT (is_i386_elf (input_bfd
));
3039 htab
= elf_i386_hash_table (info
);
3042 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3043 sym_hashes
= elf_sym_hashes (input_bfd
);
3044 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3045 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3046 /* We have to handle relocations in vxworks .tls_vars sections
3047 specially, because the dynamic loader is 'weird'. */
3048 is_vxworks_tls
= (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3050 && !strcmp (input_section
->output_section
->name
,
3053 elf_i386_set_tls_module_base (info
);
3055 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
3058 relend
= relocs
+ input_section
->reloc_count
;
3059 for (; rel
< relend
; rel
++)
3061 unsigned int r_type
;
3062 reloc_howto_type
*howto
;
3063 unsigned long r_symndx
;
3064 struct elf_link_hash_entry
*h
;
3065 Elf_Internal_Sym
*sym
;
3067 bfd_vma off
, offplt
;
3069 bfd_boolean unresolved_reloc
;
3070 bfd_reloc_status_type r
;
3074 r_type
= ELF32_R_TYPE (rel
->r_info
);
3075 if (r_type
== R_386_GNU_VTINHERIT
3076 || r_type
== R_386_GNU_VTENTRY
)
3079 if ((indx
= r_type
) >= R_386_standard
3080 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3081 >= R_386_ext
- R_386_standard
)
3082 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3083 >= R_386_irelative
- R_386_ext
))
3085 (*_bfd_error_handler
)
3086 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3087 input_bfd
, input_section
, r_type
);
3088 bfd_set_error (bfd_error_bad_value
);
3091 howto
= elf_howto_table
+ indx
;
3093 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3097 unresolved_reloc
= FALSE
;
3098 if (r_symndx
< symtab_hdr
->sh_info
)
3100 sym
= local_syms
+ r_symndx
;
3101 sec
= local_sections
[r_symndx
];
3102 relocation
= (sec
->output_section
->vma
3103 + sec
->output_offset
3106 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3107 && ((sec
->flags
& SEC_MERGE
) != 0
3108 || (info
->relocatable
3109 && sec
->output_offset
!= 0)))
3112 bfd_byte
*where
= contents
+ rel
->r_offset
;
3114 switch (howto
->size
)
3117 addend
= bfd_get_8 (input_bfd
, where
);
3118 if (howto
->pc_relative
)
3120 addend
= (addend
^ 0x80) - 0x80;
3125 addend
= bfd_get_16 (input_bfd
, where
);
3126 if (howto
->pc_relative
)
3128 addend
= (addend
^ 0x8000) - 0x8000;
3133 addend
= bfd_get_32 (input_bfd
, where
);
3134 if (howto
->pc_relative
)
3136 addend
= (addend
^ 0x80000000) - 0x80000000;
3144 if (info
->relocatable
)
3145 addend
+= sec
->output_offset
;
3148 asection
*msec
= sec
;
3149 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3151 addend
-= relocation
;
3152 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3155 switch (howto
->size
)
3158 /* FIXME: overflow checks. */
3159 if (howto
->pc_relative
)
3161 bfd_put_8 (input_bfd
, addend
, where
);
3164 if (howto
->pc_relative
)
3166 bfd_put_16 (input_bfd
, addend
, where
);
3169 if (howto
->pc_relative
)
3171 bfd_put_32 (input_bfd
, addend
, where
);
3175 else if (!info
->relocatable
3176 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3178 /* Relocate against local STT_GNU_IFUNC symbol. */
3179 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3184 /* Set STT_GNU_IFUNC symbol value. */
3185 h
->root
.u
.def
.value
= sym
->st_value
;
3186 h
->root
.u
.def
.section
= sec
;
3191 bfd_boolean warned ATTRIBUTE_UNUSED
;
3193 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3194 r_symndx
, symtab_hdr
, sym_hashes
,
3196 unresolved_reloc
, warned
);
3199 if (sec
!= NULL
&& elf_discarded_section (sec
))
3200 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3201 rel
, relend
, howto
, contents
);
3203 if (info
->relocatable
)
3206 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3207 it here if it is defined in a non-shared object. */
3209 && h
->type
== STT_GNU_IFUNC
3212 asection
*plt
, *gotplt
, *base_got
;
3216 if ((input_section
->flags
& SEC_ALLOC
) == 0
3217 || h
->plt
.offset
== (bfd_vma
) -1)
3220 /* STT_GNU_IFUNC symbol must go through PLT. */
3221 if (htab
->elf
.splt
!= NULL
)
3223 plt
= htab
->elf
.splt
;
3224 gotplt
= htab
->elf
.sgotplt
;
3228 plt
= htab
->elf
.iplt
;
3229 gotplt
= htab
->elf
.igotplt
;
3232 relocation
= (plt
->output_section
->vma
3233 + plt
->output_offset
+ h
->plt
.offset
);
3238 if (h
->root
.root
.string
)
3239 name
= h
->root
.root
.string
;
3241 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3243 (*_bfd_error_handler
)
3244 (_("%B: relocation %s against STT_GNU_IFUNC "
3245 "symbol `%s' isn't handled by %s"), input_bfd
,
3246 elf_howto_table
[r_type
].name
,
3247 name
, __FUNCTION__
);
3248 bfd_set_error (bfd_error_bad_value
);
3252 /* Generate dynamic relcoation only when there is a
3253 non-GOF reference in a shared object. */
3254 if (info
->shared
&& h
->non_got_ref
)
3256 Elf_Internal_Rela outrel
;
3261 /* Need a dynamic relocation to get the real function
3263 offset
= _bfd_elf_section_offset (output_bfd
,
3267 if (offset
== (bfd_vma
) -1
3268 || offset
== (bfd_vma
) -2)
3271 outrel
.r_offset
= (input_section
->output_section
->vma
3272 + input_section
->output_offset
3275 if (h
->dynindx
== -1
3277 || info
->executable
)
3279 /* This symbol is resolved locally. */
3280 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3281 bfd_put_32 (output_bfd
,
3282 (h
->root
.u
.def
.value
3283 + h
->root
.u
.def
.section
->output_section
->vma
3284 + h
->root
.u
.def
.section
->output_offset
),
3288 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3290 sreloc
= htab
->elf
.irelifunc
;
3291 loc
= sreloc
->contents
;
3292 loc
+= (sreloc
->reloc_count
++
3293 * sizeof (Elf32_External_Rel
));
3294 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3296 /* If this reloc is against an external symbol, we
3297 do not want to fiddle with the addend. Otherwise,
3298 we need to include the symbol value so that it
3299 becomes an addend for the dynamic reloc. For an
3300 internal symbol, we have updated addend. */
3309 base_got
= htab
->elf
.sgot
;
3310 off
= h
->got
.offset
;
3312 if (base_got
== NULL
)
3315 if (off
== (bfd_vma
) -1)
3317 /* We can't use h->got.offset here to save state, or
3318 even just remember the offset, as finish_dynamic_symbol
3319 would use that as offset into .got. */
3321 if (htab
->elf
.splt
!= NULL
)
3323 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3324 off
= (plt_index
+ 3) * 4;
3325 base_got
= htab
->elf
.sgotplt
;
3329 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3330 off
= plt_index
* 4;
3331 base_got
= htab
->elf
.igotplt
;
3334 if (h
->dynindx
== -1
3338 /* This references the local defitionion. We must
3339 initialize this entry in the global offset table.
3340 Since the offset must always be a multiple of 8,
3341 we use the least significant bit to record
3342 whether we have initialized it already.
3344 When doing a dynamic link, we create a .rela.got
3345 relocation entry to initialize the value. This
3346 is done in the finish_dynamic_symbol routine. */
3351 bfd_put_32 (output_bfd
, relocation
,
3352 base_got
->contents
+ off
);
3359 /* Adjust for static executables. */
3360 if (htab
->elf
.splt
== NULL
)
3361 relocation
+= gotplt
->output_offset
;
3365 relocation
= (base_got
->output_section
->vma
3366 + base_got
->output_offset
+ off
3367 - gotplt
->output_section
->vma
3368 - gotplt
->output_offset
);
3369 /* Adjust for static executables. */
3370 if (htab
->elf
.splt
== NULL
)
3371 relocation
+= gotplt
->output_offset
;
3377 relocation
-= (gotplt
->output_section
->vma
3378 + gotplt
->output_offset
);
3386 /* Relocation is to the entry for this symbol in the global
3388 if (htab
->elf
.sgot
== NULL
)
3395 off
= h
->got
.offset
;
3396 dyn
= htab
->elf
.dynamic_sections_created
;
3397 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3399 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3400 || (ELF_ST_VISIBILITY (h
->other
)
3401 && h
->root
.type
== bfd_link_hash_undefweak
))
3403 /* This is actually a static link, or it is a
3404 -Bsymbolic link and the symbol is defined
3405 locally, or the symbol was forced to be local
3406 because of a version file. We must initialize
3407 this entry in the global offset table. Since the
3408 offset must always be a multiple of 4, we use the
3409 least significant bit to record whether we have
3410 initialized it already.
3412 When doing a dynamic link, we create a .rel.got
3413 relocation entry to initialize the value. This
3414 is done in the finish_dynamic_symbol routine. */
3419 bfd_put_32 (output_bfd
, relocation
,
3420 htab
->elf
.sgot
->contents
+ off
);
3425 unresolved_reloc
= FALSE
;
3429 if (local_got_offsets
== NULL
)
3432 off
= local_got_offsets
[r_symndx
];
3434 /* The offset must always be a multiple of 4. We use
3435 the least significant bit to record whether we have
3436 already generated the necessary reloc. */
3441 bfd_put_32 (output_bfd
, relocation
,
3442 htab
->elf
.sgot
->contents
+ off
);
3447 Elf_Internal_Rela outrel
;
3450 s
= htab
->elf
.srelgot
;
3454 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3455 + htab
->elf
.sgot
->output_offset
3457 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3459 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3460 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3463 local_got_offsets
[r_symndx
] |= 1;
3467 if (off
>= (bfd_vma
) -2)
3470 relocation
= htab
->elf
.sgot
->output_section
->vma
3471 + htab
->elf
.sgot
->output_offset
+ off
3472 - htab
->elf
.sgotplt
->output_section
->vma
3473 - htab
->elf
.sgotplt
->output_offset
;
3477 /* Relocation is relative to the start of the global offset
3480 /* Check to make sure it isn't a protected function symbol
3481 for shared library since it may not be local when used
3482 as function address. We also need to make sure that a
3483 symbol is defined locally. */
3484 if (info
->shared
&& h
)
3486 if (!h
->def_regular
)
3490 switch (ELF_ST_VISIBILITY (h
->other
))
3493 v
= _("hidden symbol");
3496 v
= _("internal symbol");
3499 v
= _("protected symbol");
3506 (*_bfd_error_handler
)
3507 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3508 input_bfd
, v
, h
->root
.root
.string
);
3509 bfd_set_error (bfd_error_bad_value
);
3512 else if (!info
->executable
3513 && h
->type
== STT_FUNC
3514 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3516 (*_bfd_error_handler
)
3517 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3518 input_bfd
, h
->root
.root
.string
);
3519 bfd_set_error (bfd_error_bad_value
);
3524 /* Note that sgot is not involved in this
3525 calculation. We always want the start of .got.plt. If we
3526 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3527 permitted by the ABI, we might have to change this
3529 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3530 + htab
->elf
.sgotplt
->output_offset
;
3534 /* Use global offset table as symbol value. */
3535 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3536 + htab
->elf
.sgotplt
->output_offset
;
3537 unresolved_reloc
= FALSE
;
3541 /* Relocation is to the entry for this symbol in the
3542 procedure linkage table. */
3544 /* Resolve a PLT32 reloc against a local symbol directly,
3545 without using the procedure linkage table. */
3549 if (h
->plt
.offset
== (bfd_vma
) -1
3550 || htab
->elf
.splt
== NULL
)
3552 /* We didn't make a PLT entry for this symbol. This
3553 happens when statically linking PIC code, or when
3554 using -Bsymbolic. */
3558 relocation
= (htab
->elf
.splt
->output_section
->vma
3559 + htab
->elf
.splt
->output_offset
3561 unresolved_reloc
= FALSE
;
3566 if ((input_section
->flags
& SEC_ALLOC
) == 0
3572 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3573 || h
->root
.type
!= bfd_link_hash_undefweak
)
3574 && (r_type
!= R_386_PC32
3575 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3576 || (ELIMINATE_COPY_RELOCS
3583 || h
->root
.type
== bfd_link_hash_undefweak
3584 || h
->root
.type
== bfd_link_hash_undefined
)))
3586 Elf_Internal_Rela outrel
;
3588 bfd_boolean skip
, relocate
;
3591 /* When generating a shared object, these relocations
3592 are copied into the output file to be resolved at run
3599 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3601 if (outrel
.r_offset
== (bfd_vma
) -1)
3603 else if (outrel
.r_offset
== (bfd_vma
) -2)
3604 skip
= TRUE
, relocate
= TRUE
;
3605 outrel
.r_offset
+= (input_section
->output_section
->vma
3606 + input_section
->output_offset
);
3609 memset (&outrel
, 0, sizeof outrel
);
3612 && (r_type
== R_386_PC32
3614 || !SYMBOLIC_BIND (info
, h
)
3615 || !h
->def_regular
))
3616 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3619 /* This symbol is local, or marked to become local. */
3621 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3624 sreloc
= elf_section_data (input_section
)->sreloc
;
3626 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3628 r
= bfd_reloc_notsupported
;
3629 goto check_relocation_error
;
3632 loc
= sreloc
->contents
;
3633 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3635 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3637 /* If this reloc is against an external symbol, we do
3638 not want to fiddle with the addend. Otherwise, we
3639 need to include the symbol value so that it becomes
3640 an addend for the dynamic reloc. */
3647 if (!info
->executable
)
3649 Elf_Internal_Rela outrel
;
3653 outrel
.r_offset
= rel
->r_offset
3654 + input_section
->output_section
->vma
3655 + input_section
->output_offset
;
3656 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3657 sreloc
= elf_section_data (input_section
)->sreloc
;
3660 loc
= sreloc
->contents
;
3661 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3662 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3667 case R_386_TLS_GOTDESC
:
3668 case R_386_TLS_DESC_CALL
:
3669 case R_386_TLS_IE_32
:
3670 case R_386_TLS_GOTIE
:
3671 tls_type
= GOT_UNKNOWN
;
3672 if (h
== NULL
&& local_got_offsets
)
3673 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3675 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3676 if (tls_type
== GOT_TLS_IE
)
3677 tls_type
= GOT_TLS_IE_NEG
;
3679 if (! elf_i386_tls_transition (info
, input_bfd
,
3680 input_section
, contents
,
3681 symtab_hdr
, sym_hashes
,
3682 &r_type
, tls_type
, rel
,
3683 relend
, h
, r_symndx
))
3686 if (r_type
== R_386_TLS_LE_32
)
3688 BFD_ASSERT (! unresolved_reloc
);
3689 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3694 /* GD->LE transition. */
3695 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3698 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3700 movl %gs:0, %eax; subl $foo@tpoff, %eax
3701 (6 byte form of subl). */
3702 memcpy (contents
+ rel
->r_offset
- 3,
3703 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3704 roff
= rel
->r_offset
+ 5;
3708 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3710 movl %gs:0, %eax; subl $foo@tpoff, %eax
3711 (6 byte form of subl). */
3712 memcpy (contents
+ rel
->r_offset
- 2,
3713 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3714 roff
= rel
->r_offset
+ 6;
3716 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3718 /* Skip R_386_PC32/R_386_PLT32. */
3722 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3724 /* GDesc -> LE transition.
3725 It's originally something like:
3726 leal x@tlsdesc(%ebx), %eax
3730 Registers other than %eax may be set up here. */
3735 roff
= rel
->r_offset
;
3736 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3738 /* Now modify the instruction as appropriate. */
3739 /* aoliva FIXME: remove the above and xor the byte
3741 bfd_put_8 (output_bfd
, val
^ 0x86,
3742 contents
+ roff
- 1);
3743 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3747 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3749 /* GDesc -> LE transition.
3757 roff
= rel
->r_offset
;
3758 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3759 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3762 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3766 /* IE->LE transition:
3767 Originally it can be one of:
3775 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3778 /* movl foo, %eax. */
3779 bfd_put_8 (output_bfd
, 0xb8,
3780 contents
+ rel
->r_offset
- 1);
3786 type
= bfd_get_8 (input_bfd
,
3787 contents
+ rel
->r_offset
- 2);
3792 bfd_put_8 (output_bfd
, 0xc7,
3793 contents
+ rel
->r_offset
- 2);
3794 bfd_put_8 (output_bfd
,
3795 0xc0 | ((val
>> 3) & 7),
3796 contents
+ rel
->r_offset
- 1);
3800 bfd_put_8 (output_bfd
, 0x81,
3801 contents
+ rel
->r_offset
- 2);
3802 bfd_put_8 (output_bfd
,
3803 0xc0 | ((val
>> 3) & 7),
3804 contents
+ rel
->r_offset
- 1);
3811 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3812 contents
+ rel
->r_offset
);
3817 unsigned int val
, type
;
3819 /* {IE_32,GOTIE}->LE transition:
3820 Originally it can be one of:
3821 subl foo(%reg1), %reg2
3822 movl foo(%reg1), %reg2
3823 addl foo(%reg1), %reg2
3826 movl $foo, %reg2 (6 byte form)
3827 addl $foo, %reg2. */
3828 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3829 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3833 bfd_put_8 (output_bfd
, 0xc7,
3834 contents
+ rel
->r_offset
- 2);
3835 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3836 contents
+ rel
->r_offset
- 1);
3838 else if (type
== 0x2b)
3841 bfd_put_8 (output_bfd
, 0x81,
3842 contents
+ rel
->r_offset
- 2);
3843 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3844 contents
+ rel
->r_offset
- 1);
3846 else if (type
== 0x03)
3849 bfd_put_8 (output_bfd
, 0x81,
3850 contents
+ rel
->r_offset
- 2);
3851 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3852 contents
+ rel
->r_offset
- 1);
3856 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3857 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3858 contents
+ rel
->r_offset
);
3860 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3861 contents
+ rel
->r_offset
);
3866 if (htab
->elf
.sgot
== NULL
)
3871 off
= h
->got
.offset
;
3872 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3876 if (local_got_offsets
== NULL
)
3879 off
= local_got_offsets
[r_symndx
];
3880 offplt
= local_tlsdesc_gotents
[r_symndx
];
3887 Elf_Internal_Rela outrel
;
3892 if (htab
->elf
.srelgot
== NULL
)
3895 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3897 if (GOT_TLS_GDESC_P (tls_type
))
3899 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3900 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3901 <= htab
->elf
.sgotplt
->size
);
3902 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3903 + htab
->elf
.sgotplt
->output_offset
3905 + htab
->sgotplt_jump_table_size
);
3906 sreloc
= htab
->elf
.srelplt
;
3907 loc
= sreloc
->contents
;
3908 loc
+= (htab
->next_tls_desc_index
++
3909 * sizeof (Elf32_External_Rel
));
3910 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3911 <= sreloc
->contents
+ sreloc
->size
);
3912 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3915 BFD_ASSERT (! unresolved_reloc
);
3916 bfd_put_32 (output_bfd
,
3917 relocation
- elf_i386_dtpoff_base (info
),
3918 htab
->elf
.sgotplt
->contents
+ offplt
3919 + htab
->sgotplt_jump_table_size
+ 4);
3923 bfd_put_32 (output_bfd
, 0,
3924 htab
->elf
.sgotplt
->contents
+ offplt
3925 + htab
->sgotplt_jump_table_size
+ 4);
3929 sreloc
= htab
->elf
.srelgot
;
3931 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3932 + htab
->elf
.sgot
->output_offset
+ off
);
3934 if (GOT_TLS_GD_P (tls_type
))
3935 dr_type
= R_386_TLS_DTPMOD32
;
3936 else if (GOT_TLS_GDESC_P (tls_type
))
3938 else if (tls_type
== GOT_TLS_IE_POS
)
3939 dr_type
= R_386_TLS_TPOFF
;
3941 dr_type
= R_386_TLS_TPOFF32
;
3943 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3944 bfd_put_32 (output_bfd
,
3945 relocation
- elf_i386_dtpoff_base (info
),
3946 htab
->elf
.sgot
->contents
+ off
);
3947 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3948 bfd_put_32 (output_bfd
,
3949 elf_i386_dtpoff_base (info
) - relocation
,
3950 htab
->elf
.sgot
->contents
+ off
);
3951 else if (dr_type
!= R_386_TLS_DESC
)
3952 bfd_put_32 (output_bfd
, 0,
3953 htab
->elf
.sgot
->contents
+ off
);
3954 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3956 loc
= sreloc
->contents
;
3957 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3958 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3959 <= sreloc
->contents
+ sreloc
->size
);
3960 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3962 if (GOT_TLS_GD_P (tls_type
))
3966 BFD_ASSERT (! unresolved_reloc
);
3967 bfd_put_32 (output_bfd
,
3968 relocation
- elf_i386_dtpoff_base (info
),
3969 htab
->elf
.sgot
->contents
+ off
+ 4);
3973 bfd_put_32 (output_bfd
, 0,
3974 htab
->elf
.sgot
->contents
+ off
+ 4);
3975 outrel
.r_info
= ELF32_R_INFO (indx
,
3976 R_386_TLS_DTPOFF32
);
3977 outrel
.r_offset
+= 4;
3978 sreloc
->reloc_count
++;
3979 loc
+= sizeof (Elf32_External_Rel
);
3980 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3981 <= sreloc
->contents
+ sreloc
->size
);
3982 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3985 else if (tls_type
== GOT_TLS_IE_BOTH
)
3987 bfd_put_32 (output_bfd
,
3989 ? relocation
- elf_i386_dtpoff_base (info
)
3991 htab
->elf
.sgot
->contents
+ off
+ 4);
3992 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3993 outrel
.r_offset
+= 4;
3994 sreloc
->reloc_count
++;
3995 loc
+= sizeof (Elf32_External_Rel
);
3996 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4003 local_got_offsets
[r_symndx
] |= 1;
4006 if (off
>= (bfd_vma
) -2
4007 && ! GOT_TLS_GDESC_P (tls_type
))
4009 if (r_type
== R_386_TLS_GOTDESC
4010 || r_type
== R_386_TLS_DESC_CALL
)
4012 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4013 unresolved_reloc
= FALSE
;
4015 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4017 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4018 + htab
->elf
.sgotplt
->output_offset
;
4019 relocation
= htab
->elf
.sgot
->output_section
->vma
4020 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4021 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4022 && tls_type
== GOT_TLS_IE_BOTH
)
4024 if (r_type
== R_386_TLS_IE
)
4025 relocation
+= g_o_t
;
4026 unresolved_reloc
= FALSE
;
4028 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4030 unsigned int val
, type
;
4033 /* GD->IE transition. */
4034 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4035 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4038 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
4040 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4042 roff
= rel
->r_offset
- 3;
4046 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
4048 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4049 roff
= rel
->r_offset
- 2;
4051 memcpy (contents
+ roff
,
4052 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4053 contents
[roff
+ 7] = 0x80 | (val
& 7);
4054 /* If foo is used only with foo@gotntpoff(%reg) and
4055 foo@indntpoff, but not with foo@gottpoff(%reg), change
4056 subl $foo@gottpoff(%reg), %eax
4058 addl $foo@gotntpoff(%reg), %eax. */
4059 if (tls_type
== GOT_TLS_IE_POS
)
4060 contents
[roff
+ 6] = 0x03;
4061 bfd_put_32 (output_bfd
,
4062 htab
->elf
.sgot
->output_section
->vma
4063 + htab
->elf
.sgot
->output_offset
+ off
4064 - htab
->elf
.sgotplt
->output_section
->vma
4065 - htab
->elf
.sgotplt
->output_offset
,
4066 contents
+ roff
+ 8);
4067 /* Skip R_386_PLT32. */
4071 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4073 /* GDesc -> IE transition.
4074 It's originally something like:
4075 leal x@tlsdesc(%ebx), %eax
4078 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4080 movl x@gottpoff(%ebx), %eax # before negl %eax
4082 Registers other than %eax may be set up here. */
4086 /* First, make sure it's a leal adding ebx to a 32-bit
4087 offset into any register, although it's probably
4088 almost always going to be eax. */
4089 roff
= rel
->r_offset
;
4091 /* Now modify the instruction as appropriate. */
4092 /* To turn a leal into a movl in the form we use it, it
4093 suffices to change the first byte from 0x8d to 0x8b.
4094 aoliva FIXME: should we decide to keep the leal, all
4095 we have to do is remove the statement below, and
4096 adjust the relaxation of R_386_TLS_DESC_CALL. */
4097 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4099 if (tls_type
== GOT_TLS_IE_BOTH
)
4102 bfd_put_32 (output_bfd
,
4103 htab
->elf
.sgot
->output_section
->vma
4104 + htab
->elf
.sgot
->output_offset
+ off
4105 - htab
->elf
.sgotplt
->output_section
->vma
4106 - htab
->elf
.sgotplt
->output_offset
,
4110 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4112 /* GDesc -> IE transition.
4120 depending on how we transformed the TLS_GOTDESC above.
4125 roff
= rel
->r_offset
;
4127 /* Now modify the instruction as appropriate. */
4128 if (tls_type
!= GOT_TLS_IE_NEG
)
4131 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4132 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4137 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4138 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4148 if (! elf_i386_tls_transition (info
, input_bfd
,
4149 input_section
, contents
,
4150 symtab_hdr
, sym_hashes
,
4151 &r_type
, GOT_UNKNOWN
, rel
,
4152 relend
, h
, r_symndx
))
4155 if (r_type
!= R_386_TLS_LDM
)
4157 /* LD->LE transition:
4158 leal foo(%reg), %eax; call ___tls_get_addr.
4160 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
4161 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4162 memcpy (contents
+ rel
->r_offset
- 2,
4163 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4164 /* Skip R_386_PC32/R_386_PLT32. */
4169 if (htab
->elf
.sgot
== NULL
)
4172 off
= htab
->tls_ldm_got
.offset
;
4177 Elf_Internal_Rela outrel
;
4180 if (htab
->elf
.srelgot
== NULL
)
4183 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4184 + htab
->elf
.sgot
->output_offset
+ off
);
4186 bfd_put_32 (output_bfd
, 0,
4187 htab
->elf
.sgot
->contents
+ off
);
4188 bfd_put_32 (output_bfd
, 0,
4189 htab
->elf
.sgot
->contents
+ off
+ 4);
4190 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4191 loc
= htab
->elf
.srelgot
->contents
;
4192 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4193 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4194 htab
->tls_ldm_got
.offset
|= 1;
4196 relocation
= htab
->elf
.sgot
->output_section
->vma
4197 + htab
->elf
.sgot
->output_offset
+ off
4198 - htab
->elf
.sgotplt
->output_section
->vma
4199 - htab
->elf
.sgotplt
->output_offset
;
4200 unresolved_reloc
= FALSE
;
4203 case R_386_TLS_LDO_32
:
4204 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4205 relocation
-= elf_i386_dtpoff_base (info
);
4207 /* When converting LDO to LE, we must negate. */
4208 relocation
= -elf_i386_tpoff (info
, relocation
);
4211 case R_386_TLS_LE_32
:
4213 if (!info
->executable
)
4215 Elf_Internal_Rela outrel
;
4219 outrel
.r_offset
= rel
->r_offset
4220 + input_section
->output_section
->vma
4221 + input_section
->output_offset
;
4222 if (h
!= NULL
&& h
->dynindx
!= -1)
4226 if (r_type
== R_386_TLS_LE_32
)
4227 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4229 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4230 sreloc
= elf_section_data (input_section
)->sreloc
;
4233 loc
= sreloc
->contents
;
4234 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4235 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4238 else if (r_type
== R_386_TLS_LE_32
)
4239 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4241 relocation
-= elf_i386_dtpoff_base (info
);
4243 else if (r_type
== R_386_TLS_LE_32
)
4244 relocation
= elf_i386_tpoff (info
, relocation
);
4246 relocation
= -elf_i386_tpoff (info
, relocation
);
4253 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4254 because such sections are not SEC_ALLOC and thus ld.so will
4255 not process them. */
4256 if (unresolved_reloc
4257 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4259 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4260 rel
->r_offset
) != (bfd_vma
) -1)
4262 (*_bfd_error_handler
)
4263 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4266 (long) rel
->r_offset
,
4268 h
->root
.root
.string
);
4273 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4274 contents
, rel
->r_offset
,
4277 check_relocation_error
:
4278 if (r
!= bfd_reloc_ok
)
4283 name
= h
->root
.root
.string
;
4286 name
= bfd_elf_string_from_elf_section (input_bfd
,
4287 symtab_hdr
->sh_link
,
4292 name
= bfd_section_name (input_bfd
, sec
);
4295 if (r
== bfd_reloc_overflow
)
4297 if (! ((*info
->callbacks
->reloc_overflow
)
4298 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4299 (bfd_vma
) 0, input_bfd
, input_section
,
4305 (*_bfd_error_handler
)
4306 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4307 input_bfd
, input_section
,
4308 (long) rel
->r_offset
, name
, (int) r
);
4317 /* Finish up dynamic symbol handling. We set the contents of various
4318 dynamic sections here. */
4321 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4322 struct bfd_link_info
*info
,
4323 struct elf_link_hash_entry
*h
,
4324 Elf_Internal_Sym
*sym
)
4326 struct elf_i386_link_hash_table
*htab
;
4327 unsigned plt_entry_size
;
4328 const struct elf_i386_backend_data
*abed
;
4330 htab
= elf_i386_hash_table (info
);
4334 abed
= get_elf_i386_backend_data (output_bfd
);
4335 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
4337 if (h
->plt
.offset
!= (bfd_vma
) -1)
4341 Elf_Internal_Rela rel
;
4343 asection
*plt
, *gotplt
, *relplt
;
4345 /* When building a static executable, use .iplt, .igot.plt and
4346 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4347 if (htab
->elf
.splt
!= NULL
)
4349 plt
= htab
->elf
.splt
;
4350 gotplt
= htab
->elf
.sgotplt
;
4351 relplt
= htab
->elf
.srelplt
;
4355 plt
= htab
->elf
.iplt
;
4356 gotplt
= htab
->elf
.igotplt
;
4357 relplt
= htab
->elf
.irelplt
;
4360 /* This symbol has an entry in the procedure linkage table. Set
4363 if ((h
->dynindx
== -1
4364 && !((h
->forced_local
|| info
->executable
)
4366 && h
->type
== STT_GNU_IFUNC
))
4372 /* Get the index in the procedure linkage table which
4373 corresponds to this symbol. This is the index of this symbol
4374 in all the symbols for which we are making plt entries. The
4375 first entry in the procedure linkage table is reserved.
4377 Get the offset into the .got table of the entry that
4378 corresponds to this function. Each .got entry is 4 bytes.
4379 The first three are reserved.
4381 For static executables, we don't reserve anything. */
4383 if (plt
== htab
->elf
.splt
)
4385 got_offset
= h
->plt
.offset
/ plt_entry_size
- 1;
4386 got_offset
= (got_offset
+ 3) * 4;
4390 got_offset
= h
->plt
.offset
/ plt_entry_size
;
4391 got_offset
= got_offset
* 4;
4394 /* Fill in the entry in the procedure linkage table. */
4397 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->plt_entry
,
4398 abed
->plt
->plt_entry_size
);
4399 bfd_put_32 (output_bfd
,
4400 (gotplt
->output_section
->vma
4401 + gotplt
->output_offset
4403 plt
->contents
+ h
->plt
.offset
4404 + abed
->plt
->plt_got_offset
);
4406 if (abed
->is_vxworks
)
4408 int s
, k
, reloc_index
;
4410 /* Create the R_386_32 relocation referencing the GOT
4411 for this PLT entry. */
4413 /* S: Current slot number (zero-based). */
4414 s
= ((h
->plt
.offset
- abed
->plt
->plt_entry_size
)
4415 / abed
->plt
->plt_entry_size
);
4416 /* K: Number of relocations for PLTResolve. */
4418 k
= PLTRESOLVE_RELOCS_SHLIB
;
4420 k
= PLTRESOLVE_RELOCS
;
4421 /* Skip the PLTresolve relocations, and the relocations for
4422 the other PLT slots. */
4423 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4424 loc
= (htab
->srelplt2
->contents
+ reloc_index
4425 * sizeof (Elf32_External_Rel
));
4427 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4428 + htab
->elf
.splt
->output_offset
4429 + h
->plt
.offset
+ 2),
4430 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4431 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4433 /* Create the R_386_32 relocation referencing the beginning of
4434 the PLT for this GOT entry. */
4435 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4436 + htab
->elf
.sgotplt
->output_offset
4438 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4439 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4440 loc
+ sizeof (Elf32_External_Rel
));
4445 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->pic_plt_entry
,
4446 abed
->plt
->plt_entry_size
);
4447 bfd_put_32 (output_bfd
, got_offset
,
4448 plt
->contents
+ h
->plt
.offset
4449 + abed
->plt
->plt_got_offset
);
4452 /* Fill in the entry in the global offset table. */
4453 bfd_put_32 (output_bfd
,
4454 (plt
->output_section
->vma
4455 + plt
->output_offset
4457 + abed
->plt
->plt_lazy_offset
),
4458 gotplt
->contents
+ got_offset
);
4460 /* Fill in the entry in the .rel.plt section. */
4461 rel
.r_offset
= (gotplt
->output_section
->vma
4462 + gotplt
->output_offset
4464 if (h
->dynindx
== -1
4465 || ((info
->executable
4466 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4468 && h
->type
== STT_GNU_IFUNC
))
4470 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4471 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4472 in the .got.plt section. */
4473 bfd_put_32 (output_bfd
,
4474 (h
->root
.u
.def
.value
4475 + h
->root
.u
.def
.section
->output_section
->vma
4476 + h
->root
.u
.def
.section
->output_offset
),
4477 gotplt
->contents
+ got_offset
);
4478 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4479 /* R_386_IRELATIVE comes last. */
4480 plt_index
= htab
->next_irelative_index
--;
4484 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4485 plt_index
= htab
->next_jump_slot_index
++;
4487 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4488 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4490 /* Don't fill PLT entry for static executables. */
4491 if (plt
== htab
->elf
.splt
)
4493 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4494 plt
->contents
+ h
->plt
.offset
4495 + abed
->plt
->plt_reloc_offset
);
4496 bfd_put_32 (output_bfd
, - (h
->plt
.offset
4497 + abed
->plt
->plt_plt_offset
+ 4),
4498 plt
->contents
+ h
->plt
.offset
4499 + abed
->plt
->plt_plt_offset
);
4502 if (!h
->def_regular
)
4504 /* Mark the symbol as undefined, rather than as defined in
4505 the .plt section. Leave the value if there were any
4506 relocations where pointer equality matters (this is a clue
4507 for the dynamic linker, to make function pointer
4508 comparisons work between an application and shared
4509 library), otherwise set it to zero. If a function is only
4510 called from a binary, there is no need to slow down
4511 shared libraries because of that. */
4512 sym
->st_shndx
= SHN_UNDEF
;
4513 if (!h
->pointer_equality_needed
)
4518 if (h
->got
.offset
!= (bfd_vma
) -1
4519 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4520 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4522 Elf_Internal_Rela rel
;
4525 /* This symbol has an entry in the global offset table. Set it
4528 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4531 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4532 + htab
->elf
.sgot
->output_offset
4533 + (h
->got
.offset
& ~(bfd_vma
) 1));
4535 /* If this is a static link, or it is a -Bsymbolic link and the
4536 symbol is defined locally or was forced to be local because
4537 of a version file, we just want to emit a RELATIVE reloc.
4538 The entry in the global offset table will already have been
4539 initialized in the relocate_section function. */
4541 && h
->type
== STT_GNU_IFUNC
)
4545 /* Generate R_386_GLOB_DAT. */
4552 if (!h
->pointer_equality_needed
)
4555 /* For non-shared object, we can't use .got.plt, which
4556 contains the real function addres if we need pointer
4557 equality. We load the GOT entry with the PLT entry. */
4558 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4559 bfd_put_32 (output_bfd
,
4560 (plt
->output_section
->vma
4561 + plt
->output_offset
+ h
->plt
.offset
),
4562 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4566 else if (info
->shared
4567 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4569 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4570 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4574 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4576 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4577 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4578 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4581 loc
= htab
->elf
.srelgot
->contents
;
4582 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4583 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4588 Elf_Internal_Rela rel
;
4591 /* This symbol needs a copy reloc. Set it up. */
4593 if (h
->dynindx
== -1
4594 || (h
->root
.type
!= bfd_link_hash_defined
4595 && h
->root
.type
!= bfd_link_hash_defweak
)
4596 || htab
->srelbss
== NULL
)
4599 rel
.r_offset
= (h
->root
.u
.def
.value
4600 + h
->root
.u
.def
.section
->output_section
->vma
4601 + h
->root
.u
.def
.section
->output_offset
);
4602 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4603 loc
= htab
->srelbss
->contents
;
4604 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4605 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4608 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4609 be NULL for local symbols.
4611 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
4612 is relative to the ".got" section. */
4614 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4615 || (!abed
->is_vxworks
4616 && h
== htab
->elf
.hgot
)))
4617 sym
->st_shndx
= SHN_ABS
;
4622 /* Finish up local dynamic symbol handling. We set the contents of
4623 various dynamic sections here. */
4626 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4628 struct elf_link_hash_entry
*h
4629 = (struct elf_link_hash_entry
*) *slot
;
4630 struct bfd_link_info
*info
4631 = (struct bfd_link_info
*) inf
;
4633 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4637 /* Used to decide how to sort relocs in an optimal manner for the
4638 dynamic linker, before writing them out. */
4640 static enum elf_reloc_type_class
4641 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4643 switch (ELF32_R_TYPE (rela
->r_info
))
4645 case R_386_RELATIVE
:
4646 return reloc_class_relative
;
4647 case R_386_JUMP_SLOT
:
4648 return reloc_class_plt
;
4650 return reloc_class_copy
;
4652 return reloc_class_normal
;
4656 /* Finish up the dynamic sections. */
4659 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4660 struct bfd_link_info
*info
)
4662 struct elf_i386_link_hash_table
*htab
;
4665 const struct elf_i386_backend_data
*abed
;
4667 htab
= elf_i386_hash_table (info
);
4671 dynobj
= htab
->elf
.dynobj
;
4672 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4673 abed
= get_elf_i386_backend_data (output_bfd
);
4675 if (htab
->elf
.dynamic_sections_created
)
4677 Elf32_External_Dyn
*dyncon
, *dynconend
;
4679 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4682 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4683 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4684 for (; dyncon
< dynconend
; dyncon
++)
4686 Elf_Internal_Dyn dyn
;
4689 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4694 if (abed
->is_vxworks
4695 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4700 s
= htab
->elf
.sgotplt
;
4701 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4705 s
= htab
->elf
.srelplt
;
4706 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4710 s
= htab
->elf
.srelplt
;
4711 dyn
.d_un
.d_val
= s
->size
;
4715 /* My reading of the SVR4 ABI indicates that the
4716 procedure linkage table relocs (DT_JMPREL) should be
4717 included in the overall relocs (DT_REL). This is
4718 what Solaris does. However, UnixWare can not handle
4719 that case. Therefore, we override the DT_RELSZ entry
4720 here to make it not include the JMPREL relocs. */
4721 s
= htab
->elf
.srelplt
;
4724 dyn
.d_un
.d_val
-= s
->size
;
4728 /* We may not be using the standard ELF linker script.
4729 If .rel.plt is the first .rel section, we adjust
4730 DT_REL to not include it. */
4731 s
= htab
->elf
.srelplt
;
4734 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4736 dyn
.d_un
.d_ptr
+= s
->size
;
4740 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4743 /* Fill in the first entry in the procedure linkage table. */
4744 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4748 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->pic_plt0_entry
,
4749 abed
->plt
->plt0_entry_size
);
4750 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
4751 abed
->plt0_pad_byte
,
4752 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
4756 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->plt0_entry
,
4757 abed
->plt
->plt0_entry_size
);
4758 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
4759 abed
->plt0_pad_byte
,
4760 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
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_got1_offset
);
4767 bfd_put_32 (output_bfd
,
4768 (htab
->elf
.sgotplt
->output_section
->vma
4769 + htab
->elf
.sgotplt
->output_offset
4771 htab
->elf
.splt
->contents
4772 + abed
->plt
->plt0_got2_offset
);
4774 if (abed
->is_vxworks
)
4776 Elf_Internal_Rela rel
;
4778 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4779 On IA32 we use REL relocations so the addend goes in
4780 the PLT directly. */
4781 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4782 + htab
->elf
.splt
->output_offset
4783 + abed
->plt
->plt0_got1_offset
);
4784 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4785 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4786 htab
->srelplt2
->contents
);
4787 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4788 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4789 + htab
->elf
.splt
->output_offset
4790 + abed
->plt
->plt0_got2_offset
);
4791 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4792 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4793 htab
->srelplt2
->contents
+
4794 sizeof (Elf32_External_Rel
));
4798 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4799 really seem like the right value. */
4800 elf_section_data (htab
->elf
.splt
->output_section
)
4801 ->this_hdr
.sh_entsize
= 4;
4803 /* Correct the .rel.plt.unloaded relocations. */
4804 if (abed
->is_vxworks
&& !info
->shared
)
4806 int num_plts
= (htab
->elf
.splt
->size
4807 / abed
->plt
->plt_entry_size
) - 1;
4810 p
= htab
->srelplt2
->contents
;
4812 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4814 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4816 for (; num_plts
; num_plts
--)
4818 Elf_Internal_Rela rel
;
4819 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4820 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4821 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4822 p
+= sizeof (Elf32_External_Rel
);
4824 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4825 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4826 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4827 p
+= sizeof (Elf32_External_Rel
);
4833 if (htab
->elf
.sgotplt
)
4835 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4837 (*_bfd_error_handler
)
4838 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4842 /* Fill in the first three entries in the global offset table. */
4843 if (htab
->elf
.sgotplt
->size
> 0)
4845 bfd_put_32 (output_bfd
,
4847 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4848 htab
->elf
.sgotplt
->contents
);
4849 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4850 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4853 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4856 /* Adjust .eh_frame for .plt section. */
4857 if (htab
->plt_eh_frame
!= NULL
)
4859 if (htab
->elf
.splt
!= NULL
4860 && htab
->elf
.splt
->size
!= 0
4861 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4862 && htab
->elf
.splt
->output_section
!= NULL
4863 && htab
->plt_eh_frame
->output_section
!= NULL
)
4865 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4866 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4867 + htab
->plt_eh_frame
->output_offset
4868 + PLT_FDE_START_OFFSET
;
4869 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4870 htab
->plt_eh_frame
->contents
4871 + PLT_FDE_START_OFFSET
);
4873 if (htab
->plt_eh_frame
->sec_info_type
4874 == ELF_INFO_TYPE_EH_FRAME
)
4876 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4878 htab
->plt_eh_frame
->contents
))
4883 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4884 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4886 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4887 htab_traverse (htab
->loc_hash_table
,
4888 elf_i386_finish_local_dynamic_symbol
,
4894 /* Return address for Ith PLT stub in section PLT, for relocation REL
4895 or (bfd_vma) -1 if it should not be included. */
4898 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4899 const arelent
*rel ATTRIBUTE_UNUSED
)
4901 return plt
->vma
+ (i
+ 1) * GET_PLT_ENTRY_SIZE (plt
->owner
);
4904 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4907 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4909 if (h
->plt
.offset
!= (bfd_vma
) -1
4911 && !h
->pointer_equality_needed
)
4914 return _bfd_elf_hash_symbol (h
);
4917 /* Hook called by the linker routine which adds symbols from an object
4921 elf_i386_add_symbol_hook (bfd
* abfd
,
4922 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4923 Elf_Internal_Sym
* sym
,
4924 const char ** namep ATTRIBUTE_UNUSED
,
4925 flagword
* flagsp ATTRIBUTE_UNUSED
,
4926 asection
** secp ATTRIBUTE_UNUSED
,
4927 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4929 if ((abfd
->flags
& DYNAMIC
) == 0
4930 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4931 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4932 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4937 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4938 #define TARGET_LITTLE_NAME "elf32-i386"
4939 #define ELF_ARCH bfd_arch_i386
4940 #define ELF_TARGET_ID I386_ELF_DATA
4941 #define ELF_MACHINE_CODE EM_386
4942 #define ELF_MAXPAGESIZE 0x1000
4944 #define elf_backend_can_gc_sections 1
4945 #define elf_backend_can_refcount 1
4946 #define elf_backend_want_got_plt 1
4947 #define elf_backend_plt_readonly 1
4948 #define elf_backend_want_plt_sym 0
4949 #define elf_backend_got_header_size 12
4950 #define elf_backend_plt_alignment 4
4952 /* Support RELA for objdump of prelink objects. */
4953 #define elf_info_to_howto elf_i386_info_to_howto_rel
4954 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4956 #define bfd_elf32_mkobject elf_i386_mkobject
4958 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4959 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4960 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4961 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4962 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4964 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4965 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4966 #define elf_backend_check_relocs elf_i386_check_relocs
4967 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4968 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4969 #define elf_backend_fake_sections elf_i386_fake_sections
4970 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4971 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4972 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4973 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4974 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4975 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4976 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4977 #define elf_backend_relocate_section elf_i386_relocate_section
4978 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4979 #define elf_backend_always_size_sections elf_i386_always_size_sections
4980 #define elf_backend_omit_section_dynsym \
4981 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4982 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4983 #define elf_backend_hash_symbol elf_i386_hash_symbol
4984 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4985 #undef elf_backend_post_process_headers
4986 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4988 #include "elf32-target.h"
4990 /* FreeBSD support. */
4992 #undef TARGET_LITTLE_SYM
4993 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4994 #undef TARGET_LITTLE_NAME
4995 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4997 #define ELF_OSABI ELFOSABI_FREEBSD
4999 /* The kernel recognizes executables as valid only if they carry a
5000 "FreeBSD" label in the ELF header. So we put this label on all
5001 executables and (for simplicity) also all other object files. */
5004 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
5006 _bfd_elf_set_osabi (abfd
, info
);
5008 #ifdef OLD_FREEBSD_ABI_LABEL
5009 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5010 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5014 #undef elf_backend_post_process_headers
5015 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
5017 #define elf32_bed elf32_i386_fbsd_bed
5019 #undef elf_backend_add_symbol_hook
5021 #include "elf32-target.h"
5025 #undef TARGET_LITTLE_SYM
5026 #define TARGET_LITTLE_SYM bfd_elf32_i386_sol2_vec
5027 #undef TARGET_LITTLE_NAME
5028 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
5030 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5031 objects won't be recognized. */
5035 #define elf32_bed elf32_i386_sol2_bed
5037 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5039 #undef elf_backend_static_tls_alignment
5040 #define elf_backend_static_tls_alignment 8
5042 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5044 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5046 #undef elf_backend_want_plt_sym
5047 #define elf_backend_want_plt_sym 1
5049 #include "elf32-target.h"
5051 /* Native Client support. */
5053 #undef TARGET_LITTLE_SYM
5054 #define TARGET_LITTLE_SYM bfd_elf32_i386_nacl_vec
5055 #undef TARGET_LITTLE_NAME
5056 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
5058 #define elf32_bed elf32_i386_nacl_bed
5060 #undef ELF_MAXPAGESIZE
5061 #define ELF_MAXPAGESIZE 0x10000
5063 /* Restore defaults. */
5065 #undef elf_backend_want_plt_sym
5066 #define elf_backend_want_plt_sym 0
5067 #undef elf_backend_post_process_headers
5068 #define elf_backend_post_process_headers _bfd_elf_set_osabi
5069 #undef elf_backend_static_tls_alignment
5071 /* NaCl uses substantially different PLT entries for the same effects. */
5073 #undef elf_backend_plt_alignment
5074 #define elf_backend_plt_alignment 5
5075 #define NACL_PLT_ENTRY_SIZE 64
5076 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5078 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
5080 0xff, 0x35, /* pushl contents of address */
5081 0, 0, 0, 0, /* replaced with address of .got + 4. */
5082 0x8b, 0x0d, /* movl contents of address, %ecx */
5083 0, 0, 0, 0, /* replaced with address of .got + 8. */
5084 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5085 0xff, 0xe1 /* jmp *%ecx */
5088 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5090 0x8b, 0x0d, /* movl contents of address, %ecx */
5091 0, 0, 0, 0, /* replaced with GOT slot address. */
5092 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5093 0xff, 0xe1, /* jmp *%ecx */
5095 /* Pad to the next 32-byte boundary with nop instructions. */
5097 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5098 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5100 /* Lazy GOT entries point here (32-byte aligned). */
5101 0x68, /* pushl immediate */
5102 0, 0, 0, 0, /* replaced with reloc offset. */
5103 0xe9, /* jmp relative */
5104 0, 0, 0, 0, /* replaced with offset to .plt. */
5106 /* Pad to the next 32-byte boundary with nop instructions. */
5107 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5108 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5112 static const bfd_byte
5113 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
5115 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5116 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5117 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5118 0xff, 0xe1, /* jmp *%ecx */
5122 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5124 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5125 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5126 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5127 0xff, 0xe1, /* jmp *%ecx */
5129 /* Pad to the next 32-byte boundary with nop instructions. */
5131 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5132 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5134 /* Lazy GOT entries point here (32-byte aligned). */
5135 0x68, /* pushl immediate */
5136 0, 0, 0, 0, /* replaced with offset into relocation table. */
5137 0xe9, /* jmp relative */
5138 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5140 /* Pad to the next 32-byte boundary with nop instructions. */
5141 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5142 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5146 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
5148 #if (PLT_CIE_LENGTH != 20 \
5149 || PLT_FDE_LENGTH != 36 \
5150 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5151 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5152 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5154 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5155 0, 0, 0, 0, /* CIE ID */
5156 1, /* CIE version */
5157 'z', 'R', 0, /* Augmentation string */
5158 1, /* Code alignment factor */
5159 0x7c, /* Data alignment factor: -4 */
5160 8, /* Return address column */
5161 1, /* Augmentation size */
5162 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5163 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5164 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5165 DW_CFA_nop
, DW_CFA_nop
,
5167 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5168 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
5169 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5170 0, 0, 0, 0, /* .plt size goes here */
5171 0, /* Augmentation size */
5172 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
5173 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5174 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
5175 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5176 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5177 13, /* Block length */
5178 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
5179 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
5180 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5181 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
5182 DW_CFA_nop
, DW_CFA_nop
5185 static const struct elf_i386_plt_layout elf_i386_nacl_plt
=
5187 elf_i386_nacl_plt0_entry
, /* plt0_entry */
5188 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
5189 2, /* plt0_got1_offset */
5190 8, /* plt0_got2_offset */
5191 elf_i386_nacl_plt_entry
, /* plt_entry */
5192 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5193 2, /* plt_got_offset */
5194 33, /* plt_reloc_offset */
5195 38, /* plt_plt_offset */
5196 32, /* plt_lazy_offset */
5197 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
5198 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
5199 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
5200 sizeof (elf_i386_nacl_eh_frame_plt
),/* eh_frame_plt_size */
5203 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
5205 &elf_i386_nacl_plt
, /* plt */
5206 0x90, /* plt0_pad_byte: nop insn */
5210 #undef elf_backend_arch_data
5211 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
5213 #include "elf32-target.h"
5215 /* VxWorks support. */
5217 #undef TARGET_LITTLE_SYM
5218 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
5219 #undef TARGET_LITTLE_NAME
5220 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
5222 #undef elf_backend_plt_alignment
5223 #define elf_backend_plt_alignment 4
5225 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
5227 &elf_i386_plt
, /* plt */
5228 0x90, /* plt0_pad_byte */
5232 #undef elf_backend_arch_data
5233 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
5235 #undef elf_backend_relocs_compatible
5236 #undef elf_backend_post_process_headers
5237 #undef elf_backend_add_symbol_hook
5238 #define elf_backend_add_symbol_hook \
5239 elf_vxworks_add_symbol_hook
5240 #undef elf_backend_link_output_symbol_hook
5241 #define elf_backend_link_output_symbol_hook \
5242 elf_vxworks_link_output_symbol_hook
5243 #undef elf_backend_emit_relocs
5244 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5245 #undef elf_backend_final_write_processing
5246 #define elf_backend_final_write_processing \
5247 elf_vxworks_final_write_processing
5248 #undef elf_backend_static_tls_alignment
5250 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5252 #undef elf_backend_want_plt_sym
5253 #define elf_backend_want_plt_sym 1
5256 #define elf32_bed elf32_i386_vxworks_bed
5258 #include "elf32-target.h"