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