1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
29 /* 386 uses REL relocations instead of RELA. */
34 static reloc_howto_type elf_howto_table
[]=
36 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
37 bfd_elf_generic_reloc
, "R_386_NONE",
38 TRUE
, 0x00000000, 0x00000000, FALSE
),
39 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
40 bfd_elf_generic_reloc
, "R_386_32",
41 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
42 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
43 bfd_elf_generic_reloc
, "R_386_PC32",
44 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
45 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
46 bfd_elf_generic_reloc
, "R_386_GOT32",
47 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
48 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
49 bfd_elf_generic_reloc
, "R_386_PLT32",
50 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
51 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
52 bfd_elf_generic_reloc
, "R_386_COPY",
53 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
54 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
55 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
56 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
57 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
58 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
59 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
60 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
61 bfd_elf_generic_reloc
, "R_386_RELATIVE",
62 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
63 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_386_GOTOFF",
65 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
66 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_386_GOTPC",
68 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
70 /* We have a gap in the reloc numbers here.
71 R_386_standard counts the number up to this point, and
72 R_386_ext_offset is the value to subtract from a reloc type of
73 R_386_16 thru R_386_PC8 to form an index into this table. */
74 #define R_386_standard (R_386_GOTPC + 1)
75 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
77 /* These relocs are a GNU extension. */
78 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
79 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
80 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
81 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
82 bfd_elf_generic_reloc
, "R_386_TLS_IE",
83 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
84 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
86 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
87 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_386_TLS_LE",
89 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
90 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
91 bfd_elf_generic_reloc
, "R_386_TLS_GD",
92 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
93 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
94 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
95 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
96 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_386_16",
98 TRUE
, 0xffff, 0xffff, FALSE
),
99 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
100 bfd_elf_generic_reloc
, "R_386_PC16",
101 TRUE
, 0xffff, 0xffff, TRUE
),
102 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_386_8",
104 TRUE
, 0xff, 0xff, FALSE
),
105 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
106 bfd_elf_generic_reloc
, "R_386_PC8",
107 TRUE
, 0xff, 0xff, TRUE
),
109 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
110 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
111 /* These are common with Solaris TLS implementation. */
112 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
113 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
114 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
115 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
116 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
117 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
118 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
119 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
120 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
121 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
122 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
123 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
124 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
125 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
126 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
127 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
129 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
131 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
132 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
133 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
134 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
135 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
137 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
139 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
142 #define R_386_tls (R_386_TLS_DESC + 1 - R_386_tls_offset)
143 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_tls)
145 /* GNU extension to record C++ vtable hierarchy. */
146 HOWTO (R_386_GNU_VTINHERIT
, /* type */
148 2, /* size (0 = byte, 1 = short, 2 = long) */
150 FALSE
, /* pc_relative */
152 complain_overflow_dont
, /* complain_on_overflow */
153 NULL
, /* special_function */
154 "R_386_GNU_VTINHERIT", /* name */
155 FALSE
, /* partial_inplace */
158 FALSE
), /* pcrel_offset */
160 /* GNU extension to record C++ vtable member usage. */
161 HOWTO (R_386_GNU_VTENTRY
, /* type */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
165 FALSE
, /* pc_relative */
167 complain_overflow_dont
, /* complain_on_overflow */
168 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
169 "R_386_GNU_VTENTRY", /* name */
170 FALSE
, /* partial_inplace */
173 FALSE
) /* pcrel_offset */
175 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
179 #ifdef DEBUG_GEN_RELOC
181 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
186 static reloc_howto_type
*
187 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
188 bfd_reloc_code_real_type code
)
193 TRACE ("BFD_RELOC_NONE");
194 return &elf_howto_table
[R_386_NONE
];
197 TRACE ("BFD_RELOC_32");
198 return &elf_howto_table
[R_386_32
];
201 TRACE ("BFD_RELOC_CTOR");
202 return &elf_howto_table
[R_386_32
];
204 case BFD_RELOC_32_PCREL
:
205 TRACE ("BFD_RELOC_PC32");
206 return &elf_howto_table
[R_386_PC32
];
208 case BFD_RELOC_386_GOT32
:
209 TRACE ("BFD_RELOC_386_GOT32");
210 return &elf_howto_table
[R_386_GOT32
];
212 case BFD_RELOC_386_PLT32
:
213 TRACE ("BFD_RELOC_386_PLT32");
214 return &elf_howto_table
[R_386_PLT32
];
216 case BFD_RELOC_386_COPY
:
217 TRACE ("BFD_RELOC_386_COPY");
218 return &elf_howto_table
[R_386_COPY
];
220 case BFD_RELOC_386_GLOB_DAT
:
221 TRACE ("BFD_RELOC_386_GLOB_DAT");
222 return &elf_howto_table
[R_386_GLOB_DAT
];
224 case BFD_RELOC_386_JUMP_SLOT
:
225 TRACE ("BFD_RELOC_386_JUMP_SLOT");
226 return &elf_howto_table
[R_386_JUMP_SLOT
];
228 case BFD_RELOC_386_RELATIVE
:
229 TRACE ("BFD_RELOC_386_RELATIVE");
230 return &elf_howto_table
[R_386_RELATIVE
];
232 case BFD_RELOC_386_GOTOFF
:
233 TRACE ("BFD_RELOC_386_GOTOFF");
234 return &elf_howto_table
[R_386_GOTOFF
];
236 case BFD_RELOC_386_GOTPC
:
237 TRACE ("BFD_RELOC_386_GOTPC");
238 return &elf_howto_table
[R_386_GOTPC
];
240 /* These relocs are a GNU extension. */
241 case BFD_RELOC_386_TLS_TPOFF
:
242 TRACE ("BFD_RELOC_386_TLS_TPOFF");
243 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
245 case BFD_RELOC_386_TLS_IE
:
246 TRACE ("BFD_RELOC_386_TLS_IE");
247 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
249 case BFD_RELOC_386_TLS_GOTIE
:
250 TRACE ("BFD_RELOC_386_TLS_GOTIE");
251 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
253 case BFD_RELOC_386_TLS_LE
:
254 TRACE ("BFD_RELOC_386_TLS_LE");
255 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
257 case BFD_RELOC_386_TLS_GD
:
258 TRACE ("BFD_RELOC_386_TLS_GD");
259 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
261 case BFD_RELOC_386_TLS_LDM
:
262 TRACE ("BFD_RELOC_386_TLS_LDM");
263 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
266 TRACE ("BFD_RELOC_16");
267 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
269 case BFD_RELOC_16_PCREL
:
270 TRACE ("BFD_RELOC_16_PCREL");
271 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
274 TRACE ("BFD_RELOC_8");
275 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
277 case BFD_RELOC_8_PCREL
:
278 TRACE ("BFD_RELOC_8_PCREL");
279 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
281 /* Common with Sun TLS implementation. */
282 case BFD_RELOC_386_TLS_LDO_32
:
283 TRACE ("BFD_RELOC_386_TLS_LDO_32");
284 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
286 case BFD_RELOC_386_TLS_IE_32
:
287 TRACE ("BFD_RELOC_386_TLS_IE_32");
288 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
290 case BFD_RELOC_386_TLS_LE_32
:
291 TRACE ("BFD_RELOC_386_TLS_LE_32");
292 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
294 case BFD_RELOC_386_TLS_DTPMOD32
:
295 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
296 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
298 case BFD_RELOC_386_TLS_DTPOFF32
:
299 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
300 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
302 case BFD_RELOC_386_TLS_TPOFF32
:
303 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
304 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
306 case BFD_RELOC_386_TLS_GOTDESC
:
307 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
308 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
310 case BFD_RELOC_386_TLS_DESC_CALL
:
311 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
312 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
314 case BFD_RELOC_386_TLS_DESC
:
315 TRACE ("BFD_RELOC_386_TLS_DESC");
316 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
318 case BFD_RELOC_VTABLE_INHERIT
:
319 TRACE ("BFD_RELOC_VTABLE_INHERIT");
320 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
322 case BFD_RELOC_VTABLE_ENTRY
:
323 TRACE ("BFD_RELOC_VTABLE_ENTRY");
324 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
334 static reloc_howto_type
*
335 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
340 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
341 if (elf_howto_table
[i
].name
!= NULL
342 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
343 return &elf_howto_table
[i
];
349 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
351 Elf_Internal_Rela
*dst
)
353 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
356 if ((indx
= r_type
) >= R_386_standard
357 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
358 >= R_386_ext
- R_386_standard
)
359 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
360 >= R_386_tls
- R_386_ext
)
361 && ((indx
= r_type
- R_386_vt_offset
) - R_386_tls
362 >= R_386_vt
- R_386_tls
))
364 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
368 cache_ptr
->howto
= &elf_howto_table
[indx
];
371 /* Return whether a symbol name implies a local label. The UnixWare
372 2.1 cc generates temporary symbols that start with .X, so we
373 recognize them here. FIXME: do other SVR4 compilers also use .X?.
374 If so, we should move the .X recognition into
375 _bfd_elf_is_local_label_name. */
378 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
380 if (name
[0] == '.' && name
[1] == 'X')
383 return _bfd_elf_is_local_label_name (abfd
, name
);
386 /* Support for core dump NOTE sections. */
389 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
394 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
396 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
402 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
405 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
409 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
413 switch (note
->descsz
)
418 case 144: /* Linux/i386 */
420 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
423 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
433 /* Make a ".reg/999" section. */
434 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
435 size
, note
->descpos
+ offset
);
439 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
441 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
443 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
448 elf_tdata (abfd
)->core_program
449 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
450 elf_tdata (abfd
)->core_command
451 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
455 switch (note
->descsz
)
460 case 124: /* Linux/i386 elf_prpsinfo. */
461 elf_tdata (abfd
)->core_program
462 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
463 elf_tdata (abfd
)->core_command
464 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
468 /* Note that for some reason, a spurious space is tacked
469 onto the end of the args in some (at least one anyway)
470 implementations, so strip it off if it exists. */
472 char *command
= elf_tdata (abfd
)->core_command
;
473 int n
= strlen (command
);
475 if (0 < n
&& command
[n
- 1] == ' ')
476 command
[n
- 1] = '\0';
482 /* Functions for the i386 ELF linker.
484 In order to gain some understanding of code in this file without
485 knowing all the intricate details of the linker, note the
488 Functions named elf_i386_* are called by external routines, other
489 functions are only called locally. elf_i386_* functions appear
490 in this file more or less in the order in which they are called
491 from external routines. eg. elf_i386_check_relocs is called
492 early in the link process, elf_i386_finish_dynamic_sections is
493 one of the last functions. */
496 /* The name of the dynamic interpreter. This is put in the .interp
499 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
501 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
502 copying dynamic variables from a shared lib into an app's dynbss
503 section, and instead use a dynamic relocation to point into the
505 #define ELIMINATE_COPY_RELOCS 1
507 /* The size in bytes of an entry in the procedure linkage table. */
509 #define PLT_ENTRY_SIZE 16
511 /* The first entry in an absolute procedure linkage table looks like
512 this. See the SVR4 ABI i386 supplement to see how this works.
513 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
515 static const bfd_byte elf_i386_plt0_entry
[12] =
517 0xff, 0x35, /* pushl contents of address */
518 0, 0, 0, 0, /* replaced with address of .got + 4. */
519 0xff, 0x25, /* jmp indirect */
520 0, 0, 0, 0 /* replaced with address of .got + 8. */
523 /* Subsequent entries in an absolute procedure linkage table look like
526 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
528 0xff, 0x25, /* jmp indirect */
529 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
530 0x68, /* pushl immediate */
531 0, 0, 0, 0, /* replaced with offset into relocation table. */
532 0xe9, /* jmp relative */
533 0, 0, 0, 0 /* replaced with offset to start of .plt. */
536 /* The first entry in a PIC procedure linkage table look like this.
537 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
539 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
541 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
542 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
545 /* Subsequent entries in a PIC procedure linkage table look like this. */
547 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
549 0xff, 0xa3, /* jmp *offset(%ebx) */
550 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
551 0x68, /* pushl immediate */
552 0, 0, 0, 0, /* replaced with offset into relocation table. */
553 0xe9, /* jmp relative */
554 0, 0, 0, 0 /* replaced with offset to start of .plt. */
557 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
558 for the PLTResolve stub and then for each PLT entry. */
559 #define PLTRESOLVE_RELOCS_SHLIB 0
560 #define PLTRESOLVE_RELOCS 2
561 #define PLT_NON_JUMP_SLOT_RELOCS 2
563 /* The i386 linker needs to keep track of the number of relocs that it
564 decides to copy as dynamic relocs in check_relocs for each symbol.
565 This is so that it can later discard them if they are found to be
566 unnecessary. We store the information in a field extending the
567 regular ELF linker hash table. */
569 struct elf_i386_dyn_relocs
571 struct elf_i386_dyn_relocs
*next
;
573 /* The input section of the reloc. */
576 /* Total number of relocs copied for the input section. */
579 /* Number of pc-relative relocs copied for the input section. */
580 bfd_size_type pc_count
;
583 /* i386 ELF linker hash entry. */
585 struct elf_i386_link_hash_entry
587 struct elf_link_hash_entry elf
;
589 /* Track dynamic relocs copied for this symbol. */
590 struct elf_i386_dyn_relocs
*dyn_relocs
;
592 #define GOT_UNKNOWN 0
596 #define GOT_TLS_IE_POS 5
597 #define GOT_TLS_IE_NEG 6
598 #define GOT_TLS_IE_BOTH 7
599 #define GOT_TLS_GDESC 8
600 #define GOT_TLS_GD_BOTH_P(type) \
601 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
602 #define GOT_TLS_GD_P(type) \
603 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
604 #define GOT_TLS_GDESC_P(type) \
605 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
606 #define GOT_TLS_GD_ANY_P(type) \
607 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
608 unsigned char tls_type
;
610 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
611 starting at the end of the jump table. */
615 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
617 struct elf_i386_obj_tdata
619 struct elf_obj_tdata root
;
621 /* tls_type for each local got entry. */
622 char *local_got_tls_type
;
624 /* GOTPLT entries for TLS descriptors. */
625 bfd_vma
*local_tlsdesc_gotent
;
628 #define elf_i386_tdata(abfd) \
629 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
631 #define elf_i386_local_got_tls_type(abfd) \
632 (elf_i386_tdata (abfd)->local_got_tls_type)
634 #define elf_i386_local_tlsdesc_gotent(abfd) \
635 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
638 elf_i386_mkobject (bfd
*abfd
)
640 if (abfd
->tdata
.any
== NULL
)
642 bfd_size_type amt
= sizeof (struct elf_i386_obj_tdata
);
643 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
644 if (abfd
->tdata
.any
== NULL
)
647 return bfd_elf_mkobject (abfd
);
650 /* i386 ELF linker hash table. */
652 struct elf_i386_link_hash_table
654 struct elf_link_hash_table elf
;
656 /* Short-cuts to get to dynamic linker sections. */
665 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
668 /* True if the target system is VxWorks. */
671 /* Value used to fill the last word of the first plt entry. */
672 bfd_byte plt0_pad_byte
;
674 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
675 bfd_vma next_tls_desc_index
;
678 bfd_signed_vma refcount
;
682 /* The amount of space used by the reserved portion of the sgotplt
683 section, plus whatever space is used by the jump slots. */
684 bfd_vma sgotplt_jump_table_size
;
686 /* Small local sym to section mapping cache. */
687 struct sym_sec_cache sym_sec
;
690 /* Get the i386 ELF linker hash table from a link_info structure. */
692 #define elf_i386_hash_table(p) \
693 ((struct elf_i386_link_hash_table *) ((p)->hash))
695 #define elf_i386_compute_jump_table_size(htab) \
696 ((htab)->next_tls_desc_index * 4)
698 /* Create an entry in an i386 ELF linker hash table. */
700 static struct bfd_hash_entry
*
701 link_hash_newfunc (struct bfd_hash_entry
*entry
,
702 struct bfd_hash_table
*table
,
705 /* Allocate the structure if it has not already been allocated by a
709 entry
= bfd_hash_allocate (table
,
710 sizeof (struct elf_i386_link_hash_entry
));
715 /* Call the allocation method of the superclass. */
716 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
719 struct elf_i386_link_hash_entry
*eh
;
721 eh
= (struct elf_i386_link_hash_entry
*) entry
;
722 eh
->dyn_relocs
= NULL
;
723 eh
->tls_type
= GOT_UNKNOWN
;
724 eh
->tlsdesc_got
= (bfd_vma
) -1;
730 /* Create an i386 ELF linker hash table. */
732 static struct bfd_link_hash_table
*
733 elf_i386_link_hash_table_create (bfd
*abfd
)
735 struct elf_i386_link_hash_table
*ret
;
736 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
738 ret
= bfd_malloc (amt
);
742 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
,
743 sizeof (struct elf_i386_link_hash_entry
)))
756 ret
->tls_ldm_got
.refcount
= 0;
757 ret
->next_tls_desc_index
= 0;
758 ret
->sgotplt_jump_table_size
= 0;
759 ret
->sym_sec
.abfd
= NULL
;
761 ret
->srelplt2
= NULL
;
762 ret
->plt0_pad_byte
= 0;
764 return &ret
->elf
.root
;
767 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
768 shortcuts to them in our hash table. */
771 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
773 struct elf_i386_link_hash_table
*htab
;
775 if (! _bfd_elf_create_got_section (dynobj
, info
))
778 htab
= elf_i386_hash_table (info
);
779 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
780 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
781 if (!htab
->sgot
|| !htab
->sgotplt
)
784 htab
->srelgot
= bfd_make_section_with_flags (dynobj
, ".rel.got",
785 (SEC_ALLOC
| SEC_LOAD
790 if (htab
->srelgot
== NULL
791 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
796 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
797 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
801 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
803 struct elf_i386_link_hash_table
*htab
;
805 htab
= elf_i386_hash_table (info
);
806 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
809 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
812 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
813 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
814 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
816 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
818 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
819 || (!info
->shared
&& !htab
->srelbss
))
823 && !elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
829 /* Copy the extra info we tack onto an elf_link_hash_entry. */
832 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
833 struct elf_link_hash_entry
*dir
,
834 struct elf_link_hash_entry
*ind
)
836 struct elf_i386_link_hash_entry
*edir
, *eind
;
838 edir
= (struct elf_i386_link_hash_entry
*) dir
;
839 eind
= (struct elf_i386_link_hash_entry
*) ind
;
841 if (eind
->dyn_relocs
!= NULL
)
843 if (edir
->dyn_relocs
!= NULL
)
845 struct elf_i386_dyn_relocs
**pp
;
846 struct elf_i386_dyn_relocs
*p
;
848 /* Add reloc counts against the indirect sym to the direct sym
849 list. Merge any entries against the same section. */
850 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
852 struct elf_i386_dyn_relocs
*q
;
854 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
855 if (q
->sec
== p
->sec
)
857 q
->pc_count
+= p
->pc_count
;
858 q
->count
+= p
->count
;
865 *pp
= edir
->dyn_relocs
;
868 edir
->dyn_relocs
= eind
->dyn_relocs
;
869 eind
->dyn_relocs
= NULL
;
872 if (ind
->root
.type
== bfd_link_hash_indirect
873 && dir
->got
.refcount
<= 0)
875 edir
->tls_type
= eind
->tls_type
;
876 eind
->tls_type
= GOT_UNKNOWN
;
879 if (ELIMINATE_COPY_RELOCS
880 && ind
->root
.type
!= bfd_link_hash_indirect
881 && dir
->dynamic_adjusted
)
883 /* If called to transfer flags for a weakdef during processing
884 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
885 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
886 dir
->ref_dynamic
|= ind
->ref_dynamic
;
887 dir
->ref_regular
|= ind
->ref_regular
;
888 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
889 dir
->needs_plt
|= ind
->needs_plt
;
890 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
893 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
897 elf_i386_tls_transition (struct bfd_link_info
*info
, int r_type
, int is_local
)
905 case R_386_TLS_GOTDESC
:
906 case R_386_TLS_DESC_CALL
:
907 case R_386_TLS_IE_32
:
909 return R_386_TLS_LE_32
;
910 return R_386_TLS_IE_32
;
912 case R_386_TLS_GOTIE
:
914 return R_386_TLS_LE_32
;
917 return R_386_TLS_LE_32
;
923 /* Look through the relocs for a section during the first phase, and
924 calculate needed space in the global offset table, procedure linkage
925 table, and dynamic reloc sections. */
928 elf_i386_check_relocs (bfd
*abfd
,
929 struct bfd_link_info
*info
,
931 const Elf_Internal_Rela
*relocs
)
933 struct elf_i386_link_hash_table
*htab
;
934 Elf_Internal_Shdr
*symtab_hdr
;
935 struct elf_link_hash_entry
**sym_hashes
;
936 const Elf_Internal_Rela
*rel
;
937 const Elf_Internal_Rela
*rel_end
;
940 if (info
->relocatable
)
943 htab
= elf_i386_hash_table (info
);
944 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
945 sym_hashes
= elf_sym_hashes (abfd
);
949 rel_end
= relocs
+ sec
->reloc_count
;
950 for (rel
= relocs
; rel
< rel_end
; rel
++)
953 unsigned long r_symndx
;
954 struct elf_link_hash_entry
*h
;
956 r_symndx
= ELF32_R_SYM (rel
->r_info
);
957 r_type
= ELF32_R_TYPE (rel
->r_info
);
959 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
961 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
967 if (r_symndx
< symtab_hdr
->sh_info
)
971 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
972 while (h
->root
.type
== bfd_link_hash_indirect
973 || h
->root
.type
== bfd_link_hash_warning
)
974 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
977 r_type
= elf_i386_tls_transition (info
, r_type
, h
== NULL
);
982 htab
->tls_ldm_got
.refcount
+= 1;
986 /* This symbol requires a procedure linkage table entry. We
987 actually build the entry in adjust_dynamic_symbol,
988 because this might be a case of linking PIC code which is
989 never referenced by a dynamic object, in which case we
990 don't need to generate a procedure linkage table entry
993 /* If this is a local symbol, we resolve it directly without
994 creating a procedure linkage table entry. */
999 h
->plt
.refcount
+= 1;
1002 case R_386_TLS_IE_32
:
1004 case R_386_TLS_GOTIE
:
1006 info
->flags
|= DF_STATIC_TLS
;
1011 case R_386_TLS_GOTDESC
:
1012 case R_386_TLS_DESC_CALL
:
1013 /* This symbol requires a global offset table entry. */
1015 int tls_type
, old_tls_type
;
1020 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1021 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1022 case R_386_TLS_GOTDESC
:
1023 case R_386_TLS_DESC_CALL
:
1024 tls_type
= GOT_TLS_GDESC
; break;
1025 case R_386_TLS_IE_32
:
1026 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1027 tls_type
= GOT_TLS_IE_NEG
;
1029 /* If this is a GD->IE transition, we may use either of
1030 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1031 tls_type
= GOT_TLS_IE
;
1034 case R_386_TLS_GOTIE
:
1035 tls_type
= GOT_TLS_IE_POS
; break;
1040 h
->got
.refcount
+= 1;
1041 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1045 bfd_signed_vma
*local_got_refcounts
;
1047 /* This is a global offset table entry for a local symbol. */
1048 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1049 if (local_got_refcounts
== NULL
)
1053 size
= symtab_hdr
->sh_info
;
1054 size
*= (sizeof (bfd_signed_vma
)
1055 + sizeof (bfd_vma
) + sizeof(char));
1056 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1057 if (local_got_refcounts
== NULL
)
1059 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1060 elf_i386_local_tlsdesc_gotent (abfd
)
1061 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1062 elf_i386_local_got_tls_type (abfd
)
1063 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1065 local_got_refcounts
[r_symndx
] += 1;
1066 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1069 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1070 tls_type
|= old_tls_type
;
1071 /* If a TLS symbol is accessed using IE at least once,
1072 there is no point to use dynamic model for it. */
1073 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1074 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1075 || (tls_type
& GOT_TLS_IE
) == 0))
1077 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1078 tls_type
= old_tls_type
;
1079 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1080 && GOT_TLS_GD_ANY_P (tls_type
))
1081 tls_type
|= old_tls_type
;
1084 (*_bfd_error_handler
)
1085 (_("%B: `%s' accessed both as normal and "
1086 "thread local symbol"),
1088 h
? h
->root
.root
.string
: "<local>");
1093 if (old_tls_type
!= tls_type
)
1096 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1098 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1106 if (htab
->sgot
== NULL
)
1108 if (htab
->elf
.dynobj
== NULL
)
1109 htab
->elf
.dynobj
= abfd
;
1110 if (!create_got_section (htab
->elf
.dynobj
, info
))
1113 if (r_type
!= R_386_TLS_IE
)
1117 case R_386_TLS_LE_32
:
1121 info
->flags
|= DF_STATIC_TLS
;
1126 if (h
!= NULL
&& !info
->shared
)
1128 /* If this reloc is in a read-only section, we might
1129 need a copy reloc. We can't check reliably at this
1130 stage whether the section is read-only, as input
1131 sections have not yet been mapped to output sections.
1132 Tentatively set the flag for now, and correct in
1133 adjust_dynamic_symbol. */
1136 /* We may need a .plt entry if the function this reloc
1137 refers to is in a shared lib. */
1138 h
->plt
.refcount
+= 1;
1139 if (r_type
!= R_386_PC32
)
1140 h
->pointer_equality_needed
= 1;
1143 /* If we are creating a shared library, and this is a reloc
1144 against a global symbol, or a non PC relative reloc
1145 against a local symbol, then we need to copy the reloc
1146 into the shared library. However, if we are linking with
1147 -Bsymbolic, we do not need to copy a reloc against a
1148 global symbol which is defined in an object we are
1149 including in the link (i.e., DEF_REGULAR is set). At
1150 this point we have not seen all the input files, so it is
1151 possible that DEF_REGULAR is not set now but will be set
1152 later (it is never cleared). In case of a weak definition,
1153 DEF_REGULAR may be cleared later by a strong definition in
1154 a shared library. We account for that possibility below by
1155 storing information in the relocs_copied field of the hash
1156 table entry. A similar situation occurs when creating
1157 shared libraries and symbol visibility changes render the
1160 If on the other hand, we are creating an executable, we
1161 may need to keep relocations for symbols satisfied by a
1162 dynamic library if we manage to avoid copy relocs for the
1165 && (sec
->flags
& SEC_ALLOC
) != 0
1166 && (r_type
!= R_386_PC32
1168 && (! SYMBOLIC_BIND (info
, h
)
1169 || h
->root
.type
== bfd_link_hash_defweak
1170 || !h
->def_regular
))))
1171 || (ELIMINATE_COPY_RELOCS
1173 && (sec
->flags
& SEC_ALLOC
) != 0
1175 && (h
->root
.type
== bfd_link_hash_defweak
1176 || !h
->def_regular
)))
1178 struct elf_i386_dyn_relocs
*p
;
1179 struct elf_i386_dyn_relocs
**head
;
1181 /* We must copy these reloc types into the output file.
1182 Create a reloc section in dynobj and make room for
1188 unsigned int strndx
= elf_elfheader (abfd
)->e_shstrndx
;
1189 unsigned int shnam
= elf_section_data (sec
)->rel_hdr
.sh_name
;
1191 name
= bfd_elf_string_from_elf_section (abfd
, strndx
, shnam
);
1195 if (! CONST_STRNEQ (name
, ".rel")
1196 || strcmp (bfd_get_section_name (abfd
, sec
),
1199 (*_bfd_error_handler
)
1200 (_("%B: bad relocation section name `%s\'"),
1204 if (htab
->elf
.dynobj
== NULL
)
1205 htab
->elf
.dynobj
= abfd
;
1207 dynobj
= htab
->elf
.dynobj
;
1208 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1213 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1214 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1215 if ((sec
->flags
& SEC_ALLOC
) != 0)
1216 flags
|= SEC_ALLOC
| SEC_LOAD
;
1217 sreloc
= bfd_make_section_with_flags (dynobj
,
1221 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1224 elf_section_data (sec
)->sreloc
= sreloc
;
1227 /* If this is a global symbol, we count the number of
1228 relocations we need for this symbol. */
1231 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1236 /* Track dynamic relocs needed for local syms too.
1237 We really need local syms available to do this
1241 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1246 vpp
= &elf_section_data (s
)->local_dynrel
;
1247 head
= (struct elf_i386_dyn_relocs
**)vpp
;
1251 if (p
== NULL
|| p
->sec
!= sec
)
1253 bfd_size_type amt
= sizeof *p
;
1254 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
1265 if (r_type
== R_386_PC32
)
1270 /* This relocation describes the C++ object vtable hierarchy.
1271 Reconstruct it for later use during GC. */
1272 case R_386_GNU_VTINHERIT
:
1273 BFD_ASSERT (h
!= NULL
);
1275 && !bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1279 /* This relocation describes which C++ vtable entries are actually
1280 used. Record for later use during GC. */
1281 case R_386_GNU_VTENTRY
:
1282 BFD_ASSERT (h
!= NULL
);
1284 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1296 /* Return the section that should be marked against GC for a given
1300 elf_i386_gc_mark_hook (asection
*sec
,
1301 struct bfd_link_info
*info
,
1302 Elf_Internal_Rela
*rel
,
1303 struct elf_link_hash_entry
*h
,
1304 Elf_Internal_Sym
*sym
)
1307 switch (ELF32_R_TYPE (rel
->r_info
))
1309 case R_386_GNU_VTINHERIT
:
1310 case R_386_GNU_VTENTRY
:
1314 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1317 /* Update the got entry reference counts for the section being removed. */
1320 elf_i386_gc_sweep_hook (bfd
*abfd
,
1321 struct bfd_link_info
*info
,
1323 const Elf_Internal_Rela
*relocs
)
1325 Elf_Internal_Shdr
*symtab_hdr
;
1326 struct elf_link_hash_entry
**sym_hashes
;
1327 bfd_signed_vma
*local_got_refcounts
;
1328 const Elf_Internal_Rela
*rel
, *relend
;
1330 elf_section_data (sec
)->local_dynrel
= NULL
;
1332 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1333 sym_hashes
= elf_sym_hashes (abfd
);
1334 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1336 relend
= relocs
+ sec
->reloc_count
;
1337 for (rel
= relocs
; rel
< relend
; rel
++)
1339 unsigned long r_symndx
;
1340 unsigned int r_type
;
1341 struct elf_link_hash_entry
*h
= NULL
;
1343 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1344 if (r_symndx
>= symtab_hdr
->sh_info
)
1346 struct elf_i386_link_hash_entry
*eh
;
1347 struct elf_i386_dyn_relocs
**pp
;
1348 struct elf_i386_dyn_relocs
*p
;
1350 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1351 while (h
->root
.type
== bfd_link_hash_indirect
1352 || h
->root
.type
== bfd_link_hash_warning
)
1353 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1354 eh
= (struct elf_i386_link_hash_entry
*) h
;
1356 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1359 /* Everything must go for SEC. */
1365 r_type
= ELF32_R_TYPE (rel
->r_info
);
1366 r_type
= elf_i386_tls_transition (info
, r_type
, h
!= NULL
);
1370 if (elf_i386_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1371 elf_i386_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1375 case R_386_TLS_GOTDESC
:
1376 case R_386_TLS_DESC_CALL
:
1377 case R_386_TLS_IE_32
:
1379 case R_386_TLS_GOTIE
:
1383 if (h
->got
.refcount
> 0)
1384 h
->got
.refcount
-= 1;
1386 else if (local_got_refcounts
!= NULL
)
1388 if (local_got_refcounts
[r_symndx
] > 0)
1389 local_got_refcounts
[r_symndx
] -= 1;
1402 if (h
->plt
.refcount
> 0)
1403 h
->plt
.refcount
-= 1;
1415 /* Adjust a symbol defined by a dynamic object and referenced by a
1416 regular object. The current definition is in some section of the
1417 dynamic object, but we're not including those sections. We have to
1418 change the definition to something the rest of the link can
1422 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1423 struct elf_link_hash_entry
*h
)
1425 struct elf_i386_link_hash_table
*htab
;
1428 /* If this is a function, put it in the procedure linkage table. We
1429 will fill in the contents of the procedure linkage table later,
1430 when we know the address of the .got section. */
1431 if (h
->type
== STT_FUNC
1434 if (h
->plt
.refcount
<= 0
1435 || SYMBOL_CALLS_LOCAL (info
, h
)
1436 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1437 && h
->root
.type
== bfd_link_hash_undefweak
))
1439 /* This case can occur if we saw a PLT32 reloc in an input
1440 file, but the symbol was never referred to by a dynamic
1441 object, or if all references were garbage collected. In
1442 such a case, we don't actually need to build a procedure
1443 linkage table, and we can just do a PC32 reloc instead. */
1444 h
->plt
.offset
= (bfd_vma
) -1;
1451 /* It's possible that we incorrectly decided a .plt reloc was
1452 needed for an R_386_PC32 reloc to a non-function sym in
1453 check_relocs. We can't decide accurately between function and
1454 non-function syms in check-relocs; Objects loaded later in
1455 the link may change h->type. So fix it now. */
1456 h
->plt
.offset
= (bfd_vma
) -1;
1458 /* If this is a weak symbol, and there is a real definition, the
1459 processor independent code will have arranged for us to see the
1460 real definition first, and we can just use the same value. */
1461 if (h
->u
.weakdef
!= NULL
)
1463 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1464 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1465 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1466 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1467 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1468 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1472 /* This is a reference to a symbol defined by a dynamic object which
1473 is not a function. */
1475 /* If we are creating a shared library, we must presume that the
1476 only references to the symbol are via the global offset table.
1477 For such cases we need not do anything here; the relocations will
1478 be handled correctly by relocate_section. */
1482 /* If there are no references to this symbol that do not use the
1483 GOT, we don't need to generate a copy reloc. */
1484 if (!h
->non_got_ref
)
1487 /* If -z nocopyreloc was given, we won't generate them either. */
1488 if (info
->nocopyreloc
)
1494 htab
= elf_i386_hash_table (info
);
1496 /* If there aren't any dynamic relocs in read-only sections, then
1497 we can keep the dynamic relocs and avoid the copy reloc. This
1498 doesn't work on VxWorks, where we can not have dynamic relocations
1499 (other than copy and jump slot relocations) in an executable. */
1500 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
1502 struct elf_i386_link_hash_entry
* eh
;
1503 struct elf_i386_dyn_relocs
*p
;
1505 eh
= (struct elf_i386_link_hash_entry
*) h
;
1506 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1508 s
= p
->sec
->output_section
;
1509 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1522 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1523 h
->root
.root
.string
);
1527 /* We must allocate the symbol in our .dynbss section, which will
1528 become part of the .bss section of the executable. There will be
1529 an entry for this symbol in the .dynsym section. The dynamic
1530 object will contain position independent code, so all references
1531 from the dynamic object to this symbol will go through the global
1532 offset table. The dynamic linker will use the .dynsym entry to
1533 determine the address it must put in the global offset table, so
1534 both the dynamic object and the regular object will refer to the
1535 same memory location for the variable. */
1537 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
1538 copy the initial value out of the dynamic object and into the
1539 runtime process image. */
1540 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1542 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
1548 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1551 /* Allocate space in .plt, .got and associated reloc sections for
1555 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1557 struct bfd_link_info
*info
;
1558 struct elf_i386_link_hash_table
*htab
;
1559 struct elf_i386_link_hash_entry
*eh
;
1560 struct elf_i386_dyn_relocs
*p
;
1562 if (h
->root
.type
== bfd_link_hash_indirect
)
1565 if (h
->root
.type
== bfd_link_hash_warning
)
1566 /* When warning symbols are created, they **replace** the "real"
1567 entry in the hash table, thus we never get to see the real
1568 symbol in a hash traversal. So look at it now. */
1569 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1571 info
= (struct bfd_link_info
*) inf
;
1572 htab
= elf_i386_hash_table (info
);
1574 if (htab
->elf
.dynamic_sections_created
1575 && h
->plt
.refcount
> 0)
1577 /* Make sure this symbol is output as a dynamic symbol.
1578 Undefined weak syms won't yet be marked as dynamic. */
1579 if (h
->dynindx
== -1
1580 && !h
->forced_local
)
1582 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1587 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1589 asection
*s
= htab
->splt
;
1591 /* If this is the first .plt entry, make room for the special
1594 s
->size
+= PLT_ENTRY_SIZE
;
1596 h
->plt
.offset
= s
->size
;
1598 /* If this symbol is not defined in a regular file, and we are
1599 not generating a shared library, then set the symbol to this
1600 location in the .plt. This is required to make function
1601 pointers compare as equal between the normal executable and
1602 the shared library. */
1606 h
->root
.u
.def
.section
= s
;
1607 h
->root
.u
.def
.value
= h
->plt
.offset
;
1610 /* Make room for this entry. */
1611 s
->size
+= PLT_ENTRY_SIZE
;
1613 /* We also need to make an entry in the .got.plt section, which
1614 will be placed in the .got section by the linker script. */
1615 htab
->sgotplt
->size
+= 4;
1617 /* We also need to make an entry in the .rel.plt section. */
1618 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1619 htab
->next_tls_desc_index
++;
1621 if (htab
->is_vxworks
&& !info
->shared
)
1623 /* VxWorks has a second set of relocations for each PLT entry
1624 in executables. They go in a separate relocation section,
1625 which is processed by the kernel loader. */
1627 /* There are two relocations for the initial PLT entry: an
1628 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
1629 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
1631 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
1632 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1634 /* There are two extra relocations for each subsequent PLT entry:
1635 an R_386_32 relocation for the GOT entry, and an R_386_32
1636 relocation for the PLT entry. */
1638 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1643 h
->plt
.offset
= (bfd_vma
) -1;
1649 h
->plt
.offset
= (bfd_vma
) -1;
1653 eh
= (struct elf_i386_link_hash_entry
*) h
;
1654 eh
->tlsdesc_got
= (bfd_vma
) -1;
1656 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
1657 make it a R_386_TLS_LE_32 requiring no TLS entry. */
1658 if (h
->got
.refcount
> 0
1661 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
1662 h
->got
.offset
= (bfd_vma
) -1;
1663 else if (h
->got
.refcount
> 0)
1667 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1669 /* Make sure this symbol is output as a dynamic symbol.
1670 Undefined weak syms won't yet be marked as dynamic. */
1671 if (h
->dynindx
== -1
1672 && !h
->forced_local
)
1674 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1679 if (GOT_TLS_GDESC_P (tls_type
))
1681 eh
->tlsdesc_got
= htab
->sgotplt
->size
1682 - elf_i386_compute_jump_table_size (htab
);
1683 htab
->sgotplt
->size
+= 8;
1684 h
->got
.offset
= (bfd_vma
) -2;
1686 if (! GOT_TLS_GDESC_P (tls_type
)
1687 || GOT_TLS_GD_P (tls_type
))
1689 h
->got
.offset
= s
->size
;
1691 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
1692 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
1695 dyn
= htab
->elf
.dynamic_sections_created
;
1696 /* R_386_TLS_IE_32 needs one dynamic relocation,
1697 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
1698 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
1699 need two), R_386_TLS_GD needs one if local symbol and two if
1701 if (tls_type
== GOT_TLS_IE_BOTH
)
1702 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1703 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
1704 || (tls_type
& GOT_TLS_IE
))
1705 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1706 else if (GOT_TLS_GD_P (tls_type
))
1707 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1708 else if (! GOT_TLS_GDESC_P (tls_type
)
1709 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1710 || h
->root
.type
!= bfd_link_hash_undefweak
)
1712 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1713 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1714 if (GOT_TLS_GDESC_P (tls_type
))
1715 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1718 h
->got
.offset
= (bfd_vma
) -1;
1720 if (eh
->dyn_relocs
== NULL
)
1723 /* In the shared -Bsymbolic case, discard space allocated for
1724 dynamic pc-relative relocs against symbols which turn out to be
1725 defined in regular objects. For the normal shared case, discard
1726 space for pc-relative relocs that have become local due to symbol
1727 visibility changes. */
1731 /* The only reloc that uses pc_count is R_386_PC32, which will
1732 appear on a call or on something like ".long foo - .". We
1733 want calls to protected symbols to resolve directly to the
1734 function rather than going via the plt. If people want
1735 function pointer comparisons to work as expected then they
1736 should avoid writing assembly like ".long foo - .". */
1737 if (SYMBOL_CALLS_LOCAL (info
, h
))
1739 struct elf_i386_dyn_relocs
**pp
;
1741 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1743 p
->count
-= p
->pc_count
;
1752 /* Also discard relocs on undefined weak syms with non-default
1754 if (eh
->dyn_relocs
!= NULL
1755 && h
->root
.type
== bfd_link_hash_undefweak
)
1757 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
1758 eh
->dyn_relocs
= NULL
;
1760 /* Make sure undefined weak symbols are output as a dynamic
1762 else if (h
->dynindx
== -1
1763 && !h
->forced_local
)
1765 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1770 else if (ELIMINATE_COPY_RELOCS
)
1772 /* For the non-shared case, discard space for relocs against
1773 symbols which turn out to need copy relocs or are not
1779 || (htab
->elf
.dynamic_sections_created
1780 && (h
->root
.type
== bfd_link_hash_undefweak
1781 || h
->root
.type
== bfd_link_hash_undefined
))))
1783 /* Make sure this symbol is output as a dynamic symbol.
1784 Undefined weak syms won't yet be marked as dynamic. */
1785 if (h
->dynindx
== -1
1786 && !h
->forced_local
)
1788 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1792 /* If that succeeded, we know we'll be keeping all the
1794 if (h
->dynindx
!= -1)
1798 eh
->dyn_relocs
= NULL
;
1803 /* Finally, allocate space. */
1804 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1806 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1807 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
1813 /* Find any dynamic relocs that apply to read-only sections. */
1816 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1818 struct elf_i386_link_hash_entry
*eh
;
1819 struct elf_i386_dyn_relocs
*p
;
1821 if (h
->root
.type
== bfd_link_hash_warning
)
1822 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1824 eh
= (struct elf_i386_link_hash_entry
*) h
;
1825 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1827 asection
*s
= p
->sec
->output_section
;
1829 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1831 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1833 info
->flags
|= DF_TEXTREL
;
1835 /* Not an error, just cut short the traversal. */
1842 /* Set the sizes of the dynamic sections. */
1845 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1846 struct bfd_link_info
*info
)
1848 struct elf_i386_link_hash_table
*htab
;
1854 htab
= elf_i386_hash_table (info
);
1855 dynobj
= htab
->elf
.dynobj
;
1859 if (htab
->elf
.dynamic_sections_created
)
1861 /* Set the contents of the .interp section to the interpreter. */
1862 if (info
->executable
)
1864 s
= bfd_get_section_by_name (dynobj
, ".interp");
1867 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1868 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1872 /* Set up .got offsets for local syms, and space for local dynamic
1874 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1876 bfd_signed_vma
*local_got
;
1877 bfd_signed_vma
*end_local_got
;
1878 char *local_tls_type
;
1879 bfd_vma
*local_tlsdesc_gotent
;
1880 bfd_size_type locsymcount
;
1881 Elf_Internal_Shdr
*symtab_hdr
;
1884 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1887 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1889 struct elf_i386_dyn_relocs
*p
;
1891 for (p
= ((struct elf_i386_dyn_relocs
*)
1892 elf_section_data (s
)->local_dynrel
);
1896 if (!bfd_is_abs_section (p
->sec
)
1897 && bfd_is_abs_section (p
->sec
->output_section
))
1899 /* Input section has been discarded, either because
1900 it is a copy of a linkonce section or due to
1901 linker script /DISCARD/, so we'll be discarding
1904 else if (p
->count
!= 0)
1906 srel
= elf_section_data (p
->sec
)->sreloc
;
1907 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
1908 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1909 info
->flags
|= DF_TEXTREL
;
1914 local_got
= elf_local_got_refcounts (ibfd
);
1918 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1919 locsymcount
= symtab_hdr
->sh_info
;
1920 end_local_got
= local_got
+ locsymcount
;
1921 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
1922 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
1924 srel
= htab
->srelgot
;
1925 for (; local_got
< end_local_got
;
1926 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
1928 *local_tlsdesc_gotent
= (bfd_vma
) -1;
1931 if (GOT_TLS_GDESC_P (*local_tls_type
))
1933 *local_tlsdesc_gotent
= htab
->sgotplt
->size
1934 - elf_i386_compute_jump_table_size (htab
);
1935 htab
->sgotplt
->size
+= 8;
1936 *local_got
= (bfd_vma
) -2;
1938 if (! GOT_TLS_GDESC_P (*local_tls_type
)
1939 || GOT_TLS_GD_P (*local_tls_type
))
1941 *local_got
= s
->size
;
1943 if (GOT_TLS_GD_P (*local_tls_type
)
1944 || *local_tls_type
== GOT_TLS_IE_BOTH
)
1948 || GOT_TLS_GD_ANY_P (*local_tls_type
)
1949 || (*local_tls_type
& GOT_TLS_IE
))
1951 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
1952 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
1953 else if (GOT_TLS_GD_P (*local_tls_type
)
1954 || ! GOT_TLS_GDESC_P (*local_tls_type
))
1955 srel
->size
+= sizeof (Elf32_External_Rel
);
1956 if (GOT_TLS_GDESC_P (*local_tls_type
))
1957 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1961 *local_got
= (bfd_vma
) -1;
1965 if (htab
->tls_ldm_got
.refcount
> 0)
1967 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
1969 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
1970 htab
->sgot
->size
+= 8;
1971 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1974 htab
->tls_ldm_got
.offset
= -1;
1976 /* Allocate global sym .plt and .got entries, and space for global
1977 sym dynamic relocs. */
1978 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1980 /* For every jump slot reserved in the sgotplt, reloc_count is
1981 incremented. However, when we reserve space for TLS descriptors,
1982 it's not incremented, so in order to compute the space reserved
1983 for them, it suffices to multiply the reloc count by the jump
1986 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
1988 /* We now have determined the sizes of the various dynamic sections.
1989 Allocate memory for them. */
1991 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1993 bfd_boolean strip_section
= TRUE
;
1995 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2000 || s
== htab
->sgotplt
2001 || s
== htab
->sdynbss
)
2003 /* Strip this section if we don't need it; see the
2005 /* We'd like to strip these sections if they aren't needed, but if
2006 we've exported dynamic symbols from them we must leave them.
2007 It's too late to tell BFD to get rid of the symbols. */
2009 if (htab
->elf
.hplt
!= NULL
)
2010 strip_section
= FALSE
;
2012 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2014 if (s
->size
!= 0 && s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
2017 /* We use the reloc_count field as a counter if we need
2018 to copy relocs into the output file. */
2023 /* It's not one of our sections, so don't allocate space. */
2029 /* If we don't need this section, strip it from the
2030 output file. This is mostly to handle .rel.bss and
2031 .rel.plt. We must create both sections in
2032 create_dynamic_sections, because they must be created
2033 before the linker maps input sections to output
2034 sections. The linker does that before
2035 adjust_dynamic_symbol is called, and it is that
2036 function which decides whether anything needs to go
2037 into these sections. */
2039 s
->flags
|= SEC_EXCLUDE
;
2043 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2046 /* Allocate memory for the section contents. We use bfd_zalloc
2047 here in case unused entries are not reclaimed before the
2048 section's contents are written out. This should not happen,
2049 but this way if it does, we get a R_386_NONE reloc instead
2051 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
2052 if (s
->contents
== NULL
)
2056 if (htab
->elf
.dynamic_sections_created
)
2058 /* Add some entries to the .dynamic section. We fill in the
2059 values later, in elf_i386_finish_dynamic_sections, but we
2060 must add the entries now so that we get the correct size for
2061 the .dynamic section. The DT_DEBUG entry is filled in by the
2062 dynamic linker and used by the debugger. */
2063 #define add_dynamic_entry(TAG, VAL) \
2064 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2066 if (info
->executable
)
2068 if (!add_dynamic_entry (DT_DEBUG
, 0))
2072 if (htab
->splt
->size
!= 0)
2074 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2075 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2076 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2077 || !add_dynamic_entry (DT_JMPREL
, 0))
2083 if (!add_dynamic_entry (DT_REL
, 0)
2084 || !add_dynamic_entry (DT_RELSZ
, 0)
2085 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2088 /* If any dynamic relocs apply to a read-only section,
2089 then we need a DT_TEXTREL entry. */
2090 if ((info
->flags
& DF_TEXTREL
) == 0)
2091 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2094 if ((info
->flags
& DF_TEXTREL
) != 0)
2096 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2101 #undef add_dynamic_entry
2107 elf_i386_always_size_sections (bfd
*output_bfd
,
2108 struct bfd_link_info
*info
)
2110 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2114 struct elf_link_hash_entry
*tlsbase
;
2116 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2117 "_TLS_MODULE_BASE_",
2118 FALSE
, FALSE
, FALSE
);
2120 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2122 struct bfd_link_hash_entry
*bh
= NULL
;
2123 const struct elf_backend_data
*bed
2124 = get_elf_backend_data (output_bfd
);
2126 if (!(_bfd_generic_link_add_one_symbol
2127 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2128 tls_sec
, 0, NULL
, FALSE
,
2129 bed
->collect
, &bh
)))
2131 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2132 tlsbase
->def_regular
= 1;
2133 tlsbase
->other
= STV_HIDDEN
;
2134 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2141 /* Set the correct type for an x86 ELF section. We do this by the
2142 section name, which is a hack, but ought to work. */
2145 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2146 Elf_Internal_Shdr
*hdr
,
2149 register const char *name
;
2151 name
= bfd_get_section_name (abfd
, sec
);
2153 /* This is an ugly, but unfortunately necessary hack that is
2154 needed when producing EFI binaries on x86. It tells
2155 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2156 containing ELF relocation info. We need this hack in order to
2157 be able to generate ELF binaries that can be translated into
2158 EFI applications (which are essentially COFF objects). Those
2159 files contain a COFF ".reloc" section inside an ELFNN object,
2160 which would normally cause BFD to segfault because it would
2161 attempt to interpret this section as containing relocation
2162 entries for section "oc". With this hack enabled, ".reloc"
2163 will be treated as a normal data section, which will avoid the
2164 segfault. However, you won't be able to create an ELFNN binary
2165 with a section named "oc" that needs relocations, but that's
2166 the kind of ugly side-effects you get when detecting section
2167 types based on their names... In practice, this limitation is
2168 unlikely to bite. */
2169 if (strcmp (name
, ".reloc") == 0)
2170 hdr
->sh_type
= SHT_PROGBITS
;
2175 /* Return the base VMA address which should be subtracted from real addresses
2176 when resolving @dtpoff relocation.
2177 This is PT_TLS segment p_vaddr. */
2180 dtpoff_base (struct bfd_link_info
*info
)
2182 /* If tls_sec is NULL, we should have signalled an error already. */
2183 if (elf_hash_table (info
)->tls_sec
== NULL
)
2185 return elf_hash_table (info
)->tls_sec
->vma
;
2188 /* Return the relocation value for @tpoff relocation
2189 if STT_TLS virtual address is ADDRESS. */
2192 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2194 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2196 /* If tls_sec is NULL, we should have signalled an error already. */
2197 if (htab
->tls_sec
== NULL
)
2199 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2202 /* Relocate an i386 ELF section. */
2205 elf_i386_relocate_section (bfd
*output_bfd
,
2206 struct bfd_link_info
*info
,
2208 asection
*input_section
,
2210 Elf_Internal_Rela
*relocs
,
2211 Elf_Internal_Sym
*local_syms
,
2212 asection
**local_sections
)
2214 struct elf_i386_link_hash_table
*htab
;
2215 Elf_Internal_Shdr
*symtab_hdr
;
2216 struct elf_link_hash_entry
**sym_hashes
;
2217 bfd_vma
*local_got_offsets
;
2218 bfd_vma
*local_tlsdesc_gotents
;
2219 Elf_Internal_Rela
*rel
;
2220 Elf_Internal_Rela
*relend
;
2222 htab
= elf_i386_hash_table (info
);
2223 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2224 sym_hashes
= elf_sym_hashes (input_bfd
);
2225 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2226 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2229 relend
= relocs
+ input_section
->reloc_count
;
2230 for (; rel
< relend
; rel
++)
2232 unsigned int r_type
;
2233 reloc_howto_type
*howto
;
2234 unsigned long r_symndx
;
2235 struct elf_link_hash_entry
*h
;
2236 Elf_Internal_Sym
*sym
;
2238 bfd_vma off
, offplt
;
2240 bfd_boolean unresolved_reloc
;
2241 bfd_reloc_status_type r
;
2245 r_type
= ELF32_R_TYPE (rel
->r_info
);
2246 if (r_type
== R_386_GNU_VTINHERIT
2247 || r_type
== R_386_GNU_VTENTRY
)
2250 if ((indx
= r_type
) >= R_386_standard
2251 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2252 >= R_386_ext
- R_386_standard
)
2253 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2254 >= R_386_tls
- R_386_ext
))
2256 (*_bfd_error_handler
)
2257 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2258 input_bfd
, input_section
, r_type
);
2259 bfd_set_error (bfd_error_bad_value
);
2262 howto
= elf_howto_table
+ indx
;
2264 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2268 unresolved_reloc
= FALSE
;
2269 if (r_symndx
< symtab_hdr
->sh_info
)
2271 sym
= local_syms
+ r_symndx
;
2272 sec
= local_sections
[r_symndx
];
2273 relocation
= (sec
->output_section
->vma
2274 + sec
->output_offset
2277 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2278 && ((sec
->flags
& SEC_MERGE
) != 0
2279 || (info
->relocatable
2280 && sec
->output_offset
!= 0)))
2283 bfd_byte
*where
= contents
+ rel
->r_offset
;
2285 switch (howto
->size
)
2288 addend
= bfd_get_8 (input_bfd
, where
);
2289 if (howto
->pc_relative
)
2291 addend
= (addend
^ 0x80) - 0x80;
2296 addend
= bfd_get_16 (input_bfd
, where
);
2297 if (howto
->pc_relative
)
2299 addend
= (addend
^ 0x8000) - 0x8000;
2304 addend
= bfd_get_32 (input_bfd
, where
);
2305 if (howto
->pc_relative
)
2307 addend
= (addend
^ 0x80000000) - 0x80000000;
2315 if (info
->relocatable
)
2316 addend
+= sec
->output_offset
;
2319 asection
*msec
= sec
;
2320 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2322 addend
-= relocation
;
2323 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2326 switch (howto
->size
)
2329 /* FIXME: overflow checks. */
2330 if (howto
->pc_relative
)
2332 bfd_put_8 (input_bfd
, addend
, where
);
2335 if (howto
->pc_relative
)
2337 bfd_put_16 (input_bfd
, addend
, where
);
2340 if (howto
->pc_relative
)
2342 bfd_put_32 (input_bfd
, addend
, where
);
2351 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2352 r_symndx
, symtab_hdr
, sym_hashes
,
2354 unresolved_reloc
, warned
);
2357 if (sec
!= NULL
&& elf_discarded_section (sec
))
2359 /* For relocs against symbols from removed linkonce sections,
2360 or sections discarded by a linker script, we just want the
2361 section contents zeroed. Avoid any special processing. */
2362 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2368 if (info
->relocatable
)
2374 /* Relocation is to the entry for this symbol in the global
2376 if (htab
->sgot
== NULL
)
2383 off
= h
->got
.offset
;
2384 dyn
= htab
->elf
.dynamic_sections_created
;
2385 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2387 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2388 || (ELF_ST_VISIBILITY (h
->other
)
2389 && h
->root
.type
== bfd_link_hash_undefweak
))
2391 /* This is actually a static link, or it is a
2392 -Bsymbolic link and the symbol is defined
2393 locally, or the symbol was forced to be local
2394 because of a version file. We must initialize
2395 this entry in the global offset table. Since the
2396 offset must always be a multiple of 4, we use the
2397 least significant bit to record whether we have
2398 initialized it already.
2400 When doing a dynamic link, we create a .rel.got
2401 relocation entry to initialize the value. This
2402 is done in the finish_dynamic_symbol routine. */
2407 bfd_put_32 (output_bfd
, relocation
,
2408 htab
->sgot
->contents
+ off
);
2413 unresolved_reloc
= FALSE
;
2417 if (local_got_offsets
== NULL
)
2420 off
= local_got_offsets
[r_symndx
];
2422 /* The offset must always be a multiple of 4. We use
2423 the least significant bit to record whether we have
2424 already generated the necessary reloc. */
2429 bfd_put_32 (output_bfd
, relocation
,
2430 htab
->sgot
->contents
+ off
);
2435 Elf_Internal_Rela outrel
;
2442 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2443 + htab
->sgot
->output_offset
2445 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2447 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2448 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2451 local_got_offsets
[r_symndx
] |= 1;
2455 if (off
>= (bfd_vma
) -2)
2458 relocation
= htab
->sgot
->output_section
->vma
2459 + htab
->sgot
->output_offset
+ off
2460 - htab
->sgotplt
->output_section
->vma
2461 - htab
->sgotplt
->output_offset
;
2465 /* Relocation is relative to the start of the global offset
2468 /* Check to make sure it isn't a protected function symbol
2469 for shared library since it may not be local when used
2470 as function address. */
2472 && !info
->executable
2475 && h
->type
== STT_FUNC
2476 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2478 (*_bfd_error_handler
)
2479 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
2480 input_bfd
, h
->root
.root
.string
);
2481 bfd_set_error (bfd_error_bad_value
);
2485 /* Note that sgot is not involved in this
2486 calculation. We always want the start of .got.plt. If we
2487 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2488 permitted by the ABI, we might have to change this
2490 relocation
-= htab
->sgotplt
->output_section
->vma
2491 + htab
->sgotplt
->output_offset
;
2495 /* Use global offset table as symbol value. */
2496 relocation
= htab
->sgotplt
->output_section
->vma
2497 + htab
->sgotplt
->output_offset
;
2498 unresolved_reloc
= FALSE
;
2502 /* Relocation is to the entry for this symbol in the
2503 procedure linkage table. */
2505 /* Resolve a PLT32 reloc against a local symbol directly,
2506 without using the procedure linkage table. */
2510 if (h
->plt
.offset
== (bfd_vma
) -1
2511 || htab
->splt
== NULL
)
2513 /* We didn't make a PLT entry for this symbol. This
2514 happens when statically linking PIC code, or when
2515 using -Bsymbolic. */
2519 relocation
= (htab
->splt
->output_section
->vma
2520 + htab
->splt
->output_offset
2522 unresolved_reloc
= FALSE
;
2527 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2532 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2533 || h
->root
.type
!= bfd_link_hash_undefweak
)
2534 && (r_type
!= R_386_PC32
2535 || !SYMBOL_CALLS_LOCAL (info
, h
)))
2536 || (ELIMINATE_COPY_RELOCS
2543 || h
->root
.type
== bfd_link_hash_undefweak
2544 || h
->root
.type
== bfd_link_hash_undefined
)))
2546 Elf_Internal_Rela outrel
;
2548 bfd_boolean skip
, relocate
;
2551 /* When generating a shared object, these relocations
2552 are copied into the output file to be resolved at run
2559 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2561 if (outrel
.r_offset
== (bfd_vma
) -1)
2563 else if (outrel
.r_offset
== (bfd_vma
) -2)
2564 skip
= TRUE
, relocate
= TRUE
;
2565 outrel
.r_offset
+= (input_section
->output_section
->vma
2566 + input_section
->output_offset
);
2569 memset (&outrel
, 0, sizeof outrel
);
2572 && (r_type
== R_386_PC32
2574 || !SYMBOLIC_BIND (info
, h
)
2575 || !h
->def_regular
))
2576 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2579 /* This symbol is local, or marked to become local. */
2581 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2584 sreloc
= elf_section_data (input_section
)->sreloc
;
2588 loc
= sreloc
->contents
;
2589 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2590 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2592 /* If this reloc is against an external symbol, we do
2593 not want to fiddle with the addend. Otherwise, we
2594 need to include the symbol value so that it becomes
2595 an addend for the dynamic reloc. */
2604 Elf_Internal_Rela outrel
;
2608 outrel
.r_offset
= rel
->r_offset
2609 + input_section
->output_section
->vma
2610 + input_section
->output_offset
;
2611 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2612 sreloc
= elf_section_data (input_section
)->sreloc
;
2615 loc
= sreloc
->contents
;
2616 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2617 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2622 case R_386_TLS_GOTDESC
:
2623 case R_386_TLS_DESC_CALL
:
2624 case R_386_TLS_IE_32
:
2625 case R_386_TLS_GOTIE
:
2626 r_type
= elf_i386_tls_transition (info
, r_type
, h
== NULL
);
2627 tls_type
= GOT_UNKNOWN
;
2628 if (h
== NULL
&& local_got_offsets
)
2629 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
2632 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2633 if (!info
->shared
&& h
->dynindx
== -1 && (tls_type
& GOT_TLS_IE
))
2634 r_type
= R_386_TLS_LE_32
;
2636 if (tls_type
== GOT_TLS_IE
)
2637 tls_type
= GOT_TLS_IE_NEG
;
2638 if (r_type
== R_386_TLS_GD
2639 || r_type
== R_386_TLS_GOTDESC
2640 || r_type
== R_386_TLS_DESC_CALL
)
2642 if (tls_type
== GOT_TLS_IE_POS
)
2643 r_type
= R_386_TLS_GOTIE
;
2644 else if (tls_type
& GOT_TLS_IE
)
2645 r_type
= R_386_TLS_IE_32
;
2648 if (r_type
== R_386_TLS_LE_32
)
2650 BFD_ASSERT (! unresolved_reloc
);
2651 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
2653 unsigned int val
, type
;
2655 unsigned long tls_r_symndx
;
2656 struct elf_link_hash_entry
*tls_h
;
2658 /* GD->LE transition. */
2659 BFD_ASSERT (rel
->r_offset
>= 2);
2660 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2661 BFD_ASSERT (type
== 0x8d || type
== 0x04);
2662 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
2663 BFD_ASSERT (bfd_get_8 (input_bfd
,
2664 contents
+ rel
->r_offset
+ 4)
2666 BFD_ASSERT (rel
+ 1 < relend
);
2667 tls_r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
2668 BFD_ASSERT (tls_r_symndx
>= symtab_hdr
->sh_info
);
2669 tls_h
= sym_hashes
[tls_r_symndx
- symtab_hdr
->sh_info
];
2670 BFD_ASSERT (tls_h
!= NULL
2671 && tls_h
->root
.root
.string
!= NULL
2672 && strcmp (tls_h
->root
.root
.string
,
2673 "___tls_get_addr") == 0);
2674 BFD_ASSERT ((! info
->shared
2675 && ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
)
2676 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
2677 roff
= rel
->r_offset
+ 5;
2678 val
= bfd_get_8 (input_bfd
,
2679 contents
+ rel
->r_offset
- 1);
2682 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
2684 movl %gs:0, %eax; subl $foo@tpoff, %eax
2685 (6 byte form of subl). */
2686 BFD_ASSERT (rel
->r_offset
>= 3);
2687 BFD_ASSERT (bfd_get_8 (input_bfd
,
2688 contents
+ rel
->r_offset
- 3)
2690 BFD_ASSERT ((val
& 0xc7) == 0x05 && val
!= (4 << 3));
2691 memcpy (contents
+ rel
->r_offset
- 3,
2692 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2696 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
2697 if (rel
->r_offset
+ 10 <= input_section
->size
2698 && bfd_get_8 (input_bfd
,
2699 contents
+ rel
->r_offset
+ 9) == 0x90)
2701 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
2703 movl %gs:0, %eax; subl $foo@tpoff, %eax
2704 (6 byte form of subl). */
2705 memcpy (contents
+ rel
->r_offset
- 2,
2706 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2707 roff
= rel
->r_offset
+ 6;
2711 /* leal foo(%reg), %eax; call ___tls_get_addr
2713 movl %gs:0, %eax; subl $foo@tpoff, %eax
2714 (5 byte form of subl). */
2715 memcpy (contents
+ rel
->r_offset
- 2,
2716 "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2719 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2721 /* Skip R_386_PC32/R_386_PLT32. */
2725 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
2727 /* GDesc -> LE transition.
2728 It's originally something like:
2729 leal x@tlsdesc(%ebx), %eax
2733 Registers other than %eax may be set up here. */
2735 unsigned int val
, type
;
2738 /* First, make sure it's a leal adding ebx to a
2739 32-bit offset into any register, although it's
2740 probably almost always going to be eax. */
2741 roff
= rel
->r_offset
;
2742 BFD_ASSERT (roff
>= 2);
2743 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
2744 BFD_ASSERT (type
== 0x8d);
2745 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2746 BFD_ASSERT ((val
& 0xc7) == 0x83);
2747 BFD_ASSERT (roff
+ 4 <= input_section
->size
);
2749 /* Now modify the instruction as appropriate. */
2750 /* aoliva FIXME: remove the above and xor the byte
2752 bfd_put_8 (output_bfd
, val
^ 0x86,
2753 contents
+ roff
- 1);
2754 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2758 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
2760 /* GDesc -> LE transition.
2766 unsigned int val
, type
;
2769 /* First, make sure it's a call *(%eax). */
2770 roff
= rel
->r_offset
;
2771 BFD_ASSERT (roff
+ 2 <= input_section
->size
);
2772 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
2773 BFD_ASSERT (type
== 0xff);
2774 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
2775 BFD_ASSERT (val
== 0x10);
2777 /* Now modify the instruction as appropriate. Use
2778 xchg %ax,%ax instead of 2 nops. */
2779 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
2780 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
2783 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
2785 unsigned int val
, type
;
2787 /* IE->LE transition:
2788 Originally it can be one of:
2796 BFD_ASSERT (rel
->r_offset
>= 1);
2797 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2798 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->size
);
2801 /* movl foo, %eax. */
2802 bfd_put_8 (output_bfd
, 0xb8,
2803 contents
+ rel
->r_offset
- 1);
2807 BFD_ASSERT (rel
->r_offset
>= 2);
2808 type
= bfd_get_8 (input_bfd
,
2809 contents
+ rel
->r_offset
- 2);
2814 BFD_ASSERT ((val
& 0xc7) == 0x05);
2815 bfd_put_8 (output_bfd
, 0xc7,
2816 contents
+ rel
->r_offset
- 2);
2817 bfd_put_8 (output_bfd
,
2818 0xc0 | ((val
>> 3) & 7),
2819 contents
+ rel
->r_offset
- 1);
2823 BFD_ASSERT ((val
& 0xc7) == 0x05);
2824 bfd_put_8 (output_bfd
, 0x81,
2825 contents
+ rel
->r_offset
- 2);
2826 bfd_put_8 (output_bfd
,
2827 0xc0 | ((val
>> 3) & 7),
2828 contents
+ rel
->r_offset
- 1);
2835 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2836 contents
+ rel
->r_offset
);
2841 unsigned int val
, type
;
2843 /* {IE_32,GOTIE}->LE transition:
2844 Originally it can be one of:
2845 subl foo(%reg1), %reg2
2846 movl foo(%reg1), %reg2
2847 addl foo(%reg1), %reg2
2850 movl $foo, %reg2 (6 byte form)
2851 addl $foo, %reg2. */
2852 BFD_ASSERT (rel
->r_offset
>= 2);
2853 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2854 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2855 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->size
);
2856 BFD_ASSERT ((val
& 0xc0) == 0x80 && (val
& 7) != 4);
2860 bfd_put_8 (output_bfd
, 0xc7,
2861 contents
+ rel
->r_offset
- 2);
2862 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
2863 contents
+ rel
->r_offset
- 1);
2865 else if (type
== 0x2b)
2868 bfd_put_8 (output_bfd
, 0x81,
2869 contents
+ rel
->r_offset
- 2);
2870 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
2871 contents
+ rel
->r_offset
- 1);
2873 else if (type
== 0x03)
2876 bfd_put_8 (output_bfd
, 0x81,
2877 contents
+ rel
->r_offset
- 2);
2878 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
2879 contents
+ rel
->r_offset
- 1);
2883 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
2884 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2885 contents
+ rel
->r_offset
);
2887 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2888 contents
+ rel
->r_offset
);
2893 if (htab
->sgot
== NULL
)
2898 off
= h
->got
.offset
;
2899 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
2903 if (local_got_offsets
== NULL
)
2906 off
= local_got_offsets
[r_symndx
];
2907 offplt
= local_tlsdesc_gotents
[r_symndx
];
2914 Elf_Internal_Rela outrel
;
2919 if (htab
->srelgot
== NULL
)
2922 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2924 if (GOT_TLS_GDESC_P (tls_type
))
2926 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
2927 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
2928 <= htab
->sgotplt
->size
);
2929 outrel
.r_offset
= (htab
->sgotplt
->output_section
->vma
2930 + htab
->sgotplt
->output_offset
2932 + htab
->sgotplt_jump_table_size
);
2933 sreloc
= htab
->srelplt
;
2934 loc
= sreloc
->contents
;
2935 loc
+= (htab
->next_tls_desc_index
++
2936 * sizeof (Elf32_External_Rel
));
2937 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
2938 <= sreloc
->contents
+ sreloc
->size
);
2939 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2942 BFD_ASSERT (! unresolved_reloc
);
2943 bfd_put_32 (output_bfd
,
2944 relocation
- dtpoff_base (info
),
2945 htab
->sgotplt
->contents
+ offplt
2946 + htab
->sgotplt_jump_table_size
+ 4);
2950 bfd_put_32 (output_bfd
, 0,
2951 htab
->sgotplt
->contents
+ offplt
2952 + htab
->sgotplt_jump_table_size
+ 4);
2956 sreloc
= htab
->srelgot
;
2958 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2959 + htab
->sgot
->output_offset
+ off
);
2961 if (GOT_TLS_GD_P (tls_type
))
2962 dr_type
= R_386_TLS_DTPMOD32
;
2963 else if (GOT_TLS_GDESC_P (tls_type
))
2965 else if (tls_type
== GOT_TLS_IE_POS
)
2966 dr_type
= R_386_TLS_TPOFF
;
2968 dr_type
= R_386_TLS_TPOFF32
;
2970 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
2971 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
2972 htab
->sgot
->contents
+ off
);
2973 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
2974 bfd_put_32 (output_bfd
, dtpoff_base (info
) - relocation
,
2975 htab
->sgot
->contents
+ off
);
2976 else if (dr_type
!= R_386_TLS_DESC
)
2977 bfd_put_32 (output_bfd
, 0,
2978 htab
->sgot
->contents
+ off
);
2979 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
2981 loc
= sreloc
->contents
;
2982 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2983 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
2984 <= sreloc
->contents
+ sreloc
->size
);
2985 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2987 if (GOT_TLS_GD_P (tls_type
))
2991 BFD_ASSERT (! unresolved_reloc
);
2992 bfd_put_32 (output_bfd
,
2993 relocation
- dtpoff_base (info
),
2994 htab
->sgot
->contents
+ off
+ 4);
2998 bfd_put_32 (output_bfd
, 0,
2999 htab
->sgot
->contents
+ off
+ 4);
3000 outrel
.r_info
= ELF32_R_INFO (indx
,
3001 R_386_TLS_DTPOFF32
);
3002 outrel
.r_offset
+= 4;
3003 sreloc
->reloc_count
++;
3004 loc
+= sizeof (Elf32_External_Rel
);
3005 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3006 <= sreloc
->contents
+ sreloc
->size
);
3007 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3010 else if (tls_type
== GOT_TLS_IE_BOTH
)
3012 bfd_put_32 (output_bfd
,
3013 indx
== 0 ? relocation
- dtpoff_base (info
) : 0,
3014 htab
->sgot
->contents
+ off
+ 4);
3015 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3016 outrel
.r_offset
+= 4;
3017 sreloc
->reloc_count
++;
3018 loc
+= sizeof (Elf32_External_Rel
);
3019 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3026 local_got_offsets
[r_symndx
] |= 1;
3029 if (off
>= (bfd_vma
) -2
3030 && ! GOT_TLS_GDESC_P (tls_type
))
3032 if (r_type
== R_386_TLS_GOTDESC
3033 || r_type
== R_386_TLS_DESC_CALL
)
3035 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3036 unresolved_reloc
= FALSE
;
3038 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3040 bfd_vma g_o_t
= htab
->sgotplt
->output_section
->vma
3041 + htab
->sgotplt
->output_offset
;
3042 relocation
= htab
->sgot
->output_section
->vma
3043 + htab
->sgot
->output_offset
+ off
- g_o_t
;
3044 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3045 && tls_type
== GOT_TLS_IE_BOTH
)
3047 if (r_type
== R_386_TLS_IE
)
3048 relocation
+= g_o_t
;
3049 unresolved_reloc
= FALSE
;
3051 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3053 unsigned int val
, type
;
3056 /* GD->IE transition. */
3057 BFD_ASSERT (rel
->r_offset
>= 2);
3058 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3059 BFD_ASSERT (type
== 0x8d || type
== 0x04);
3060 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
3061 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
3063 BFD_ASSERT (rel
+ 1 < relend
);
3064 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
3065 roff
= rel
->r_offset
- 3;
3066 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3069 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3071 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3072 BFD_ASSERT (rel
->r_offset
>= 3);
3073 BFD_ASSERT (bfd_get_8 (input_bfd
,
3074 contents
+ rel
->r_offset
- 3)
3076 BFD_ASSERT ((val
& 0xc7) == 0x05 && val
!= (4 << 3));
3081 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3083 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3084 BFD_ASSERT (rel
->r_offset
+ 10 <= input_section
->size
);
3085 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
3086 BFD_ASSERT (bfd_get_8 (input_bfd
,
3087 contents
+ rel
->r_offset
+ 9)
3089 roff
= rel
->r_offset
- 2;
3091 memcpy (contents
+ roff
,
3092 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3093 contents
[roff
+ 7] = 0x80 | (val
& 7);
3094 /* If foo is used only with foo@gotntpoff(%reg) and
3095 foo@indntpoff, but not with foo@gottpoff(%reg), change
3096 subl $foo@gottpoff(%reg), %eax
3098 addl $foo@gotntpoff(%reg), %eax. */
3099 if (tls_type
== GOT_TLS_IE_POS
)
3100 contents
[roff
+ 6] = 0x03;
3101 bfd_put_32 (output_bfd
,
3102 htab
->sgot
->output_section
->vma
3103 + htab
->sgot
->output_offset
+ off
3104 - htab
->sgotplt
->output_section
->vma
3105 - htab
->sgotplt
->output_offset
,
3106 contents
+ roff
+ 8);
3107 /* Skip R_386_PLT32. */
3111 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3113 /* GDesc -> IE transition.
3114 It's originally something like:
3115 leal x@tlsdesc(%ebx), %eax
3118 movl x@gotntpoff(%ebx), %eax # before nop; nop
3120 movl x@gottpoff(%ebx), %eax # before negl %eax
3122 Registers other than %eax may be set up here. */
3124 unsigned int val
, type
;
3127 /* First, make sure it's a leal adding ebx to a 32-bit
3128 offset into any register, although it's probably
3129 almost always going to be eax. */
3130 roff
= rel
->r_offset
;
3131 BFD_ASSERT (roff
>= 2);
3132 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3133 BFD_ASSERT (type
== 0x8d);
3134 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3135 BFD_ASSERT ((val
& 0xc7) == 0x83);
3136 BFD_ASSERT (roff
+ 4 <= input_section
->size
);
3138 /* Now modify the instruction as appropriate. */
3139 /* To turn a leal into a movl in the form we use it, it
3140 suffices to change the first byte from 0x8d to 0x8b.
3141 aoliva FIXME: should we decide to keep the leal, all
3142 we have to do is remove the statement below, and
3143 adjust the relaxation of R_386_TLS_DESC_CALL. */
3144 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3146 if (tls_type
== GOT_TLS_IE_BOTH
)
3149 bfd_put_32 (output_bfd
,
3150 htab
->sgot
->output_section
->vma
3151 + htab
->sgot
->output_offset
+ off
3152 - htab
->sgotplt
->output_section
->vma
3153 - htab
->sgotplt
->output_offset
,
3157 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3159 /* GDesc -> IE transition.
3167 depending on how we transformed the TLS_GOTDESC above.
3170 unsigned int val
, type
;
3173 /* First, make sure it's a call *(%eax). */
3174 roff
= rel
->r_offset
;
3175 BFD_ASSERT (roff
+ 2 <= input_section
->size
);
3176 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
3177 BFD_ASSERT (type
== 0xff);
3178 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
3179 BFD_ASSERT (val
== 0x10);
3181 /* Now modify the instruction as appropriate. */
3182 if (tls_type
!= GOT_TLS_IE_NEG
)
3185 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3186 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3191 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3192 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3205 unsigned long tls_r_symndx
;
3206 struct elf_link_hash_entry
*tls_h
;
3208 /* LD->LE transition:
3210 leal foo(%reg), %eax; call ___tls_get_addr.
3212 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3213 BFD_ASSERT (rel
->r_offset
>= 2);
3214 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2)
3216 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3217 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
3218 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
3219 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
3221 BFD_ASSERT (rel
+ 1 < relend
);
3222 tls_r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
3223 BFD_ASSERT (tls_r_symndx
>= symtab_hdr
->sh_info
);
3224 tls_h
= sym_hashes
[tls_r_symndx
- symtab_hdr
->sh_info
];
3225 BFD_ASSERT (tls_h
!= NULL
3226 && tls_h
->root
.root
.string
!= NULL
3227 && strcmp (tls_h
->root
.root
.string
,
3228 "___tls_get_addr") == 0);
3229 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PC32
3230 || ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
3231 memcpy (contents
+ rel
->r_offset
- 2,
3232 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3233 /* Skip R_386_PC32/R_386_PLT32. */
3238 if (htab
->sgot
== NULL
)
3241 off
= htab
->tls_ldm_got
.offset
;
3246 Elf_Internal_Rela outrel
;
3249 if (htab
->srelgot
== NULL
)
3252 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3253 + htab
->sgot
->output_offset
+ off
);
3255 bfd_put_32 (output_bfd
, 0,
3256 htab
->sgot
->contents
+ off
);
3257 bfd_put_32 (output_bfd
, 0,
3258 htab
->sgot
->contents
+ off
+ 4);
3259 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3260 loc
= htab
->srelgot
->contents
;
3261 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3262 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3263 htab
->tls_ldm_got
.offset
|= 1;
3265 relocation
= htab
->sgot
->output_section
->vma
3266 + htab
->sgot
->output_offset
+ off
3267 - htab
->sgotplt
->output_section
->vma
3268 - htab
->sgotplt
->output_offset
;
3269 unresolved_reloc
= FALSE
;
3272 case R_386_TLS_LDO_32
:
3273 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3274 relocation
-= dtpoff_base (info
);
3276 /* When converting LDO to LE, we must negate. */
3277 relocation
= -tpoff (info
, relocation
);
3280 case R_386_TLS_LE_32
:
3284 Elf_Internal_Rela outrel
;
3289 outrel
.r_offset
= rel
->r_offset
3290 + input_section
->output_section
->vma
3291 + input_section
->output_offset
;
3292 if (h
!= NULL
&& h
->dynindx
!= -1)
3296 if (r_type
== R_386_TLS_LE_32
)
3297 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3299 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3300 sreloc
= elf_section_data (input_section
)->sreloc
;
3303 loc
= sreloc
->contents
;
3304 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3305 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3308 else if (r_type
== R_386_TLS_LE_32
)
3309 relocation
= dtpoff_base (info
) - relocation
;
3311 relocation
-= dtpoff_base (info
);
3313 else if (r_type
== R_386_TLS_LE_32
)
3314 relocation
= tpoff (info
, relocation
);
3316 relocation
= -tpoff (info
, relocation
);
3323 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3324 because such sections are not SEC_ALLOC and thus ld.so will
3325 not process them. */
3326 if (unresolved_reloc
3327 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3330 (*_bfd_error_handler
)
3331 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3334 (long) rel
->r_offset
,
3336 h
->root
.root
.string
);
3340 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3341 contents
, rel
->r_offset
,
3344 if (r
!= bfd_reloc_ok
)
3349 name
= h
->root
.root
.string
;
3352 name
= bfd_elf_string_from_elf_section (input_bfd
,
3353 symtab_hdr
->sh_link
,
3358 name
= bfd_section_name (input_bfd
, sec
);
3361 if (r
== bfd_reloc_overflow
)
3363 if (! ((*info
->callbacks
->reloc_overflow
)
3364 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3365 (bfd_vma
) 0, input_bfd
, input_section
,
3371 (*_bfd_error_handler
)
3372 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3373 input_bfd
, input_section
,
3374 (long) rel
->r_offset
, name
, (int) r
);
3383 /* Finish up dynamic symbol handling. We set the contents of various
3384 dynamic sections here. */
3387 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3388 struct bfd_link_info
*info
,
3389 struct elf_link_hash_entry
*h
,
3390 Elf_Internal_Sym
*sym
)
3392 struct elf_i386_link_hash_table
*htab
;
3394 htab
= elf_i386_hash_table (info
);
3396 if (h
->plt
.offset
!= (bfd_vma
) -1)
3400 Elf_Internal_Rela rel
;
3403 /* This symbol has an entry in the procedure linkage table. Set
3406 if (h
->dynindx
== -1
3407 || htab
->splt
== NULL
3408 || htab
->sgotplt
== NULL
3409 || htab
->srelplt
== NULL
)
3412 /* Get the index in the procedure linkage table which
3413 corresponds to this symbol. This is the index of this symbol
3414 in all the symbols for which we are making plt entries. The
3415 first entry in the procedure linkage table is reserved. */
3416 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3418 /* Get the offset into the .got table of the entry that
3419 corresponds to this function. Each .got entry is 4 bytes.
3420 The first three are reserved. */
3421 got_offset
= (plt_index
+ 3) * 4;
3423 /* Fill in the entry in the procedure linkage table. */
3426 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
3428 bfd_put_32 (output_bfd
,
3429 (htab
->sgotplt
->output_section
->vma
3430 + htab
->sgotplt
->output_offset
3432 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3434 if (htab
->is_vxworks
)
3436 int s
, k
, reloc_index
;
3438 /* Create the R_386_32 relocation referencing the GOT
3439 for this PLT entry. */
3441 /* S: Current slot number (zero-based). */
3442 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3443 /* K: Number of relocations for PLTResolve. */
3445 k
= PLTRESOLVE_RELOCS_SHLIB
;
3447 k
= PLTRESOLVE_RELOCS
;
3448 /* Skip the PLTresolve relocations, and the relocations for
3449 the other PLT slots. */
3450 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3451 loc
= (htab
->srelplt2
->contents
+ reloc_index
3452 * sizeof (Elf32_External_Rel
));
3454 rel
.r_offset
= (htab
->splt
->output_section
->vma
3455 + htab
->splt
->output_offset
3456 + h
->plt
.offset
+ 2),
3457 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3458 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3460 /* Create the R_386_32 relocation referencing the beginning of
3461 the PLT for this GOT entry. */
3462 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3463 + htab
->sgotplt
->output_offset
3465 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3466 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3467 loc
+ sizeof (Elf32_External_Rel
));
3472 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
3474 bfd_put_32 (output_bfd
, got_offset
,
3475 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3478 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
3479 htab
->splt
->contents
+ h
->plt
.offset
+ 7);
3480 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
3481 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3483 /* Fill in the entry in the global offset table. */
3484 bfd_put_32 (output_bfd
,
3485 (htab
->splt
->output_section
->vma
3486 + htab
->splt
->output_offset
3489 htab
->sgotplt
->contents
+ got_offset
);
3491 /* Fill in the entry in the .rel.plt section. */
3492 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3493 + htab
->sgotplt
->output_offset
3495 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3496 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3497 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3499 if (!h
->def_regular
)
3501 /* Mark the symbol as undefined, rather than as defined in
3502 the .plt section. Leave the value if there were any
3503 relocations where pointer equality matters (this is a clue
3504 for the dynamic linker, to make function pointer
3505 comparisons work between an application and shared
3506 library), otherwise set it to zero. If a function is only
3507 called from a binary, there is no need to slow down
3508 shared libraries because of that. */
3509 sym
->st_shndx
= SHN_UNDEF
;
3510 if (!h
->pointer_equality_needed
)
3515 if (h
->got
.offset
!= (bfd_vma
) -1
3516 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
3517 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
3519 Elf_Internal_Rela rel
;
3522 /* This symbol has an entry in the global offset table. Set it
3525 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3528 rel
.r_offset
= (htab
->sgot
->output_section
->vma
3529 + htab
->sgot
->output_offset
3530 + (h
->got
.offset
& ~(bfd_vma
) 1));
3532 /* If this is a static link, or it is a -Bsymbolic link and the
3533 symbol is defined locally or was forced to be local because
3534 of a version file, we just want to emit a RELATIVE reloc.
3535 The entry in the global offset table will already have been
3536 initialized in the relocate_section function. */
3538 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3540 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3541 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3545 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3546 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3547 htab
->sgot
->contents
+ h
->got
.offset
);
3548 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3551 loc
= htab
->srelgot
->contents
;
3552 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3553 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3558 Elf_Internal_Rela rel
;
3561 /* This symbol needs a copy reloc. Set it up. */
3563 if (h
->dynindx
== -1
3564 || (h
->root
.type
!= bfd_link_hash_defined
3565 && h
->root
.type
!= bfd_link_hash_defweak
)
3566 || htab
->srelbss
== NULL
)
3569 rel
.r_offset
= (h
->root
.u
.def
.value
3570 + h
->root
.u
.def
.section
->output_section
->vma
3571 + h
->root
.u
.def
.section
->output_offset
);
3572 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
3573 loc
= htab
->srelbss
->contents
;
3574 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3575 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3578 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.
3579 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
3580 is relative to the ".got" section. */
3581 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3582 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
))
3583 sym
->st_shndx
= SHN_ABS
;
3588 /* Used to decide how to sort relocs in an optimal manner for the
3589 dynamic linker, before writing them out. */
3591 static enum elf_reloc_type_class
3592 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
3594 switch (ELF32_R_TYPE (rela
->r_info
))
3596 case R_386_RELATIVE
:
3597 return reloc_class_relative
;
3598 case R_386_JUMP_SLOT
:
3599 return reloc_class_plt
;
3601 return reloc_class_copy
;
3603 return reloc_class_normal
;
3607 /* Finish up the dynamic sections. */
3610 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
3611 struct bfd_link_info
*info
)
3613 struct elf_i386_link_hash_table
*htab
;
3617 htab
= elf_i386_hash_table (info
);
3618 dynobj
= htab
->elf
.dynobj
;
3619 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3621 if (htab
->elf
.dynamic_sections_created
)
3623 Elf32_External_Dyn
*dyncon
, *dynconend
;
3625 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3628 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3629 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3630 for (; dyncon
< dynconend
; dyncon
++)
3632 Elf_Internal_Dyn dyn
;
3635 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3644 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3649 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3654 dyn
.d_un
.d_val
= s
->size
;
3658 /* My reading of the SVR4 ABI indicates that the
3659 procedure linkage table relocs (DT_JMPREL) should be
3660 included in the overall relocs (DT_REL). This is
3661 what Solaris does. However, UnixWare can not handle
3662 that case. Therefore, we override the DT_RELSZ entry
3663 here to make it not include the JMPREL relocs. */
3667 dyn
.d_un
.d_val
-= s
->size
;
3671 /* We may not be using the standard ELF linker script.
3672 If .rel.plt is the first .rel section, we adjust
3673 DT_REL to not include it. */
3677 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
3679 dyn
.d_un
.d_ptr
+= s
->size
;
3683 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3686 /* Fill in the first entry in the procedure linkage table. */
3687 if (htab
->splt
&& htab
->splt
->size
> 0)
3691 memcpy (htab
->splt
->contents
, elf_i386_pic_plt0_entry
,
3692 sizeof (elf_i386_pic_plt0_entry
));
3693 memset (htab
->splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
3694 htab
->plt0_pad_byte
,
3695 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
3699 memcpy (htab
->splt
->contents
, elf_i386_plt0_entry
,
3700 sizeof(elf_i386_plt0_entry
));
3701 memset (htab
->splt
->contents
+ sizeof (elf_i386_plt0_entry
),
3702 htab
->plt0_pad_byte
,
3703 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
3704 bfd_put_32 (output_bfd
,
3705 (htab
->sgotplt
->output_section
->vma
3706 + htab
->sgotplt
->output_offset
3708 htab
->splt
->contents
+ 2);
3709 bfd_put_32 (output_bfd
,
3710 (htab
->sgotplt
->output_section
->vma
3711 + htab
->sgotplt
->output_offset
3713 htab
->splt
->contents
+ 8);
3715 if (htab
->is_vxworks
)
3717 Elf_Internal_Rela rel
;
3719 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
3720 On IA32 we use REL relocations so the addend goes in
3721 the PLT directly. */
3722 rel
.r_offset
= (htab
->splt
->output_section
->vma
3723 + htab
->splt
->output_offset
3725 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3726 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3727 htab
->srelplt2
->contents
);
3728 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
3729 rel
.r_offset
= (htab
->splt
->output_section
->vma
3730 + htab
->splt
->output_offset
3732 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3733 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3734 htab
->srelplt2
->contents
+
3735 sizeof (Elf32_External_Rel
));
3739 /* UnixWare sets the entsize of .plt to 4, although that doesn't
3740 really seem like the right value. */
3741 elf_section_data (htab
->splt
->output_section
)
3742 ->this_hdr
.sh_entsize
= 4;
3744 /* Correct the .rel.plt.unloaded relocations. */
3745 if (htab
->is_vxworks
&& !info
->shared
)
3747 int num_plts
= (htab
->splt
->size
/ PLT_ENTRY_SIZE
) - 1;
3750 p
= htab
->srelplt2
->contents
;
3752 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
3754 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
3756 for (; num_plts
; num_plts
--)
3758 Elf_Internal_Rela rel
;
3759 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3760 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3761 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3762 p
+= sizeof (Elf32_External_Rel
);
3764 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3765 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3766 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3767 p
+= sizeof (Elf32_External_Rel
);
3775 /* Fill in the first three entries in the global offset table. */
3776 if (htab
->sgotplt
->size
> 0)
3778 bfd_put_32 (output_bfd
,
3780 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
3781 htab
->sgotplt
->contents
);
3782 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 4);
3783 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 8);
3786 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
3789 if (htab
->sgot
&& htab
->sgot
->size
> 0)
3790 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
3795 /* Return address for Ith PLT stub in section PLT, for relocation REL
3796 or (bfd_vma) -1 if it should not be included. */
3799 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
3800 const arelent
*rel ATTRIBUTE_UNUSED
)
3802 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3805 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3808 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
3810 if (h
->plt
.offset
!= (bfd_vma
) -1
3812 && !h
->pointer_equality_needed
)
3815 return _bfd_elf_hash_symbol (h
);
3818 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
3819 #define TARGET_LITTLE_NAME "elf32-i386"
3820 #define ELF_ARCH bfd_arch_i386
3821 #define ELF_MACHINE_CODE EM_386
3822 #define ELF_MAXPAGESIZE 0x1000
3824 #define elf_backend_can_gc_sections 1
3825 #define elf_backend_can_refcount 1
3826 #define elf_backend_want_got_plt 1
3827 #define elf_backend_plt_readonly 1
3828 #define elf_backend_want_plt_sym 0
3829 #define elf_backend_got_header_size 12
3831 /* Support RELA for objdump of prelink objects. */
3832 #define elf_info_to_howto elf_i386_info_to_howto_rel
3833 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
3835 #define bfd_elf32_mkobject elf_i386_mkobject
3837 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
3838 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
3839 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
3840 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
3842 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
3843 #define elf_backend_check_relocs elf_i386_check_relocs
3844 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
3845 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
3846 #define elf_backend_fake_sections elf_i386_fake_sections
3847 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
3848 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
3849 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
3850 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
3851 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
3852 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
3853 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
3854 #define elf_backend_relocate_section elf_i386_relocate_section
3855 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
3856 #define elf_backend_always_size_sections elf_i386_always_size_sections
3857 #define elf_backend_omit_section_dynsym \
3858 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
3859 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
3860 #define elf_backend_hash_symbol elf_i386_hash_symbol
3862 #include "elf32-target.h"
3864 /* FreeBSD support. */
3866 #undef TARGET_LITTLE_SYM
3867 #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
3868 #undef TARGET_LITTLE_NAME
3869 #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
3871 #define ELF_OSABI ELFOSABI_FREEBSD
3873 /* The kernel recognizes executables as valid only if they carry a
3874 "FreeBSD" label in the ELF header. So we put this label on all
3875 executables and (for simplicity) also all other object files. */
3878 elf_i386_post_process_headers (bfd
*abfd
,
3879 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3881 Elf_Internal_Ehdr
*i_ehdrp
;
3883 i_ehdrp
= elf_elfheader (abfd
);
3885 /* Put an ABI label supported by FreeBSD >= 4.1. */
3886 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
3887 #ifdef OLD_FREEBSD_ABI_LABEL
3888 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
3889 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
3893 #undef elf_backend_post_process_headers
3894 #define elf_backend_post_process_headers elf_i386_post_process_headers
3896 #define elf32_bed elf32_i386_fbsd_bed
3898 #include "elf32-target.h"
3900 /* VxWorks support. */
3902 #undef TARGET_LITTLE_SYM
3903 #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
3904 #undef TARGET_LITTLE_NAME
3905 #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
3908 /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */
3910 static struct bfd_link_hash_table
*
3911 elf_i386_vxworks_link_hash_table_create (bfd
*abfd
)
3913 struct bfd_link_hash_table
*ret
;
3914 struct elf_i386_link_hash_table
*htab
;
3916 ret
= elf_i386_link_hash_table_create (abfd
);
3919 htab
= (struct elf_i386_link_hash_table
*) ret
;
3920 htab
->is_vxworks
= 1;
3921 htab
->plt0_pad_byte
= 0x90;
3928 #undef elf_backend_post_process_headers
3929 #undef bfd_elf32_bfd_link_hash_table_create
3930 #define bfd_elf32_bfd_link_hash_table_create \
3931 elf_i386_vxworks_link_hash_table_create
3932 #undef elf_backend_add_symbol_hook
3933 #define elf_backend_add_symbol_hook \
3934 elf_vxworks_add_symbol_hook
3935 #undef elf_backend_link_output_symbol_hook
3936 #define elf_backend_link_output_symbol_hook \
3937 elf_vxworks_link_output_symbol_hook
3938 #undef elf_backend_emit_relocs
3939 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
3940 #undef elf_backend_final_write_processing
3941 #define elf_backend_final_write_processing \
3942 elf_vxworks_final_write_processing
3944 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
3946 #undef elf_backend_want_plt_sym
3947 #define elf_backend_want_plt_sym 1
3950 #define elf32_bed elf32_i386_vxworks_bed
3952 #include "elf32-target.h"