1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright (C) 1993-2015 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
28 #include "bfd_stdint.h"
33 /* 386 uses REL relocations instead of RELA. */
38 static reloc_howto_type elf_howto_table
[]=
40 HOWTO(R_386_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
41 bfd_elf_generic_reloc
, "R_386_NONE",
42 TRUE
, 0x00000000, 0x00000000, FALSE
),
43 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
44 bfd_elf_generic_reloc
, "R_386_32",
45 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
46 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
47 bfd_elf_generic_reloc
, "R_386_PC32",
48 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
49 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
50 bfd_elf_generic_reloc
, "R_386_GOT32",
51 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
52 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
53 bfd_elf_generic_reloc
, "R_386_PLT32",
54 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
55 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
56 bfd_elf_generic_reloc
, "R_386_COPY",
57 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
58 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
59 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
60 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
61 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
63 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
64 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
65 bfd_elf_generic_reloc
, "R_386_RELATIVE",
66 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
67 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
68 bfd_elf_generic_reloc
, "R_386_GOTOFF",
69 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
70 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
71 bfd_elf_generic_reloc
, "R_386_GOTPC",
72 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
74 /* We have a gap in the reloc numbers here.
75 R_386_standard counts the number up to this point, and
76 R_386_ext_offset is the value to subtract from a reloc type of
77 R_386_16 thru R_386_PC8 to form an index into this table. */
78 #define R_386_standard (R_386_GOTPC + 1)
79 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
81 /* These relocs are a GNU extension. */
82 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
84 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
85 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
86 bfd_elf_generic_reloc
, "R_386_TLS_IE",
87 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
88 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
90 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
91 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
92 bfd_elf_generic_reloc
, "R_386_TLS_LE",
93 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
94 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_386_TLS_GD",
96 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
97 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
98 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
99 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
100 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
101 bfd_elf_generic_reloc
, "R_386_16",
102 TRUE
, 0xffff, 0xffff, FALSE
),
103 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
104 bfd_elf_generic_reloc
, "R_386_PC16",
105 TRUE
, 0xffff, 0xffff, TRUE
),
106 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
107 bfd_elf_generic_reloc
, "R_386_8",
108 TRUE
, 0xff, 0xff, FALSE
),
109 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
110 bfd_elf_generic_reloc
, "R_386_PC8",
111 TRUE
, 0xff, 0xff, TRUE
),
113 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
114 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
115 /* These are common with Solaris TLS implementation. */
116 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
118 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
119 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
121 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
122 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
123 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
124 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
125 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
126 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
127 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
128 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
129 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
130 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
131 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
132 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
133 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
135 bfd_elf_generic_reloc
, "R_386_SIZE32",
136 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
137 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
139 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
140 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
141 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
143 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
145 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
146 HOWTO(R_386_IRELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
147 bfd_elf_generic_reloc
, "R_386_IRELATIVE",
148 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
151 #define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
152 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
154 /* GNU extension to record C++ vtable hierarchy. */
155 HOWTO (R_386_GNU_VTINHERIT
, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 FALSE
, /* pc_relative */
161 complain_overflow_dont
, /* complain_on_overflow */
162 NULL
, /* special_function */
163 "R_386_GNU_VTINHERIT", /* name */
164 FALSE
, /* partial_inplace */
167 FALSE
), /* pcrel_offset */
169 /* GNU extension to record C++ vtable member usage. */
170 HOWTO (R_386_GNU_VTENTRY
, /* type */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
174 FALSE
, /* pc_relative */
176 complain_overflow_dont
, /* complain_on_overflow */
177 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
178 "R_386_GNU_VTENTRY", /* name */
179 FALSE
, /* partial_inplace */
182 FALSE
) /* pcrel_offset */
184 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
188 #ifdef DEBUG_GEN_RELOC
190 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
195 static reloc_howto_type
*
196 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
197 bfd_reloc_code_real_type code
)
202 TRACE ("BFD_RELOC_NONE");
203 return &elf_howto_table
[R_386_NONE
];
206 TRACE ("BFD_RELOC_32");
207 return &elf_howto_table
[R_386_32
];
210 TRACE ("BFD_RELOC_CTOR");
211 return &elf_howto_table
[R_386_32
];
213 case BFD_RELOC_32_PCREL
:
214 TRACE ("BFD_RELOC_PC32");
215 return &elf_howto_table
[R_386_PC32
];
217 case BFD_RELOC_386_GOT32
:
218 TRACE ("BFD_RELOC_386_GOT32");
219 return &elf_howto_table
[R_386_GOT32
];
221 case BFD_RELOC_386_PLT32
:
222 TRACE ("BFD_RELOC_386_PLT32");
223 return &elf_howto_table
[R_386_PLT32
];
225 case BFD_RELOC_386_COPY
:
226 TRACE ("BFD_RELOC_386_COPY");
227 return &elf_howto_table
[R_386_COPY
];
229 case BFD_RELOC_386_GLOB_DAT
:
230 TRACE ("BFD_RELOC_386_GLOB_DAT");
231 return &elf_howto_table
[R_386_GLOB_DAT
];
233 case BFD_RELOC_386_JUMP_SLOT
:
234 TRACE ("BFD_RELOC_386_JUMP_SLOT");
235 return &elf_howto_table
[R_386_JUMP_SLOT
];
237 case BFD_RELOC_386_RELATIVE
:
238 TRACE ("BFD_RELOC_386_RELATIVE");
239 return &elf_howto_table
[R_386_RELATIVE
];
241 case BFD_RELOC_386_GOTOFF
:
242 TRACE ("BFD_RELOC_386_GOTOFF");
243 return &elf_howto_table
[R_386_GOTOFF
];
245 case BFD_RELOC_386_GOTPC
:
246 TRACE ("BFD_RELOC_386_GOTPC");
247 return &elf_howto_table
[R_386_GOTPC
];
249 /* These relocs are a GNU extension. */
250 case BFD_RELOC_386_TLS_TPOFF
:
251 TRACE ("BFD_RELOC_386_TLS_TPOFF");
252 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
254 case BFD_RELOC_386_TLS_IE
:
255 TRACE ("BFD_RELOC_386_TLS_IE");
256 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
258 case BFD_RELOC_386_TLS_GOTIE
:
259 TRACE ("BFD_RELOC_386_TLS_GOTIE");
260 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
262 case BFD_RELOC_386_TLS_LE
:
263 TRACE ("BFD_RELOC_386_TLS_LE");
264 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
266 case BFD_RELOC_386_TLS_GD
:
267 TRACE ("BFD_RELOC_386_TLS_GD");
268 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
270 case BFD_RELOC_386_TLS_LDM
:
271 TRACE ("BFD_RELOC_386_TLS_LDM");
272 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
275 TRACE ("BFD_RELOC_16");
276 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
278 case BFD_RELOC_16_PCREL
:
279 TRACE ("BFD_RELOC_16_PCREL");
280 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
283 TRACE ("BFD_RELOC_8");
284 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
286 case BFD_RELOC_8_PCREL
:
287 TRACE ("BFD_RELOC_8_PCREL");
288 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
290 /* Common with Sun TLS implementation. */
291 case BFD_RELOC_386_TLS_LDO_32
:
292 TRACE ("BFD_RELOC_386_TLS_LDO_32");
293 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
295 case BFD_RELOC_386_TLS_IE_32
:
296 TRACE ("BFD_RELOC_386_TLS_IE_32");
297 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
299 case BFD_RELOC_386_TLS_LE_32
:
300 TRACE ("BFD_RELOC_386_TLS_LE_32");
301 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
303 case BFD_RELOC_386_TLS_DTPMOD32
:
304 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
305 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
307 case BFD_RELOC_386_TLS_DTPOFF32
:
308 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
309 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
311 case BFD_RELOC_386_TLS_TPOFF32
:
312 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
313 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
315 case BFD_RELOC_SIZE32
:
316 TRACE ("BFD_RELOC_SIZE32");
317 return &elf_howto_table
[R_386_SIZE32
- R_386_tls_offset
];
319 case BFD_RELOC_386_TLS_GOTDESC
:
320 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
321 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
323 case BFD_RELOC_386_TLS_DESC_CALL
:
324 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
325 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
327 case BFD_RELOC_386_TLS_DESC
:
328 TRACE ("BFD_RELOC_386_TLS_DESC");
329 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
331 case BFD_RELOC_386_IRELATIVE
:
332 TRACE ("BFD_RELOC_386_IRELATIVE");
333 return &elf_howto_table
[R_386_IRELATIVE
- R_386_tls_offset
];
335 case BFD_RELOC_VTABLE_INHERIT
:
336 TRACE ("BFD_RELOC_VTABLE_INHERIT");
337 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
339 case BFD_RELOC_VTABLE_ENTRY
:
340 TRACE ("BFD_RELOC_VTABLE_ENTRY");
341 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
351 static reloc_howto_type
*
352 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
357 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
358 if (elf_howto_table
[i
].name
!= NULL
359 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
360 return &elf_howto_table
[i
];
365 static reloc_howto_type
*
366 elf_i386_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
370 if ((indx
= r_type
) >= R_386_standard
371 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
372 >= R_386_ext
- R_386_standard
)
373 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
374 >= R_386_irelative
- R_386_ext
)
375 && ((indx
= r_type
- R_386_vt_offset
) - R_386_irelative
376 >= R_386_vt
- R_386_irelative
))
378 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
382 /* PR 17512: file: 0f67f69d. */
383 if (elf_howto_table
[indx
].type
!= r_type
)
385 return &elf_howto_table
[indx
];
389 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
391 Elf_Internal_Rela
*dst
)
393 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
394 cache_ptr
->howto
= elf_i386_rtype_to_howto (abfd
, r_type
);
397 /* Return whether a symbol name implies a local label. The UnixWare
398 2.1 cc generates temporary symbols that start with .X, so we
399 recognize them here. FIXME: do other SVR4 compilers also use .X?.
400 If so, we should move the .X recognition into
401 _bfd_elf_is_local_label_name. */
404 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
406 if (name
[0] == '.' && name
[1] == 'X')
409 return _bfd_elf_is_local_label_name (abfd
, name
);
412 /* Support for core dump NOTE sections. */
415 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
420 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
422 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
428 elf_tdata (abfd
)->core
->signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
431 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
435 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
439 switch (note
->descsz
)
444 case 144: /* Linux/i386 */
446 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
449 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
459 /* Make a ".reg/999" section. */
460 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
461 size
, note
->descpos
+ offset
);
465 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
467 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
469 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
474 elf_tdata (abfd
)->core
->program
475 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
476 elf_tdata (abfd
)->core
->command
477 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
481 switch (note
->descsz
)
486 case 124: /* Linux/i386 elf_prpsinfo. */
487 elf_tdata (abfd
)->core
->pid
488 = bfd_get_32 (abfd
, note
->descdata
+ 12);
489 elf_tdata (abfd
)->core
->program
490 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
491 elf_tdata (abfd
)->core
->command
492 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
496 /* Note that for some reason, a spurious space is tacked
497 onto the end of the args in some (at least one anyway)
498 implementations, so strip it off if it exists. */
500 char *command
= elf_tdata (abfd
)->core
->command
;
501 int n
= strlen (command
);
503 if (0 < n
&& command
[n
- 1] == ' ')
504 command
[n
- 1] = '\0';
510 /* Functions for the i386 ELF linker.
512 In order to gain some understanding of code in this file without
513 knowing all the intricate details of the linker, note the
516 Functions named elf_i386_* are called by external routines, other
517 functions are only called locally. elf_i386_* functions appear
518 in this file more or less in the order in which they are called
519 from external routines. eg. elf_i386_check_relocs is called
520 early in the link process, elf_i386_finish_dynamic_sections is
521 one of the last functions. */
524 /* The name of the dynamic interpreter. This is put in the .interp
527 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
529 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
530 copying dynamic variables from a shared lib into an app's dynbss
531 section, and instead use a dynamic relocation to point into the
533 #define ELIMINATE_COPY_RELOCS 1
535 /* The size in bytes of an entry in the procedure linkage table. */
537 #define PLT_ENTRY_SIZE 16
539 /* The first entry in an absolute procedure linkage table looks like
540 this. See the SVR4 ABI i386 supplement to see how this works.
541 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
543 static const bfd_byte elf_i386_plt0_entry
[12] =
545 0xff, 0x35, /* pushl contents of address */
546 0, 0, 0, 0, /* replaced with address of .got + 4. */
547 0xff, 0x25, /* jmp indirect */
548 0, 0, 0, 0 /* replaced with address of .got + 8. */
551 /* Subsequent entries in an absolute procedure linkage table look like
554 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
556 0xff, 0x25, /* jmp indirect */
557 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
558 0x68, /* pushl immediate */
559 0, 0, 0, 0, /* replaced with offset into relocation table. */
560 0xe9, /* jmp relative */
561 0, 0, 0, 0 /* replaced with offset to start of .plt. */
564 /* The first entry in a PIC procedure linkage table look like this.
565 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
567 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
569 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
570 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
573 /* Subsequent entries in a PIC procedure linkage table look like this. */
575 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
577 0xff, 0xa3, /* jmp *offset(%ebx) */
578 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
579 0x68, /* pushl immediate */
580 0, 0, 0, 0, /* replaced with offset into relocation table. */
581 0xe9, /* jmp relative */
582 0, 0, 0, 0 /* replaced with offset to start of .plt. */
585 /* Entries in the GOT procedure linkage table look like this. */
587 static const bfd_byte elf_i386_got_plt_entry
[8] =
589 0xff, 0x25, /* jmp indirect */
590 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
591 0x66, 0x90 /* xchg %ax,%ax */
594 /* Entries in the PIC GOT procedure linkage table look like this. */
596 static const bfd_byte elf_i386_pic_got_plt_entry
[8] =
598 0xff, 0xa3, /* jmp *offset(%ebx) */
599 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
600 0x66, 0x90 /* xchg %ax,%ax */
603 /* .eh_frame covering the .plt section. */
605 static const bfd_byte elf_i386_eh_frame_plt
[] =
607 #define PLT_CIE_LENGTH 20
608 #define PLT_FDE_LENGTH 36
609 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
610 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
611 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
612 0, 0, 0, 0, /* CIE ID */
614 'z', 'R', 0, /* Augmentation string */
615 1, /* Code alignment factor */
616 0x7c, /* Data alignment factor */
617 8, /* Return address column */
618 1, /* Augmentation size */
619 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
620 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
621 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
622 DW_CFA_nop
, DW_CFA_nop
,
624 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
625 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
626 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
627 0, 0, 0, 0, /* .plt size goes here */
628 0, /* Augmentation size */
629 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
630 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
631 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
632 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
633 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
634 11, /* Block length */
635 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
636 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
637 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
638 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
639 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
642 struct elf_i386_plt_layout
644 /* The first entry in an absolute procedure linkage table looks like this. */
645 const bfd_byte
*plt0_entry
;
646 unsigned int plt0_entry_size
;
648 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
649 unsigned int plt0_got1_offset
;
650 unsigned int plt0_got2_offset
;
652 /* Later entries in an absolute procedure linkage table look like this. */
653 const bfd_byte
*plt_entry
;
654 unsigned int plt_entry_size
;
656 /* Offsets into plt_entry that are to be replaced with... */
657 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
658 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
659 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
661 /* Offset into plt_entry where the initial value of the GOT entry points. */
662 unsigned int plt_lazy_offset
;
664 /* The first entry in a PIC procedure linkage table looks like this. */
665 const bfd_byte
*pic_plt0_entry
;
667 /* Subsequent entries in a PIC procedure linkage table look like this. */
668 const bfd_byte
*pic_plt_entry
;
670 /* .eh_frame covering the .plt section. */
671 const bfd_byte
*eh_frame_plt
;
672 unsigned int eh_frame_plt_size
;
675 #define GET_PLT_ENTRY_SIZE(abfd) \
676 get_elf_i386_backend_data (abfd)->plt->plt_entry_size
678 /* These are the standard parameters. */
679 static const struct elf_i386_plt_layout elf_i386_plt
=
681 elf_i386_plt0_entry
, /* plt0_entry */
682 sizeof (elf_i386_plt0_entry
), /* plt0_entry_size */
683 2, /* plt0_got1_offset */
684 8, /* plt0_got2_offset */
685 elf_i386_plt_entry
, /* plt_entry */
686 PLT_ENTRY_SIZE
, /* plt_entry_size */
687 2, /* plt_got_offset */
688 7, /* plt_reloc_offset */
689 12, /* plt_plt_offset */
690 6, /* plt_lazy_offset */
691 elf_i386_pic_plt0_entry
, /* pic_plt0_entry */
692 elf_i386_pic_plt_entry
, /* pic_plt_entry */
693 elf_i386_eh_frame_plt
, /* eh_frame_plt */
694 sizeof (elf_i386_eh_frame_plt
), /* eh_frame_plt_size */
698 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
699 for the PLTResolve stub and then for each PLT entry. */
700 #define PLTRESOLVE_RELOCS_SHLIB 0
701 #define PLTRESOLVE_RELOCS 2
702 #define PLT_NON_JUMP_SLOT_RELOCS 2
704 /* Architecture-specific backend data for i386. */
706 struct elf_i386_backend_data
708 /* Parameters describing PLT generation. */
709 const struct elf_i386_plt_layout
*plt
;
711 /* Value used to fill the unused bytes of the first PLT entry. */
712 bfd_byte plt0_pad_byte
;
714 /* True if the target system is VxWorks. */
718 #define get_elf_i386_backend_data(abfd) \
719 ((const struct elf_i386_backend_data *) \
720 get_elf_backend_data (abfd)->arch_data)
722 /* These are the standard parameters. */
723 static const struct elf_i386_backend_data elf_i386_arch_bed
=
725 &elf_i386_plt
, /* plt */
726 0, /* plt0_pad_byte */
730 #define elf_backend_arch_data &elf_i386_arch_bed
732 /* i386 ELF linker hash entry. */
734 struct elf_i386_link_hash_entry
736 struct elf_link_hash_entry elf
;
738 /* Track dynamic relocs copied for this symbol. */
739 struct elf_dyn_relocs
*dyn_relocs
;
741 #define GOT_UNKNOWN 0
745 #define GOT_TLS_IE_POS 5
746 #define GOT_TLS_IE_NEG 6
747 #define GOT_TLS_IE_BOTH 7
748 #define GOT_TLS_GDESC 8
749 #define GOT_TLS_GD_BOTH_P(type) \
750 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
751 #define GOT_TLS_GD_P(type) \
752 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
753 #define GOT_TLS_GDESC_P(type) \
754 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
755 #define GOT_TLS_GD_ANY_P(type) \
756 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
757 unsigned char tls_type
;
759 /* Symbol is referenced by R_386_GOTOFF relocation. */
760 unsigned int gotoff_ref
: 1;
762 /* Information about the GOT PLT entry. Filled when there are both
763 GOT and PLT relocations against the same function. */
764 union gotplt_union plt_got
;
766 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
767 starting at the end of the jump table. */
771 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
773 struct elf_i386_obj_tdata
775 struct elf_obj_tdata root
;
777 /* tls_type for each local got entry. */
778 char *local_got_tls_type
;
780 /* GOTPLT entries for TLS descriptors. */
781 bfd_vma
*local_tlsdesc_gotent
;
784 #define elf_i386_tdata(abfd) \
785 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
787 #define elf_i386_local_got_tls_type(abfd) \
788 (elf_i386_tdata (abfd)->local_got_tls_type)
790 #define elf_i386_local_tlsdesc_gotent(abfd) \
791 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
793 #define is_i386_elf(bfd) \
794 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
795 && elf_tdata (bfd) != NULL \
796 && elf_object_id (bfd) == I386_ELF_DATA)
799 elf_i386_mkobject (bfd
*abfd
)
801 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_i386_obj_tdata
),
805 /* i386 ELF linker hash table. */
807 struct elf_i386_link_hash_table
809 struct elf_link_hash_table elf
;
811 /* Short-cuts to get to dynamic linker sections. */
814 asection
*plt_eh_frame
;
819 bfd_signed_vma refcount
;
823 /* The amount of space used by the reserved portion of the sgotplt
824 section, plus whatever space is used by the jump slots. */
825 bfd_vma sgotplt_jump_table_size
;
827 /* Small local sym cache. */
828 struct sym_cache sym_cache
;
830 /* _TLS_MODULE_BASE_ symbol. */
831 struct bfd_link_hash_entry
*tls_module_base
;
833 /* Used by local STT_GNU_IFUNC symbols. */
834 htab_t loc_hash_table
;
835 void * loc_hash_memory
;
837 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
840 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
841 bfd_vma next_tls_desc_index
;
843 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
844 bfd_vma next_jump_slot_index
;
846 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
847 bfd_vma next_irelative_index
;
850 /* Get the i386 ELF linker hash table from a link_info structure. */
852 #define elf_i386_hash_table(p) \
853 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
854 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
856 #define elf_i386_compute_jump_table_size(htab) \
857 ((htab)->elf.srelplt->reloc_count * 4)
859 /* Create an entry in an i386 ELF linker hash table. */
861 static struct bfd_hash_entry
*
862 elf_i386_link_hash_newfunc (struct bfd_hash_entry
*entry
,
863 struct bfd_hash_table
*table
,
866 /* Allocate the structure if it has not already been allocated by a
870 entry
= (struct bfd_hash_entry
*)
871 bfd_hash_allocate (table
, sizeof (struct elf_i386_link_hash_entry
));
876 /* Call the allocation method of the superclass. */
877 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
880 struct elf_i386_link_hash_entry
*eh
;
882 eh
= (struct elf_i386_link_hash_entry
*) entry
;
883 eh
->dyn_relocs
= NULL
;
884 eh
->tls_type
= GOT_UNKNOWN
;
886 eh
->plt_got
.offset
= (bfd_vma
) -1;
887 eh
->tlsdesc_got
= (bfd_vma
) -1;
893 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
894 for local symbol so that we can handle local STT_GNU_IFUNC symbols
895 as global symbol. We reuse indx and dynstr_index for local symbol
896 hash since they aren't used by global symbols in this backend. */
899 elf_i386_local_htab_hash (const void *ptr
)
901 struct elf_link_hash_entry
*h
902 = (struct elf_link_hash_entry
*) ptr
;
903 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
906 /* Compare local hash entries. */
909 elf_i386_local_htab_eq (const void *ptr1
, const void *ptr2
)
911 struct elf_link_hash_entry
*h1
912 = (struct elf_link_hash_entry
*) ptr1
;
913 struct elf_link_hash_entry
*h2
914 = (struct elf_link_hash_entry
*) ptr2
;
916 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
919 /* Find and/or create a hash entry for local symbol. */
921 static struct elf_link_hash_entry
*
922 elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table
*htab
,
923 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
926 struct elf_i386_link_hash_entry e
, *ret
;
927 asection
*sec
= abfd
->sections
;
928 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
929 ELF32_R_SYM (rel
->r_info
));
932 e
.elf
.indx
= sec
->id
;
933 e
.elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
934 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
935 create
? INSERT
: NO_INSERT
);
942 ret
= (struct elf_i386_link_hash_entry
*) *slot
;
946 ret
= (struct elf_i386_link_hash_entry
*)
947 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
948 sizeof (struct elf_i386_link_hash_entry
));
951 memset (ret
, 0, sizeof (*ret
));
952 ret
->elf
.indx
= sec
->id
;
953 ret
->elf
.dynstr_index
= ELF32_R_SYM (rel
->r_info
);
954 ret
->elf
.dynindx
= -1;
955 ret
->plt_got
.offset
= (bfd_vma
) -1;
961 /* Destroy an i386 ELF linker hash table. */
964 elf_i386_link_hash_table_free (bfd
*obfd
)
966 struct elf_i386_link_hash_table
*htab
967 = (struct elf_i386_link_hash_table
*) obfd
->link
.hash
;
969 if (htab
->loc_hash_table
)
970 htab_delete (htab
->loc_hash_table
);
971 if (htab
->loc_hash_memory
)
972 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
973 _bfd_elf_link_hash_table_free (obfd
);
976 /* Create an i386 ELF linker hash table. */
978 static struct bfd_link_hash_table
*
979 elf_i386_link_hash_table_create (bfd
*abfd
)
981 struct elf_i386_link_hash_table
*ret
;
982 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
984 ret
= (struct elf_i386_link_hash_table
*) bfd_zmalloc (amt
);
988 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
989 elf_i386_link_hash_newfunc
,
990 sizeof (struct elf_i386_link_hash_entry
),
997 ret
->loc_hash_table
= htab_try_create (1024,
998 elf_i386_local_htab_hash
,
999 elf_i386_local_htab_eq
,
1001 ret
->loc_hash_memory
= objalloc_create ();
1002 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1004 elf_i386_link_hash_table_free (abfd
);
1007 ret
->elf
.root
.hash_table_free
= elf_i386_link_hash_table_free
;
1009 return &ret
->elf
.root
;
1012 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1013 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1017 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1019 struct elf_i386_link_hash_table
*htab
;
1021 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1024 htab
= elf_i386_hash_table (info
);
1028 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
1032 if (info
->executable
)
1034 /* Always allow copy relocs for building executables. */
1035 asection
*s
= bfd_get_linker_section (dynobj
, ".rel.bss");
1038 const struct elf_backend_data
*bed
= get_elf_backend_data (dynobj
);
1039 s
= bfd_make_section_anyway_with_flags (dynobj
,
1041 (bed
->dynamic_sec_flags
1044 || ! bfd_set_section_alignment (dynobj
, s
,
1045 bed
->s
->log_file_align
))
1051 if (get_elf_i386_backend_data (dynobj
)->is_vxworks
1052 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
1056 if (!info
->no_ld_generated_unwind_info
1057 && htab
->plt_eh_frame
== NULL
1058 && htab
->elf
.splt
!= NULL
)
1060 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1061 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1062 | SEC_LINKER_CREATED
);
1064 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1065 if (htab
->plt_eh_frame
== NULL
1066 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 2))
1073 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1076 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
1077 struct elf_link_hash_entry
*dir
,
1078 struct elf_link_hash_entry
*ind
)
1080 struct elf_i386_link_hash_entry
*edir
, *eind
;
1082 edir
= (struct elf_i386_link_hash_entry
*) dir
;
1083 eind
= (struct elf_i386_link_hash_entry
*) ind
;
1085 if (eind
->dyn_relocs
!= NULL
)
1087 if (edir
->dyn_relocs
!= NULL
)
1089 struct elf_dyn_relocs
**pp
;
1090 struct elf_dyn_relocs
*p
;
1092 /* Add reloc counts against the indirect sym to the direct sym
1093 list. Merge any entries against the same section. */
1094 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1096 struct elf_dyn_relocs
*q
;
1098 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1099 if (q
->sec
== p
->sec
)
1101 q
->pc_count
+= p
->pc_count
;
1102 q
->count
+= p
->count
;
1109 *pp
= edir
->dyn_relocs
;
1112 edir
->dyn_relocs
= eind
->dyn_relocs
;
1113 eind
->dyn_relocs
= NULL
;
1116 if (ind
->root
.type
== bfd_link_hash_indirect
1117 && dir
->got
.refcount
<= 0)
1119 edir
->tls_type
= eind
->tls_type
;
1120 eind
->tls_type
= GOT_UNKNOWN
;
1123 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1124 generate a R_386_COPY reloc. */
1125 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1127 if (ELIMINATE_COPY_RELOCS
1128 && ind
->root
.type
!= bfd_link_hash_indirect
1129 && dir
->dynamic_adjusted
)
1131 /* If called to transfer flags for a weakdef during processing
1132 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1133 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1134 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1135 dir
->ref_regular
|= ind
->ref_regular
;
1136 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1137 dir
->needs_plt
|= ind
->needs_plt
;
1138 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1141 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1144 /* Return TRUE if the TLS access code sequence support transition
1148 elf_i386_check_tls_transition (bfd
*abfd
, asection
*sec
,
1150 Elf_Internal_Shdr
*symtab_hdr
,
1151 struct elf_link_hash_entry
**sym_hashes
,
1152 unsigned int r_type
,
1153 const Elf_Internal_Rela
*rel
,
1154 const Elf_Internal_Rela
*relend
)
1156 unsigned int val
, type
;
1157 unsigned long r_symndx
;
1158 struct elf_link_hash_entry
*h
;
1161 /* Get the section contents. */
1162 if (contents
== NULL
)
1164 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1165 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1168 /* FIXME: How to better handle error condition? */
1169 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1172 /* Cache the section contents for elf_link_input_bfd. */
1173 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1177 offset
= rel
->r_offset
;
1182 if (offset
< 2 || (rel
+ 1) >= relend
)
1185 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1186 if (r_type
== R_386_TLS_GD
)
1188 /* Check transition from GD access model. Only
1189 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1190 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1191 can transit to different access model. */
1192 if ((offset
+ 10) > sec
->size
||
1193 (type
!= 0x8d && type
!= 0x04))
1196 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1199 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1203 if (bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x8d)
1206 if ((val
& 0xc7) != 0x05 || val
== (4 << 3))
1211 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1212 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1215 if (bfd_get_8 (abfd
, contents
+ offset
+ 9) != 0x90)
1221 /* Check transition from LD access model. Only
1222 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1223 can transit to different access model. */
1224 if (type
!= 0x8d || (offset
+ 9) > sec
->size
)
1227 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1228 if ((val
& 0xf8) != 0x80 || (val
& 7) == 4)
1232 if (bfd_get_8 (abfd
, contents
+ offset
+ 4) != 0xe8)
1235 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
1236 if (r_symndx
< symtab_hdr
->sh_info
)
1239 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1240 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1241 may be versioned. */
1243 && h
->root
.root
.string
!= NULL
1244 && (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
1245 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
)
1246 && (strncmp (h
->root
.root
.string
, "___tls_get_addr",
1250 /* Check transition from IE access model:
1251 movl foo@indntpoff(%rip), %eax
1252 movl foo@indntpoff(%rip), %reg
1253 addl foo@indntpoff(%rip), %reg
1256 if (offset
< 1 || (offset
+ 4) > sec
->size
)
1259 /* Check "movl foo@tpoff(%rip), %eax" first. */
1260 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1267 /* Check movl|addl foo@tpoff(%rip), %reg. */
1268 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1269 return ((type
== 0x8b || type
== 0x03)
1270 && (val
& 0xc7) == 0x05);
1272 case R_386_TLS_GOTIE
:
1273 case R_386_TLS_IE_32
:
1274 /* Check transition from {IE_32,GOTIE} access model:
1275 subl foo@{tpoff,gontoff}(%reg1), %reg2
1276 movl foo@{tpoff,gontoff}(%reg1), %reg2
1277 addl foo@{tpoff,gontoff}(%reg1), %reg2
1280 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1283 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1284 if ((val
& 0xc0) != 0x80 || (val
& 7) == 4)
1287 type
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1288 return type
== 0x8b || type
== 0x2b || type
== 0x03;
1290 case R_386_TLS_GOTDESC
:
1291 /* Check transition from GDesc access model:
1292 leal x@tlsdesc(%ebx), %eax
1294 Make sure it's a leal adding ebx to a 32-bit offset
1295 into any register, although it's probably almost always
1298 if (offset
< 2 || (offset
+ 4) > sec
->size
)
1301 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1304 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1305 return (val
& 0xc7) == 0x83;
1307 case R_386_TLS_DESC_CALL
:
1308 /* Check transition from GDesc access model:
1309 call *x@tlsdesc(%rax)
1311 if (offset
+ 2 <= sec
->size
)
1313 /* Make sure that it's a call *x@tlsdesc(%rax). */
1314 static const unsigned char call
[] = { 0xff, 0x10 };
1315 return memcmp (contents
+ offset
, call
, 2) == 0;
1325 /* Return TRUE if the TLS access transition is OK or no transition
1326 will be performed. Update R_TYPE if there is a transition. */
1329 elf_i386_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1330 asection
*sec
, bfd_byte
*contents
,
1331 Elf_Internal_Shdr
*symtab_hdr
,
1332 struct elf_link_hash_entry
**sym_hashes
,
1333 unsigned int *r_type
, int tls_type
,
1334 const Elf_Internal_Rela
*rel
,
1335 const Elf_Internal_Rela
*relend
,
1336 struct elf_link_hash_entry
*h
,
1337 unsigned long r_symndx
)
1339 unsigned int from_type
= *r_type
;
1340 unsigned int to_type
= from_type
;
1341 bfd_boolean check
= TRUE
;
1343 /* Skip TLS transition for functions. */
1345 && (h
->type
== STT_FUNC
1346 || h
->type
== STT_GNU_IFUNC
))
1352 case R_386_TLS_GOTDESC
:
1353 case R_386_TLS_DESC_CALL
:
1354 case R_386_TLS_IE_32
:
1356 case R_386_TLS_GOTIE
:
1357 if (info
->executable
)
1360 to_type
= R_386_TLS_LE_32
;
1361 else if (from_type
!= R_386_TLS_IE
1362 && from_type
!= R_386_TLS_GOTIE
)
1363 to_type
= R_386_TLS_IE_32
;
1366 /* When we are called from elf_i386_relocate_section, CONTENTS
1367 isn't NULL and there may be additional transitions based on
1369 if (contents
!= NULL
)
1371 unsigned int new_to_type
= to_type
;
1373 if (info
->executable
1376 && (tls_type
& GOT_TLS_IE
))
1377 new_to_type
= R_386_TLS_LE_32
;
1379 if (to_type
== R_386_TLS_GD
1380 || to_type
== R_386_TLS_GOTDESC
1381 || to_type
== R_386_TLS_DESC_CALL
)
1383 if (tls_type
== GOT_TLS_IE_POS
)
1384 new_to_type
= R_386_TLS_GOTIE
;
1385 else if (tls_type
& GOT_TLS_IE
)
1386 new_to_type
= R_386_TLS_IE_32
;
1389 /* We checked the transition before when we were called from
1390 elf_i386_check_relocs. We only want to check the new
1391 transition which hasn't been checked before. */
1392 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1393 to_type
= new_to_type
;
1399 if (info
->executable
)
1400 to_type
= R_386_TLS_LE_32
;
1407 /* Return TRUE if there is no transition. */
1408 if (from_type
== to_type
)
1411 /* Check if the transition can be performed. */
1413 && ! elf_i386_check_tls_transition (abfd
, sec
, contents
,
1414 symtab_hdr
, sym_hashes
,
1415 from_type
, rel
, relend
))
1417 reloc_howto_type
*from
, *to
;
1420 from
= elf_i386_rtype_to_howto (abfd
, from_type
);
1421 to
= elf_i386_rtype_to_howto (abfd
, to_type
);
1424 name
= h
->root
.root
.string
;
1427 struct elf_i386_link_hash_table
*htab
;
1429 htab
= elf_i386_hash_table (info
);
1434 Elf_Internal_Sym
*isym
;
1436 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1438 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1442 (*_bfd_error_handler
)
1443 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1444 "in section `%A' failed"),
1445 abfd
, sec
, from
->name
, to
->name
, name
,
1446 (unsigned long) rel
->r_offset
);
1447 bfd_set_error (bfd_error_bad_value
);
1455 /* Rename some of the generic section flags to better document how they
1457 #define need_convert_mov_to_lea sec_flg0
1459 /* Look through the relocs for a section during the first phase, and
1460 calculate needed space in the global offset table, procedure linkage
1461 table, and dynamic reloc sections. */
1464 elf_i386_check_relocs (bfd
*abfd
,
1465 struct bfd_link_info
*info
,
1467 const Elf_Internal_Rela
*relocs
)
1469 struct elf_i386_link_hash_table
*htab
;
1470 Elf_Internal_Shdr
*symtab_hdr
;
1471 struct elf_link_hash_entry
**sym_hashes
;
1472 const Elf_Internal_Rela
*rel
;
1473 const Elf_Internal_Rela
*rel_end
;
1475 bfd_boolean use_plt_got
;
1477 if (info
->relocatable
)
1480 BFD_ASSERT (is_i386_elf (abfd
));
1482 htab
= elf_i386_hash_table (info
);
1486 use_plt_got
= (!get_elf_i386_backend_data (abfd
)->is_vxworks
1487 && (get_elf_i386_backend_data (abfd
)
1488 == &elf_i386_arch_bed
));
1490 symtab_hdr
= &elf_symtab_hdr (abfd
);
1491 sym_hashes
= elf_sym_hashes (abfd
);
1495 rel_end
= relocs
+ sec
->reloc_count
;
1496 for (rel
= relocs
; rel
< rel_end
; rel
++)
1498 unsigned int r_type
;
1499 unsigned long r_symndx
;
1500 struct elf_link_hash_entry
*h
;
1501 struct elf_i386_link_hash_entry
*eh
;
1502 Elf_Internal_Sym
*isym
;
1504 bfd_boolean size_reloc
;
1506 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1507 r_type
= ELF32_R_TYPE (rel
->r_info
);
1509 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1511 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1517 if (r_symndx
< symtab_hdr
->sh_info
)
1519 /* A local symbol. */
1520 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1525 /* Check relocation against local STT_GNU_IFUNC symbol. */
1526 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1528 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, TRUE
);
1532 /* Fake a STT_GNU_IFUNC symbol. */
1533 h
->type
= STT_GNU_IFUNC
;
1536 h
->forced_local
= 1;
1537 h
->root
.type
= bfd_link_hash_defined
;
1545 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1546 while (h
->root
.type
== bfd_link_hash_indirect
1547 || h
->root
.type
== bfd_link_hash_warning
)
1548 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1551 eh
= (struct elf_i386_link_hash_entry
*) h
;
1554 /* Create the ifunc sections for static executables. If we
1555 never see an indirect function symbol nor we are building
1556 a static executable, those sections will be empty and
1557 won't appear in output. */
1569 if (htab
->elf
.dynobj
== NULL
)
1570 htab
->elf
.dynobj
= abfd
;
1571 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1576 /* It is referenced by a non-shared object. */
1578 h
->root
.non_ir_ref
= 1;
1581 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
1582 symtab_hdr
, sym_hashes
,
1583 &r_type
, GOT_UNKNOWN
,
1584 rel
, rel_end
, h
, r_symndx
))
1590 htab
->tls_ldm_got
.refcount
+= 1;
1594 /* This symbol requires a procedure linkage table entry. We
1595 actually build the entry in adjust_dynamic_symbol,
1596 because this might be a case of linking PIC code which is
1597 never referenced by a dynamic object, in which case we
1598 don't need to generate a procedure linkage table entry
1601 /* If this is a local symbol, we resolve it directly without
1602 creating a procedure linkage table entry. */
1607 h
->plt
.refcount
+= 1;
1614 case R_386_TLS_IE_32
:
1616 case R_386_TLS_GOTIE
:
1617 if (!info
->executable
)
1618 info
->flags
|= DF_STATIC_TLS
;
1623 case R_386_TLS_GOTDESC
:
1624 case R_386_TLS_DESC_CALL
:
1625 /* This symbol requires a global offset table entry. */
1627 int tls_type
, old_tls_type
;
1632 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1633 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1634 case R_386_TLS_GOTDESC
:
1635 case R_386_TLS_DESC_CALL
:
1636 tls_type
= GOT_TLS_GDESC
; break;
1637 case R_386_TLS_IE_32
:
1638 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1639 tls_type
= GOT_TLS_IE_NEG
;
1641 /* If this is a GD->IE transition, we may use either of
1642 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1643 tls_type
= GOT_TLS_IE
;
1646 case R_386_TLS_GOTIE
:
1647 tls_type
= GOT_TLS_IE_POS
; break;
1652 h
->got
.refcount
+= 1;
1653 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1657 bfd_signed_vma
*local_got_refcounts
;
1659 /* This is a global offset table entry for a local symbol. */
1660 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1661 if (local_got_refcounts
== NULL
)
1665 size
= symtab_hdr
->sh_info
;
1666 size
*= (sizeof (bfd_signed_vma
)
1667 + sizeof (bfd_vma
) + sizeof(char));
1668 local_got_refcounts
= (bfd_signed_vma
*)
1669 bfd_zalloc (abfd
, size
);
1670 if (local_got_refcounts
== NULL
)
1672 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1673 elf_i386_local_tlsdesc_gotent (abfd
)
1674 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1675 elf_i386_local_got_tls_type (abfd
)
1676 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1678 local_got_refcounts
[r_symndx
] += 1;
1679 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1682 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1683 tls_type
|= old_tls_type
;
1684 /* If a TLS symbol is accessed using IE at least once,
1685 there is no point to use dynamic model for it. */
1686 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1687 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1688 || (tls_type
& GOT_TLS_IE
) == 0))
1690 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1691 tls_type
= old_tls_type
;
1692 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1693 && GOT_TLS_GD_ANY_P (tls_type
))
1694 tls_type
|= old_tls_type
;
1698 name
= h
->root
.root
.string
;
1700 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1702 (*_bfd_error_handler
)
1703 (_("%B: `%s' accessed both as normal and "
1704 "thread local symbol"),
1706 bfd_set_error (bfd_error_bad_value
);
1711 if (old_tls_type
!= tls_type
)
1714 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1716 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1724 if (htab
->elf
.sgot
== NULL
)
1726 if (htab
->elf
.dynobj
== NULL
)
1727 htab
->elf
.dynobj
= abfd
;
1728 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
1731 if (r_type
!= R_386_TLS_IE
)
1735 case R_386_TLS_LE_32
:
1737 if (info
->executable
)
1739 info
->flags
|= DF_STATIC_TLS
;
1744 if (h
!= NULL
&& info
->executable
)
1746 /* If this reloc is in a read-only section, we might
1747 need a copy reloc. We can't check reliably at this
1748 stage whether the section is read-only, as input
1749 sections have not yet been mapped to output sections.
1750 Tentatively set the flag for now, and correct in
1751 adjust_dynamic_symbol. */
1754 /* We may need a .plt entry if the function this reloc
1755 refers to is in a shared lib. */
1756 h
->plt
.refcount
+= 1;
1757 if (r_type
!= R_386_PC32
)
1758 h
->pointer_equality_needed
= 1;
1763 /* If we are creating a shared library, and this is a reloc
1764 against a global symbol, or a non PC relative reloc
1765 against a local symbol, then we need to copy the reloc
1766 into the shared library. However, if we are linking with
1767 -Bsymbolic, we do not need to copy a reloc against a
1768 global symbol which is defined in an object we are
1769 including in the link (i.e., DEF_REGULAR is set). At
1770 this point we have not seen all the input files, so it is
1771 possible that DEF_REGULAR is not set now but will be set
1772 later (it is never cleared). In case of a weak definition,
1773 DEF_REGULAR may be cleared later by a strong definition in
1774 a shared library. We account for that possibility below by
1775 storing information in the relocs_copied field of the hash
1776 table entry. A similar situation occurs when creating
1777 shared libraries and symbol visibility changes render the
1780 If on the other hand, we are creating an executable, we
1781 may need to keep relocations for symbols satisfied by a
1782 dynamic library if we manage to avoid copy relocs for the
1785 && (sec
->flags
& SEC_ALLOC
) != 0
1786 && (r_type
!= R_386_PC32
1788 && (! SYMBOLIC_BIND (info
, h
)
1789 || h
->root
.type
== bfd_link_hash_defweak
1790 || !h
->def_regular
))))
1791 || (ELIMINATE_COPY_RELOCS
1793 && (sec
->flags
& SEC_ALLOC
) != 0
1795 && (h
->root
.type
== bfd_link_hash_defweak
1796 || !h
->def_regular
)))
1798 struct elf_dyn_relocs
*p
;
1799 struct elf_dyn_relocs
**head
;
1801 /* We must copy these reloc types into the output file.
1802 Create a reloc section in dynobj and make room for
1806 if (htab
->elf
.dynobj
== NULL
)
1807 htab
->elf
.dynobj
= abfd
;
1809 sreloc
= _bfd_elf_make_dynamic_reloc_section
1810 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ FALSE
);
1816 /* If this is a global symbol, we count the number of
1817 relocations we need for this symbol. */
1820 head
= &eh
->dyn_relocs
;
1824 /* Track dynamic relocs needed for local syms too.
1825 We really need local syms available to do this
1830 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1835 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1839 vpp
= &elf_section_data (s
)->local_dynrel
;
1840 head
= (struct elf_dyn_relocs
**)vpp
;
1844 if (p
== NULL
|| p
->sec
!= sec
)
1846 bfd_size_type amt
= sizeof *p
;
1847 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->elf
.dynobj
,
1859 /* Count size relocation as PC-relative relocation. */
1860 if (r_type
== R_386_PC32
|| size_reloc
)
1865 /* This relocation describes the C++ object vtable hierarchy.
1866 Reconstruct it for later use during GC. */
1867 case R_386_GNU_VTINHERIT
:
1868 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1872 /* This relocation describes which C++ vtable entries are actually
1873 used. Record for later use during GC. */
1874 case R_386_GNU_VTENTRY
:
1875 BFD_ASSERT (h
!= NULL
);
1877 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1887 && h
->plt
.refcount
> 0
1888 && h
->got
.refcount
> 0
1889 && htab
->plt_got
== NULL
)
1891 /* Create the GOT procedure linkage table. */
1892 unsigned int plt_got_align
;
1893 const struct elf_backend_data
*bed
;
1895 bed
= get_elf_backend_data (info
->output_bfd
);
1896 BFD_ASSERT (sizeof (elf_i386_got_plt_entry
) == 8
1897 && (sizeof (elf_i386_got_plt_entry
)
1898 == sizeof (elf_i386_pic_got_plt_entry
)));
1901 if (htab
->elf
.dynobj
== NULL
)
1902 htab
->elf
.dynobj
= abfd
;
1904 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
1906 (bed
->dynamic_sec_flags
1911 if (htab
->plt_got
== NULL
1912 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
1918 if (r_type
== R_386_GOT32
1919 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1920 sec
->need_convert_mov_to_lea
= 1;
1926 /* Return the section that should be marked against GC for a given
1930 elf_i386_gc_mark_hook (asection
*sec
,
1931 struct bfd_link_info
*info
,
1932 Elf_Internal_Rela
*rel
,
1933 struct elf_link_hash_entry
*h
,
1934 Elf_Internal_Sym
*sym
)
1937 switch (ELF32_R_TYPE (rel
->r_info
))
1939 case R_386_GNU_VTINHERIT
:
1940 case R_386_GNU_VTENTRY
:
1944 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1947 /* Update the got entry reference counts for the section being removed. */
1950 elf_i386_gc_sweep_hook (bfd
*abfd
,
1951 struct bfd_link_info
*info
,
1953 const Elf_Internal_Rela
*relocs
)
1955 struct elf_i386_link_hash_table
*htab
;
1956 Elf_Internal_Shdr
*symtab_hdr
;
1957 struct elf_link_hash_entry
**sym_hashes
;
1958 bfd_signed_vma
*local_got_refcounts
;
1959 const Elf_Internal_Rela
*rel
, *relend
;
1961 if (info
->relocatable
)
1964 htab
= elf_i386_hash_table (info
);
1968 elf_section_data (sec
)->local_dynrel
= NULL
;
1970 symtab_hdr
= &elf_symtab_hdr (abfd
);
1971 sym_hashes
= elf_sym_hashes (abfd
);
1972 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1974 relend
= relocs
+ sec
->reloc_count
;
1975 for (rel
= relocs
; rel
< relend
; rel
++)
1977 unsigned long r_symndx
;
1978 unsigned int r_type
;
1979 struct elf_link_hash_entry
*h
= NULL
;
1981 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1982 if (r_symndx
>= symtab_hdr
->sh_info
)
1984 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1985 while (h
->root
.type
== bfd_link_hash_indirect
1986 || h
->root
.type
== bfd_link_hash_warning
)
1987 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1991 /* A local symbol. */
1992 Elf_Internal_Sym
*isym
;
1994 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1997 /* Check relocation against local STT_GNU_IFUNC symbol. */
1999 && ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2001 h
= elf_i386_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
2009 struct elf_i386_link_hash_entry
*eh
;
2010 struct elf_dyn_relocs
**pp
;
2011 struct elf_dyn_relocs
*p
;
2013 eh
= (struct elf_i386_link_hash_entry
*) h
;
2014 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2017 /* Everything must go for SEC. */
2023 r_type
= ELF32_R_TYPE (rel
->r_info
);
2024 if (! elf_i386_tls_transition (info
, abfd
, sec
, NULL
,
2025 symtab_hdr
, sym_hashes
,
2026 &r_type
, GOT_UNKNOWN
,
2027 rel
, relend
, h
, r_symndx
))
2033 if (htab
->tls_ldm_got
.refcount
> 0)
2034 htab
->tls_ldm_got
.refcount
-= 1;
2038 case R_386_TLS_GOTDESC
:
2039 case R_386_TLS_DESC_CALL
:
2040 case R_386_TLS_IE_32
:
2042 case R_386_TLS_GOTIE
:
2046 if (h
->got
.refcount
> 0)
2047 h
->got
.refcount
-= 1;
2048 if (h
->type
== STT_GNU_IFUNC
)
2050 if (h
->plt
.refcount
> 0)
2051 h
->plt
.refcount
-= 1;
2054 else if (local_got_refcounts
!= NULL
)
2056 if (local_got_refcounts
[r_symndx
] > 0)
2057 local_got_refcounts
[r_symndx
] -= 1;
2065 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2072 if (h
->plt
.refcount
> 0)
2073 h
->plt
.refcount
-= 1;
2078 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2080 if (h
->got
.refcount
> 0)
2081 h
->got
.refcount
-= 1;
2082 if (h
->plt
.refcount
> 0)
2083 h
->plt
.refcount
-= 1;
2095 /* Adjust a symbol defined by a dynamic object and referenced by a
2096 regular object. The current definition is in some section of the
2097 dynamic object, but we're not including those sections. We have to
2098 change the definition to something the rest of the link can
2102 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2103 struct elf_link_hash_entry
*h
)
2105 struct elf_i386_link_hash_table
*htab
;
2107 struct elf_i386_link_hash_entry
*eh
;
2108 struct elf_dyn_relocs
*p
;
2110 /* STT_GNU_IFUNC symbol must go through PLT. */
2111 if (h
->type
== STT_GNU_IFUNC
)
2113 /* All local STT_GNU_IFUNC references must be treate as local
2114 calls via local PLT. */
2116 && SYMBOL_CALLS_LOCAL (info
, h
))
2118 bfd_size_type pc_count
= 0, count
= 0;
2119 struct elf_dyn_relocs
**pp
;
2121 eh
= (struct elf_i386_link_hash_entry
*) h
;
2122 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2124 pc_count
+= p
->pc_count
;
2125 p
->count
-= p
->pc_count
;
2134 if (pc_count
|| count
)
2138 if (h
->plt
.refcount
<= 0)
2139 h
->plt
.refcount
= 1;
2141 h
->plt
.refcount
+= 1;
2145 if (h
->plt
.refcount
<= 0)
2147 h
->plt
.offset
= (bfd_vma
) -1;
2153 /* If this is a function, put it in the procedure linkage table. We
2154 will fill in the contents of the procedure linkage table later,
2155 when we know the address of the .got section. */
2156 if (h
->type
== STT_FUNC
2159 if (h
->plt
.refcount
<= 0
2160 || SYMBOL_CALLS_LOCAL (info
, h
)
2161 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2162 && h
->root
.type
== bfd_link_hash_undefweak
))
2164 /* This case can occur if we saw a PLT32 reloc in an input
2165 file, but the symbol was never referred to by a dynamic
2166 object, or if all references were garbage collected. In
2167 such a case, we don't actually need to build a procedure
2168 linkage table, and we can just do a PC32 reloc instead. */
2169 h
->plt
.offset
= (bfd_vma
) -1;
2176 /* It's possible that we incorrectly decided a .plt reloc was
2177 needed for an R_386_PC32 reloc to a non-function sym in
2178 check_relocs. We can't decide accurately between function and
2179 non-function syms in check-relocs; Objects loaded later in
2180 the link may change h->type. So fix it now. */
2181 h
->plt
.offset
= (bfd_vma
) -1;
2183 /* If this is a weak symbol, and there is a real definition, the
2184 processor independent code will have arranged for us to see the
2185 real definition first, and we can just use the same value. */
2186 if (h
->u
.weakdef
!= NULL
)
2188 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2189 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2190 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2191 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2192 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2193 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2197 /* This is a reference to a symbol defined by a dynamic object which
2198 is not a function. */
2200 /* If we are creating a shared library, we must presume that the
2201 only references to the symbol are via the global offset table.
2202 For such cases we need not do anything here; the relocations will
2203 be handled correctly by relocate_section. */
2204 if (!info
->executable
)
2207 /* If there are no references to this symbol that do not use the
2208 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2210 eh
= (struct elf_i386_link_hash_entry
*) h
;
2211 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2214 /* If -z nocopyreloc was given, we won't generate them either. */
2215 if (info
->nocopyreloc
)
2221 htab
= elf_i386_hash_table (info
);
2225 /* If there aren't any dynamic relocs in read-only sections nor
2226 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2227 avoid the copy reloc. This doesn't work on VxWorks, where we can
2228 not have dynamic relocations (other than copy and jump slot
2229 relocations) in an executable. */
2230 if (ELIMINATE_COPY_RELOCS
2232 && !get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2234 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2236 s
= p
->sec
->output_section
;
2237 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2248 /* We must allocate the symbol in our .dynbss section, which will
2249 become part of the .bss section of the executable. There will be
2250 an entry for this symbol in the .dynsym section. The dynamic
2251 object will contain position independent code, so all references
2252 from the dynamic object to this symbol will go through the global
2253 offset table. The dynamic linker will use the .dynsym entry to
2254 determine the address it must put in the global offset table, so
2255 both the dynamic object and the regular object will refer to the
2256 same memory location for the variable. */
2258 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2259 copy the initial value out of the dynamic object and into the
2260 runtime process image. */
2261 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2263 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
2269 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2272 /* Allocate space in .plt, .got and associated reloc sections for
2276 elf_i386_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2278 struct bfd_link_info
*info
;
2279 struct elf_i386_link_hash_table
*htab
;
2280 struct elf_i386_link_hash_entry
*eh
;
2281 struct elf_dyn_relocs
*p
;
2282 unsigned plt_entry_size
;
2284 if (h
->root
.type
== bfd_link_hash_indirect
)
2287 eh
= (struct elf_i386_link_hash_entry
*) h
;
2289 info
= (struct bfd_link_info
*) inf
;
2290 htab
= elf_i386_hash_table (info
);
2294 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2296 /* We can't use the GOT PLT if pointer equality is needed since
2297 finish_dynamic_symbol won't clear symbol value and the dynamic
2298 linker won't update the GOT slot. We will get into an infinite
2299 loop at run-time. */
2300 if (htab
->plt_got
!= NULL
2301 && h
->type
!= STT_GNU_IFUNC
2302 && !h
->pointer_equality_needed
2303 && h
->plt
.refcount
> 0
2304 && h
->got
.refcount
> 0)
2306 /* Don't use the regular PLT if there are both GOT and GOTPLT
2308 h
->plt
.offset
= (bfd_vma
) -1;
2310 /* Use the GOT PLT. */
2311 eh
->plt_got
.refcount
= 1;
2314 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2315 here if it is defined and referenced in a non-shared object. */
2316 if (h
->type
== STT_GNU_IFUNC
2318 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &eh
->dyn_relocs
,
2321 else if (htab
->elf
.dynamic_sections_created
2322 && (h
->plt
.refcount
> 0 || eh
->plt_got
.refcount
> 0))
2324 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
2326 /* Make sure this symbol is output as a dynamic symbol.
2327 Undefined weak syms won't yet be marked as dynamic. */
2328 if (h
->dynindx
== -1
2329 && !h
->forced_local
)
2331 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2336 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2338 asection
*s
= htab
->elf
.splt
;
2339 asection
*got_s
= htab
->plt_got
;
2342 eh
->plt_got
.offset
= got_s
->size
;
2345 /* If this is the first .plt entry, make room for the
2346 special first entry. */
2348 s
->size
= plt_entry_size
;
2349 h
->plt
.offset
= s
->size
;
2352 /* If this symbol is not defined in a regular file, and we are
2353 not generating a shared library, then set the symbol to this
2354 location in the .plt. This is required to make function
2355 pointers compare as equal between the normal executable and
2356 the shared library. */
2362 /* We need to make a call to the entry of the GOT PLT
2363 instead of regular PLT entry. */
2364 h
->root
.u
.def
.section
= got_s
;
2365 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2369 h
->root
.u
.def
.section
= s
;
2370 h
->root
.u
.def
.value
= h
->plt
.offset
;
2374 /* Make room for this entry. */
2376 got_s
->size
+= sizeof (elf_i386_got_plt_entry
);
2379 s
->size
+= plt_entry_size
;
2381 /* We also need to make an entry in the .got.plt section,
2382 which will be placed in the .got section by the linker
2384 htab
->elf
.sgotplt
->size
+= 4;
2386 /* We also need to make an entry in the .rel.plt section. */
2387 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2388 htab
->elf
.srelplt
->reloc_count
++;
2391 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
2394 /* VxWorks has a second set of relocations for each PLT entry
2395 in executables. They go in a separate relocation section,
2396 which is processed by the kernel loader. */
2398 /* There are two relocations for the initial PLT entry: an
2399 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2400 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2402 if (h
->plt
.offset
== plt_entry_size
)
2403 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2405 /* There are two extra relocations for each subsequent PLT entry:
2406 an R_386_32 relocation for the GOT entry, and an R_386_32
2407 relocation for the PLT entry. */
2409 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
2414 h
->plt
.offset
= (bfd_vma
) -1;
2420 h
->plt
.offset
= (bfd_vma
) -1;
2424 eh
->tlsdesc_got
= (bfd_vma
) -1;
2426 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
2427 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2428 if (h
->got
.refcount
> 0
2431 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
2432 h
->got
.offset
= (bfd_vma
) -1;
2433 else if (h
->got
.refcount
> 0)
2437 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2439 /* Make sure this symbol is output as a dynamic symbol.
2440 Undefined weak syms won't yet be marked as dynamic. */
2441 if (h
->dynindx
== -1
2442 && !h
->forced_local
)
2444 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2449 if (GOT_TLS_GDESC_P (tls_type
))
2451 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2452 - elf_i386_compute_jump_table_size (htab
);
2453 htab
->elf
.sgotplt
->size
+= 8;
2454 h
->got
.offset
= (bfd_vma
) -2;
2456 if (! GOT_TLS_GDESC_P (tls_type
)
2457 || GOT_TLS_GD_P (tls_type
))
2459 h
->got
.offset
= s
->size
;
2461 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2462 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
2465 dyn
= htab
->elf
.dynamic_sections_created
;
2466 /* R_386_TLS_IE_32 needs one dynamic relocation,
2467 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2468 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2469 need two), R_386_TLS_GD needs one if local symbol and two if
2471 if (tls_type
== GOT_TLS_IE_BOTH
)
2472 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2473 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2474 || (tls_type
& GOT_TLS_IE
))
2475 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2476 else if (GOT_TLS_GD_P (tls_type
))
2477 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
2478 else if (! GOT_TLS_GDESC_P (tls_type
)
2479 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2480 || h
->root
.type
!= bfd_link_hash_undefweak
)
2482 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2483 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2484 if (GOT_TLS_GDESC_P (tls_type
))
2485 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2488 h
->got
.offset
= (bfd_vma
) -1;
2490 if (eh
->dyn_relocs
== NULL
)
2493 /* In the shared -Bsymbolic case, discard space allocated for
2494 dynamic pc-relative relocs against symbols which turn out to be
2495 defined in regular objects. For the normal shared case, discard
2496 space for pc-relative relocs that have become local due to symbol
2497 visibility changes. */
2501 /* The only reloc that uses pc_count is R_386_PC32, which will
2502 appear on a call or on something like ".long foo - .". We
2503 want calls to protected symbols to resolve directly to the
2504 function rather than going via the plt. If people want
2505 function pointer comparisons to work as expected then they
2506 should avoid writing assembly like ".long foo - .". */
2507 if (SYMBOL_CALLS_LOCAL (info
, h
))
2509 struct elf_dyn_relocs
**pp
;
2511 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2513 p
->count
-= p
->pc_count
;
2522 if (get_elf_i386_backend_data (info
->output_bfd
)->is_vxworks
)
2524 struct elf_dyn_relocs
**pp
;
2525 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2527 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
2534 /* Also discard relocs on undefined weak syms with non-default
2536 if (eh
->dyn_relocs
!= NULL
2537 && h
->root
.type
== bfd_link_hash_undefweak
)
2539 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2540 eh
->dyn_relocs
= NULL
;
2542 /* Make sure undefined weak symbols are output as a dynamic
2544 else if (h
->dynindx
== -1
2545 && !h
->forced_local
)
2547 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2552 else if (ELIMINATE_COPY_RELOCS
)
2554 /* For the non-shared case, discard space for relocs against
2555 symbols which turn out to need copy relocs or are not
2561 || (htab
->elf
.dynamic_sections_created
2562 && (h
->root
.type
== bfd_link_hash_undefweak
2563 || h
->root
.type
== bfd_link_hash_undefined
))))
2565 /* Make sure this symbol is output as a dynamic symbol.
2566 Undefined weak syms won't yet be marked as dynamic. */
2567 if (h
->dynindx
== -1
2568 && !h
->forced_local
)
2570 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2574 /* If that succeeded, we know we'll be keeping all the
2576 if (h
->dynindx
!= -1)
2580 eh
->dyn_relocs
= NULL
;
2585 /* Finally, allocate space. */
2586 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2590 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2592 BFD_ASSERT (sreloc
!= NULL
);
2593 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2599 /* Allocate space in .plt, .got and associated reloc sections for
2600 local dynamic relocs. */
2603 elf_i386_allocate_local_dynrelocs (void **slot
, void *inf
)
2605 struct elf_link_hash_entry
*h
2606 = (struct elf_link_hash_entry
*) *slot
;
2608 if (h
->type
!= STT_GNU_IFUNC
2612 || h
->root
.type
!= bfd_link_hash_defined
)
2615 return elf_i386_allocate_dynrelocs (h
, inf
);
2618 /* Find any dynamic relocs that apply to read-only sections. */
2621 elf_i386_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2623 struct elf_i386_link_hash_entry
*eh
;
2624 struct elf_dyn_relocs
*p
;
2626 /* Skip local IFUNC symbols. */
2627 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2630 eh
= (struct elf_i386_link_hash_entry
*) h
;
2631 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2633 asection
*s
= p
->sec
->output_section
;
2635 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2637 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2639 info
->flags
|= DF_TEXTREL
;
2641 if ((info
->warn_shared_textrel
&& info
->shared
)
2642 || info
->error_textrel
)
2643 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
2644 p
->sec
->owner
, h
->root
.root
.string
,
2647 /* Not an error, just cut short the traversal. */
2655 mov foo@GOT(%reg), %reg
2657 lea foo@GOTOFF(%reg), %reg
2658 with the local symbol, foo. */
2661 elf_i386_convert_mov_to_lea (bfd
*abfd
, asection
*sec
,
2662 struct bfd_link_info
*link_info
)
2664 Elf_Internal_Shdr
*symtab_hdr
;
2665 Elf_Internal_Rela
*internal_relocs
;
2666 Elf_Internal_Rela
*irel
, *irelend
;
2668 struct elf_i386_link_hash_table
*htab
;
2669 bfd_boolean changed_contents
;
2670 bfd_boolean changed_relocs
;
2671 bfd_signed_vma
*local_got_refcounts
;
2673 /* Don't even try to convert non-ELF outputs. */
2674 if (!is_elf_hash_table (link_info
->hash
))
2677 /* Nothing to do if there is no need or no output. */
2678 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
2679 || sec
->need_convert_mov_to_lea
== 0
2680 || bfd_is_abs_section (sec
->output_section
))
2683 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2685 /* Load the relocations for this section. */
2686 internal_relocs
= (_bfd_elf_link_read_relocs
2687 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2688 link_info
->keep_memory
));
2689 if (internal_relocs
== NULL
)
2692 htab
= elf_i386_hash_table (link_info
);
2693 changed_contents
= FALSE
;
2694 changed_relocs
= FALSE
;
2695 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2697 /* Get the section contents. */
2698 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2699 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2702 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2706 irelend
= internal_relocs
+ sec
->reloc_count
;
2707 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2709 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
2710 unsigned int r_symndx
= ELF32_R_SYM (irel
->r_info
);
2712 struct elf_link_hash_entry
*h
;
2714 if (r_type
!= R_386_GOT32
)
2717 /* Get the symbol referred to by the reloc. */
2718 if (r_symndx
< symtab_hdr
->sh_info
)
2720 Elf_Internal_Sym
*isym
;
2722 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2725 /* STT_GNU_IFUNC must keep R_386_GOT32 relocation. */
2726 if (ELF_ST_TYPE (isym
->st_info
) != STT_GNU_IFUNC
2727 && irel
->r_offset
>= 2
2728 && bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 2) == 0x8b)
2730 bfd_put_8 (abfd
, 0x8d, contents
+ irel
->r_offset
- 2);
2731 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_GOTOFF
);
2732 if (local_got_refcounts
!= NULL
2733 && local_got_refcounts
[r_symndx
] > 0)
2734 local_got_refcounts
[r_symndx
] -= 1;
2735 changed_contents
= TRUE
;
2736 changed_relocs
= TRUE
;
2741 indx
= r_symndx
- symtab_hdr
->sh_info
;
2742 h
= elf_sym_hashes (abfd
)[indx
];
2743 BFD_ASSERT (h
!= NULL
);
2745 while (h
->root
.type
== bfd_link_hash_indirect
2746 || h
->root
.type
== bfd_link_hash_warning
)
2747 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2749 /* STT_GNU_IFUNC must keep R_386_GOT32 relocation. We also avoid
2750 optimizing _DYNAMIC since ld.so may use its link-time address. */
2752 && h
->type
!= STT_GNU_IFUNC
2753 && h
!= htab
->elf
.hdynamic
2754 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)
2755 && irel
->r_offset
>= 2
2756 && bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 2) == 0x8b)
2758 bfd_put_8 (abfd
, 0x8d, contents
+ irel
->r_offset
- 2);
2759 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_386_GOTOFF
);
2760 if (h
->got
.refcount
> 0)
2761 h
->got
.refcount
-= 1;
2762 changed_contents
= TRUE
;
2763 changed_relocs
= TRUE
;
2767 if (contents
!= NULL
2768 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2770 if (!changed_contents
&& !link_info
->keep_memory
)
2774 /* Cache the section contents for elf_link_input_bfd. */
2775 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2779 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2781 if (!changed_relocs
)
2782 free (internal_relocs
);
2784 elf_section_data (sec
)->relocs
= internal_relocs
;
2790 if (contents
!= NULL
2791 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2793 if (internal_relocs
!= NULL
2794 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2795 free (internal_relocs
);
2799 /* Set the sizes of the dynamic sections. */
2802 elf_i386_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2804 struct elf_i386_link_hash_table
*htab
;
2810 htab
= elf_i386_hash_table (info
);
2813 dynobj
= htab
->elf
.dynobj
;
2817 if (htab
->elf
.dynamic_sections_created
)
2819 /* Set the contents of the .interp section to the interpreter. */
2820 if (info
->executable
)
2822 s
= bfd_get_linker_section (dynobj
, ".interp");
2825 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2826 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2830 /* Set up .got offsets for local syms, and space for local dynamic
2832 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2834 bfd_signed_vma
*local_got
;
2835 bfd_signed_vma
*end_local_got
;
2836 char *local_tls_type
;
2837 bfd_vma
*local_tlsdesc_gotent
;
2838 bfd_size_type locsymcount
;
2839 Elf_Internal_Shdr
*symtab_hdr
;
2842 if (! is_i386_elf (ibfd
))
2845 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2847 struct elf_dyn_relocs
*p
;
2849 if (!elf_i386_convert_mov_to_lea (ibfd
, s
, info
))
2852 for (p
= ((struct elf_dyn_relocs
*)
2853 elf_section_data (s
)->local_dynrel
);
2857 if (!bfd_is_abs_section (p
->sec
)
2858 && bfd_is_abs_section (p
->sec
->output_section
))
2860 /* Input section has been discarded, either because
2861 it is a copy of a linkonce section or due to
2862 linker script /DISCARD/, so we'll be discarding
2865 else if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
2866 && strcmp (p
->sec
->output_section
->name
,
2869 /* Relocations in vxworks .tls_vars sections are
2870 handled specially by the loader. */
2872 else if (p
->count
!= 0)
2874 srel
= elf_section_data (p
->sec
)->sreloc
;
2875 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
2876 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2877 && (info
->flags
& DF_TEXTREL
) == 0)
2879 info
->flags
|= DF_TEXTREL
;
2880 if ((info
->warn_shared_textrel
&& info
->shared
)
2881 || info
->error_textrel
)
2882 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
2883 p
->sec
->owner
, p
->sec
);
2889 local_got
= elf_local_got_refcounts (ibfd
);
2893 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2894 locsymcount
= symtab_hdr
->sh_info
;
2895 end_local_got
= local_got
+ locsymcount
;
2896 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
2897 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
2899 srel
= htab
->elf
.srelgot
;
2900 for (; local_got
< end_local_got
;
2901 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2903 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2906 if (GOT_TLS_GDESC_P (*local_tls_type
))
2908 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2909 - elf_i386_compute_jump_table_size (htab
);
2910 htab
->elf
.sgotplt
->size
+= 8;
2911 *local_got
= (bfd_vma
) -2;
2913 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2914 || GOT_TLS_GD_P (*local_tls_type
))
2916 *local_got
= s
->size
;
2918 if (GOT_TLS_GD_P (*local_tls_type
)
2919 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2923 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2924 || (*local_tls_type
& GOT_TLS_IE
))
2926 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2927 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2928 else if (GOT_TLS_GD_P (*local_tls_type
)
2929 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2930 srel
->size
+= sizeof (Elf32_External_Rel
);
2931 if (GOT_TLS_GDESC_P (*local_tls_type
))
2932 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rel
);
2936 *local_got
= (bfd_vma
) -1;
2940 if (htab
->tls_ldm_got
.refcount
> 0)
2942 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2944 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2945 htab
->elf
.sgot
->size
+= 8;
2946 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rel
);
2949 htab
->tls_ldm_got
.offset
= -1;
2951 /* Allocate global sym .plt and .got entries, and space for global
2952 sym dynamic relocs. */
2953 elf_link_hash_traverse (&htab
->elf
, elf_i386_allocate_dynrelocs
, info
);
2955 /* Allocate .plt and .got entries, and space for local symbols. */
2956 htab_traverse (htab
->loc_hash_table
,
2957 elf_i386_allocate_local_dynrelocs
,
2960 /* For every jump slot reserved in the sgotplt, reloc_count is
2961 incremented. However, when we reserve space for TLS descriptors,
2962 it's not incremented, so in order to compute the space reserved
2963 for them, it suffices to multiply the reloc count by the jump
2966 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2967 so that R_386_IRELATIVE entries come last. */
2968 if (htab
->elf
.srelplt
)
2970 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
2971 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2972 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2974 else if (htab
->elf
.irelplt
)
2975 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2978 if (htab
->elf
.sgotplt
)
2980 /* Don't allocate .got.plt section if there are no GOT nor PLT
2981 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
2982 if ((htab
->elf
.hgot
== NULL
2983 || !htab
->elf
.hgot
->ref_regular_nonweak
)
2984 && (htab
->elf
.sgotplt
->size
2985 == get_elf_backend_data (output_bfd
)->got_header_size
)
2986 && (htab
->elf
.splt
== NULL
2987 || htab
->elf
.splt
->size
== 0)
2988 && (htab
->elf
.sgot
== NULL
2989 || htab
->elf
.sgot
->size
== 0)
2990 && (htab
->elf
.iplt
== NULL
2991 || htab
->elf
.iplt
->size
== 0)
2992 && (htab
->elf
.igotplt
== NULL
2993 || htab
->elf
.igotplt
->size
== 0))
2994 htab
->elf
.sgotplt
->size
= 0;
2998 if (htab
->plt_eh_frame
!= NULL
2999 && htab
->elf
.splt
!= NULL
3000 && htab
->elf
.splt
->size
!= 0
3001 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
)
3002 && _bfd_elf_eh_frame_present (info
))
3003 htab
->plt_eh_frame
->size
= sizeof (elf_i386_eh_frame_plt
);
3005 /* We now have determined the sizes of the various dynamic sections.
3006 Allocate memory for them. */
3008 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3010 bfd_boolean strip_section
= TRUE
;
3012 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3015 if (s
== htab
->elf
.splt
3016 || s
== htab
->elf
.sgot
)
3018 /* Strip this section if we don't need it; see the
3020 /* We'd like to strip these sections if they aren't needed, but if
3021 we've exported dynamic symbols from them we must leave them.
3022 It's too late to tell BFD to get rid of the symbols. */
3024 if (htab
->elf
.hplt
!= NULL
)
3025 strip_section
= FALSE
;
3027 else if (s
== htab
->elf
.sgotplt
3028 || s
== htab
->elf
.iplt
3029 || s
== htab
->elf
.igotplt
3030 || s
== htab
->plt_got
3031 || s
== htab
->plt_eh_frame
3032 || s
== htab
->sdynbss
)
3034 /* Strip these too. */
3036 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
3039 && s
!= htab
->elf
.srelplt
3040 && s
!= htab
->srelplt2
)
3043 /* We use the reloc_count field as a counter if we need
3044 to copy relocs into the output file. */
3049 /* It's not one of our sections, so don't allocate space. */
3055 /* If we don't need this section, strip it from the
3056 output file. This is mostly to handle .rel.bss and
3057 .rel.plt. We must create both sections in
3058 create_dynamic_sections, because they must be created
3059 before the linker maps input sections to output
3060 sections. The linker does that before
3061 adjust_dynamic_symbol is called, and it is that
3062 function which decides whether anything needs to go
3063 into these sections. */
3065 s
->flags
|= SEC_EXCLUDE
;
3069 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3072 /* Allocate memory for the section contents. We use bfd_zalloc
3073 here in case unused entries are not reclaimed before the
3074 section's contents are written out. This should not happen,
3075 but this way if it does, we get a R_386_NONE reloc instead
3077 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
3078 if (s
->contents
== NULL
)
3082 if (htab
->plt_eh_frame
!= NULL
3083 && htab
->plt_eh_frame
->contents
!= NULL
)
3085 memcpy (htab
->plt_eh_frame
->contents
, elf_i386_eh_frame_plt
,
3086 sizeof (elf_i386_eh_frame_plt
));
3087 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3088 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3091 if (htab
->elf
.dynamic_sections_created
)
3093 /* Add some entries to the .dynamic section. We fill in the
3094 values later, in elf_i386_finish_dynamic_sections, but we
3095 must add the entries now so that we get the correct size for
3096 the .dynamic section. The DT_DEBUG entry is filled in by the
3097 dynamic linker and used by the debugger. */
3098 #define add_dynamic_entry(TAG, VAL) \
3099 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3101 if (info
->executable
)
3103 if (!add_dynamic_entry (DT_DEBUG
, 0))
3107 if (htab
->elf
.splt
->size
!= 0)
3109 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3110 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3111 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3112 || !add_dynamic_entry (DT_JMPREL
, 0))
3118 if (!add_dynamic_entry (DT_REL
, 0)
3119 || !add_dynamic_entry (DT_RELSZ
, 0)
3120 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3123 /* If any dynamic relocs apply to a read-only section,
3124 then we need a DT_TEXTREL entry. */
3125 if ((info
->flags
& DF_TEXTREL
) == 0)
3126 elf_link_hash_traverse (&htab
->elf
,
3127 elf_i386_readonly_dynrelocs
, info
);
3129 if ((info
->flags
& DF_TEXTREL
) != 0)
3131 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3135 if (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3136 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3139 #undef add_dynamic_entry
3145 elf_i386_always_size_sections (bfd
*output_bfd
,
3146 struct bfd_link_info
*info
)
3148 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3152 struct elf_link_hash_entry
*tlsbase
;
3154 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3155 "_TLS_MODULE_BASE_",
3156 FALSE
, FALSE
, FALSE
);
3158 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3160 struct elf_i386_link_hash_table
*htab
;
3161 struct bfd_link_hash_entry
*bh
= NULL
;
3162 const struct elf_backend_data
*bed
3163 = get_elf_backend_data (output_bfd
);
3165 htab
= elf_i386_hash_table (info
);
3169 if (!(_bfd_generic_link_add_one_symbol
3170 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3171 tls_sec
, 0, NULL
, FALSE
,
3172 bed
->collect
, &bh
)))
3175 htab
->tls_module_base
= bh
;
3177 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3178 tlsbase
->def_regular
= 1;
3179 tlsbase
->other
= STV_HIDDEN
;
3180 tlsbase
->root
.linker_def
= 1;
3181 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
3188 /* Set the correct type for an x86 ELF section. We do this by the
3189 section name, which is a hack, but ought to work. */
3192 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3193 Elf_Internal_Shdr
*hdr
,
3198 name
= bfd_get_section_name (abfd
, sec
);
3200 /* This is an ugly, but unfortunately necessary hack that is
3201 needed when producing EFI binaries on x86. It tells
3202 elf.c:elf_fake_sections() not to consider ".reloc" as a section
3203 containing ELF relocation info. We need this hack in order to
3204 be able to generate ELF binaries that can be translated into
3205 EFI applications (which are essentially COFF objects). Those
3206 files contain a COFF ".reloc" section inside an ELFNN object,
3207 which would normally cause BFD to segfault because it would
3208 attempt to interpret this section as containing relocation
3209 entries for section "oc". With this hack enabled, ".reloc"
3210 will be treated as a normal data section, which will avoid the
3211 segfault. However, you won't be able to create an ELFNN binary
3212 with a section named "oc" that needs relocations, but that's
3213 the kind of ugly side-effects you get when detecting section
3214 types based on their names... In practice, this limitation is
3215 unlikely to bite. */
3216 if (strcmp (name
, ".reloc") == 0)
3217 hdr
->sh_type
= SHT_PROGBITS
;
3222 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3223 executables. Rather than setting it to the beginning of the TLS
3224 section, we have to set it to the end. This function may be called
3225 multiple times, it is idempotent. */
3228 elf_i386_set_tls_module_base (struct bfd_link_info
*info
)
3230 struct elf_i386_link_hash_table
*htab
;
3231 struct bfd_link_hash_entry
*base
;
3233 if (!info
->executable
)
3236 htab
= elf_i386_hash_table (info
);
3240 base
= htab
->tls_module_base
;
3244 base
->u
.def
.value
= htab
->elf
.tls_size
;
3247 /* Return the base VMA address which should be subtracted from real addresses
3248 when resolving @dtpoff relocation.
3249 This is PT_TLS segment p_vaddr. */
3252 elf_i386_dtpoff_base (struct bfd_link_info
*info
)
3254 /* If tls_sec is NULL, we should have signalled an error already. */
3255 if (elf_hash_table (info
)->tls_sec
== NULL
)
3257 return elf_hash_table (info
)->tls_sec
->vma
;
3260 /* Return the relocation value for @tpoff relocation
3261 if STT_TLS virtual address is ADDRESS. */
3264 elf_i386_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3266 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3267 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3268 bfd_vma static_tls_size
;
3270 /* If tls_sec is NULL, we should have signalled an error already. */
3271 if (htab
->tls_sec
== NULL
)
3274 /* Consider special static TLS alignment requirements. */
3275 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3276 return static_tls_size
+ htab
->tls_sec
->vma
- address
;
3279 /* Relocate an i386 ELF section. */
3282 elf_i386_relocate_section (bfd
*output_bfd
,
3283 struct bfd_link_info
*info
,
3285 asection
*input_section
,
3287 Elf_Internal_Rela
*relocs
,
3288 Elf_Internal_Sym
*local_syms
,
3289 asection
**local_sections
)
3291 struct elf_i386_link_hash_table
*htab
;
3292 Elf_Internal_Shdr
*symtab_hdr
;
3293 struct elf_link_hash_entry
**sym_hashes
;
3294 bfd_vma
*local_got_offsets
;
3295 bfd_vma
*local_tlsdesc_gotents
;
3296 Elf_Internal_Rela
*rel
;
3297 Elf_Internal_Rela
*relend
;
3298 bfd_boolean is_vxworks_tls
;
3299 unsigned plt_entry_size
;
3301 BFD_ASSERT (is_i386_elf (input_bfd
));
3303 htab
= elf_i386_hash_table (info
);
3306 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3307 sym_hashes
= elf_sym_hashes (input_bfd
);
3308 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3309 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
3310 /* We have to handle relocations in vxworks .tls_vars sections
3311 specially, because the dynamic loader is 'weird'. */
3312 is_vxworks_tls
= (get_elf_i386_backend_data (output_bfd
)->is_vxworks
3314 && !strcmp (input_section
->output_section
->name
,
3317 elf_i386_set_tls_module_base (info
);
3319 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
3322 relend
= relocs
+ input_section
->reloc_count
;
3323 for (; rel
< relend
; rel
++)
3325 unsigned int r_type
;
3326 reloc_howto_type
*howto
;
3327 unsigned long r_symndx
;
3328 struct elf_link_hash_entry
*h
;
3329 struct elf_i386_link_hash_entry
*eh
;
3330 Elf_Internal_Sym
*sym
;
3332 bfd_vma off
, offplt
, plt_offset
;
3334 bfd_boolean unresolved_reloc
;
3335 bfd_reloc_status_type r
;
3339 asection
*resolved_plt
;
3341 r_type
= ELF32_R_TYPE (rel
->r_info
);
3342 if (r_type
== R_386_GNU_VTINHERIT
3343 || r_type
== R_386_GNU_VTENTRY
)
3346 if ((indx
= r_type
) >= R_386_standard
3347 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
3348 >= R_386_ext
- R_386_standard
)
3349 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
3350 >= R_386_irelative
- R_386_ext
))
3352 (*_bfd_error_handler
)
3353 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3354 input_bfd
, input_section
, r_type
);
3355 bfd_set_error (bfd_error_bad_value
);
3358 howto
= elf_howto_table
+ indx
;
3360 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3364 unresolved_reloc
= FALSE
;
3365 if (r_symndx
< symtab_hdr
->sh_info
)
3367 sym
= local_syms
+ r_symndx
;
3368 sec
= local_sections
[r_symndx
];
3369 relocation
= (sec
->output_section
->vma
3370 + sec
->output_offset
3372 st_size
= sym
->st_size
;
3374 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3375 && ((sec
->flags
& SEC_MERGE
) != 0
3376 || (info
->relocatable
3377 && sec
->output_offset
!= 0)))
3380 bfd_byte
*where
= contents
+ rel
->r_offset
;
3382 switch (howto
->size
)
3385 addend
= bfd_get_8 (input_bfd
, where
);
3386 if (howto
->pc_relative
)
3388 addend
= (addend
^ 0x80) - 0x80;
3393 addend
= bfd_get_16 (input_bfd
, where
);
3394 if (howto
->pc_relative
)
3396 addend
= (addend
^ 0x8000) - 0x8000;
3401 addend
= bfd_get_32 (input_bfd
, where
);
3402 if (howto
->pc_relative
)
3404 addend
= (addend
^ 0x80000000) - 0x80000000;
3412 if (info
->relocatable
)
3413 addend
+= sec
->output_offset
;
3416 asection
*msec
= sec
;
3417 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
3419 addend
-= relocation
;
3420 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3423 switch (howto
->size
)
3426 /* FIXME: overflow checks. */
3427 if (howto
->pc_relative
)
3429 bfd_put_8 (input_bfd
, addend
, where
);
3432 if (howto
->pc_relative
)
3434 bfd_put_16 (input_bfd
, addend
, where
);
3437 if (howto
->pc_relative
)
3439 bfd_put_32 (input_bfd
, addend
, where
);
3443 else if (!info
->relocatable
3444 && ELF32_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3446 /* Relocate against local STT_GNU_IFUNC symbol. */
3447 h
= elf_i386_get_local_sym_hash (htab
, input_bfd
, rel
,
3452 /* Set STT_GNU_IFUNC symbol value. */
3453 h
->root
.u
.def
.value
= sym
->st_value
;
3454 h
->root
.u
.def
.section
= sec
;
3459 bfd_boolean warned ATTRIBUTE_UNUSED
;
3460 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3462 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3463 r_symndx
, symtab_hdr
, sym_hashes
,
3465 unresolved_reloc
, warned
, ignored
);
3469 if (sec
!= NULL
&& discarded_section (sec
))
3470 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3471 rel
, 1, relend
, howto
, 0, contents
);
3473 if (info
->relocatable
)
3476 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3477 it here if it is defined in a non-shared object. */
3479 && h
->type
== STT_GNU_IFUNC
3482 asection
*plt
, *gotplt
, *base_got
;
3486 if ((input_section
->flags
& SEC_ALLOC
) == 0
3487 || h
->plt
.offset
== (bfd_vma
) -1)
3490 /* STT_GNU_IFUNC symbol must go through PLT. */
3491 if (htab
->elf
.splt
!= NULL
)
3493 plt
= htab
->elf
.splt
;
3494 gotplt
= htab
->elf
.sgotplt
;
3498 plt
= htab
->elf
.iplt
;
3499 gotplt
= htab
->elf
.igotplt
;
3502 relocation
= (plt
->output_section
->vma
3503 + plt
->output_offset
+ h
->plt
.offset
);
3508 if (h
->root
.root
.string
)
3509 name
= h
->root
.root
.string
;
3511 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3513 (*_bfd_error_handler
)
3514 (_("%B: relocation %s against STT_GNU_IFUNC "
3515 "symbol `%s' isn't handled by %s"), input_bfd
,
3516 elf_howto_table
[r_type
].name
,
3517 name
, __FUNCTION__
);
3518 bfd_set_error (bfd_error_bad_value
);
3522 /* Generate dynamic relcoation only when there is a
3523 non-GOT reference in a shared object. */
3524 if (info
->shared
&& h
->non_got_ref
)
3526 Elf_Internal_Rela outrel
;
3530 /* Need a dynamic relocation to get the real function
3532 offset
= _bfd_elf_section_offset (output_bfd
,
3536 if (offset
== (bfd_vma
) -1
3537 || offset
== (bfd_vma
) -2)
3540 outrel
.r_offset
= (input_section
->output_section
->vma
3541 + input_section
->output_offset
3544 if (h
->dynindx
== -1
3546 || info
->executable
)
3548 /* This symbol is resolved locally. */
3549 outrel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
3550 bfd_put_32 (output_bfd
,
3551 (h
->root
.u
.def
.value
3552 + h
->root
.u
.def
.section
->output_section
->vma
3553 + h
->root
.u
.def
.section
->output_offset
),
3557 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3559 sreloc
= htab
->elf
.irelifunc
;
3560 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3562 /* If this reloc is against an external symbol, we
3563 do not want to fiddle with the addend. Otherwise,
3564 we need to include the symbol value so that it
3565 becomes an addend for the dynamic reloc. For an
3566 internal symbol, we have updated addend. */
3575 base_got
= htab
->elf
.sgot
;
3576 off
= h
->got
.offset
;
3578 if (base_got
== NULL
)
3581 if (off
== (bfd_vma
) -1)
3583 /* We can't use h->got.offset here to save state, or
3584 even just remember the offset, as finish_dynamic_symbol
3585 would use that as offset into .got. */
3587 if (htab
->elf
.splt
!= NULL
)
3589 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3590 off
= (plt_index
+ 3) * 4;
3591 base_got
= htab
->elf
.sgotplt
;
3595 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3596 off
= plt_index
* 4;
3597 base_got
= htab
->elf
.igotplt
;
3600 if (h
->dynindx
== -1
3604 /* This references the local defitionion. We must
3605 initialize this entry in the global offset table.
3606 Since the offset must always be a multiple of 8,
3607 we use the least significant bit to record
3608 whether we have initialized it already.
3610 When doing a dynamic link, we create a .rela.got
3611 relocation entry to initialize the value. This
3612 is done in the finish_dynamic_symbol routine. */
3617 bfd_put_32 (output_bfd
, relocation
,
3618 base_got
->contents
+ off
);
3625 /* Adjust for static executables. */
3626 if (htab
->elf
.splt
== NULL
)
3627 relocation
+= gotplt
->output_offset
;
3631 relocation
= (base_got
->output_section
->vma
3632 + base_got
->output_offset
+ off
3633 - gotplt
->output_section
->vma
3634 - gotplt
->output_offset
);
3635 /* Adjust for static executables. */
3636 if (htab
->elf
.splt
== NULL
)
3637 relocation
+= gotplt
->output_offset
;
3643 relocation
-= (gotplt
->output_section
->vma
3644 + gotplt
->output_offset
);
3652 /* Relocation is to the entry for this symbol in the global
3654 if (htab
->elf
.sgot
== NULL
)
3661 off
= h
->got
.offset
;
3662 dyn
= htab
->elf
.dynamic_sections_created
;
3663 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3665 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3666 || (ELF_ST_VISIBILITY (h
->other
)
3667 && h
->root
.type
== bfd_link_hash_undefweak
))
3669 /* This is actually a static link, or it is a
3670 -Bsymbolic link and the symbol is defined
3671 locally, or the symbol was forced to be local
3672 because of a version file. We must initialize
3673 this entry in the global offset table. Since the
3674 offset must always be a multiple of 4, we use the
3675 least significant bit to record whether we have
3676 initialized it already.
3678 When doing a dynamic link, we create a .rel.got
3679 relocation entry to initialize the value. This
3680 is done in the finish_dynamic_symbol routine. */
3685 bfd_put_32 (output_bfd
, relocation
,
3686 htab
->elf
.sgot
->contents
+ off
);
3691 unresolved_reloc
= FALSE
;
3695 if (local_got_offsets
== NULL
)
3698 off
= local_got_offsets
[r_symndx
];
3700 /* The offset must always be a multiple of 4. We use
3701 the least significant bit to record whether we have
3702 already generated the necessary reloc. */
3707 bfd_put_32 (output_bfd
, relocation
,
3708 htab
->elf
.sgot
->contents
+ off
);
3713 Elf_Internal_Rela outrel
;
3715 s
= htab
->elf
.srelgot
;
3719 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3720 + htab
->elf
.sgot
->output_offset
3722 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3723 elf_append_rel (output_bfd
, s
, &outrel
);
3726 local_got_offsets
[r_symndx
] |= 1;
3730 if (off
>= (bfd_vma
) -2)
3733 relocation
= htab
->elf
.sgot
->output_section
->vma
3734 + htab
->elf
.sgot
->output_offset
+ off
3735 - htab
->elf
.sgotplt
->output_section
->vma
3736 - htab
->elf
.sgotplt
->output_offset
;
3740 /* Relocation is relative to the start of the global offset
3743 /* Check to make sure it isn't a protected function or data
3744 symbol for shared library since it may not be local when
3745 used as function address or with copy relocation. We also
3746 need to make sure that a symbol is referenced locally. */
3747 if (!info
->executable
&& h
)
3749 if (!h
->def_regular
)
3753 switch (ELF_ST_VISIBILITY (h
->other
))
3756 v
= _("hidden symbol");
3759 v
= _("internal symbol");
3762 v
= _("protected symbol");
3769 (*_bfd_error_handler
)
3770 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3771 input_bfd
, v
, h
->root
.root
.string
);
3772 bfd_set_error (bfd_error_bad_value
);
3775 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
3776 && (h
->type
== STT_FUNC
3777 || h
->type
== STT_OBJECT
)
3778 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3780 (*_bfd_error_handler
)
3781 (_("%B: relocation R_386_GOTOFF against protected %s `%s' can not be used when making a shared object"),
3783 h
->type
== STT_FUNC
? "function" : "data",
3784 h
->root
.root
.string
);
3785 bfd_set_error (bfd_error_bad_value
);
3790 /* Note that sgot is not involved in this
3791 calculation. We always want the start of .got.plt. If we
3792 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3793 permitted by the ABI, we might have to change this
3795 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3796 + htab
->elf
.sgotplt
->output_offset
;
3800 /* Use global offset table as symbol value. */
3801 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3802 + htab
->elf
.sgotplt
->output_offset
;
3803 unresolved_reloc
= FALSE
;
3807 /* Relocation is to the entry for this symbol in the
3808 procedure linkage table. */
3810 /* Resolve a PLT32 reloc against a local symbol directly,
3811 without using the procedure linkage table. */
3815 eh
= (struct elf_i386_link_hash_entry
*) h
;
3816 if ((h
->plt
.offset
== (bfd_vma
) -1
3817 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3818 || htab
->elf
.splt
== NULL
)
3820 /* We didn't make a PLT entry for this symbol. This
3821 happens when statically linking PIC code, or when
3822 using -Bsymbolic. */
3826 if (h
->plt
.offset
!= (bfd_vma
) -1)
3828 resolved_plt
= htab
->elf
.splt
;
3829 plt_offset
= h
->plt
.offset
;
3833 resolved_plt
= htab
->plt_got
;
3834 plt_offset
= eh
->plt_got
.offset
;
3837 relocation
= (resolved_plt
->output_section
->vma
3838 + resolved_plt
->output_offset
3840 unresolved_reloc
= FALSE
;
3844 /* Set to symbol size. */
3845 relocation
= st_size
;
3850 if ((input_section
->flags
& SEC_ALLOC
) == 0
3856 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3857 || h
->root
.type
!= bfd_link_hash_undefweak
)
3858 && ((r_type
!= R_386_PC32
&& r_type
!= R_386_SIZE32
)
3859 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3860 || (ELIMINATE_COPY_RELOCS
3867 || h
->root
.type
== bfd_link_hash_undefweak
3868 || h
->root
.type
== bfd_link_hash_undefined
)))
3870 Elf_Internal_Rela outrel
;
3871 bfd_boolean skip
, relocate
;
3874 /* When generating a shared object, these relocations
3875 are copied into the output file to be resolved at run
3882 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3884 if (outrel
.r_offset
== (bfd_vma
) -1)
3886 else if (outrel
.r_offset
== (bfd_vma
) -2)
3887 skip
= TRUE
, relocate
= TRUE
;
3888 outrel
.r_offset
+= (input_section
->output_section
->vma
3889 + input_section
->output_offset
);
3892 memset (&outrel
, 0, sizeof outrel
);
3895 && (r_type
== R_386_PC32
3897 || !SYMBOLIC_BIND (info
, h
)
3898 || !h
->def_regular
))
3899 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3902 /* This symbol is local, or marked to become local. */
3904 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3907 sreloc
= elf_section_data (input_section
)->sreloc
;
3909 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3911 r
= bfd_reloc_notsupported
;
3912 goto check_relocation_error
;
3915 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3917 /* If this reloc is against an external symbol, we do
3918 not want to fiddle with the addend. Otherwise, we
3919 need to include the symbol value so that it becomes
3920 an addend for the dynamic reloc. */
3927 if (!info
->executable
)
3929 Elf_Internal_Rela outrel
;
3932 outrel
.r_offset
= rel
->r_offset
3933 + input_section
->output_section
->vma
3934 + input_section
->output_offset
;
3935 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3936 sreloc
= elf_section_data (input_section
)->sreloc
;
3939 elf_append_rel (output_bfd
, sreloc
, &outrel
);
3944 case R_386_TLS_GOTDESC
:
3945 case R_386_TLS_DESC_CALL
:
3946 case R_386_TLS_IE_32
:
3947 case R_386_TLS_GOTIE
:
3948 tls_type
= GOT_UNKNOWN
;
3949 if (h
== NULL
&& local_got_offsets
)
3950 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
3952 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
3953 if (tls_type
== GOT_TLS_IE
)
3954 tls_type
= GOT_TLS_IE_NEG
;
3956 if (! elf_i386_tls_transition (info
, input_bfd
,
3957 input_section
, contents
,
3958 symtab_hdr
, sym_hashes
,
3959 &r_type
, tls_type
, rel
,
3960 relend
, h
, r_symndx
))
3963 if (r_type
== R_386_TLS_LE_32
)
3965 BFD_ASSERT (! unresolved_reloc
);
3966 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3971 /* GD->LE transition. */
3972 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3975 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3977 movl %gs:0, %eax; subl $foo@tpoff, %eax
3978 (6 byte form of subl). */
3979 memcpy (contents
+ rel
->r_offset
- 3,
3980 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3981 roff
= rel
->r_offset
+ 5;
3985 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3987 movl %gs:0, %eax; subl $foo@tpoff, %eax
3988 (6 byte form of subl). */
3989 memcpy (contents
+ rel
->r_offset
- 2,
3990 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3991 roff
= rel
->r_offset
+ 6;
3993 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
3995 /* Skip R_386_PC32/R_386_PLT32. */
3999 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4001 /* GDesc -> LE transition.
4002 It's originally something like:
4003 leal x@tlsdesc(%ebx), %eax
4007 Registers other than %eax may be set up here. */
4012 roff
= rel
->r_offset
;
4013 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4015 /* Now modify the instruction as appropriate. */
4016 /* aoliva FIXME: remove the above and xor the byte
4018 bfd_put_8 (output_bfd
, val
^ 0x86,
4019 contents
+ roff
- 1);
4020 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4024 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4026 /* GDesc -> LE transition.
4034 roff
= rel
->r_offset
;
4035 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4036 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4039 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
4043 /* IE->LE transition:
4044 Originally it can be one of:
4052 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4055 /* movl foo, %eax. */
4056 bfd_put_8 (output_bfd
, 0xb8,
4057 contents
+ rel
->r_offset
- 1);
4063 type
= bfd_get_8 (input_bfd
,
4064 contents
+ rel
->r_offset
- 2);
4069 bfd_put_8 (output_bfd
, 0xc7,
4070 contents
+ rel
->r_offset
- 2);
4071 bfd_put_8 (output_bfd
,
4072 0xc0 | ((val
>> 3) & 7),
4073 contents
+ rel
->r_offset
- 1);
4077 bfd_put_8 (output_bfd
, 0x81,
4078 contents
+ rel
->r_offset
- 2);
4079 bfd_put_8 (output_bfd
,
4080 0xc0 | ((val
>> 3) & 7),
4081 contents
+ rel
->r_offset
- 1);
4088 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4089 contents
+ rel
->r_offset
);
4094 unsigned int val
, type
;
4096 /* {IE_32,GOTIE}->LE transition:
4097 Originally it can be one of:
4098 subl foo(%reg1), %reg2
4099 movl foo(%reg1), %reg2
4100 addl foo(%reg1), %reg2
4103 movl $foo, %reg2 (6 byte form)
4104 addl $foo, %reg2. */
4105 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4106 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4110 bfd_put_8 (output_bfd
, 0xc7,
4111 contents
+ rel
->r_offset
- 2);
4112 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4113 contents
+ rel
->r_offset
- 1);
4115 else if (type
== 0x2b)
4118 bfd_put_8 (output_bfd
, 0x81,
4119 contents
+ rel
->r_offset
- 2);
4120 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
4121 contents
+ rel
->r_offset
- 1);
4123 else if (type
== 0x03)
4126 bfd_put_8 (output_bfd
, 0x81,
4127 contents
+ rel
->r_offset
- 2);
4128 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4129 contents
+ rel
->r_offset
- 1);
4133 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
4134 bfd_put_32 (output_bfd
, -elf_i386_tpoff (info
, relocation
),
4135 contents
+ rel
->r_offset
);
4137 bfd_put_32 (output_bfd
, elf_i386_tpoff (info
, relocation
),
4138 contents
+ rel
->r_offset
);
4143 if (htab
->elf
.sgot
== NULL
)
4148 off
= h
->got
.offset
;
4149 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
4153 if (local_got_offsets
== NULL
)
4156 off
= local_got_offsets
[r_symndx
];
4157 offplt
= local_tlsdesc_gotents
[r_symndx
];
4164 Elf_Internal_Rela outrel
;
4168 if (htab
->elf
.srelgot
== NULL
)
4171 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4173 if (GOT_TLS_GDESC_P (tls_type
))
4176 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
4177 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
4178 <= htab
->elf
.sgotplt
->size
);
4179 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4180 + htab
->elf
.sgotplt
->output_offset
4182 + htab
->sgotplt_jump_table_size
);
4183 sreloc
= htab
->elf
.srelplt
;
4184 loc
= sreloc
->contents
;
4185 loc
+= (htab
->next_tls_desc_index
++
4186 * sizeof (Elf32_External_Rel
));
4187 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
4188 <= sreloc
->contents
+ sreloc
->size
);
4189 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
4192 BFD_ASSERT (! unresolved_reloc
);
4193 bfd_put_32 (output_bfd
,
4194 relocation
- elf_i386_dtpoff_base (info
),
4195 htab
->elf
.sgotplt
->contents
+ offplt
4196 + htab
->sgotplt_jump_table_size
+ 4);
4200 bfd_put_32 (output_bfd
, 0,
4201 htab
->elf
.sgotplt
->contents
+ offplt
4202 + htab
->sgotplt_jump_table_size
+ 4);
4206 sreloc
= htab
->elf
.srelgot
;
4208 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4209 + htab
->elf
.sgot
->output_offset
+ off
);
4211 if (GOT_TLS_GD_P (tls_type
))
4212 dr_type
= R_386_TLS_DTPMOD32
;
4213 else if (GOT_TLS_GDESC_P (tls_type
))
4215 else if (tls_type
== GOT_TLS_IE_POS
)
4216 dr_type
= R_386_TLS_TPOFF
;
4218 dr_type
= R_386_TLS_TPOFF32
;
4220 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
4221 bfd_put_32 (output_bfd
,
4222 relocation
- elf_i386_dtpoff_base (info
),
4223 htab
->elf
.sgot
->contents
+ off
);
4224 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
4225 bfd_put_32 (output_bfd
,
4226 elf_i386_dtpoff_base (info
) - relocation
,
4227 htab
->elf
.sgot
->contents
+ off
);
4228 else if (dr_type
!= R_386_TLS_DESC
)
4229 bfd_put_32 (output_bfd
, 0,
4230 htab
->elf
.sgot
->contents
+ off
);
4231 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
4233 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4235 if (GOT_TLS_GD_P (tls_type
))
4239 BFD_ASSERT (! unresolved_reloc
);
4240 bfd_put_32 (output_bfd
,
4241 relocation
- elf_i386_dtpoff_base (info
),
4242 htab
->elf
.sgot
->contents
+ off
+ 4);
4246 bfd_put_32 (output_bfd
, 0,
4247 htab
->elf
.sgot
->contents
+ off
+ 4);
4248 outrel
.r_info
= ELF32_R_INFO (indx
,
4249 R_386_TLS_DTPOFF32
);
4250 outrel
.r_offset
+= 4;
4251 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4254 else if (tls_type
== GOT_TLS_IE_BOTH
)
4256 bfd_put_32 (output_bfd
,
4258 ? relocation
- elf_i386_dtpoff_base (info
)
4260 htab
->elf
.sgot
->contents
+ off
+ 4);
4261 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4262 outrel
.r_offset
+= 4;
4263 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4270 local_got_offsets
[r_symndx
] |= 1;
4273 if (off
>= (bfd_vma
) -2
4274 && ! GOT_TLS_GDESC_P (tls_type
))
4276 if (r_type
== R_386_TLS_GOTDESC
4277 || r_type
== R_386_TLS_DESC_CALL
)
4279 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
4280 unresolved_reloc
= FALSE
;
4282 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4284 bfd_vma g_o_t
= htab
->elf
.sgotplt
->output_section
->vma
4285 + htab
->elf
.sgotplt
->output_offset
;
4286 relocation
= htab
->elf
.sgot
->output_section
->vma
4287 + htab
->elf
.sgot
->output_offset
+ off
- g_o_t
;
4288 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
4289 && tls_type
== GOT_TLS_IE_BOTH
)
4291 if (r_type
== R_386_TLS_IE
)
4292 relocation
+= g_o_t
;
4293 unresolved_reloc
= FALSE
;
4295 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
4297 unsigned int val
, type
;
4300 /* GD->IE transition. */
4301 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
4302 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
4305 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
4307 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4309 roff
= rel
->r_offset
- 3;
4313 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
4315 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
4316 roff
= rel
->r_offset
- 2;
4318 memcpy (contents
+ roff
,
4319 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4320 contents
[roff
+ 7] = 0x80 | (val
& 7);
4321 /* If foo is used only with foo@gotntpoff(%reg) and
4322 foo@indntpoff, but not with foo@gottpoff(%reg), change
4323 subl $foo@gottpoff(%reg), %eax
4325 addl $foo@gotntpoff(%reg), %eax. */
4326 if (tls_type
== GOT_TLS_IE_POS
)
4327 contents
[roff
+ 6] = 0x03;
4328 bfd_put_32 (output_bfd
,
4329 htab
->elf
.sgot
->output_section
->vma
4330 + htab
->elf
.sgot
->output_offset
+ off
4331 - htab
->elf
.sgotplt
->output_section
->vma
4332 - htab
->elf
.sgotplt
->output_offset
,
4333 contents
+ roff
+ 8);
4334 /* Skip R_386_PLT32. */
4338 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
4340 /* GDesc -> IE transition.
4341 It's originally something like:
4342 leal x@tlsdesc(%ebx), %eax
4345 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
4347 movl x@gottpoff(%ebx), %eax # before negl %eax
4349 Registers other than %eax may be set up here. */
4353 /* First, make sure it's a leal adding ebx to a 32-bit
4354 offset into any register, although it's probably
4355 almost always going to be eax. */
4356 roff
= rel
->r_offset
;
4358 /* Now modify the instruction as appropriate. */
4359 /* To turn a leal into a movl in the form we use it, it
4360 suffices to change the first byte from 0x8d to 0x8b.
4361 aoliva FIXME: should we decide to keep the leal, all
4362 we have to do is remove the statement below, and
4363 adjust the relaxation of R_386_TLS_DESC_CALL. */
4364 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4366 if (tls_type
== GOT_TLS_IE_BOTH
)
4369 bfd_put_32 (output_bfd
,
4370 htab
->elf
.sgot
->output_section
->vma
4371 + htab
->elf
.sgot
->output_offset
+ off
4372 - htab
->elf
.sgotplt
->output_section
->vma
4373 - htab
->elf
.sgotplt
->output_offset
,
4377 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
4379 /* GDesc -> IE transition.
4387 depending on how we transformed the TLS_GOTDESC above.
4392 roff
= rel
->r_offset
;
4394 /* Now modify the instruction as appropriate. */
4395 if (tls_type
!= GOT_TLS_IE_NEG
)
4398 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4399 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4404 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
4405 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
4415 if (! elf_i386_tls_transition (info
, input_bfd
,
4416 input_section
, contents
,
4417 symtab_hdr
, sym_hashes
,
4418 &r_type
, GOT_UNKNOWN
, rel
,
4419 relend
, h
, r_symndx
))
4422 if (r_type
!= R_386_TLS_LDM
)
4424 /* LD->LE transition:
4425 leal foo(%reg), %eax; call ___tls_get_addr.
4427 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
4428 BFD_ASSERT (r_type
== R_386_TLS_LE_32
);
4429 memcpy (contents
+ rel
->r_offset
- 2,
4430 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
4431 /* Skip R_386_PC32/R_386_PLT32. */
4436 if (htab
->elf
.sgot
== NULL
)
4439 off
= htab
->tls_ldm_got
.offset
;
4444 Elf_Internal_Rela outrel
;
4446 if (htab
->elf
.srelgot
== NULL
)
4449 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4450 + htab
->elf
.sgot
->output_offset
+ off
);
4452 bfd_put_32 (output_bfd
, 0,
4453 htab
->elf
.sgot
->contents
+ off
);
4454 bfd_put_32 (output_bfd
, 0,
4455 htab
->elf
.sgot
->contents
+ off
+ 4);
4456 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
4457 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &outrel
);
4458 htab
->tls_ldm_got
.offset
|= 1;
4460 relocation
= htab
->elf
.sgot
->output_section
->vma
4461 + htab
->elf
.sgot
->output_offset
+ off
4462 - htab
->elf
.sgotplt
->output_section
->vma
4463 - htab
->elf
.sgotplt
->output_offset
;
4464 unresolved_reloc
= FALSE
;
4467 case R_386_TLS_LDO_32
:
4468 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4469 relocation
-= elf_i386_dtpoff_base (info
);
4471 /* When converting LDO to LE, we must negate. */
4472 relocation
= -elf_i386_tpoff (info
, relocation
);
4475 case R_386_TLS_LE_32
:
4477 if (!info
->executable
)
4479 Elf_Internal_Rela outrel
;
4482 outrel
.r_offset
= rel
->r_offset
4483 + input_section
->output_section
->vma
4484 + input_section
->output_offset
;
4485 if (h
!= NULL
&& h
->dynindx
!= -1)
4489 if (r_type
== R_386_TLS_LE_32
)
4490 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
4492 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
4493 sreloc
= elf_section_data (input_section
)->sreloc
;
4496 elf_append_rel (output_bfd
, sreloc
, &outrel
);
4499 else if (r_type
== R_386_TLS_LE_32
)
4500 relocation
= elf_i386_dtpoff_base (info
) - relocation
;
4502 relocation
-= elf_i386_dtpoff_base (info
);
4504 else if (r_type
== R_386_TLS_LE_32
)
4505 relocation
= elf_i386_tpoff (info
, relocation
);
4507 relocation
= -elf_i386_tpoff (info
, relocation
);
4514 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4515 because such sections are not SEC_ALLOC and thus ld.so will
4516 not process them. */
4517 if (unresolved_reloc
4518 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4520 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4521 rel
->r_offset
) != (bfd_vma
) -1)
4523 (*_bfd_error_handler
)
4524 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4527 (long) rel
->r_offset
,
4529 h
->root
.root
.string
);
4534 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4535 contents
, rel
->r_offset
,
4538 check_relocation_error
:
4539 if (r
!= bfd_reloc_ok
)
4544 name
= h
->root
.root
.string
;
4547 name
= bfd_elf_string_from_elf_section (input_bfd
,
4548 symtab_hdr
->sh_link
,
4553 name
= bfd_section_name (input_bfd
, sec
);
4556 if (r
== bfd_reloc_overflow
)
4558 if (! ((*info
->callbacks
->reloc_overflow
)
4559 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4560 (bfd_vma
) 0, input_bfd
, input_section
,
4566 (*_bfd_error_handler
)
4567 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4568 input_bfd
, input_section
,
4569 (long) rel
->r_offset
, name
, (int) r
);
4578 /* Finish up dynamic symbol handling. We set the contents of various
4579 dynamic sections here. */
4582 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
4583 struct bfd_link_info
*info
,
4584 struct elf_link_hash_entry
*h
,
4585 Elf_Internal_Sym
*sym
)
4587 struct elf_i386_link_hash_table
*htab
;
4588 unsigned plt_entry_size
;
4589 const struct elf_i386_backend_data
*abed
;
4590 struct elf_i386_link_hash_entry
*eh
;
4592 htab
= elf_i386_hash_table (info
);
4596 abed
= get_elf_i386_backend_data (output_bfd
);
4597 plt_entry_size
= GET_PLT_ENTRY_SIZE (output_bfd
);
4599 eh
= (struct elf_i386_link_hash_entry
*) h
;
4601 if (h
->plt
.offset
!= (bfd_vma
) -1)
4605 Elf_Internal_Rela rel
;
4607 asection
*plt
, *gotplt
, *relplt
;
4609 /* When building a static executable, use .iplt, .igot.plt and
4610 .rel.iplt sections for STT_GNU_IFUNC symbols. */
4611 if (htab
->elf
.splt
!= NULL
)
4613 plt
= htab
->elf
.splt
;
4614 gotplt
= htab
->elf
.sgotplt
;
4615 relplt
= htab
->elf
.srelplt
;
4619 plt
= htab
->elf
.iplt
;
4620 gotplt
= htab
->elf
.igotplt
;
4621 relplt
= htab
->elf
.irelplt
;
4624 /* This symbol has an entry in the procedure linkage table. Set
4627 if ((h
->dynindx
== -1
4628 && !((h
->forced_local
|| info
->executable
)
4630 && h
->type
== STT_GNU_IFUNC
))
4636 /* Get the index in the procedure linkage table which
4637 corresponds to this symbol. This is the index of this symbol
4638 in all the symbols for which we are making plt entries. The
4639 first entry in the procedure linkage table is reserved.
4641 Get the offset into the .got table of the entry that
4642 corresponds to this function. Each .got entry is 4 bytes.
4643 The first three are reserved.
4645 For static executables, we don't reserve anything. */
4647 if (plt
== htab
->elf
.splt
)
4649 got_offset
= h
->plt
.offset
/ plt_entry_size
- 1;
4650 got_offset
= (got_offset
+ 3) * 4;
4654 got_offset
= h
->plt
.offset
/ plt_entry_size
;
4655 got_offset
= got_offset
* 4;
4658 /* Fill in the entry in the procedure linkage table. */
4661 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->plt_entry
,
4662 abed
->plt
->plt_entry_size
);
4663 bfd_put_32 (output_bfd
,
4664 (gotplt
->output_section
->vma
4665 + gotplt
->output_offset
4667 plt
->contents
+ h
->plt
.offset
4668 + abed
->plt
->plt_got_offset
);
4670 if (abed
->is_vxworks
)
4672 int s
, k
, reloc_index
;
4674 /* Create the R_386_32 relocation referencing the GOT
4675 for this PLT entry. */
4677 /* S: Current slot number (zero-based). */
4678 s
= ((h
->plt
.offset
- abed
->plt
->plt_entry_size
)
4679 / abed
->plt
->plt_entry_size
);
4680 /* K: Number of relocations for PLTResolve. */
4682 k
= PLTRESOLVE_RELOCS_SHLIB
;
4684 k
= PLTRESOLVE_RELOCS
;
4685 /* Skip the PLTresolve relocations, and the relocations for
4686 the other PLT slots. */
4687 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
4688 loc
= (htab
->srelplt2
->contents
+ reloc_index
4689 * sizeof (Elf32_External_Rel
));
4691 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
4692 + htab
->elf
.splt
->output_offset
4693 + h
->plt
.offset
+ 2),
4694 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
4695 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4697 /* Create the R_386_32 relocation referencing the beginning of
4698 the PLT for this GOT entry. */
4699 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4700 + htab
->elf
.sgotplt
->output_offset
4702 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
4703 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
4704 loc
+ sizeof (Elf32_External_Rel
));
4709 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt
->pic_plt_entry
,
4710 abed
->plt
->plt_entry_size
);
4711 bfd_put_32 (output_bfd
, got_offset
,
4712 plt
->contents
+ h
->plt
.offset
4713 + abed
->plt
->plt_got_offset
);
4716 /* Fill in the entry in the global offset table. */
4717 bfd_put_32 (output_bfd
,
4718 (plt
->output_section
->vma
4719 + plt
->output_offset
4721 + abed
->plt
->plt_lazy_offset
),
4722 gotplt
->contents
+ got_offset
);
4724 /* Fill in the entry in the .rel.plt section. */
4725 rel
.r_offset
= (gotplt
->output_section
->vma
4726 + gotplt
->output_offset
4728 if (h
->dynindx
== -1
4729 || ((info
->executable
4730 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4732 && h
->type
== STT_GNU_IFUNC
))
4734 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4735 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4736 in the .got.plt section. */
4737 bfd_put_32 (output_bfd
,
4738 (h
->root
.u
.def
.value
4739 + h
->root
.u
.def
.section
->output_section
->vma
4740 + h
->root
.u
.def
.section
->output_offset
),
4741 gotplt
->contents
+ got_offset
);
4742 rel
.r_info
= ELF32_R_INFO (0, R_386_IRELATIVE
);
4743 /* R_386_IRELATIVE comes last. */
4744 plt_index
= htab
->next_irelative_index
--;
4748 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
4749 plt_index
= htab
->next_jump_slot_index
++;
4751 loc
= relplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
4752 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
4754 /* Don't fill PLT entry for static executables. */
4755 if (plt
== htab
->elf
.splt
)
4757 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
4758 plt
->contents
+ h
->plt
.offset
4759 + abed
->plt
->plt_reloc_offset
);
4760 bfd_put_32 (output_bfd
, - (h
->plt
.offset
4761 + abed
->plt
->plt_plt_offset
+ 4),
4762 plt
->contents
+ h
->plt
.offset
4763 + abed
->plt
->plt_plt_offset
);
4766 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4768 bfd_vma got_offset
, plt_offset
;
4769 asection
*plt
, *got
, *gotplt
;
4770 const bfd_byte
*got_plt_entry
;
4772 /* Offset of displacement of the indirect jump. */
4773 bfd_vma plt_got_offset
= 2;
4775 /* Set the entry in the GOT procedure linkage table. */
4776 plt
= htab
->plt_got
;
4777 got
= htab
->elf
.sgot
;
4778 gotplt
= htab
->elf
.sgotplt
;
4779 got_offset
= h
->got
.offset
;
4781 if (got_offset
== (bfd_vma
) -1
4787 /* Fill in the entry in the GOT procedure linkage table. */
4790 got_plt_entry
= elf_i386_got_plt_entry
;
4791 got_offset
+= got
->output_section
->vma
+ got
->output_offset
;
4795 got_plt_entry
= elf_i386_pic_got_plt_entry
;
4796 got_offset
+= (got
->output_section
->vma
4797 + got
->output_offset
4798 - gotplt
->output_section
->vma
4799 - gotplt
->output_offset
);
4802 plt_offset
= eh
->plt_got
.offset
;
4803 memcpy (plt
->contents
+ plt_offset
, got_plt_entry
,
4804 sizeof (elf_i386_got_plt_entry
));
4805 bfd_put_32 (output_bfd
, got_offset
,
4806 plt
->contents
+ plt_offset
+ plt_got_offset
);
4810 && (h
->plt
.offset
!= (bfd_vma
) -1
4811 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4813 /* Mark the symbol as undefined, rather than as defined in
4814 the .plt section. Leave the value if there were any
4815 relocations where pointer equality matters (this is a clue
4816 for the dynamic linker, to make function pointer
4817 comparisons work between an application and shared
4818 library), otherwise set it to zero. If a function is only
4819 called from a binary, there is no need to slow down
4820 shared libraries because of that. */
4821 sym
->st_shndx
= SHN_UNDEF
;
4822 if (!h
->pointer_equality_needed
)
4826 if (h
->got
.offset
!= (bfd_vma
) -1
4827 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
4828 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
4830 Elf_Internal_Rela rel
;
4832 /* This symbol has an entry in the global offset table. Set it
4835 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4838 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4839 + htab
->elf
.sgot
->output_offset
4840 + (h
->got
.offset
& ~(bfd_vma
) 1));
4842 /* If this is a static link, or it is a -Bsymbolic link and the
4843 symbol is defined locally or was forced to be local because
4844 of a version file, we just want to emit a RELATIVE reloc.
4845 The entry in the global offset table will already have been
4846 initialized in the relocate_section function. */
4848 && h
->type
== STT_GNU_IFUNC
)
4852 /* Generate R_386_GLOB_DAT. */
4859 if (!h
->pointer_equality_needed
)
4862 /* For non-shared object, we can't use .got.plt, which
4863 contains the real function addres if we need pointer
4864 equality. We load the GOT entry with the PLT entry. */
4865 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4866 bfd_put_32 (output_bfd
,
4867 (plt
->output_section
->vma
4868 + plt
->output_offset
+ h
->plt
.offset
),
4869 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4873 else if (info
->shared
4874 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4876 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4877 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
4881 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4883 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4884 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4885 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
4888 elf_append_rel (output_bfd
, htab
->elf
.srelgot
, &rel
);
4893 Elf_Internal_Rela rel
;
4895 /* This symbol needs a copy reloc. Set it up. */
4897 if (h
->dynindx
== -1
4898 || (h
->root
.type
!= bfd_link_hash_defined
4899 && h
->root
.type
!= bfd_link_hash_defweak
)
4900 || htab
->srelbss
== NULL
)
4903 rel
.r_offset
= (h
->root
.u
.def
.value
4904 + h
->root
.u
.def
.section
->output_section
->vma
4905 + h
->root
.u
.def
.section
->output_offset
);
4906 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
4907 elf_append_rel (output_bfd
, htab
->srelbss
, &rel
);
4913 /* Finish up local dynamic symbol handling. We set the contents of
4914 various dynamic sections here. */
4917 elf_i386_finish_local_dynamic_symbol (void **slot
, void *inf
)
4919 struct elf_link_hash_entry
*h
4920 = (struct elf_link_hash_entry
*) *slot
;
4921 struct bfd_link_info
*info
4922 = (struct bfd_link_info
*) inf
;
4924 return elf_i386_finish_dynamic_symbol (info
->output_bfd
, info
,
4928 /* Used to decide how to sort relocs in an optimal manner for the
4929 dynamic linker, before writing them out. */
4931 static enum elf_reloc_type_class
4932 elf_i386_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4933 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4934 const Elf_Internal_Rela
*rela
)
4936 switch (ELF32_R_TYPE (rela
->r_info
))
4938 case R_386_RELATIVE
:
4939 return reloc_class_relative
;
4940 case R_386_JUMP_SLOT
:
4941 return reloc_class_plt
;
4943 return reloc_class_copy
;
4945 return reloc_class_normal
;
4949 /* Finish up the dynamic sections. */
4952 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
4953 struct bfd_link_info
*info
)
4955 struct elf_i386_link_hash_table
*htab
;
4958 const struct elf_i386_backend_data
*abed
;
4960 htab
= elf_i386_hash_table (info
);
4964 dynobj
= htab
->elf
.dynobj
;
4965 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4966 abed
= get_elf_i386_backend_data (output_bfd
);
4968 if (htab
->elf
.dynamic_sections_created
)
4970 Elf32_External_Dyn
*dyncon
, *dynconend
;
4972 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4975 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4976 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4977 for (; dyncon
< dynconend
; dyncon
++)
4979 Elf_Internal_Dyn dyn
;
4982 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4987 if (abed
->is_vxworks
4988 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
4993 s
= htab
->elf
.sgotplt
;
4994 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4998 s
= htab
->elf
.srelplt
;
4999 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5003 s
= htab
->elf
.srelplt
;
5004 dyn
.d_un
.d_val
= s
->size
;
5008 /* My reading of the SVR4 ABI indicates that the
5009 procedure linkage table relocs (DT_JMPREL) should be
5010 included in the overall relocs (DT_REL). This is
5011 what Solaris does. However, UnixWare can not handle
5012 that case. Therefore, we override the DT_RELSZ entry
5013 here to make it not include the JMPREL relocs. */
5014 s
= htab
->elf
.srelplt
;
5017 dyn
.d_un
.d_val
-= s
->size
;
5021 /* We may not be using the standard ELF linker script.
5022 If .rel.plt is the first .rel section, we adjust
5023 DT_REL to not include it. */
5024 s
= htab
->elf
.srelplt
;
5027 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
5029 dyn
.d_un
.d_ptr
+= s
->size
;
5033 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5036 /* Fill in the first entry in the procedure linkage table. */
5037 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5041 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->pic_plt0_entry
,
5042 abed
->plt
->plt0_entry_size
);
5043 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5044 abed
->plt0_pad_byte
,
5045 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5049 memcpy (htab
->elf
.splt
->contents
, abed
->plt
->plt0_entry
,
5050 abed
->plt
->plt0_entry_size
);
5051 memset (htab
->elf
.splt
->contents
+ abed
->plt
->plt0_entry_size
,
5052 abed
->plt0_pad_byte
,
5053 abed
->plt
->plt_entry_size
- abed
->plt
->plt0_entry_size
);
5054 bfd_put_32 (output_bfd
,
5055 (htab
->elf
.sgotplt
->output_section
->vma
5056 + htab
->elf
.sgotplt
->output_offset
5058 htab
->elf
.splt
->contents
5059 + abed
->plt
->plt0_got1_offset
);
5060 bfd_put_32 (output_bfd
,
5061 (htab
->elf
.sgotplt
->output_section
->vma
5062 + htab
->elf
.sgotplt
->output_offset
5064 htab
->elf
.splt
->contents
5065 + abed
->plt
->plt0_got2_offset
);
5067 if (abed
->is_vxworks
)
5069 Elf_Internal_Rela rel
;
5071 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
5072 On IA32 we use REL relocations so the addend goes in
5073 the PLT directly. */
5074 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5075 + htab
->elf
.splt
->output_offset
5076 + abed
->plt
->plt0_got1_offset
);
5077 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5078 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5079 htab
->srelplt2
->contents
);
5080 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
5081 rel
.r_offset
= (htab
->elf
.splt
->output_section
->vma
5082 + htab
->elf
.splt
->output_offset
5083 + abed
->plt
->plt0_got2_offset
);
5084 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5085 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
5086 htab
->srelplt2
->contents
+
5087 sizeof (Elf32_External_Rel
));
5091 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5092 really seem like the right value. */
5093 elf_section_data (htab
->elf
.splt
->output_section
)
5094 ->this_hdr
.sh_entsize
= 4;
5096 /* Correct the .rel.plt.unloaded relocations. */
5097 if (abed
->is_vxworks
&& !info
->shared
)
5099 int num_plts
= (htab
->elf
.splt
->size
5100 / abed
->plt
->plt_entry_size
) - 1;
5103 p
= htab
->srelplt2
->contents
;
5105 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
5107 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
5109 for (; num_plts
; num_plts
--)
5111 Elf_Internal_Rela rel
;
5112 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5113 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
5114 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5115 p
+= sizeof (Elf32_External_Rel
);
5117 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
5118 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
5119 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
5120 p
+= sizeof (Elf32_External_Rel
);
5126 if (htab
->elf
.sgotplt
)
5128 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5130 (*_bfd_error_handler
)
5131 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5135 /* Fill in the first three entries in the global offset table. */
5136 if (htab
->elf
.sgotplt
->size
> 0)
5138 bfd_put_32 (output_bfd
,
5140 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
5141 htab
->elf
.sgotplt
->contents
);
5142 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 4);
5143 bfd_put_32 (output_bfd
, 0, htab
->elf
.sgotplt
->contents
+ 8);
5146 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
5149 /* Adjust .eh_frame for .plt section. */
5150 if (htab
->plt_eh_frame
!= NULL
5151 && htab
->plt_eh_frame
->contents
!= NULL
)
5153 if (htab
->elf
.splt
!= NULL
5154 && htab
->elf
.splt
->size
!= 0
5155 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5156 && htab
->elf
.splt
->output_section
!= NULL
5157 && htab
->plt_eh_frame
->output_section
!= NULL
)
5159 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5160 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5161 + htab
->plt_eh_frame
->output_offset
5162 + PLT_FDE_START_OFFSET
;
5163 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5164 htab
->plt_eh_frame
->contents
5165 + PLT_FDE_START_OFFSET
);
5167 if (htab
->plt_eh_frame
->sec_info_type
5168 == SEC_INFO_TYPE_EH_FRAME
)
5170 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5172 htab
->plt_eh_frame
->contents
))
5177 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5178 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5180 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5181 htab_traverse (htab
->loc_hash_table
,
5182 elf_i386_finish_local_dynamic_symbol
,
5188 /* Return an array of PLT entry symbol values. */
5191 elf_i386_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
5194 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
5197 bfd_vma
*plt_sym_val
;
5199 bfd_byte
*plt_contents
;
5200 const struct elf_i386_backend_data
*bed
5201 = get_elf_i386_backend_data (abfd
);
5202 Elf_Internal_Shdr
*hdr
;
5204 /* Get the .plt section contents. */
5205 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
5206 if (plt_contents
== NULL
)
5208 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
5209 plt_contents
, 0, plt
->size
))
5212 free (plt_contents
);
5216 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
5217 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
5220 hdr
= &elf_section_data (relplt
)->this_hdr
;
5221 count
= relplt
->size
/ hdr
->sh_entsize
;
5223 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
5224 if (plt_sym_val
== NULL
)
5227 for (i
= 0; i
< count
; i
++)
5228 plt_sym_val
[i
] = -1;
5230 plt_offset
= bed
->plt
->plt_entry_size
;
5231 p
= relplt
->relocation
;
5232 for (i
= 0; i
< count
; i
++, p
++)
5236 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
5237 if (p
->howto
== NULL
)
5240 if (p
->howto
->type
!= R_386_JUMP_SLOT
5241 && p
->howto
->type
!= R_386_IRELATIVE
)
5244 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
5245 + bed
->plt
->plt_reloc_offset
));
5246 reloc_index
/= sizeof (Elf32_External_Rel
);
5247 if (reloc_index
>= count
)
5249 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
5250 plt_offset
+= bed
->plt
->plt_entry_size
;
5253 free (plt_contents
);
5258 /* Similar to _bfd_elf_get_synthetic_symtab. */
5261 elf_i386_get_synthetic_symtab (bfd
*abfd
,
5268 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt");
5269 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
5270 dynsymcount
, dynsyms
, ret
,
5272 elf_i386_get_plt_sym_val
);
5275 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5278 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
5280 if (h
->plt
.offset
!= (bfd_vma
) -1
5282 && !h
->pointer_equality_needed
)
5285 return _bfd_elf_hash_symbol (h
);
5288 /* Hook called by the linker routine which adds symbols from an object
5292 elf_i386_add_symbol_hook (bfd
* abfd
,
5293 struct bfd_link_info
* info
,
5294 Elf_Internal_Sym
* sym
,
5295 const char ** namep ATTRIBUTE_UNUSED
,
5296 flagword
* flagsp ATTRIBUTE_UNUSED
,
5297 asection
** secp ATTRIBUTE_UNUSED
,
5298 bfd_vma
* valp ATTRIBUTE_UNUSED
)
5300 if ((ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
5301 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
)
5302 && (abfd
->flags
& DYNAMIC
) == 0
5303 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
5304 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
5309 #define TARGET_LITTLE_SYM i386_elf32_vec
5310 #define TARGET_LITTLE_NAME "elf32-i386"
5311 #define ELF_ARCH bfd_arch_i386
5312 #define ELF_TARGET_ID I386_ELF_DATA
5313 #define ELF_MACHINE_CODE EM_386
5314 #define ELF_MAXPAGESIZE 0x1000
5316 #define elf_backend_can_gc_sections 1
5317 #define elf_backend_can_refcount 1
5318 #define elf_backend_want_got_plt 1
5319 #define elf_backend_plt_readonly 1
5320 #define elf_backend_want_plt_sym 0
5321 #define elf_backend_got_header_size 12
5322 #define elf_backend_plt_alignment 4
5323 #define elf_backend_extern_protected_data 1
5325 /* Support RELA for objdump of prelink objects. */
5326 #define elf_info_to_howto elf_i386_info_to_howto_rel
5327 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
5329 #define bfd_elf32_mkobject elf_i386_mkobject
5331 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
5332 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
5333 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
5334 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
5335 #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
5337 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
5338 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
5339 #define elf_backend_check_relocs elf_i386_check_relocs
5340 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
5341 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
5342 #define elf_backend_fake_sections elf_i386_fake_sections
5343 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
5344 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
5345 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
5346 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
5347 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
5348 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
5349 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
5350 #define elf_backend_relocate_section elf_i386_relocate_section
5351 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
5352 #define elf_backend_always_size_sections elf_i386_always_size_sections
5353 #define elf_backend_omit_section_dynsym \
5354 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
5355 #define elf_backend_hash_symbol elf_i386_hash_symbol
5356 #define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
5358 #include "elf32-target.h"
5360 /* FreeBSD support. */
5362 #undef TARGET_LITTLE_SYM
5363 #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
5364 #undef TARGET_LITTLE_NAME
5365 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
5367 #define ELF_OSABI ELFOSABI_FREEBSD
5369 /* The kernel recognizes executables as valid only if they carry a
5370 "FreeBSD" label in the ELF header. So we put this label on all
5371 executables and (for simplicity) also all other object files. */
5374 elf_i386_fbsd_post_process_headers (bfd
*abfd
, struct bfd_link_info
*info
)
5376 _bfd_elf_post_process_headers (abfd
, info
);
5378 #ifdef OLD_FREEBSD_ABI_LABEL
5380 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5381 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
5382 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5387 #undef elf_backend_post_process_headers
5388 #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
5390 #define elf32_bed elf32_i386_fbsd_bed
5392 #undef elf_backend_add_symbol_hook
5394 #include "elf32-target.h"
5398 #undef TARGET_LITTLE_SYM
5399 #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
5400 #undef TARGET_LITTLE_NAME
5401 #define TARGET_LITTLE_NAME "elf32-i386-sol2"
5403 #undef elf_backend_post_process_headers
5405 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5406 objects won't be recognized. */
5410 #define elf32_bed elf32_i386_sol2_bed
5412 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5414 #undef elf_backend_static_tls_alignment
5415 #define elf_backend_static_tls_alignment 8
5417 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5419 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5421 #undef elf_backend_want_plt_sym
5422 #define elf_backend_want_plt_sym 1
5424 #include "elf32-target.h"
5426 /* Intel MCU support. */
5429 elf32_iamcu_elf_object_p (bfd
*abfd
)
5431 /* Set the right machine number for an IAMCU elf32 file. */
5432 bfd_default_set_arch_mach (abfd
, bfd_arch_iamcu
, bfd_mach_i386_iamcu
);
5436 #undef TARGET_LITTLE_SYM
5437 #define TARGET_LITTLE_SYM iamcu_elf32_vec
5438 #undef TARGET_LITTLE_NAME
5439 #define TARGET_LITTLE_NAME "elf32-iamcu"
5441 #define ELF_ARCH bfd_arch_iamcu
5443 #undef ELF_MACHINE_CODE
5444 #define ELF_MACHINE_CODE EM_IAMCU
5449 #define elf32_bed elf32_iamcu_bed
5451 #undef elf_backend_object_p
5452 #define elf_backend_object_p elf32_iamcu_elf_object_p
5454 #undef elf_backend_static_tls_alignment
5456 #undef elf_backend_want_plt_sym
5457 #define elf_backend_want_plt_sym 0
5459 #include "elf32-target.h"
5461 /* Restore defaults. */
5463 #define ELF_ARCH bfd_arch_i386
5464 #undef ELF_MACHINE_CODE
5465 #define ELF_MACHINE_CODE EM_386
5467 /* Native Client support. */
5469 #undef TARGET_LITTLE_SYM
5470 #define TARGET_LITTLE_SYM i386_elf32_nacl_vec
5471 #undef TARGET_LITTLE_NAME
5472 #define TARGET_LITTLE_NAME "elf32-i386-nacl"
5474 #define elf32_bed elf32_i386_nacl_bed
5476 #undef ELF_MAXPAGESIZE
5477 #define ELF_MAXPAGESIZE 0x10000
5479 /* Restore defaults. */
5481 #undef elf_backend_want_plt_sym
5482 #define elf_backend_want_plt_sym 0
5483 #undef elf_backend_post_process_headers
5484 #undef elf_backend_static_tls_alignment
5486 /* NaCl uses substantially different PLT entries for the same effects. */
5488 #undef elf_backend_plt_alignment
5489 #define elf_backend_plt_alignment 5
5490 #define NACL_PLT_ENTRY_SIZE 64
5491 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5493 static const bfd_byte elf_i386_nacl_plt0_entry
[] =
5495 0xff, 0x35, /* pushl contents of address */
5496 0, 0, 0, 0, /* replaced with address of .got + 4. */
5497 0x8b, 0x0d, /* movl contents of address, %ecx */
5498 0, 0, 0, 0, /* replaced with address of .got + 8. */
5499 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5500 0xff, 0xe1 /* jmp *%ecx */
5503 static const bfd_byte elf_i386_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5505 0x8b, 0x0d, /* movl contents of address, %ecx */
5506 0, 0, 0, 0, /* replaced with GOT slot address. */
5507 0x83, 0xe1, NACLMASK
, /* andl $NACLMASK, %ecx */
5508 0xff, 0xe1, /* jmp *%ecx */
5510 /* Pad to the next 32-byte boundary with nop instructions. */
5512 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5513 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5515 /* Lazy GOT entries point here (32-byte aligned). */
5516 0x68, /* pushl immediate */
5517 0, 0, 0, 0, /* replaced with reloc offset. */
5518 0xe9, /* jmp relative */
5519 0, 0, 0, 0, /* replaced with offset to .plt. */
5521 /* Pad to the next 32-byte boundary with nop instructions. */
5522 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5523 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5527 static const bfd_byte
5528 elf_i386_nacl_pic_plt0_entry
[sizeof (elf_i386_nacl_plt0_entry
)] =
5530 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5531 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5532 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5533 0xff, 0xe1, /* jmp *%ecx */
5535 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
5536 so pad to that size with nop instructions. */
5537 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
5540 static const bfd_byte elf_i386_nacl_pic_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5542 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5543 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5544 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5545 0xff, 0xe1, /* jmp *%ecx */
5547 /* Pad to the next 32-byte boundary with nop instructions. */
5549 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5550 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5552 /* Lazy GOT entries point here (32-byte aligned). */
5553 0x68, /* pushl immediate */
5554 0, 0, 0, 0, /* replaced with offset into relocation table. */
5555 0xe9, /* jmp relative */
5556 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5558 /* Pad to the next 32-byte boundary with nop instructions. */
5559 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5560 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5564 static const bfd_byte elf_i386_nacl_eh_frame_plt
[] =
5566 #if (PLT_CIE_LENGTH != 20 \
5567 || PLT_FDE_LENGTH != 36 \
5568 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5569 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5570 # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5572 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5573 0, 0, 0, 0, /* CIE ID */
5574 1, /* CIE version */
5575 'z', 'R', 0, /* Augmentation string */
5576 1, /* Code alignment factor */
5577 0x7c, /* Data alignment factor: -4 */
5578 8, /* Return address column */
5579 1, /* Augmentation size */
5580 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5581 DW_CFA_def_cfa
, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5582 DW_CFA_offset
+ 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5583 DW_CFA_nop
, DW_CFA_nop
,
5585 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5586 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
5587 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5588 0, 0, 0, 0, /* .plt size goes here */
5589 0, /* Augmentation size */
5590 DW_CFA_def_cfa_offset
, 8, /* DW_CFA_def_cfa_offset: 8 */
5591 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5592 DW_CFA_def_cfa_offset
, 12, /* DW_CFA_def_cfa_offset: 12 */
5593 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5594 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5595 13, /* Block length */
5596 DW_OP_breg4
, 4, /* DW_OP_breg4 (esp): 4 */
5597 DW_OP_breg8
, 0, /* DW_OP_breg8 (eip): 0 */
5598 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5599 DW_OP_lit2
, DW_OP_shl
, DW_OP_plus
,
5600 DW_CFA_nop
, DW_CFA_nop
5603 static const struct elf_i386_plt_layout elf_i386_nacl_plt
=
5605 elf_i386_nacl_plt0_entry
, /* plt0_entry */
5606 sizeof (elf_i386_nacl_plt0_entry
), /* plt0_entry_size */
5607 2, /* plt0_got1_offset */
5608 8, /* plt0_got2_offset */
5609 elf_i386_nacl_plt_entry
, /* plt_entry */
5610 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5611 2, /* plt_got_offset */
5612 33, /* plt_reloc_offset */
5613 38, /* plt_plt_offset */
5614 32, /* plt_lazy_offset */
5615 elf_i386_nacl_pic_plt0_entry
, /* pic_plt0_entry */
5616 elf_i386_nacl_pic_plt_entry
, /* pic_plt_entry */
5617 elf_i386_nacl_eh_frame_plt
, /* eh_frame_plt */
5618 sizeof (elf_i386_nacl_eh_frame_plt
),/* eh_frame_plt_size */
5621 static const struct elf_i386_backend_data elf_i386_nacl_arch_bed
=
5623 &elf_i386_nacl_plt
, /* plt */
5624 0x90, /* plt0_pad_byte: nop insn */
5629 elf32_i386_nacl_elf_object_p (bfd
*abfd
)
5631 /* Set the right machine number for a NaCl i386 ELF32 file. */
5632 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386_nacl
);
5636 #undef elf_backend_arch_data
5637 #define elf_backend_arch_data &elf_i386_nacl_arch_bed
5639 #undef elf_backend_object_p
5640 #define elf_backend_object_p elf32_i386_nacl_elf_object_p
5641 #undef elf_backend_modify_segment_map
5642 #define elf_backend_modify_segment_map nacl_modify_segment_map
5643 #undef elf_backend_modify_program_headers
5644 #define elf_backend_modify_program_headers nacl_modify_program_headers
5645 #undef elf_backend_final_write_processing
5646 #define elf_backend_final_write_processing nacl_final_write_processing
5648 #include "elf32-target.h"
5650 /* Restore defaults. */
5651 #undef elf_backend_object_p
5652 #undef elf_backend_modify_segment_map
5653 #undef elf_backend_modify_program_headers
5654 #undef elf_backend_final_write_processing
5656 /* VxWorks support. */
5658 #undef TARGET_LITTLE_SYM
5659 #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
5660 #undef TARGET_LITTLE_NAME
5661 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
5663 #undef elf_backend_plt_alignment
5664 #define elf_backend_plt_alignment 4
5666 static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed
=
5668 &elf_i386_plt
, /* plt */
5669 0x90, /* plt0_pad_byte */
5673 #undef elf_backend_arch_data
5674 #define elf_backend_arch_data &elf_i386_vxworks_arch_bed
5676 #undef elf_backend_relocs_compatible
5677 #undef elf_backend_add_symbol_hook
5678 #define elf_backend_add_symbol_hook \
5679 elf_vxworks_add_symbol_hook
5680 #undef elf_backend_link_output_symbol_hook
5681 #define elf_backend_link_output_symbol_hook \
5682 elf_vxworks_link_output_symbol_hook
5683 #undef elf_backend_emit_relocs
5684 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
5685 #undef elf_backend_final_write_processing
5686 #define elf_backend_final_write_processing \
5687 elf_vxworks_final_write_processing
5688 #undef elf_backend_static_tls_alignment
5690 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5692 #undef elf_backend_want_plt_sym
5693 #define elf_backend_want_plt_sym 1
5696 #define elf32_bed elf32_i386_vxworks_bed
5698 #include "elf32-target.h"