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
;
811 /* Get the i386 ELF linker hash table from a link_info structure. */
813 #define elf_i386_hash_table(p) \
814 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
815 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
817 #define elf_i386_compute_jump_table_size(htab) \
818 ((htab)->next_tls_desc_index * 4)
820 /* Create an entry in an i386 ELF linker hash table. */
822 static struct bfd_hash_entry
*
823 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
824 struct bfd_hash_table
*table
,
827 /* Allocate the structure if it has not already been allocated by a
831 entry
= (struct bfd_hash_entry
*)
832 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
837 /* Call the allocation method of the superclass. */
838 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
841 struct elf_i386_link_hash_entry
*eh
;
843 eh
= (struct elf_i386_link_hash_entry
*) entry
;
844 eh
->dyn_relocs
= NULL
;
845 eh
->tls_type
= GOT_UNKNOWN
;
846 eh
->tlsdesc_got
= (bfd_vma
) -1;
852 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
853 for local symbol so that we can handle local STT_GNU_IFUNC symbols
854 as global symbol. We reuse indx and dynstr_index for local symbol
855 hash since they aren't used by global symbols in this backend. */
858 elf_i386_local_htab_hash (const void *ptr
)
860 struct elf_link_hash_entry
*h
861 = (struct elf_link_hash_entry
*) ptr
;
862 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
865 /* Compare local hash entries. */
868 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
870 struct elf_link_hash_entry
*h1
871 = (struct elf_link_hash_entry
*) ptr1
;
872 struct elf_link_hash_entry
*h2
873 = (struct elf_link_hash_entry
*) ptr2
;
875 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
878 /* Find and/or create a hash entry for local symbol. */
880 static struct elf_link_hash_entry
*
881 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
882 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
885 struct elf_i386_link_hash_entry e
, *ret
;
886 asection
*sec
= abfd
->sections
;
887 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
888 ELF32_R_SYM (rel
->r_info
));
891 e
.elf
.indx
= sec
->id
;
892 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
893 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
894 create
? INSERT
: NO_INSERT
);
901 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
905 ret
= (struct elf_i386_link_hash_entry
*)
906 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
907 sizeof (struct elf_i386_link_hash_entry
));
910 memset (ret
, 0, sizeof (*ret
));
911 ret
->elf
.indx
= sec
->id
;
912 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
913 ret
->elf
.dynindx
= -1;
919 /* Create an i386 ELF linker hash table. */
921 static struct bfd_link_hash_table
*
922 elf_i386_link_hash_table_create (bfd
*abfd
)
924 struct elf_i386_link_hash_table
*ret
;
925 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
927 ret
= (struct elf_i386_link_hash_table
*) bfd_malloc (amt
);
931 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
932 elf_i386_link_hash_newfunc
,
933 sizeof (struct elf_i386_link_hash_entry
),
942 ret
->plt_eh_frame
= NULL
;
943 ret
->tls_ldm_got
.refcount
= 0;
944 ret
->next_tls_desc_index
= 0;
945 ret
->sgotplt_jump_table_size
= 0;
946 ret
->sym_cache
.abfd
= NULL
;
947 ret
->srelplt2
= NULL
;
948 ret
->tls_module_base
= NULL
;
950 ret
->loc_hash_table
= htab_try_create (1024,
951 elf_i386_local_htab_hash
,
952 elf_i386_local_htab_eq
,
954 ret
->loc_hash_memory
= objalloc_create ();
955 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
961 return &ret
->elf
.root
;
964 /* Destroy an i386 ELF linker hash table. */
967 elf_i386_link_hash_table_free (struct bfd_link_hash_table
*hash
)
969 struct elf_i386_link_hash_table
*htab
970 = (struct elf_i386_link_hash_table
*) hash
;
972 if (htab
->loc_hash_table
)
973 htab_delete (htab
->loc_hash_table
);
974 if (htab
->loc_hash_memory
)
975 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
976 _bfd_generic_link_hash_table_free (hash
);
979 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
980 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
984 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
986 struct elf_i386_link_hash_table
*htab
;
988 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
991 htab
= elf_i386_hash_table (info
);
995 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
997 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
1000 || (!info
->shared
&& !htab
->srelbss
))
1003 if (get_elf_i386_backend_data (dynobj
)->is_vxworks
1004 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
1008 if (!info
->no_ld_generated_unwind_info
1009 && bfd_get_section_by_name (dynobj
, ".eh_frame") == NULL
1010 && htab
->elf
.splt
!= NULL
)
1012 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
1014 = bfd_make_section_with_flags (dynobj
, ".eh_frame",
1015 flags
| SEC_READONLY
);
1016 if (htab
->plt_eh_frame
== NULL
1017 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 2))
1020 htab
->plt_eh_frame
->size
= sizeof (elf_i386_eh_frame_plt
);
1021 htab
->plt_eh_frame
->contents
1022 = bfd_alloc (dynobj
, htab
->plt_eh_frame
->size
);
1023 memcpy (htab
->plt_eh_frame
->contents
, elf_i386_eh_frame_plt
,
1024 sizeof (elf_i386_eh_frame_plt
));
1030 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1033 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1034 struct elf_link_hash_entry
*dir
,
1035 struct elf_link_hash_entry
*ind
)
1037 struct elf_i386_link_hash_entry
*edir
, *eind
;
1039 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1040 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1042 if (eind
->dyn_relocs
!= NULL
)
1044 if (edir
->dyn_relocs
!= NULL
)
1046 struct elf_dyn_relocs
**pp
;
1047 struct elf_dyn_relocs
*p
;
1049 /* Add reloc counts against the indirect sym to the direct sym
1050 list. Merge any entries against the same section. */
1051 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1053 struct elf_dyn_relocs
*q
;
1055 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1056 if (q
->sec
== p
->sec
)
1058 q
->pc_count
+= p
->pc_count
;
1059 q
->count
+= p
->count
;
1066 *pp
= edir
->dyn_relocs
;
1069 edir
->dyn_relocs
= eind
->dyn_relocs
;
1070 eind
->dyn_relocs
= NULL
;
1073 if (ind
->root
.type
== bfd_link_hash_indirect
1074 && dir
->got
.refcount
<= 0)
1076 edir
->tls_type
= eind
->tls_type
;
1077 eind
->tls_type
= GOT_UNKNOWN
;
1080 if (ELIMINATE_COPY_RELOCS
1081 && ind
->root
.type
!= bfd_link_hash_indirect
1082 && dir
->dynamic_adjusted
)
1084 /* If called to transfer flags for a weakdef during processing
1085 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1086 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1087 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1088 dir
->ref_regular
|= ind
->ref_regular
;
1089 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1090 dir
->needs_plt
|= ind
->needs_plt
;
1091 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1094 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1104 /* Return TRUE if the TLS access code sequence support transition
1108 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
1110 Elf_Internal_Shdr
*symtab_hdr
,
1111 struct elf_link_hash_entry
**sym_hashes
,
1112 unsigned int r_type
,
1113 const Elf_Internal_Rela
*rel
,
1114 const Elf_Internal_Rela
*relend
)
1116 unsigned int val
, type
;
1117 unsigned long r_symndx
;
1118 struct elf_link_hash_entry
*h
;
1121 /* Get the section contents. */
1122 if (contents
== NULL
)
1124 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1125 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1128 /* FIXME: How to better handle error condition? */
1129 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1132 /* Cache the section contents for elf_link_input_bfd. */
1133 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1137 offset
= rel
->r_offset
;
1142 if (offset
< 2 || (rel
+ 1) >= relend
)
1145 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1146 if (r_type
== R_386_TLS_GD
)
1148 /* Check transition from GD access model. Only
1149 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1150 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1151 can transit to different access model. */
1152 if ((offset
+ 10) > sec
->size
||
1153 (type
!= 0x8d && type
!= 0x04))
1156 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1159 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1163 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1166 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1171 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1172 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1175 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1181 /* Check transition from LD access model. Only
1182 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1183 can transit to different access model. */
1184 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1187 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1188 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1192 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1195 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1196 if (r_symndx
< symtab_hdr
->sh_info
)
1199 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1200 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1201 may be versioned. */
1203 && h
->root
.root
.string
!= NULL
1204 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1205 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1206 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1210 /* Check transition from IE access model:
1211 movl foo@indntpoff(%rip), %eax
1212 movl foo@indntpoff(%rip), %reg
1213 addl foo@indntpoff(%rip), %reg
1216 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1219 /* Check "movl foo@tpoff(%rip), %eax" first. */
1220 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1227 /* Check movl|addl foo@tpoff(%rip), %reg. */
1228 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1229 return ((type
== 0x8b || type
== 0x03)
1230 && (val
& 0xc7) == 0x05);
1232 case R_386_TLS_GOTIE
:
1233 case R_386_TLS_IE_32
:
1234 /* Check transition from {IE_32,GOTIE} access model:
1235 subl foo@{tpoff,gontoff}(%reg1), %reg2
1236 movl foo@{tpoff,gontoff}(%reg1), %reg2
1237 addl foo@{tpoff,gontoff}(%reg1), %reg2
1240 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1243 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1244 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1247 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1248 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1250 case R_386_TLS_GOTDESC
:
1251 /* Check transition from GDesc access model:
1252 leal x@tlsdesc(%ebx), %eax
1254 Make sure it's a leal adding ebx to a 32-bit offset
1255 into any register, although it's probably almost always
1258 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1261 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1264 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1265 return (val
& 0xc7) == 0x83;
1267 case R_386_TLS_DESC_CALL
:
1268 /* Check transition from GDesc access model:
1269 call *x@tlsdesc(%rax)
1271 if (offset
+ 2 <= sec
->size
)
1273 /* Make sure that it's a call *x@tlsdesc(%rax). */
1274 static i386_opcode16 call
= { { 0xff, 0x10 } };
1275 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1285 /* Return TRUE if the TLS access transition is OK or no transition
1286 will be performed. Update R_TYPE if there is a transition. */
1289 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1290 asection
*sec
, bfd_byte
*contents
,
1291 Elf_Internal_Shdr
*symtab_hdr
,
1292 struct elf_link_hash_entry
**sym_hashes
,
1293 unsigned int *r_type
, int tls_type
,
1294 const Elf_Internal_Rela
*rel
,
1295 const Elf_Internal_Rela
*relend
,
1296 struct elf_link_hash_entry
*h
,
1297 unsigned long r_symndx
)
1299 unsigned int from_type
= *r_type
;
1300 unsigned int to_type
= from_type
;
1301 bfd_boolean check
= TRUE
;
1303 /* Skip TLS transition for functions. */
1305 && (h
->type
== STT_FUNC
1306 || h
->type
== STT_GNU_IFUNC
))
1312 case R_386_TLS_GOTDESC
:
1313 case R_386_TLS_DESC_CALL
:
1314 case R_386_TLS_IE_32
:
1316 case R_386_TLS_GOTIE
:
1317 if (info
->executable
)
1320 to_type
= R_386_TLS_LE_32
;
1321 else if (from_type
!= R_386_TLS_IE
1322 && from_type
!= R_386_TLS_GOTIE
)
1323 to_type
= R_386_TLS_IE_32
;
1326 /* When we are called from elf_i386_relocate_section, CONTENTS
1327 isn't NULL and there may be additional transitions based on
1329 if (contents
!= NULL
)
1331 unsigned int new_to_type
= to_type
;
1333 if (info
->executable
1336 && (tls_type
& GOT_TLS_IE
))
1337 new_to_type
= R_386_TLS_LE_32
;
1339 if (to_type
== R_386_TLS_GD
1340 || to_type
== R_386_TLS_GOTDESC
1341 || to_type
== R_386_TLS_DESC_CALL
)
1343 if (tls_type
== GOT_TLS_IE_POS
)
1344 new_to_type
= R_386_TLS_GOTIE
;
1345 else if (tls_type
& GOT_TLS_IE
)
1346 new_to_type
= R_386_TLS_IE_32
;
1349 /* We checked the transition before when we were called from
1350 elf_i386_check_relocs. We only want to check the new
1351 transition which hasn't been checked before. */
1352 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1353 to_type
= new_to_type
;
1359 if (info
->executable
)
1360 to_type
= R_386_TLS_LE_32
;
1367 /* Return TRUE if there is no transition. */
1368 if (from_type
== to_type
)
1371 /* Check if the transition can be performed. */
1373 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1374 symtab_hdr
, sym_hashes
,
1375 from_type
, rel
, relend
))
1377 reloc_howto_type
*from
, *to
;
1380 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1381 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1384 name
= h
->root
.root
.string
;
1387 struct elf_i386_link_hash_table
*htab
;
1389 htab
= elf_i386_hash_table (info
);
1394 Elf_Internal_Sym
*isym
;
1396 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1398 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1402 (*_bfd_error_handler
)
1403 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1404 "in section `%A' failed"),
1405 abfd
, sec
, from
->name
, to
->name
, name
,
1406 (unsigned long) rel
->r_offset
);
1407 bfd_set_error (bfd_error_bad_value
);
1415 /* Look through the relocs for a section during the first phase, and
1416 calculate needed space in the global offset table, procedure linkage
1417 table, and dynamic reloc sections. */
1420 elf_i386_check_relocs (bfd
*abfd
,
1421 struct bfd_link_info
*info
,
1423 const Elf_Internal_Rela
*relocs
)
1425 struct elf_i386_link_hash_table
*htab
;
1426 Elf_Internal_Shdr
*symtab_hdr
;
1427 struct elf_link_hash_entry
**sym_hashes
;
1428 const Elf_Internal_Rela
*rel
;
1429 const Elf_Internal_Rela
*rel_end
;
1432 if (info
->relocatable
)
1435 BFD_ASSERT (is_i386_elf (abfd
));
1437 htab
= elf_i386_hash_table (info
);
1441 symtab_hdr
= &elf_symtab_hdr (abfd
);
1442 sym_hashes
= elf_sym_hashes (abfd
);
1446 rel_end
= relocs
+ sec
->reloc_count
;
1447 for (rel
= relocs
; rel
< rel_end
; rel
++)
1449 unsigned int r_type
;
1450 unsigned long r_symndx
;
1451 struct elf_link_hash_entry
*h
;
1452 Elf_Internal_Sym
*isym
;
1455 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1456 r_type
= ELF32_R_TYPE (rel
->r_info
);
1458 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1460 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1466 if (r_symndx
< symtab_hdr
->sh_info
)
1468 /* A local symbol. */
1469 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1474 /* Check relocation against local STT_GNU_IFUNC symbol. */
1475 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1477 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1481 /* Fake a STT_GNU_IFUNC symbol. */
1482 h
->type
= STT_GNU_IFUNC
;
1485 h
->forced_local
= 1;
1486 h
->root
.type
= bfd_link_hash_defined
;
1494 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1495 while (h
->root
.type
== bfd_link_hash_indirect
1496 || h
->root
.type
== bfd_link_hash_warning
)
1497 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1502 /* Create the ifunc sections for static executables. If we
1503 never see an indirect function symbol nor we are building
1504 a static executable, those sections will be empty and
1505 won't appear in output. */
1516 if (htab
->elf
.dynobj
== NULL
)
1517 htab
->elf
.dynobj
= abfd
;
1518 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1523 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1524 it here if it is defined in a non-shared object. */
1525 if (h
->type
== STT_GNU_IFUNC
1528 /* It is referenced by a non-shared object. */
1532 /* STT_GNU_IFUNC symbol must go through PLT. */
1533 h
->plt
.refcount
+= 1;
1535 /* STT_GNU_IFUNC needs dynamic sections. */
1536 if (htab
->elf
.dynobj
== NULL
)
1537 htab
->elf
.dynobj
= abfd
;
1542 if (h
->root
.root
.string
)
1543 name
= h
->root
.root
.string
;
1545 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1547 (*_bfd_error_handler
)
1548 (_("%B: relocation %s against STT_GNU_IFUNC "
1549 "symbol `%s' isn't handled by %s"), abfd
,
1550 elf_howto_table
[r_type
].name
,
1551 name
, __FUNCTION__
);
1552 bfd_set_error (bfd_error_bad_value
);
1557 h
->pointer_equality_needed
= 1;
1560 /* We must copy these reloc types into the
1561 output file. Create a reloc section in
1562 dynobj and make room for this reloc. */
1563 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1564 (abfd
, info
, sec
, sreloc
,
1565 &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
);
1580 h
->got
.refcount
+= 1;
1581 if (htab
->elf
.sgot
== NULL
1582 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1592 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1593 symtab_hdr
, sym_hashes
,
1594 &r_type
, GOT_UNKNOWN
,
1595 rel
, rel_end
, h
, r_symndx
))
1601 htab
->tls_ldm_got
.refcount
+= 1;
1605 /* This symbol requires a procedure linkage table entry. We
1606 actually build the entry in adjust_dynamic_symbol,
1607 because this might be a case of linking PIC code which is
1608 never referenced by a dynamic object, in which case we
1609 don't need to generate a procedure linkage table entry
1612 /* If this is a local symbol, we resolve it directly without
1613 creating a procedure linkage table entry. */
1618 h
->plt
.refcount
+= 1;
1621 case R_386_TLS_IE_32
:
1623 case R_386_TLS_GOTIE
:
1624 if (!info
->executable
)
1625 info
->flags
|= DF_STATIC_TLS
;
1630 case R_386_TLS_GOTDESC
:
1631 case R_386_TLS_DESC_CALL
:
1632 /* This symbol requires a global offset table entry. */
1634 int tls_type
, old_tls_type
;
1639 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1640 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1641 case R_386_TLS_GOTDESC
:
1642 case R_386_TLS_DESC_CALL
:
1643 tls_type
= GOT_TLS_GDESC
; break;
1644 case R_386_TLS_IE_32
:
1645 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1646 tls_type
= GOT_TLS_IE_NEG
;
1648 /* If this is a GD->IE transition, we may use either of
1649 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1650 tls_type
= GOT_TLS_IE
;
1653 case R_386_TLS_GOTIE
:
1654 tls_type
= GOT_TLS_IE_POS
; break;
1659 h
->got
.refcount
+= 1;
1660 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1664 bfd_signed_vma
*local_got_refcounts
;
1666 /* This is a global offset table entry for a local symbol. */
1667 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1668 if (local_got_refcounts
== NULL
)
1672 size
= symtab_hdr
->sh_info
;
1673 size
*= (sizeof (bfd_signed_vma
)
1674 + sizeof (bfd_vma
) + sizeof(char));
1675 local_got_refcounts
= (bfd_signed_vma
*)
1676 bfd_zalloc (abfd
, size
);
1677 if (local_got_refcounts
== NULL
)
1679 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1680 elf_i386_local_tlsdesc_gotent (abfd
)
1681 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1682 elf_i386_local_got_tls_type (abfd
)
1683 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1685 local_got_refcounts
[r_symndx
] += 1;
1686 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1689 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1690 tls_type
|= old_tls_type
;
1691 /* If a TLS symbol is accessed using IE at least once,
1692 there is no point to use dynamic model for it. */
1693 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1694 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1695 || (tls_type
& GOT_TLS_IE
) == 0))
1697 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1698 tls_type
= old_tls_type
;
1699 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1700 && GOT_TLS_GD_ANY_P (tls_type
))
1701 tls_type
|= old_tls_type
;
1705 name
= h
->root
.root
.string
;
1707 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1709 (*_bfd_error_handler
)
1710 (_("%B: `%s' accessed both as normal and "
1711 "thread local symbol"),
1717 if (old_tls_type
!= tls_type
)
1720 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1722 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1730 if (htab
->elf
.sgot
== NULL
)
1732 if (htab
->elf
.dynobj
== NULL
)
1733 htab
->elf
.dynobj
= abfd
;
1734 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1737 if (r_type
!= R_386_TLS_IE
)
1741 case R_386_TLS_LE_32
:
1743 if (info
->executable
)
1745 info
->flags
|= DF_STATIC_TLS
;
1750 if (h
!= NULL
&& info
->executable
)
1752 /* If this reloc is in a read-only section, we might
1753 need a copy reloc. We can't check reliably at this
1754 stage whether the section is read-only, as input
1755 sections have not yet been mapped to output sections.
1756 Tentatively set the flag for now, and correct in
1757 adjust_dynamic_symbol. */
1760 /* We may need a .plt entry if the function this reloc
1761 refers to is in a shared lib. */
1762 h
->plt
.refcount
+= 1;
1763 if (r_type
!= R_386_PC32
)
1764 h
->pointer_equality_needed
= 1;
1767 /* If we are creating a shared library, and this is a reloc
1768 against a global symbol, or a non PC relative reloc
1769 against a local symbol, then we need to copy the reloc
1770 into the shared library. However, if we are linking with
1771 -Bsymbolic, we do not need to copy a reloc against a
1772 global symbol which is defined in an object we are
1773 including in the link (i.e., DEF_REGULAR is set). At
1774 this point we have not seen all the input files, so it is
1775 possible that DEF_REGULAR is not set now but will be set
1776 later (it is never cleared). In case of a weak definition,
1777 DEF_REGULAR may be cleared later by a strong definition in
1778 a shared library. We account for that possibility below by
1779 storing information in the relocs_copied field of the hash
1780 table entry. A similar situation occurs when creating
1781 shared libraries and symbol visibility changes render the
1784 If on the other hand, we are creating an executable, we
1785 may need to keep relocations for symbols satisfied by a
1786 dynamic library if we manage to avoid copy relocs for the
1789 && (sec
->flags
& SEC_ALLOC
) != 0
1790 && (r_type
!= R_386_PC32
1792 && (! SYMBOLIC_BIND (info
, h
)
1793 || h
->root
.type
== bfd_link_hash_defweak
1794 || !h
->def_regular
))))
1795 || (ELIMINATE_COPY_RELOCS
1797 && (sec
->flags
& SEC_ALLOC
) != 0
1799 && (h
->root
.type
== bfd_link_hash_defweak
1800 || !h
->def_regular
)))
1802 struct elf_dyn_relocs
*p
;
1803 struct elf_dyn_relocs
**head
;
1805 /* We must copy these reloc types into the output file.
1806 Create a reloc section in dynobj and make room for
1810 if (htab
->elf
.dynobj
== NULL
)
1811 htab
->elf
.dynobj
= abfd
;
1813 sreloc
= _bfd_elf_make_dynamic_reloc_section
1814 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1820 /* If this is a global symbol, we count the number of
1821 relocations we need for this symbol. */
1824 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1828 /* Track dynamic relocs needed for local syms too.
1829 We really need local syms available to do this
1834 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1839 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1843 vpp
= &elf_section_data (s
)->local_dynrel
;
1844 head
= (struct elf_dyn_relocs
**)vpp
;
1848 if (p
== NULL
|| p
->sec
!= sec
)
1850 bfd_size_type amt
= sizeof *p
;
1851 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1863 if (r_type
== R_386_PC32
)
1868 /* This relocation describes the C++ object vtable hierarchy.
1869 Reconstruct it for later use during GC. */
1870 case R_386_GNU_VTINHERIT
:
1871 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1875 /* This relocation describes which C++ vtable entries are actually
1876 used. Record for later use during GC. */
1877 case R_386_GNU_VTENTRY
:
1878 BFD_ASSERT (h
!= NULL
);
1880 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1892 /* Return the section that should be marked against GC for a given
1896 elf_i386_gc_mark_hook (asection
*sec
,
1897 struct bfd_link_info
*info
,
1898 Elf_Internal_Rela
*rel
,
1899 struct elf_link_hash_entry
*h
,
1900 Elf_Internal_Sym
*sym
)
1903 switch (ELF32_R_TYPE (rel
->r_info
))
1905 case R_386_GNU_VTINHERIT
:
1906 case R_386_GNU_VTENTRY
:
1910 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1913 /* Update the got entry reference counts for the section being removed. */
1916 elf_i386_gc_sweep_hook (bfd
*abfd
,
1917 struct bfd_link_info
*info
,
1919 const Elf_Internal_Rela
*relocs
)
1921 struct elf_i386_link_hash_table
*htab
;
1922 Elf_Internal_Shdr
*symtab_hdr
;
1923 struct elf_link_hash_entry
**sym_hashes
;
1924 bfd_signed_vma
*local_got_refcounts
;
1925 const Elf_Internal_Rela
*rel
, *relend
;
1927 if (info
->relocatable
)
1930 htab
= elf_i386_hash_table (info
);
1934 elf_section_data (sec
)->local_dynrel
= NULL
;
1936 symtab_hdr
= &elf_symtab_hdr (abfd
);
1937 sym_hashes
= elf_sym_hashes (abfd
);
1938 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1940 relend
= relocs
+ sec
->reloc_count
;
1941 for (rel
= relocs
; rel
< relend
; rel
++)
1943 unsigned long r_symndx
;
1944 unsigned int r_type
;
1945 struct elf_link_hash_entry
*h
= NULL
;
1947 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1948 if (r_symndx
>= symtab_hdr
->sh_info
)
1950 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1951 while (h
->root
.type
== bfd_link_hash_indirect
1952 || h
->root
.type
== bfd_link_hash_warning
)
1953 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1957 /* A local symbol. */
1958 Elf_Internal_Sym
*isym
;
1960 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1963 /* Check relocation against local STT_GNU_IFUNC symbol. */
1965 && ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1967 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1975 struct elf_i386_link_hash_entry
*eh
;
1976 struct elf_dyn_relocs
**pp
;
1977 struct elf_dyn_relocs
*p
;
1979 eh
= (struct elf_i386_link_hash_entry
*) h
;
1980 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1983 /* Everything must go for SEC. */
1989 r_type
= ELF32_R_TYPE (rel
->r_info
);
1990 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1991 symtab_hdr
, sym_hashes
,
1992 &r_type
, GOT_UNKNOWN
,
1993 rel
, relend
, h
, r_symndx
))
1999 if (htab
->tls_ldm_got
.refcount
> 0)
2000 htab
->tls_ldm_got
.refcount
-= 1;
2004 case R_386_TLS_GOTDESC
:
2005 case R_386_TLS_DESC_CALL
:
2006 case R_386_TLS_IE_32
:
2008 case R_386_TLS_GOTIE
:
2012 if (h
->got
.refcount
> 0)
2013 h
->got
.refcount
-= 1;
2014 if (h
->type
== STT_GNU_IFUNC
)
2016 if (h
->plt
.refcount
> 0)
2017 h
->plt
.refcount
-= 1;
2020 else if (local_got_refcounts
!= NULL
)
2022 if (local_got_refcounts
[r_symndx
] > 0)
2023 local_got_refcounts
[r_symndx
] -= 1;
2030 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2037 if (h
->plt
.refcount
> 0)
2038 h
->plt
.refcount
-= 1;
2043 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2045 if (h
->got
.refcount
> 0)
2046 h
->got
.refcount
-= 1;
2047 if (h
->plt
.refcount
> 0)
2048 h
->plt
.refcount
-= 1;
2060 /* Adjust a symbol defined by a dynamic object and referenced by a
2061 regular object. The current definition is in some section of the
2062 dynamic object, but we're not including those sections. We have to
2063 change the definition to something the rest of the link can
2067 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2068 struct elf_link_hash_entry
*h
)
2070 struct elf_i386_link_hash_table
*htab
;
2073 /* STT_GNU_IFUNC symbol must go through PLT. */
2074 if (h
->type
== STT_GNU_IFUNC
)
2076 if (h
->plt
.refcount
<= 0)
2078 h
->plt
.offset
= (bfd_vma
) -1;
2084 /* If this is a function, put it in the procedure linkage table. We
2085 will fill in the contents of the procedure linkage table later,
2086 when we know the address of the .got section. */
2087 if (h
->type
== STT_FUNC
2090 if (h
->plt
.refcount
<= 0
2091 || SYMBOL_CALLS_LOCAL (info
, h
)
2092 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2093 && h
->root
.type
== bfd_link_hash_undefweak
))
2095 /* This case can occur if we saw a PLT32 reloc in an input
2096 file, but the symbol was never referred to by a dynamic
2097 object, or if all references were garbage collected. In
2098 such a case, we don't actually need to build a procedure
2099 linkage table, and we can just do a PC32 reloc instead. */
2100 h
->plt
.offset
= (bfd_vma
) -1;
2107 /* It's possible that we incorrectly decided a .plt reloc was
2108 needed for an R_386_PC32 reloc to a non-function sym in
2109 check_relocs. We can't decide accurately between function and
2110 non-function syms in check-relocs; Objects loaded later in
2111 the link may change h->type. So fix it now. */
2112 h
->plt
.offset
= (bfd_vma
) -1;
2114 /* If this is a weak symbol, and there is a real definition, the
2115 processor independent code will have arranged for us to see the
2116 real definition first, and we can just use the same value. */
2117 if (h
->u
.weakdef
!= NULL
)
2119 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2120 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2121 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2122 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2123 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2124 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2128 /* This is a reference to a symbol defined by a dynamic object which
2129 is not a function. */
2131 /* If we are creating a shared library, we must presume that the
2132 only references to the symbol are via the global offset table.
2133 For such cases we need not do anything here; the relocations will
2134 be handled correctly by relocate_section. */
2138 /* If there are no references to this symbol that do not use the
2139 GOT, we don't need to generate a copy reloc. */
2140 if (!h
->non_got_ref
)
2143 /* If -z nocopyreloc was given, we won't generate them either. */
2144 if (info
->nocopyreloc
)
2150 htab
= elf_i386_hash_table (info
);
2154 /* If there aren't any dynamic relocs in read-only sections, then
2155 we can keep the dynamic relocs and avoid the copy reloc. This
2156 doesn't work on VxWorks, where we can not have dynamic relocations
2157 (other than copy and jump slot relocations) in an executable. */
2158 if (ELIMINATE_COPY_RELOCS
2159 && !get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2161 struct elf_i386_link_hash_entry
* eh
;
2162 struct elf_dyn_relocs
*p
;
2164 eh
= (struct elf_i386_link_hash_entry
*) h
;
2165 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2167 s
= p
->sec
->output_section
;
2168 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2181 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2182 h
->root
.root
.string
);
2186 /* We must allocate the symbol in our .dynbss section, which will
2187 become part of the .bss section of the executable. There will be
2188 an entry for this symbol in the .dynsym section. The dynamic
2189 object will contain position independent code, so all references
2190 from the dynamic object to this symbol will go through the global
2191 offset table. The dynamic linker will use the .dynsym entry to
2192 determine the address it must put in the global offset table, so
2193 both the dynamic object and the regular object will refer to the
2194 same memory location for the variable. */
2196 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2197 copy the initial value out of the dynamic object and into the
2198 runtime process image. */
2199 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2201 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2207 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2210 /* Allocate space in .plt, .got and associated reloc sections for
2214 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2216 struct bfd_link_info
*info
;
2217 struct elf_i386_link_hash_table
*htab
;
2218 struct elf_i386_link_hash_entry
*eh
;
2219 struct elf_dyn_relocs
*p
;
2220 unsigned plt_entry_size
;
2222 if (h
->root
.type
== bfd_link_hash_indirect
)
2225 eh
= (struct elf_i386_link_hash_entry
*) h
;
2227 info
= (struct bfd_link_info
*) inf
;
2228 htab
= elf_i386_hash_table (info
);
2232 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2234 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2235 here if it is defined and referenced in a non-shared object. */
2236 if (h
->type
== STT_GNU_IFUNC
2238 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2240 else if (htab
->elf
.dynamic_sections_created
2241 && h
->plt
.refcount
> 0)
2243 /* Make sure this symbol is output as a dynamic symbol.
2244 Undefined weak syms won't yet be marked as dynamic. */
2245 if (h
->dynindx
== -1
2246 && !h
->forced_local
)
2248 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2253 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2255 asection
*s
= htab
->elf
.splt
;
2257 /* If this is the first .plt entry, make room for the special
2260 s
->size
+= plt_entry_size
;
2262 h
->plt
.offset
= s
->size
;
2264 /* If this symbol is not defined in a regular file, and we are
2265 not generating a shared library, then set the symbol to this
2266 location in the .plt. This is required to make function
2267 pointers compare as equal between the normal executable and
2268 the shared library. */
2272 h
->root
.u
.def
.section
= s
;
2273 h
->root
.u
.def
.value
= h
->plt
.offset
;
2276 /* Make room for this entry. */
2277 s
->size
+= plt_entry_size
;
2279 /* We also need to make an entry in the .got.plt section, which
2280 will be placed in the .got section by the linker script. */
2281 htab
->elf
.sgotplt
->size
+= 4;
2283 /* We also need to make an entry in the .rel.plt section. */
2284 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2285 htab
->next_tls_desc_index
++;
2287 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
2290 /* VxWorks has a second set of relocations for each PLT entry
2291 in executables. They go in a separate relocation section,
2292 which is processed by the kernel loader. */
2294 /* There are two relocations for the initial PLT entry: an
2295 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2296 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2298 if (h
->plt
.offset
== plt_entry_size
)
2299 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2301 /* There are two extra relocations for each subsequent PLT entry:
2302 an R_386_32 relocation for the GOT entry, and an R_386_32
2303 relocation for the PLT entry. */
2305 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2310 h
->plt
.offset
= (bfd_vma
) -1;
2316 h
->plt
.offset
= (bfd_vma
) -1;
2320 eh
->tlsdesc_got
= (bfd_vma
) -1;
2322 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2323 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2324 if (h
->got
.refcount
> 0
2327 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2328 h
->got
.offset
= (bfd_vma
) -1;
2329 else if (h
->got
.refcount
> 0)
2333 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2335 /* Make sure this symbol is output as a dynamic symbol.
2336 Undefined weak syms won't yet be marked as dynamic. */
2337 if (h
->dynindx
== -1
2338 && !h
->forced_local
)
2340 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2345 if (GOT_TLS_GDESC_P (tls_type
))
2347 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2348 - elf_i386_compute_jump_table_size (htab
);
2349 htab
->elf
.sgotplt
->size
+= 8;
2350 h
->got
.offset
= (bfd_vma
) -2;
2352 if (! GOT_TLS_GDESC_P (tls_type
)
2353 || GOT_TLS_GD_P (tls_type
))
2355 h
->got
.offset
= s
->size
;
2357 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2358 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2361 dyn
= htab
->elf
.dynamic_sections_created
;
2362 /* R_386_TLS_IE_32 needs one dynamic relocation,
2363 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2364 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2365 need two), R_386_TLS_GD needs one if local symbol and two if
2367 if (tls_type
== GOT_TLS_IE_BOTH
)
2368 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2369 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2370 || (tls_type
& GOT_TLS_IE
))
2371 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2372 else if (GOT_TLS_GD_P (tls_type
))
2373 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2374 else if (! GOT_TLS_GDESC_P (tls_type
)
2375 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2376 || h
->root
.type
!= bfd_link_hash_undefweak
)
2378 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2379 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2380 if (GOT_TLS_GDESC_P (tls_type
))
2381 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2384 h
->got
.offset
= (bfd_vma
) -1;
2386 if (eh
->dyn_relocs
== NULL
)
2389 /* In the shared -Bsymbolic case, discard space allocated for
2390 dynamic pc-relative relocs against symbols which turn out to be
2391 defined in regular objects. For the normal shared case, discard
2392 space for pc-relative relocs that have become local due to symbol
2393 visibility changes. */
2397 /* The only reloc that uses pc_count is R_386_PC32, which will
2398 appear on a call or on something like ".long foo - .". We
2399 want calls to protected symbols to resolve directly to the
2400 function rather than going via the plt. If people want
2401 function pointer comparisons to work as expected then they
2402 should avoid writing assembly like ".long foo - .". */
2403 if (SYMBOL_CALLS_LOCAL (info
, h
))
2405 struct elf_dyn_relocs
**pp
;
2407 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2409 p
->count
-= p
->pc_count
;
2418 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2420 struct elf_dyn_relocs
**pp
;
2421 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2423 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2430 /* Also discard relocs on undefined weak syms with non-default
2432 if (eh
->dyn_relocs
!= NULL
2433 && h
->root
.type
== bfd_link_hash_undefweak
)
2435 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2436 eh
->dyn_relocs
= NULL
;
2438 /* Make sure undefined weak symbols are output as a dynamic
2440 else if (h
->dynindx
== -1
2441 && !h
->forced_local
)
2443 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2448 else if (ELIMINATE_COPY_RELOCS
)
2450 /* For the non-shared case, discard space for relocs against
2451 symbols which turn out to need copy relocs or are not
2457 || (htab
->elf
.dynamic_sections_created
2458 && (h
->root
.type
== bfd_link_hash_undefweak
2459 || h
->root
.type
== bfd_link_hash_undefined
))))
2461 /* Make sure this symbol is output as a dynamic symbol.
2462 Undefined weak syms won't yet be marked as dynamic. */
2463 if (h
->dynindx
== -1
2464 && !h
->forced_local
)
2466 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2470 /* If that succeeded, we know we'll be keeping all the
2472 if (h
->dynindx
!= -1)
2476 eh
->dyn_relocs
= NULL
;
2481 /* Finally, allocate space. */
2482 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2486 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2488 BFD_ASSERT (sreloc
!= NULL
);
2489 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2495 /* Allocate space in .plt, .got and associated reloc sections for
2496 local dynamic relocs. */
2499 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2501 struct elf_link_hash_entry
*h
2502 = (struct elf_link_hash_entry
*) *slot
;
2504 if (h
->type
!= STT_GNU_IFUNC
2508 || h
->root
.type
!= bfd_link_hash_defined
)
2511 return elf_i386_allocate_dynrelocs (h
, inf
);
2514 /* Find any dynamic relocs that apply to read-only sections. */
2517 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2519 struct elf_i386_link_hash_entry
*eh
;
2520 struct elf_dyn_relocs
*p
;
2522 /* Skip local IFUNC symbols. */
2523 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2526 eh
= (struct elf_i386_link_hash_entry
*) h
;
2527 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2529 asection
*s
= p
->sec
->output_section
;
2531 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2533 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2535 info
->flags
|= DF_TEXTREL
;
2537 if (info
->warn_shared_textrel
&& info
->shared
)
2538 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2539 p
->sec
->owner
, h
->root
.root
.string
,
2542 /* Not an error, just cut short the traversal. */
2549 /* Set the sizes of the dynamic sections. */
2552 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2554 struct elf_i386_link_hash_table
*htab
;
2560 htab
= elf_i386_hash_table (info
);
2563 dynobj
= htab
->elf
.dynobj
;
2567 if (htab
->elf
.dynamic_sections_created
)
2569 /* Set the contents of the .interp section to the interpreter. */
2570 if (info
->executable
)
2572 s
= bfd_get_section_by_name (dynobj
, ".interp");
2575 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2576 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2580 /* Set up .got offsets for local syms, and space for local dynamic
2582 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2584 bfd_signed_vma
*local_got
;
2585 bfd_signed_vma
*end_local_got
;
2586 char *local_tls_type
;
2587 bfd_vma
*local_tlsdesc_gotent
;
2588 bfd_size_type locsymcount
;
2589 Elf_Internal_Shdr
*symtab_hdr
;
2592 if (! is_i386_elf (ibfd
))
2595 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2597 struct elf_dyn_relocs
*p
;
2599 for (p
= ((struct elf_dyn_relocs
*)
2600 elf_section_data (s
)->local_dynrel
);
2604 if (!bfd_is_abs_section (p
->sec
)
2605 && bfd_is_abs_section (p
->sec
->output_section
))
2607 /* Input section has been discarded, either because
2608 it is a copy of a linkonce section or due to
2609 linker script /DISCARD/, so we'll be discarding
2612 else if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2613 && strcmp (p
->sec
->output_section
->name
,
2616 /* Relocations in vxworks .tls_vars sections are
2617 handled specially by the loader. */
2619 else if (p
->count
!= 0)
2621 srel
= elf_section_data (p
->sec
)->sreloc
;
2622 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2623 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2624 && (info
->flags
& DF_TEXTREL
) == 0)
2626 info
->flags
|= DF_TEXTREL
;
2627 if (info
->warn_shared_textrel
&& info
->shared
)
2628 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2629 p
->sec
->owner
, p
->sec
);
2635 local_got
= elf_local_got_refcounts (ibfd
);
2639 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2640 locsymcount
= symtab_hdr
->sh_info
;
2641 end_local_got
= local_got
+ locsymcount
;
2642 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2643 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2645 srel
= htab
->elf
.srelgot
;
2646 for (; local_got
< end_local_got
;
2647 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2649 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2652 if (GOT_TLS_GDESC_P (*local_tls_type
))
2654 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2655 - elf_i386_compute_jump_table_size (htab
);
2656 htab
->elf
.sgotplt
->size
+= 8;
2657 *local_got
= (bfd_vma
) -2;
2659 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2660 || GOT_TLS_GD_P (*local_tls_type
))
2662 *local_got
= s
->size
;
2664 if (GOT_TLS_GD_P (*local_tls_type
)
2665 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2669 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2670 || (*local_tls_type
& GOT_TLS_IE
))
2672 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2673 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2674 else if (GOT_TLS_GD_P (*local_tls_type
)
2675 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2676 srel
->size
+= sizeof (Elf32_External_Rel
);
2677 if (GOT_TLS_GDESC_P (*local_tls_type
))
2678 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2682 *local_got
= (bfd_vma
) -1;
2686 if (htab
->tls_ldm_got
.refcount
> 0)
2688 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2690 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2691 htab
->elf
.sgot
->size
+= 8;
2692 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2695 htab
->tls_ldm_got
.offset
= -1;
2697 /* Allocate global sym .plt and .got entries, and space for global
2698 sym dynamic relocs. */
2699 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2701 /* Allocate .plt and .got entries, and space for local symbols. */
2702 htab_traverse (htab
->loc_hash_table
,
2703 elf_i386_allocate_local_dynrelocs
,
2706 /* For every jump slot reserved in the sgotplt, reloc_count is
2707 incremented. However, when we reserve space for TLS descriptors,
2708 it's not incremented, so in order to compute the space reserved
2709 for them, it suffices to multiply the reloc count by the jump
2711 if (htab
->elf
.srelplt
)
2712 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2714 if (htab
->elf
.sgotplt
)
2716 struct elf_link_hash_entry
*got
;
2717 got
= elf_link_hash_lookup (elf_hash_table (info
),
2718 "_GLOBAL_OFFSET_TABLE_",
2719 FALSE
, FALSE
, FALSE
);
2721 /* Don't allocate .got.plt section if there are no GOT nor PLT
2722 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2724 || !got
->ref_regular_nonweak
)
2725 && (htab
->elf
.sgotplt
->size
2726 == get_elf_backend_data (output_bfd
)->got_header_size
)
2727 && (htab
->elf
.splt
== NULL
2728 || htab
->elf
.splt
->size
== 0)
2729 && (htab
->elf
.sgot
== NULL
2730 || htab
->elf
.sgot
->size
== 0)
2731 && (htab
->elf
.iplt
== NULL
2732 || htab
->elf
.iplt
->size
== 0)
2733 && (htab
->elf
.igotplt
== NULL
2734 || htab
->elf
.igotplt
->size
== 0))
2735 htab
->elf
.sgotplt
->size
= 0;
2738 /* We now have determined the sizes of the various dynamic sections.
2739 Allocate memory for them. */
2741 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2743 bfd_boolean strip_section
= TRUE
;
2745 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2748 if (s
== htab
->elf
.splt
2749 || s
== htab
->elf
.sgot
2750 || s
== htab
->elf
.sgotplt
2751 || s
== htab
->elf
.iplt
2752 || s
== htab
->elf
.igotplt
2753 || s
== htab
->sdynbss
)
2755 /* Strip this section if we don't need it; see the
2757 /* We'd like to strip these sections if they aren't needed, but if
2758 we've exported dynamic symbols from them we must leave them.
2759 It's too late to tell BFD to get rid of the symbols. */
2761 if (htab
->elf
.hplt
!= NULL
)
2762 strip_section
= FALSE
;
2764 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2767 && s
!= htab
->elf
.srelplt
2768 && s
!= htab
->srelplt2
)
2771 /* We use the reloc_count field as a counter if we need
2772 to copy relocs into the output file. */
2777 /* It's not one of our sections, so don't allocate space. */
2783 /* If we don't need this section, strip it from the
2784 output file. This is mostly to handle .rel.bss and
2785 .rel.plt. We must create both sections in
2786 create_dynamic_sections, because they must be created
2787 before the linker maps input sections to output
2788 sections. The linker does that before
2789 adjust_dynamic_symbol is called, and it is that
2790 function which decides whether anything needs to go
2791 into these sections. */
2793 s
->flags
|= SEC_EXCLUDE
;
2797 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2800 /* Allocate memory for the section contents. We use bfd_zalloc
2801 here in case unused entries are not reclaimed before the
2802 section's contents are written out. This should not happen,
2803 but this way if it does, we get a R_386_NONE reloc instead
2805 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2806 if (s
->contents
== NULL
)
2810 if (htab
->plt_eh_frame
!= NULL
2811 && htab
->elf
.splt
!= NULL
2812 && htab
->elf
.splt
->size
!= 0
2813 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0)
2814 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2815 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2817 if (htab
->elf
.dynamic_sections_created
)
2819 /* Add some entries to the .dynamic section. We fill in the
2820 values later, in elf_i386_finish_dynamic_sections, but we
2821 must add the entries now so that we get the correct size for
2822 the .dynamic section. The DT_DEBUG entry is filled in by the
2823 dynamic linker and used by the debugger. */
2824 #define add_dynamic_entry(TAG, VAL) \
2825 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2827 if (info
->executable
)
2829 if (!add_dynamic_entry (DT_DEBUG
, 0))
2833 if (htab
->elf
.splt
->size
!= 0)
2835 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2836 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2837 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2838 || !add_dynamic_entry (DT_JMPREL
, 0))
2844 if (!add_dynamic_entry (DT_REL
, 0)
2845 || !add_dynamic_entry (DT_RELSZ
, 0)
2846 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2849 /* If any dynamic relocs apply to a read-only section,
2850 then we need a DT_TEXTREL entry. */
2851 if ((info
->flags
& DF_TEXTREL
) == 0)
2852 elf_link_hash_traverse (&htab
->elf
,
2853 elf_i386_readonly_dynrelocs
, info
);
2855 if ((info
->flags
& DF_TEXTREL
) != 0)
2857 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2861 if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2862 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
2865 #undef add_dynamic_entry
2871 elf_i386_always_size_sections (bfd
*output_bfd
,
2872 struct bfd_link_info
*info
)
2874 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2878 struct elf_link_hash_entry
*tlsbase
;
2880 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2881 "_TLS_MODULE_BASE_",
2882 FALSE
, FALSE
, FALSE
);
2884 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2886 struct elf_i386_link_hash_table
*htab
;
2887 struct bfd_link_hash_entry
*bh
= NULL
;
2888 const struct elf_backend_data
*bed
2889 = get_elf_backend_data (output_bfd
);
2891 htab
= elf_i386_hash_table (info
);
2895 if (!(_bfd_generic_link_add_one_symbol
2896 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2897 tls_sec
, 0, NULL
, FALSE
,
2898 bed
->collect
, &bh
)))
2901 htab
->tls_module_base
= bh
;
2903 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2904 tlsbase
->def_regular
= 1;
2905 tlsbase
->other
= STV_HIDDEN
;
2906 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2913 /* Set the correct type for an x86 ELF section. We do this by the
2914 section name, which is a hack, but ought to work. */
2917 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2918 Elf_Internal_Shdr
*hdr
,
2923 name
= bfd_get_section_name (abfd
, sec
);
2925 /* This is an ugly, but unfortunately necessary hack that is
2926 needed when producing EFI binaries on x86. It tells
2927 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2928 containing ELF relocation info. We need this hack in order to
2929 be able to generate ELF binaries that can be translated into
2930 EFI applications (which are essentially COFF objects). Those
2931 files contain a COFF ".reloc" section inside an ELFNN object,
2932 which would normally cause BFD to segfault because it would
2933 attempt to interpret this section as containing relocation
2934 entries for section "oc". With this hack enabled, ".reloc"
2935 will be treated as a normal data section, which will avoid the
2936 segfault. However, you won't be able to create an ELFNN binary
2937 with a section named "oc" that needs relocations, but that's
2938 the kind of ugly side-effects you get when detecting section
2939 types based on their names... In practice, this limitation is
2940 unlikely to bite. */
2941 if (strcmp (name
, ".reloc") == 0)
2942 hdr
->sh_type
= SHT_PROGBITS
;
2947 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2948 executables. Rather than setting it to the beginning of the TLS
2949 section, we have to set it to the end. This function may be called
2950 multiple times, it is idempotent. */
2953 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
2955 struct elf_i386_link_hash_table
*htab
;
2956 struct bfd_link_hash_entry
*base
;
2958 if (!info
->executable
)
2961 htab
= elf_i386_hash_table (info
);
2965 base
= htab
->tls_module_base
;
2969 base
->u
.def
.value
= htab
->elf
.tls_size
;
2972 /* Return the base VMA address which should be subtracted from real addresses
2973 when resolving @dtpoff relocation.
2974 This is PT_TLS segment p_vaddr. */
2977 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
2979 /* If tls_sec is NULL, we should have signalled an error already. */
2980 if (elf_hash_table (info
)->tls_sec
== NULL
)
2982 return elf_hash_table (info
)->tls_sec
->vma
;
2985 /* Return the relocation value for @tpoff relocation
2986 if STT_TLS virtual address is ADDRESS. */
2989 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2991 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2992 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2993 bfd_vma static_tls_size
;
2995 /* If tls_sec is NULL, we should have signalled an error already. */
2996 if (htab
->tls_sec
== NULL
)
2999 /* Consider special static TLS alignment requirements. */
3000 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3001 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3004 /* Relocate an i386 ELF section. */
3007 elf_i386_relocate_section (bfd
*output_bfd
,
3008 struct bfd_link_info
*info
,
3010 asection
*input_section
,
3012 Elf_Internal_Rela
*relocs
,
3013 Elf_Internal_Sym
*local_syms
,
3014 asection
**local_sections
)
3016 struct elf_i386_link_hash_table
*htab
;
3017 Elf_Internal_Shdr
*symtab_hdr
;
3018 struct elf_link_hash_entry
**sym_hashes
;
3019 bfd_vma
*local_got_offsets
;
3020 bfd_vma
*local_tlsdesc_gotents
;
3021 Elf_Internal_Rela
*rel
;
3022 Elf_Internal_Rela
*relend
;
3023 bfd_boolean is_vxworks_tls
;
3024 unsigned plt_entry_size
;
3026 BFD_ASSERT (is_i386_elf (input_bfd
));
3028 htab
= elf_i386_hash_table (info
);
3031 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3032 sym_hashes
= elf_sym_hashes (input_bfd
);
3033 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3034 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3035 /* We have to handle relocations in vxworks .tls_vars sections
3036 specially, because the dynamic loader is 'weird'. */
3037 is_vxworks_tls
= (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3039 && !strcmp (input_section
->output_section
->name
,
3042 elf_i386_set_tls_module_base (info
);
3044 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
3047 relend
= relocs
+ input_section
->reloc_count
;
3048 for (; rel
< relend
; rel
++)
3050 unsigned int r_type
;
3051 reloc_howto_type
*howto
;
3052 unsigned long r_symndx
;
3053 struct elf_link_hash_entry
*h
;
3054 Elf_Internal_Sym
*sym
;
3056 bfd_vma off
, offplt
;
3058 bfd_boolean unresolved_reloc
;
3059 bfd_reloc_status_type r
;
3063 r_type
= ELF32_R_TYPE (rel
->r_info
);
3064 if (r_type
== R_386_GNU_VTINHERIT
3065 || r_type
== R_386_GNU_VTENTRY
)
3068 if ((indx
= r_type
) >= R_386_standard
3069 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3070 >= R_386_ext
- R_386_standard
)
3071 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3072 >= R_386_irelative
- R_386_ext
))
3074 (*_bfd_error_handler
)
3075 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3076 input_bfd
, input_section
, r_type
);
3077 bfd_set_error (bfd_error_bad_value
);
3080 howto
= elf_howto_table
+ indx
;
3082 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3086 unresolved_reloc
= FALSE
;
3087 if (r_symndx
< symtab_hdr
->sh_info
)
3089 sym
= local_syms
+ r_symndx
;
3090 sec
= local_sections
[r_symndx
];
3091 relocation
= (sec
->output_section
->vma
3092 + sec
->output_offset
3095 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3096 && ((sec
->flags
& SEC_MERGE
) != 0
3097 || (info
->relocatable
3098 && sec
->output_offset
!= 0)))
3101 bfd_byte
*where
= contents
+ rel
->r_offset
;
3103 switch (howto
->size
)
3106 addend
= bfd_get_8 (input_bfd
, where
);
3107 if (howto
->pc_relative
)
3109 addend
= (addend
^ 0x80) - 0x80;
3114 addend
= bfd_get_16 (input_bfd
, where
);
3115 if (howto
->pc_relative
)
3117 addend
= (addend
^ 0x8000) - 0x8000;
3122 addend
= bfd_get_32 (input_bfd
, where
);
3123 if (howto
->pc_relative
)
3125 addend
= (addend
^ 0x80000000) - 0x80000000;
3133 if (info
->relocatable
)
3134 addend
+= sec
->output_offset
;
3137 asection
*msec
= sec
;
3138 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3140 addend
-= relocation
;
3141 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3144 switch (howto
->size
)
3147 /* FIXME: overflow checks. */
3148 if (howto
->pc_relative
)
3150 bfd_put_8 (input_bfd
, addend
, where
);
3153 if (howto
->pc_relative
)
3155 bfd_put_16 (input_bfd
, addend
, where
);
3158 if (howto
->pc_relative
)
3160 bfd_put_32 (input_bfd
, addend
, where
);
3164 else if (!info
->relocatable
3165 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3167 /* Relocate against local STT_GNU_IFUNC symbol. */
3168 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3173 /* Set STT_GNU_IFUNC symbol value. */
3174 h
->root
.u
.def
.value
= sym
->st_value
;
3175 h
->root
.u
.def
.section
= sec
;
3180 bfd_boolean warned ATTRIBUTE_UNUSED
;
3182 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3183 r_symndx
, symtab_hdr
, sym_hashes
,
3185 unresolved_reloc
, warned
);
3188 if (sec
!= NULL
&& elf_discarded_section (sec
))
3189 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3190 rel
, relend
, howto
, contents
);
3192 if (info
->relocatable
)
3195 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3196 it here if it is defined in a non-shared object. */
3198 && h
->type
== STT_GNU_IFUNC
3201 asection
*plt
, *gotplt
, *base_got
;
3205 if ((input_section
->flags
& SEC_ALLOC
) == 0
3206 || h
->plt
.offset
== (bfd_vma
) -1)
3209 /* STT_GNU_IFUNC symbol must go through PLT. */
3210 if (htab
->elf
.splt
!= NULL
)
3212 plt
= htab
->elf
.splt
;
3213 gotplt
= htab
->elf
.sgotplt
;
3217 plt
= htab
->elf
.iplt
;
3218 gotplt
= htab
->elf
.igotplt
;
3221 relocation
= (plt
->output_section
->vma
3222 + plt
->output_offset
+ h
->plt
.offset
);
3227 if (h
->root
.root
.string
)
3228 name
= h
->root
.root
.string
;
3230 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3232 (*_bfd_error_handler
)
3233 (_("%B: relocation %s against STT_GNU_IFUNC "
3234 "symbol `%s' isn't handled by %s"), input_bfd
,
3235 elf_howto_table
[r_type
].name
,
3236 name
, __FUNCTION__
);
3237 bfd_set_error (bfd_error_bad_value
);
3241 /* Generate dynamic relcoation only when there is a
3242 non-GOF reference in a shared object. */
3243 if (info
->shared
&& h
->non_got_ref
)
3245 Elf_Internal_Rela outrel
;
3250 /* Need a dynamic relocation to get the real function
3252 offset
= _bfd_elf_section_offset (output_bfd
,
3256 if (offset
== (bfd_vma
) -1
3257 || offset
== (bfd_vma
) -2)
3260 outrel
.r_offset
= (input_section
->output_section
->vma
3261 + input_section
->output_offset
3264 if (h
->dynindx
== -1
3266 || info
->executable
)
3268 /* This symbol is resolved locally. */
3269 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3270 bfd_put_32 (output_bfd
,
3271 (h
->root
.u
.def
.value
3272 + h
->root
.u
.def
.section
->output_section
->vma
3273 + h
->root
.u
.def
.section
->output_offset
),
3277 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3279 sreloc
= htab
->elf
.irelifunc
;
3280 loc
= sreloc
->contents
;
3281 loc
+= (sreloc
->reloc_count
++
3282 * sizeof (Elf32_External_Rel
));
3283 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3285 /* If this reloc is against an external symbol, we
3286 do not want to fiddle with the addend. Otherwise,
3287 we need to include the symbol value so that it
3288 becomes an addend for the dynamic reloc. For an
3289 internal symbol, we have updated addend. */
3298 base_got
= htab
->elf
.sgot
;
3299 off
= h
->got
.offset
;
3301 if (base_got
== NULL
)
3304 if (off
== (bfd_vma
) -1)
3306 /* We can't use h->got.offset here to save state, or
3307 even just remember the offset, as finish_dynamic_symbol
3308 would use that as offset into .got. */
3310 if (htab
->elf
.splt
!= NULL
)
3312 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3313 off
= (plt_index
+ 3) * 4;
3314 base_got
= htab
->elf
.sgotplt
;
3318 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3319 off
= plt_index
* 4;
3320 base_got
= htab
->elf
.igotplt
;
3323 if (h
->dynindx
== -1
3327 /* This references the local defitionion. We must
3328 initialize this entry in the global offset table.
3329 Since the offset must always be a multiple of 8,
3330 we use the least significant bit to record
3331 whether we have initialized it already.
3333 When doing a dynamic link, we create a .rela.got
3334 relocation entry to initialize the value. This
3335 is done in the finish_dynamic_symbol routine. */
3340 bfd_put_32 (output_bfd
, relocation
,
3341 base_got
->contents
+ off
);
3348 /* Adjust for static executables. */
3349 if (htab
->elf
.splt
== NULL
)
3350 relocation
+= gotplt
->output_offset
;
3354 relocation
= (base_got
->output_section
->vma
3355 + base_got
->output_offset
+ off
3356 - gotplt
->output_section
->vma
3357 - gotplt
->output_offset
);
3358 /* Adjust for static executables. */
3359 if (htab
->elf
.splt
== NULL
)
3360 relocation
+= gotplt
->output_offset
;
3366 relocation
-= (gotplt
->output_section
->vma
3367 + gotplt
->output_offset
);
3375 /* Relocation is to the entry for this symbol in the global
3377 if (htab
->elf
.sgot
== NULL
)
3384 off
= h
->got
.offset
;
3385 dyn
= htab
->elf
.dynamic_sections_created
;
3386 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3388 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3389 || (ELF_ST_VISIBILITY (h
->other
)
3390 && h
->root
.type
== bfd_link_hash_undefweak
))
3392 /* This is actually a static link, or it is a
3393 -Bsymbolic link and the symbol is defined
3394 locally, or the symbol was forced to be local
3395 because of a version file. We must initialize
3396 this entry in the global offset table. Since the
3397 offset must always be a multiple of 4, we use the
3398 least significant bit to record whether we have
3399 initialized it already.
3401 When doing a dynamic link, we create a .rel.got
3402 relocation entry to initialize the value. This
3403 is done in the finish_dynamic_symbol routine. */
3408 bfd_put_32 (output_bfd
, relocation
,
3409 htab
->elf
.sgot
->contents
+ off
);
3414 unresolved_reloc
= FALSE
;
3418 if (local_got_offsets
== NULL
)
3421 off
= local_got_offsets
[r_symndx
];
3423 /* The offset must always be a multiple of 4. We use
3424 the least significant bit to record whether we have
3425 already generated the necessary reloc. */
3430 bfd_put_32 (output_bfd
, relocation
,
3431 htab
->elf
.sgot
->contents
+ off
);
3436 Elf_Internal_Rela outrel
;
3439 s
= htab
->elf
.srelgot
;
3443 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3444 + htab
->elf
.sgot
->output_offset
3446 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3448 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3449 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3452 local_got_offsets
[r_symndx
] |= 1;
3456 if (off
>= (bfd_vma
) -2)
3459 relocation
= htab
->elf
.sgot
->output_section
->vma
3460 + htab
->elf
.sgot
->output_offset
+ off
3461 - htab
->elf
.sgotplt
->output_section
->vma
3462 - htab
->elf
.sgotplt
->output_offset
;
3466 /* Relocation is relative to the start of the global offset
3469 /* Check to make sure it isn't a protected function symbol
3470 for shared library since it may not be local when used
3471 as function address. We also need to make sure that a
3472 symbol is defined locally. */
3473 if (info
->shared
&& h
)
3475 if (!h
->def_regular
)
3479 switch (ELF_ST_VISIBILITY (h
->other
))
3482 v
= _("hidden symbol");
3485 v
= _("internal symbol");
3488 v
= _("protected symbol");
3495 (*_bfd_error_handler
)
3496 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3497 input_bfd
, v
, h
->root
.root
.string
);
3498 bfd_set_error (bfd_error_bad_value
);
3501 else if (!info
->executable
3502 && h
->type
== STT_FUNC
3503 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3505 (*_bfd_error_handler
)
3506 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3507 input_bfd
, h
->root
.root
.string
);
3508 bfd_set_error (bfd_error_bad_value
);
3513 /* Note that sgot is not involved in this
3514 calculation. We always want the start of .got.plt. If we
3515 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3516 permitted by the ABI, we might have to change this
3518 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3519 + htab
->elf
.sgotplt
->output_offset
;
3523 /* Use global offset table as symbol value. */
3524 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3525 + htab
->elf
.sgotplt
->output_offset
;
3526 unresolved_reloc
= FALSE
;
3530 /* Relocation is to the entry for this symbol in the
3531 procedure linkage table. */
3533 /* Resolve a PLT32 reloc against a local symbol directly,
3534 without using the procedure linkage table. */
3538 if (h
->plt
.offset
== (bfd_vma
) -1
3539 || htab
->elf
.splt
== NULL
)
3541 /* We didn't make a PLT entry for this symbol. This
3542 happens when statically linking PIC code, or when
3543 using -Bsymbolic. */
3547 relocation
= (htab
->elf
.splt
->output_section
->vma
3548 + htab
->elf
.splt
->output_offset
3550 unresolved_reloc
= FALSE
;
3555 if ((input_section
->flags
& SEC_ALLOC
) == 0
3561 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3562 || h
->root
.type
!= bfd_link_hash_undefweak
)
3563 && (r_type
!= R_386_PC32
3564 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3565 || (ELIMINATE_COPY_RELOCS
3572 || h
->root
.type
== bfd_link_hash_undefweak
3573 || h
->root
.type
== bfd_link_hash_undefined
)))
3575 Elf_Internal_Rela outrel
;
3577 bfd_boolean skip
, relocate
;
3580 /* When generating a shared object, these relocations
3581 are copied into the output file to be resolved at run
3588 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3590 if (outrel
.r_offset
== (bfd_vma
) -1)
3592 else if (outrel
.r_offset
== (bfd_vma
) -2)
3593 skip
= TRUE
, relocate
= TRUE
;
3594 outrel
.r_offset
+= (input_section
->output_section
->vma
3595 + input_section
->output_offset
);
3598 memset (&outrel
, 0, sizeof outrel
);
3601 && (r_type
== R_386_PC32
3603 || !SYMBOLIC_BIND (info
, h
)
3604 || !h
->def_regular
))
3605 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3608 /* This symbol is local, or marked to become local. */
3610 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3613 sreloc
= elf_section_data (input_section
)->sreloc
;
3615 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3617 r
= bfd_reloc_notsupported
;
3618 goto check_relocation_error
;
3621 loc
= sreloc
->contents
;
3622 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3624 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3626 /* If this reloc is against an external symbol, we do
3627 not want to fiddle with the addend. Otherwise, we
3628 need to include the symbol value so that it becomes
3629 an addend for the dynamic reloc. */
3636 if (!info
->executable
)
3638 Elf_Internal_Rela outrel
;
3642 outrel
.r_offset
= rel
->r_offset
3643 + input_section
->output_section
->vma
3644 + input_section
->output_offset
;
3645 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3646 sreloc
= elf_section_data (input_section
)->sreloc
;
3649 loc
= sreloc
->contents
;
3650 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3651 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3656 case R_386_TLS_GOTDESC
:
3657 case R_386_TLS_DESC_CALL
:
3658 case R_386_TLS_IE_32
:
3659 case R_386_TLS_GOTIE
:
3660 tls_type
= GOT_UNKNOWN
;
3661 if (h
== NULL
&& local_got_offsets
)
3662 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3664 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3665 if (tls_type
== GOT_TLS_IE
)
3666 tls_type
= GOT_TLS_IE_NEG
;
3668 if (! elf_i386_tls_transition (info
, input_bfd
,
3669 input_section
, contents
,
3670 symtab_hdr
, sym_hashes
,
3671 &r_type
, tls_type
, rel
,
3672 relend
, h
, r_symndx
))
3675 if (r_type
== R_386_TLS_LE_32
)
3677 BFD_ASSERT (! unresolved_reloc
);
3678 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3683 /* GD->LE transition. */
3684 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3687 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3689 movl %gs:0, %eax; subl $foo@tpoff, %eax
3690 (6 byte form of subl). */
3691 memcpy (contents
+ rel
->r_offset
- 3,
3692 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3693 roff
= rel
->r_offset
+ 5;
3697 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3699 movl %gs:0, %eax; subl $foo@tpoff, %eax
3700 (6 byte form of subl). */
3701 memcpy (contents
+ rel
->r_offset
- 2,
3702 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3703 roff
= rel
->r_offset
+ 6;
3705 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3707 /* Skip R_386_PC32/R_386_PLT32. */
3711 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3713 /* GDesc -> LE transition.
3714 It's originally something like:
3715 leal x@tlsdesc(%ebx), %eax
3719 Registers other than %eax may be set up here. */
3724 roff
= rel
->r_offset
;
3725 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3727 /* Now modify the instruction as appropriate. */
3728 /* aoliva FIXME: remove the above and xor the byte
3730 bfd_put_8 (output_bfd
, val
^ 0x86,
3731 contents
+ roff
- 1);
3732 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3736 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3738 /* GDesc -> LE transition.
3746 roff
= rel
->r_offset
;
3747 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3748 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3751 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
3755 /* IE->LE transition:
3756 Originally it can be one of:
3764 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3767 /* movl foo, %eax. */
3768 bfd_put_8 (output_bfd
, 0xb8,
3769 contents
+ rel
->r_offset
- 1);
3775 type
= bfd_get_8 (input_bfd
,
3776 contents
+ rel
->r_offset
- 2);
3781 bfd_put_8 (output_bfd
, 0xc7,
3782 contents
+ rel
->r_offset
- 2);
3783 bfd_put_8 (output_bfd
,
3784 0xc0 | ((val
>> 3) & 7),
3785 contents
+ rel
->r_offset
- 1);
3789 bfd_put_8 (output_bfd
, 0x81,
3790 contents
+ rel
->r_offset
- 2);
3791 bfd_put_8 (output_bfd
,
3792 0xc0 | ((val
>> 3) & 7),
3793 contents
+ rel
->r_offset
- 1);
3800 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3801 contents
+ rel
->r_offset
);
3806 unsigned int val
, type
;
3808 /* {IE_32,GOTIE}->LE transition:
3809 Originally it can be one of:
3810 subl foo(%reg1), %reg2
3811 movl foo(%reg1), %reg2
3812 addl foo(%reg1), %reg2
3815 movl $foo, %reg2 (6 byte form)
3816 addl $foo, %reg2. */
3817 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3818 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3822 bfd_put_8 (output_bfd
, 0xc7,
3823 contents
+ rel
->r_offset
- 2);
3824 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3825 contents
+ rel
->r_offset
- 1);
3827 else if (type
== 0x2b)
3830 bfd_put_8 (output_bfd
, 0x81,
3831 contents
+ rel
->r_offset
- 2);
3832 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
3833 contents
+ rel
->r_offset
- 1);
3835 else if (type
== 0x03)
3838 bfd_put_8 (output_bfd
, 0x81,
3839 contents
+ rel
->r_offset
- 2);
3840 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3841 contents
+ rel
->r_offset
- 1);
3845 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
3846 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
3847 contents
+ rel
->r_offset
);
3849 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3850 contents
+ rel
->r_offset
);
3855 if (htab
->elf
.sgot
== NULL
)
3860 off
= h
->got
.offset
;
3861 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
3865 if (local_got_offsets
== NULL
)
3868 off
= local_got_offsets
[r_symndx
];
3869 offplt
= local_tlsdesc_gotents
[r_symndx
];
3876 Elf_Internal_Rela outrel
;
3881 if (htab
->elf
.srelgot
== NULL
)
3884 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3886 if (GOT_TLS_GDESC_P (tls_type
))
3888 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
3889 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
3890 <= htab
->elf
.sgotplt
->size
);
3891 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3892 + htab
->elf
.sgotplt
->output_offset
3894 + htab
->sgotplt_jump_table_size
);
3895 sreloc
= htab
->elf
.srelplt
;
3896 loc
= sreloc
->contents
;
3897 loc
+= (htab
->next_tls_desc_index
++
3898 * sizeof (Elf32_External_Rel
));
3899 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3900 <= sreloc
->contents
+ sreloc
->size
);
3901 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3904 BFD_ASSERT (! unresolved_reloc
);
3905 bfd_put_32 (output_bfd
,
3906 relocation
- elf_i386_dtpoff_base (info
),
3907 htab
->elf
.sgotplt
->contents
+ offplt
3908 + htab
->sgotplt_jump_table_size
+ 4);
3912 bfd_put_32 (output_bfd
, 0,
3913 htab
->elf
.sgotplt
->contents
+ offplt
3914 + htab
->sgotplt_jump_table_size
+ 4);
3918 sreloc
= htab
->elf
.srelgot
;
3920 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3921 + htab
->elf
.sgot
->output_offset
+ off
);
3923 if (GOT_TLS_GD_P (tls_type
))
3924 dr_type
= R_386_TLS_DTPMOD32
;
3925 else if (GOT_TLS_GDESC_P (tls_type
))
3927 else if (tls_type
== GOT_TLS_IE_POS
)
3928 dr_type
= R_386_TLS_TPOFF
;
3930 dr_type
= R_386_TLS_TPOFF32
;
3932 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3933 bfd_put_32 (output_bfd
,
3934 relocation
- elf_i386_dtpoff_base (info
),
3935 htab
->elf
.sgot
->contents
+ off
);
3936 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3937 bfd_put_32 (output_bfd
,
3938 elf_i386_dtpoff_base (info
) - relocation
,
3939 htab
->elf
.sgot
->contents
+ off
);
3940 else if (dr_type
!= R_386_TLS_DESC
)
3941 bfd_put_32 (output_bfd
, 0,
3942 htab
->elf
.sgot
->contents
+ off
);
3943 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3945 loc
= sreloc
->contents
;
3946 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3947 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3948 <= sreloc
->contents
+ sreloc
->size
);
3949 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3951 if (GOT_TLS_GD_P (tls_type
))
3955 BFD_ASSERT (! unresolved_reloc
);
3956 bfd_put_32 (output_bfd
,
3957 relocation
- elf_i386_dtpoff_base (info
),
3958 htab
->elf
.sgot
->contents
+ off
+ 4);
3962 bfd_put_32 (output_bfd
, 0,
3963 htab
->elf
.sgot
->contents
+ off
+ 4);
3964 outrel
.r_info
= ELF32_R_INFO (indx
,
3965 R_386_TLS_DTPOFF32
);
3966 outrel
.r_offset
+= 4;
3967 sreloc
->reloc_count
++;
3968 loc
+= sizeof (Elf32_External_Rel
);
3969 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3970 <= sreloc
->contents
+ sreloc
->size
);
3971 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3974 else if (tls_type
== GOT_TLS_IE_BOTH
)
3976 bfd_put_32 (output_bfd
,
3978 ? relocation
- elf_i386_dtpoff_base (info
)
3980 htab
->elf
.sgot
->contents
+ off
+ 4);
3981 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3982 outrel
.r_offset
+= 4;
3983 sreloc
->reloc_count
++;
3984 loc
+= sizeof (Elf32_External_Rel
);
3985 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3992 local_got_offsets
[r_symndx
] |= 1;
3995 if (off
>= (bfd_vma
) -2
3996 && ! GOT_TLS_GDESC_P (tls_type
))
3998 if (r_type
== R_386_TLS_GOTDESC
3999 || r_type
== R_386_TLS_DESC_CALL
)
4001 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4002 unresolved_reloc
= FALSE
;
4004 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4006 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4007 + htab
->elf
.sgotplt
->output_offset
;
4008 relocation
= htab
->elf
.sgot
->output_section
->vma
4009 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4010 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4011 && tls_type
== GOT_TLS_IE_BOTH
)
4013 if (r_type
== R_386_TLS_IE
)
4014 relocation
+= g_o_t
;
4015 unresolved_reloc
= FALSE
;
4017 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4019 unsigned int val
, type
;
4022 /* GD->IE transition. */
4023 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4024 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4027 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
4029 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4031 roff
= rel
->r_offset
- 3;
4035 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
4037 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4038 roff
= rel
->r_offset
- 2;
4040 memcpy (contents
+ roff
,
4041 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4042 contents
[roff
+ 7] = 0x80 | (val
& 7);
4043 /* If foo is used only with foo@gotntpoff(%reg) and
4044 foo@indntpoff, but not with foo@gottpoff(%reg), change
4045 subl $foo@gottpoff(%reg), %eax
4047 addl $foo@gotntpoff(%reg), %eax. */
4048 if (tls_type
== GOT_TLS_IE_POS
)
4049 contents
[roff
+ 6] = 0x03;
4050 bfd_put_32 (output_bfd
,
4051 htab
->elf
.sgot
->output_section
->vma
4052 + htab
->elf
.sgot
->output_offset
+ off
4053 - htab
->elf
.sgotplt
->output_section
->vma
4054 - htab
->elf
.sgotplt
->output_offset
,
4055 contents
+ roff
+ 8);
4056 /* Skip R_386_PLT32. */
4060 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4062 /* GDesc -> IE transition.
4063 It's originally something like:
4064 leal x@tlsdesc(%ebx), %eax
4067 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4069 movl x@gottpoff(%ebx), %eax # before negl %eax
4071 Registers other than %eax may be set up here. */
4075 /* First, make sure it's a leal adding ebx to a 32-bit
4076 offset into any register, although it's probably
4077 almost always going to be eax. */
4078 roff
= rel
->r_offset
;
4080 /* Now modify the instruction as appropriate. */
4081 /* To turn a leal into a movl in the form we use it, it
4082 suffices to change the first byte from 0x8d to 0x8b.
4083 aoliva FIXME: should we decide to keep the leal, all
4084 we have to do is remove the statement below, and
4085 adjust the relaxation of R_386_TLS_DESC_CALL. */
4086 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4088 if (tls_type
== GOT_TLS_IE_BOTH
)
4091 bfd_put_32 (output_bfd
,
4092 htab
->elf
.sgot
->output_section
->vma
4093 + htab
->elf
.sgot
->output_offset
+ off
4094 - htab
->elf
.sgotplt
->output_section
->vma
4095 - htab
->elf
.sgotplt
->output_offset
,
4099 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4101 /* GDesc -> IE transition.
4109 depending on how we transformed the TLS_GOTDESC above.
4114 roff
= rel
->r_offset
;
4116 /* Now modify the instruction as appropriate. */
4117 if (tls_type
!= GOT_TLS_IE_NEG
)
4120 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4121 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4126 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4127 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4137 if (! elf_i386_tls_transition (info
, input_bfd
,
4138 input_section
, contents
,
4139 symtab_hdr
, sym_hashes
,
4140 &r_type
, GOT_UNKNOWN
, rel
,
4141 relend
, h
, r_symndx
))
4144 if (r_type
!= R_386_TLS_LDM
)
4146 /* LD->LE transition:
4147 leal foo(%reg), %eax; call ___tls_get_addr.
4149 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
4150 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4151 memcpy (contents
+ rel
->r_offset
- 2,
4152 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4153 /* Skip R_386_PC32/R_386_PLT32. */
4158 if (htab
->elf
.sgot
== NULL
)
4161 off
= htab
->tls_ldm_got
.offset
;
4166 Elf_Internal_Rela outrel
;
4169 if (htab
->elf
.srelgot
== NULL
)
4172 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4173 + htab
->elf
.sgot
->output_offset
+ off
);
4175 bfd_put_32 (output_bfd
, 0,
4176 htab
->elf
.sgot
->contents
+ off
);
4177 bfd_put_32 (output_bfd
, 0,
4178 htab
->elf
.sgot
->contents
+ off
+ 4);
4179 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4180 loc
= htab
->elf
.srelgot
->contents
;
4181 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4182 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4183 htab
->tls_ldm_got
.offset
|= 1;
4185 relocation
= htab
->elf
.sgot
->output_section
->vma
4186 + htab
->elf
.sgot
->output_offset
+ off
4187 - htab
->elf
.sgotplt
->output_section
->vma
4188 - htab
->elf
.sgotplt
->output_offset
;
4189 unresolved_reloc
= FALSE
;
4192 case R_386_TLS_LDO_32
:
4193 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4194 relocation
-= elf_i386_dtpoff_base (info
);
4196 /* When converting LDO to LE, we must negate. */
4197 relocation
= -elf_i386_tpoff (info
, relocation
);
4200 case R_386_TLS_LE_32
:
4202 if (!info
->executable
)
4204 Elf_Internal_Rela outrel
;
4208 outrel
.r_offset
= rel
->r_offset
4209 + input_section
->output_section
->vma
4210 + input_section
->output_offset
;
4211 if (h
!= NULL
&& h
->dynindx
!= -1)
4215 if (r_type
== R_386_TLS_LE_32
)
4216 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4218 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4219 sreloc
= elf_section_data (input_section
)->sreloc
;
4222 loc
= sreloc
->contents
;
4223 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4224 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4227 else if (r_type
== R_386_TLS_LE_32
)
4228 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4230 relocation
-= elf_i386_dtpoff_base (info
);
4232 else if (r_type
== R_386_TLS_LE_32
)
4233 relocation
= elf_i386_tpoff (info
, relocation
);
4235 relocation
= -elf_i386_tpoff (info
, relocation
);
4242 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4243 because such sections are not SEC_ALLOC and thus ld.so will
4244 not process them. */
4245 if (unresolved_reloc
4246 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4249 (*_bfd_error_handler
)
4250 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4253 (long) rel
->r_offset
,
4255 h
->root
.root
.string
);
4260 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4261 contents
, rel
->r_offset
,
4264 check_relocation_error
:
4265 if (r
!= bfd_reloc_ok
)
4270 name
= h
->root
.root
.string
;
4273 name
= bfd_elf_string_from_elf_section (input_bfd
,
4274 symtab_hdr
->sh_link
,
4279 name
= bfd_section_name (input_bfd
, sec
);
4282 if (r
== bfd_reloc_overflow
)
4284 if (! ((*info
->callbacks
->reloc_overflow
)
4285 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4286 (bfd_vma
) 0, input_bfd
, input_section
,
4292 (*_bfd_error_handler
)
4293 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4294 input_bfd
, input_section
,
4295 (long) rel
->r_offset
, name
, (int) r
);
4304 /* Finish up dynamic symbol handling. We set the contents of various
4305 dynamic sections here. */
4308 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4309 struct bfd_link_info
*info
,
4310 struct elf_link_hash_entry
*h
,
4311 Elf_Internal_Sym
*sym
)
4313 struct elf_i386_link_hash_table
*htab
;
4314 unsigned plt_entry_size
;
4315 const struct elf_i386_backend_data
*abed
;
4317 htab
= elf_i386_hash_table (info
);
4321 abed
= get_elf_i386_backend_data (output_bfd
);
4322 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
4324 if (h
->plt
.offset
!= (bfd_vma
) -1)
4328 Elf_Internal_Rela rel
;
4330 asection
*plt
, *gotplt
, *relplt
;
4332 /* When building a static executable, use .iplt, .igot.plt and
4333 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4334 if (htab
->elf
.splt
!= NULL
)
4336 plt
= htab
->elf
.splt
;
4337 gotplt
= htab
->elf
.sgotplt
;
4338 relplt
= htab
->elf
.srelplt
;
4342 plt
= htab
->elf
.iplt
;
4343 gotplt
= htab
->elf
.igotplt
;
4344 relplt
= htab
->elf
.irelplt
;
4347 /* This symbol has an entry in the procedure linkage table. Set
4350 if ((h
->dynindx
== -1
4351 && !((h
->forced_local
|| info
->executable
)
4353 && h
->type
== STT_GNU_IFUNC
))
4359 /* Get the index in the procedure linkage table which
4360 corresponds to this symbol. This is the index of this symbol
4361 in all the symbols for which we are making plt entries. The
4362 first entry in the procedure linkage table is reserved.
4364 Get the offset into the .got table of the entry that
4365 corresponds to this function. Each .got entry is 4 bytes.
4366 The first three are reserved.
4368 For static executables, we don't reserve anything. */
4370 if (plt
== htab
->elf
.splt
)
4372 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4373 got_offset
= (plt_index
+ 3) * 4;
4377 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4378 got_offset
= plt_index
* 4;
4381 /* Fill in the entry in the procedure linkage table. */
4384 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->plt_entry
,
4385 abed
->plt
->plt_entry_size
);
4386 bfd_put_32 (output_bfd
,
4387 (gotplt
->output_section
->vma
4388 + gotplt
->output_offset
4390 plt
->contents
+ h
->plt
.offset
4391 + abed
->plt
->plt_got_offset
);
4393 if (abed
->is_vxworks
)
4395 int s
, k
, reloc_index
;
4397 /* Create the R_386_32 relocation referencing the GOT
4398 for this PLT entry. */
4400 /* S: Current slot number (zero-based). */
4401 s
= ((h
->plt
.offset
- abed
->plt
->plt_entry_size
)
4402 / abed
->plt
->plt_entry_size
);
4403 /* K: Number of relocations for PLTResolve. */
4405 k
= PLTRESOLVE_RELOCS_SHLIB
;
4407 k
= PLTRESOLVE_RELOCS
;
4408 /* Skip the PLTresolve relocations, and the relocations for
4409 the other PLT slots. */
4410 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4411 loc
= (htab
->srelplt2
->contents
+ reloc_index
4412 * sizeof (Elf32_External_Rel
));
4414 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4415 + htab
->elf
.splt
->output_offset
4416 + h
->plt
.offset
+ 2),
4417 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4418 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4420 /* Create the R_386_32 relocation referencing the beginning of
4421 the PLT for this GOT entry. */
4422 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4423 + htab
->elf
.sgotplt
->output_offset
4425 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4426 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4427 loc
+ sizeof (Elf32_External_Rel
));
4432 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->pic_plt_entry
,
4433 abed
->plt
->plt_entry_size
);
4434 bfd_put_32 (output_bfd
, got_offset
,
4435 plt
->contents
+ h
->plt
.offset
4436 + abed
->plt
->plt_got_offset
);
4439 /* Don't fill PLT entry for static executables. */
4440 if (plt
== htab
->elf
.splt
)
4442 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4443 plt
->contents
+ h
->plt
.offset
4444 + abed
->plt
->plt_reloc_offset
);
4445 bfd_put_32 (output_bfd
, - (h
->plt
.offset
4446 + abed
->plt
->plt_plt_offset
+ 4),
4447 plt
->contents
+ h
->plt
.offset
4448 + abed
->plt
->plt_plt_offset
);
4451 /* Fill in the entry in the global offset table. */
4452 bfd_put_32 (output_bfd
,
4453 (plt
->output_section
->vma
4454 + plt
->output_offset
4456 + abed
->plt
->plt_lazy_offset
),
4457 gotplt
->contents
+ got_offset
);
4459 /* Fill in the entry in the .rel.plt section. */
4460 rel
.r_offset
= (gotplt
->output_section
->vma
4461 + gotplt
->output_offset
4463 if (h
->dynindx
== -1
4464 || ((info
->executable
4465 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4467 && h
->type
== STT_GNU_IFUNC
))
4469 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4470 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4471 in the .got.plt section. */
4472 bfd_put_32 (output_bfd
,
4473 (h
->root
.u
.def
.value
4474 + h
->root
.u
.def
.section
->output_section
->vma
4475 + h
->root
.u
.def
.section
->output_offset
),
4476 gotplt
->contents
+ got_offset
);
4477 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4480 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4481 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4482 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4484 if (!h
->def_regular
)
4486 /* Mark the symbol as undefined, rather than as defined in
4487 the .plt section. Leave the value if there were any
4488 relocations where pointer equality matters (this is a clue
4489 for the dynamic linker, to make function pointer
4490 comparisons work between an application and shared
4491 library), otherwise set it to zero. If a function is only
4492 called from a binary, there is no need to slow down
4493 shared libraries because of that. */
4494 sym
->st_shndx
= SHN_UNDEF
;
4495 if (!h
->pointer_equality_needed
)
4500 if (h
->got
.offset
!= (bfd_vma
) -1
4501 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4502 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4504 Elf_Internal_Rela rel
;
4507 /* This symbol has an entry in the global offset table. Set it
4510 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4513 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4514 + htab
->elf
.sgot
->output_offset
4515 + (h
->got
.offset
& ~(bfd_vma
) 1));
4517 /* If this is a static link, or it is a -Bsymbolic link and the
4518 symbol is defined locally or was forced to be local because
4519 of a version file, we just want to emit a RELATIVE reloc.
4520 The entry in the global offset table will already have been
4521 initialized in the relocate_section function. */
4523 && h
->type
== STT_GNU_IFUNC
)
4527 /* Generate R_386_GLOB_DAT. */
4534 if (!h
->pointer_equality_needed
)
4537 /* For non-shared object, we can't use .got.plt, which
4538 contains the real function addres if we need pointer
4539 equality. We load the GOT entry with the PLT entry. */
4540 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4541 bfd_put_32 (output_bfd
,
4542 (plt
->output_section
->vma
4543 + plt
->output_offset
+ h
->plt
.offset
),
4544 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4548 else if (info
->shared
4549 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4551 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4552 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4556 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4558 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4559 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4560 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4563 loc
= htab
->elf
.srelgot
->contents
;
4564 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4565 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4570 Elf_Internal_Rela rel
;
4573 /* This symbol needs a copy reloc. Set it up. */
4575 if (h
->dynindx
== -1
4576 || (h
->root
.type
!= bfd_link_hash_defined
4577 && h
->root
.type
!= bfd_link_hash_defweak
)
4578 || htab
->srelbss
== NULL
)
4581 rel
.r_offset
= (h
->root
.u
.def
.value
4582 + h
->root
.u
.def
.section
->output_section
->vma
4583 + h
->root
.u
.def
.section
->output_offset
);
4584 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4585 loc
= htab
->srelbss
->contents
;
4586 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
4587 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4590 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4591 be NULL for local symbols.
4593 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
4594 is relative to the ".got" section. */
4596 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4597 || (!abed
->is_vxworks
4598 && h
== htab
->elf
.hgot
)))
4599 sym
->st_shndx
= SHN_ABS
;
4604 /* Finish up local dynamic symbol handling. We set the contents of
4605 various dynamic sections here. */
4608 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4610 struct elf_link_hash_entry
*h
4611 = (struct elf_link_hash_entry
*) *slot
;
4612 struct bfd_link_info
*info
4613 = (struct bfd_link_info
*) inf
;
4615 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4619 /* Used to decide how to sort relocs in an optimal manner for the
4620 dynamic linker, before writing them out. */
4622 static enum elf_reloc_type_class
4623 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
4625 switch (ELF32_R_TYPE (rela
->r_info
))
4627 case R_386_RELATIVE
:
4628 return reloc_class_relative
;
4629 case R_386_JUMP_SLOT
:
4630 return reloc_class_plt
;
4632 return reloc_class_copy
;
4634 return reloc_class_normal
;
4638 /* Finish up the dynamic sections. */
4641 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4642 struct bfd_link_info
*info
)
4644 struct elf_i386_link_hash_table
*htab
;
4647 const struct elf_i386_backend_data
*abed
;
4649 htab
= elf_i386_hash_table (info
);
4653 dynobj
= htab
->elf
.dynobj
;
4654 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4655 abed
= get_elf_i386_backend_data (output_bfd
);
4657 if (htab
->elf
.dynamic_sections_created
)
4659 Elf32_External_Dyn
*dyncon
, *dynconend
;
4661 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4664 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4665 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4666 for (; dyncon
< dynconend
; dyncon
++)
4668 Elf_Internal_Dyn dyn
;
4671 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4676 if (abed
->is_vxworks
4677 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4682 s
= htab
->elf
.sgotplt
;
4683 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4687 s
= htab
->elf
.srelplt
;
4688 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4692 s
= htab
->elf
.srelplt
;
4693 dyn
.d_un
.d_val
= s
->size
;
4697 /* My reading of the SVR4 ABI indicates that the
4698 procedure linkage table relocs (DT_JMPREL) should be
4699 included in the overall relocs (DT_REL). This is
4700 what Solaris does. However, UnixWare can not handle
4701 that case. Therefore, we override the DT_RELSZ entry
4702 here to make it not include the JMPREL relocs. */
4703 s
= htab
->elf
.srelplt
;
4706 dyn
.d_un
.d_val
-= s
->size
;
4710 /* We may not be using the standard ELF linker script.
4711 If .rel.plt is the first .rel section, we adjust
4712 DT_REL to not include it. */
4713 s
= htab
->elf
.srelplt
;
4716 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4718 dyn
.d_un
.d_ptr
+= s
->size
;
4722 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4725 /* Fill in the first entry in the procedure linkage table. */
4726 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4730 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->pic_plt0_entry
,
4731 abed
->plt
->plt0_entry_size
);
4732 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
4733 abed
->plt0_pad_byte
,
4734 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
4738 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->plt0_entry
,
4739 abed
->plt
->plt0_entry_size
);
4740 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
4741 abed
->plt0_pad_byte
,
4742 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
4743 bfd_put_32 (output_bfd
,
4744 (htab
->elf
.sgotplt
->output_section
->vma
4745 + htab
->elf
.sgotplt
->output_offset
4747 htab
->elf
.splt
->contents
4748 + abed
->plt
->plt0_got1_offset
);
4749 bfd_put_32 (output_bfd
,
4750 (htab
->elf
.sgotplt
->output_section
->vma
4751 + htab
->elf
.sgotplt
->output_offset
4753 htab
->elf
.splt
->contents
4754 + abed
->plt
->plt0_got2_offset
);
4756 if (abed
->is_vxworks
)
4758 Elf_Internal_Rela rel
;
4760 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4761 On IA32 we use REL relocations so the addend goes in
4762 the PLT directly. */
4763 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4764 + htab
->elf
.splt
->output_offset
4765 + abed
->plt
->plt0_got1_offset
);
4766 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4767 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4768 htab
->srelplt2
->contents
);
4769 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
4770 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4771 + htab
->elf
.splt
->output_offset
4772 + abed
->plt
->plt0_got2_offset
);
4773 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4774 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4775 htab
->srelplt2
->contents
+
4776 sizeof (Elf32_External_Rel
));
4780 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4781 really seem like the right value. */
4782 elf_section_data (htab
->elf
.splt
->output_section
)
4783 ->this_hdr
.sh_entsize
= 4;
4785 /* Correct the .rel.plt.unloaded relocations. */
4786 if (abed
->is_vxworks
&& !info
->shared
)
4788 int num_plts
= (htab
->elf
.splt
->size
4789 / abed
->plt
->plt_entry_size
) - 1;
4792 p
= htab
->srelplt2
->contents
;
4794 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
4796 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
4798 for (; num_plts
; num_plts
--)
4800 Elf_Internal_Rela rel
;
4801 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4802 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4803 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4804 p
+= sizeof (Elf32_External_Rel
);
4806 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
4807 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4808 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
4809 p
+= sizeof (Elf32_External_Rel
);
4815 if (htab
->elf
.sgotplt
)
4817 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4819 (*_bfd_error_handler
)
4820 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4824 /* Fill in the first three entries in the global offset table. */
4825 if (htab
->elf
.sgotplt
->size
> 0)
4827 bfd_put_32 (output_bfd
,
4829 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
4830 htab
->elf
.sgotplt
->contents
);
4831 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
4832 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
4835 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
4838 /* Adjust .eh_frame for .plt section. */
4839 if (htab
->plt_eh_frame
!= NULL
)
4841 if (htab
->elf
.splt
!= NULL
4842 && htab
->elf
.splt
->size
!= 0
4843 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4844 && htab
->elf
.splt
->output_section
!= NULL
4845 && htab
->plt_eh_frame
->output_section
!= NULL
)
4847 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4848 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4849 + htab
->plt_eh_frame
->output_offset
4850 + PLT_FDE_START_OFFSET
;
4851 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4852 htab
->plt_eh_frame
->contents
4853 + PLT_FDE_START_OFFSET
);
4855 if (htab
->plt_eh_frame
->sec_info_type
4856 == ELF_INFO_TYPE_EH_FRAME
)
4858 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4860 htab
->plt_eh_frame
->contents
))
4865 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4866 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4868 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4869 htab_traverse (htab
->loc_hash_table
,
4870 elf_i386_finish_local_dynamic_symbol
,
4876 /* Return address for Ith PLT stub in section PLT, for relocation REL
4877 or (bfd_vma) -1 if it should not be included. */
4880 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
4881 const arelent
*rel ATTRIBUTE_UNUSED
)
4883 return plt
->vma
+ (i
+ 1) * GET_PLT_ENTRY_SIZE (plt
->owner
);
4886 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4889 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
4891 if (h
->plt
.offset
!= (bfd_vma
) -1
4893 && !h
->pointer_equality_needed
)
4896 return _bfd_elf_hash_symbol (h
);
4899 /* Hook called by the linker routine which adds symbols from an object
4903 elf_i386_add_symbol_hook (bfd
* abfd
,
4904 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4905 Elf_Internal_Sym
* sym
,
4906 const char ** namep ATTRIBUTE_UNUSED
,
4907 flagword
* flagsp ATTRIBUTE_UNUSED
,
4908 asection
** secp ATTRIBUTE_UNUSED
,
4909 bfd_vma
* valp ATTRIBUTE_UNUSED
)
4911 if ((abfd
->flags
& DYNAMIC
) == 0
4912 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4913 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4914 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4919 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4920 #define TARGET_LITTLE_NAME "elf32-i386"
4921 #define ELF_ARCH bfd_arch_i386
4922 #define ELF_TARGET_ID I386_ELF_DATA
4923 #define ELF_MACHINE_CODE EM_386
4924 #define ELF_MAXPAGESIZE 0x1000
4926 #define elf_backend_can_gc_sections 1
4927 #define elf_backend_can_refcount 1
4928 #define elf_backend_want_got_plt 1
4929 #define elf_backend_plt_readonly 1
4930 #define elf_backend_want_plt_sym 0
4931 #define elf_backend_got_header_size 12
4932 #define elf_backend_plt_alignment 4
4934 /* Support RELA for objdump of prelink objects. */
4935 #define elf_info_to_howto elf_i386_info_to_howto_rel
4936 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4938 #define bfd_elf32_mkobject elf_i386_mkobject
4940 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4941 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
4942 #define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
4943 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
4944 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
4946 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
4947 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4948 #define elf_backend_check_relocs elf_i386_check_relocs
4949 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
4950 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
4951 #define elf_backend_fake_sections elf_i386_fake_sections
4952 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4953 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4954 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4955 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
4956 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
4957 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
4958 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
4959 #define elf_backend_relocate_section elf_i386_relocate_section
4960 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
4961 #define elf_backend_always_size_sections elf_i386_always_size_sections
4962 #define elf_backend_omit_section_dynsym \
4963 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4964 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
4965 #define elf_backend_hash_symbol elf_i386_hash_symbol
4966 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4967 #undef elf_backend_post_process_headers
4968 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4970 #include "elf32-target.h"
4972 /* FreeBSD support. */
4974 #undef TARGET_LITTLE_SYM
4975 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4976 #undef TARGET_LITTLE_NAME
4977 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
4979 #define ELF_OSABI ELFOSABI_FREEBSD
4981 /* The kernel recognizes executables as valid only if they carry a
4982 "FreeBSD" label in the ELF header. So we put this label on all
4983 executables and (for simplicity) also all other object files. */
4986 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
4988 _bfd_elf_set_osabi (abfd
, info
);
4990 #ifdef OLD_FREEBSD_ABI_LABEL
4991 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4992 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
4996 #undef elf_backend_post_process_headers
4997 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
4999 #define elf32_bed elf32_i386_fbsd_bed
5001 #undef elf_backend_add_symbol_hook
5003 #include "elf32-target.h"
5007 #undef TARGET_LITTLE_SYM
5008 #define TARGET_LITTLE_SYM bfd_elf32_i386_sol2_vec
5009 #undef TARGET_LITTLE_NAME
5010 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
5012 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5013 objects won't be recognized. */
5017 #define elf32_bed elf32_i386_sol2_bed
5019 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5021 #undef elf_backend_static_tls_alignment
5022 #define elf_backend_static_tls_alignment 8
5024 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5026 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5028 #undef elf_backend_want_plt_sym
5029 #define elf_backend_want_plt_sym 1
5031 #include "elf32-target.h"
5033 /* Native Client support. */
5035 #undef TARGET_LITTLE_SYM
5036 #define TARGET_LITTLE_SYM bfd_elf32_i386_nacl_vec
5037 #undef TARGET_LITTLE_NAME
5038 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
5040 #define elf32_bed elf32_i386_nacl_bed
5042 #undef ELF_MAXPAGESIZE
5043 #define ELF_MAXPAGESIZE 0x10000
5045 /* Restore defaults. */
5047 #undef elf_backend_want_plt_sym
5048 #define elf_backend_want_plt_sym 0
5049 #undef elf_backend_post_process_headers
5050 #define elf_backend_post_process_headers _bfd_elf_set_osabi
5051 #undef elf_backend_static_tls_alignment
5053 /* NaCl uses substantially different PLT entries for the same effects. */
5055 #undef elf_backend_plt_alignment
5056 #define elf_backend_plt_alignment 5
5057 #define NACL_PLT_ENTRY_SIZE 64
5058 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5060 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
5062 0xff, 0x35, /* pushl contents of address */
5063 0, 0, 0, 0, /* replaced with address of .got + 4. */
5064 0x8b, 0x0d, /* movl contents of address, %ecx */
5065 0, 0, 0, 0, /* replaced with address of .got + 8. */
5066 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5067 0xff, 0xe1 /* jmp *%ecx */
5070 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5072 0x8b, 0x0d, /* movl contents of address, %ecx */
5073 0, 0, 0, 0, /* replaced with GOT slot address. */
5074 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5075 0xff, 0xe1, /* jmp *%ecx */
5077 /* Pad to the next 32-byte boundary with nop instructions. */
5079 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5080 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5082 /* Lazy GOT entries point here (32-byte aligned). */
5083 0x68, /* pushl immediate */
5084 0, 0, 0, 0, /* replaced with reloc offset. */
5085 0xe9, /* jmp relative */
5086 0, 0, 0, 0, /* replaced with offset to .plt. */
5088 /* Pad to the next 32-byte boundary with nop instructions. */
5089 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5090 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5094 static const bfd_byte
5095 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
5097 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5098 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5099 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5100 0xff, 0xe1, /* jmp *%ecx */
5104 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5106 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5107 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5108 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5109 0xff, 0xe1, /* jmp *%ecx */
5111 /* Pad to the next 32-byte boundary with nop instructions. */
5113 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5114 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5116 /* Lazy GOT entries point here (32-byte aligned). */
5117 0x68, /* pushl immediate */
5118 0, 0, 0, 0, /* replaced with offset into relocation table. */
5119 0xe9, /* jmp relative */
5120 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5122 /* Pad to the next 32-byte boundary with nop instructions. */
5123 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5124 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5128 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
5130 #if (PLT_CIE_LENGTH != 20 \
5131 || PLT_FDE_LENGTH != 36 \
5132 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5133 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5134 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5136 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5137 0, 0, 0, 0, /* CIE ID */
5138 1, /* CIE version */
5139 'z', 'R', 0, /* Augmentation string */
5140 1, /* Code alignment factor */
5141 0x7c, /* Data alignment factor: -4 */
5142 8, /* Return address column */
5143 1, /* Augmentation size */
5144 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5145 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5146 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5147 DW_CFA_nop
, DW_CFA_nop
,
5149 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5150 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
5151 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5152 0, 0, 0, 0, /* .plt size goes here */
5153 0, /* Augmentation size */
5154 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
5155 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5156 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
5157 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5158 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5159 13, /* Block length */
5160 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
5161 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
5162 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5163 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
5164 DW_CFA_nop
, DW_CFA_nop
5167 static const struct elf_i386_plt_layout elf_i386_nacl_plt
=
5169 elf_i386_nacl_plt0_entry
, /* plt0_entry */
5170 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
5171 2, /* plt0_got1_offset */
5172 8, /* plt0_got2_offset */
5173 elf_i386_nacl_plt_entry
, /* plt_entry */
5174 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5175 2, /* plt_got_offset */
5176 33, /* plt_reloc_offset */
5177 38, /* plt_plt_offset */
5178 32, /* plt_lazy_offset */
5179 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
5180 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
5181 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
5182 sizeof (elf_i386_nacl_eh_frame_plt
),/* eh_frame_plt_size */
5185 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
5187 &elf_i386_nacl_plt
, /* plt */
5188 0x90, /* plt0_pad_byte: nop insn */
5192 #undef elf_backend_arch_data
5193 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
5195 #include "elf32-target.h"
5197 /* VxWorks support. */
5199 #undef TARGET_LITTLE_SYM
5200 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
5201 #undef TARGET_LITTLE_NAME
5202 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
5204 #undef elf_backend_plt_alignment
5205 #define elf_backend_plt_alignment 4
5207 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
5209 &elf_i386_plt
, /* plt */
5210 0x90, /* plt0_pad_byte */
5214 #undef elf_backend_arch_data
5215 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
5217 #undef elf_backend_relocs_compatible
5218 #undef elf_backend_post_process_headers
5219 #undef elf_backend_add_symbol_hook
5220 #define elf_backend_add_symbol_hook \
5221 elf_vxworks_add_symbol_hook
5222 #undef elf_backend_link_output_symbol_hook
5223 #define elf_backend_link_output_symbol_hook \
5224 elf_vxworks_link_output_symbol_hook
5225 #undef elf_backend_emit_relocs
5226 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5227 #undef elf_backend_final_write_processing
5228 #define elf_backend_final_write_processing \
5229 elf_vxworks_final_write_processing
5230 #undef elf_backend_static_tls_alignment
5232 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5234 #undef elf_backend_want_plt_sym
5235 #define elf_backend_want_plt_sym 1
5238 #define elf32_bed elf32_i386_vxworks_bed
5240 #include "elf32-target.h"