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