1 /* Intel 80386/80486-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
30 /* NativeClient binary format description input. */
31 /* NativeClient format is based on elf32. */
34 /* 386 uses REL relocations instead of RELA. */
39 static reloc_howto_type elf_howto_table
[]=
41 HOWTO(R_386_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_bitfield
,
42 bfd_elf_generic_reloc
, "R_386_NONE",
43 TRUE
, 0x00000000, 0x00000000, FALSE
),
44 HOWTO(R_386_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
45 bfd_elf_generic_reloc
, "R_386_32",
46 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
47 HOWTO(R_386_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
48 bfd_elf_generic_reloc
, "R_386_PC32",
49 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
50 HOWTO(R_386_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
51 bfd_elf_generic_reloc
, "R_386_GOT32",
52 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
53 HOWTO(R_386_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
54 bfd_elf_generic_reloc
, "R_386_PLT32",
55 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
56 HOWTO(R_386_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
57 bfd_elf_generic_reloc
, "R_386_COPY",
58 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
59 HOWTO(R_386_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
60 bfd_elf_generic_reloc
, "R_386_GLOB_DAT",
61 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
62 HOWTO(R_386_JUMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
, "R_386_JUMP_SLOT",
64 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
65 HOWTO(R_386_RELATIVE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
66 bfd_elf_generic_reloc
, "R_386_RELATIVE",
67 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
68 HOWTO(R_386_GOTOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
69 bfd_elf_generic_reloc
, "R_386_GOTOFF",
70 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
71 HOWTO(R_386_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
72 bfd_elf_generic_reloc
, "R_386_GOTPC",
73 TRUE
, 0xffffffff, 0xffffffff, TRUE
),
75 /* We have a gap in the reloc numbers here.
76 R_386_standard counts the number up to this point, and
77 R_386_ext_offset is the value to subtract from a reloc type of
78 R_386_16 thru R_386_PC8 to form an index into this table. */
79 #define R_386_standard (R_386_GOTPC + 1)
80 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
82 /* These relocs are a GNU extension. */
83 HOWTO(R_386_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
84 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF",
85 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
86 HOWTO(R_386_TLS_IE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_386_TLS_IE",
88 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
89 HOWTO(R_386_TLS_GOTIE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
90 bfd_elf_generic_reloc
, "R_386_TLS_GOTIE",
91 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
92 HOWTO(R_386_TLS_LE
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_386_TLS_LE",
94 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
95 HOWTO(R_386_TLS_GD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_386_TLS_GD",
97 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
98 HOWTO(R_386_TLS_LDM
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_386_TLS_LDM",
100 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
101 HOWTO(R_386_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
102 bfd_elf_generic_reloc
, "R_386_16",
103 TRUE
, 0xffff, 0xffff, FALSE
),
104 HOWTO(R_386_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
105 bfd_elf_generic_reloc
, "R_386_PC16",
106 TRUE
, 0xffff, 0xffff, TRUE
),
107 HOWTO(R_386_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
108 bfd_elf_generic_reloc
, "R_386_8",
109 TRUE
, 0xff, 0xff, FALSE
),
110 HOWTO(R_386_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
111 bfd_elf_generic_reloc
, "R_386_PC8",
112 TRUE
, 0xff, 0xff, TRUE
),
114 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
115 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
116 /* These are common with Solaris TLS implementation. */
117 HOWTO(R_386_TLS_LDO_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
118 bfd_elf_generic_reloc
, "R_386_TLS_LDO_32",
119 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
120 HOWTO(R_386_TLS_IE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
121 bfd_elf_generic_reloc
, "R_386_TLS_IE_32",
122 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
123 HOWTO(R_386_TLS_LE_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
124 bfd_elf_generic_reloc
, "R_386_TLS_LE_32",
125 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
126 HOWTO(R_386_TLS_DTPMOD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_386_TLS_DTPMOD32",
128 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
129 HOWTO(R_386_TLS_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_386_TLS_DTPOFF32",
131 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
132 HOWTO(R_386_TLS_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
133 bfd_elf_generic_reloc
, "R_386_TLS_TPOFF32",
134 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
136 HOWTO(R_386_TLS_GOTDESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
137 bfd_elf_generic_reloc
, "R_386_TLS_GOTDESC",
138 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
139 HOWTO(R_386_TLS_DESC_CALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
140 bfd_elf_generic_reloc
, "R_386_TLS_DESC_CALL",
142 HOWTO(R_386_TLS_DESC
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
143 bfd_elf_generic_reloc
, "R_386_TLS_DESC",
144 TRUE
, 0xffffffff, 0xffffffff, FALSE
),
147 #define R_386_tls (R_386_TLS_DESC + 1 - R_386_tls_offset)
148 #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_tls)
150 /* GNU extension to record C++ vtable hierarchy. */
151 HOWTO (R_386_GNU_VTINHERIT
, /* type */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
155 FALSE
, /* pc_relative */
157 complain_overflow_dont
, /* complain_on_overflow */
158 NULL
, /* special_function */
159 "R_386_GNU_VTINHERIT", /* name */
160 FALSE
, /* partial_inplace */
163 FALSE
), /* pcrel_offset */
165 /* GNU extension to record C++ vtable member usage. */
166 HOWTO (R_386_GNU_VTENTRY
, /* type */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
170 FALSE
, /* pc_relative */
172 complain_overflow_dont
, /* complain_on_overflow */
173 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
174 "R_386_GNU_VTENTRY", /* name */
175 FALSE
, /* partial_inplace */
178 FALSE
) /* pcrel_offset */
180 #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
184 #ifdef DEBUG_GEN_RELOC
186 fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
191 static reloc_howto_type
*
192 elf_i386_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
193 bfd_reloc_code_real_type code
)
198 TRACE ("BFD_RELOC_NONE");
199 return &elf_howto_table
[R_386_NONE
];
202 TRACE ("BFD_RELOC_32");
203 return &elf_howto_table
[R_386_32
];
206 TRACE ("BFD_RELOC_CTOR");
207 return &elf_howto_table
[R_386_32
];
209 case BFD_RELOC_32_PCREL
:
210 TRACE ("BFD_RELOC_PC32");
211 return &elf_howto_table
[R_386_PC32
];
213 case BFD_RELOC_386_GOT32
:
214 TRACE ("BFD_RELOC_386_GOT32");
215 return &elf_howto_table
[R_386_GOT32
];
217 case BFD_RELOC_386_PLT32
:
218 TRACE ("BFD_RELOC_386_PLT32");
219 return &elf_howto_table
[R_386_PLT32
];
221 case BFD_RELOC_386_COPY
:
222 TRACE ("BFD_RELOC_386_COPY");
223 return &elf_howto_table
[R_386_COPY
];
225 case BFD_RELOC_386_GLOB_DAT
:
226 TRACE ("BFD_RELOC_386_GLOB_DAT");
227 return &elf_howto_table
[R_386_GLOB_DAT
];
229 case BFD_RELOC_386_JUMP_SLOT
:
230 TRACE ("BFD_RELOC_386_JUMP_SLOT");
231 return &elf_howto_table
[R_386_JUMP_SLOT
];
233 case BFD_RELOC_386_RELATIVE
:
234 TRACE ("BFD_RELOC_386_RELATIVE");
235 return &elf_howto_table
[R_386_RELATIVE
];
237 case BFD_RELOC_386_GOTOFF
:
238 TRACE ("BFD_RELOC_386_GOTOFF");
239 return &elf_howto_table
[R_386_GOTOFF
];
241 case BFD_RELOC_386_GOTPC
:
242 TRACE ("BFD_RELOC_386_GOTPC");
243 return &elf_howto_table
[R_386_GOTPC
];
245 /* These relocs are a GNU extension. */
246 case BFD_RELOC_386_TLS_TPOFF
:
247 TRACE ("BFD_RELOC_386_TLS_TPOFF");
248 return &elf_howto_table
[R_386_TLS_TPOFF
- R_386_ext_offset
];
250 case BFD_RELOC_386_TLS_IE
:
251 TRACE ("BFD_RELOC_386_TLS_IE");
252 return &elf_howto_table
[R_386_TLS_IE
- R_386_ext_offset
];
254 case BFD_RELOC_386_TLS_GOTIE
:
255 TRACE ("BFD_RELOC_386_TLS_GOTIE");
256 return &elf_howto_table
[R_386_TLS_GOTIE
- R_386_ext_offset
];
258 case BFD_RELOC_386_TLS_LE
:
259 TRACE ("BFD_RELOC_386_TLS_LE");
260 return &elf_howto_table
[R_386_TLS_LE
- R_386_ext_offset
];
262 case BFD_RELOC_386_TLS_GD
:
263 TRACE ("BFD_RELOC_386_TLS_GD");
264 return &elf_howto_table
[R_386_TLS_GD
- R_386_ext_offset
];
266 case BFD_RELOC_386_TLS_LDM
:
267 TRACE ("BFD_RELOC_386_TLS_LDM");
268 return &elf_howto_table
[R_386_TLS_LDM
- R_386_ext_offset
];
271 TRACE ("BFD_RELOC_16");
272 return &elf_howto_table
[R_386_16
- R_386_ext_offset
];
274 case BFD_RELOC_16_PCREL
:
275 TRACE ("BFD_RELOC_16_PCREL");
276 return &elf_howto_table
[R_386_PC16
- R_386_ext_offset
];
279 TRACE ("BFD_RELOC_8");
280 return &elf_howto_table
[R_386_8
- R_386_ext_offset
];
282 case BFD_RELOC_8_PCREL
:
283 TRACE ("BFD_RELOC_8_PCREL");
284 return &elf_howto_table
[R_386_PC8
- R_386_ext_offset
];
286 /* Common with Sun TLS implementation. */
287 case BFD_RELOC_386_TLS_LDO_32
:
288 TRACE ("BFD_RELOC_386_TLS_LDO_32");
289 return &elf_howto_table
[R_386_TLS_LDO_32
- R_386_tls_offset
];
291 case BFD_RELOC_386_TLS_IE_32
:
292 TRACE ("BFD_RELOC_386_TLS_IE_32");
293 return &elf_howto_table
[R_386_TLS_IE_32
- R_386_tls_offset
];
295 case BFD_RELOC_386_TLS_LE_32
:
296 TRACE ("BFD_RELOC_386_TLS_LE_32");
297 return &elf_howto_table
[R_386_TLS_LE_32
- R_386_tls_offset
];
299 case BFD_RELOC_386_TLS_DTPMOD32
:
300 TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
301 return &elf_howto_table
[R_386_TLS_DTPMOD32
- R_386_tls_offset
];
303 case BFD_RELOC_386_TLS_DTPOFF32
:
304 TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
305 return &elf_howto_table
[R_386_TLS_DTPOFF32
- R_386_tls_offset
];
307 case BFD_RELOC_386_TLS_TPOFF32
:
308 TRACE ("BFD_RELOC_386_TLS_TPOFF32");
309 return &elf_howto_table
[R_386_TLS_TPOFF32
- R_386_tls_offset
];
311 case BFD_RELOC_386_TLS_GOTDESC
:
312 TRACE ("BFD_RELOC_386_TLS_GOTDESC");
313 return &elf_howto_table
[R_386_TLS_GOTDESC
- R_386_tls_offset
];
315 case BFD_RELOC_386_TLS_DESC_CALL
:
316 TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
317 return &elf_howto_table
[R_386_TLS_DESC_CALL
- R_386_tls_offset
];
319 case BFD_RELOC_386_TLS_DESC
:
320 TRACE ("BFD_RELOC_386_TLS_DESC");
321 return &elf_howto_table
[R_386_TLS_DESC
- R_386_tls_offset
];
323 case BFD_RELOC_VTABLE_INHERIT
:
324 TRACE ("BFD_RELOC_VTABLE_INHERIT");
325 return &elf_howto_table
[R_386_GNU_VTINHERIT
- R_386_vt_offset
];
327 case BFD_RELOC_VTABLE_ENTRY
:
328 TRACE ("BFD_RELOC_VTABLE_ENTRY");
329 return &elf_howto_table
[R_386_GNU_VTENTRY
- R_386_vt_offset
];
339 static reloc_howto_type
*
340 elf_i386_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
345 for (i
= 0; i
< sizeof (elf_howto_table
) / sizeof (elf_howto_table
[0]); i
++)
346 if (elf_howto_table
[i
].name
!= NULL
347 && strcasecmp (elf_howto_table
[i
].name
, r_name
) == 0)
348 return &elf_howto_table
[i
];
354 elf_i386_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
356 Elf_Internal_Rela
*dst
)
358 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
361 if ((indx
= r_type
) >= R_386_standard
362 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
363 >= R_386_ext
- R_386_standard
)
364 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
365 >= R_386_tls
- R_386_ext
)
366 && ((indx
= r_type
- R_386_vt_offset
) - R_386_tls
367 >= R_386_vt
- R_386_tls
))
369 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
373 cache_ptr
->howto
= &elf_howto_table
[indx
];
376 /* Return whether a symbol name implies a local label. The UnixWare
377 2.1 cc generates temporary symbols that start with .X, so we
378 recognize them here. FIXME: do other SVR4 compilers also use .X?.
379 If so, we should move the .X recognition into
380 _bfd_elf_is_local_label_name. */
383 elf_i386_is_local_label_name (bfd
*abfd
, const char *name
)
385 if (name
[0] == '.' && name
[1] == 'X')
388 return _bfd_elf_is_local_label_name (abfd
, name
);
391 /* Support for core dump NOTE sections. */
394 elf_i386_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
399 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
401 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
407 elf_tdata (abfd
)->core_signal
= bfd_get_32 (abfd
, note
->descdata
+ 20);
410 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
414 size
= bfd_get_32 (abfd
, note
->descdata
+ 8);
418 switch (note
->descsz
)
423 case 144: /* Linux/i386 */
425 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
428 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
438 /* Make a ".reg/999" section. */
439 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
440 size
, note
->descpos
+ offset
);
444 elf_i386_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
446 if (note
->namesz
== 8 && strcmp (note
->namedata
, "FreeBSD") == 0)
448 int pr_version
= bfd_get_32 (abfd
, note
->descdata
);
453 elf_tdata (abfd
)->core_program
454 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 8, 17);
455 elf_tdata (abfd
)->core_command
456 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 25, 81);
460 switch (note
->descsz
)
465 case 124: /* Linux/i386 elf_prpsinfo. */
466 elf_tdata (abfd
)->core_program
467 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
468 elf_tdata (abfd
)->core_command
469 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
473 /* Note that for some reason, a spurious space is tacked
474 onto the end of the args in some (at least one anyway)
475 implementations, so strip it off if it exists. */
477 char *command
= elf_tdata (abfd
)->core_command
;
478 int n
= strlen (command
);
480 if (0 < n
&& command
[n
- 1] == ' ')
481 command
[n
- 1] = '\0';
487 /* Functions for the i386 ELF linker.
489 In order to gain some understanding of code in this file without
490 knowing all the intricate details of the linker, note the
493 Functions named elf_i386_* are called by external routines, other
494 functions are only called locally. elf_i386_* functions appear
495 in this file more or less in the order in which they are called
496 from external routines. eg. elf_i386_check_relocs is called
497 early in the link process, elf_i386_finish_dynamic_sections is
498 one of the last functions. */
501 /* The name of the dynamic interpreter. This is put in the .interp
504 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
506 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
507 copying dynamic variables from a shared lib into an app's dynbss
508 section, and instead use a dynamic relocation to point into the
510 #define ELIMINATE_COPY_RELOCS 1
512 /* The size in bytes of an entry in the procedure linkage table. */
514 #define PLT_ENTRY_SIZE 64
516 /* The first entry in an absolute procedure linkage table looks like
517 this. See the SVR4 ABI i386 supplement to see how this works.
518 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
520 static const bfd_byte elf_i386_plt0_entry
[18] =
522 0xff, 0x35, /* pushl contents of address */
523 #define elf_i386_plt0_entry_offset1 2
524 0, 0, 0, 0, /* replaced with address of .got + 4. */
525 0xb9, /* movl address, %ecx */
526 #define elf_i386_plt0_entry_offset2 7
527 0, 0, 0, 0, /* replaced with address of .got + 8. */
528 0x8b, 0x09, /* mov (%ecx), %ecx */
529 0x83, 0xe1, 0xe0, /* andl %ecx, NACLMASK */
530 0xff, 0xe1 /* jmp *%ecx */
533 /* Subsequent entries in an absolute procedure linkage table look like
536 static const bfd_byte elf_i386_plt_entry
[PLT_ENTRY_SIZE
] =
538 0xb9, /* movl address, %ecx */
539 #define elf_i386_plt_entry_offset1 1
540 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
541 0x8b, 0x09, /* mov (%ecx), %ecx */
542 0x83, 0xe1, 0xe0, /* andl %ecx, NACLMASK */
543 0xff, 0xe1, /* jmp *%ecx */
544 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
545 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
546 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
547 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
548 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
549 #define elf_i386_plt_entry_offset2 32
550 0x68, /* pushl immediate */
551 #define elf_i386_plt_entry_offset3 33
552 0, 0, 0, 0, /* replaced with offset into relocation table. */
553 0xe9, /* jmp relative */
554 #define elf_i386_plt_entry_offset4 38
555 0, 0, 0, 0, /* replaced with offset to start of .plt. */
556 #define elf_i386_plt_entry_offset5 42
557 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
558 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
559 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
560 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
561 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
562 0xf4, 0xf4 /* fill with hlt instructions. */
565 /* The first entry in a PIC procedure linkage table look like this.
566 Will be padded to PLT_ENTRY_SIZE with htab->plt0_pad_byte. */
568 static const bfd_byte elf_i386_pic_plt0_entry
[12] =
570 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
571 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
574 /* Subsequent entries in a PIC procedure linkage table look like this. */
576 static const bfd_byte elf_i386_pic_plt_entry
[PLT_ENTRY_SIZE
] =
578 0x8b, 0x8b, /* movl offset(%ebx), %ecx */
579 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
580 0x83, 0xe1, 0xe0, /* andl %ecx, NACLMASK */
581 0xff, 0xe1, /* jmp *%ecx */
582 0xf4, /* fill with hlt instructions. */
583 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
584 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
585 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
586 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
587 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
589 0x68, /* pushl immediate */
590 0, 0, 0, 0, /* replaced with offset into relocation table. */
591 0xe9, /* jmp relative */
592 0, 0, 0, 0, /* replaced with offset to start of .plt. */
593 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
594 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
595 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
596 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
597 0xf4, 0xf4, 0xf4, 0xf4, /* fill with hlt instructions. */
598 0xf4, 0xf4 /* fill with hlt instructions. */
601 /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
602 for the PLTResolve stub and then for each PLT entry. */
603 #define PLTRESOLVE_RELOCS_SHLIB 0
604 #define PLTRESOLVE_RELOCS 2
605 #define PLT_NON_JUMP_SLOT_RELOCS 2
607 /* The i386 linker needs to keep track of the number of relocs that it
608 decides to copy as dynamic relocs in check_relocs for each symbol.
609 This is so that it can later discard them if they are found to be
610 unnecessary. We store the information in a field extending the
611 regular ELF linker hash table. */
613 struct elf_i386_dyn_relocs
615 struct elf_i386_dyn_relocs
*next
;
617 /* The input section of the reloc. */
620 /* Total number of relocs copied for the input section. */
623 /* Number of pc-relative relocs copied for the input section. */
624 bfd_size_type pc_count
;
627 /* i386 ELF linker hash entry. */
629 struct elf_i386_link_hash_entry
631 struct elf_link_hash_entry elf
;
633 /* Track dynamic relocs copied for this symbol. */
634 struct elf_i386_dyn_relocs
*dyn_relocs
;
636 #define GOT_UNKNOWN 0
640 #define GOT_TLS_IE_POS 5
641 #define GOT_TLS_IE_NEG 6
642 #define GOT_TLS_IE_BOTH 7
643 #define GOT_TLS_GDESC 8
644 #define GOT_TLS_GD_BOTH_P(type) \
645 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
646 #define GOT_TLS_GD_P(type) \
647 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
648 #define GOT_TLS_GDESC_P(type) \
649 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
650 #define GOT_TLS_GD_ANY_P(type) \
651 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
652 unsigned char tls_type
;
654 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
655 starting at the end of the jump table. */
659 #define elf_i386_hash_entry(ent) ((struct elf_i386_link_hash_entry *)(ent))
661 struct elf_i386_obj_tdata
663 struct elf_obj_tdata root
;
665 /* tls_type for each local got entry. */
666 char *local_got_tls_type
;
668 /* GOTPLT entries for TLS descriptors. */
669 bfd_vma
*local_tlsdesc_gotent
;
672 #define elf_i386_tdata(abfd) \
673 ((struct elf_i386_obj_tdata *) (abfd)->tdata.any)
675 #define elf_i386_local_got_tls_type(abfd) \
676 (elf_i386_tdata (abfd)->local_got_tls_type)
678 #define elf_i386_local_tlsdesc_gotent(abfd) \
679 (elf_i386_tdata (abfd)->local_tlsdesc_gotent)
682 elf_i386_mkobject (bfd
*abfd
)
684 if (abfd
->tdata
.any
== NULL
)
686 bfd_size_type amt
= sizeof (struct elf_i386_obj_tdata
);
687 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
688 if (abfd
->tdata
.any
== NULL
)
691 return bfd_elf_mkobject (abfd
);
694 /* i386 ELF linker hash table. */
696 struct elf_i386_link_hash_table
698 struct elf_link_hash_table elf
;
700 /* Short-cuts to get to dynamic linker sections. */
709 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
712 /* True if the target system is VxWorks. */
715 /* Value used to fill the last word of the first plt entry. */
716 bfd_byte plt0_pad_byte
;
718 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
719 bfd_vma next_tls_desc_index
;
722 bfd_signed_vma refcount
;
726 /* The amount of space used by the reserved portion of the sgotplt
727 section, plus whatever space is used by the jump slots. */
728 bfd_vma sgotplt_jump_table_size
;
730 /* Small local sym to section mapping cache. */
731 struct sym_sec_cache sym_sec
;
734 /* Get the i386 ELF linker hash table from a link_info structure. */
736 #define elf_i386_hash_table(p) \
737 ((struct elf_i386_link_hash_table *) ((p)->hash))
739 #define elf_i386_compute_jump_table_size(htab) \
740 ((htab)->next_tls_desc_index * 4)
742 /* Create an entry in an i386 ELF linker hash table. */
744 static struct bfd_hash_entry
*
745 link_hash_newfunc (struct bfd_hash_entry
*entry
,
746 struct bfd_hash_table
*table
,
749 /* Allocate the structure if it has not already been allocated by a
753 entry
= bfd_hash_allocate (table
,
754 sizeof (struct elf_i386_link_hash_entry
));
759 /* Call the allocation method of the superclass. */
760 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
763 struct elf_i386_link_hash_entry
*eh
;
765 eh
= (struct elf_i386_link_hash_entry
*) entry
;
766 eh
->dyn_relocs
= NULL
;
767 eh
->tls_type
= GOT_UNKNOWN
;
768 eh
->tlsdesc_got
= (bfd_vma
) -1;
774 /* Create an i386 ELF linker hash table. */
776 static struct bfd_link_hash_table
*
777 elf_i386_link_hash_table_create (bfd
*abfd
)
779 struct elf_i386_link_hash_table
*ret
;
780 bfd_size_type amt
= sizeof (struct elf_i386_link_hash_table
);
782 ret
= bfd_malloc (amt
);
786 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
,
787 sizeof (struct elf_i386_link_hash_entry
)))
800 ret
->tls_ldm_got
.refcount
= 0;
801 ret
->next_tls_desc_index
= 0;
802 ret
->sgotplt_jump_table_size
= 0;
803 ret
->sym_sec
.abfd
= NULL
;
805 ret
->srelplt2
= NULL
;
806 ret
->plt0_pad_byte
= 0xf4;
808 return &ret
->elf
.root
;
811 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
812 shortcuts to them in our hash table. */
815 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
817 struct elf_i386_link_hash_table
*htab
;
819 if (! _bfd_elf_create_got_section (dynobj
, info
))
822 htab
= elf_i386_hash_table (info
);
823 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
824 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
825 if (!htab
->sgot
|| !htab
->sgotplt
)
828 htab
->srelgot
= bfd_make_section_with_flags (dynobj
, ".rel.got",
829 (SEC_ALLOC
| SEC_LOAD
834 if (htab
->srelgot
== NULL
835 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
840 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
841 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
845 elf_i386_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
847 struct elf_i386_link_hash_table
*htab
;
849 htab
= elf_i386_hash_table (info
);
850 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
853 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
856 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
857 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
858 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
860 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
862 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
863 || (!info
->shared
&& !htab
->srelbss
))
866 if (!bfd_set_section_alignment (dynobj
, htab
->splt
, 5))
870 && !elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
876 /* Copy the extra info we tack onto an elf_link_hash_entry. */
879 elf_i386_copy_indirect_symbol (struct bfd_link_info
*info
,
880 struct elf_link_hash_entry
*dir
,
881 struct elf_link_hash_entry
*ind
)
883 struct elf_i386_link_hash_entry
*edir
, *eind
;
885 edir
= (struct elf_i386_link_hash_entry
*) dir
;
886 eind
= (struct elf_i386_link_hash_entry
*) ind
;
888 if (eind
->dyn_relocs
!= NULL
)
890 if (edir
->dyn_relocs
!= NULL
)
892 struct elf_i386_dyn_relocs
**pp
;
893 struct elf_i386_dyn_relocs
*p
;
895 /* Add reloc counts against the indirect sym to the direct sym
896 list. Merge any entries against the same section. */
897 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
899 struct elf_i386_dyn_relocs
*q
;
901 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
902 if (q
->sec
== p
->sec
)
904 q
->pc_count
+= p
->pc_count
;
905 q
->count
+= p
->count
;
912 *pp
= edir
->dyn_relocs
;
915 edir
->dyn_relocs
= eind
->dyn_relocs
;
916 eind
->dyn_relocs
= NULL
;
919 if (ind
->root
.type
== bfd_link_hash_indirect
920 && dir
->got
.refcount
<= 0)
922 edir
->tls_type
= eind
->tls_type
;
923 eind
->tls_type
= GOT_UNKNOWN
;
926 if (ELIMINATE_COPY_RELOCS
927 && ind
->root
.type
!= bfd_link_hash_indirect
928 && dir
->dynamic_adjusted
)
930 /* If called to transfer flags for a weakdef during processing
931 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
932 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
933 dir
->ref_dynamic
|= ind
->ref_dynamic
;
934 dir
->ref_regular
|= ind
->ref_regular
;
935 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
936 dir
->needs_plt
|= ind
->needs_plt
;
937 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
940 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
944 elf_i386_tls_transition (struct bfd_link_info
*info
, int r_type
, int is_local
)
952 case R_386_TLS_GOTDESC
:
953 case R_386_TLS_DESC_CALL
:
954 case R_386_TLS_IE_32
:
956 return R_386_TLS_LE_32
;
957 return R_386_TLS_IE_32
;
959 case R_386_TLS_GOTIE
:
961 return R_386_TLS_LE_32
;
964 return R_386_TLS_LE_32
;
970 /* Look through the relocs for a section during the first phase, and
971 calculate needed space in the global offset table, procedure linkage
972 table, and dynamic reloc sections. */
975 elf_i386_check_relocs (bfd
*abfd
,
976 struct bfd_link_info
*info
,
978 const Elf_Internal_Rela
*relocs
)
980 struct elf_i386_link_hash_table
*htab
;
981 Elf_Internal_Shdr
*symtab_hdr
;
982 struct elf_link_hash_entry
**sym_hashes
;
983 const Elf_Internal_Rela
*rel
;
984 const Elf_Internal_Rela
*rel_end
;
987 if (info
->relocatable
)
990 htab
= elf_i386_hash_table (info
);
991 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
992 sym_hashes
= elf_sym_hashes (abfd
);
996 rel_end
= relocs
+ sec
->reloc_count
;
997 for (rel
= relocs
; rel
< rel_end
; rel
++)
1000 unsigned long r_symndx
;
1001 struct elf_link_hash_entry
*h
;
1003 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1004 r_type
= ELF32_R_TYPE (rel
->r_info
);
1006 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1008 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1014 if (r_symndx
< symtab_hdr
->sh_info
)
1018 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1019 while (h
->root
.type
== bfd_link_hash_indirect
1020 || h
->root
.type
== bfd_link_hash_warning
)
1021 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1024 r_type
= elf_i386_tls_transition (info
, r_type
, h
== NULL
);
1029 htab
->tls_ldm_got
.refcount
+= 1;
1033 /* This symbol requires a procedure linkage table entry. We
1034 actually build the entry in adjust_dynamic_symbol,
1035 because this might be a case of linking PIC code which is
1036 never referenced by a dynamic object, in which case we
1037 don't need to generate a procedure linkage table entry
1040 /* If this is a local symbol, we resolve it directly without
1041 creating a procedure linkage table entry. */
1046 h
->plt
.refcount
+= 1;
1049 case R_386_TLS_IE_32
:
1051 case R_386_TLS_GOTIE
:
1053 info
->flags
|= DF_STATIC_TLS
;
1058 case R_386_TLS_GOTDESC
:
1059 case R_386_TLS_DESC_CALL
:
1060 /* This symbol requires a global offset table entry. */
1062 int tls_type
, old_tls_type
;
1067 case R_386_GOT32
: tls_type
= GOT_NORMAL
; break;
1068 case R_386_TLS_GD
: tls_type
= GOT_TLS_GD
; break;
1069 case R_386_TLS_GOTDESC
:
1070 case R_386_TLS_DESC_CALL
:
1071 tls_type
= GOT_TLS_GDESC
; break;
1072 case R_386_TLS_IE_32
:
1073 if (ELF32_R_TYPE (rel
->r_info
) == r_type
)
1074 tls_type
= GOT_TLS_IE_NEG
;
1076 /* If this is a GD->IE transition, we may use either of
1077 R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
1078 tls_type
= GOT_TLS_IE
;
1081 case R_386_TLS_GOTIE
:
1082 tls_type
= GOT_TLS_IE_POS
; break;
1087 h
->got
.refcount
+= 1;
1088 old_tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1092 bfd_signed_vma
*local_got_refcounts
;
1094 /* This is a global offset table entry for a local symbol. */
1095 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1096 if (local_got_refcounts
== NULL
)
1100 size
= symtab_hdr
->sh_info
;
1101 size
*= (sizeof (bfd_signed_vma
)
1102 + sizeof (bfd_vma
) + sizeof(char));
1103 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1104 if (local_got_refcounts
== NULL
)
1106 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1107 elf_i386_local_tlsdesc_gotent (abfd
)
1108 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1109 elf_i386_local_got_tls_type (abfd
)
1110 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1112 local_got_refcounts
[r_symndx
] += 1;
1113 old_tls_type
= elf_i386_local_got_tls_type (abfd
) [r_symndx
];
1116 if ((old_tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_IE
))
1117 tls_type
|= old_tls_type
;
1118 /* If a TLS symbol is accessed using IE at least once,
1119 there is no point to use dynamic model for it. */
1120 else if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1121 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1122 || (tls_type
& GOT_TLS_IE
) == 0))
1124 if ((old_tls_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (tls_type
))
1125 tls_type
= old_tls_type
;
1126 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1127 && GOT_TLS_GD_ANY_P (tls_type
))
1128 tls_type
|= old_tls_type
;
1131 (*_bfd_error_handler
)
1132 (_("%B: `%s' accessed both as normal and "
1133 "thread local symbol"),
1135 h
? h
->root
.root
.string
: "<local>");
1140 if (old_tls_type
!= tls_type
)
1143 elf_i386_hash_entry (h
)->tls_type
= tls_type
;
1145 elf_i386_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1153 if (htab
->sgot
== NULL
)
1155 if (htab
->elf
.dynobj
== NULL
)
1156 htab
->elf
.dynobj
= abfd
;
1157 if (!create_got_section (htab
->elf
.dynobj
, info
))
1160 if (r_type
!= R_386_TLS_IE
)
1164 case R_386_TLS_LE_32
:
1168 info
->flags
|= DF_STATIC_TLS
;
1173 if (h
!= NULL
&& !info
->shared
)
1175 /* If this reloc is in a read-only section, we might
1176 need a copy reloc. We can't check reliably at this
1177 stage whether the section is read-only, as input
1178 sections have not yet been mapped to output sections.
1179 Tentatively set the flag for now, and correct in
1180 adjust_dynamic_symbol. */
1183 /* We may need a .plt entry if the function this reloc
1184 refers to is in a shared lib. */
1185 h
->plt
.refcount
+= 1;
1186 if (r_type
!= R_386_PC32
)
1187 h
->pointer_equality_needed
= 1;
1190 /* If we are creating a shared library, and this is a reloc
1191 against a global symbol, or a non PC relative reloc
1192 against a local symbol, then we need to copy the reloc
1193 into the shared library. However, if we are linking with
1194 -Bsymbolic, we do not need to copy a reloc against a
1195 global symbol which is defined in an object we are
1196 including in the link (i.e., DEF_REGULAR is set). At
1197 this point we have not seen all the input files, so it is
1198 possible that DEF_REGULAR is not set now but will be set
1199 later (it is never cleared). In case of a weak definition,
1200 DEF_REGULAR may be cleared later by a strong definition in
1201 a shared library. We account for that possibility below by
1202 storing information in the relocs_copied field of the hash
1203 table entry. A similar situation occurs when creating
1204 shared libraries and symbol visibility changes render the
1207 If on the other hand, we are creating an executable, we
1208 may need to keep relocations for symbols satisfied by a
1209 dynamic library if we manage to avoid copy relocs for the
1212 && (sec
->flags
& SEC_ALLOC
) != 0
1213 && (r_type
!= R_386_PC32
1215 && (! SYMBOLIC_BIND (info
, h
)
1216 || h
->root
.type
== bfd_link_hash_defweak
1217 || !h
->def_regular
))))
1218 || (ELIMINATE_COPY_RELOCS
1220 && (sec
->flags
& SEC_ALLOC
) != 0
1222 && (h
->root
.type
== bfd_link_hash_defweak
1223 || !h
->def_regular
)))
1225 struct elf_i386_dyn_relocs
*p
;
1226 struct elf_i386_dyn_relocs
**head
;
1228 /* We must copy these reloc types into the output file.
1229 Create a reloc section in dynobj and make room for
1235 unsigned int strndx
= elf_elfheader (abfd
)->e_shstrndx
;
1236 unsigned int shnam
= elf_section_data (sec
)->rel_hdr
.sh_name
;
1238 name
= bfd_elf_string_from_elf_section (abfd
, strndx
, shnam
);
1242 if (! CONST_STRNEQ (name
, ".rel")
1243 || strcmp (bfd_get_section_name (abfd
, sec
),
1246 (*_bfd_error_handler
)
1247 (_("%B: bad relocation section name `%s\'"),
1251 if (htab
->elf
.dynobj
== NULL
)
1252 htab
->elf
.dynobj
= abfd
;
1254 dynobj
= htab
->elf
.dynobj
;
1255 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1260 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1261 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1262 if ((sec
->flags
& SEC_ALLOC
) != 0)
1263 flags
|= SEC_ALLOC
| SEC_LOAD
;
1264 sreloc
= bfd_make_section_with_flags (dynobj
,
1268 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1271 elf_section_data (sec
)->sreloc
= sreloc
;
1274 /* If this is a global symbol, we count the number of
1275 relocations we need for this symbol. */
1278 head
= &((struct elf_i386_link_hash_entry
*) h
)->dyn_relocs
;
1283 /* Track dynamic relocs needed for local syms too.
1284 We really need local syms available to do this
1288 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1293 vpp
= &elf_section_data (s
)->local_dynrel
;
1294 head
= (struct elf_i386_dyn_relocs
**)vpp
;
1298 if (p
== NULL
|| p
->sec
!= sec
)
1300 bfd_size_type amt
= sizeof *p
;
1301 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
1312 if (r_type
== R_386_PC32
)
1317 /* This relocation describes the C++ object vtable hierarchy.
1318 Reconstruct it for later use during GC. */
1319 case R_386_GNU_VTINHERIT
:
1320 BFD_ASSERT (h
!= NULL
);
1322 && !bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1326 /* This relocation describes which C++ vtable entries are actually
1327 used. Record for later use during GC. */
1328 case R_386_GNU_VTENTRY
:
1329 BFD_ASSERT (h
!= NULL
);
1331 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
1343 /* Return the section that should be marked against GC for a given
1347 elf_i386_gc_mark_hook (asection
*sec
,
1348 struct bfd_link_info
*info
,
1349 Elf_Internal_Rela
*rel
,
1350 struct elf_link_hash_entry
*h
,
1351 Elf_Internal_Sym
*sym
)
1354 switch (ELF32_R_TYPE (rel
->r_info
))
1356 case R_386_GNU_VTINHERIT
:
1357 case R_386_GNU_VTENTRY
:
1361 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1364 /* Update the got entry reference counts for the section being removed. */
1367 elf_i386_gc_sweep_hook (bfd
*abfd
,
1368 struct bfd_link_info
*info
,
1370 const Elf_Internal_Rela
*relocs
)
1372 Elf_Internal_Shdr
*symtab_hdr
;
1373 struct elf_link_hash_entry
**sym_hashes
;
1374 bfd_signed_vma
*local_got_refcounts
;
1375 const Elf_Internal_Rela
*rel
, *relend
;
1377 elf_section_data (sec
)->local_dynrel
= NULL
;
1379 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1380 sym_hashes
= elf_sym_hashes (abfd
);
1381 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1383 relend
= relocs
+ sec
->reloc_count
;
1384 for (rel
= relocs
; rel
< relend
; rel
++)
1386 unsigned long r_symndx
;
1387 unsigned int r_type
;
1388 struct elf_link_hash_entry
*h
= NULL
;
1390 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1391 if (r_symndx
>= symtab_hdr
->sh_info
)
1393 struct elf_i386_link_hash_entry
*eh
;
1394 struct elf_i386_dyn_relocs
**pp
;
1395 struct elf_i386_dyn_relocs
*p
;
1397 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1398 while (h
->root
.type
== bfd_link_hash_indirect
1399 || h
->root
.type
== bfd_link_hash_warning
)
1400 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1401 eh
= (struct elf_i386_link_hash_entry
*) h
;
1403 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1406 /* Everything must go for SEC. */
1412 r_type
= ELF32_R_TYPE (rel
->r_info
);
1413 r_type
= elf_i386_tls_transition (info
, r_type
, h
!= NULL
);
1417 if (elf_i386_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1418 elf_i386_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1422 case R_386_TLS_GOTDESC
:
1423 case R_386_TLS_DESC_CALL
:
1424 case R_386_TLS_IE_32
:
1426 case R_386_TLS_GOTIE
:
1430 if (h
->got
.refcount
> 0)
1431 h
->got
.refcount
-= 1;
1433 else if (local_got_refcounts
!= NULL
)
1435 if (local_got_refcounts
[r_symndx
] > 0)
1436 local_got_refcounts
[r_symndx
] -= 1;
1449 if (h
->plt
.refcount
> 0)
1450 h
->plt
.refcount
-= 1;
1462 /* Adjust a symbol defined by a dynamic object and referenced by a
1463 regular object. The current definition is in some section of the
1464 dynamic object, but we're not including those sections. We have to
1465 change the definition to something the rest of the link can
1469 elf_i386_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1470 struct elf_link_hash_entry
*h
)
1472 struct elf_i386_link_hash_table
*htab
;
1475 /* If this is a function, put it in the procedure linkage table. We
1476 will fill in the contents of the procedure linkage table later,
1477 when we know the address of the .got section. */
1478 if (h
->type
== STT_FUNC
1481 if (h
->plt
.refcount
<= 0
1482 || SYMBOL_CALLS_LOCAL (info
, h
)
1483 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1484 && h
->root
.type
== bfd_link_hash_undefweak
))
1486 /* This case can occur if we saw a PLT32 reloc in an input
1487 file, but the symbol was never referred to by a dynamic
1488 object, or if all references were garbage collected. In
1489 such a case, we don't actually need to build a procedure
1490 linkage table, and we can just do a PC32 reloc instead. */
1491 h
->plt
.offset
= (bfd_vma
) -1;
1498 /* It's possible that we incorrectly decided a .plt reloc was
1499 needed for an R_386_PC32 reloc to a non-function sym in
1500 check_relocs. We can't decide accurately between function and
1501 non-function syms in check-relocs; Objects loaded later in
1502 the link may change h->type. So fix it now. */
1503 h
->plt
.offset
= (bfd_vma
) -1;
1505 /* If this is a weak symbol, and there is a real definition, the
1506 processor independent code will have arranged for us to see the
1507 real definition first, and we can just use the same value. */
1508 if (h
->u
.weakdef
!= NULL
)
1510 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1511 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1512 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1513 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1514 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1515 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1519 /* This is a reference to a symbol defined by a dynamic object which
1520 is not a function. */
1522 /* If we are creating a shared library, we must presume that the
1523 only references to the symbol are via the global offset table.
1524 For such cases we need not do anything here; the relocations will
1525 be handled correctly by relocate_section. */
1529 /* If there are no references to this symbol that do not use the
1530 GOT, we don't need to generate a copy reloc. */
1531 if (!h
->non_got_ref
)
1534 /* If -z nocopyreloc was given, we won't generate them either. */
1535 if (info
->nocopyreloc
)
1541 htab
= elf_i386_hash_table (info
);
1543 /* If there aren't any dynamic relocs in read-only sections, then
1544 we can keep the dynamic relocs and avoid the copy reloc. This
1545 doesn't work on VxWorks, where we can not have dynamic relocations
1546 (other than copy and jump slot relocations) in an executable. */
1547 if (ELIMINATE_COPY_RELOCS
&& !htab
->is_vxworks
)
1549 struct elf_i386_link_hash_entry
* eh
;
1550 struct elf_i386_dyn_relocs
*p
;
1552 eh
= (struct elf_i386_link_hash_entry
*) h
;
1553 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1555 s
= p
->sec
->output_section
;
1556 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1569 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1570 h
->root
.root
.string
);
1574 /* We must allocate the symbol in our .dynbss section, which will
1575 become part of the .bss section of the executable. There will be
1576 an entry for this symbol in the .dynsym section. The dynamic
1577 object will contain position independent code, so all references
1578 from the dynamic object to this symbol will go through the global
1579 offset table. The dynamic linker will use the .dynsym entry to
1580 determine the address it must put in the global offset table, so
1581 both the dynamic object and the regular object will refer to the
1582 same memory location for the variable. */
1584 /* We must generate a R_386_COPY reloc to tell the dynamic linker to
1585 copy the initial value out of the dynamic object and into the
1586 runtime process image. */
1587 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1589 htab
->srelbss
->size
+= sizeof (Elf32_External_Rel
);
1595 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1598 /* Allocate space in .plt, .got and associated reloc sections for
1602 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1604 struct bfd_link_info
*info
;
1605 struct elf_i386_link_hash_table
*htab
;
1606 struct elf_i386_link_hash_entry
*eh
;
1607 struct elf_i386_dyn_relocs
*p
;
1609 if (h
->root
.type
== bfd_link_hash_indirect
)
1612 if (h
->root
.type
== bfd_link_hash_warning
)
1613 /* When warning symbols are created, they **replace** the "real"
1614 entry in the hash table, thus we never get to see the real
1615 symbol in a hash traversal. So look at it now. */
1616 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1618 info
= (struct bfd_link_info
*) inf
;
1619 htab
= elf_i386_hash_table (info
);
1621 if (htab
->elf
.dynamic_sections_created
1622 && h
->plt
.refcount
> 0)
1624 /* Make sure this symbol is output as a dynamic symbol.
1625 Undefined weak syms won't yet be marked as dynamic. */
1626 if (h
->dynindx
== -1
1627 && !h
->forced_local
)
1629 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1634 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1636 asection
*s
= htab
->splt
;
1638 /* If this is the first .plt entry, make room for the special
1641 s
->size
+= PLT_ENTRY_SIZE
;
1643 h
->plt
.offset
= s
->size
;
1645 /* If this symbol is not defined in a regular file, and we are
1646 not generating a shared library, then set the symbol to this
1647 location in the .plt. This is required to make function
1648 pointers compare as equal between the normal executable and
1649 the shared library. */
1653 h
->root
.u
.def
.section
= s
;
1654 h
->root
.u
.def
.value
= h
->plt
.offset
;
1657 /* Make room for this entry. */
1658 s
->size
+= PLT_ENTRY_SIZE
;
1660 /* We also need to make an entry in the .got.plt section, which
1661 will be placed in the .got section by the linker script. */
1662 htab
->sgotplt
->size
+= 4;
1664 /* We also need to make an entry in the .rel.plt section. */
1665 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1666 htab
->next_tls_desc_index
++;
1668 if (htab
->is_vxworks
&& !info
->shared
)
1670 /* VxWorks has a second set of relocations for each PLT entry
1671 in executables. They go in a separate relocation section,
1672 which is processed by the kernel loader. */
1674 /* There are two relocations for the initial PLT entry: an
1675 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
1676 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
1678 if (h
->plt
.offset
== PLT_ENTRY_SIZE
)
1679 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1681 /* There are two extra relocations for each subsequent PLT entry:
1682 an R_386_32 relocation for the GOT entry, and an R_386_32
1683 relocation for the PLT entry. */
1685 htab
->srelplt2
->size
+= (sizeof (Elf32_External_Rel
) * 2);
1690 h
->plt
.offset
= (bfd_vma
) -1;
1696 h
->plt
.offset
= (bfd_vma
) -1;
1700 eh
= (struct elf_i386_link_hash_entry
*) h
;
1701 eh
->tlsdesc_got
= (bfd_vma
) -1;
1703 /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary,
1704 make it a R_386_TLS_LE_32 requiring no TLS entry. */
1705 if (h
->got
.refcount
> 0
1708 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
))
1709 h
->got
.offset
= (bfd_vma
) -1;
1710 else if (h
->got
.refcount
> 0)
1714 int tls_type
= elf_i386_hash_entry(h
)->tls_type
;
1716 /* Make sure this symbol is output as a dynamic symbol.
1717 Undefined weak syms won't yet be marked as dynamic. */
1718 if (h
->dynindx
== -1
1719 && !h
->forced_local
)
1721 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1726 if (GOT_TLS_GDESC_P (tls_type
))
1728 eh
->tlsdesc_got
= htab
->sgotplt
->size
1729 - elf_i386_compute_jump_table_size (htab
);
1730 htab
->sgotplt
->size
+= 8;
1731 h
->got
.offset
= (bfd_vma
) -2;
1733 if (! GOT_TLS_GDESC_P (tls_type
)
1734 || GOT_TLS_GD_P (tls_type
))
1736 h
->got
.offset
= s
->size
;
1738 /* R_386_TLS_GD needs 2 consecutive GOT slots. */
1739 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
1742 dyn
= htab
->elf
.dynamic_sections_created
;
1743 /* R_386_TLS_IE_32 needs one dynamic relocation,
1744 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
1745 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
1746 need two), R_386_TLS_GD needs one if local symbol and two if
1748 if (tls_type
== GOT_TLS_IE_BOTH
)
1749 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1750 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
1751 || (tls_type
& GOT_TLS_IE
))
1752 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1753 else if (GOT_TLS_GD_P (tls_type
))
1754 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rel
);
1755 else if (! GOT_TLS_GDESC_P (tls_type
)
1756 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1757 || h
->root
.type
!= bfd_link_hash_undefweak
)
1759 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1760 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
1761 if (GOT_TLS_GDESC_P (tls_type
))
1762 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
1765 h
->got
.offset
= (bfd_vma
) -1;
1767 if (eh
->dyn_relocs
== NULL
)
1770 /* In the shared -Bsymbolic case, discard space allocated for
1771 dynamic pc-relative relocs against symbols which turn out to be
1772 defined in regular objects. For the normal shared case, discard
1773 space for pc-relative relocs that have become local due to symbol
1774 visibility changes. */
1778 /* The only reloc that uses pc_count is R_386_PC32, which will
1779 appear on a call or on something like ".long foo - .". We
1780 want calls to protected symbols to resolve directly to the
1781 function rather than going via the plt. If people want
1782 function pointer comparisons to work as expected then they
1783 should avoid writing assembly like ".long foo - .". */
1784 if (SYMBOL_CALLS_LOCAL (info
, h
))
1786 struct elf_i386_dyn_relocs
**pp
;
1788 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1790 p
->count
-= p
->pc_count
;
1799 /* Also discard relocs on undefined weak syms with non-default
1801 if (eh
->dyn_relocs
!= NULL
1802 && h
->root
.type
== bfd_link_hash_undefweak
)
1804 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
1805 eh
->dyn_relocs
= NULL
;
1807 /* Make sure undefined weak symbols are output as a dynamic
1809 else if (h
->dynindx
== -1
1810 && !h
->forced_local
)
1812 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1817 else if (ELIMINATE_COPY_RELOCS
)
1819 /* For the non-shared case, discard space for relocs against
1820 symbols which turn out to need copy relocs or are not
1826 || (htab
->elf
.dynamic_sections_created
1827 && (h
->root
.type
== bfd_link_hash_undefweak
1828 || h
->root
.type
== bfd_link_hash_undefined
))))
1830 /* Make sure this symbol is output as a dynamic symbol.
1831 Undefined weak syms won't yet be marked as dynamic. */
1832 if (h
->dynindx
== -1
1833 && !h
->forced_local
)
1835 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1839 /* If that succeeded, we know we'll be keeping all the
1841 if (h
->dynindx
!= -1)
1845 eh
->dyn_relocs
= NULL
;
1850 /* Finally, allocate space. */
1851 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1853 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1854 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
1860 /* Find any dynamic relocs that apply to read-only sections. */
1863 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1865 struct elf_i386_link_hash_entry
*eh
;
1866 struct elf_i386_dyn_relocs
*p
;
1868 if (h
->root
.type
== bfd_link_hash_warning
)
1869 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1871 eh
= (struct elf_i386_link_hash_entry
*) h
;
1872 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1874 asection
*s
= p
->sec
->output_section
;
1876 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1878 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1880 info
->flags
|= DF_TEXTREL
;
1882 /* Not an error, just cut short the traversal. */
1889 /* Set the sizes of the dynamic sections. */
1892 elf_i386_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1893 struct bfd_link_info
*info
)
1895 struct elf_i386_link_hash_table
*htab
;
1901 htab
= elf_i386_hash_table (info
);
1902 dynobj
= htab
->elf
.dynobj
;
1906 if (htab
->elf
.dynamic_sections_created
)
1908 /* Set the contents of the .interp section to the interpreter. */
1909 if (info
->executable
)
1911 s
= bfd_get_section_by_name (dynobj
, ".interp");
1914 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1915 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1919 /* Set up .got offsets for local syms, and space for local dynamic
1921 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1923 bfd_signed_vma
*local_got
;
1924 bfd_signed_vma
*end_local_got
;
1925 char *local_tls_type
;
1926 bfd_vma
*local_tlsdesc_gotent
;
1927 bfd_size_type locsymcount
;
1928 Elf_Internal_Shdr
*symtab_hdr
;
1931 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1934 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1936 struct elf_i386_dyn_relocs
*p
;
1938 for (p
= ((struct elf_i386_dyn_relocs
*)
1939 elf_section_data (s
)->local_dynrel
);
1943 if (!bfd_is_abs_section (p
->sec
)
1944 && bfd_is_abs_section (p
->sec
->output_section
))
1946 /* Input section has been discarded, either because
1947 it is a copy of a linkonce section or due to
1948 linker script /DISCARD/, so we'll be discarding
1951 else if (p
->count
!= 0)
1953 srel
= elf_section_data (p
->sec
)->sreloc
;
1954 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
1955 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1956 info
->flags
|= DF_TEXTREL
;
1961 local_got
= elf_local_got_refcounts (ibfd
);
1965 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1966 locsymcount
= symtab_hdr
->sh_info
;
1967 end_local_got
= local_got
+ locsymcount
;
1968 local_tls_type
= elf_i386_local_got_tls_type (ibfd
);
1969 local_tlsdesc_gotent
= elf_i386_local_tlsdesc_gotent (ibfd
);
1971 srel
= htab
->srelgot
;
1972 for (; local_got
< end_local_got
;
1973 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
1975 *local_tlsdesc_gotent
= (bfd_vma
) -1;
1978 if (GOT_TLS_GDESC_P (*local_tls_type
))
1980 *local_tlsdesc_gotent
= htab
->sgotplt
->size
1981 - elf_i386_compute_jump_table_size (htab
);
1982 htab
->sgotplt
->size
+= 8;
1983 *local_got
= (bfd_vma
) -2;
1985 if (! GOT_TLS_GDESC_P (*local_tls_type
)
1986 || GOT_TLS_GD_P (*local_tls_type
))
1988 *local_got
= s
->size
;
1990 if (GOT_TLS_GD_P (*local_tls_type
)
1991 || *local_tls_type
== GOT_TLS_IE_BOTH
)
1995 || GOT_TLS_GD_ANY_P (*local_tls_type
)
1996 || (*local_tls_type
& GOT_TLS_IE
))
1998 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
1999 srel
->size
+= 2 * sizeof (Elf32_External_Rel
);
2000 else if (GOT_TLS_GD_P (*local_tls_type
)
2001 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2002 srel
->size
+= sizeof (Elf32_External_Rel
);
2003 if (GOT_TLS_GDESC_P (*local_tls_type
))
2004 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
2008 *local_got
= (bfd_vma
) -1;
2012 if (htab
->tls_ldm_got
.refcount
> 0)
2014 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2016 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
2017 htab
->sgot
->size
+= 8;
2018 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
2021 htab
->tls_ldm_got
.offset
= -1;
2023 /* Allocate global sym .plt and .got entries, and space for global
2024 sym dynamic relocs. */
2025 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
2027 /* For every jump slot reserved in the sgotplt, reloc_count is
2028 incremented. However, when we reserve space for TLS descriptors,
2029 it's not incremented, so in order to compute the space reserved
2030 for them, it suffices to multiply the reloc count by the jump
2033 htab
->sgotplt_jump_table_size
= htab
->next_tls_desc_index
* 4;
2035 /* We now have determined the sizes of the various dynamic sections.
2036 Allocate memory for them. */
2038 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2040 bfd_boolean strip_section
= TRUE
;
2042 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2047 || s
== htab
->sgotplt
2048 || s
== htab
->sdynbss
)
2050 /* Strip this section if we don't need it; see the
2052 /* We'd like to strip these sections if they aren't needed, but if
2053 we've exported dynamic symbols from them we must leave them.
2054 It's too late to tell BFD to get rid of the symbols. */
2056 if (htab
->elf
.hplt
!= NULL
)
2057 strip_section
= FALSE
;
2059 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rel"))
2061 if (s
->size
!= 0 && s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
2064 /* We use the reloc_count field as a counter if we need
2065 to copy relocs into the output file. */
2070 /* It's not one of our sections, so don't allocate space. */
2076 /* If we don't need this section, strip it from the
2077 output file. This is mostly to handle .rel.bss and
2078 .rel.plt. We must create both sections in
2079 create_dynamic_sections, because they must be created
2080 before the linker maps input sections to output
2081 sections. The linker does that before
2082 adjust_dynamic_symbol is called, and it is that
2083 function which decides whether anything needs to go
2084 into these sections. */
2086 s
->flags
|= SEC_EXCLUDE
;
2090 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2093 /* Allocate memory for the section contents. We use bfd_zalloc
2094 here in case unused entries are not reclaimed before the
2095 section's contents are written out. This should not happen,
2096 but this way if it does, we get a R_386_NONE reloc instead
2098 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
2099 if (s
->contents
== NULL
)
2103 if (htab
->elf
.dynamic_sections_created
)
2105 /* Add some entries to the .dynamic section. We fill in the
2106 values later, in elf_i386_finish_dynamic_sections, but we
2107 must add the entries now so that we get the correct size for
2108 the .dynamic section. The DT_DEBUG entry is filled in by the
2109 dynamic linker and used by the debugger. */
2110 #define add_dynamic_entry(TAG, VAL) \
2111 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2113 if (info
->executable
)
2115 if (!add_dynamic_entry (DT_DEBUG
, 0))
2119 if (htab
->splt
->size
!= 0)
2121 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2122 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2123 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
2124 || !add_dynamic_entry (DT_JMPREL
, 0))
2130 if (!add_dynamic_entry (DT_REL
, 0)
2131 || !add_dynamic_entry (DT_RELSZ
, 0)
2132 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
2135 /* If any dynamic relocs apply to a read-only section,
2136 then we need a DT_TEXTREL entry. */
2137 if ((info
->flags
& DF_TEXTREL
) == 0)
2138 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2141 if ((info
->flags
& DF_TEXTREL
) != 0)
2143 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2148 #undef add_dynamic_entry
2154 elf_i386_always_size_sections (bfd
*output_bfd
,
2155 struct bfd_link_info
*info
)
2157 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2161 struct elf_link_hash_entry
*tlsbase
;
2163 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2164 "_TLS_MODULE_BASE_",
2165 FALSE
, FALSE
, FALSE
);
2167 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2169 struct bfd_link_hash_entry
*bh
= NULL
;
2170 const struct elf_backend_data
*bed
2171 = get_elf_backend_data (output_bfd
);
2173 if (!(_bfd_generic_link_add_one_symbol
2174 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2175 tls_sec
, 0, NULL
, FALSE
,
2176 bed
->collect
, &bh
)))
2178 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2179 tlsbase
->def_regular
= 1;
2180 tlsbase
->other
= STV_HIDDEN
;
2181 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2188 /* Set the correct type for an x86 ELF section. We do this by the
2189 section name, which is a hack, but ought to work. */
2192 elf_i386_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2193 Elf_Internal_Shdr
*hdr
,
2196 register const char *name
;
2198 name
= bfd_get_section_name (abfd
, sec
);
2200 /* This is an ugly, but unfortunately necessary hack that is
2201 needed when producing EFI binaries on x86. It tells
2202 elf.c:elf_fake_sections() not to consider ".reloc" as a section
2203 containing ELF relocation info. We need this hack in order to
2204 be able to generate ELF binaries that can be translated into
2205 EFI applications (which are essentially COFF objects). Those
2206 files contain a COFF ".reloc" section inside an ELFNN object,
2207 which would normally cause BFD to segfault because it would
2208 attempt to interpret this section as containing relocation
2209 entries for section "oc". With this hack enabled, ".reloc"
2210 will be treated as a normal data section, which will avoid the
2211 segfault. However, you won't be able to create an ELFNN binary
2212 with a section named "oc" that needs relocations, but that's
2213 the kind of ugly side-effects you get when detecting section
2214 types based on their names... In practice, this limitation is
2215 unlikely to bite. */
2216 if (strcmp (name
, ".reloc") == 0)
2217 hdr
->sh_type
= SHT_PROGBITS
;
2222 /* Return the base VMA address which should be subtracted from real addresses
2223 when resolving @dtpoff relocation.
2224 This is PT_TLS segment p_vaddr. */
2227 dtpoff_base (struct bfd_link_info
*info
)
2229 /* If tls_sec is NULL, we should have signalled an error already. */
2230 if (elf_hash_table (info
)->tls_sec
== NULL
)
2232 return elf_hash_table (info
)->tls_sec
->vma
;
2235 /* Return the relocation value for @tpoff relocation
2236 if STT_TLS virtual address is ADDRESS. */
2239 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2241 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2243 /* If tls_sec is NULL, we should have signalled an error already. */
2244 if (htab
->tls_sec
== NULL
)
2246 return htab
->tls_size
+ htab
->tls_sec
->vma
- address
;
2249 /* Relocate an i386 ELF section. */
2252 elf_i386_relocate_section (bfd
*output_bfd
,
2253 struct bfd_link_info
*info
,
2255 asection
*input_section
,
2257 Elf_Internal_Rela
*relocs
,
2258 Elf_Internal_Sym
*local_syms
,
2259 asection
**local_sections
)
2261 struct elf_i386_link_hash_table
*htab
;
2262 Elf_Internal_Shdr
*symtab_hdr
;
2263 struct elf_link_hash_entry
**sym_hashes
;
2264 bfd_vma
*local_got_offsets
;
2265 bfd_vma
*local_tlsdesc_gotents
;
2266 Elf_Internal_Rela
*rel
;
2267 Elf_Internal_Rela
*relend
;
2269 htab
= elf_i386_hash_table (info
);
2270 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2271 sym_hashes
= elf_sym_hashes (input_bfd
);
2272 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2273 local_tlsdesc_gotents
= elf_i386_local_tlsdesc_gotent (input_bfd
);
2276 relend
= relocs
+ input_section
->reloc_count
;
2277 for (; rel
< relend
; rel
++)
2279 unsigned int r_type
;
2280 reloc_howto_type
*howto
;
2281 unsigned long r_symndx
;
2282 struct elf_link_hash_entry
*h
;
2283 Elf_Internal_Sym
*sym
;
2285 bfd_vma off
, offplt
;
2287 bfd_boolean unresolved_reloc
;
2288 bfd_reloc_status_type r
;
2292 r_type
= ELF32_R_TYPE (rel
->r_info
);
2293 if (r_type
== R_386_GNU_VTINHERIT
2294 || r_type
== R_386_GNU_VTENTRY
)
2297 if ((indx
= r_type
) >= R_386_standard
2298 && ((indx
= r_type
- R_386_ext_offset
) - R_386_standard
2299 >= R_386_ext
- R_386_standard
)
2300 && ((indx
= r_type
- R_386_tls_offset
) - R_386_ext
2301 >= R_386_tls
- R_386_ext
))
2303 (*_bfd_error_handler
)
2304 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2305 input_bfd
, input_section
, r_type
);
2306 bfd_set_error (bfd_error_bad_value
);
2309 howto
= elf_howto_table
+ indx
;
2311 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2315 unresolved_reloc
= FALSE
;
2316 if (r_symndx
< symtab_hdr
->sh_info
)
2318 sym
= local_syms
+ r_symndx
;
2319 sec
= local_sections
[r_symndx
];
2320 relocation
= (sec
->output_section
->vma
2321 + sec
->output_offset
2324 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2325 && ((sec
->flags
& SEC_MERGE
) != 0
2326 || (info
->relocatable
2327 && sec
->output_offset
!= 0)))
2330 bfd_byte
*where
= contents
+ rel
->r_offset
;
2332 switch (howto
->size
)
2335 addend
= bfd_get_8 (input_bfd
, where
);
2336 if (howto
->pc_relative
)
2338 addend
= (addend
^ 0x80) - 0x80;
2343 addend
= bfd_get_16 (input_bfd
, where
);
2344 if (howto
->pc_relative
)
2346 addend
= (addend
^ 0x8000) - 0x8000;
2351 addend
= bfd_get_32 (input_bfd
, where
);
2352 if (howto
->pc_relative
)
2354 addend
= (addend
^ 0x80000000) - 0x80000000;
2362 if (info
->relocatable
)
2363 addend
+= sec
->output_offset
;
2366 asection
*msec
= sec
;
2367 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
,
2369 addend
-= relocation
;
2370 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2373 switch (howto
->size
)
2376 /* FIXME: overflow checks. */
2377 if (howto
->pc_relative
)
2379 bfd_put_8 (input_bfd
, addend
, where
);
2382 if (howto
->pc_relative
)
2384 bfd_put_16 (input_bfd
, addend
, where
);
2387 if (howto
->pc_relative
)
2389 bfd_put_32 (input_bfd
, addend
, where
);
2398 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2399 r_symndx
, symtab_hdr
, sym_hashes
,
2401 unresolved_reloc
, warned
);
2404 if (sec
!= NULL
&& elf_discarded_section (sec
))
2406 /* For relocs against symbols from removed linkonce sections,
2407 or sections discarded by a linker script, we just want the
2408 section contents zeroed. Avoid any special processing. */
2409 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2415 if (info
->relocatable
)
2421 /* Relocation is to the entry for this symbol in the global
2423 if (htab
->sgot
== NULL
)
2430 off
= h
->got
.offset
;
2431 dyn
= htab
->elf
.dynamic_sections_created
;
2432 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2434 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2435 || (ELF_ST_VISIBILITY (h
->other
)
2436 && h
->root
.type
== bfd_link_hash_undefweak
))
2438 /* This is actually a static link, or it is a
2439 -Bsymbolic link and the symbol is defined
2440 locally, or the symbol was forced to be local
2441 because of a version file. We must initialize
2442 this entry in the global offset table. Since the
2443 offset must always be a multiple of 4, we use the
2444 least significant bit to record whether we have
2445 initialized it already.
2447 When doing a dynamic link, we create a .rel.got
2448 relocation entry to initialize the value. This
2449 is done in the finish_dynamic_symbol routine. */
2454 bfd_put_32 (output_bfd
, relocation
,
2455 htab
->sgot
->contents
+ off
);
2460 unresolved_reloc
= FALSE
;
2464 if (local_got_offsets
== NULL
)
2467 off
= local_got_offsets
[r_symndx
];
2469 /* The offset must always be a multiple of 4. We use
2470 the least significant bit to record whether we have
2471 already generated the necessary reloc. */
2476 bfd_put_32 (output_bfd
, relocation
,
2477 htab
->sgot
->contents
+ off
);
2482 Elf_Internal_Rela outrel
;
2489 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2490 + htab
->sgot
->output_offset
2492 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2494 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2495 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2498 local_got_offsets
[r_symndx
] |= 1;
2502 if (off
>= (bfd_vma
) -2)
2505 relocation
= htab
->sgot
->output_section
->vma
2506 + htab
->sgot
->output_offset
+ off
2507 - htab
->sgotplt
->output_section
->vma
2508 - htab
->sgotplt
->output_offset
;
2512 /* Relocation is relative to the start of the global offset
2515 /* Check to make sure it isn't a protected function symbol
2516 for shared library since it may not be local when used
2517 as function address. */
2519 && !info
->executable
2522 && h
->type
== STT_FUNC
2523 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2525 (*_bfd_error_handler
)
2526 (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
2527 input_bfd
, h
->root
.root
.string
);
2528 bfd_set_error (bfd_error_bad_value
);
2532 /* Note that sgot is not involved in this
2533 calculation. We always want the start of .got.plt. If we
2534 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2535 permitted by the ABI, we might have to change this
2537 relocation
-= htab
->sgotplt
->output_section
->vma
2538 + htab
->sgotplt
->output_offset
;
2542 /* Use global offset table as symbol value. */
2543 relocation
= htab
->sgotplt
->output_section
->vma
2544 + htab
->sgotplt
->output_offset
;
2545 unresolved_reloc
= FALSE
;
2549 /* Relocation is to the entry for this symbol in the
2550 procedure linkage table. */
2552 /* Resolve a PLT32 reloc against a local symbol directly,
2553 without using the procedure linkage table. */
2557 if (h
->plt
.offset
== (bfd_vma
) -1
2558 || htab
->splt
== NULL
)
2560 /* We didn't make a PLT entry for this symbol. This
2561 happens when statically linking PIC code, or when
2562 using -Bsymbolic. */
2566 relocation
= (htab
->splt
->output_section
->vma
2567 + htab
->splt
->output_offset
2569 unresolved_reloc
= FALSE
;
2574 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2579 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2580 || h
->root
.type
!= bfd_link_hash_undefweak
)
2581 && (r_type
!= R_386_PC32
2582 || !SYMBOL_CALLS_LOCAL (info
, h
)))
2583 || (ELIMINATE_COPY_RELOCS
2590 || h
->root
.type
== bfd_link_hash_undefweak
2591 || h
->root
.type
== bfd_link_hash_undefined
)))
2593 Elf_Internal_Rela outrel
;
2595 bfd_boolean skip
, relocate
;
2598 /* When generating a shared object, these relocations
2599 are copied into the output file to be resolved at run
2606 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2608 if (outrel
.r_offset
== (bfd_vma
) -1)
2610 else if (outrel
.r_offset
== (bfd_vma
) -2)
2611 skip
= TRUE
, relocate
= TRUE
;
2612 outrel
.r_offset
+= (input_section
->output_section
->vma
2613 + input_section
->output_offset
);
2616 memset (&outrel
, 0, sizeof outrel
);
2619 && (r_type
== R_386_PC32
2621 || !SYMBOLIC_BIND (info
, h
)
2622 || !h
->def_regular
))
2623 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2626 /* This symbol is local, or marked to become local. */
2628 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2631 sreloc
= elf_section_data (input_section
)->sreloc
;
2635 loc
= sreloc
->contents
;
2636 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2637 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2639 /* If this reloc is against an external symbol, we do
2640 not want to fiddle with the addend. Otherwise, we
2641 need to include the symbol value so that it becomes
2642 an addend for the dynamic reloc. */
2651 Elf_Internal_Rela outrel
;
2655 outrel
.r_offset
= rel
->r_offset
2656 + input_section
->output_section
->vma
2657 + input_section
->output_offset
;
2658 outrel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
2659 sreloc
= elf_section_data (input_section
)->sreloc
;
2662 loc
= sreloc
->contents
;
2663 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2664 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2669 case R_386_TLS_GOTDESC
:
2670 case R_386_TLS_DESC_CALL
:
2671 case R_386_TLS_IE_32
:
2672 case R_386_TLS_GOTIE
:
2673 r_type
= elf_i386_tls_transition (info
, r_type
, h
== NULL
);
2674 tls_type
= GOT_UNKNOWN
;
2675 if (h
== NULL
&& local_got_offsets
)
2676 tls_type
= elf_i386_local_got_tls_type (input_bfd
) [r_symndx
];
2679 tls_type
= elf_i386_hash_entry(h
)->tls_type
;
2680 if (!info
->shared
&& h
->dynindx
== -1 && (tls_type
& GOT_TLS_IE
))
2681 r_type
= R_386_TLS_LE_32
;
2683 if (tls_type
== GOT_TLS_IE
)
2684 tls_type
= GOT_TLS_IE_NEG
;
2685 if (r_type
== R_386_TLS_GD
2686 || r_type
== R_386_TLS_GOTDESC
2687 || r_type
== R_386_TLS_DESC_CALL
)
2689 if (tls_type
== GOT_TLS_IE_POS
)
2690 r_type
= R_386_TLS_GOTIE
;
2691 else if (tls_type
& GOT_TLS_IE
)
2692 r_type
= R_386_TLS_IE_32
;
2695 /* Don't attempt to rewrite General Dynamic code sequences,
2696 because the NaCl assembler will put no-ops into the
2697 middle of the sequence before the call, which we can't
2699 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
2700 r_type
= R_386_TLS_GD
;
2702 if (r_type
== R_386_TLS_LE_32
)
2704 BFD_ASSERT (! unresolved_reloc
);
2705 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
2707 unsigned int val
, type
;
2710 /* GD->LE transition. */
2711 BFD_ASSERT (rel
->r_offset
>= 2);
2712 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2713 BFD_ASSERT (type
== 0x8d || type
== 0x04);
2714 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
2715 BFD_ASSERT (bfd_get_8 (input_bfd
,
2716 contents
+ rel
->r_offset
+ 4)
2718 BFD_ASSERT (rel
+ 1 < relend
);
2719 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
2720 roff
= rel
->r_offset
+ 5;
2721 val
= bfd_get_8 (input_bfd
,
2722 contents
+ rel
->r_offset
- 1);
2725 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
2727 movl %gs:0, %eax; subl $foo@tpoff, %eax
2728 (6 byte form of subl). */
2729 BFD_ASSERT (rel
->r_offset
>= 3);
2730 BFD_ASSERT (bfd_get_8 (input_bfd
,
2731 contents
+ rel
->r_offset
- 3)
2733 BFD_ASSERT ((val
& 0xc7) == 0x05 && val
!= (4 << 3));
2734 memcpy (contents
+ rel
->r_offset
- 3,
2735 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2739 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
2740 if (rel
->r_offset
+ 10 <= input_section
->size
2741 && bfd_get_8 (input_bfd
,
2742 contents
+ rel
->r_offset
+ 9) == 0x90)
2744 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
2746 movl %gs:0, %eax; subl $foo@tpoff, %eax
2747 (6 byte form of subl). */
2748 memcpy (contents
+ rel
->r_offset
- 2,
2749 "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
2750 roff
= rel
->r_offset
+ 6;
2754 /* leal foo(%reg), %eax; call ___tls_get_addr
2756 movl %gs:0, %eax; subl $foo@tpoff, %eax
2757 (5 byte form of subl). */
2758 memcpy (contents
+ rel
->r_offset
- 2,
2759 "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
2762 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2764 /* Skip R_386_PLT32. */
2768 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
2770 /* GDesc -> LE transition.
2771 It's originally something like:
2772 leal x@tlsdesc(%ebx), %eax
2776 Registers other than %eax may be set up here. */
2778 unsigned int val
, type
;
2781 /* First, make sure it's a leal adding ebx to a
2782 32-bit offset into any register, although it's
2783 probably almost always going to be eax. */
2784 roff
= rel
->r_offset
;
2785 BFD_ASSERT (roff
>= 2);
2786 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
2787 BFD_ASSERT (type
== 0x8d);
2788 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
2789 BFD_ASSERT ((val
& 0xc7) == 0x83);
2790 BFD_ASSERT (roff
+ 4 <= input_section
->size
);
2792 /* Now modify the instruction as appropriate. */
2793 /* aoliva FIXME: remove the above and xor the byte
2795 bfd_put_8 (output_bfd
, val
^ 0x86,
2796 contents
+ roff
- 1);
2797 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2801 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
2803 /* GDesc -> LE transition.
2809 unsigned int val
, type
;
2812 /* First, make sure it's a call *(%eax). */
2813 roff
= rel
->r_offset
;
2814 BFD_ASSERT (roff
+ 2 <= input_section
->size
);
2815 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
2816 BFD_ASSERT (type
== 0xff);
2817 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
2818 BFD_ASSERT (val
== 0x10);
2820 /* Now modify the instruction as appropriate. Use
2821 xchg %ax,%ax instead of 2 nops. */
2822 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
2823 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
2826 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_IE
)
2828 unsigned int val
, type
;
2830 /* IE->LE transition:
2831 Originally it can be one of:
2839 BFD_ASSERT (rel
->r_offset
>= 1);
2840 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2841 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->size
);
2844 /* movl foo, %eax. */
2845 bfd_put_8 (output_bfd
, 0xb8,
2846 contents
+ rel
->r_offset
- 1);
2850 BFD_ASSERT (rel
->r_offset
>= 2);
2851 type
= bfd_get_8 (input_bfd
,
2852 contents
+ rel
->r_offset
- 2);
2857 BFD_ASSERT ((val
& 0xc7) == 0x05);
2858 bfd_put_8 (output_bfd
, 0xc7,
2859 contents
+ rel
->r_offset
- 2);
2860 bfd_put_8 (output_bfd
,
2861 0xc0 | ((val
>> 3) & 7),
2862 contents
+ rel
->r_offset
- 1);
2866 BFD_ASSERT ((val
& 0xc7) == 0x05);
2867 bfd_put_8 (output_bfd
, 0x81,
2868 contents
+ rel
->r_offset
- 2);
2869 bfd_put_8 (output_bfd
,
2870 0xc0 | ((val
>> 3) & 7),
2871 contents
+ rel
->r_offset
- 1);
2878 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2879 contents
+ rel
->r_offset
);
2884 unsigned int val
, type
;
2886 /* {IE_32,GOTIE}->LE transition:
2887 Originally it can be one of:
2888 subl foo(%reg1), %reg2
2889 movl foo(%reg1), %reg2
2890 addl foo(%reg1), %reg2
2893 movl $foo, %reg2 (6 byte form)
2894 addl $foo, %reg2. */
2895 BFD_ASSERT (rel
->r_offset
>= 2);
2896 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2897 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2898 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->size
);
2899 BFD_ASSERT ((val
& 0xc0) == 0x80 && (val
& 7) != 4);
2903 bfd_put_8 (output_bfd
, 0xc7,
2904 contents
+ rel
->r_offset
- 2);
2905 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
2906 contents
+ rel
->r_offset
- 1);
2908 else if (type
== 0x2b)
2911 bfd_put_8 (output_bfd
, 0x81,
2912 contents
+ rel
->r_offset
- 2);
2913 bfd_put_8 (output_bfd
, 0xe8 | ((val
>> 3) & 7),
2914 contents
+ rel
->r_offset
- 1);
2916 else if (type
== 0x03)
2919 bfd_put_8 (output_bfd
, 0x81,
2920 contents
+ rel
->r_offset
- 2);
2921 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
2922 contents
+ rel
->r_offset
- 1);
2926 if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTIE
)
2927 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2928 contents
+ rel
->r_offset
);
2930 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2931 contents
+ rel
->r_offset
);
2936 if (htab
->sgot
== NULL
)
2941 off
= h
->got
.offset
;
2942 offplt
= elf_i386_hash_entry (h
)->tlsdesc_got
;
2946 if (local_got_offsets
== NULL
)
2949 off
= local_got_offsets
[r_symndx
];
2950 offplt
= local_tlsdesc_gotents
[r_symndx
];
2957 Elf_Internal_Rela outrel
;
2962 if (htab
->srelgot
== NULL
)
2965 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2967 if (GOT_TLS_GDESC_P (tls_type
))
2969 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_DESC
);
2970 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
+ 8
2971 <= htab
->sgotplt
->size
);
2972 outrel
.r_offset
= (htab
->sgotplt
->output_section
->vma
2973 + htab
->sgotplt
->output_offset
2975 + htab
->sgotplt_jump_table_size
);
2976 sreloc
= htab
->srelplt
;
2977 loc
= sreloc
->contents
;
2978 loc
+= (htab
->next_tls_desc_index
++
2979 * sizeof (Elf32_External_Rel
));
2980 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
2981 <= sreloc
->contents
+ sreloc
->size
);
2982 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2985 BFD_ASSERT (! unresolved_reloc
);
2986 bfd_put_32 (output_bfd
,
2987 relocation
- dtpoff_base (info
),
2988 htab
->sgotplt
->contents
+ offplt
2989 + htab
->sgotplt_jump_table_size
+ 4);
2993 bfd_put_32 (output_bfd
, 0,
2994 htab
->sgotplt
->contents
+ offplt
2995 + htab
->sgotplt_jump_table_size
+ 4);
2999 sreloc
= htab
->srelgot
;
3001 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3002 + htab
->sgot
->output_offset
+ off
);
3004 if (GOT_TLS_GD_P (tls_type
))
3005 dr_type
= R_386_TLS_DTPMOD32
;
3006 else if (GOT_TLS_GDESC_P (tls_type
))
3008 else if (tls_type
== GOT_TLS_IE_POS
)
3009 dr_type
= R_386_TLS_TPOFF
;
3011 dr_type
= R_386_TLS_TPOFF32
;
3013 if (dr_type
== R_386_TLS_TPOFF
&& indx
== 0)
3014 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3015 htab
->sgot
->contents
+ off
);
3016 else if (dr_type
== R_386_TLS_TPOFF32
&& indx
== 0)
3017 bfd_put_32 (output_bfd
, dtpoff_base (info
) - relocation
,
3018 htab
->sgot
->contents
+ off
);
3019 else if (dr_type
!= R_386_TLS_DESC
)
3020 bfd_put_32 (output_bfd
, 0,
3021 htab
->sgot
->contents
+ off
);
3022 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
3024 loc
= sreloc
->contents
;
3025 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3026 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3027 <= sreloc
->contents
+ sreloc
->size
);
3028 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3030 if (GOT_TLS_GD_P (tls_type
))
3034 BFD_ASSERT (! unresolved_reloc
);
3035 bfd_put_32 (output_bfd
,
3036 relocation
- dtpoff_base (info
),
3037 htab
->sgot
->contents
+ off
+ 4);
3041 bfd_put_32 (output_bfd
, 0,
3042 htab
->sgot
->contents
+ off
+ 4);
3043 outrel
.r_info
= ELF32_R_INFO (indx
,
3044 R_386_TLS_DTPOFF32
);
3045 outrel
.r_offset
+= 4;
3046 sreloc
->reloc_count
++;
3047 loc
+= sizeof (Elf32_External_Rel
);
3048 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rel
)
3049 <= sreloc
->contents
+ sreloc
->size
);
3050 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3053 else if (tls_type
== GOT_TLS_IE_BOTH
)
3055 bfd_put_32 (output_bfd
,
3056 indx
== 0 ? relocation
- dtpoff_base (info
) : 0,
3057 htab
->sgot
->contents
+ off
+ 4);
3058 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3059 outrel
.r_offset
+= 4;
3060 sreloc
->reloc_count
++;
3061 loc
+= sizeof (Elf32_External_Rel
);
3062 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3069 local_got_offsets
[r_symndx
] |= 1;
3072 if (off
>= (bfd_vma
) -2
3073 && ! GOT_TLS_GDESC_P (tls_type
))
3075 if (r_type
== R_386_TLS_GOTDESC
3076 || r_type
== R_386_TLS_DESC_CALL
)
3078 relocation
= htab
->sgotplt_jump_table_size
+ offplt
;
3079 unresolved_reloc
= FALSE
;
3081 else if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3083 bfd_vma g_o_t
= htab
->sgotplt
->output_section
->vma
3084 + htab
->sgotplt
->output_offset
;
3085 relocation
= htab
->sgot
->output_section
->vma
3086 + htab
->sgot
->output_offset
+ off
- g_o_t
;
3087 if ((r_type
== R_386_TLS_IE
|| r_type
== R_386_TLS_GOTIE
)
3088 && tls_type
== GOT_TLS_IE_BOTH
)
3090 if (r_type
== R_386_TLS_IE
)
3091 relocation
+= g_o_t
;
3092 unresolved_reloc
= FALSE
;
3094 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GD
)
3096 unsigned int val
, type
;
3099 /* GD->IE transition. */
3100 BFD_ASSERT (rel
->r_offset
>= 2);
3101 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
3102 BFD_ASSERT (type
== 0x8d || type
== 0x04);
3103 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
3104 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
3106 BFD_ASSERT (rel
+ 1 < relend
);
3107 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
3108 roff
= rel
->r_offset
- 3;
3109 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3112 /* leal foo(,%reg,1), %eax; call ___tls_get_addr
3114 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3115 BFD_ASSERT (rel
->r_offset
>= 3);
3116 BFD_ASSERT (bfd_get_8 (input_bfd
,
3117 contents
+ rel
->r_offset
- 3)
3119 BFD_ASSERT ((val
& 0xc7) == 0x05 && val
!= (4 << 3));
3124 /* leal foo(%reg), %eax; call ___tls_get_addr; nop
3126 movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
3127 BFD_ASSERT (rel
->r_offset
+ 10 <= input_section
->size
);
3128 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
3129 BFD_ASSERT (bfd_get_8 (input_bfd
,
3130 contents
+ rel
->r_offset
+ 9)
3132 roff
= rel
->r_offset
- 2;
3134 memcpy (contents
+ roff
,
3135 "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
3136 contents
[roff
+ 7] = 0x80 | (val
& 7);
3137 /* If foo is used only with foo@gotntpoff(%reg) and
3138 foo@indntpoff, but not with foo@gottpoff(%reg), change
3139 subl $foo@gottpoff(%reg), %eax
3141 addl $foo@gotntpoff(%reg), %eax. */
3142 if (tls_type
== GOT_TLS_IE_POS
)
3143 contents
[roff
+ 6] = 0x03;
3144 bfd_put_32 (output_bfd
,
3145 htab
->sgot
->output_section
->vma
3146 + htab
->sgot
->output_offset
+ off
3147 - htab
->sgotplt
->output_section
->vma
3148 - htab
->sgotplt
->output_offset
,
3149 contents
+ roff
+ 8);
3150 /* Skip R_386_PLT32. */
3154 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_GOTDESC
)
3156 /* GDesc -> IE transition.
3157 It's originally something like:
3158 leal x@tlsdesc(%ebx), %eax
3161 movl x@gotntpoff(%ebx), %eax # before nop; nop
3163 movl x@gottpoff(%ebx), %eax # before negl %eax
3165 Registers other than %eax may be set up here. */
3167 unsigned int val
, type
;
3170 /* First, make sure it's a leal adding ebx to a 32-bit
3171 offset into any register, although it's probably
3172 almost always going to be eax. */
3173 roff
= rel
->r_offset
;
3174 BFD_ASSERT (roff
>= 2);
3175 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3176 BFD_ASSERT (type
== 0x8d);
3177 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3178 BFD_ASSERT ((val
& 0xc7) == 0x83);
3179 BFD_ASSERT (roff
+ 4 <= input_section
->size
);
3181 /* Now modify the instruction as appropriate. */
3182 /* To turn a leal into a movl in the form we use it, it
3183 suffices to change the first byte from 0x8d to 0x8b.
3184 aoliva FIXME: should we decide to keep the leal, all
3185 we have to do is remove the statement below, and
3186 adjust the relaxation of R_386_TLS_DESC_CALL. */
3187 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3189 if (tls_type
== GOT_TLS_IE_BOTH
)
3192 bfd_put_32 (output_bfd
,
3193 htab
->sgot
->output_section
->vma
3194 + htab
->sgot
->output_offset
+ off
3195 - htab
->sgotplt
->output_section
->vma
3196 - htab
->sgotplt
->output_offset
,
3200 else if (ELF32_R_TYPE (rel
->r_info
) == R_386_TLS_DESC_CALL
)
3202 /* GDesc -> IE transition.
3210 depending on how we transformed the TLS_GOTDESC above.
3213 unsigned int val
, type
;
3216 /* First, make sure it's a call *(%eax). */
3217 roff
= rel
->r_offset
;
3218 BFD_ASSERT (roff
+ 2 <= input_section
->size
);
3219 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
3220 BFD_ASSERT (type
== 0xff);
3221 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
3222 BFD_ASSERT (val
== 0x10);
3224 /* Now modify the instruction as appropriate. */
3225 if (tls_type
!= GOT_TLS_IE_NEG
)
3228 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3229 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3234 bfd_put_8 (output_bfd
, 0xf7, contents
+ roff
);
3235 bfd_put_8 (output_bfd
, 0xd8, contents
+ roff
+ 1);
3249 /* LD->LE transition:
3251 leal foo(%reg), %eax; call ___tls_get_addr.
3253 movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
3254 BFD_ASSERT (rel
->r_offset
>= 2);
3255 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2)
3257 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
3258 BFD_ASSERT ((val
& 0xf8) == 0x80 && (val
& 7) != 4);
3259 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
3260 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
3262 BFD_ASSERT (rel
+ 1 < relend
);
3263 BFD_ASSERT (ELF32_R_TYPE (rel
[1].r_info
) == R_386_PLT32
);
3264 memcpy (contents
+ rel
->r_offset
- 2,
3265 "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
3266 /* Skip R_386_PLT32. */
3271 if (htab
->sgot
== NULL
)
3274 off
= htab
->tls_ldm_got
.offset
;
3279 Elf_Internal_Rela outrel
;
3282 if (htab
->srelgot
== NULL
)
3285 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3286 + htab
->sgot
->output_offset
+ off
);
3288 bfd_put_32 (output_bfd
, 0,
3289 htab
->sgot
->contents
+ off
);
3290 bfd_put_32 (output_bfd
, 0,
3291 htab
->sgot
->contents
+ off
+ 4);
3292 outrel
.r_info
= ELF32_R_INFO (0, R_386_TLS_DTPMOD32
);
3293 loc
= htab
->srelgot
->contents
;
3294 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3295 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3296 htab
->tls_ldm_got
.offset
|= 1;
3298 relocation
= htab
->sgot
->output_section
->vma
3299 + htab
->sgot
->output_offset
+ off
3300 - htab
->sgotplt
->output_section
->vma
3301 - htab
->sgotplt
->output_offset
;
3302 unresolved_reloc
= FALSE
;
3305 case R_386_TLS_LDO_32
:
3306 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3307 relocation
-= dtpoff_base (info
);
3309 /* When converting LDO to LE, we must negate. */
3310 relocation
= -tpoff (info
, relocation
);
3313 case R_386_TLS_LE_32
:
3317 Elf_Internal_Rela outrel
;
3322 outrel
.r_offset
= rel
->r_offset
3323 + input_section
->output_section
->vma
3324 + input_section
->output_offset
;
3325 if (h
!= NULL
&& h
->dynindx
!= -1)
3329 if (r_type
== R_386_TLS_LE_32
)
3330 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF32
);
3332 outrel
.r_info
= ELF32_R_INFO (indx
, R_386_TLS_TPOFF
);
3333 sreloc
= elf_section_data (input_section
)->sreloc
;
3336 loc
= sreloc
->contents
;
3337 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3338 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3341 else if (r_type
== R_386_TLS_LE_32
)
3342 relocation
= dtpoff_base (info
) - relocation
;
3344 relocation
-= dtpoff_base (info
);
3346 else if (r_type
== R_386_TLS_LE_32
)
3347 relocation
= tpoff (info
, relocation
);
3349 relocation
= -tpoff (info
, relocation
);
3356 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3357 because such sections are not SEC_ALLOC and thus ld.so will
3358 not process them. */
3359 if (unresolved_reloc
3360 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3363 (*_bfd_error_handler
)
3364 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3367 (long) rel
->r_offset
,
3369 h
->root
.root
.string
);
3373 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3374 contents
, rel
->r_offset
,
3377 if (r
!= bfd_reloc_ok
)
3382 name
= h
->root
.root
.string
;
3385 name
= bfd_elf_string_from_elf_section (input_bfd
,
3386 symtab_hdr
->sh_link
,
3391 name
= bfd_section_name (input_bfd
, sec
);
3394 if (r
== bfd_reloc_overflow
)
3396 if (! ((*info
->callbacks
->reloc_overflow
)
3397 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3398 (bfd_vma
) 0, input_bfd
, input_section
,
3404 (*_bfd_error_handler
)
3405 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3406 input_bfd
, input_section
,
3407 (long) rel
->r_offset
, name
, (int) r
);
3416 /* Finish up dynamic symbol handling. We set the contents of various
3417 dynamic sections here. */
3420 elf_i386_finish_dynamic_symbol (bfd
*output_bfd
,
3421 struct bfd_link_info
*info
,
3422 struct elf_link_hash_entry
*h
,
3423 Elf_Internal_Sym
*sym
)
3425 struct elf_i386_link_hash_table
*htab
;
3427 htab
= elf_i386_hash_table (info
);
3429 if (h
->plt
.offset
!= (bfd_vma
) -1)
3433 Elf_Internal_Rela rel
;
3436 /* This symbol has an entry in the procedure linkage table. Set
3439 if (h
->dynindx
== -1
3440 || htab
->splt
== NULL
3441 || htab
->sgotplt
== NULL
3442 || htab
->srelplt
== NULL
)
3445 /* Get the index in the procedure linkage table which
3446 corresponds to this symbol. This is the index of this symbol
3447 in all the symbols for which we are making plt entries. The
3448 first entry in the procedure linkage table is reserved. */
3449 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3451 /* Get the offset into the .got table of the entry that
3452 corresponds to this function. Each .got entry is 4 bytes.
3453 The first three are reserved. */
3454 got_offset
= (plt_index
+ 3) * 4;
3456 /* Fill in the entry in the procedure linkage table. */
3459 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_plt_entry
,
3461 bfd_put_32 (output_bfd
,
3462 (htab
->sgotplt
->output_section
->vma
3463 + htab
->sgotplt
->output_offset
3465 htab
->splt
->contents
+ h
->plt
.offset
+
3466 elf_i386_plt_entry_offset1
);
3468 if (htab
->is_vxworks
)
3470 int s
, k
, reloc_index
;
3472 /* Create the R_386_32 relocation referencing the GOT
3473 for this PLT entry. */
3475 /* S: Current slot number (zero-based). */
3476 s
= (h
->plt
.offset
- PLT_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3477 /* K: Number of relocations for PLTResolve. */
3479 k
= PLTRESOLVE_RELOCS_SHLIB
;
3481 k
= PLTRESOLVE_RELOCS
;
3482 /* Skip the PLTresolve relocations, and the relocations for
3483 the other PLT slots. */
3484 reloc_index
= k
+ s
* PLT_NON_JUMP_SLOT_RELOCS
;
3485 loc
= (htab
->srelplt2
->contents
+ reloc_index
3486 * sizeof (Elf32_External_Rel
));
3488 rel
.r_offset
= (htab
->splt
->output_section
->vma
3489 + htab
->splt
->output_offset
3490 + h
->plt
.offset
+ 2),
3491 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3492 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3494 /* Create the R_386_32 relocation referencing the beginning of
3495 the PLT for this GOT entry. */
3496 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3497 + htab
->sgotplt
->output_offset
3499 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3500 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3501 loc
+ sizeof (Elf32_External_Rel
));
3506 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf_i386_pic_plt_entry
,
3508 bfd_put_32 (output_bfd
, got_offset
,
3509 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3512 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rel
),
3513 htab
->splt
->contents
+ h
->plt
.offset
+
3514 elf_i386_plt_entry_offset3
);
3516 * The previous code assumed that the jump entry ended a PLT entry.
3517 * Forcing alignment to 0mod32 adds some hlt bytes at the end (11).
3518 * We therefore need to subtract those bytes from the jump offset.
3520 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ elf_i386_plt_entry_offset5
),
3521 htab
->splt
->contents
+ h
->plt
.offset
+
3522 elf_i386_plt_entry_offset4
);
3524 /* Fill in the entry in the global offset table. */
3525 bfd_put_32 (output_bfd
,
3526 (htab
->splt
->output_section
->vma
3527 + htab
->splt
->output_offset
3529 + elf_i386_plt_entry_offset2
),
3530 htab
->sgotplt
->contents
+ got_offset
);
3532 /* Fill in the entry in the .rel.plt section. */
3533 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3534 + htab
->sgotplt
->output_offset
3536 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_JUMP_SLOT
);
3537 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3538 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3540 if (!h
->def_regular
)
3542 /* Mark the symbol as undefined, rather than as defined in
3543 the .plt section. Leave the value if there were any
3544 relocations where pointer equality matters (this is a clue
3545 for the dynamic linker, to make function pointer
3546 comparisons work between an application and shared
3547 library), otherwise set it to zero. If a function is only
3548 called from a binary, there is no need to slow down
3549 shared libraries because of that. */
3550 sym
->st_shndx
= SHN_UNDEF
;
3551 if (!h
->pointer_equality_needed
)
3556 if (h
->got
.offset
!= (bfd_vma
) -1
3557 && ! GOT_TLS_GD_ANY_P (elf_i386_hash_entry(h
)->tls_type
)
3558 && (elf_i386_hash_entry(h
)->tls_type
& GOT_TLS_IE
) == 0)
3560 Elf_Internal_Rela rel
;
3563 /* This symbol has an entry in the global offset table. Set it
3566 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3569 rel
.r_offset
= (htab
->sgot
->output_section
->vma
3570 + htab
->sgot
->output_offset
3571 + (h
->got
.offset
& ~(bfd_vma
) 1));
3573 /* If this is a static link, or it is a -Bsymbolic link and the
3574 symbol is defined locally or was forced to be local because
3575 of a version file, we just want to emit a RELATIVE reloc.
3576 The entry in the global offset table will already have been
3577 initialized in the relocate_section function. */
3579 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3581 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3582 rel
.r_info
= ELF32_R_INFO (0, R_386_RELATIVE
);
3586 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3587 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3588 htab
->sgot
->contents
+ h
->got
.offset
);
3589 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_GLOB_DAT
);
3592 loc
= htab
->srelgot
->contents
;
3593 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3594 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3599 Elf_Internal_Rela rel
;
3602 /* This symbol needs a copy reloc. Set it up. */
3604 if (h
->dynindx
== -1
3605 || (h
->root
.type
!= bfd_link_hash_defined
3606 && h
->root
.type
!= bfd_link_hash_defweak
)
3607 || htab
->srelbss
== NULL
)
3610 rel
.r_offset
= (h
->root
.u
.def
.value
3611 + h
->root
.u
.def
.section
->output_section
->vma
3612 + h
->root
.u
.def
.section
->output_offset
);
3613 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_386_COPY
);
3614 loc
= htab
->srelbss
->contents
;
3615 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3616 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3619 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.
3620 On VxWorks, the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it
3621 is relative to the ".got" section. */
3622 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3623 || (!htab
->is_vxworks
&& h
== htab
->elf
.hgot
))
3624 sym
->st_shndx
= SHN_ABS
;
3629 /* Used to decide how to sort relocs in an optimal manner for the
3630 dynamic linker, before writing them out. */
3632 static enum elf_reloc_type_class
3633 elf_i386_reloc_type_class (const Elf_Internal_Rela
*rela
)
3635 switch (ELF32_R_TYPE (rela
->r_info
))
3637 case R_386_RELATIVE
:
3638 return reloc_class_relative
;
3639 case R_386_JUMP_SLOT
:
3640 return reloc_class_plt
;
3642 return reloc_class_copy
;
3644 return reloc_class_normal
;
3648 /* Finish up the dynamic sections. */
3651 elf_i386_finish_dynamic_sections (bfd
*output_bfd
,
3652 struct bfd_link_info
*info
)
3654 struct elf_i386_link_hash_table
*htab
;
3658 htab
= elf_i386_hash_table (info
);
3659 dynobj
= htab
->elf
.dynobj
;
3660 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3662 if (htab
->elf
.dynamic_sections_created
)
3664 Elf32_External_Dyn
*dyncon
, *dynconend
;
3666 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3669 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3670 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3671 for (; dyncon
< dynconend
; dyncon
++)
3673 Elf_Internal_Dyn dyn
;
3676 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3685 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3690 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3695 dyn
.d_un
.d_val
= s
->size
;
3699 /* My reading of the SVR4 ABI indicates that the
3700 procedure linkage table relocs (DT_JMPREL) should be
3701 included in the overall relocs (DT_REL). This is
3702 what Solaris does. However, UnixWare can not handle
3703 that case. Therefore, we override the DT_RELSZ entry
3704 here to make it not include the JMPREL relocs. */
3708 dyn
.d_un
.d_val
-= s
->size
;
3712 /* We may not be using the standard ELF linker script.
3713 If .rel.plt is the first .rel section, we adjust
3714 DT_REL to not include it. */
3718 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
3720 dyn
.d_un
.d_ptr
+= s
->size
;
3724 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3727 /* Fill in the first entry in the procedure linkage table. */
3728 if (htab
->splt
&& htab
->splt
->size
> 0)
3732 memcpy (htab
->splt
->contents
, elf_i386_pic_plt0_entry
,
3733 sizeof (elf_i386_pic_plt0_entry
));
3734 memset (htab
->splt
->contents
+ sizeof (elf_i386_pic_plt0_entry
),
3735 htab
->plt0_pad_byte
,
3736 PLT_ENTRY_SIZE
- sizeof (elf_i386_pic_plt0_entry
));
3740 memcpy (htab
->splt
->contents
, elf_i386_plt0_entry
,
3741 sizeof(elf_i386_plt0_entry
));
3742 memset (htab
->splt
->contents
+ sizeof (elf_i386_plt0_entry
),
3743 htab
->plt0_pad_byte
,
3744 PLT_ENTRY_SIZE
- sizeof (elf_i386_plt0_entry
));
3745 bfd_put_32 (output_bfd
,
3746 (htab
->sgotplt
->output_section
->vma
3747 + htab
->sgotplt
->output_offset
3749 htab
->splt
->contents
+ elf_i386_plt0_entry_offset1
);
3750 bfd_put_32 (output_bfd
,
3751 (htab
->sgotplt
->output_section
->vma
3752 + htab
->sgotplt
->output_offset
3754 htab
->splt
->contents
+ elf_i386_plt0_entry_offset2
);
3756 if (htab
->is_vxworks
)
3758 Elf_Internal_Rela rel
;
3760 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4.
3761 On IA32 we use REL relocations so the addend goes in
3762 the PLT directly. */
3763 rel
.r_offset
= (htab
->splt
->output_section
->vma
3764 + htab
->splt
->output_offset
3766 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3767 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3768 htab
->srelplt2
->contents
);
3769 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
3770 rel
.r_offset
= (htab
->splt
->output_section
->vma
3771 + htab
->splt
->output_offset
3773 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3774 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3775 htab
->srelplt2
->contents
+
3776 sizeof (Elf32_External_Rel
));
3780 /* UnixWare sets the entsize of .plt to 4, although that doesn't
3781 really seem like the right value. */
3782 elf_section_data (htab
->splt
->output_section
)
3783 ->this_hdr
.sh_entsize
= 4;
3785 /* Correct the .rel.plt.unloaded relocations. */
3786 if (htab
->is_vxworks
&& !info
->shared
)
3788 int num_plts
= (htab
->splt
->size
/ PLT_ENTRY_SIZE
) - 1;
3791 p
= htab
->srelplt2
->contents
;
3793 p
+= PLTRESOLVE_RELOCS_SHLIB
* sizeof (Elf32_External_Rel
);
3795 p
+= PLTRESOLVE_RELOCS
* sizeof (Elf32_External_Rel
);
3797 for (; num_plts
; num_plts
--)
3799 Elf_Internal_Rela rel
;
3800 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3801 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_386_32
);
3802 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3803 p
+= sizeof (Elf32_External_Rel
);
3805 bfd_elf32_swap_reloc_in (output_bfd
, p
, &rel
);
3806 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_386_32
);
3807 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, p
);
3808 p
+= sizeof (Elf32_External_Rel
);
3816 /* Fill in the first three entries in the global offset table. */
3817 if (htab
->sgotplt
->size
> 0)
3819 bfd_put_32 (output_bfd
,
3821 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
3822 htab
->sgotplt
->contents
);
3823 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 4);
3824 bfd_put_32 (output_bfd
, 0, htab
->sgotplt
->contents
+ 8);
3827 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
3830 if (htab
->sgot
&& htab
->sgot
->size
> 0)
3831 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
3836 /* Return address for Ith PLT stub in section PLT, for relocation REL
3837 or (bfd_vma) -1 if it should not be included. */
3840 elf_i386_plt_sym_val (bfd_vma i
, const asection
*plt
,
3841 const arelent
*rel ATTRIBUTE_UNUSED
)
3843 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3846 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3849 elf_i386_hash_symbol (struct elf_link_hash_entry
*h
)
3851 if (h
->plt
.offset
!= (bfd_vma
) -1
3853 && !h
->pointer_equality_needed
)
3856 return _bfd_elf_hash_symbol (h
);
3859 #define TARGET_LITTLE_SYM bfd_elf32_nacl_vec
3860 #define TARGET_LITTLE_NAME "elf32-nacl"
3862 /* NativeClient defines its own ABI.*/
3864 #define ELF_OSABI ELFOSABI_NACL
3866 #define ELF_ARCH bfd_arch_i386
3867 #define ELF_MACHINE_CODE EM_386
3868 #define ELF_MAXPAGESIZE 0x1000
3870 #define elf_backend_can_gc_sections 1
3871 #define elf_backend_can_refcount 1
3872 #define elf_backend_want_got_plt 1
3873 #define elf_backend_plt_readonly 1
3874 #define elf_backend_want_plt_sym 0
3875 #define elf_backend_got_header_size 12
3877 /* Support RELA for objdump of prelink objects. */
3878 #define elf_info_to_howto elf_i386_info_to_howto_rel
3879 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
3881 #define bfd_elf32_mkobject elf_i386_mkobject
3883 #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
3884 #define bfd_elf32_bfd_link_hash_table_create elf_i386_link_hash_table_create
3885 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
3886 #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
3888 #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol
3889 #define elf_backend_check_relocs elf_i386_check_relocs
3890 #define elf_backend_copy_indirect_symbol elf_i386_copy_indirect_symbol
3891 #define elf_backend_create_dynamic_sections elf_i386_create_dynamic_sections
3892 #define elf_backend_fake_sections elf_i386_fake_sections
3893 #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
3894 #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
3895 #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
3896 #define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
3897 #define elf_backend_grok_prstatus elf_i386_grok_prstatus
3898 #define elf_backend_grok_psinfo elf_i386_grok_psinfo
3899 #define elf_backend_reloc_type_class elf_i386_reloc_type_class
3900 #define elf_backend_relocate_section elf_i386_relocate_section
3901 #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
3902 #define elf_backend_always_size_sections elf_i386_always_size_sections
3903 #define elf_backend_omit_section_dynsym \
3904 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
3905 #define elf_backend_plt_sym_val elf_i386_plt_sym_val
3906 #define elf_backend_hash_symbol elf_i386_hash_symbol
3908 #define bfd_elf32_bfd_merge_private_bfd_data \
3909 elf32_nacl_merge_private_bfd_data
3911 static unsigned long previous_ibfd_e_flags
= (unsigned long) EF_NACL_ALIGN_LIB
;
3912 static unsigned char previous_ibfd_abiversion
= 0;
3915 elf32_nacl_merge_private_bfd_data (bfd
*ibfd
,
3918 unsigned long ibfd_e_flags
;
3919 unsigned char ibfd_abiversion
;
3921 ibfd_e_flags
= elf_elfheader (ibfd
)->e_flags
& EF_NACL_ALIGN_MASK
;
3922 if ((ibfd_e_flags
!= EF_NACL_ALIGN_LIB
) &&
3923 (previous_ibfd_e_flags
!= EF_NACL_ALIGN_LIB
) &&
3924 (ibfd_e_flags
!= previous_ibfd_e_flags
)) {
3925 (*_bfd_error_handler
)
3926 (_("%B: linking files with incompatible alignments"), ibfd
);
3927 bfd_set_error (bfd_error_bad_value
);
3931 ibfd_abiversion
= elf_elfheader (ibfd
)->e_ident
[EI_ABIVERSION
];
3932 if (ibfd_abiversion
!= 0 &&
3933 previous_ibfd_abiversion
!= 0 &&
3934 ibfd_abiversion
!= previous_ibfd_abiversion
) {
3935 (*_bfd_error_handler
)
3936 (_("%B: linking files with incompatible abi version"), ibfd
);
3937 bfd_set_error (bfd_error_bad_value
);
3941 previous_ibfd_e_flags
= ibfd_e_flags
;
3942 elf_elfheader (obfd
)->e_flags
|= previous_ibfd_e_flags
;
3944 previous_ibfd_abiversion
= ibfd_abiversion
;
3945 elf_elfheader (obfd
)->e_ident
[EI_ABIVERSION
] = previous_ibfd_abiversion
;
3950 #define elf_backend_final_write_processing \
3951 elf32_nacl_backend_final_write_processing
3954 elf32_nacl_backend_final_write_processing (bfd
*abfd
,
3955 bfd_boolean linker ATTRIBUTE_UNUSED
)
3957 elf_elfheader (abfd
)->e_ident
[EI_OSABI
] = ELFOSABI_NACL
;
3958 elf_elfheader (abfd
)->e_ident
[EI_ABIVERSION
] = EF_NACL_ABIVERSION
;
3959 elf_elfheader (abfd
)->e_flags
|= previous_ibfd_e_flags
;
3962 #include "elf32-target.h"