2012-05-22 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / bfd / elf32-i386.c
CommitLineData
252b5132 1/* Intel 80386/80486-specific support for 32-bit ELF
b2a8e766 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
1d7e9d18 3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
9f973f28 4 Free Software Foundation, Inc.
252b5132 5
571fe01f 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
571fe01f
NC
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
cd123cb7 10 the Free Software Foundation; either version 3 of the License, or
571fe01f 11 (at your option) any later version.
252b5132 12
571fe01f
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
252b5132 17
571fe01f
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
cd123cb7
NC
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
252b5132 22
252b5132 23#include "sysdep.h"
3db64b00 24#include "bfd.h"
252b5132
RH
25#include "bfdlink.h"
26#include "libbfd.h"
27#include "elf-bfd.h"
5a68afcf 28#include "elf-nacl.h"
eac338cf 29#include "elf-vxworks.h"
142411ca 30#include "bfd_stdint.h"
c25bc9fc
L
31#include "objalloc.h"
32#include "hashtab.h"
e41b3a13 33#include "dwarf2.h"
252b5132 34
55fd94b0
AM
35/* 386 uses REL relocations instead of RELA. */
36#define USE_REL 1
252b5132
RH
37
38#include "elf/i386.h"
39
40static reloc_howto_type elf_howto_table[]=
41{
b34976b6 42 HOWTO(R_386_NONE, 0, 0, 0, FALSE, 0, complain_overflow_bitfield,
1b452ec6 43 bfd_elf_generic_reloc, "R_386_NONE",
b34976b6
AM
44 TRUE, 0x00000000, 0x00000000, FALSE),
45 HOWTO(R_386_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
1b452ec6 46 bfd_elf_generic_reloc, "R_386_32",
b34976b6
AM
47 TRUE, 0xffffffff, 0xffffffff, FALSE),
48 HOWTO(R_386_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
1b452ec6 49 bfd_elf_generic_reloc, "R_386_PC32",
b34976b6
AM
50 TRUE, 0xffffffff, 0xffffffff, TRUE),
51 HOWTO(R_386_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
1b452ec6 52 bfd_elf_generic_reloc, "R_386_GOT32",
b34976b6
AM
53 TRUE, 0xffffffff, 0xffffffff, FALSE),
54 HOWTO(R_386_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
1b452ec6 55 bfd_elf_generic_reloc, "R_386_PLT32",
b34976b6
AM
56 TRUE, 0xffffffff, 0xffffffff, TRUE),
57 HOWTO(R_386_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
1b452ec6 58 bfd_elf_generic_reloc, "R_386_COPY",
b34976b6
AM
59 TRUE, 0xffffffff, 0xffffffff, FALSE),
60 HOWTO(R_386_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
1b452ec6 61 bfd_elf_generic_reloc, "R_386_GLOB_DAT",
b34976b6
AM
62 TRUE, 0xffffffff, 0xffffffff, FALSE),
63 HOWTO(R_386_JUMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
1b452ec6 64 bfd_elf_generic_reloc, "R_386_JUMP_SLOT",
b34976b6
AM
65 TRUE, 0xffffffff, 0xffffffff, FALSE),
66 HOWTO(R_386_RELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
1b452ec6 67 bfd_elf_generic_reloc, "R_386_RELATIVE",
b34976b6
AM
68 TRUE, 0xffffffff, 0xffffffff, FALSE),
69 HOWTO(R_386_GOTOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
1b452ec6 70 bfd_elf_generic_reloc, "R_386_GOTOFF",
b34976b6
AM
71 TRUE, 0xffffffff, 0xffffffff, FALSE),
72 HOWTO(R_386_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
1b452ec6 73 bfd_elf_generic_reloc, "R_386_GOTPC",
b34976b6 74 TRUE, 0xffffffff, 0xffffffff, TRUE),
1b452ec6 75
dc47f327
AM
76 /* We have a gap in the reloc numbers here.
77 R_386_standard counts the number up to this point, and
78 R_386_ext_offset is the value to subtract from a reloc type of
79 R_386_16 thru R_386_PC8 to form an index into this table. */
55fd94b0
AM
80#define R_386_standard (R_386_GOTPC + 1)
81#define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
1b452ec6 82
37e55690 83 /* These relocs are a GNU extension. */
b34976b6 84 HOWTO(R_386_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
37e55690 85 bfd_elf_generic_reloc, "R_386_TLS_TPOFF",
b34976b6
AM
86 TRUE, 0xffffffff, 0xffffffff, FALSE),
87 HOWTO(R_386_TLS_IE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
37e55690 88 bfd_elf_generic_reloc, "R_386_TLS_IE",
b34976b6
AM
89 TRUE, 0xffffffff, 0xffffffff, FALSE),
90 HOWTO(R_386_TLS_GOTIE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
37e55690 91 bfd_elf_generic_reloc, "R_386_TLS_GOTIE",
b34976b6
AM
92 TRUE, 0xffffffff, 0xffffffff, FALSE),
93 HOWTO(R_386_TLS_LE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 94 bfd_elf_generic_reloc, "R_386_TLS_LE",
b34976b6
AM
95 TRUE, 0xffffffff, 0xffffffff, FALSE),
96 HOWTO(R_386_TLS_GD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 97 bfd_elf_generic_reloc, "R_386_TLS_GD",
b34976b6
AM
98 TRUE, 0xffffffff, 0xffffffff, FALSE),
99 HOWTO(R_386_TLS_LDM, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 100 bfd_elf_generic_reloc, "R_386_TLS_LDM",
b34976b6
AM
101 TRUE, 0xffffffff, 0xffffffff, FALSE),
102 HOWTO(R_386_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
1b452ec6 103 bfd_elf_generic_reloc, "R_386_16",
b34976b6 104 TRUE, 0xffff, 0xffff, FALSE),
b0360d8c 105 HOWTO(R_386_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
1b452ec6 106 bfd_elf_generic_reloc, "R_386_PC16",
b34976b6
AM
107 TRUE, 0xffff, 0xffff, TRUE),
108 HOWTO(R_386_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
1b452ec6 109 bfd_elf_generic_reloc, "R_386_8",
b34976b6
AM
110 TRUE, 0xff, 0xff, FALSE),
111 HOWTO(R_386_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
1b452ec6 112 bfd_elf_generic_reloc, "R_386_PC8",
b34976b6 113 TRUE, 0xff, 0xff, TRUE),
dc47f327 114
55fd94b0
AM
115#define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
116#define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
13ae64f3 117 /* These are common with Solaris TLS implementation. */
b34976b6 118 HOWTO(R_386_TLS_LDO_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 119 bfd_elf_generic_reloc, "R_386_TLS_LDO_32",
b34976b6
AM
120 TRUE, 0xffffffff, 0xffffffff, FALSE),
121 HOWTO(R_386_TLS_IE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 122 bfd_elf_generic_reloc, "R_386_TLS_IE_32",
b34976b6
AM
123 TRUE, 0xffffffff, 0xffffffff, FALSE),
124 HOWTO(R_386_TLS_LE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 125 bfd_elf_generic_reloc, "R_386_TLS_LE_32",
b34976b6
AM
126 TRUE, 0xffffffff, 0xffffffff, FALSE),
127 HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 128 bfd_elf_generic_reloc, "R_386_TLS_DTPMOD32",
b34976b6
AM
129 TRUE, 0xffffffff, 0xffffffff, FALSE),
130 HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 131 bfd_elf_generic_reloc, "R_386_TLS_DTPOFF32",
b34976b6
AM
132 TRUE, 0xffffffff, 0xffffffff, FALSE),
133 HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
13ae64f3 134 bfd_elf_generic_reloc, "R_386_TLS_TPOFF32",
b34976b6 135 TRUE, 0xffffffff, 0xffffffff, FALSE),
67a4f2b7
AO
136 EMPTY_HOWTO (38),
137 HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
138 bfd_elf_generic_reloc, "R_386_TLS_GOTDESC",
139 TRUE, 0xffffffff, 0xffffffff, FALSE),
140 HOWTO(R_386_TLS_DESC_CALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
141 bfd_elf_generic_reloc, "R_386_TLS_DESC_CALL",
142 FALSE, 0, 0, FALSE),
143 HOWTO(R_386_TLS_DESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
144 bfd_elf_generic_reloc, "R_386_TLS_DESC",
145 TRUE, 0xffffffff, 0xffffffff, FALSE),
cbe950e9
L
146 HOWTO(R_386_IRELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
147 bfd_elf_generic_reloc, "R_386_IRELATIVE",
148 TRUE, 0xffffffff, 0xffffffff, FALSE),
13ae64f3
JJ
149
150 /* Another gap. */
cbe950e9
L
151#define R_386_irelative (R_386_IRELATIVE + 1 - R_386_tls_offset)
152#define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_irelative)
252b5132
RH
153
154/* GNU extension to record C++ vtable hierarchy. */
252b5132
RH
155 HOWTO (R_386_GNU_VTINHERIT, /* type */
156 0, /* rightshift */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
158 0, /* bitsize */
b34976b6 159 FALSE, /* pc_relative */
252b5132
RH
160 0, /* bitpos */
161 complain_overflow_dont, /* complain_on_overflow */
162 NULL, /* special_function */
163 "R_386_GNU_VTINHERIT", /* name */
b34976b6 164 FALSE, /* partial_inplace */
252b5132
RH
165 0, /* src_mask */
166 0, /* dst_mask */
b34976b6 167 FALSE), /* pcrel_offset */
252b5132
RH
168
169/* GNU extension to record C++ vtable member usage. */
252b5132
RH
170 HOWTO (R_386_GNU_VTENTRY, /* type */
171 0, /* rightshift */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
173 0, /* bitsize */
b34976b6 174 FALSE, /* pc_relative */
252b5132
RH
175 0, /* bitpos */
176 complain_overflow_dont, /* complain_on_overflow */
177 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
178 "R_386_GNU_VTENTRY", /* name */
b34976b6 179 FALSE, /* partial_inplace */
252b5132
RH
180 0, /* src_mask */
181 0, /* dst_mask */
b34976b6 182 FALSE) /* pcrel_offset */
dc47f327 183
55fd94b0 184#define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
dc47f327
AM
185
186};
187
252b5132 188#ifdef DEBUG_GEN_RELOC
55fd94b0
AM
189#define TRACE(str) \
190 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
252b5132
RH
191#else
192#define TRACE(str)
193#endif
194
195static reloc_howto_type *
55fd94b0
AM
196elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
197 bfd_reloc_code_real_type code)
252b5132
RH
198{
199 switch (code)
200 {
201 case BFD_RELOC_NONE:
202 TRACE ("BFD_RELOC_NONE");
55fd94b0 203 return &elf_howto_table[R_386_NONE];
252b5132
RH
204
205 case BFD_RELOC_32:
206 TRACE ("BFD_RELOC_32");
55fd94b0 207 return &elf_howto_table[R_386_32];
252b5132
RH
208
209 case BFD_RELOC_CTOR:
210 TRACE ("BFD_RELOC_CTOR");
55fd94b0 211 return &elf_howto_table[R_386_32];
252b5132
RH
212
213 case BFD_RELOC_32_PCREL:
214 TRACE ("BFD_RELOC_PC32");
55fd94b0 215 return &elf_howto_table[R_386_PC32];
252b5132
RH
216
217 case BFD_RELOC_386_GOT32:
218 TRACE ("BFD_RELOC_386_GOT32");
55fd94b0 219 return &elf_howto_table[R_386_GOT32];
252b5132
RH
220
221 case BFD_RELOC_386_PLT32:
222 TRACE ("BFD_RELOC_386_PLT32");
55fd94b0 223 return &elf_howto_table[R_386_PLT32];
252b5132
RH
224
225 case BFD_RELOC_386_COPY:
226 TRACE ("BFD_RELOC_386_COPY");
55fd94b0 227 return &elf_howto_table[R_386_COPY];
252b5132
RH
228
229 case BFD_RELOC_386_GLOB_DAT:
230 TRACE ("BFD_RELOC_386_GLOB_DAT");
55fd94b0 231 return &elf_howto_table[R_386_GLOB_DAT];
252b5132
RH
232
233 case BFD_RELOC_386_JUMP_SLOT:
234 TRACE ("BFD_RELOC_386_JUMP_SLOT");
55fd94b0 235 return &elf_howto_table[R_386_JUMP_SLOT];
252b5132
RH
236
237 case BFD_RELOC_386_RELATIVE:
238 TRACE ("BFD_RELOC_386_RELATIVE");
55fd94b0 239 return &elf_howto_table[R_386_RELATIVE];
252b5132
RH
240
241 case BFD_RELOC_386_GOTOFF:
242 TRACE ("BFD_RELOC_386_GOTOFF");
55fd94b0 243 return &elf_howto_table[R_386_GOTOFF];
252b5132
RH
244
245 case BFD_RELOC_386_GOTPC:
246 TRACE ("BFD_RELOC_386_GOTPC");
55fd94b0 247 return &elf_howto_table[R_386_GOTPC];
252b5132 248
37e55690
JJ
249 /* These relocs are a GNU extension. */
250 case BFD_RELOC_386_TLS_TPOFF:
251 TRACE ("BFD_RELOC_386_TLS_TPOFF");
55fd94b0 252 return &elf_howto_table[R_386_TLS_TPOFF - R_386_ext_offset];
37e55690
JJ
253
254 case BFD_RELOC_386_TLS_IE:
255 TRACE ("BFD_RELOC_386_TLS_IE");
55fd94b0 256 return &elf_howto_table[R_386_TLS_IE - R_386_ext_offset];
37e55690
JJ
257
258 case BFD_RELOC_386_TLS_GOTIE:
259 TRACE ("BFD_RELOC_386_TLS_GOTIE");
55fd94b0 260 return &elf_howto_table[R_386_TLS_GOTIE - R_386_ext_offset];
37e55690 261
13ae64f3
JJ
262 case BFD_RELOC_386_TLS_LE:
263 TRACE ("BFD_RELOC_386_TLS_LE");
55fd94b0 264 return &elf_howto_table[R_386_TLS_LE - R_386_ext_offset];
13ae64f3
JJ
265
266 case BFD_RELOC_386_TLS_GD:
267 TRACE ("BFD_RELOC_386_TLS_GD");
55fd94b0 268 return &elf_howto_table[R_386_TLS_GD - R_386_ext_offset];
13ae64f3
JJ
269
270 case BFD_RELOC_386_TLS_LDM:
271 TRACE ("BFD_RELOC_386_TLS_LDM");
55fd94b0 272 return &elf_howto_table[R_386_TLS_LDM - R_386_ext_offset];
13ae64f3 273
252b5132
RH
274 case BFD_RELOC_16:
275 TRACE ("BFD_RELOC_16");
55fd94b0 276 return &elf_howto_table[R_386_16 - R_386_ext_offset];
252b5132
RH
277
278 case BFD_RELOC_16_PCREL:
279 TRACE ("BFD_RELOC_16_PCREL");
55fd94b0 280 return &elf_howto_table[R_386_PC16 - R_386_ext_offset];
252b5132
RH
281
282 case BFD_RELOC_8:
283 TRACE ("BFD_RELOC_8");
55fd94b0 284 return &elf_howto_table[R_386_8 - R_386_ext_offset];
252b5132
RH
285
286 case BFD_RELOC_8_PCREL:
287 TRACE ("BFD_RELOC_8_PCREL");
55fd94b0 288 return &elf_howto_table[R_386_PC8 - R_386_ext_offset];
252b5132 289
13ae64f3
JJ
290 /* Common with Sun TLS implementation. */
291 case BFD_RELOC_386_TLS_LDO_32:
292 TRACE ("BFD_RELOC_386_TLS_LDO_32");
55fd94b0 293 return &elf_howto_table[R_386_TLS_LDO_32 - R_386_tls_offset];
13ae64f3
JJ
294
295 case BFD_RELOC_386_TLS_IE_32:
296 TRACE ("BFD_RELOC_386_TLS_IE_32");
55fd94b0 297 return &elf_howto_table[R_386_TLS_IE_32 - R_386_tls_offset];
13ae64f3
JJ
298
299 case BFD_RELOC_386_TLS_LE_32:
300 TRACE ("BFD_RELOC_386_TLS_LE_32");
55fd94b0 301 return &elf_howto_table[R_386_TLS_LE_32 - R_386_tls_offset];
13ae64f3
JJ
302
303 case BFD_RELOC_386_TLS_DTPMOD32:
304 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
55fd94b0 305 return &elf_howto_table[R_386_TLS_DTPMOD32 - R_386_tls_offset];
13ae64f3
JJ
306
307 case BFD_RELOC_386_TLS_DTPOFF32:
308 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
55fd94b0 309 return &elf_howto_table[R_386_TLS_DTPOFF32 - R_386_tls_offset];
13ae64f3
JJ
310
311 case BFD_RELOC_386_TLS_TPOFF32:
312 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
55fd94b0 313 return &elf_howto_table[R_386_TLS_TPOFF32 - R_386_tls_offset];
13ae64f3 314
67a4f2b7
AO
315 case BFD_RELOC_386_TLS_GOTDESC:
316 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
317 return &elf_howto_table[R_386_TLS_GOTDESC - R_386_tls_offset];
318
319 case BFD_RELOC_386_TLS_DESC_CALL:
320 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
321 return &elf_howto_table[R_386_TLS_DESC_CALL - R_386_tls_offset];
322
323 case BFD_RELOC_386_TLS_DESC:
324 TRACE ("BFD_RELOC_386_TLS_DESC");
325 return &elf_howto_table[R_386_TLS_DESC - R_386_tls_offset];
326
cbe950e9
L
327 case BFD_RELOC_386_IRELATIVE:
328 TRACE ("BFD_RELOC_386_IRELATIVE");
2a750708 329 return &elf_howto_table[R_386_IRELATIVE - R_386_tls_offset];
cbe950e9 330
252b5132
RH
331 case BFD_RELOC_VTABLE_INHERIT:
332 TRACE ("BFD_RELOC_VTABLE_INHERIT");
55fd94b0 333 return &elf_howto_table[R_386_GNU_VTINHERIT - R_386_vt_offset];
252b5132
RH
334
335 case BFD_RELOC_VTABLE_ENTRY:
336 TRACE ("BFD_RELOC_VTABLE_ENTRY");
55fd94b0 337 return &elf_howto_table[R_386_GNU_VTENTRY - R_386_vt_offset];
252b5132
RH
338
339 default:
340 break;
341 }
342
343 TRACE ("Unknown");
344 return 0;
345}
346
157090f7
AM
347static reloc_howto_type *
348elf_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
349 const char *r_name)
350{
351 unsigned int i;
352
353 for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++)
354 if (elf_howto_table[i].name != NULL
355 && strcasecmp (elf_howto_table[i].name, r_name) == 0)
356 return &elf_howto_table[i];
357
358 return NULL;
359}
360
142411ca
L
361static reloc_howto_type *
362elf_i386_rtype_to_howto (bfd *abfd, unsigned r_type)
252b5132 363{
dc47f327
AM
364 unsigned int indx;
365
366 if ((indx = r_type) >= R_386_standard
367 && ((indx = r_type - R_386_ext_offset) - R_386_standard
368 >= R_386_ext - R_386_standard)
13ae64f3 369 && ((indx = r_type - R_386_tls_offset) - R_386_ext
cbe950e9
L
370 >= R_386_irelative - R_386_ext)
371 && ((indx = r_type - R_386_vt_offset) - R_386_irelative
372 >= R_386_vt - R_386_irelative))
252b5132 373 {
d003868e
AM
374 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
375 abfd, (int) r_type);
55fd94b0 376 indx = R_386_NONE;
252b5132 377 }
142411ca
L
378 BFD_ASSERT (elf_howto_table [indx].type == r_type);
379 return &elf_howto_table[indx];
380}
381
382static void
383elf_i386_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
384 arelent *cache_ptr,
385 Elf_Internal_Rela *dst)
386{
387 unsigned int r_type = ELF32_R_TYPE (dst->r_info);
388 cache_ptr->howto = elf_i386_rtype_to_howto (abfd, r_type);
252b5132
RH
389}
390
391/* Return whether a symbol name implies a local label. The UnixWare
392 2.1 cc generates temporary symbols that start with .X, so we
393 recognize them here. FIXME: do other SVR4 compilers also use .X?.
394 If so, we should move the .X recognition into
395 _bfd_elf_is_local_label_name. */
396
b34976b6 397static bfd_boolean
55fd94b0 398elf_i386_is_local_label_name (bfd *abfd, const char *name)
252b5132
RH
399{
400 if (name[0] == '.' && name[1] == 'X')
b34976b6 401 return TRUE;
252b5132
RH
402
403 return _bfd_elf_is_local_label_name (abfd, name);
404}
405\f
38701953 406/* Support for core dump NOTE sections. */
61adc1a4 407
b34976b6 408static bfd_boolean
55fd94b0 409elf_i386_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
38701953
AM
410{
411 int offset;
eea6121a 412 size_t size;
38701953 413
61adc1a4 414 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
38701953 415 {
61adc1a4
NC
416 int pr_version = bfd_get_32 (abfd, note->descdata);
417
418 if (pr_version != 1)
419 return FALSE;
420
421 /* pr_cursig */
422 elf_tdata (abfd)->core_signal = bfd_get_32 (abfd, note->descdata + 20);
423
424 /* pr_pid */
261b8d08 425 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
61adc1a4
NC
426
427 /* pr_reg */
428 offset = 28;
eea6121a 429 size = bfd_get_32 (abfd, note->descdata + 8);
61adc1a4
NC
430 }
431 else
432 {
433 switch (note->descsz)
434 {
435 default:
436 return FALSE;
38701953 437
61adc1a4
NC
438 case 144: /* Linux/i386 */
439 /* pr_cursig */
440 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
38701953 441
61adc1a4 442 /* pr_pid */
261b8d08 443 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
38701953 444
61adc1a4
NC
445 /* pr_reg */
446 offset = 72;
eea6121a 447 size = 68;
38701953 448
61adc1a4
NC
449 break;
450 }
38701953
AM
451 }
452
453 /* Make a ".reg/999" section. */
454 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
eea6121a 455 size, note->descpos + offset);
38701953
AM
456}
457
b34976b6 458static bfd_boolean
55fd94b0 459elf_i386_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
38701953 460{
61adc1a4 461 if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
38701953 462 {
61adc1a4
NC
463 int pr_version = bfd_get_32 (abfd, note->descdata);
464
465 if (pr_version != 1)
b34976b6 466 return FALSE;
38701953 467
61adc1a4
NC
468 elf_tdata (abfd)->core_program
469 = _bfd_elfcore_strndup (abfd, note->descdata + 8, 17);
470 elf_tdata (abfd)->core_command
471 = _bfd_elfcore_strndup (abfd, note->descdata + 25, 81);
472 }
473 else
474 {
475 switch (note->descsz)
476 {
477 default:
478 return FALSE;
479
480 case 124: /* Linux/i386 elf_prpsinfo. */
261b8d08
PA
481 elf_tdata (abfd)->core_pid
482 = bfd_get_32 (abfd, note->descdata + 12);
61adc1a4
NC
483 elf_tdata (abfd)->core_program
484 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
485 elf_tdata (abfd)->core_command
486 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
487 }
38701953
AM
488 }
489
490 /* Note that for some reason, a spurious space is tacked
491 onto the end of the args in some (at least one anyway)
492 implementations, so strip it off if it exists. */
38701953
AM
493 {
494 char *command = elf_tdata (abfd)->core_command;
495 int n = strlen (command);
496
497 if (0 < n && command[n - 1] == ' ')
498 command[n - 1] = '\0';
499 }
500
b34976b6 501 return TRUE;
38701953
AM
502}
503\f
504/* Functions for the i386 ELF linker.
505
506 In order to gain some understanding of code in this file without
507 knowing all the intricate details of the linker, note the
508 following:
509
510 Functions named elf_i386_* are called by external routines, other
511 functions are only called locally. elf_i386_* functions appear
512 in this file more or less in the order in which they are called
513 from external routines. eg. elf_i386_check_relocs is called
514 early in the link process, elf_i386_finish_dynamic_sections is
515 one of the last functions. */
516
252b5132
RH
517
518/* The name of the dynamic interpreter. This is put in the .interp
519 section. */
520
521#define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
522
a23b6845
AM
523/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
524 copying dynamic variables from a shared lib into an app's dynbss
525 section, and instead use a dynamic relocation to point into the
526 shared lib. */
527#define ELIMINATE_COPY_RELOCS 1
528
252b5132
RH
529/* The size in bytes of an entry in the procedure linkage table. */
530
531#define PLT_ENTRY_SIZE 16
532
533/* The first entry in an absolute procedure linkage table looks like
eac338cf
PB
534 this. See the SVR4 ABI i386 supplement to see how this works.
535 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
252b5132 536
eac338cf 537static const bfd_byte elf_i386_plt0_entry[12] =
252b5132
RH
538{
539 0xff, 0x35, /* pushl contents of address */
540 0, 0, 0, 0, /* replaced with address of .got + 4. */
541 0xff, 0x25, /* jmp indirect */
eac338cf 542 0, 0, 0, 0 /* replaced with address of .got + 8. */
252b5132
RH
543};
544
545/* Subsequent entries in an absolute procedure linkage table look like
546 this. */
547
548static const bfd_byte elf_i386_plt_entry[PLT_ENTRY_SIZE] =
549{
550 0xff, 0x25, /* jmp indirect */
551 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
552 0x68, /* pushl immediate */
553 0, 0, 0, 0, /* replaced with offset into relocation table. */
554 0xe9, /* jmp relative */
555 0, 0, 0, 0 /* replaced with offset to start of .plt. */
556};
557
eac338cf
PB
558/* The first entry in a PIC procedure linkage table look like this.
559 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
252b5132 560
eac338cf 561static const bfd_byte elf_i386_pic_plt0_entry[12] =
252b5132
RH
562{
563 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
eac338cf 564 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
252b5132
RH
565};
566
567/* Subsequent entries in a PIC procedure linkage table look like this. */
568
569static const bfd_byte elf_i386_pic_plt_entry[PLT_ENTRY_SIZE] =
570{
571 0xff, 0xa3, /* jmp *offset(%ebx) */
572 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
573 0x68, /* pushl immediate */
574 0, 0, 0, 0, /* replaced with offset into relocation table. */
575 0xe9, /* jmp relative */
576 0, 0, 0, 0 /* replaced with offset to start of .plt. */
577};
578
e41b3a13
JJ
579/* .eh_frame covering the .plt section. */
580
581static const bfd_byte elf_i386_eh_frame_plt[] =
582{
583#define PLT_CIE_LENGTH 20
584#define PLT_FDE_LENGTH 36
585#define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
586#define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
587 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
588 0, 0, 0, 0, /* CIE ID */
589 1, /* CIE version */
590 'z', 'R', 0, /* Augmentation string */
591 1, /* Code alignment factor */
592 0x7c, /* Data alignment factor */
593 8, /* Return address column */
594 1, /* Augmentation size */
595 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
596 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
597 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
598 DW_CFA_nop, DW_CFA_nop,
599
600 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
601 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
602 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
603 0, 0, 0, 0, /* .plt size goes here */
604 0, /* Augmentation size */
605 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
606 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
607 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
608 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
609 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
610 11, /* Block length */
611 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
612 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
613 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
28ede8be 614 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
e41b3a13
JJ
615 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
616};
617
25e762b9
RM
618struct elf_i386_plt_layout
619{
620 /* The first entry in an absolute procedure linkage table looks like this. */
621 const bfd_byte *plt0_entry;
622 unsigned int plt0_entry_size;
623
624 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
625 unsigned int plt0_got1_offset;
626 unsigned int plt0_got2_offset;
627
628 /* Later entries in an absolute procedure linkage table look like this. */
629 const bfd_byte *plt_entry;
630 unsigned int plt_entry_size;
631
632 /* Offsets into plt_entry that are to be replaced with... */
633 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
634 unsigned int plt_reloc_offset; /* ... offset into relocation table. */
635 unsigned int plt_plt_offset; /* ... offset to start of .plt. */
636
637 /* Offset into plt_entry where the initial value of the GOT entry points. */
638 unsigned int plt_lazy_offset;
639
640 /* The first entry in a PIC procedure linkage table looks like this. */
641 const bfd_byte *pic_plt0_entry;
642
643 /* Subsequent entries in a PIC procedure linkage table look like this. */
644 const bfd_byte *pic_plt_entry;
645
646 /* .eh_frame covering the .plt section. */
647 const bfd_byte *eh_frame_plt;
648 unsigned int eh_frame_plt_size;
649};
650
651#define GET_PLT_ENTRY_SIZE(abfd) \
652 get_elf_i386_backend_data (abfd)->plt->plt_entry_size
653
654/* These are the standard parameters. */
655static const struct elf_i386_plt_layout elf_i386_plt =
656 {
657 elf_i386_plt0_entry, /* plt0_entry */
658 sizeof (elf_i386_plt0_entry), /* plt0_entry_size */
659 2, /* plt0_got1_offset */
660 8, /* plt0_got2_offset */
661 elf_i386_plt_entry, /* plt_entry */
662 PLT_ENTRY_SIZE, /* plt_entry_size */
663 2, /* plt_got_offset */
664 7, /* plt_reloc_offset */
665 12, /* plt_plt_offset */
666 6, /* plt_lazy_offset */
667 elf_i386_pic_plt0_entry, /* pic_plt0_entry */
668 elf_i386_pic_plt_entry, /* pic_plt_entry */
669 elf_i386_eh_frame_plt, /* eh_frame_plt */
670 sizeof (elf_i386_eh_frame_plt), /* eh_frame_plt_size */
671 };
672\f
673
eac338cf
PB
674/* On VxWorks, the .rel.plt.unloaded section has absolute relocations
675 for the PLTResolve stub and then for each PLT entry. */
676#define PLTRESOLVE_RELOCS_SHLIB 0
677#define PLTRESOLVE_RELOCS 2
678#define PLT_NON_JUMP_SLOT_RELOCS 2
679
23209a78
RM
680/* Architecture-specific backend data for i386. */
681
682struct elf_i386_backend_data
683{
25e762b9
RM
684 /* Parameters describing PLT generation. */
685 const struct elf_i386_plt_layout *plt;
686
23209a78
RM
687 /* Value used to fill the unused bytes of the first PLT entry. */
688 bfd_byte plt0_pad_byte;
689
690 /* True if the target system is VxWorks. */
691 int is_vxworks;
692};
693
694#define get_elf_i386_backend_data(abfd) \
695 ((const struct elf_i386_backend_data *) \
696 get_elf_backend_data (abfd)->arch_data)
697
698/* These are the standard parameters. */
699static const struct elf_i386_backend_data elf_i386_arch_bed =
700 {
25e762b9 701 &elf_i386_plt, /* plt */
23209a78
RM
702 0, /* plt0_pad_byte */
703 0, /* is_vxworks */
704 };
705
706#define elf_backend_arch_data &elf_i386_arch_bed
707
252b5132
RH
708/* i386 ELF linker hash entry. */
709
710struct elf_i386_link_hash_entry
711{
ebe50bae 712 struct elf_link_hash_entry elf;
252b5132 713
0c715baa 714 /* Track dynamic relocs copied for this symbol. */
e03a8ed8 715 struct elf_dyn_relocs *dyn_relocs;
13ae64f3 716
37e55690
JJ
717#define GOT_UNKNOWN 0
718#define GOT_NORMAL 1
719#define GOT_TLS_GD 2
720#define GOT_TLS_IE 4
721#define GOT_TLS_IE_POS 5
722#define GOT_TLS_IE_NEG 6
723#define GOT_TLS_IE_BOTH 7
67a4f2b7
AO
724#define GOT_TLS_GDESC 8
725#define GOT_TLS_GD_BOTH_P(type) \
726 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
727#define GOT_TLS_GD_P(type) \
728 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
729#define GOT_TLS_GDESC_P(type) \
730 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
731#define GOT_TLS_GD_ANY_P(type) \
732 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
37e55690 733 unsigned char tls_type;
67a4f2b7
AO
734
735 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
736 starting at the end of the jump table. */
737 bfd_vma tlsdesc_got;
13ae64f3
JJ
738};
739
740#define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
741
742struct elf_i386_obj_tdata
743{
744 struct elf_obj_tdata root;
745
746 /* tls_type for each local got entry. */
747 char *local_got_tls_type;
67a4f2b7
AO
748
749 /* GOTPLT entries for TLS descriptors. */
750 bfd_vma *local_tlsdesc_gotent;
252b5132
RH
751};
752
13ae64f3
JJ
753#define elf_i386_tdata(abfd) \
754 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
755
756#define elf_i386_local_got_tls_type(abfd) \
757 (elf_i386_tdata (abfd)->local_got_tls_type)
758
67a4f2b7
AO
759#define elf_i386_local_tlsdesc_gotent(abfd) \
760 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
761
0ffa91dd
NC
762#define is_i386_elf(bfd) \
763 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
764 && elf_tdata (bfd) != NULL \
4dfe6ac6 765 && elf_object_id (bfd) == I386_ELF_DATA)
0ffa91dd 766
b34976b6 767static bfd_boolean
55fd94b0 768elf_i386_mkobject (bfd *abfd)
13ae64f3 769{
0ffa91dd 770 return bfd_elf_allocate_object (abfd, sizeof (struct elf_i386_obj_tdata),
4dfe6ac6 771 I386_ELF_DATA);
13ae64f3 772}
cedb70c5 773
252b5132
RH
774/* i386 ELF linker hash table. */
775
776struct elf_i386_link_hash_table
777{
ebe50bae 778 struct elf_link_hash_table elf;
252b5132 779
6725bdbf 780 /* Short-cuts to get to dynamic linker sections. */
6725bdbf
AM
781 asection *sdynbss;
782 asection *srelbss;
e41b3a13 783 asection *plt_eh_frame;
9635fe29 784
4dfe6ac6
NC
785 union
786 {
13ae64f3
JJ
787 bfd_signed_vma refcount;
788 bfd_vma offset;
789 } tls_ldm_got;
790
67a4f2b7
AO
791 /* The amount of space used by the reserved portion of the sgotplt
792 section, plus whatever space is used by the jump slots. */
793 bfd_vma sgotplt_jump_table_size;
794
87d72d41
AM
795 /* Small local sym cache. */
796 struct sym_cache sym_cache;
9f03412a
AO
797
798 /* _TLS_MODULE_BASE_ symbol. */
799 struct bfd_link_hash_entry *tls_module_base;
c25bc9fc
L
800
801 /* Used by local STT_GNU_IFUNC symbols. */
802 htab_t loc_hash_table;
4dfe6ac6
NC
803 void * loc_hash_memory;
804
805 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
806 asection *srelplt2;
807
4dfe6ac6
NC
808 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
809 bfd_vma next_tls_desc_index;
e1f98742
L
810
811 /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
812 bfd_vma next_jump_slot_index;
813
814 /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
815 bfd_vma next_irelative_index;
6725bdbf 816};
252b5132
RH
817
818/* Get the i386 ELF linker hash table from a link_info structure. */
819
820#define elf_i386_hash_table(p) \
4dfe6ac6
NC
821 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
822 == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL)
252b5132 823
67a4f2b7 824#define elf_i386_compute_jump_table_size(htab) \
5ae0bfb6 825 ((htab)->next_tls_desc_index * 4)
67a4f2b7 826
252b5132
RH
827/* Create an entry in an i386 ELF linker hash table. */
828
829static struct bfd_hash_entry *
eb4ff4d6
L
830elf_i386_link_hash_newfunc (struct bfd_hash_entry *entry,
831 struct bfd_hash_table *table,
832 const char *string)
252b5132 833{
252b5132
RH
834 /* Allocate the structure if it has not already been allocated by a
835 subclass. */
ebe50bae
AM
836 if (entry == NULL)
837 {
a50b1753
NC
838 entry = (struct bfd_hash_entry *)
839 bfd_hash_allocate (table, sizeof (struct elf_i386_link_hash_entry));
ebe50bae
AM
840 if (entry == NULL)
841 return entry;
842 }
252b5132
RH
843
844 /* Call the allocation method of the superclass. */
ebe50bae
AM
845 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
846 if (entry != NULL)
252b5132 847 {
ebe50bae
AM
848 struct elf_i386_link_hash_entry *eh;
849
850 eh = (struct elf_i386_link_hash_entry *) entry;
851 eh->dyn_relocs = NULL;
13ae64f3 852 eh->tls_type = GOT_UNKNOWN;
67a4f2b7 853 eh->tlsdesc_got = (bfd_vma) -1;
252b5132
RH
854 }
855
ebe50bae 856 return entry;
252b5132
RH
857}
858
c25bc9fc
L
859/* Compute a hash of a local hash entry. We use elf_link_hash_entry
860 for local symbol so that we can handle local STT_GNU_IFUNC symbols
861 as global symbol. We reuse indx and dynstr_index for local symbol
862 hash since they aren't used by global symbols in this backend. */
863
864static hashval_t
865elf_i386_local_htab_hash (const void *ptr)
866{
867 struct elf_link_hash_entry *h
868 = (struct elf_link_hash_entry *) ptr;
d2149d72 869 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
c25bc9fc
L
870}
871
872/* Compare local hash entries. */
873
874static int
875elf_i386_local_htab_eq (const void *ptr1, const void *ptr2)
876{
877 struct elf_link_hash_entry *h1
878 = (struct elf_link_hash_entry *) ptr1;
879 struct elf_link_hash_entry *h2
880 = (struct elf_link_hash_entry *) ptr2;
881
882 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
883}
884
885/* Find and/or create a hash entry for local symbol. */
886
887static struct elf_link_hash_entry *
888elf_i386_get_local_sym_hash (struct elf_i386_link_hash_table *htab,
889 bfd *abfd, const Elf_Internal_Rela *rel,
890 bfd_boolean create)
891{
892 struct elf_i386_link_hash_entry e, *ret;
893 asection *sec = abfd->sections;
d2149d72
L
894 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
895 ELF32_R_SYM (rel->r_info));
c25bc9fc
L
896 void **slot;
897
898 e.elf.indx = sec->id;
899 e.elf.dynstr_index = ELF32_R_SYM (rel->r_info);
900 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
901 create ? INSERT : NO_INSERT);
902
903 if (!slot)
904 return NULL;
905
906 if (*slot)
907 {
908 ret = (struct elf_i386_link_hash_entry *) *slot;
909 return &ret->elf;
910 }
911
912 ret = (struct elf_i386_link_hash_entry *)
913 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
914 sizeof (struct elf_i386_link_hash_entry));
915 if (ret)
916 {
917 memset (ret, 0, sizeof (*ret));
918 ret->elf.indx = sec->id;
919 ret->elf.dynstr_index = ELF32_R_SYM (rel->r_info);
920 ret->elf.dynindx = -1;
c25bc9fc
L
921 *slot = ret;
922 }
923 return &ret->elf;
924}
925
252b5132
RH
926/* Create an i386 ELF linker hash table. */
927
928static struct bfd_link_hash_table *
55fd94b0 929elf_i386_link_hash_table_create (bfd *abfd)
252b5132
RH
930{
931 struct elf_i386_link_hash_table *ret;
dc810e39 932 bfd_size_type amt = sizeof (struct elf_i386_link_hash_table);
252b5132 933
a50b1753 934 ret = (struct elf_i386_link_hash_table *) bfd_malloc (amt);
ebe50bae 935 if (ret == NULL)
252b5132
RH
936 return NULL;
937
eb4ff4d6
L
938 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
939 elf_i386_link_hash_newfunc,
4dfe6ac6
NC
940 sizeof (struct elf_i386_link_hash_entry),
941 I386_ELF_DATA))
252b5132 942 {
e2d34d7d 943 free (ret);
252b5132
RH
944 return NULL;
945 }
946
6725bdbf
AM
947 ret->sdynbss = NULL;
948 ret->srelbss = NULL;
332ce62b 949 ret->plt_eh_frame = NULL;
7a624474 950 ret->tls_ldm_got.refcount = 0;
5ae0bfb6 951 ret->next_tls_desc_index = 0;
67a4f2b7 952 ret->sgotplt_jump_table_size = 0;
87d72d41 953 ret->sym_cache.abfd = NULL;
eac338cf 954 ret->srelplt2 = NULL;
9f03412a 955 ret->tls_module_base = NULL;
e1f98742
L
956 ret->next_jump_slot_index = 0;
957 ret->next_irelative_index = 0;
6725bdbf 958
c25bc9fc
L
959 ret->loc_hash_table = htab_try_create (1024,
960 elf_i386_local_htab_hash,
961 elf_i386_local_htab_eq,
962 NULL);
963 ret->loc_hash_memory = objalloc_create ();
964 if (!ret->loc_hash_table || !ret->loc_hash_memory)
965 {
966 free (ret);
967 return NULL;
968 }
969
ebe50bae 970 return &ret->elf.root;
252b5132
RH
971}
972
c25bc9fc
L
973/* Destroy an i386 ELF linker hash table. */
974
975static void
976elf_i386_link_hash_table_free (struct bfd_link_hash_table *hash)
977{
978 struct elf_i386_link_hash_table *htab
979 = (struct elf_i386_link_hash_table *) hash;
980
981 if (htab->loc_hash_table)
982 htab_delete (htab->loc_hash_table);
983 if (htab->loc_hash_memory)
984 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
985 _bfd_generic_link_hash_table_free (hash);
986}
987
6725bdbf
AM
988/* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
989 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
990 hash table. */
991
b34976b6 992static bfd_boolean
55fd94b0 993elf_i386_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
6725bdbf
AM
994{
995 struct elf_i386_link_hash_table *htab;
996
6725bdbf 997 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
b34976b6 998 return FALSE;
6725bdbf 999
6de2ae4a 1000 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
1001 if (htab == NULL)
1002 return FALSE;
1003
6725bdbf
AM
1004 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1005 if (!info->shared)
1006 htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss");
1007
6de2ae4a 1008 if (!htab->sdynbss
6725bdbf
AM
1009 || (!info->shared && !htab->srelbss))
1010 abort ();
1011
23209a78 1012 if (get_elf_i386_backend_data (dynobj)->is_vxworks
6de2ae4a
L
1013 && !elf_vxworks_create_dynamic_sections (dynobj, info,
1014 &htab->srelplt2))
711de32c 1015 return FALSE;
eac338cf 1016
e41b3a13 1017 if (!info->no_ld_generated_unwind_info
2fe0fd06 1018 && htab->plt_eh_frame == NULL
5d4f7eb2
L
1019 && htab->elf.splt != NULL
1020 && bfd_get_section_by_name (dynobj, ".eh_frame") != NULL)
e41b3a13
JJ
1021 {
1022 flagword flags = get_elf_backend_data (dynobj)->dynamic_sec_flags;
1023 htab->plt_eh_frame
2fe0fd06
L
1024 = bfd_make_section_anyway_with_flags (dynobj, ".eh_frame",
1025 (flags
1026 | SEC_LINKER_CREATED
1027 | SEC_READONLY));
e41b3a13
JJ
1028 if (htab->plt_eh_frame == NULL
1029 || !bfd_set_section_alignment (dynobj, htab->plt_eh_frame, 2))
1030 return FALSE;
1031
1032 htab->plt_eh_frame->size = sizeof (elf_i386_eh_frame_plt);
1033 htab->plt_eh_frame->contents
1034 = bfd_alloc (dynobj, htab->plt_eh_frame->size);
1035 memcpy (htab->plt_eh_frame->contents, elf_i386_eh_frame_plt,
1036 sizeof (elf_i386_eh_frame_plt));
1037 }
1038
b34976b6 1039 return TRUE;
6725bdbf
AM
1040}
1041
ebe50bae
AM
1042/* Copy the extra info we tack onto an elf_link_hash_entry. */
1043
51b64d56 1044static void
fcfa13d2 1045elf_i386_copy_indirect_symbol (struct bfd_link_info *info,
55fd94b0
AM
1046 struct elf_link_hash_entry *dir,
1047 struct elf_link_hash_entry *ind)
ebe50bae
AM
1048{
1049 struct elf_i386_link_hash_entry *edir, *eind;
1050
1051 edir = (struct elf_i386_link_hash_entry *) dir;
1052 eind = (struct elf_i386_link_hash_entry *) ind;
1053
bbd7ec4a 1054 if (eind->dyn_relocs != NULL)
ebe50bae 1055 {
bbd7ec4a
AM
1056 if (edir->dyn_relocs != NULL)
1057 {
e03a8ed8
L
1058 struct elf_dyn_relocs **pp;
1059 struct elf_dyn_relocs *p;
bbd7ec4a 1060
fcfa13d2 1061 /* Add reloc counts against the indirect sym to the direct sym
bbd7ec4a
AM
1062 list. Merge any entries against the same section. */
1063 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1064 {
e03a8ed8 1065 struct elf_dyn_relocs *q;
bbd7ec4a
AM
1066
1067 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1068 if (q->sec == p->sec)
1069 {
1070 q->pc_count += p->pc_count;
1071 q->count += p->count;
1072 *pp = p->next;
1073 break;
1074 }
1075 if (q == NULL)
1076 pp = &p->next;
1077 }
1078 *pp = edir->dyn_relocs;
1079 }
1080
ebe50bae
AM
1081 edir->dyn_relocs = eind->dyn_relocs;
1082 eind->dyn_relocs = NULL;
1083 }
ebe50bae 1084
cd67d266
JJ
1085 if (ind->root.type == bfd_link_hash_indirect
1086 && dir->got.refcount <= 0)
1087 {
1088 edir->tls_type = eind->tls_type;
1089 eind->tls_type = GOT_UNKNOWN;
1090 }
81848ca0
AM
1091
1092 if (ELIMINATE_COPY_RELOCS
1093 && ind->root.type != bfd_link_hash_indirect
f5385ebf
AM
1094 && dir->dynamic_adjusted)
1095 {
1096 /* If called to transfer flags for a weakdef during processing
1097 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1098 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1099 dir->ref_dynamic |= ind->ref_dynamic;
1100 dir->ref_regular |= ind->ref_regular;
1101 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
1102 dir->needs_plt |= ind->needs_plt;
1103 dir->pointer_equality_needed |= ind->pointer_equality_needed;
1104 }
81848ca0 1105 else
fcfa13d2 1106 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
ebe50bae
AM
1107}
1108
142411ca
L
1109/* Return TRUE if the TLS access code sequence support transition
1110 from R_TYPE. */
1111
1112static bfd_boolean
1113elf_i386_check_tls_transition (bfd *abfd, asection *sec,
1114 bfd_byte *contents,
1115 Elf_Internal_Shdr *symtab_hdr,
1116 struct elf_link_hash_entry **sym_hashes,
1117 unsigned int r_type,
1118 const Elf_Internal_Rela *rel,
1119 const Elf_Internal_Rela *relend)
13ae64f3 1120{
142411ca
L
1121 unsigned int val, type;
1122 unsigned long r_symndx;
1123 struct elf_link_hash_entry *h;
1124 bfd_vma offset;
1125
1126 /* Get the section contents. */
1127 if (contents == NULL)
1128 {
1129 if (elf_section_data (sec)->this_hdr.contents != NULL)
1130 contents = elf_section_data (sec)->this_hdr.contents;
1131 else
1132 {
1133 /* FIXME: How to better handle error condition? */
1134 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1135 return FALSE;
13ae64f3 1136
142411ca
L
1137 /* Cache the section contents for elf_link_input_bfd. */
1138 elf_section_data (sec)->this_hdr.contents = contents;
1139 }
1140 }
1141
1142 offset = rel->r_offset;
13ae64f3 1143 switch (r_type)
142411ca
L
1144 {
1145 case R_386_TLS_GD:
1146 case R_386_TLS_LDM:
1147 if (offset < 2 || (rel + 1) >= relend)
1148 return FALSE;
1149
1150 type = bfd_get_8 (abfd, contents + offset - 2);
1151 if (r_type == R_386_TLS_GD)
1152 {
09e8c3bf 1153 /* Check transition from GD access model. Only
142411ca
L
1154 leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr
1155 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop
1156 can transit to different access model. */
1157 if ((offset + 10) > sec->size ||
1158 (type != 0x8d && type != 0x04))
1159 return FALSE;
1160
1161 val = bfd_get_8 (abfd, contents + offset - 1);
1162 if (type == 0x04)
1163 {
1164 /* leal foo@tlsgd(,%reg,1), %eax; call ___tls_get_addr */
1165 if (offset < 3)
1166 return FALSE;
1167
1168 if (bfd_get_8 (abfd, contents + offset - 3) != 0x8d)
1169 return FALSE;
1170
1171 if ((val & 0xc7) != 0x05 || val == (4 << 3))
1172 return FALSE;
1173 }
1174 else
1175 {
1176 /* leal foo@tlsgd(%reg), %eax; call ___tls_get_addr; nop */
1177 if ((val & 0xf8) != 0x80 || (val & 7) == 4)
1178 return FALSE;
1179
1180 if (bfd_get_8 (abfd, contents + offset + 9) != 0x90)
1181 return FALSE;
1182 }
1183 }
1184 else
1185 {
1186 /* Check transition from LD access model. Only
1187 leal foo@tlsgd(%reg), %eax; call ___tls_get_addr
1188 can transit to different access model. */
1189 if (type != 0x8d || (offset + 9) > sec->size)
1190 return FALSE;
1191
1192 val = bfd_get_8 (abfd, contents + offset - 1);
1193 if ((val & 0xf8) != 0x80 || (val & 7) == 4)
1194 return FALSE;
1195 }
1196
1197 if (bfd_get_8 (abfd, contents + offset + 4) != 0xe8)
1198 return FALSE;
1199
1200 r_symndx = ELF32_R_SYM (rel[1].r_info);
1201 if (r_symndx < symtab_hdr->sh_info)
1202 return FALSE;
1203
1204 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
c4fb387b
L
1205 /* Use strncmp to check ___tls_get_addr since ___tls_get_addr
1206 may be versioned. */
142411ca
L
1207 return (h != NULL
1208 && h->root.root.string != NULL
1209 && (ELF32_R_TYPE (rel[1].r_info) == R_386_PC32
1210 || ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32)
c4fb387b
L
1211 && (strncmp (h->root.root.string, "___tls_get_addr",
1212 15) == 0));
142411ca
L
1213
1214 case R_386_TLS_IE:
1215 /* Check transition from IE access model:
1216 movl foo@indntpoff(%rip), %eax
1217 movl foo@indntpoff(%rip), %reg
1218 addl foo@indntpoff(%rip), %reg
1219 */
1220
1221 if (offset < 1 || (offset + 4) > sec->size)
1222 return FALSE;
1223
1224 /* Check "movl foo@tpoff(%rip), %eax" first. */
1225 val = bfd_get_8 (abfd, contents + offset - 1);
1226 if (val == 0xa1)
1227 return TRUE;
1228
1229 if (offset < 2)
1230 return FALSE;
1231
1232 /* Check movl|addl foo@tpoff(%rip), %reg. */
1233 type = bfd_get_8 (abfd, contents + offset - 2);
1234 return ((type == 0x8b || type == 0x03)
1235 && (val & 0xc7) == 0x05);
1236
1237 case R_386_TLS_GOTIE:
1238 case R_386_TLS_IE_32:
1239 /* Check transition from {IE_32,GOTIE} access model:
1240 subl foo@{tpoff,gontoff}(%reg1), %reg2
1241 movl foo@{tpoff,gontoff}(%reg1), %reg2
1242 addl foo@{tpoff,gontoff}(%reg1), %reg2
1243 */
1244
1245 if (offset < 2 || (offset + 4) > sec->size)
1246 return FALSE;
1247
1248 val = bfd_get_8 (abfd, contents + offset - 1);
1249 if ((val & 0xc0) != 0x80 || (val & 7) == 4)
1250 return FALSE;
1251
1252 type = bfd_get_8 (abfd, contents + offset - 2);
1253 return type == 0x8b || type == 0x2b || type == 0x03;
1254
1255 case R_386_TLS_GOTDESC:
1256 /* Check transition from GDesc access model:
1257 leal x@tlsdesc(%ebx), %eax
1258
1259 Make sure it's a leal adding ebx to a 32-bit offset
1260 into any register, although it's probably almost always
1261 going to be eax. */
1262
1263 if (offset < 2 || (offset + 4) > sec->size)
1264 return FALSE;
1265
1266 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1267 return FALSE;
1268
1269 val = bfd_get_8 (abfd, contents + offset - 1);
1270 return (val & 0xc7) == 0x83;
1271
1272 case R_386_TLS_DESC_CALL:
1273 /* Check transition from GDesc access model:
1274 call *x@tlsdesc(%rax)
1275 */
1276 if (offset + 2 <= sec->size)
1277 {
1278 /* Make sure that it's a call *x@tlsdesc(%rax). */
fa289a5f
AM
1279 static const unsigned char call[] = { 0xff, 0x10 };
1280 return memcmp (contents + offset, call, 2) == 0;
142411ca
L
1281 }
1282
1283 return FALSE;
1284
1285 default:
1286 abort ();
1287 }
1288}
1289
1290/* Return TRUE if the TLS access transition is OK or no transition
1291 will be performed. Update R_TYPE if there is a transition. */
1292
1293static bfd_boolean
1294elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd,
1295 asection *sec, bfd_byte *contents,
1296 Elf_Internal_Shdr *symtab_hdr,
1297 struct elf_link_hash_entry **sym_hashes,
1298 unsigned int *r_type, int tls_type,
1299 const Elf_Internal_Rela *rel,
1300 const Elf_Internal_Rela *relend,
4c544807
L
1301 struct elf_link_hash_entry *h,
1302 unsigned long r_symndx)
142411ca
L
1303{
1304 unsigned int from_type = *r_type;
1305 unsigned int to_type = from_type;
1306 bfd_boolean check = TRUE;
1307
bb1cb422
L
1308 /* Skip TLS transition for functions. */
1309 if (h != NULL
1310 && (h->type == STT_FUNC
1311 || h->type == STT_GNU_IFUNC))
1312 return TRUE;
1313
142411ca 1314 switch (from_type)
13ae64f3
JJ
1315 {
1316 case R_386_TLS_GD:
67a4f2b7
AO
1317 case R_386_TLS_GOTDESC:
1318 case R_386_TLS_DESC_CALL:
13ae64f3 1319 case R_386_TLS_IE_32:
37e55690
JJ
1320 case R_386_TLS_IE:
1321 case R_386_TLS_GOTIE:
1d85728f 1322 if (info->executable)
142411ca
L
1323 {
1324 if (h == NULL)
1325 to_type = R_386_TLS_LE_32;
1326 else if (from_type != R_386_TLS_IE
1327 && from_type != R_386_TLS_GOTIE)
1328 to_type = R_386_TLS_IE_32;
1329 }
1330
1331 /* When we are called from elf_i386_relocate_section, CONTENTS
1332 isn't NULL and there may be additional transitions based on
1333 TLS_TYPE. */
1334 if (contents != NULL)
1335 {
1336 unsigned int new_to_type = to_type;
1337
1d85728f 1338 if (info->executable
142411ca
L
1339 && h != NULL
1340 && h->dynindx == -1
1341 && (tls_type & GOT_TLS_IE))
1342 new_to_type = R_386_TLS_LE_32;
1343
1344 if (to_type == R_386_TLS_GD
1345 || to_type == R_386_TLS_GOTDESC
1346 || to_type == R_386_TLS_DESC_CALL)
1347 {
1348 if (tls_type == GOT_TLS_IE_POS)
1349 new_to_type = R_386_TLS_GOTIE;
1350 else if (tls_type & GOT_TLS_IE)
1351 new_to_type = R_386_TLS_IE_32;
1352 }
1353
1354 /* We checked the transition before when we were called from
1355 elf_i386_check_relocs. We only want to check the new
1356 transition which hasn't been checked before. */
1357 check = new_to_type != to_type && from_type == to_type;
1358 to_type = new_to_type;
1359 }
1360
1361 break;
1362
13ae64f3 1363 case R_386_TLS_LDM:
1d85728f 1364 if (info->executable)
142411ca
L
1365 to_type = R_386_TLS_LE_32;
1366 break;
1367
1368 default:
1369 return TRUE;
1370 }
1371
1372 /* Return TRUE if there is no transition. */
1373 if (from_type == to_type)
1374 return TRUE;
1375
1376 /* Check if the transition can be performed. */
1377 if (check
1378 && ! elf_i386_check_tls_transition (abfd, sec, contents,
1379 symtab_hdr, sym_hashes,
1380 from_type, rel, relend))
1381 {
2f629d23 1382 reloc_howto_type *from, *to;
4c544807 1383 const char *name;
142411ca
L
1384
1385 from = elf_i386_rtype_to_howto (abfd, from_type);
1386 to = elf_i386_rtype_to_howto (abfd, to_type);
1387
4c544807
L
1388 if (h)
1389 name = h->root.root.string;
1390 else
1391 {
4c544807 1392 struct elf_i386_link_hash_table *htab;
4dfe6ac6 1393
4c544807 1394 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
1395 if (htab == NULL)
1396 name = "*unknown*";
1397 else
1398 {
1399 Elf_Internal_Sym *isym;
1400
1401 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1402 abfd, r_symndx);
1403 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1404 }
4c544807
L
1405 }
1406
142411ca
L
1407 (*_bfd_error_handler)
1408 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1409 "in section `%A' failed"),
4c544807 1410 abfd, sec, from->name, to->name, name,
142411ca
L
1411 (unsigned long) rel->r_offset);
1412 bfd_set_error (bfd_error_bad_value);
1413 return FALSE;
13ae64f3
JJ
1414 }
1415
142411ca
L
1416 *r_type = to_type;
1417 return TRUE;
13ae64f3
JJ
1418}
1419
252b5132 1420/* Look through the relocs for a section during the first phase, and
0ac8d2ca
AM
1421 calculate needed space in the global offset table, procedure linkage
1422 table, and dynamic reloc sections. */
252b5132 1423
b34976b6 1424static bfd_boolean
55fd94b0
AM
1425elf_i386_check_relocs (bfd *abfd,
1426 struct bfd_link_info *info,
1427 asection *sec,
1428 const Elf_Internal_Rela *relocs)
252b5132 1429{
6725bdbf 1430 struct elf_i386_link_hash_table *htab;
252b5132
RH
1431 Elf_Internal_Shdr *symtab_hdr;
1432 struct elf_link_hash_entry **sym_hashes;
252b5132
RH
1433 const Elf_Internal_Rela *rel;
1434 const Elf_Internal_Rela *rel_end;
252b5132
RH
1435 asection *sreloc;
1436
1049f94e 1437 if (info->relocatable)
b34976b6 1438 return TRUE;
252b5132 1439
0ffa91dd
NC
1440 BFD_ASSERT (is_i386_elf (abfd));
1441
6725bdbf 1442 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
1443 if (htab == NULL)
1444 return FALSE;
1445
0ffa91dd 1446 symtab_hdr = &elf_symtab_hdr (abfd);
252b5132 1447 sym_hashes = elf_sym_hashes (abfd);
252b5132 1448
252b5132
RH
1449 sreloc = NULL;
1450
1451 rel_end = relocs + sec->reloc_count;
1452 for (rel = relocs; rel < rel_end; rel++)
1453 {
13ae64f3 1454 unsigned int r_type;
252b5132
RH
1455 unsigned long r_symndx;
1456 struct elf_link_hash_entry *h;
4c544807
L
1457 Elf_Internal_Sym *isym;
1458 const char *name;
252b5132
RH
1459
1460 r_symndx = ELF32_R_SYM (rel->r_info);
13ae64f3 1461 r_type = ELF32_R_TYPE (rel->r_info);
252b5132 1462
d9bc7a44 1463 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
f5f31454 1464 {
d003868e
AM
1465 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1466 abfd,
8f615d07 1467 r_symndx);
b34976b6 1468 return FALSE;
f5f31454
L
1469 }
1470
252b5132 1471 if (r_symndx < symtab_hdr->sh_info)
c25bc9fc
L
1472 {
1473 /* A local symbol. */
c2e61a4e
L
1474 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1475 abfd, r_symndx);
1476 if (isym == NULL)
1477 return FALSE;
c25bc9fc
L
1478
1479 /* Check relocation against local STT_GNU_IFUNC symbol. */
c25bc9fc
L
1480 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1481 {
9fff0c39 1482 h = elf_i386_get_local_sym_hash (htab, abfd, rel, TRUE);
c25bc9fc 1483 if (h == NULL)
c2e61a4e 1484 return FALSE;
6bbec505 1485
c25bc9fc
L
1486 /* Fake a STT_GNU_IFUNC symbol. */
1487 h->type = STT_GNU_IFUNC;
1488 h->def_regular = 1;
1489 h->ref_regular = 1;
1490 h->forced_local = 1;
1491 h->root.type = bfd_link_hash_defined;
1492 }
1493 else
1494 h = NULL;
1495 }
252b5132 1496 else
71cb9464 1497 {
4c544807 1498 isym = NULL;
71cb9464
L
1499 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1500 while (h->root.type == bfd_link_hash_indirect
1501 || h->root.type == bfd_link_hash_warning)
1502 h = (struct elf_link_hash_entry *) h->root.u.i.link;
c25bc9fc 1503 }
cbe950e9 1504
c25bc9fc
L
1505 if (h != NULL)
1506 {
cbe950e9
L
1507 /* Create the ifunc sections for static executables. If we
1508 never see an indirect function symbol nor we are building
1509 a static executable, those sections will be empty and
1510 won't appear in output. */
1511 switch (r_type)
1512 {
1513 default:
1514 break;
1515
1516 case R_386_32:
1517 case R_386_PC32:
1518 case R_386_PLT32:
1519 case R_386_GOT32:
1520 case R_386_GOTOFF:
9d4057ee
AM
1521 if (htab->elf.dynobj == NULL)
1522 htab->elf.dynobj = abfd;
1523 if (!_bfd_elf_create_ifunc_sections (htab->elf.dynobj, info))
c2e61a4e 1524 return FALSE;
cbe950e9
L
1525 break;
1526 }
1527
1528 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1529 it here if it is defined in a non-shared object. */
1530 if (h->type == STT_GNU_IFUNC
1531 && h->def_regular)
1532 {
1533 /* It is referenced by a non-shared object. */
1534 h->ref_regular = 1;
7ae26bc1 1535 h->needs_plt = 1;
6bbec505 1536
cbe950e9
L
1537 /* STT_GNU_IFUNC symbol must go through PLT. */
1538 h->plt.refcount += 1;
1539
1540 /* STT_GNU_IFUNC needs dynamic sections. */
1541 if (htab->elf.dynobj == NULL)
1542 htab->elf.dynobj = abfd;
1543
1544 switch (r_type)
1545 {
048cbda4 1546 default:
4c544807
L
1547 if (h->root.root.string)
1548 name = h->root.root.string;
1549 else
1550 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1551 NULL);
048cbda4
L
1552 (*_bfd_error_handler)
1553 (_("%B: relocation %s against STT_GNU_IFUNC "
1554 "symbol `%s' isn't handled by %s"), abfd,
1555 elf_howto_table[r_type].name,
4c544807 1556 name, __FUNCTION__);
048cbda4 1557 bfd_set_error (bfd_error_bad_value);
c2e61a4e 1558 return FALSE;
cbe950e9
L
1559
1560 case R_386_32:
710ab287
L
1561 h->non_got_ref = 1;
1562 h->pointer_equality_needed = 1;
1563 if (info->shared)
1564 {
710ab287
L
1565 /* We must copy these reloc types into the
1566 output file. Create a reloc section in
1567 dynobj and make room for this reloc. */
e03a8ed8
L
1568 sreloc = _bfd_elf_create_ifunc_dyn_reloc
1569 (abfd, info, sec, sreloc,
1570 &((struct elf_i386_link_hash_entry *) h)->dyn_relocs);
710ab287 1571 if (sreloc == NULL)
c2e61a4e 1572 return FALSE;
710ab287
L
1573 }
1574 break;
1575
cbe950e9
L
1576 case R_386_PC32:
1577 h->non_got_ref = 1;
cbe950e9
L
1578 break;
1579
1580 case R_386_PLT32:
1581 break;
1582
1583 case R_386_GOT32:
1584 case R_386_GOTOFF:
7afd84dc 1585 h->got.refcount += 1;
6de2ae4a
L
1586 if (htab->elf.sgot == NULL
1587 && !_bfd_elf_create_got_section (htab->elf.dynobj,
cbe950e9 1588 info))
c2e61a4e 1589 return FALSE;
cbe950e9
L
1590 break;
1591 }
1592
1593 continue;
1594 }
71cb9464 1595 }
252b5132 1596
142411ca
L
1597 if (! elf_i386_tls_transition (info, abfd, sec, NULL,
1598 symtab_hdr, sym_hashes,
1599 &r_type, GOT_UNKNOWN,
23209a78 1600 rel, rel_end, h, r_symndx))
c2e61a4e 1601 return FALSE;
13ae64f3
JJ
1602
1603 switch (r_type)
252b5132 1604 {
37e55690
JJ
1605 case R_386_TLS_LDM:
1606 htab->tls_ldm_got.refcount += 1;
1607 goto create_got;
1608
1609 case R_386_PLT32:
1610 /* This symbol requires a procedure linkage table entry. We
1611 actually build the entry in adjust_dynamic_symbol,
1612 because this might be a case of linking PIC code which is
1613 never referenced by a dynamic object, in which case we
1614 don't need to generate a procedure linkage table entry
1615 after all. */
1616
1617 /* If this is a local symbol, we resolve it directly without
1618 creating a procedure linkage table entry. */
1619 if (h == NULL)
1620 continue;
1621
f5385ebf 1622 h->needs_plt = 1;
37e55690
JJ
1623 h->plt.refcount += 1;
1624 break;
1625
13ae64f3 1626 case R_386_TLS_IE_32:
37e55690
JJ
1627 case R_386_TLS_IE:
1628 case R_386_TLS_GOTIE:
1d85728f 1629 if (!info->executable)
13ae64f3 1630 info->flags |= DF_STATIC_TLS;
37e55690
JJ
1631 /* Fall through */
1632
252b5132 1633 case R_386_GOT32:
13ae64f3 1634 case R_386_TLS_GD:
67a4f2b7
AO
1635 case R_386_TLS_GOTDESC:
1636 case R_386_TLS_DESC_CALL:
252b5132 1637 /* This symbol requires a global offset table entry. */
13ae64f3
JJ
1638 {
1639 int tls_type, old_tls_type;
1640
1641 switch (r_type)
1642 {
1643 default:
1644 case R_386_GOT32: tls_type = GOT_NORMAL; break;
1645 case R_386_TLS_GD: tls_type = GOT_TLS_GD; break;
67a4f2b7
AO
1646 case R_386_TLS_GOTDESC:
1647 case R_386_TLS_DESC_CALL:
1648 tls_type = GOT_TLS_GDESC; break;
37e55690
JJ
1649 case R_386_TLS_IE_32:
1650 if (ELF32_R_TYPE (rel->r_info) == r_type)
1651 tls_type = GOT_TLS_IE_NEG;
1652 else
ebcfb3c0
JJ
1653 /* If this is a GD->IE transition, we may use either of
1654 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
37e55690
JJ
1655 tls_type = GOT_TLS_IE;
1656 break;
1657 case R_386_TLS_IE:
1658 case R_386_TLS_GOTIE:
1659 tls_type = GOT_TLS_IE_POS; break;
13ae64f3
JJ
1660 }
1661
1662 if (h != NULL)
1663 {
1664 h->got.refcount += 1;
1665 old_tls_type = elf_i386_hash_entry(h)->tls_type;
1666 }
1667 else
1668 {
1669 bfd_signed_vma *local_got_refcounts;
1670
1671 /* This is a global offset table entry for a local symbol. */
1672 local_got_refcounts = elf_local_got_refcounts (abfd);
1673 if (local_got_refcounts == NULL)
1674 {
1675 bfd_size_type size;
1676
1677 size = symtab_hdr->sh_info;
67a4f2b7
AO
1678 size *= (sizeof (bfd_signed_vma)
1679 + sizeof (bfd_vma) + sizeof(char));
a50b1753
NC
1680 local_got_refcounts = (bfd_signed_vma *)
1681 bfd_zalloc (abfd, size);
13ae64f3 1682 if (local_got_refcounts == NULL)
c2e61a4e 1683 return FALSE;
13ae64f3 1684 elf_local_got_refcounts (abfd) = local_got_refcounts;
67a4f2b7
AO
1685 elf_i386_local_tlsdesc_gotent (abfd)
1686 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
13ae64f3 1687 elf_i386_local_got_tls_type (abfd)
67a4f2b7 1688 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
13ae64f3
JJ
1689 }
1690 local_got_refcounts[r_symndx] += 1;
1691 old_tls_type = elf_i386_local_got_tls_type (abfd) [r_symndx];
1692 }
1693
37e55690
JJ
1694 if ((old_tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_IE))
1695 tls_type |= old_tls_type;
13ae64f3
JJ
1696 /* If a TLS symbol is accessed using IE at least once,
1697 there is no point to use dynamic model for it. */
ebcfb3c0 1698 else if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
67a4f2b7 1699 && (! GOT_TLS_GD_ANY_P (old_tls_type)
37e55690 1700 || (tls_type & GOT_TLS_IE) == 0))
13ae64f3 1701 {
67a4f2b7 1702 if ((old_tls_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (tls_type))
37e55690 1703 tls_type = old_tls_type;
67a4f2b7
AO
1704 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1705 && GOT_TLS_GD_ANY_P (tls_type))
1706 tls_type |= old_tls_type;
13ae64f3
JJ
1707 else
1708 {
09a24cbf 1709 if (h)
4c544807
L
1710 name = h->root.root.string;
1711 else
1712 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1713 NULL);
13ae64f3 1714 (*_bfd_error_handler)
d003868e 1715 (_("%B: `%s' accessed both as normal and "
55fd94b0 1716 "thread local symbol"),
4c544807 1717 abfd, name);
c2e61a4e 1718 return FALSE;
13ae64f3
JJ
1719 }
1720 }
1721
1722 if (old_tls_type != tls_type)
1723 {
1724 if (h != NULL)
1725 elf_i386_hash_entry (h)->tls_type = tls_type;
1726 else
1727 elf_i386_local_got_tls_type (abfd) [r_symndx] = tls_type;
1728 }
1729 }
0ac8d2ca
AM
1730 /* Fall through */
1731
1732 case R_386_GOTOFF:
1733 case R_386_GOTPC:
13ae64f3 1734 create_got:
6de2ae4a 1735 if (htab->elf.sgot == NULL)
0ac8d2ca
AM
1736 {
1737 if (htab->elf.dynobj == NULL)
1738 htab->elf.dynobj = abfd;
6de2ae4a 1739 if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
c2e61a4e 1740 return FALSE;
0ac8d2ca 1741 }
37e55690
JJ
1742 if (r_type != R_386_TLS_IE)
1743 break;
1744 /* Fall through */
252b5132 1745
37e55690
JJ
1746 case R_386_TLS_LE_32:
1747 case R_386_TLS_LE:
1d85728f 1748 if (info->executable)
37e55690 1749 break;
bffbf940 1750 info->flags |= DF_STATIC_TLS;
b34976b6 1751 /* Fall through */
252b5132
RH
1752
1753 case R_386_32:
1754 case R_386_PC32:
710ab287 1755 if (h != NULL && info->executable)
6725bdbf 1756 {
12d0ee4a 1757 /* If this reloc is in a read-only section, we might
ebe50bae
AM
1758 need a copy reloc. We can't check reliably at this
1759 stage whether the section is read-only, as input
1760 sections have not yet been mapped to output sections.
1761 Tentatively set the flag for now, and correct in
1762 adjust_dynamic_symbol. */
f5385ebf 1763 h->non_got_ref = 1;
12d0ee4a
AM
1764
1765 /* We may need a .plt entry if the function this reloc
1766 refers to is in a shared lib. */
51b64d56 1767 h->plt.refcount += 1;
c6585bbb 1768 if (r_type != R_386_PC32)
f5385ebf 1769 h->pointer_equality_needed = 1;
6725bdbf 1770 }
7843f00e 1771
252b5132 1772 /* If we are creating a shared library, and this is a reloc
f69da49f
AM
1773 against a global symbol, or a non PC relative reloc
1774 against a local symbol, then we need to copy the reloc
1775 into the shared library. However, if we are linking with
1776 -Bsymbolic, we do not need to copy a reloc against a
1777 global symbol which is defined in an object we are
1778 including in the link (i.e., DEF_REGULAR is set). At
1779 this point we have not seen all the input files, so it is
1780 possible that DEF_REGULAR is not set now but will be set
1f655a09
L
1781 later (it is never cleared). In case of a weak definition,
1782 DEF_REGULAR may be cleared later by a strong definition in
ebe50bae 1783 a shared library. We account for that possibility below by
1f655a09
L
1784 storing information in the relocs_copied field of the hash
1785 table entry. A similar situation occurs when creating
1786 shared libraries and symbol visibility changes render the
12d0ee4a 1787 symbol local.
56882138 1788
12d0ee4a
AM
1789 If on the other hand, we are creating an executable, we
1790 may need to keep relocations for symbols satisfied by a
1791 dynamic library if we manage to avoid copy relocs for the
1792 symbol. */
1793 if ((info->shared
1794 && (sec->flags & SEC_ALLOC) != 0
13ae64f3 1795 && (r_type != R_386_PC32
12d0ee4a 1796 || (h != NULL
55255dae 1797 && (! SYMBOLIC_BIND (info, h)
12d0ee4a 1798 || h->root.type == bfd_link_hash_defweak
f5385ebf 1799 || !h->def_regular))))
a23b6845
AM
1800 || (ELIMINATE_COPY_RELOCS
1801 && !info->shared
12d0ee4a
AM
1802 && (sec->flags & SEC_ALLOC) != 0
1803 && h != NULL
12d0ee4a 1804 && (h->root.type == bfd_link_hash_defweak
0f88be7a 1805 || !h->def_regular)))
252b5132 1806 {
e03a8ed8
L
1807 struct elf_dyn_relocs *p;
1808 struct elf_dyn_relocs **head;
ec338859 1809
12d0ee4a
AM
1810 /* We must copy these reloc types into the output file.
1811 Create a reloc section in dynobj and make room for
1812 this reloc. */
252b5132
RH
1813 if (sreloc == NULL)
1814 {
0ac8d2ca
AM
1815 if (htab->elf.dynobj == NULL)
1816 htab->elf.dynobj = abfd;
1817
83bac4b0
NC
1818 sreloc = _bfd_elf_make_dynamic_reloc_section
1819 (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ FALSE);
1820
252b5132 1821 if (sreloc == NULL)
c2e61a4e 1822 return FALSE;
252b5132
RH
1823 }
1824
0c715baa
AM
1825 /* If this is a global symbol, we count the number of
1826 relocations we need for this symbol. */
1827 if (h != NULL)
252b5132 1828 {
ec338859 1829 head = &((struct elf_i386_link_hash_entry *) h)->dyn_relocs;
0c715baa
AM
1830 }
1831 else
1832 {
ec338859
AM
1833 /* Track dynamic relocs needed for local syms too.
1834 We really need local syms available to do this
1835 easily. Oh well. */
87d72d41 1836 void **vpp;
ec338859 1837 asection *s;
87d72d41
AM
1838
1839 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1840 abfd, r_symndx);
1841 if (isym == NULL)
1842 return FALSE;
1843
1844 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
ec338859 1845 if (s == NULL)
87d72d41 1846 s = sec;
ec338859 1847
e81d3500 1848 vpp = &elf_section_data (s)->local_dynrel;
e03a8ed8 1849 head = (struct elf_dyn_relocs **)vpp;
ec338859
AM
1850 }
1851
1852 p = *head;
1853 if (p == NULL || p->sec != sec)
1854 {
1855 bfd_size_type amt = sizeof *p;
a50b1753
NC
1856 p = (struct elf_dyn_relocs *) bfd_alloc (htab->elf.dynobj,
1857 amt);
ec338859 1858 if (p == NULL)
c2e61a4e 1859 return FALSE;
ec338859
AM
1860 p->next = *head;
1861 *head = p;
1862 p->sec = sec;
1863 p->count = 0;
1864 p->pc_count = 0;
252b5132 1865 }
ec338859
AM
1866
1867 p->count += 1;
13ae64f3 1868 if (r_type == R_386_PC32)
ec338859 1869 p->pc_count += 1;
252b5132 1870 }
252b5132
RH
1871 break;
1872
1873 /* This relocation describes the C++ object vtable hierarchy.
1874 Reconstruct it for later use during GC. */
1875 case R_386_GNU_VTINHERIT:
d17e0c6e 1876 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
c2e61a4e 1877 return FALSE;
252b5132
RH
1878 break;
1879
1880 /* This relocation describes which C++ vtable entries are actually
1881 used. Record for later use during GC. */
1882 case R_386_GNU_VTENTRY:
c6aa130f
MS
1883 BFD_ASSERT (h != NULL);
1884 if (h != NULL
1885 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
c2e61a4e 1886 return FALSE;
252b5132
RH
1887 break;
1888
1889 default:
1890 break;
1891 }
1892 }
1893
b34976b6 1894 return TRUE;
252b5132
RH
1895}
1896
1897/* Return the section that should be marked against GC for a given
1898 relocation. */
1899
1900static asection *
55fd94b0 1901elf_i386_gc_mark_hook (asection *sec,
07adf181 1902 struct bfd_link_info *info,
55fd94b0
AM
1903 Elf_Internal_Rela *rel,
1904 struct elf_link_hash_entry *h,
1905 Elf_Internal_Sym *sym)
252b5132
RH
1906{
1907 if (h != NULL)
07adf181
AM
1908 switch (ELF32_R_TYPE (rel->r_info))
1909 {
1910 case R_386_GNU_VTINHERIT:
1911 case R_386_GNU_VTENTRY:
1912 return NULL;
1913 }
1914
1915 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
252b5132
RH
1916}
1917
1918/* Update the got entry reference counts for the section being removed. */
1919
b34976b6 1920static bfd_boolean
55fd94b0
AM
1921elf_i386_gc_sweep_hook (bfd *abfd,
1922 struct bfd_link_info *info,
1923 asection *sec,
1924 const Elf_Internal_Rela *relocs)
252b5132 1925{
4dfe6ac6 1926 struct elf_i386_link_hash_table *htab;
dd5724d5
AM
1927 Elf_Internal_Shdr *symtab_hdr;
1928 struct elf_link_hash_entry **sym_hashes;
1929 bfd_signed_vma *local_got_refcounts;
1930 const Elf_Internal_Rela *rel, *relend;
dd5724d5 1931
7dda2462
TG
1932 if (info->relocatable)
1933 return TRUE;
1934
4dfe6ac6
NC
1935 htab = elf_i386_hash_table (info);
1936 if (htab == NULL)
1937 return FALSE;
1938
ec338859 1939 elf_section_data (sec)->local_dynrel = NULL;
dd5724d5 1940
0ffa91dd 1941 symtab_hdr = &elf_symtab_hdr (abfd);
6725bdbf
AM
1942 sym_hashes = elf_sym_hashes (abfd);
1943 local_got_refcounts = elf_local_got_refcounts (abfd);
dd5724d5
AM
1944
1945 relend = relocs + sec->reloc_count;
1946 for (rel = relocs; rel < relend; rel++)
26e41594
AM
1947 {
1948 unsigned long r_symndx;
1949 unsigned int r_type;
1950 struct elf_link_hash_entry *h = NULL;
37e55690 1951
26e41594
AM
1952 r_symndx = ELF32_R_SYM (rel->r_info);
1953 if (r_symndx >= symtab_hdr->sh_info)
1954 {
26e41594 1955 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3eb128b2
AM
1956 while (h->root.type == bfd_link_hash_indirect
1957 || h->root.type == bfd_link_hash_warning)
1958 h = (struct elf_link_hash_entry *) h->root.u.i.link;
26e41594 1959 }
bb1cb422
L
1960 else
1961 {
1962 /* A local symbol. */
1963 Elf_Internal_Sym *isym;
1964
1965 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1966 abfd, r_symndx);
1967
1968 /* Check relocation against local STT_GNU_IFUNC symbol. */
1969 if (isym != NULL
1970 && ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1971 {
1972 h = elf_i386_get_local_sym_hash (htab, abfd, rel, FALSE);
1973 if (h == NULL)
1974 abort ();
1975 }
1976 }
0c715baa 1977
3db2e7dd
L
1978 if (h)
1979 {
1980 struct elf_i386_link_hash_entry *eh;
1981 struct elf_dyn_relocs **pp;
1982 struct elf_dyn_relocs *p;
1983
1984 eh = (struct elf_i386_link_hash_entry *) h;
1985 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1986 if (p->sec == sec)
1987 {
1988 /* Everything must go for SEC. */
1989 *pp = p->next;
1990 break;
1991 }
1992 }
1993
26e41594 1994 r_type = ELF32_R_TYPE (rel->r_info);
142411ca
L
1995 if (! elf_i386_tls_transition (info, abfd, sec, NULL,
1996 symtab_hdr, sym_hashes,
1997 &r_type, GOT_UNKNOWN,
23209a78 1998 rel, relend, h, r_symndx))
142411ca
L
1999 return FALSE;
2000
26e41594
AM
2001 switch (r_type)
2002 {
2003 case R_386_TLS_LDM:
4dfe6ac6
NC
2004 if (htab->tls_ldm_got.refcount > 0)
2005 htab->tls_ldm_got.refcount -= 1;
26e41594 2006 break;
0c715baa 2007
26e41594 2008 case R_386_TLS_GD:
67a4f2b7
AO
2009 case R_386_TLS_GOTDESC:
2010 case R_386_TLS_DESC_CALL:
26e41594
AM
2011 case R_386_TLS_IE_32:
2012 case R_386_TLS_IE:
2013 case R_386_TLS_GOTIE:
2014 case R_386_GOT32:
2015 if (h != NULL)
2016 {
2017 if (h->got.refcount > 0)
2018 h->got.refcount -= 1;
bb1cb422
L
2019 if (h->type == STT_GNU_IFUNC)
2020 {
2021 if (h->plt.refcount > 0)
2022 h->plt.refcount -= 1;
2023 }
26e41594
AM
2024 }
2025 else if (local_got_refcounts != NULL)
2026 {
2027 if (local_got_refcounts[r_symndx] > 0)
2028 local_got_refcounts[r_symndx] -= 1;
2029 }
2030 break;
0c715baa 2031
26e41594
AM
2032 case R_386_32:
2033 case R_386_PC32:
3db2e7dd
L
2034 if (info->shared
2035 && (h == NULL || h->type != STT_GNU_IFUNC))
26e41594
AM
2036 break;
2037 /* Fall through */
6725bdbf 2038
26e41594
AM
2039 case R_386_PLT32:
2040 if (h != NULL)
2041 {
2042 if (h->plt.refcount > 0)
2043 h->plt.refcount -= 1;
2044 }
2045 break;
dd5724d5 2046
bb1cb422
L
2047 case R_386_GOTOFF:
2048 if (h != NULL && h->type == STT_GNU_IFUNC)
2049 {
2050 if (h->got.refcount > 0)
2051 h->got.refcount -= 1;
2052 if (h->plt.refcount > 0)
2053 h->plt.refcount -= 1;
2054 }
2055 break;
2056
26e41594
AM
2057 default:
2058 break;
2059 }
2060 }
252b5132 2061
b34976b6 2062 return TRUE;
252b5132
RH
2063}
2064
2065/* Adjust a symbol defined by a dynamic object and referenced by a
2066 regular object. The current definition is in some section of the
2067 dynamic object, but we're not including those sections. We have to
2068 change the definition to something the rest of the link can
2069 understand. */
2070
b34976b6 2071static bfd_boolean
55fd94b0
AM
2072elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
2073 struct elf_link_hash_entry *h)
252b5132 2074{
6725bdbf 2075 struct elf_i386_link_hash_table *htab;
252b5132 2076 asection *s;
252b5132 2077
cbe950e9
L
2078 /* STT_GNU_IFUNC symbol must go through PLT. */
2079 if (h->type == STT_GNU_IFUNC)
2080 {
2081 if (h->plt.refcount <= 0)
2082 {
2083 h->plt.offset = (bfd_vma) -1;
2084 h->needs_plt = 0;
2085 }
2086 return TRUE;
2087 }
2088
252b5132
RH
2089 /* If this is a function, put it in the procedure linkage table. We
2090 will fill in the contents of the procedure linkage table later,
2091 when we know the address of the .got section. */
2092 if (h->type == STT_FUNC
f5385ebf 2093 || h->needs_plt)
252b5132 2094 {
6725bdbf 2095 if (h->plt.refcount <= 0
9c7a29a3
AM
2096 || SYMBOL_CALLS_LOCAL (info, h)
2097 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2098 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
2099 {
2100 /* This case can occur if we saw a PLT32 reloc in an input
dd5724d5
AM
2101 file, but the symbol was never referred to by a dynamic
2102 object, or if all references were garbage collected. In
2103 such a case, we don't actually need to build a procedure
2104 linkage table, and we can just do a PC32 reloc instead. */
bbd7ec4a 2105 h->plt.offset = (bfd_vma) -1;
f5385ebf 2106 h->needs_plt = 0;
252b5132
RH
2107 }
2108
b34976b6 2109 return TRUE;
252b5132 2110 }
6725bdbf
AM
2111 else
2112 /* It's possible that we incorrectly decided a .plt reloc was
2113 needed for an R_386_PC32 reloc to a non-function sym in
2114 check_relocs. We can't decide accurately between function and
2115 non-function syms in check-relocs; Objects loaded later in
2116 the link may change h->type. So fix it now. */
bbd7ec4a 2117 h->plt.offset = (bfd_vma) -1;
252b5132
RH
2118
2119 /* If this is a weak symbol, and there is a real definition, the
2120 processor independent code will have arranged for us to see the
2121 real definition first, and we can just use the same value. */
f6e332e6 2122 if (h->u.weakdef != NULL)
252b5132 2123 {
f6e332e6
AM
2124 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2125 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2126 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2127 h->root.u.def.value = h->u.weakdef->root.u.def.value;
a23b6845 2128 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
f6e332e6 2129 h->non_got_ref = h->u.weakdef->non_got_ref;
b34976b6 2130 return TRUE;
252b5132
RH
2131 }
2132
2133 /* This is a reference to a symbol defined by a dynamic object which
2134 is not a function. */
2135
2136 /* If we are creating a shared library, we must presume that the
2137 only references to the symbol are via the global offset table.
2138 For such cases we need not do anything here; the relocations will
2139 be handled correctly by relocate_section. */
2140 if (info->shared)
b34976b6 2141 return TRUE;
252b5132 2142
7843f00e
ILT
2143 /* If there are no references to this symbol that do not use the
2144 GOT, we don't need to generate a copy reloc. */
f5385ebf 2145 if (!h->non_got_ref)
b34976b6 2146 return TRUE;
7843f00e 2147
8bd621d8
AM
2148 /* If -z nocopyreloc was given, we won't generate them either. */
2149 if (info->nocopyreloc)
2150 {
f5385ebf 2151 h->non_got_ref = 0;
b34976b6 2152 return TRUE;
8bd621d8
AM
2153 }
2154
643796e3 2155 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
2156 if (htab == NULL)
2157 return FALSE;
643796e3
DJ
2158
2159 /* If there aren't any dynamic relocs in read-only sections, then
2160 we can keep the dynamic relocs and avoid the copy reloc. This
2161 doesn't work on VxWorks, where we can not have dynamic relocations
2162 (other than copy and jump slot relocations) in an executable. */
23209a78
RM
2163 if (ELIMINATE_COPY_RELOCS
2164 && !get_elf_i386_backend_data (info->output_bfd)->is_vxworks)
ebe50bae 2165 {
a23b6845 2166 struct elf_i386_link_hash_entry * eh;
e03a8ed8 2167 struct elf_dyn_relocs *p;
ebe50bae 2168
a23b6845
AM
2169 eh = (struct elf_i386_link_hash_entry *) h;
2170 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2171 {
2172 s = p->sec->output_section;
2173 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2174 break;
2175 }
2176
a23b6845
AM
2177 if (p == NULL)
2178 {
f5385ebf 2179 h->non_got_ref = 0;
a23b6845
AM
2180 return TRUE;
2181 }
ebe50bae
AM
2182 }
2183
252b5132
RH
2184 /* We must allocate the symbol in our .dynbss section, which will
2185 become part of the .bss section of the executable. There will be
2186 an entry for this symbol in the .dynsym section. The dynamic
2187 object will contain position independent code, so all references
2188 from the dynamic object to this symbol will go through the global
2189 offset table. The dynamic linker will use the .dynsym entry to
2190 determine the address it must put in the global offset table, so
2191 both the dynamic object and the regular object will refer to the
2192 same memory location for the variable. */
2193
252b5132
RH
2194 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
2195 copy the initial value out of the dynamic object and into the
0ac8d2ca 2196 runtime process image. */
1d7e9d18 2197 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
252b5132 2198 {
eea6121a 2199 htab->srelbss->size += sizeof (Elf32_External_Rel);
f5385ebf 2200 h->needs_copy = 1;
252b5132
RH
2201 }
2202
0ac8d2ca 2203 s = htab->sdynbss;
252b5132 2204
027297b7 2205 return _bfd_elf_adjust_dynamic_copy (h, s);
252b5132
RH
2206}
2207
6725bdbf 2208/* Allocate space in .plt, .got and associated reloc sections for
0c715baa 2209 dynamic relocs. */
6725bdbf 2210
b34976b6 2211static bfd_boolean
eb4ff4d6 2212elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
6725bdbf
AM
2213{
2214 struct bfd_link_info *info;
2215 struct elf_i386_link_hash_table *htab;
5a15f56f 2216 struct elf_i386_link_hash_entry *eh;
e03a8ed8 2217 struct elf_dyn_relocs *p;
25e762b9 2218 unsigned plt_entry_size;
6725bdbf 2219
e92d460e 2220 if (h->root.type == bfd_link_hash_indirect)
b34976b6 2221 return TRUE;
6725bdbf 2222
cbe950e9 2223 eh = (struct elf_i386_link_hash_entry *) h;
e92d460e 2224
6725bdbf
AM
2225 info = (struct bfd_link_info *) inf;
2226 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
2227 if (htab == NULL)
2228 return FALSE;
6725bdbf 2229
25e762b9
RM
2230 plt_entry_size = GET_PLT_ENTRY_SIZE (info->output_bfd);
2231
cbe950e9
L
2232 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2233 here if it is defined and referenced in a non-shared object. */
2234 if (h->type == STT_GNU_IFUNC
2235 && h->def_regular)
25e762b9
RM
2236 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h, &eh->dyn_relocs,
2237 plt_entry_size, 4);
cbe950e9
L
2238 else if (htab->elf.dynamic_sections_created
2239 && h->plt.refcount > 0)
6725bdbf 2240 {
5a15f56f
AM
2241 /* Make sure this symbol is output as a dynamic symbol.
2242 Undefined weak syms won't yet be marked as dynamic. */
2243 if (h->dynindx == -1
f5385ebf 2244 && !h->forced_local)
5a15f56f 2245 {
c152c796 2246 if (! bfd_elf_link_record_dynamic_symbol (info, h))
b34976b6 2247 return FALSE;
5a15f56f
AM
2248 }
2249
4e795f50
AM
2250 if (info->shared
2251 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
ced53ee5 2252 {
6de2ae4a 2253 asection *s = htab->elf.splt;
6725bdbf 2254
ced53ee5
AM
2255 /* If this is the first .plt entry, make room for the special
2256 first entry. */
eea6121a 2257 if (s->size == 0)
25e762b9 2258 s->size += plt_entry_size;
6725bdbf 2259
eea6121a 2260 h->plt.offset = s->size;
6725bdbf 2261
ced53ee5
AM
2262 /* If this symbol is not defined in a regular file, and we are
2263 not generating a shared library, then set the symbol to this
2264 location in the .plt. This is required to make function
2265 pointers compare as equal between the normal executable and
2266 the shared library. */
2267 if (! info->shared
f5385ebf 2268 && !h->def_regular)
ced53ee5
AM
2269 {
2270 h->root.u.def.section = s;
2271 h->root.u.def.value = h->plt.offset;
2272 }
6725bdbf 2273
ced53ee5 2274 /* Make room for this entry. */
25e762b9 2275 s->size += plt_entry_size;
6725bdbf 2276
ced53ee5
AM
2277 /* We also need to make an entry in the .got.plt section, which
2278 will be placed in the .got section by the linker script. */
6de2ae4a 2279 htab->elf.sgotplt->size += 4;
6725bdbf 2280
6725bdbf 2281 /* We also need to make an entry in the .rel.plt section. */
6de2ae4a 2282 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
e1f98742 2283 htab->elf.srelplt->reloc_count++;
eac338cf 2284
23209a78
RM
2285 if (get_elf_i386_backend_data (info->output_bfd)->is_vxworks
2286 && !info->shared)
eac338cf
PB
2287 {
2288 /* VxWorks has a second set of relocations for each PLT entry
2289 in executables. They go in a separate relocation section,
2290 which is processed by the kernel loader. */
2291
2292 /* There are two relocations for the initial PLT entry: an
2293 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
2294 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
2295
25e762b9 2296 if (h->plt.offset == plt_entry_size)
eac338cf
PB
2297 htab->srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
2298
2299 /* There are two extra relocations for each subsequent PLT entry:
2300 an R_386_32 relocation for the GOT entry, and an R_386_32
2301 relocation for the PLT entry. */
2302
2303 htab->srelplt2->size += (sizeof (Elf32_External_Rel) * 2);
2304 }
6725bdbf 2305 }
ced53ee5
AM
2306 else
2307 {
51b64d56 2308 h->plt.offset = (bfd_vma) -1;
f5385ebf 2309 h->needs_plt = 0;
ced53ee5 2310 }
6725bdbf
AM
2311 }
2312 else
2313 {
51b64d56 2314 h->plt.offset = (bfd_vma) -1;
f5385ebf 2315 h->needs_plt = 0;
6725bdbf
AM
2316 }
2317
67a4f2b7
AO
2318 eh->tlsdesc_got = (bfd_vma) -1;
2319
37e55690 2320 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
13ae64f3
JJ
2321 make it a R_386_TLS_LE_32 requiring no TLS entry. */
2322 if (h->got.refcount > 0
1d85728f 2323 && info->executable
13ae64f3 2324 && h->dynindx == -1
37e55690 2325 && (elf_i386_hash_entry(h)->tls_type & GOT_TLS_IE))
cedb70c5 2326 h->got.offset = (bfd_vma) -1;
13ae64f3 2327 else if (h->got.refcount > 0)
6725bdbf 2328 {
0ac8d2ca 2329 asection *s;
b34976b6 2330 bfd_boolean dyn;
13ae64f3 2331 int tls_type = elf_i386_hash_entry(h)->tls_type;
6725bdbf 2332
5a15f56f
AM
2333 /* Make sure this symbol is output as a dynamic symbol.
2334 Undefined weak syms won't yet be marked as dynamic. */
2335 if (h->dynindx == -1
f5385ebf 2336 && !h->forced_local)
5a15f56f 2337 {
c152c796 2338 if (! bfd_elf_link_record_dynamic_symbol (info, h))
b34976b6 2339 return FALSE;
5a15f56f
AM
2340 }
2341
6de2ae4a 2342 s = htab->elf.sgot;
67a4f2b7
AO
2343 if (GOT_TLS_GDESC_P (tls_type))
2344 {
6de2ae4a 2345 eh->tlsdesc_got = htab->elf.sgotplt->size
67a4f2b7 2346 - elf_i386_compute_jump_table_size (htab);
6de2ae4a 2347 htab->elf.sgotplt->size += 8;
67a4f2b7
AO
2348 h->got.offset = (bfd_vma) -2;
2349 }
2350 if (! GOT_TLS_GDESC_P (tls_type)
2351 || GOT_TLS_GD_P (tls_type))
2352 {
2353 h->got.offset = s->size;
2354 s->size += 4;
2355 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
2356 if (GOT_TLS_GD_P (tls_type) || tls_type == GOT_TLS_IE_BOTH)
2357 s->size += 4;
2358 }
ebe50bae 2359 dyn = htab->elf.dynamic_sections_created;
13ae64f3 2360 /* R_386_TLS_IE_32 needs one dynamic relocation,
37e55690
JJ
2361 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
2362 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
2363 need two), R_386_TLS_GD needs one if local symbol and two if
2364 global. */
2365 if (tls_type == GOT_TLS_IE_BOTH)
6de2ae4a 2366 htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel);
67a4f2b7 2367 else if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
37e55690 2368 || (tls_type & GOT_TLS_IE))
6de2ae4a 2369 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
67a4f2b7 2370 else if (GOT_TLS_GD_P (tls_type))
6de2ae4a 2371 htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel);
67a4f2b7
AO
2372 else if (! GOT_TLS_GDESC_P (tls_type)
2373 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2374 || h->root.type != bfd_link_hash_undefweak)
ef5aade5
L
2375 && (info->shared
2376 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
6de2ae4a 2377 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
67a4f2b7 2378 if (GOT_TLS_GDESC_P (tls_type))
6de2ae4a 2379 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
6725bdbf
AM
2380 }
2381 else
51b64d56 2382 h->got.offset = (bfd_vma) -1;
6725bdbf 2383
5a15f56f 2384 if (eh->dyn_relocs == NULL)
b34976b6 2385 return TRUE;
5a15f56f 2386
0c715baa
AM
2387 /* In the shared -Bsymbolic case, discard space allocated for
2388 dynamic pc-relative relocs against symbols which turn out to be
2389 defined in regular objects. For the normal shared case, discard
0ac8d2ca
AM
2390 space for pc-relative relocs that have become local due to symbol
2391 visibility changes. */
0c715baa
AM
2392
2393 if (info->shared)
5a15f56f 2394 {
09695f56
AM
2395 /* The only reloc that uses pc_count is R_386_PC32, which will
2396 appear on a call or on something like ".long foo - .". We
2397 want calls to protected symbols to resolve directly to the
2398 function rather than going via the plt. If people want
2399 function pointer comparisons to work as expected then they
2400 should avoid writing assembly like ".long foo - .". */
2401 if (SYMBOL_CALLS_LOCAL (info, h))
5a15f56f 2402 {
e03a8ed8 2403 struct elf_dyn_relocs **pp;
0c715baa
AM
2404
2405 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2406 {
2407 p->count -= p->pc_count;
2408 p->pc_count = 0;
2409 if (p->count == 0)
2410 *pp = p->next;
2411 else
2412 pp = &p->next;
2413 }
5a15f56f 2414 }
4e795f50 2415
23209a78 2416 if (get_elf_i386_backend_data (info->output_bfd)->is_vxworks)
3348747a 2417 {
e03a8ed8 2418 struct elf_dyn_relocs **pp;
3348747a
NS
2419 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2420 {
2421 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
2422 *pp = p->next;
2423 else
2424 pp = &p->next;
2425 }
2426 }
2427
4e795f50 2428 /* Also discard relocs on undefined weak syms with non-default
3348747a 2429 visibility. */
22d606e9 2430 if (eh->dyn_relocs != NULL
4e795f50 2431 && h->root.type == bfd_link_hash_undefweak)
22d606e9
AM
2432 {
2433 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2434 eh->dyn_relocs = NULL;
2435
2436 /* Make sure undefined weak symbols are output as a dynamic
2437 symbol in PIEs. */
2438 else if (h->dynindx == -1
2439 && !h->forced_local)
2440 {
2441 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2442 return FALSE;
2443 }
2444 }
0c715baa 2445 }
a23b6845 2446 else if (ELIMINATE_COPY_RELOCS)
0c715baa
AM
2447 {
2448 /* For the non-shared case, discard space for relocs against
2449 symbols which turn out to need copy relocs or are not
2450 dynamic. */
2451
f5385ebf
AM
2452 if (!h->non_got_ref
2453 && ((h->def_dynamic
2454 && !h->def_regular)
ebe50bae 2455 || (htab->elf.dynamic_sections_created
0c715baa
AM
2456 && (h->root.type == bfd_link_hash_undefweak
2457 || h->root.type == bfd_link_hash_undefined))))
2458 {
2459 /* Make sure this symbol is output as a dynamic symbol.
2460 Undefined weak syms won't yet be marked as dynamic. */
2461 if (h->dynindx == -1
f5385ebf 2462 && !h->forced_local)
0c715baa 2463 {
c152c796 2464 if (! bfd_elf_link_record_dynamic_symbol (info, h))
b34976b6 2465 return FALSE;
0c715baa 2466 }
5a15f56f 2467
0c715baa
AM
2468 /* If that succeeded, we know we'll be keeping all the
2469 relocs. */
2470 if (h->dynindx != -1)
2471 goto keep;
2472 }
2473
2474 eh->dyn_relocs = NULL;
2475
ec338859 2476 keep: ;
5a15f56f
AM
2477 }
2478
0c715baa
AM
2479 /* Finally, allocate space. */
2480 for (p = eh->dyn_relocs; p != NULL; p = p->next)
12d0ee4a 2481 {
e7c33416
NC
2482 asection *sreloc;
2483
cbe950e9 2484 sreloc = elf_section_data (p->sec)->sreloc;
e7c33416
NC
2485
2486 BFD_ASSERT (sreloc != NULL);
eea6121a 2487 sreloc->size += p->count * sizeof (Elf32_External_Rel);
12d0ee4a
AM
2488 }
2489
b34976b6 2490 return TRUE;
6725bdbf
AM
2491}
2492
c25bc9fc
L
2493/* Allocate space in .plt, .got and associated reloc sections for
2494 local dynamic relocs. */
2495
2496static bfd_boolean
2497elf_i386_allocate_local_dynrelocs (void **slot, void *inf)
2498{
2499 struct elf_link_hash_entry *h
2500 = (struct elf_link_hash_entry *) *slot;
2501
2502 if (h->type != STT_GNU_IFUNC
2503 || !h->def_regular
2504 || !h->ref_regular
2505 || !h->forced_local
2506 || h->root.type != bfd_link_hash_defined)
2507 abort ();
2508
2509 return elf_i386_allocate_dynrelocs (h, inf);
2510}
2511
0c715baa
AM
2512/* Find any dynamic relocs that apply to read-only sections. */
2513
b34976b6 2514static bfd_boolean
eb4ff4d6 2515elf_i386_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
0c715baa
AM
2516{
2517 struct elf_i386_link_hash_entry *eh;
e03a8ed8 2518 struct elf_dyn_relocs *p;
0c715baa 2519
aa715242
L
2520 /* Skip local IFUNC symbols. */
2521 if (h->forced_local && h->type == STT_GNU_IFUNC)
2522 return TRUE;
2523
0c715baa
AM
2524 eh = (struct elf_i386_link_hash_entry *) h;
2525 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2526 {
2527 asection *s = p->sec->output_section;
2528
2529 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2530 {
2531 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2532
2533 info->flags |= DF_TEXTREL;
2534
b70321a2
L
2535 if (info->warn_shared_textrel && info->shared)
2536 info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2537 p->sec->owner, h->root.root.string,
2538 p->sec);
2539
0c715baa 2540 /* Not an error, just cut short the traversal. */
b34976b6 2541 return FALSE;
0c715baa
AM
2542 }
2543 }
b34976b6 2544 return TRUE;
0c715baa
AM
2545}
2546
252b5132
RH
2547/* Set the sizes of the dynamic sections. */
2548
b34976b6 2549static bfd_boolean
23209a78 2550elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
252b5132 2551{
6725bdbf 2552 struct elf_i386_link_hash_table *htab;
252b5132
RH
2553 bfd *dynobj;
2554 asection *s;
b34976b6 2555 bfd_boolean relocs;
0c715baa 2556 bfd *ibfd;
252b5132 2557
6725bdbf 2558 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
2559 if (htab == NULL)
2560 return FALSE;
ebe50bae 2561 dynobj = htab->elf.dynobj;
ffb2e45b
AM
2562 if (dynobj == NULL)
2563 abort ();
252b5132 2564
ebe50bae 2565 if (htab->elf.dynamic_sections_created)
252b5132
RH
2566 {
2567 /* Set the contents of the .interp section to the interpreter. */
36af4a4e 2568 if (info->executable)
252b5132
RH
2569 {
2570 s = bfd_get_section_by_name (dynobj, ".interp");
ffb2e45b
AM
2571 if (s == NULL)
2572 abort ();
eea6121a 2573 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
252b5132
RH
2574 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2575 }
161d71a6 2576 }
6725bdbf 2577
0c715baa
AM
2578 /* Set up .got offsets for local syms, and space for local dynamic
2579 relocs. */
2580 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
161d71a6
L
2581 {
2582 bfd_signed_vma *local_got;
2583 bfd_signed_vma *end_local_got;
13ae64f3 2584 char *local_tls_type;
67a4f2b7 2585 bfd_vma *local_tlsdesc_gotent;
161d71a6
L
2586 bfd_size_type locsymcount;
2587 Elf_Internal_Shdr *symtab_hdr;
2588 asection *srel;
6725bdbf 2589
0ffa91dd 2590 if (! is_i386_elf (ibfd))
161d71a6 2591 continue;
6725bdbf 2592
0c715baa
AM
2593 for (s = ibfd->sections; s != NULL; s = s->next)
2594 {
e03a8ed8 2595 struct elf_dyn_relocs *p;
0c715baa 2596
e03a8ed8 2597 for (p = ((struct elf_dyn_relocs *)
e81d3500 2598 elf_section_data (s)->local_dynrel);
ec338859
AM
2599 p != NULL;
2600 p = p->next)
0c715baa 2601 {
ec338859
AM
2602 if (!bfd_is_abs_section (p->sec)
2603 && bfd_is_abs_section (p->sec->output_section))
2604 {
2605 /* Input section has been discarded, either because
2606 it is a copy of a linkonce section or due to
2607 linker script /DISCARD/, so we'll be discarding
2608 the relocs too. */
2609 }
23209a78 2610 else if (get_elf_i386_backend_data (output_bfd)->is_vxworks
3348747a
NS
2611 && strcmp (p->sec->output_section->name,
2612 ".tls_vars") == 0)
2613 {
2614 /* Relocations in vxworks .tls_vars sections are
2615 handled specially by the loader. */
2616 }
248866a8 2617 else if (p->count != 0)
ec338859
AM
2618 {
2619 srel = elf_section_data (p->sec)->sreloc;
eea6121a 2620 srel->size += p->count * sizeof (Elf32_External_Rel);
4b819e1f
L
2621 if ((p->sec->output_section->flags & SEC_READONLY) != 0
2622 && (info->flags & DF_TEXTREL) == 0)
b70321a2
L
2623 {
2624 info->flags |= DF_TEXTREL;
2625 if (info->warn_shared_textrel && info->shared)
2626 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2627 p->sec->owner, p->sec);
b70321a2 2628 }
ec338859 2629 }
0c715baa
AM
2630 }
2631 }
2632
2633 local_got = elf_local_got_refcounts (ibfd);
161d71a6
L
2634 if (!local_got)
2635 continue;
6725bdbf 2636
0ffa91dd 2637 symtab_hdr = &elf_symtab_hdr (ibfd);
161d71a6
L
2638 locsymcount = symtab_hdr->sh_info;
2639 end_local_got = local_got + locsymcount;
13ae64f3 2640 local_tls_type = elf_i386_local_got_tls_type (ibfd);
67a4f2b7 2641 local_tlsdesc_gotent = elf_i386_local_tlsdesc_gotent (ibfd);
6de2ae4a
L
2642 s = htab->elf.sgot;
2643 srel = htab->elf.srelgot;
67a4f2b7
AO
2644 for (; local_got < end_local_got;
2645 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
161d71a6 2646 {
67a4f2b7 2647 *local_tlsdesc_gotent = (bfd_vma) -1;
161d71a6 2648 if (*local_got > 0)
6725bdbf 2649 {
67a4f2b7
AO
2650 if (GOT_TLS_GDESC_P (*local_tls_type))
2651 {
6de2ae4a 2652 *local_tlsdesc_gotent = htab->elf.sgotplt->size
67a4f2b7 2653 - elf_i386_compute_jump_table_size (htab);
6de2ae4a 2654 htab->elf.sgotplt->size += 8;
67a4f2b7
AO
2655 *local_got = (bfd_vma) -2;
2656 }
2657 if (! GOT_TLS_GDESC_P (*local_tls_type)
2658 || GOT_TLS_GD_P (*local_tls_type))
2659 {
2660 *local_got = s->size;
2661 s->size += 4;
2662 if (GOT_TLS_GD_P (*local_tls_type)
2663 || *local_tls_type == GOT_TLS_IE_BOTH)
2664 s->size += 4;
2665 }
13ae64f3 2666 if (info->shared
67a4f2b7 2667 || GOT_TLS_GD_ANY_P (*local_tls_type)
37e55690
JJ
2668 || (*local_tls_type & GOT_TLS_IE))
2669 {
2670 if (*local_tls_type == GOT_TLS_IE_BOTH)
eea6121a 2671 srel->size += 2 * sizeof (Elf32_External_Rel);
67a4f2b7
AO
2672 else if (GOT_TLS_GD_P (*local_tls_type)
2673 || ! GOT_TLS_GDESC_P (*local_tls_type))
eea6121a 2674 srel->size += sizeof (Elf32_External_Rel);
67a4f2b7 2675 if (GOT_TLS_GDESC_P (*local_tls_type))
6de2ae4a 2676 htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
37e55690 2677 }
6725bdbf 2678 }
161d71a6
L
2679 else
2680 *local_got = (bfd_vma) -1;
6725bdbf 2681 }
252b5132 2682 }
6725bdbf 2683
13ae64f3
JJ
2684 if (htab->tls_ldm_got.refcount > 0)
2685 {
2686 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2687 relocs. */
6de2ae4a
L
2688 htab->tls_ldm_got.offset = htab->elf.sgot->size;
2689 htab->elf.sgot->size += 8;
2690 htab->elf.srelgot->size += sizeof (Elf32_External_Rel);
13ae64f3
JJ
2691 }
2692 else
2693 htab->tls_ldm_got.offset = -1;
2694
0c715baa
AM
2695 /* Allocate global sym .plt and .got entries, and space for global
2696 sym dynamic relocs. */
eb4ff4d6 2697 elf_link_hash_traverse (&htab->elf, elf_i386_allocate_dynrelocs, info);
252b5132 2698
c25bc9fc
L
2699 /* Allocate .plt and .got entries, and space for local symbols. */
2700 htab_traverse (htab->loc_hash_table,
2701 elf_i386_allocate_local_dynrelocs,
2702 info);
2703
67a4f2b7
AO
2704 /* For every jump slot reserved in the sgotplt, reloc_count is
2705 incremented. However, when we reserve space for TLS descriptors,
2706 it's not incremented, so in order to compute the space reserved
2707 for them, it suffices to multiply the reloc count by the jump
e1f98742 2708 slot size.
caa0075c 2709
e1f98742
L
2710 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2711 so that R_386_IRELATIVE entries come last. */
6de2ae4a 2712 if (htab->elf.srelplt)
e1f98742
L
2713 {
2714 htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
2715 htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;
2716 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
2717 }
2718 else if (htab->elf.irelplt)
2719 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
2720
67a4f2b7 2721
a7b16ceb
L
2722 if (htab->elf.sgotplt)
2723 {
e28df02b
L
2724 struct elf_link_hash_entry *got;
2725 got = elf_link_hash_lookup (elf_hash_table (info),
2726 "_GLOBAL_OFFSET_TABLE_",
2727 FALSE, FALSE, FALSE);
2728
a7b16ceb 2729 /* Don't allocate .got.plt section if there are no GOT nor PLT
e28df02b
L
2730 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2731 if ((got == NULL
2732 || !got->ref_regular_nonweak)
2733 && (htab->elf.sgotplt->size
2734 == get_elf_backend_data (output_bfd)->got_header_size)
a7b16ceb
L
2735 && (htab->elf.splt == NULL
2736 || htab->elf.splt->size == 0)
2737 && (htab->elf.sgot == NULL
2738 || htab->elf.sgot->size == 0)
2739 && (htab->elf.iplt == NULL
2740 || htab->elf.iplt->size == 0)
2741 && (htab->elf.igotplt == NULL
2742 || htab->elf.igotplt->size == 0))
2743 htab->elf.sgotplt->size = 0;
2744 }
2745
5a15f56f
AM
2746 /* We now have determined the sizes of the various dynamic sections.
2747 Allocate memory for them. */
b34976b6 2748 relocs = FALSE;
252b5132
RH
2749 for (s = dynobj->sections; s != NULL; s = s->next)
2750 {
eac338cf
PB
2751 bfd_boolean strip_section = TRUE;
2752
252b5132
RH
2753 if ((s->flags & SEC_LINKER_CREATED) == 0)
2754 continue;
2755
6de2ae4a
L
2756 if (s == htab->elf.splt
2757 || s == htab->elf.sgot
2758 || s == htab->elf.sgotplt
2759 || s == htab->elf.iplt
2760 || s == htab->elf.igotplt
75ff4589 2761 || s == htab->sdynbss)
252b5132 2762 {
6725bdbf
AM
2763 /* Strip this section if we don't need it; see the
2764 comment below. */
eac338cf
PB
2765 /* We'd like to strip these sections if they aren't needed, but if
2766 we've exported dynamic symbols from them we must leave them.
2767 It's too late to tell BFD to get rid of the symbols. */
2768
7325306f 2769 if (htab->elf.hplt != NULL)
eac338cf 2770 strip_section = FALSE;
252b5132 2771 }
0112cd26 2772 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rel"))
252b5132 2773 {
6de2ae4a
L
2774 if (s->size != 0
2775 && s != htab->elf.srelplt
2776 && s != htab->srelplt2)
b34976b6 2777 relocs = TRUE;
252b5132 2778
0ac8d2ca
AM
2779 /* We use the reloc_count field as a counter if we need
2780 to copy relocs into the output file. */
5ae0bfb6 2781 s->reloc_count = 0;
252b5132 2782 }
6725bdbf 2783 else
252b5132
RH
2784 {
2785 /* It's not one of our sections, so don't allocate space. */
2786 continue;
2787 }
2788
c456f082 2789 if (s->size == 0)
252b5132 2790 {
0ac8d2ca
AM
2791 /* If we don't need this section, strip it from the
2792 output file. This is mostly to handle .rel.bss and
2793 .rel.plt. We must create both sections in
2794 create_dynamic_sections, because they must be created
2795 before the linker maps input sections to output
2796 sections. The linker does that before
2797 adjust_dynamic_symbol is called, and it is that
2798 function which decides whether anything needs to go
2799 into these sections. */
c456f082
AM
2800 if (strip_section)
2801 s->flags |= SEC_EXCLUDE;
252b5132
RH
2802 continue;
2803 }
2804
c456f082
AM
2805 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2806 continue;
2807
f69da49f
AM
2808 /* Allocate memory for the section contents. We use bfd_zalloc
2809 here in case unused entries are not reclaimed before the
2810 section's contents are written out. This should not happen,
2811 but this way if it does, we get a R_386_NONE reloc instead
2812 of garbage. */
a50b1753 2813 s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
6725bdbf 2814 if (s->contents == NULL)
b34976b6 2815 return FALSE;
252b5132
RH
2816 }
2817
e41b3a13
JJ
2818 if (htab->plt_eh_frame != NULL
2819 && htab->elf.splt != NULL
2820 && htab->elf.splt->size != 0
2821 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0)
2822 bfd_put_32 (dynobj, htab->elf.splt->size,
2823 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
2824
ebe50bae 2825 if (htab->elf.dynamic_sections_created)
252b5132
RH
2826 {
2827 /* Add some entries to the .dynamic section. We fill in the
2828 values later, in elf_i386_finish_dynamic_sections, but we
2829 must add the entries now so that we get the correct size for
2830 the .dynamic section. The DT_DEBUG entry is filled in by the
2831 dynamic linker and used by the debugger. */
dc810e39 2832#define add_dynamic_entry(TAG, VAL) \
5a580b3a 2833 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
dc810e39 2834
36af4a4e 2835 if (info->executable)
252b5132 2836 {
dc810e39 2837 if (!add_dynamic_entry (DT_DEBUG, 0))
b34976b6 2838 return FALSE;
252b5132
RH
2839 }
2840
6de2ae4a 2841 if (htab->elf.splt->size != 0)
252b5132 2842 {
dc810e39
AM
2843 if (!add_dynamic_entry (DT_PLTGOT, 0)
2844 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2845 || !add_dynamic_entry (DT_PLTREL, DT_REL)
2846 || !add_dynamic_entry (DT_JMPREL, 0))
b34976b6 2847 return FALSE;
252b5132
RH
2848 }
2849
2850 if (relocs)
2851 {
dc810e39
AM
2852 if (!add_dynamic_entry (DT_REL, 0)
2853 || !add_dynamic_entry (DT_RELSZ, 0)
2854 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
b34976b6 2855 return FALSE;
252b5132 2856
0c715baa
AM
2857 /* If any dynamic relocs apply to a read-only section,
2858 then we need a DT_TEXTREL entry. */
248866a8 2859 if ((info->flags & DF_TEXTREL) == 0)
eb4ff4d6
L
2860 elf_link_hash_traverse (&htab->elf,
2861 elf_i386_readonly_dynrelocs, info);
0c715baa
AM
2862
2863 if ((info->flags & DF_TEXTREL) != 0)
2864 {
2865 if (!add_dynamic_entry (DT_TEXTREL, 0))
b34976b6 2866 return FALSE;
0c715baa 2867 }
252b5132 2868 }
23209a78 2869 if (get_elf_i386_backend_data (output_bfd)->is_vxworks
7a2b07ff
NS
2870 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
2871 return FALSE;
252b5132 2872 }
dc810e39 2873#undef add_dynamic_entry
252b5132 2874
b34976b6 2875 return TRUE;
252b5132
RH
2876}
2877
67a4f2b7
AO
2878static bfd_boolean
2879elf_i386_always_size_sections (bfd *output_bfd,
2880 struct bfd_link_info *info)
2881{
2882 asection *tls_sec = elf_hash_table (info)->tls_sec;
2883
2884 if (tls_sec)
2885 {
2886 struct elf_link_hash_entry *tlsbase;
2887
2888 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2889 "_TLS_MODULE_BASE_",
2890 FALSE, FALSE, FALSE);
2891
2892 if (tlsbase && tlsbase->type == STT_TLS)
2893 {
4dfe6ac6 2894 struct elf_i386_link_hash_table *htab;
67a4f2b7
AO
2895 struct bfd_link_hash_entry *bh = NULL;
2896 const struct elf_backend_data *bed
2897 = get_elf_backend_data (output_bfd);
2898
4dfe6ac6
NC
2899 htab = elf_i386_hash_table (info);
2900 if (htab == NULL)
2901 return FALSE;
2902
67a4f2b7
AO
2903 if (!(_bfd_generic_link_add_one_symbol
2904 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2905 tls_sec, 0, NULL, FALSE,
2906 bed->collect, &bh)))
2907 return FALSE;
9f03412a 2908
4dfe6ac6 2909 htab->tls_module_base = bh;
9f03412a 2910
67a4f2b7
AO
2911 tlsbase = (struct elf_link_hash_entry *)bh;
2912 tlsbase->def_regular = 1;
2913 tlsbase->other = STV_HIDDEN;
2914 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2915 }
2916 }
2917
2918 return TRUE;
2919}
2920
38701953
AM
2921/* Set the correct type for an x86 ELF section. We do this by the
2922 section name, which is a hack, but ought to work. */
2923
b34976b6 2924static bfd_boolean
55fd94b0
AM
2925elf_i386_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
2926 Elf_Internal_Shdr *hdr,
2927 asection *sec)
38701953 2928{
91d6fa6a 2929 const char *name;
38701953
AM
2930
2931 name = bfd_get_section_name (abfd, sec);
2932
2933 /* This is an ugly, but unfortunately necessary hack that is
2934 needed when producing EFI binaries on x86. It tells
2935 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2936 containing ELF relocation info. We need this hack in order to
2937 be able to generate ELF binaries that can be translated into
2938 EFI applications (which are essentially COFF objects). Those
2939 files contain a COFF ".reloc" section inside an ELFNN object,
2940 which would normally cause BFD to segfault because it would
2941 attempt to interpret this section as containing relocation
2942 entries for section "oc". With this hack enabled, ".reloc"
2943 will be treated as a normal data section, which will avoid the
2944 segfault. However, you won't be able to create an ELFNN binary
2945 with a section named "oc" that needs relocations, but that's
2946 the kind of ugly side-effects you get when detecting section
2947 types based on their names... In practice, this limitation is
2948 unlikely to bite. */
2949 if (strcmp (name, ".reloc") == 0)
2950 hdr->sh_type = SHT_PROGBITS;
2951
b34976b6 2952 return TRUE;
38701953
AM
2953}
2954
9f03412a
AO
2955/* _TLS_MODULE_BASE_ needs to be treated especially when linking
2956 executables. Rather than setting it to the beginning of the TLS
2957 section, we have to set it to the end. This function may be called
2958 multiple times, it is idempotent. */
2959
2960static void
eb4ff4d6 2961elf_i386_set_tls_module_base (struct bfd_link_info *info)
9f03412a 2962{
4dfe6ac6 2963 struct elf_i386_link_hash_table *htab;
9f03412a
AO
2964 struct bfd_link_hash_entry *base;
2965
2966 if (!info->executable)
2967 return;
2968
4dfe6ac6
NC
2969 htab = elf_i386_hash_table (info);
2970 if (htab == NULL)
2971 return;
9f03412a 2972
4dfe6ac6
NC
2973 base = htab->tls_module_base;
2974 if (base == NULL)
9f03412a
AO
2975 return;
2976
4dfe6ac6 2977 base->u.def.value = htab->elf.tls_size;
9f03412a
AO
2978}
2979
13ae64f3
JJ
2980/* Return the base VMA address which should be subtracted from real addresses
2981 when resolving @dtpoff relocation.
2982 This is PT_TLS segment p_vaddr. */
2983
2984static bfd_vma
eb4ff4d6 2985elf_i386_dtpoff_base (struct bfd_link_info *info)
13ae64f3 2986{
e1918d23
AM
2987 /* If tls_sec is NULL, we should have signalled an error already. */
2988 if (elf_hash_table (info)->tls_sec == NULL)
6a30718d 2989 return 0;
e1918d23 2990 return elf_hash_table (info)->tls_sec->vma;
13ae64f3
JJ
2991}
2992
2993/* Return the relocation value for @tpoff relocation
2994 if STT_TLS virtual address is ADDRESS. */
2995
2996static bfd_vma
eb4ff4d6 2997elf_i386_tpoff (struct bfd_link_info *info, bfd_vma address)
13ae64f3 2998{
e1918d23 2999 struct elf_link_hash_table *htab = elf_hash_table (info);
7dc98aea
RO
3000 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
3001 bfd_vma static_tls_size;
13ae64f3 3002
e1918d23
AM
3003 /* If tls_sec is NULL, we should have signalled an error already. */
3004 if (htab->tls_sec == NULL)
6a30718d 3005 return 0;
7dc98aea
RO
3006
3007 /* Consider special static TLS alignment requirements. */
3008 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
3009 return static_tls_size + htab->tls_sec->vma - address;
13ae64f3
JJ
3010}
3011
252b5132
RH
3012/* Relocate an i386 ELF section. */
3013
b34976b6 3014static bfd_boolean
55fd94b0
AM
3015elf_i386_relocate_section (bfd *output_bfd,
3016 struct bfd_link_info *info,
3017 bfd *input_bfd,
3018 asection *input_section,
3019 bfd_byte *contents,
3020 Elf_Internal_Rela *relocs,
3021 Elf_Internal_Sym *local_syms,
3022 asection **local_sections)
252b5132 3023{
6725bdbf 3024 struct elf_i386_link_hash_table *htab;
252b5132
RH
3025 Elf_Internal_Shdr *symtab_hdr;
3026 struct elf_link_hash_entry **sym_hashes;
3027 bfd_vma *local_got_offsets;
67a4f2b7 3028 bfd_vma *local_tlsdesc_gotents;
252b5132
RH
3029 Elf_Internal_Rela *rel;
3030 Elf_Internal_Rela *relend;
3348747a 3031 bfd_boolean is_vxworks_tls;
25e762b9 3032 unsigned plt_entry_size;
252b5132 3033
0ffa91dd 3034 BFD_ASSERT (is_i386_elf (input_bfd));
6bbec505 3035
6725bdbf 3036 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
3037 if (htab == NULL)
3038 return FALSE;
0ffa91dd 3039 symtab_hdr = &elf_symtab_hdr (input_bfd);
252b5132
RH
3040 sym_hashes = elf_sym_hashes (input_bfd);
3041 local_got_offsets = elf_local_got_offsets (input_bfd);
67a4f2b7 3042 local_tlsdesc_gotents = elf_i386_local_tlsdesc_gotent (input_bfd);
3348747a
NS
3043 /* We have to handle relocations in vxworks .tls_vars sections
3044 specially, because the dynamic loader is 'weird'. */
23209a78
RM
3045 is_vxworks_tls = (get_elf_i386_backend_data (output_bfd)->is_vxworks
3046 && info->shared
3348747a
NS
3047 && !strcmp (input_section->output_section->name,
3048 ".tls_vars"));
252b5132 3049
eb4ff4d6 3050 elf_i386_set_tls_module_base (info);
9f03412a 3051
25e762b9
RM
3052 plt_entry_size = GET_PLT_ENTRY_SIZE (output_bfd);
3053
252b5132
RH
3054 rel = relocs;
3055 relend = relocs + input_section->reloc_count;
3056 for (; rel < relend; rel++)
3057 {
13ae64f3 3058 unsigned int r_type;
252b5132
RH
3059 reloc_howto_type *howto;
3060 unsigned long r_symndx;
3061 struct elf_link_hash_entry *h;
3062 Elf_Internal_Sym *sym;
3063 asection *sec;
67a4f2b7 3064 bfd_vma off, offplt;
252b5132 3065 bfd_vma relocation;
b34976b6 3066 bfd_boolean unresolved_reloc;
252b5132 3067 bfd_reloc_status_type r;
1b452ec6 3068 unsigned int indx;
13ae64f3 3069 int tls_type;
252b5132
RH
3070
3071 r_type = ELF32_R_TYPE (rel->r_info);
55fd94b0
AM
3072 if (r_type == R_386_GNU_VTINHERIT
3073 || r_type == R_386_GNU_VTENTRY)
252b5132 3074 continue;
dc47f327 3075
55fd94b0 3076 if ((indx = r_type) >= R_386_standard
13ae64f3
JJ
3077 && ((indx = r_type - R_386_ext_offset) - R_386_standard
3078 >= R_386_ext - R_386_standard)
3079 && ((indx = r_type - R_386_tls_offset) - R_386_ext
cbe950e9 3080 >= R_386_irelative - R_386_ext))
252b5132 3081 {
6ba842b6 3082 (*_bfd_error_handler)
d003868e
AM
3083 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3084 input_bfd, input_section, r_type);
252b5132 3085 bfd_set_error (bfd_error_bad_value);
b34976b6 3086 return FALSE;
252b5132 3087 }
1b452ec6 3088 howto = elf_howto_table + indx;
252b5132
RH
3089
3090 r_symndx = ELF32_R_SYM (rel->r_info);
252b5132
RH
3091 h = NULL;
3092 sym = NULL;
3093 sec = NULL;
b34976b6 3094 unresolved_reloc = FALSE;
252b5132
RH
3095 if (r_symndx < symtab_hdr->sh_info)
3096 {
3097 sym = local_syms + r_symndx;
3098 sec = local_sections[r_symndx];
3099 relocation = (sec->output_section->vma
3100 + sec->output_offset
3101 + sym->st_value);
ab96bf03
AM
3102
3103 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION
3104 && ((sec->flags & SEC_MERGE) != 0
3105 || (info->relocatable
3106 && sec->output_offset != 0)))
f8df10f4 3107 {
f8df10f4 3108 bfd_vma addend;
4a335f3d 3109 bfd_byte *where = contents + rel->r_offset;
f8df10f4 3110
4a335f3d 3111 switch (howto->size)
f8df10f4 3112 {
4a335f3d
AM
3113 case 0:
3114 addend = bfd_get_8 (input_bfd, where);
3115 if (howto->pc_relative)
3116 {
3117 addend = (addend ^ 0x80) - 0x80;
3118 addend += 1;
3119 }
3120 break;
3121 case 1:
3122 addend = bfd_get_16 (input_bfd, where);
3123 if (howto->pc_relative)
3124 {
3125 addend = (addend ^ 0x8000) - 0x8000;
3126 addend += 2;
3127 }
3128 break;
3129 case 2:
3130 addend = bfd_get_32 (input_bfd, where);
3131 if (howto->pc_relative)
3132 {
3133 addend = (addend ^ 0x80000000) - 0x80000000;
3134 addend += 4;
3135 }
3136 break;
3137 default:
3138 abort ();
f8df10f4
JJ
3139 }
3140
ab96bf03
AM
3141 if (info->relocatable)
3142 addend += sec->output_offset;
3143 else
3144 {
3145 asection *msec = sec;
3146 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec,
3147 addend);
3148 addend -= relocation;
3149 addend += msec->output_section->vma + msec->output_offset;
3150 }
4a335f3d
AM
3151
3152 switch (howto->size)
3153 {
3154 case 0:
16a10388 3155 /* FIXME: overflow checks. */
4a335f3d
AM
3156 if (howto->pc_relative)
3157 addend -= 1;
3158 bfd_put_8 (input_bfd, addend, where);
4a335f3d
AM
3159 break;
3160 case 1:
3161 if (howto->pc_relative)
3162 addend -= 2;
3163 bfd_put_16 (input_bfd, addend, where);
4a335f3d
AM
3164 break;
3165 case 2:
3166 if (howto->pc_relative)
3167 addend -= 4;
3168 bfd_put_32 (input_bfd, addend, where);
3169 break;
3170 }
f8df10f4 3171 }
1f85278f
L
3172 else if (!info->relocatable
3173 && ELF32_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
c25bc9fc
L
3174 {
3175 /* Relocate against local STT_GNU_IFUNC symbol. */
9fff0c39
L
3176 h = elf_i386_get_local_sym_hash (htab, input_bfd, rel,
3177 FALSE);
c25bc9fc
L
3178 if (h == NULL)
3179 abort ();
3180
23209a78 3181 /* Set STT_GNU_IFUNC symbol value. */
c25bc9fc
L
3182 h->root.u.def.value = sym->st_value;
3183 h->root.u.def.section = sec;
3184 }
252b5132
RH
3185 }
3186 else
3187 {
3d540e93 3188 bfd_boolean warned ATTRIBUTE_UNUSED;
ffb2e45b 3189
b2a8e766
AM
3190 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3191 r_symndx, symtab_hdr, sym_hashes,
3192 h, sec, relocation,
3193 unresolved_reloc, warned);
252b5132
RH
3194 }
3195
dbaa2011 3196 if (sec != NULL && discarded_section (sec))
0672748a 3197 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
545fd46b 3198 rel, 1, relend, howto, 0, contents);
9635fe29 3199
ab96bf03
AM
3200 if (info->relocatable)
3201 continue;
3202
cbe950e9
L
3203 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3204 it here if it is defined in a non-shared object. */
3205 if (h != NULL
3206 && h->type == STT_GNU_IFUNC
3207 && h->def_regular)
3208 {
3209 asection *plt, *gotplt, *base_got;
3210 bfd_vma plt_index;
4c544807 3211 const char *name;
cbe950e9
L
3212
3213 if ((input_section->flags & SEC_ALLOC) == 0
3214 || h->plt.offset == (bfd_vma) -1)
3215 abort ();
3216
3217 /* STT_GNU_IFUNC symbol must go through PLT. */
6de2ae4a 3218 if (htab->elf.splt != NULL)
cbe950e9 3219 {
6de2ae4a
L
3220 plt = htab->elf.splt;
3221 gotplt = htab->elf.sgotplt;
cbe950e9
L
3222 }
3223 else
3224 {
6de2ae4a
L
3225 plt = htab->elf.iplt;
3226 gotplt = htab->elf.igotplt;
cbe950e9
L
3227 }
3228
3229 relocation = (plt->output_section->vma
3230 + plt->output_offset + h->plt.offset);
3231
3232 switch (r_type)
3233 {
3234 default:
4c544807
L
3235 if (h->root.root.string)
3236 name = h->root.root.string;
3237 else
3238 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3239 NULL);
cbe950e9
L
3240 (*_bfd_error_handler)
3241 (_("%B: relocation %s against STT_GNU_IFUNC "
3242 "symbol `%s' isn't handled by %s"), input_bfd,
3243 elf_howto_table[r_type].name,
4c544807 3244 name, __FUNCTION__);
cbe950e9
L
3245 bfd_set_error (bfd_error_bad_value);
3246 return FALSE;
3247
3248 case R_386_32:
710ab287 3249 /* Generate dynamic relcoation only when there is a
c293fa49 3250 non-GOT reference in a shared object. */
710ab287
L
3251 if (info->shared && h->non_got_ref)
3252 {
3253 Elf_Internal_Rela outrel;
3254 bfd_byte *loc;
3255 asection *sreloc;
3256 bfd_vma offset;
3257
c25bc9fc
L
3258 /* Need a dynamic relocation to get the real function
3259 adddress. */
710ab287
L
3260 offset = _bfd_elf_section_offset (output_bfd,
3261 info,
3262 input_section,
3263 rel->r_offset);
3264 if (offset == (bfd_vma) -1
3265 || offset == (bfd_vma) -2)
3266 abort ();
3267
3268 outrel.r_offset = (input_section->output_section->vma
3269 + input_section->output_offset
3270 + offset);
3271
3272 if (h->dynindx == -1
44c4ea11
L
3273 || h->forced_local
3274 || info->executable)
710ab287
L
3275 {
3276 /* This symbol is resolved locally. */
56b8aada
L
3277 outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
3278 bfd_put_32 (output_bfd,
3279 (h->root.u.def.value
3280 + h->root.u.def.section->output_section->vma
3281 + h->root.u.def.section->output_offset),
3282 contents + offset);
710ab287
L
3283 }
3284 else
56b8aada 3285 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
710ab287 3286
6de2ae4a 3287 sreloc = htab->elf.irelifunc;
710ab287
L
3288 loc = sreloc->contents;
3289 loc += (sreloc->reloc_count++
3290 * sizeof (Elf32_External_Rel));
3291 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3292
3293 /* If this reloc is against an external symbol, we
3294 do not want to fiddle with the addend. Otherwise,
3295 we need to include the symbol value so that it
3296 becomes an addend for the dynamic reloc. For an
3297 internal symbol, we have updated addend. */
56b8aada 3298 continue;
710ab287 3299 }
d59a60e9 3300 /* FALLTHROUGH */
cbe950e9
L
3301 case R_386_PC32:
3302 case R_386_PLT32:
3303 goto do_relocation;
3304
3305 case R_386_GOT32:
6de2ae4a 3306 base_got = htab->elf.sgot;
cbe950e9
L
3307 off = h->got.offset;
3308
7afd84dc 3309 if (base_got == NULL)
cbe950e9
L
3310 abort ();
3311
7afd84dc 3312 if (off == (bfd_vma) -1)
cbe950e9 3313 {
7afd84dc
L
3314 /* We can't use h->got.offset here to save state, or
3315 even just remember the offset, as finish_dynamic_symbol
3316 would use that as offset into .got. */
6bbec505 3317
6de2ae4a 3318 if (htab->elf.splt != NULL)
7afd84dc 3319 {
25e762b9 3320 plt_index = h->plt.offset / plt_entry_size - 1;
7afd84dc 3321 off = (plt_index + 3) * 4;
6de2ae4a 3322 base_got = htab->elf.sgotplt;
7afd84dc 3323 }
cbe950e9
L
3324 else
3325 {
25e762b9 3326 plt_index = h->plt.offset / plt_entry_size;
7afd84dc 3327 off = plt_index * 4;
6de2ae4a 3328 base_got = htab->elf.igotplt;
7afd84dc
L
3329 }
3330
3331 if (h->dynindx == -1
3332 || h->forced_local
3333 || info->symbolic)
3334 {
3335 /* This references the local defitionion. We must
3336 initialize this entry in the global offset table.
3337 Since the offset must always be a multiple of 8,
3338 we use the least significant bit to record
3339 whether we have initialized it already.
3340
3341 When doing a dynamic link, we create a .rela.got
3342 relocation entry to initialize the value. This
3343 is done in the finish_dynamic_symbol routine. */
3344 if ((off & 1) != 0)
3345 off &= ~1;
3346 else
3347 {
3348 bfd_put_32 (output_bfd, relocation,
3349 base_got->contents + off);
3350 h->got.offset |= 1;
3351 }
cbe950e9 3352 }
cbe950e9 3353
7afd84dc 3354 relocation = off;
cbe950e9 3355
7afd84dc 3356 /* Adjust for static executables. */
6de2ae4a 3357 if (htab->elf.splt == NULL)
7afd84dc
L
3358 relocation += gotplt->output_offset;
3359 }
3360 else
0018b0a3
L
3361 {
3362 relocation = (base_got->output_section->vma
3363 + base_got->output_offset + off
3364 - gotplt->output_section->vma
3365 - gotplt->output_offset);
3366 /* Adjust for static executables. */
6de2ae4a 3367 if (htab->elf.splt == NULL)
0018b0a3
L
3368 relocation += gotplt->output_offset;
3369 }
3370
cbe950e9
L
3371 goto do_relocation;
3372
3373 case R_386_GOTOFF:
3374 relocation -= (gotplt->output_section->vma
3375 + gotplt->output_offset);
3376 goto do_relocation;
3377 }
3378 }
3379
252b5132
RH
3380 switch (r_type)
3381 {
3382 case R_386_GOT32:
3383 /* Relocation is to the entry for this symbol in the global
3384 offset table. */
6de2ae4a 3385 if (htab->elf.sgot == NULL)
ffb2e45b 3386 abort ();
252b5132
RH
3387
3388 if (h != NULL)
3389 {
b34976b6 3390 bfd_boolean dyn;
252b5132
RH
3391
3392 off = h->got.offset;
ebe50bae 3393 dyn = htab->elf.dynamic_sections_created;
26e41594 3394 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
252b5132 3395 || (info->shared
586119b3 3396 && SYMBOL_REFERENCES_LOCAL (info, h))
ef5aade5
L
3397 || (ELF_ST_VISIBILITY (h->other)
3398 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
3399 {
3400 /* This is actually a static link, or it is a
3401 -Bsymbolic link and the symbol is defined
3402 locally, or the symbol was forced to be local
3403 because of a version file. We must initialize
3404 this entry in the global offset table. Since the
3405 offset must always be a multiple of 4, we use the
3406 least significant bit to record whether we have
3407 initialized it already.
3408
3409 When doing a dynamic link, we create a .rel.got
3410 relocation entry to initialize the value. This
3411 is done in the finish_dynamic_symbol routine. */
3412 if ((off & 1) != 0)
3413 off &= ~1;
3414 else
3415 {
3416 bfd_put_32 (output_bfd, relocation,
6de2ae4a 3417 htab->elf.sgot->contents + off);
252b5132
RH
3418 h->got.offset |= 1;
3419 }
3420 }
8c694914 3421 else
b34976b6 3422 unresolved_reloc = FALSE;
252b5132
RH
3423 }
3424 else
3425 {
ffb2e45b
AM
3426 if (local_got_offsets == NULL)
3427 abort ();
252b5132
RH
3428
3429 off = local_got_offsets[r_symndx];
3430
3431 /* The offset must always be a multiple of 4. We use
83be169b
AM
3432 the least significant bit to record whether we have
3433 already generated the necessary reloc. */
252b5132
RH
3434 if ((off & 1) != 0)
3435 off &= ~1;
3436 else
3437 {
6725bdbf 3438 bfd_put_32 (output_bfd, relocation,
6de2ae4a 3439 htab->elf.sgot->contents + off);
252b5132
RH
3440
3441 if (info->shared)
3442 {
947216bf
AM
3443 asection *s;
3444 Elf_Internal_Rela outrel;
3445 bfd_byte *loc;
252b5132 3446
6de2ae4a 3447 s = htab->elf.srelgot;
947216bf 3448 if (s == NULL)
ffb2e45b 3449 abort ();
252b5132 3450
6de2ae4a
L
3451 outrel.r_offset = (htab->elf.sgot->output_section->vma
3452 + htab->elf.sgot->output_offset
252b5132
RH
3453 + off);
3454 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
947216bf
AM
3455 loc = s->contents;
3456 loc += s->reloc_count++ * sizeof (Elf32_External_Rel);
0ac8d2ca 3457 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
252b5132
RH
3458 }
3459
3460 local_got_offsets[r_symndx] |= 1;
3461 }
252b5132
RH
3462 }
3463
ffb2e45b
AM
3464 if (off >= (bfd_vma) -2)
3465 abort ();
3466
6de2ae4a
L
3467 relocation = htab->elf.sgot->output_section->vma
3468 + htab->elf.sgot->output_offset + off
3469 - htab->elf.sgotplt->output_section->vma
3470 - htab->elf.sgotplt->output_offset;
252b5132
RH
3471 break;
3472
3473 case R_386_GOTOFF:
3474 /* Relocation is relative to the start of the global offset
3475 table. */
3476
90f487df
L
3477 /* Check to make sure it isn't a protected function symbol
3478 for shared library since it may not be local when used
41bed6dd
L
3479 as function address. We also need to make sure that a
3480 symbol is defined locally. */
3481 if (info->shared && h)
90f487df 3482 {
41bed6dd
L
3483 if (!h->def_regular)
3484 {
3485 const char *v;
3486
3487 switch (ELF_ST_VISIBILITY (h->other))
3488 {
3489 case STV_HIDDEN:
3490 v = _("hidden symbol");
3491 break;
3492 case STV_INTERNAL:
3493 v = _("internal symbol");
3494 break;
3495 case STV_PROTECTED:
3496 v = _("protected symbol");
3497 break;
3498 default:
3499 v = _("symbol");
3500 break;
3501 }
3502
3503 (*_bfd_error_handler)
3504 (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
3505 input_bfd, v, h->root.root.string);
3506 bfd_set_error (bfd_error_bad_value);
3507 return FALSE;
3508 }
3509 else if (!info->executable
bdb892b9 3510 && !SYMBOLIC_BIND (info, h)
41bed6dd
L
3511 && h->type == STT_FUNC
3512 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
3513 {
3514 (*_bfd_error_handler)
3515 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
3516 input_bfd, h->root.root.string);
3517 bfd_set_error (bfd_error_bad_value);
3518 return FALSE;
3519 }
90f487df
L
3520 }
3521
8c37241b
JJ
3522 /* Note that sgot is not involved in this
3523 calculation. We always want the start of .got.plt. If we
3524 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
252b5132
RH
3525 permitted by the ABI, we might have to change this
3526 calculation. */
6de2ae4a
L
3527 relocation -= htab->elf.sgotplt->output_section->vma
3528 + htab->elf.sgotplt->output_offset;
252b5132
RH
3529 break;
3530
3531 case R_386_GOTPC:
3532 /* Use global offset table as symbol value. */
6de2ae4a
L
3533 relocation = htab->elf.sgotplt->output_section->vma
3534 + htab->elf.sgotplt->output_offset;
b34976b6 3535 unresolved_reloc = FALSE;
252b5132
RH
3536 break;
3537
3538 case R_386_PLT32:
3539 /* Relocation is to the entry for this symbol in the
3540 procedure linkage table. */
3541
dd5724d5 3542 /* Resolve a PLT32 reloc against a local symbol directly,
83be169b 3543 without using the procedure linkage table. */
252b5132
RH
3544 if (h == NULL)
3545 break;
3546
dd5724d5 3547 if (h->plt.offset == (bfd_vma) -1
6de2ae4a 3548 || htab->elf.splt == NULL)
252b5132
RH
3549 {
3550 /* We didn't make a PLT entry for this symbol. This
83be169b
AM
3551 happens when statically linking PIC code, or when
3552 using -Bsymbolic. */
252b5132
RH
3553 break;
3554 }
3555
6de2ae4a
L
3556 relocation = (htab->elf.splt->output_section->vma
3557 + htab->elf.splt->output_offset
252b5132 3558 + h->plt.offset);
b34976b6 3559 unresolved_reloc = FALSE;
252b5132
RH
3560 break;
3561
3562 case R_386_32:
3563 case R_386_PC32:
3348747a
NS
3564 if ((input_section->flags & SEC_ALLOC) == 0
3565 || is_vxworks_tls)
ec338859
AM
3566 break;
3567
12d0ee4a 3568 if ((info->shared
ef5aade5
L
3569 && (h == NULL
3570 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3571 || h->root.type != bfd_link_hash_undefweak)
12d0ee4a 3572 && (r_type != R_386_PC32
f6c52c13 3573 || !SYMBOL_CALLS_LOCAL (info, h)))
a23b6845
AM
3574 || (ELIMINATE_COPY_RELOCS
3575 && !info->shared
12d0ee4a
AM
3576 && h != NULL
3577 && h->dynindx != -1
f5385ebf
AM
3578 && !h->non_got_ref
3579 && ((h->def_dynamic
3580 && !h->def_regular)
28d0b90e 3581 || h->root.type == bfd_link_hash_undefweak
0f88be7a 3582 || h->root.type == bfd_link_hash_undefined)))
252b5132 3583 {
947216bf
AM
3584 Elf_Internal_Rela outrel;
3585 bfd_byte *loc;
b34976b6 3586 bfd_boolean skip, relocate;
0c715baa 3587 asection *sreloc;
252b5132
RH
3588
3589 /* When generating a shared object, these relocations
3590 are copied into the output file to be resolved at run
3591 time. */
3592
b34976b6
AM
3593 skip = FALSE;
3594 relocate = FALSE;
252b5132 3595
c629eae0
JJ
3596 outrel.r_offset =
3597 _bfd_elf_section_offset (output_bfd, info, input_section,
3598 rel->r_offset);
3599 if (outrel.r_offset == (bfd_vma) -1)
b34976b6 3600 skip = TRUE;
0bb2d96a 3601 else if (outrel.r_offset == (bfd_vma) -2)
b34976b6 3602 skip = TRUE, relocate = TRUE;
252b5132
RH
3603 outrel.r_offset += (input_section->output_section->vma
3604 + input_section->output_offset);
3605
3606 if (skip)
0bb2d96a 3607 memset (&outrel, 0, sizeof outrel);
5a15f56f
AM
3608 else if (h != NULL
3609 && h->dynindx != -1
3610 && (r_type == R_386_PC32
3611 || !info->shared
55255dae 3612 || !SYMBOLIC_BIND (info, h)
f5385ebf 3613 || !h->def_regular))
0bb2d96a 3614 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
252b5132
RH
3615 else
3616 {
5a15f56f 3617 /* This symbol is local, or marked to become local. */
b34976b6 3618 relocate = TRUE;
5a15f56f 3619 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
252b5132
RH
3620 }
3621
cbe950e9 3622 sreloc = elf_section_data (input_section)->sreloc;
e7c33416 3623
62d78908
L
3624 if (sreloc == NULL || sreloc->contents == NULL)
3625 {
3626 r = bfd_reloc_notsupported;
3627 goto check_relocation_error;
3628 }
0c715baa 3629
947216bf
AM
3630 loc = sreloc->contents;
3631 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
e7c33416 3632
0c715baa 3633 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
252b5132
RH
3634
3635 /* If this reloc is against an external symbol, we do
3636 not want to fiddle with the addend. Otherwise, we
3637 need to include the symbol value so that it becomes
3638 an addend for the dynamic reloc. */
0f88be7a 3639 if (! relocate)
252b5132
RH
3640 continue;
3641 }
252b5132
RH
3642 break;
3643
37e55690 3644 case R_386_TLS_IE:
1d85728f 3645 if (!info->executable)
37e55690 3646 {
947216bf
AM
3647 Elf_Internal_Rela outrel;
3648 bfd_byte *loc;
37e55690 3649 asection *sreloc;
37e55690
JJ
3650
3651 outrel.r_offset = rel->r_offset
3652 + input_section->output_section->vma
3653 + input_section->output_offset;
3654 outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
3655 sreloc = elf_section_data (input_section)->sreloc;
3656 if (sreloc == NULL)
3657 abort ();
947216bf
AM
3658 loc = sreloc->contents;
3659 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
37e55690
JJ
3660 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3661 }
3662 /* Fall through */
3663
13ae64f3 3664 case R_386_TLS_GD:
67a4f2b7
AO
3665 case R_386_TLS_GOTDESC:
3666 case R_386_TLS_DESC_CALL:
13ae64f3 3667 case R_386_TLS_IE_32:
37e55690 3668 case R_386_TLS_GOTIE:
13ae64f3
JJ
3669 tls_type = GOT_UNKNOWN;
3670 if (h == NULL && local_got_offsets)
3671 tls_type = elf_i386_local_got_tls_type (input_bfd) [r_symndx];
3672 else if (h != NULL)
142411ca 3673 tls_type = elf_i386_hash_entry(h)->tls_type;
37e55690
JJ
3674 if (tls_type == GOT_TLS_IE)
3675 tls_type = GOT_TLS_IE_NEG;
142411ca
L
3676
3677 if (! elf_i386_tls_transition (info, input_bfd,
3678 input_section, contents,
3679 symtab_hdr, sym_hashes,
3680 &r_type, tls_type, rel,
4c544807 3681 relend, h, r_symndx))
142411ca 3682 return FALSE;
13ae64f3
JJ
3683
3684 if (r_type == R_386_TLS_LE_32)
3685 {
82e51918 3686 BFD_ASSERT (! unresolved_reloc);
13ae64f3
JJ
3687 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
3688 {
142411ca 3689 unsigned int type;
13ae64f3
JJ
3690 bfd_vma roff;
3691
3692 /* GD->LE transition. */
13ae64f3 3693 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
13ae64f3
JJ
3694 if (type == 0x04)
3695 {
3696 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3697 Change it into:
3698 movl %gs:0, %eax; subl $foo@tpoff, %eax
3699 (6 byte form of subl). */
13ae64f3
JJ
3700 memcpy (contents + rel->r_offset - 3,
3701 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
142411ca 3702 roff = rel->r_offset + 5;
13ae64f3
JJ
3703 }
3704 else
3705 {
142411ca
L
3706 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3707 Change it into:
3708 movl %gs:0, %eax; subl $foo@tpoff, %eax
3709 (6 byte form of subl). */
3710 memcpy (contents + rel->r_offset - 2,
3711 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
3712 roff = rel->r_offset + 6;
13ae64f3 3713 }
eb4ff4d6 3714 bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
13ae64f3 3715 contents + roff);
a3fadc9a 3716 /* Skip R_386_PC32/R_386_PLT32. */
13ae64f3
JJ
3717 rel++;
3718 continue;
3719 }
67a4f2b7
AO
3720 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
3721 {
3722 /* GDesc -> LE transition.
3723 It's originally something like:
3724 leal x@tlsdesc(%ebx), %eax
3725
3726 leal x@ntpoff, %eax
3727
3728 Registers other than %eax may be set up here. */
3729
142411ca 3730 unsigned int val;
67a4f2b7
AO
3731 bfd_vma roff;
3732
67a4f2b7 3733 roff = rel->r_offset;
67a4f2b7 3734 val = bfd_get_8 (input_bfd, contents + roff - 1);
67a4f2b7
AO
3735
3736 /* Now modify the instruction as appropriate. */
3737 /* aoliva FIXME: remove the above and xor the byte
3738 below with 0x86. */
3739 bfd_put_8 (output_bfd, val ^ 0x86,
3740 contents + roff - 1);
eb4ff4d6 3741 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
67a4f2b7
AO
3742 contents + roff);
3743 continue;
3744 }
3745 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
3746 {
3747 /* GDesc -> LE transition.
3748 It's originally:
3749 call *(%eax)
3750 Turn it into:
142411ca 3751 xchg %ax,%ax */
67a4f2b7 3752
67a4f2b7 3753 bfd_vma roff;
6bbec505 3754
67a4f2b7 3755 roff = rel->r_offset;
10efb593 3756 bfd_put_8 (output_bfd, 0x66, contents + roff);
67a4f2b7
AO
3757 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3758 continue;
3759 }
37e55690 3760 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_IE)
13ae64f3 3761 {
142411ca 3762 unsigned int val;
13ae64f3
JJ
3763
3764 /* IE->LE transition:
37e55690
JJ
3765 Originally it can be one of:
3766 movl foo, %eax
3767 movl foo, %reg
3768 addl foo, %reg
3769 We change it into:
3770 movl $foo, %eax
3771 movl $foo, %reg
3772 addl $foo, %reg. */
37e55690 3773 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
37e55690
JJ
3774 if (val == 0xa1)
3775 {
3776 /* movl foo, %eax. */
55fd94b0
AM
3777 bfd_put_8 (output_bfd, 0xb8,
3778 contents + rel->r_offset - 1);
37e55690 3779 }
299bf759 3780 else
37e55690 3781 {
142411ca
L
3782 unsigned int type;
3783
55fd94b0
AM
3784 type = bfd_get_8 (input_bfd,
3785 contents + rel->r_offset - 2);
299bf759 3786 switch (type)
26e41594 3787 {
299bf759
L
3788 case 0x8b:
3789 /* movl */
299bf759
L
3790 bfd_put_8 (output_bfd, 0xc7,
3791 contents + rel->r_offset - 2);
3792 bfd_put_8 (output_bfd,
3793 0xc0 | ((val >> 3) & 7),
3794 contents + rel->r_offset - 1);
3795 break;
3796 case 0x03:
3797 /* addl */
299bf759
L
3798 bfd_put_8 (output_bfd, 0x81,
3799 contents + rel->r_offset - 2);
3800 bfd_put_8 (output_bfd,
3801 0xc0 | ((val >> 3) & 7),
3802 contents + rel->r_offset - 1);
3803 break;
3804 default:
3805 BFD_FAIL ();
3806 break;
26e41594 3807 }
37e55690 3808 }
eb4ff4d6 3809 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
37e55690
JJ
3810 contents + rel->r_offset);
3811 continue;
3812 }
3813 else
3814 {
3815 unsigned int val, type;
3816
3817 /* {IE_32,GOTIE}->LE transition:
3818 Originally it can be one of:
13ae64f3 3819 subl foo(%reg1), %reg2
13ae64f3 3820 movl foo(%reg1), %reg2
37e55690 3821 addl foo(%reg1), %reg2
13ae64f3
JJ
3822 We change it into:
3823 subl $foo, %reg2
37e55690
JJ
3824 movl $foo, %reg2 (6 byte form)
3825 addl $foo, %reg2. */
13ae64f3
JJ
3826 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
3827 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
13ae64f3
JJ
3828 if (type == 0x8b)
3829 {
3830 /* movl */
13ae64f3
JJ
3831 bfd_put_8 (output_bfd, 0xc7,
3832 contents + rel->r_offset - 2);
3833 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
3834 contents + rel->r_offset - 1);
3835 }
3836 else if (type == 0x2b)
3837 {
3838 /* subl */
13ae64f3
JJ
3839 bfd_put_8 (output_bfd, 0x81,
3840 contents + rel->r_offset - 2);
3841 bfd_put_8 (output_bfd, 0xe8 | ((val >> 3) & 7),
3842 contents + rel->r_offset - 1);
3843 }
37e55690
JJ
3844 else if (type == 0x03)
3845 {
3846 /* addl */
3847 bfd_put_8 (output_bfd, 0x81,
3848 contents + rel->r_offset - 2);
3849 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
3850 contents + rel->r_offset - 1);
3851 }
13ae64f3
JJ
3852 else
3853 BFD_FAIL ();
37e55690 3854 if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTIE)
eb4ff4d6 3855 bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
37e55690
JJ
3856 contents + rel->r_offset);
3857 else
eb4ff4d6 3858 bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
37e55690 3859 contents + rel->r_offset);
13ae64f3
JJ
3860 continue;
3861 }
3862 }
3863
6de2ae4a 3864 if (htab->elf.sgot == NULL)
13ae64f3
JJ
3865 abort ();
3866
3867 if (h != NULL)
67a4f2b7
AO
3868 {
3869 off = h->got.offset;
3870 offplt = elf_i386_hash_entry (h)->tlsdesc_got;
3871 }
13ae64f3
JJ
3872 else
3873 {
3874 if (local_got_offsets == NULL)
3875 abort ();
3876
3877 off = local_got_offsets[r_symndx];
67a4f2b7 3878 offplt = local_tlsdesc_gotents[r_symndx];
13ae64f3
JJ
3879 }
3880
3881 if ((off & 1) != 0)
3882 off &= ~1;
26e41594 3883 else
13ae64f3 3884 {
947216bf
AM
3885 Elf_Internal_Rela outrel;
3886 bfd_byte *loc;
91d6fa6a 3887 int dr_type;
67a4f2b7 3888 asection *sreloc;
13ae64f3 3889
6de2ae4a 3890 if (htab->elf.srelgot == NULL)
13ae64f3
JJ
3891 abort ();
3892
67a4f2b7
AO
3893 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3894
3895 if (GOT_TLS_GDESC_P (tls_type))
3896 {
3897 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
3898 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
6de2ae4a
L
3899 <= htab->elf.sgotplt->size);
3900 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
3901 + htab->elf.sgotplt->output_offset
67a4f2b7
AO
3902 + offplt
3903 + htab->sgotplt_jump_table_size);
6de2ae4a 3904 sreloc = htab->elf.srelplt;
67a4f2b7 3905 loc = sreloc->contents;
5ae0bfb6
RS
3906 loc += (htab->next_tls_desc_index++
3907 * sizeof (Elf32_External_Rel));
67a4f2b7
AO
3908 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
3909 <= sreloc->contents + sreloc->size);
3910 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3911 if (indx == 0)
3912 {
3913 BFD_ASSERT (! unresolved_reloc);
3914 bfd_put_32 (output_bfd,
eb4ff4d6 3915 relocation - elf_i386_dtpoff_base (info),
6de2ae4a 3916 htab->elf.sgotplt->contents + offplt
67a4f2b7
AO
3917 + htab->sgotplt_jump_table_size + 4);
3918 }
3919 else
3920 {
3921 bfd_put_32 (output_bfd, 0,
6de2ae4a 3922 htab->elf.sgotplt->contents + offplt
67a4f2b7
AO
3923 + htab->sgotplt_jump_table_size + 4);
3924 }
3925 }
3926
6de2ae4a 3927 sreloc = htab->elf.srelgot;
67a4f2b7 3928
6de2ae4a
L
3929 outrel.r_offset = (htab->elf.sgot->output_section->vma
3930 + htab->elf.sgot->output_offset + off);
13ae64f3 3931
67a4f2b7 3932 if (GOT_TLS_GD_P (tls_type))
13ae64f3 3933 dr_type = R_386_TLS_DTPMOD32;
67a4f2b7
AO
3934 else if (GOT_TLS_GDESC_P (tls_type))
3935 goto dr_done;
37e55690
JJ
3936 else if (tls_type == GOT_TLS_IE_POS)
3937 dr_type = R_386_TLS_TPOFF;
13ae64f3
JJ
3938 else
3939 dr_type = R_386_TLS_TPOFF32;
67a4f2b7 3940
37e55690 3941 if (dr_type == R_386_TLS_TPOFF && indx == 0)
eb4ff4d6
L
3942 bfd_put_32 (output_bfd,
3943 relocation - elf_i386_dtpoff_base (info),
6de2ae4a 3944 htab->elf.sgot->contents + off);
37e55690 3945 else if (dr_type == R_386_TLS_TPOFF32 && indx == 0)
23209a78 3946 bfd_put_32 (output_bfd,
eb4ff4d6 3947 elf_i386_dtpoff_base (info) - relocation,
6de2ae4a 3948 htab->elf.sgot->contents + off);
67a4f2b7 3949 else if (dr_type != R_386_TLS_DESC)
c366c25e 3950 bfd_put_32 (output_bfd, 0,
6de2ae4a 3951 htab->elf.sgot->contents + off);
13ae64f3 3952 outrel.r_info = ELF32_R_INFO (indx, dr_type);
67a4f2b7
AO
3953
3954 loc = sreloc->contents;
3955 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
3956 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
3957 <= sreloc->contents + sreloc->size);
13ae64f3
JJ
3958 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3959
67a4f2b7 3960 if (GOT_TLS_GD_P (tls_type))
13ae64f3
JJ
3961 {
3962 if (indx == 0)
3963 {
82e51918 3964 BFD_ASSERT (! unresolved_reloc);
13ae64f3 3965 bfd_put_32 (output_bfd,
eb4ff4d6 3966 relocation - elf_i386_dtpoff_base (info),
6de2ae4a 3967 htab->elf.sgot->contents + off + 4);
13ae64f3
JJ
3968 }
3969 else
3970 {
3971 bfd_put_32 (output_bfd, 0,
6de2ae4a 3972 htab->elf.sgot->contents + off + 4);
13ae64f3
JJ
3973 outrel.r_info = ELF32_R_INFO (indx,
3974 R_386_TLS_DTPOFF32);
3975 outrel.r_offset += 4;
67a4f2b7 3976 sreloc->reloc_count++;
947216bf 3977 loc += sizeof (Elf32_External_Rel);
67a4f2b7
AO
3978 BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
3979 <= sreloc->contents + sreloc->size);
947216bf 3980 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
13ae64f3
JJ
3981 }
3982 }
37e55690
JJ
3983 else if (tls_type == GOT_TLS_IE_BOTH)
3984 {
3985 bfd_put_32 (output_bfd,
eb4ff4d6
L
3986 (indx == 0
3987 ? relocation - elf_i386_dtpoff_base (info)
3988 : 0),
6de2ae4a 3989 htab->elf.sgot->contents + off + 4);
37e55690
JJ
3990 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
3991 outrel.r_offset += 4;
67a4f2b7 3992 sreloc->reloc_count++;
947216bf 3993 loc += sizeof (Elf32_External_Rel);
37e55690
JJ
3994 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3995 }
13ae64f3 3996
67a4f2b7 3997 dr_done:
13ae64f3
JJ
3998 if (h != NULL)
3999 h->got.offset |= 1;
4000 else
4001 local_got_offsets[r_symndx] |= 1;
4002 }
4003
67a4f2b7
AO
4004 if (off >= (bfd_vma) -2
4005 && ! GOT_TLS_GDESC_P (tls_type))
13ae64f3 4006 abort ();
67a4f2b7
AO
4007 if (r_type == R_386_TLS_GOTDESC
4008 || r_type == R_386_TLS_DESC_CALL)
4009 {
4010 relocation = htab->sgotplt_jump_table_size + offplt;
4011 unresolved_reloc = FALSE;
4012 }
4013 else if (r_type == ELF32_R_TYPE (rel->r_info))
13ae64f3 4014 {
6de2ae4a
L
4015 bfd_vma g_o_t = htab->elf.sgotplt->output_section->vma
4016 + htab->elf.sgotplt->output_offset;
4017 relocation = htab->elf.sgot->output_section->vma
4018 + htab->elf.sgot->output_offset + off - g_o_t;
37e55690
JJ
4019 if ((r_type == R_386_TLS_IE || r_type == R_386_TLS_GOTIE)
4020 && tls_type == GOT_TLS_IE_BOTH)
4021 relocation += 4;
4022 if (r_type == R_386_TLS_IE)
8c37241b 4023 relocation += g_o_t;
b34976b6 4024 unresolved_reloc = FALSE;
13ae64f3 4025 }
67a4f2b7 4026 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
13ae64f3
JJ
4027 {
4028 unsigned int val, type;
4029 bfd_vma roff;
4030
4031 /* GD->IE transition. */
13ae64f3 4032 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
13ae64f3
JJ
4033 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
4034 if (type == 0x04)
4035 {
4036 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
4037 Change it into:
4038 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
13ae64f3 4039 val >>= 3;
142411ca 4040 roff = rel->r_offset - 3;
13ae64f3
JJ
4041 }
4042 else
4043 {
4044 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
4045 Change it into:
4046 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
13ae64f3
JJ
4047 roff = rel->r_offset - 2;
4048 }
4049 memcpy (contents + roff,
4050 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
4051 contents[roff + 7] = 0x80 | (val & 7);
37e55690
JJ
4052 /* If foo is used only with foo@gotntpoff(%reg) and
4053 foo@indntpoff, but not with foo@gottpoff(%reg), change
4054 subl $foo@gottpoff(%reg), %eax
4055 into:
4056 addl $foo@gotntpoff(%reg), %eax. */
ebcfb3c0
JJ
4057 if (tls_type == GOT_TLS_IE_POS)
4058 contents[roff + 6] = 0x03;
8c37241b 4059 bfd_put_32 (output_bfd,
6de2ae4a
L
4060 htab->elf.sgot->output_section->vma
4061 + htab->elf.sgot->output_offset + off
4062 - htab->elf.sgotplt->output_section->vma
4063 - htab->elf.sgotplt->output_offset,
13ae64f3
JJ
4064 contents + roff + 8);
4065 /* Skip R_386_PLT32. */
4066 rel++;
4067 continue;
4068 }
67a4f2b7
AO
4069 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC)
4070 {
4071 /* GDesc -> IE transition.
4072 It's originally something like:
4073 leal x@tlsdesc(%ebx), %eax
4074
4075 Change it to:
142411ca 4076 movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
67a4f2b7
AO
4077 or:
4078 movl x@gottpoff(%ebx), %eax # before negl %eax
4079
4080 Registers other than %eax may be set up here. */
4081
67a4f2b7
AO
4082 bfd_vma roff;
4083
4084 /* First, make sure it's a leal adding ebx to a 32-bit
4085 offset into any register, although it's probably
4086 almost always going to be eax. */
4087 roff = rel->r_offset;
67a4f2b7
AO
4088
4089 /* Now modify the instruction as appropriate. */
4090 /* To turn a leal into a movl in the form we use it, it
4091 suffices to change the first byte from 0x8d to 0x8b.
4092 aoliva FIXME: should we decide to keep the leal, all
4093 we have to do is remove the statement below, and
4094 adjust the relaxation of R_386_TLS_DESC_CALL. */
4095 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
4096
4097 if (tls_type == GOT_TLS_IE_BOTH)
4098 off += 4;
4099
4100 bfd_put_32 (output_bfd,
6de2ae4a
L
4101 htab->elf.sgot->output_section->vma
4102 + htab->elf.sgot->output_offset + off
4103 - htab->elf.sgotplt->output_section->vma
4104 - htab->elf.sgotplt->output_offset,
67a4f2b7
AO
4105 contents + roff);
4106 continue;
4107 }
4108 else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL)
4109 {
4110 /* GDesc -> IE transition.
4111 It's originally:
4112 call *(%eax)
4113
4114 Change it to:
142411ca 4115 xchg %ax,%ax
67a4f2b7
AO
4116 or
4117 negl %eax
4118 depending on how we transformed the TLS_GOTDESC above.
4119 */
4120
67a4f2b7
AO
4121 bfd_vma roff;
4122
67a4f2b7 4123 roff = rel->r_offset;
67a4f2b7
AO
4124
4125 /* Now modify the instruction as appropriate. */
4126 if (tls_type != GOT_TLS_IE_NEG)
4127 {
10efb593
L
4128 /* xchg %ax,%ax */
4129 bfd_put_8 (output_bfd, 0x66, contents + roff);
67a4f2b7
AO
4130 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
4131 }
4132 else
4133 {
4134 /* negl %eax */
4135 bfd_put_8 (output_bfd, 0xf7, contents + roff);
4136 bfd_put_8 (output_bfd, 0xd8, contents + roff + 1);
4137 }
4138
4139 continue;
4140 }
4141 else
4142 BFD_ASSERT (FALSE);
13ae64f3
JJ
4143 break;
4144
4145 case R_386_TLS_LDM:
142411ca
L
4146 if (! elf_i386_tls_transition (info, input_bfd,
4147 input_section, contents,
4148 symtab_hdr, sym_hashes,
4149 &r_type, GOT_UNKNOWN, rel,
4c544807 4150 relend, h, r_symndx))
142411ca 4151 return FALSE;
13ae64f3 4152
142411ca
L
4153 if (r_type != R_386_TLS_LDM)
4154 {
13ae64f3 4155 /* LD->LE transition:
13ae64f3
JJ
4156 leal foo(%reg), %eax; call ___tls_get_addr.
4157 We change it into:
4158 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
142411ca 4159 BFD_ASSERT (r_type == R_386_TLS_LE_32);
13ae64f3
JJ
4160 memcpy (contents + rel->r_offset - 2,
4161 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
a3fadc9a 4162 /* Skip R_386_PC32/R_386_PLT32. */
13ae64f3
JJ
4163 rel++;
4164 continue;
4165 }
4166
6de2ae4a 4167 if (htab->elf.sgot == NULL)
13ae64f3
JJ
4168 abort ();
4169
4170 off = htab->tls_ldm_got.offset;
4171 if (off & 1)
4172 off &= ~1;
4173 else
4174 {
947216bf
AM
4175 Elf_Internal_Rela outrel;
4176 bfd_byte *loc;
13ae64f3 4177
6de2ae4a 4178 if (htab->elf.srelgot == NULL)
13ae64f3
JJ
4179 abort ();
4180
6de2ae4a
L
4181 outrel.r_offset = (htab->elf.sgot->output_section->vma
4182 + htab->elf.sgot->output_offset + off);
13ae64f3
JJ
4183
4184 bfd_put_32 (output_bfd, 0,
6de2ae4a 4185 htab->elf.sgot->contents + off);
13ae64f3 4186 bfd_put_32 (output_bfd, 0,
6de2ae4a 4187 htab->elf.sgot->contents + off + 4);
13ae64f3 4188 outrel.r_info = ELF32_R_INFO (0, R_386_TLS_DTPMOD32);
6de2ae4a
L
4189 loc = htab->elf.srelgot->contents;
4190 loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
13ae64f3
JJ
4191 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
4192 htab->tls_ldm_got.offset |= 1;
4193 }
6de2ae4a
L
4194 relocation = htab->elf.sgot->output_section->vma
4195 + htab->elf.sgot->output_offset + off
4196 - htab->elf.sgotplt->output_section->vma
4197 - htab->elf.sgotplt->output_offset;
b34976b6 4198 unresolved_reloc = FALSE;
13ae64f3
JJ
4199 break;
4200
4201 case R_386_TLS_LDO_32:
959b0961 4202 if (!info->executable || (input_section->flags & SEC_CODE) == 0)
eb4ff4d6 4203 relocation -= elf_i386_dtpoff_base (info);
13ae64f3
JJ
4204 else
4205 /* When converting LDO to LE, we must negate. */
eb4ff4d6 4206 relocation = -elf_i386_tpoff (info, relocation);
13ae64f3
JJ
4207 break;
4208
4209 case R_386_TLS_LE_32:
13ae64f3 4210 case R_386_TLS_LE:
1d85728f 4211 if (!info->executable)
37e55690 4212 {
947216bf 4213 Elf_Internal_Rela outrel;
37e55690 4214 asection *sreloc;
947216bf 4215 bfd_byte *loc;
37e55690
JJ
4216
4217 outrel.r_offset = rel->r_offset
4218 + input_section->output_section->vma
4219 + input_section->output_offset;
4220 if (h != NULL && h->dynindx != -1)
4221 indx = h->dynindx;
4222 else
4223 indx = 0;
4224 if (r_type == R_386_TLS_LE_32)
4225 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF32);
4226 else
4227 outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
4228 sreloc = elf_section_data (input_section)->sreloc;
4229 if (sreloc == NULL)
4230 abort ();
947216bf
AM
4231 loc = sreloc->contents;
4232 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
37e55690
JJ
4233 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
4234 if (indx)
4235 continue;
4236 else if (r_type == R_386_TLS_LE_32)
eb4ff4d6 4237 relocation = elf_i386_dtpoff_base (info) - relocation;
37e55690 4238 else
eb4ff4d6 4239 relocation -= elf_i386_dtpoff_base (info);
37e55690
JJ
4240 }
4241 else if (r_type == R_386_TLS_LE_32)
eb4ff4d6 4242 relocation = elf_i386_tpoff (info, relocation);
37e55690 4243 else
eb4ff4d6 4244 relocation = -elf_i386_tpoff (info, relocation);
13ae64f3
JJ
4245 break;
4246
252b5132
RH
4247 default:
4248 break;
4249 }
4250
239e1f3a
AM
4251 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4252 because such sections are not SEC_ALLOC and thus ld.so will
4253 not process them. */
8c694914 4254 if (unresolved_reloc
239e1f3a 4255 && !((input_section->flags & SEC_DEBUGGING) != 0
1d5316ab
AM
4256 && h->def_dynamic)
4257 && _bfd_elf_section_offset (output_bfd, info, input_section,
4258 rel->r_offset) != (bfd_vma) -1)
6a30718d
JJ
4259 {
4260 (*_bfd_error_handler)
843fe662 4261 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
d003868e
AM
4262 input_bfd,
4263 input_section,
6a30718d 4264 (long) rel->r_offset,
843fe662 4265 howto->name,
6a30718d 4266 h->root.root.string);
b34976b6 4267 return FALSE;
6a30718d 4268 }
83be169b 4269
cbe950e9 4270do_relocation:
252b5132
RH
4271 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4272 contents, rel->r_offset,
55fd94b0 4273 relocation, 0);
252b5132 4274
62d78908 4275check_relocation_error:
cf5c0c5b 4276 if (r != bfd_reloc_ok)
252b5132 4277 {
cf5c0c5b 4278 const char *name;
ffb2e45b 4279
cf5c0c5b
AM
4280 if (h != NULL)
4281 name = h->root.root.string;
4282 else
4283 {
4284 name = bfd_elf_string_from_elf_section (input_bfd,
4285 symtab_hdr->sh_link,
4286 sym->st_name);
4287 if (name == NULL)
b34976b6 4288 return FALSE;
cf5c0c5b
AM
4289 if (*name == '\0')
4290 name = bfd_section_name (input_bfd, sec);
4291 }
ffb2e45b 4292
cf5c0c5b
AM
4293 if (r == bfd_reloc_overflow)
4294 {
cf5c0c5b 4295 if (! ((*info->callbacks->reloc_overflow)
dfeffb9f
L
4296 (info, (h ? &h->root : NULL), name, howto->name,
4297 (bfd_vma) 0, input_bfd, input_section,
4298 rel->r_offset)))
b34976b6 4299 return FALSE;
cf5c0c5b
AM
4300 }
4301 else
4302 {
4303 (*_bfd_error_handler)
d003868e
AM
4304 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4305 input_bfd, input_section,
cf5c0c5b 4306 (long) rel->r_offset, name, (int) r);
b34976b6 4307 return FALSE;
cf5c0c5b 4308 }
252b5132
RH
4309 }
4310 }
4311
b34976b6 4312 return TRUE;
252b5132
RH
4313}
4314
4315/* Finish up dynamic symbol handling. We set the contents of various
4316 dynamic sections here. */
4317
b34976b6 4318static bfd_boolean
55fd94b0
AM
4319elf_i386_finish_dynamic_symbol (bfd *output_bfd,
4320 struct bfd_link_info *info,
4321 struct elf_link_hash_entry *h,
4322 Elf_Internal_Sym *sym)
252b5132 4323{
6725bdbf 4324 struct elf_i386_link_hash_table *htab;
25e762b9
RM
4325 unsigned plt_entry_size;
4326 const struct elf_i386_backend_data *abed;
252b5132 4327
6725bdbf 4328 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
4329 if (htab == NULL)
4330 return FALSE;
252b5132 4331
25e762b9
RM
4332 abed = get_elf_i386_backend_data (output_bfd);
4333 plt_entry_size = GET_PLT_ENTRY_SIZE (output_bfd);
4334
252b5132
RH
4335 if (h->plt.offset != (bfd_vma) -1)
4336 {
252b5132
RH
4337 bfd_vma plt_index;
4338 bfd_vma got_offset;
947216bf
AM
4339 Elf_Internal_Rela rel;
4340 bfd_byte *loc;
cbe950e9
L
4341 asection *plt, *gotplt, *relplt;
4342
4343 /* When building a static executable, use .iplt, .igot.plt and
4344 .rel.iplt sections for STT_GNU_IFUNC symbols. */
6de2ae4a 4345 if (htab->elf.splt != NULL)
cbe950e9 4346 {
6de2ae4a
L
4347 plt = htab->elf.splt;
4348 gotplt = htab->elf.sgotplt;
4349 relplt = htab->elf.srelplt;
cbe950e9
L
4350 }
4351 else
4352 {
6de2ae4a
L
4353 plt = htab->elf.iplt;
4354 gotplt = htab->elf.igotplt;
4355 relplt = htab->elf.irelplt;
cbe950e9 4356 }
252b5132
RH
4357
4358 /* This symbol has an entry in the procedure linkage table. Set
4359 it up. */
4360
cbe950e9
L
4361 if ((h->dynindx == -1
4362 && !((h->forced_local || info->executable)
4363 && h->def_regular
4364 && h->type == STT_GNU_IFUNC))
4365 || plt == NULL
4366 || gotplt == NULL
4367 || relplt == NULL)
f6df62c8 4368 return FALSE;
252b5132
RH
4369
4370 /* Get the index in the procedure linkage table which
4371 corresponds to this symbol. This is the index of this symbol
4372 in all the symbols for which we are making plt entries. The
cbe950e9 4373 first entry in the procedure linkage table is reserved.
252b5132 4374
cbe950e9 4375 Get the offset into the .got table of the entry that
252b5132 4376 corresponds to this function. Each .got entry is 4 bytes.
cbe950e9 4377 The first three are reserved.
6bbec505 4378
cbe950e9
L
4379 For static executables, we don't reserve anything. */
4380
6de2ae4a 4381 if (plt == htab->elf.splt)
cbe950e9 4382 {
e1f98742
L
4383 got_offset = h->plt.offset / plt_entry_size - 1;
4384 got_offset = (got_offset + 3) * 4;
cbe950e9
L
4385 }
4386 else
4387 {
e1f98742
L
4388 got_offset = h->plt.offset / plt_entry_size;
4389 got_offset = got_offset * 4;
cbe950e9 4390 }
252b5132
RH
4391
4392 /* Fill in the entry in the procedure linkage table. */
4393 if (! info->shared)
4394 {
25e762b9
RM
4395 memcpy (plt->contents + h->plt.offset, abed->plt->plt_entry,
4396 abed->plt->plt_entry_size);
252b5132 4397 bfd_put_32 (output_bfd,
cbe950e9
L
4398 (gotplt->output_section->vma
4399 + gotplt->output_offset
252b5132 4400 + got_offset),
25e762b9
RM
4401 plt->contents + h->plt.offset
4402 + abed->plt->plt_got_offset);
eac338cf 4403
25e762b9 4404 if (abed->is_vxworks)
eac338cf
PB
4405 {
4406 int s, k, reloc_index;
4407
4408 /* Create the R_386_32 relocation referencing the GOT
4409 for this PLT entry. */
4410
4411 /* S: Current slot number (zero-based). */
25e762b9
RM
4412 s = ((h->plt.offset - abed->plt->plt_entry_size)
4413 / abed->plt->plt_entry_size);
eac338cf
PB
4414 /* K: Number of relocations for PLTResolve. */
4415 if (info->shared)
4416 k = PLTRESOLVE_RELOCS_SHLIB;
4417 else
4418 k = PLTRESOLVE_RELOCS;
4419 /* Skip the PLTresolve relocations, and the relocations for
4420 the other PLT slots. */
4421 reloc_index = k + s * PLT_NON_JUMP_SLOT_RELOCS;
4422 loc = (htab->srelplt2->contents + reloc_index
4423 * sizeof (Elf32_External_Rel));
4424
6de2ae4a
L
4425 rel.r_offset = (htab->elf.splt->output_section->vma
4426 + htab->elf.splt->output_offset
eac338cf 4427 + h->plt.offset + 2),
7325306f 4428 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
eac338cf
PB
4429 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4430
4431 /* Create the R_386_32 relocation referencing the beginning of
4432 the PLT for this GOT entry. */
6de2ae4a
L
4433 rel.r_offset = (htab->elf.sgotplt->output_section->vma
4434 + htab->elf.sgotplt->output_offset
eac338cf 4435 + got_offset);
7325306f 4436 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32);
eac338cf
PB
4437 bfd_elf32_swap_reloc_out (output_bfd, &rel,
4438 loc + sizeof (Elf32_External_Rel));
4439 }
252b5132
RH
4440 }
4441 else
4442 {
25e762b9
RM
4443 memcpy (plt->contents + h->plt.offset, abed->plt->pic_plt_entry,
4444 abed->plt->plt_entry_size);
252b5132 4445 bfd_put_32 (output_bfd, got_offset,
25e762b9
RM
4446 plt->contents + h->plt.offset
4447 + abed->plt->plt_got_offset);
252b5132
RH
4448 }
4449
252b5132
RH
4450 /* Fill in the entry in the global offset table. */
4451 bfd_put_32 (output_bfd,
cbe950e9
L
4452 (plt->output_section->vma
4453 + plt->output_offset
252b5132 4454 + h->plt.offset
25e762b9 4455 + abed->plt->plt_lazy_offset),
cbe950e9 4456 gotplt->contents + got_offset);
252b5132
RH
4457
4458 /* Fill in the entry in the .rel.plt section. */
cbe950e9
L
4459 rel.r_offset = (gotplt->output_section->vma
4460 + gotplt->output_offset
252b5132 4461 + got_offset);
cbe950e9
L
4462 if (h->dynindx == -1
4463 || ((info->executable
4464 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4465 && h->def_regular
4466 && h->type == STT_GNU_IFUNC))
4467 {
4468 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4469 R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
4470 in the .got.plt section. */
4471 bfd_put_32 (output_bfd,
23209a78 4472 (h->root.u.def.value
cbe950e9
L
4473 + h->root.u.def.section->output_section->vma
4474 + h->root.u.def.section->output_offset),
4475 gotplt->contents + got_offset);
4476 rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
e1f98742
L
4477 /* R_386_IRELATIVE comes last. */
4478 plt_index = htab->next_irelative_index--;
cbe950e9
L
4479 }
4480 else
e1f98742
L
4481 {
4482 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
4483 plt_index = htab->next_jump_slot_index++;
4484 }
cbe950e9 4485 loc = relplt->contents + plt_index * sizeof (Elf32_External_Rel);
0ac8d2ca 4486 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
252b5132 4487
e1f98742
L
4488 /* Don't fill PLT entry for static executables. */
4489 if (plt == htab->elf.splt)
4490 {
4491 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rel),
4492 plt->contents + h->plt.offset
4493 + abed->plt->plt_reloc_offset);
4494 bfd_put_32 (output_bfd, - (h->plt.offset
4495 + abed->plt->plt_plt_offset + 4),
4496 plt->contents + h->plt.offset
4497 + abed->plt->plt_plt_offset);
4498 }
4499
f5385ebf 4500 if (!h->def_regular)
252b5132
RH
4501 {
4502 /* Mark the symbol as undefined, rather than as defined in
c6585bbb
JJ
4503 the .plt section. Leave the value if there were any
4504 relocations where pointer equality matters (this is a clue
51b64d56
AM
4505 for the dynamic linker, to make function pointer
4506 comparisons work between an application and shared
c6585bbb
JJ
4507 library), otherwise set it to zero. If a function is only
4508 called from a binary, there is no need to slow down
4509 shared libraries because of that. */
252b5132 4510 sym->st_shndx = SHN_UNDEF;
f5385ebf 4511 if (!h->pointer_equality_needed)
c6585bbb 4512 sym->st_value = 0;
252b5132
RH
4513 }
4514 }
4515
13ae64f3 4516 if (h->got.offset != (bfd_vma) -1
67a4f2b7 4517 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h)->tls_type)
37e55690 4518 && (elf_i386_hash_entry(h)->tls_type & GOT_TLS_IE) == 0)
252b5132 4519 {
947216bf
AM
4520 Elf_Internal_Rela rel;
4521 bfd_byte *loc;
252b5132
RH
4522
4523 /* This symbol has an entry in the global offset table. Set it
4524 up. */
4525
6de2ae4a 4526 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
ffb2e45b 4527 abort ();
252b5132 4528
6de2ae4a
L
4529 rel.r_offset = (htab->elf.sgot->output_section->vma
4530 + htab->elf.sgot->output_offset
dc810e39 4531 + (h->got.offset & ~(bfd_vma) 1));
252b5132 4532
dd5724d5
AM
4533 /* If this is a static link, or it is a -Bsymbolic link and the
4534 symbol is defined locally or was forced to be local because
4535 of a version file, we just want to emit a RELATIVE reloc.
252b5132
RH
4536 The entry in the global offset table will already have been
4537 initialized in the relocate_section function. */
710ab287 4538 if (h->def_regular
0018b0a3
L
4539 && h->type == STT_GNU_IFUNC)
4540 {
710ab287
L
4541 if (info->shared)
4542 {
4543 /* Generate R_386_GLOB_DAT. */
4544 goto do_glob_dat;
4545 }
4546 else
4547 {
cd2b2c10
L
4548 asection *plt;
4549
710ab287
L
4550 if (!h->pointer_equality_needed)
4551 abort ();
4552
4553 /* For non-shared object, we can't use .got.plt, which
4554 contains the real function addres if we need pointer
4555 equality. We load the GOT entry with the PLT entry. */
cd2b2c10 4556 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
710ab287
L
4557 bfd_put_32 (output_bfd,
4558 (plt->output_section->vma
4559 + plt->output_offset + h->plt.offset),
6de2ae4a 4560 htab->elf.sgot->contents + h->got.offset);
710ab287
L
4561 return TRUE;
4562 }
0018b0a3
L
4563 }
4564 else if (info->shared
4565 && SYMBOL_REFERENCES_LOCAL (info, h))
dd5724d5 4566 {
6725bdbf 4567 BFD_ASSERT((h->got.offset & 1) != 0);
dd5724d5
AM
4568 rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
4569 }
252b5132
RH
4570 else
4571 {
dd5724d5 4572 BFD_ASSERT((h->got.offset & 1) == 0);
710ab287 4573do_glob_dat:
6725bdbf 4574 bfd_put_32 (output_bfd, (bfd_vma) 0,
6de2ae4a 4575 htab->elf.sgot->contents + h->got.offset);
252b5132
RH
4576 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
4577 }
4578
6de2ae4a
L
4579 loc = htab->elf.srelgot->contents;
4580 loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
0ac8d2ca 4581 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
252b5132
RH
4582 }
4583
f5385ebf 4584 if (h->needs_copy)
252b5132 4585 {
947216bf
AM
4586 Elf_Internal_Rela rel;
4587 bfd_byte *loc;
252b5132
RH
4588
4589 /* This symbol needs a copy reloc. Set it up. */
4590
ffb2e45b
AM
4591 if (h->dynindx == -1
4592 || (h->root.type != bfd_link_hash_defined
4593 && h->root.type != bfd_link_hash_defweak)
4594 || htab->srelbss == NULL)
4595 abort ();
252b5132
RH
4596
4597 rel.r_offset = (h->root.u.def.value
4598 + h->root.u.def.section->output_section->vma
4599 + h->root.u.def.section->output_offset);
4600 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
947216bf
AM
4601 loc = htab->srelbss->contents;
4602 loc += htab->srelbss->reloc_count++ * sizeof (Elf32_External_Rel);
0ac8d2ca 4603 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
252b5132
RH
4604 }
4605
b34976b6 4606 return TRUE;
252b5132
RH
4607}
4608
c25bc9fc
L
4609/* Finish up local dynamic symbol handling. We set the contents of
4610 various dynamic sections here. */
4611
4612static bfd_boolean
4613elf_i386_finish_local_dynamic_symbol (void **slot, void *inf)
4614{
4615 struct elf_link_hash_entry *h
4616 = (struct elf_link_hash_entry *) *slot;
4617 struct bfd_link_info *info
23209a78 4618 = (struct bfd_link_info *) inf;
c25bc9fc
L
4619
4620 return elf_i386_finish_dynamic_symbol (info->output_bfd, info,
4621 h, NULL);
4622}
4623
38701953
AM
4624/* Used to decide how to sort relocs in an optimal manner for the
4625 dynamic linker, before writing them out. */
4626
4627static enum elf_reloc_type_class
55fd94b0 4628elf_i386_reloc_type_class (const Elf_Internal_Rela *rela)
38701953 4629{
55fd94b0 4630 switch (ELF32_R_TYPE (rela->r_info))
38701953
AM
4631 {
4632 case R_386_RELATIVE:
4633 return reloc_class_relative;
4634 case R_386_JUMP_SLOT:
4635 return reloc_class_plt;
4636 case R_386_COPY:
4637 return reloc_class_copy;
4638 default:
4639 return reloc_class_normal;
4640 }
4641}
4642
252b5132
RH
4643/* Finish up the dynamic sections. */
4644
b34976b6 4645static bfd_boolean
55fd94b0
AM
4646elf_i386_finish_dynamic_sections (bfd *output_bfd,
4647 struct bfd_link_info *info)
252b5132 4648{
6725bdbf 4649 struct elf_i386_link_hash_table *htab;
252b5132 4650 bfd *dynobj;
252b5132 4651 asection *sdyn;
25e762b9 4652 const struct elf_i386_backend_data *abed;
252b5132 4653
6725bdbf 4654 htab = elf_i386_hash_table (info);
4dfe6ac6
NC
4655 if (htab == NULL)
4656 return FALSE;
4657
ebe50bae 4658 dynobj = htab->elf.dynobj;
252b5132 4659 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
25e762b9 4660 abed = get_elf_i386_backend_data (output_bfd);
252b5132 4661
ebe50bae 4662 if (htab->elf.dynamic_sections_created)
252b5132 4663 {
252b5132
RH
4664 Elf32_External_Dyn *dyncon, *dynconend;
4665
6de2ae4a 4666 if (sdyn == NULL || htab->elf.sgot == NULL)
ffb2e45b 4667 abort ();
252b5132
RH
4668
4669 dyncon = (Elf32_External_Dyn *) sdyn->contents;
eea6121a 4670 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
252b5132
RH
4671 for (; dyncon < dynconend; dyncon++)
4672 {
4673 Elf_Internal_Dyn dyn;
51b64d56 4674 asection *s;
252b5132
RH
4675
4676 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4677
4678 switch (dyn.d_tag)
4679 {
4680 default:
25e762b9
RM
4681 if (abed->is_vxworks
4682 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
7a2b07ff 4683 break;
0ac8d2ca 4684 continue;
252b5132
RH
4685
4686 case DT_PLTGOT:
6de2ae4a 4687 s = htab->elf.sgotplt;
8c37241b 4688 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6725bdbf
AM
4689 break;
4690
252b5132 4691 case DT_JMPREL:
6de2ae4a 4692 s = htab->elf.srelplt;
6348e046 4693 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
252b5132
RH
4694 break;
4695
4696 case DT_PLTRELSZ:
6de2ae4a 4697 s = htab->elf.srelplt;
eea6121a 4698 dyn.d_un.d_val = s->size;
252b5132
RH
4699 break;
4700
4701 case DT_RELSZ:
4702 /* My reading of the SVR4 ABI indicates that the
4703 procedure linkage table relocs (DT_JMPREL) should be
4704 included in the overall relocs (DT_REL). This is
4705 what Solaris does. However, UnixWare can not handle
4706 that case. Therefore, we override the DT_RELSZ entry
6348e046 4707 here to make it not include the JMPREL relocs. */
6de2ae4a 4708 s = htab->elf.srelplt;
6348e046
AM
4709 if (s == NULL)
4710 continue;
eea6121a 4711 dyn.d_un.d_val -= s->size;
6348e046
AM
4712 break;
4713
4714 case DT_REL:
4715 /* We may not be using the standard ELF linker script.
4716 If .rel.plt is the first .rel section, we adjust
4717 DT_REL to not include it. */
6de2ae4a 4718 s = htab->elf.srelplt;
6348e046
AM
4719 if (s == NULL)
4720 continue;
4721 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
4722 continue;
eea6121a 4723 dyn.d_un.d_ptr += s->size;
252b5132
RH
4724 break;
4725 }
0ac8d2ca
AM
4726
4727 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
252b5132
RH
4728 }
4729
4730 /* Fill in the first entry in the procedure linkage table. */
6de2ae4a 4731 if (htab->elf.splt && htab->elf.splt->size > 0)
252b5132
RH
4732 {
4733 if (info->shared)
eac338cf 4734 {
25e762b9
RM
4735 memcpy (htab->elf.splt->contents, abed->plt->pic_plt0_entry,
4736 abed->plt->plt0_entry_size);
4737 memset (htab->elf.splt->contents + abed->plt->plt0_entry_size,
4738 abed->plt0_pad_byte,
4739 abed->plt->plt_entry_size - abed->plt->plt0_entry_size);
eac338cf 4740 }
252b5132
RH
4741 else
4742 {
25e762b9
RM
4743 memcpy (htab->elf.splt->contents, abed->plt->plt0_entry,
4744 abed->plt->plt0_entry_size);
4745 memset (htab->elf.splt->contents + abed->plt->plt0_entry_size,
4746 abed->plt0_pad_byte,
4747 abed->plt->plt_entry_size - abed->plt->plt0_entry_size);
252b5132 4748 bfd_put_32 (output_bfd,
6de2ae4a
L
4749 (htab->elf.sgotplt->output_section->vma
4750 + htab->elf.sgotplt->output_offset
6725bdbf 4751 + 4),
25e762b9
RM
4752 htab->elf.splt->contents
4753 + abed->plt->plt0_got1_offset);
252b5132 4754 bfd_put_32 (output_bfd,
6de2ae4a
L
4755 (htab->elf.sgotplt->output_section->vma
4756 + htab->elf.sgotplt->output_offset
6725bdbf 4757 + 8),
25e762b9
RM
4758 htab->elf.splt->contents
4759 + abed->plt->plt0_got2_offset);
eac338cf 4760
25e762b9 4761 if (abed->is_vxworks)
eac338cf
PB
4762 {
4763 Elf_Internal_Rela rel;
7325306f 4764
eac338cf
PB
4765 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
4766 On IA32 we use REL relocations so the addend goes in
4767 the PLT directly. */
6de2ae4a
L
4768 rel.r_offset = (htab->elf.splt->output_section->vma
4769 + htab->elf.splt->output_offset
25e762b9 4770 + abed->plt->plt0_got1_offset);
7325306f 4771 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
eac338cf
PB
4772 bfd_elf32_swap_reloc_out (output_bfd, &rel,
4773 htab->srelplt2->contents);
4774 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
6de2ae4a
L
4775 rel.r_offset = (htab->elf.splt->output_section->vma
4776 + htab->elf.splt->output_offset
25e762b9 4777 + abed->plt->plt0_got2_offset);
7325306f 4778 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
eac338cf
PB
4779 bfd_elf32_swap_reloc_out (output_bfd, &rel,
4780 htab->srelplt2->contents +
4781 sizeof (Elf32_External_Rel));
4782 }
252b5132
RH
4783 }
4784
4785 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4786 really seem like the right value. */
6de2ae4a 4787 elf_section_data (htab->elf.splt->output_section)
6725bdbf 4788 ->this_hdr.sh_entsize = 4;
eac338cf
PB
4789
4790 /* Correct the .rel.plt.unloaded relocations. */
25e762b9 4791 if (abed->is_vxworks && !info->shared)
eac338cf 4792 {
25e762b9
RM
4793 int num_plts = (htab->elf.splt->size
4794 / abed->plt->plt_entry_size) - 1;
4c9b0de6 4795 unsigned char *p;
eac338cf
PB
4796
4797 p = htab->srelplt2->contents;
4798 if (info->shared)
4799 p += PLTRESOLVE_RELOCS_SHLIB * sizeof (Elf32_External_Rel);
4800 else
4801 p += PLTRESOLVE_RELOCS * sizeof (Elf32_External_Rel);
4802
4803 for (; num_plts; num_plts--)
4804 {
4805 Elf_Internal_Rela rel;
4806 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
7325306f 4807 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
eac338cf
PB
4808 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
4809 p += sizeof (Elf32_External_Rel);
4810
4811 bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
7325306f 4812 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32);
eac338cf
PB
4813 bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
4814 p += sizeof (Elf32_External_Rel);
4815 }
4816 }
252b5132
RH
4817 }
4818 }
4819
6de2ae4a 4820 if (htab->elf.sgotplt)
252b5132 4821 {
56d4289c
L
4822 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
4823 {
4824 (*_bfd_error_handler)
4825 (_("discarded output section: `%A'"), htab->elf.sgotplt);
4826 return FALSE;
4827 }
4828
12d0ee4a 4829 /* Fill in the first three entries in the global offset table. */
6de2ae4a 4830 if (htab->elf.sgotplt->size > 0)
12d0ee4a
AM
4831 {
4832 bfd_put_32 (output_bfd,
55fd94b0 4833 (sdyn == NULL ? 0
12d0ee4a 4834 : sdyn->output_section->vma + sdyn->output_offset),
6de2ae4a
L
4835 htab->elf.sgotplt->contents);
4836 bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 4);
4837 bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 8);
12d0ee4a 4838 }
252b5132 4839
6de2ae4a 4840 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize = 4;
12d0ee4a 4841 }
8c37241b 4842
e41b3a13
JJ
4843 /* Adjust .eh_frame for .plt section. */
4844 if (htab->plt_eh_frame != NULL)
4845 {
4846 if (htab->elf.splt != NULL
4847 && htab->elf.splt->size != 0
4848 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
4849 && htab->elf.splt->output_section != NULL
4850 && htab->plt_eh_frame->output_section != NULL)
4851 {
4852 bfd_vma plt_start = htab->elf.splt->output_section->vma;
4853 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
4854 + htab->plt_eh_frame->output_offset
4855 + PLT_FDE_START_OFFSET;
4856 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
4857 htab->plt_eh_frame->contents
4858 + PLT_FDE_START_OFFSET);
4859 }
4860 if (htab->plt_eh_frame->sec_info_type
dbaa2011 4861 == SEC_INFO_TYPE_EH_FRAME)
e41b3a13
JJ
4862 {
4863 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
4864 htab->plt_eh_frame,
4865 htab->plt_eh_frame->contents))
4866 return FALSE;
4867 }
4868 }
4869
6de2ae4a
L
4870 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4871 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4;
8c37241b 4872
c25bc9fc
L
4873 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4874 htab_traverse (htab->loc_hash_table,
4875 elf_i386_finish_local_dynamic_symbol,
4876 info);
4877
b34976b6 4878 return TRUE;
252b5132
RH
4879}
4880
4c45e5c9
JJ
4881/* Return address for Ith PLT stub in section PLT, for relocation REL
4882 or (bfd_vma) -1 if it should not be included. */
4883
4884static bfd_vma
4885elf_i386_plt_sym_val (bfd_vma i, const asection *plt,
4886 const arelent *rel ATTRIBUTE_UNUSED)
4887{
25e762b9 4888 return plt->vma + (i + 1) * GET_PLT_ENTRY_SIZE (plt->owner);
4c45e5c9
JJ
4889}
4890
fdc90cb4
JJ
4891/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4892
4893static bfd_boolean
4894elf_i386_hash_symbol (struct elf_link_hash_entry *h)
4895{
4896 if (h->plt.offset != (bfd_vma) -1
4897 && !h->def_regular
4898 && !h->pointer_equality_needed)
4899 return FALSE;
4900
4901 return _bfd_elf_hash_symbol (h);
4902}
4c45e5c9 4903
d8045f23
NC
4904/* Hook called by the linker routine which adds symbols from an object
4905 file. */
4906
4907static bfd_boolean
c16153ae 4908elf_i386_add_symbol_hook (bfd * abfd,
d8045f23
NC
4909 struct bfd_link_info * info ATTRIBUTE_UNUSED,
4910 Elf_Internal_Sym * sym,
4911 const char ** namep ATTRIBUTE_UNUSED,
4912 flagword * flagsp ATTRIBUTE_UNUSED,
4913 asection ** secp ATTRIBUTE_UNUSED,
4914 bfd_vma * valp ATTRIBUTE_UNUSED)
4915{
c16153ae 4916 if ((abfd->flags & DYNAMIC) == 0
f64b2e8d
NC
4917 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
4918 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
4919 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
d8045f23
NC
4920
4921 return TRUE;
4922}
4923
252b5132
RH
4924#define TARGET_LITTLE_SYM bfd_elf32_i386_vec
4925#define TARGET_LITTLE_NAME "elf32-i386"
4926#define ELF_ARCH bfd_arch_i386
ae95ffa6 4927#define ELF_TARGET_ID I386_ELF_DATA
252b5132
RH
4928#define ELF_MACHINE_CODE EM_386
4929#define ELF_MAXPAGESIZE 0x1000
252b5132
RH
4930
4931#define elf_backend_can_gc_sections 1
51b64d56 4932#define elf_backend_can_refcount 1
252b5132
RH
4933#define elf_backend_want_got_plt 1
4934#define elf_backend_plt_readonly 1
4935#define elf_backend_want_plt_sym 0
4936#define elf_backend_got_header_size 12
e41b3a13 4937#define elf_backend_plt_alignment 4
252b5132 4938
8c29f035
AM
4939/* Support RELA for objdump of prelink objects. */
4940#define elf_info_to_howto elf_i386_info_to_howto_rel
dd5724d5
AM
4941#define elf_info_to_howto_rel elf_i386_info_to_howto_rel
4942
13ae64f3 4943#define bfd_elf32_mkobject elf_i386_mkobject
13ae64f3 4944
dd5724d5
AM
4945#define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
4946#define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
c25bc9fc 4947#define bfd_elf32_bfd_link_hash_table_free elf_i386_link_hash_table_free
dd5724d5 4948#define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
13285a1b 4949#define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
dd5724d5
AM
4950
4951#define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
13285a1b 4952#define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
dd5724d5 4953#define elf_backend_check_relocs elf_i386_check_relocs
0ac8d2ca 4954#define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
6725bdbf 4955#define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
0ac8d2ca 4956#define elf_backend_fake_sections elf_i386_fake_sections
dd5724d5
AM
4957#define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
4958#define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
4959#define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
4960#define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
c5fccbec
DJ
4961#define elf_backend_grok_prstatus elf_i386_grok_prstatus
4962#define elf_backend_grok_psinfo elf_i386_grok_psinfo
db6751f2 4963#define elf_backend_reloc_type_class elf_i386_reloc_type_class
0ac8d2ca
AM
4964#define elf_backend_relocate_section elf_i386_relocate_section
4965#define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
67a4f2b7 4966#define elf_backend_always_size_sections elf_i386_always_size_sections
74541ad4
AM
4967#define elf_backend_omit_section_dynsym \
4968 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4c45e5c9 4969#define elf_backend_plt_sym_val elf_i386_plt_sym_val
fdc90cb4 4970#define elf_backend_hash_symbol elf_i386_hash_symbol
d8045f23
NC
4971#define elf_backend_add_symbol_hook elf_i386_add_symbol_hook
4972#undef elf_backend_post_process_headers
4973#define elf_backend_post_process_headers _bfd_elf_set_osabi
dd5724d5 4974
252b5132 4975#include "elf32-target.h"
2bc3c89a
AM
4976
4977/* FreeBSD support. */
4978
4979#undef TARGET_LITTLE_SYM
4980#define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec
4981#undef TARGET_LITTLE_NAME
4982#define TARGET_LITTLE_NAME "elf32-i386-freebsd"
d1036acb
L
4983#undef ELF_OSABI
4984#define ELF_OSABI ELFOSABI_FREEBSD
2bc3c89a
AM
4985
4986/* The kernel recognizes executables as valid only if they carry a
4987 "FreeBSD" label in the ELF header. So we put this label on all
4988 executables and (for simplicity) also all other object files. */
4989
2bc3c89a 4990static void
d8045f23 4991elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info)
2bc3c89a 4992{
d8045f23 4993 _bfd_elf_set_osabi (abfd, info);
2bc3c89a 4994
2bc3c89a
AM
4995#ifdef OLD_FREEBSD_ABI_LABEL
4996 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
4997 memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
caf47ea6 4998#endif
2bc3c89a
AM
4999}
5000
5001#undef elf_backend_post_process_headers
d8045f23 5002#define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
571fe01f
NC
5003#undef elf32_bed
5004#define elf32_bed elf32_i386_fbsd_bed
2bc3c89a 5005
d8045f23
NC
5006#undef elf_backend_add_symbol_hook
5007
2bc3c89a 5008#include "elf32-target.h"
eac338cf 5009
a6cc6b3b
RO
5010/* Solaris 2. */
5011
5012#undef TARGET_LITTLE_SYM
5013#define TARGET_LITTLE_SYM bfd_elf32_i386_sol2_vec
5014#undef TARGET_LITTLE_NAME
5015#define TARGET_LITTLE_NAME "elf32-i386-sol2"
5016
5017/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5018 objects won't be recognized. */
5019#undef ELF_OSABI
5020
5021#undef elf32_bed
5022#define elf32_bed elf32_i386_sol2_bed
5023
7dc98aea
RO
5024/* The 32-bit static TLS arena size is rounded to the nearest 8-byte
5025 boundary. */
5026#undef elf_backend_static_tls_alignment
5027#define elf_backend_static_tls_alignment 8
5028
a6cc6b3b
RO
5029/* The Solaris 2 ABI requires a plt symbol on all platforms.
5030
5031 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5032 File, p.63. */
5033#undef elf_backend_want_plt_sym
5034#define elf_backend_want_plt_sym 1
5035
5036#include "elf32-target.h"
5037
a27e4371
RM
5038/* Native Client support. */
5039
5040#undef TARGET_LITTLE_SYM
5041#define TARGET_LITTLE_SYM bfd_elf32_i386_nacl_vec
5042#undef TARGET_LITTLE_NAME
5043#define TARGET_LITTLE_NAME "elf32-i386-nacl"
5044#undef elf32_bed
5045#define elf32_bed elf32_i386_nacl_bed
5046
5047#undef ELF_MAXPAGESIZE
5048#define ELF_MAXPAGESIZE 0x10000
5049
5050/* Restore defaults. */
5051#undef ELF_OSABI
5052#undef elf_backend_want_plt_sym
5053#define elf_backend_want_plt_sym 0
5054#undef elf_backend_post_process_headers
5055#define elf_backend_post_process_headers _bfd_elf_set_osabi
5056#undef elf_backend_static_tls_alignment
5057
5058/* NaCl uses substantially different PLT entries for the same effects. */
5059
5060#undef elf_backend_plt_alignment
5061#define elf_backend_plt_alignment 5
5062#define NACL_PLT_ENTRY_SIZE 64
5063#define NACLMASK 0xe0 /* 32-byte alignment mask. */
5064
5065static const bfd_byte elf_i386_nacl_plt0_entry[] =
5066 {
5067 0xff, 0x35, /* pushl contents of address */
5068 0, 0, 0, 0, /* replaced with address of .got + 4. */
5069 0x8b, 0x0d, /* movl contents of address, %ecx */
5070 0, 0, 0, 0, /* replaced with address of .got + 8. */
5071 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */
5072 0xff, 0xe1 /* jmp *%ecx */
5073 };
5074
5075static const bfd_byte elf_i386_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
5076 {
5077 0x8b, 0x0d, /* movl contents of address, %ecx */
5078 0, 0, 0, 0, /* replaced with GOT slot address. */
5079 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */
5080 0xff, 0xe1, /* jmp *%ecx */
5081
5082 /* Pad to the next 32-byte boundary with nop instructions. */
5083 0x90,
5084 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5085 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5086
5087 /* Lazy GOT entries point here (32-byte aligned). */
5088 0x68, /* pushl immediate */
5089 0, 0, 0, 0, /* replaced with reloc offset. */
5090 0xe9, /* jmp relative */
5091 0, 0, 0, 0, /* replaced with offset to .plt. */
5092
5093 /* Pad to the next 32-byte boundary with nop instructions. */
5094 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5095 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5096 0x90, 0x90
5097 };
5098
5099static const bfd_byte
5100elf_i386_nacl_pic_plt0_entry[sizeof (elf_i386_nacl_plt0_entry)] =
5101 {
5102 0xff, 0x73, 0x04, /* pushl 4(%ebx) */
5103 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */
5104 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */
5105 0xff, 0xe1, /* jmp *%ecx */
caa0075c
RM
5106
5107 /* This is expected to be the same size as elf_i386_nacl_plt0_entry,
5108 so pad to that size with nop instructions. */
5109 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
a27e4371
RM
5110 };
5111
5112static const bfd_byte elf_i386_nacl_pic_plt_entry[NACL_PLT_ENTRY_SIZE] =
5113 {
5114 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
5115 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
5116 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */
5117 0xff, 0xe1, /* jmp *%ecx */
5118
5119 /* Pad to the next 32-byte boundary with nop instructions. */
5120 0x90,
5121 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5122 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5123
5124 /* Lazy GOT entries point here (32-byte aligned). */
5125 0x68, /* pushl immediate */
5126 0, 0, 0, 0, /* replaced with offset into relocation table. */
5127 0xe9, /* jmp relative */
5128 0, 0, 0, 0, /* replaced with offset to start of .plt. */
5129
5130 /* Pad to the next 32-byte boundary with nop instructions. */
5131 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5132 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
5133 0x90, 0x90
5134 };
5135
5136static const bfd_byte elf_i386_nacl_eh_frame_plt[] =
5137 {
5138#if (PLT_CIE_LENGTH != 20 \
5139 || PLT_FDE_LENGTH != 36 \
5140 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5141 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5142# error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!"
5143#endif
5144 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
5145 0, 0, 0, 0, /* CIE ID */
5146 1, /* CIE version */
5147 'z', 'R', 0, /* Augmentation string */
5148 1, /* Code alignment factor */
5149 0x7c, /* Data alignment factor: -4 */
5150 8, /* Return address column */
5151 1, /* Augmentation size */
5152 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
5153 DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
5154 DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
5155 DW_CFA_nop, DW_CFA_nop,
5156
5157 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
5158 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
5159 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
5160 0, 0, 0, 0, /* .plt size goes here */
5161 0, /* Augmentation size */
5162 DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
5163 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5164 DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
5165 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5166 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
5167 13, /* Block length */
5168 DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
5169 DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
5170 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
5171 DW_OP_lit2, DW_OP_shl, DW_OP_plus,
5172 DW_CFA_nop, DW_CFA_nop
5173 };
5174
5175static const struct elf_i386_plt_layout elf_i386_nacl_plt =
5176 {
5177 elf_i386_nacl_plt0_entry, /* plt0_entry */
5178 sizeof (elf_i386_nacl_plt0_entry), /* plt0_entry_size */
5179 2, /* plt0_got1_offset */
5180 8, /* plt0_got2_offset */
5181 elf_i386_nacl_plt_entry, /* plt_entry */
5182 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
5183 2, /* plt_got_offset */
5184 33, /* plt_reloc_offset */
5185 38, /* plt_plt_offset */
5186 32, /* plt_lazy_offset */
5187 elf_i386_nacl_pic_plt0_entry, /* pic_plt0_entry */
5188 elf_i386_nacl_pic_plt_entry, /* pic_plt_entry */
5189 elf_i386_nacl_eh_frame_plt, /* eh_frame_plt */
5190 sizeof (elf_i386_nacl_eh_frame_plt),/* eh_frame_plt_size */
5191 };
5192
5193static const struct elf_i386_backend_data elf_i386_nacl_arch_bed =
5194 {
5195 &elf_i386_nacl_plt, /* plt */
5196 0x90, /* plt0_pad_byte: nop insn */
5197 0, /* is_vxworks */
5198 };
5199
5200#undef elf_backend_arch_data
5201#define elf_backend_arch_data &elf_i386_nacl_arch_bed
5202
5a68afcf
RM
5203#undef elf_backend_modify_segment_map
5204#define elf_backend_modify_segment_map nacl_modify_segment_map
5205#undef elf_backend_modify_program_headers
5206#define elf_backend_modify_program_headers nacl_modify_program_headers
5207
a27e4371
RM
5208#include "elf32-target.h"
5209
5a68afcf
RM
5210/* Restore defaults. */
5211#undef elf_backend_modify_segment_map
5212#undef elf_backend_modify_program_headers
5213
eac338cf
PB
5214/* VxWorks support. */
5215
5216#undef TARGET_LITTLE_SYM
5217#define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec
5218#undef TARGET_LITTLE_NAME
5219#define TARGET_LITTLE_NAME "elf32-i386-vxworks"
d1036acb 5220#undef ELF_OSABI
a27e4371
RM
5221#undef elf_backend_plt_alignment
5222#define elf_backend_plt_alignment 4
eac338cf 5223
23209a78
RM
5224static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed =
5225 {
25e762b9 5226 &elf_i386_plt, /* plt */
23209a78
RM
5227 0x90, /* plt0_pad_byte */
5228 1, /* is_vxworks */
5229 };
eac338cf 5230
23209a78
RM
5231#undef elf_backend_arch_data
5232#define elf_backend_arch_data &elf_i386_vxworks_arch_bed
eac338cf 5233
13285a1b
AM
5234#undef elf_backend_relocs_compatible
5235#undef elf_backend_post_process_headers
eac338cf
PB
5236#undef elf_backend_add_symbol_hook
5237#define elf_backend_add_symbol_hook \
5238 elf_vxworks_add_symbol_hook
5239#undef elf_backend_link_output_symbol_hook
5240#define elf_backend_link_output_symbol_hook \
9c72ff84 5241 elf_vxworks_link_output_symbol_hook
eac338cf
PB
5242#undef elf_backend_emit_relocs
5243#define elf_backend_emit_relocs elf_vxworks_emit_relocs
5244#undef elf_backend_final_write_processing
5245#define elf_backend_final_write_processing \
5246 elf_vxworks_final_write_processing
7dc98aea 5247#undef elf_backend_static_tls_alignment
eac338cf
PB
5248
5249/* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
5250 define it. */
5251#undef elf_backend_want_plt_sym
5252#define elf_backend_want_plt_sym 1
5253
5254#undef elf32_bed
5255#define elf32_bed elf32_i386_vxworks_bed
5256
5257#include "elf32-target.h"
This page took 1.004426 seconds and 4 git commands to generate.