Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Intel 80386/80486-specific support for 32-bit ELF |
2571583a | 2 | Copyright (C) 1993-2017 Free Software Foundation, Inc. |
252b5132 | 3 | |
571fe01f | 4 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 5 | |
571fe01f NC |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 8 | the Free Software Foundation; either version 3 of the License, or |
571fe01f | 9 | (at your option) any later version. |
252b5132 | 10 | |
571fe01f NC |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
252b5132 | 15 | |
571fe01f NC |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | MA 02110-1301, USA. */ | |
252b5132 | 20 | |
0afcef53 | 21 | #include "elfxx-x86.h" |
5a68afcf | 22 | #include "elf-nacl.h" |
eac338cf | 23 | #include "elf-vxworks.h" |
e41b3a13 | 24 | #include "dwarf2.h" |
02a86693 | 25 | #include "opcode/i386.h" |
252b5132 | 26 | |
55fd94b0 AM |
27 | /* 386 uses REL relocations instead of RELA. */ |
28 | #define USE_REL 1 | |
252b5132 RH |
29 | |
30 | #include "elf/i386.h" | |
31 | ||
32 | static reloc_howto_type elf_howto_table[]= | |
33 | { | |
6346d5ca | 34 | HOWTO(R_386_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont, |
1b452ec6 | 35 | bfd_elf_generic_reloc, "R_386_NONE", |
b34976b6 AM |
36 | TRUE, 0x00000000, 0x00000000, FALSE), |
37 | HOWTO(R_386_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 38 | bfd_elf_generic_reloc, "R_386_32", |
b34976b6 AM |
39 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
40 | HOWTO(R_386_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
1b452ec6 | 41 | bfd_elf_generic_reloc, "R_386_PC32", |
b34976b6 AM |
42 | TRUE, 0xffffffff, 0xffffffff, TRUE), |
43 | HOWTO(R_386_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 44 | bfd_elf_generic_reloc, "R_386_GOT32", |
b34976b6 AM |
45 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
46 | HOWTO(R_386_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
1b452ec6 | 47 | bfd_elf_generic_reloc, "R_386_PLT32", |
b34976b6 AM |
48 | TRUE, 0xffffffff, 0xffffffff, TRUE), |
49 | HOWTO(R_386_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 50 | bfd_elf_generic_reloc, "R_386_COPY", |
b34976b6 AM |
51 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
52 | HOWTO(R_386_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 53 | bfd_elf_generic_reloc, "R_386_GLOB_DAT", |
b34976b6 AM |
54 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
55 | HOWTO(R_386_JUMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 56 | bfd_elf_generic_reloc, "R_386_JUMP_SLOT", |
b34976b6 AM |
57 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
58 | HOWTO(R_386_RELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 59 | bfd_elf_generic_reloc, "R_386_RELATIVE", |
b34976b6 AM |
60 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
61 | HOWTO(R_386_GOTOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 62 | bfd_elf_generic_reloc, "R_386_GOTOFF", |
b34976b6 AM |
63 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
64 | HOWTO(R_386_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
1b452ec6 | 65 | bfd_elf_generic_reloc, "R_386_GOTPC", |
b34976b6 | 66 | TRUE, 0xffffffff, 0xffffffff, TRUE), |
1b452ec6 | 67 | |
dc47f327 AM |
68 | /* We have a gap in the reloc numbers here. |
69 | R_386_standard counts the number up to this point, and | |
70 | R_386_ext_offset is the value to subtract from a reloc type of | |
71 | R_386_16 thru R_386_PC8 to form an index into this table. */ | |
55fd94b0 AM |
72 | #define R_386_standard (R_386_GOTPC + 1) |
73 | #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard) | |
1b452ec6 | 74 | |
37e55690 | 75 | /* These relocs are a GNU extension. */ |
b34976b6 | 76 | HOWTO(R_386_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, |
37e55690 | 77 | bfd_elf_generic_reloc, "R_386_TLS_TPOFF", |
b34976b6 AM |
78 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
79 | HOWTO(R_386_TLS_IE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
37e55690 | 80 | bfd_elf_generic_reloc, "R_386_TLS_IE", |
b34976b6 AM |
81 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
82 | HOWTO(R_386_TLS_GOTIE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
37e55690 | 83 | bfd_elf_generic_reloc, "R_386_TLS_GOTIE", |
b34976b6 AM |
84 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
85 | HOWTO(R_386_TLS_LE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 86 | bfd_elf_generic_reloc, "R_386_TLS_LE", |
b34976b6 AM |
87 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
88 | HOWTO(R_386_TLS_GD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 89 | bfd_elf_generic_reloc, "R_386_TLS_GD", |
b34976b6 AM |
90 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
91 | HOWTO(R_386_TLS_LDM, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 92 | bfd_elf_generic_reloc, "R_386_TLS_LDM", |
b34976b6 AM |
93 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
94 | HOWTO(R_386_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 95 | bfd_elf_generic_reloc, "R_386_16", |
b34976b6 | 96 | TRUE, 0xffff, 0xffff, FALSE), |
b0360d8c | 97 | HOWTO(R_386_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield, |
1b452ec6 | 98 | bfd_elf_generic_reloc, "R_386_PC16", |
b34976b6 AM |
99 | TRUE, 0xffff, 0xffff, TRUE), |
100 | HOWTO(R_386_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, | |
1b452ec6 | 101 | bfd_elf_generic_reloc, "R_386_8", |
b34976b6 AM |
102 | TRUE, 0xff, 0xff, FALSE), |
103 | HOWTO(R_386_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, | |
1b452ec6 | 104 | bfd_elf_generic_reloc, "R_386_PC8", |
b34976b6 | 105 | TRUE, 0xff, 0xff, TRUE), |
dc47f327 | 106 | |
55fd94b0 AM |
107 | #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset) |
108 | #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext) | |
13ae64f3 | 109 | /* These are common with Solaris TLS implementation. */ |
b34976b6 | 110 | HOWTO(R_386_TLS_LDO_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, |
13ae64f3 | 111 | bfd_elf_generic_reloc, "R_386_TLS_LDO_32", |
b34976b6 AM |
112 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
113 | HOWTO(R_386_TLS_IE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 114 | bfd_elf_generic_reloc, "R_386_TLS_IE_32", |
b34976b6 AM |
115 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
116 | HOWTO(R_386_TLS_LE_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 117 | bfd_elf_generic_reloc, "R_386_TLS_LE_32", |
b34976b6 AM |
118 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
119 | HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 120 | bfd_elf_generic_reloc, "R_386_TLS_DTPMOD32", |
b34976b6 AM |
121 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
122 | HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 123 | bfd_elf_generic_reloc, "R_386_TLS_DTPOFF32", |
b34976b6 AM |
124 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
125 | HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
13ae64f3 | 126 | bfd_elf_generic_reloc, "R_386_TLS_TPOFF32", |
b34976b6 | 127 | TRUE, 0xffffffff, 0xffffffff, FALSE), |
1788fc08 L |
128 | HOWTO(R_386_SIZE32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned, |
129 | bfd_elf_generic_reloc, "R_386_SIZE32", | |
130 | TRUE, 0xffffffff, 0xffffffff, FALSE), | |
67a4f2b7 AO |
131 | HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, |
132 | bfd_elf_generic_reloc, "R_386_TLS_GOTDESC", | |
133 | TRUE, 0xffffffff, 0xffffffff, FALSE), | |
134 | HOWTO(R_386_TLS_DESC_CALL, 0, 0, 0, FALSE, 0, complain_overflow_dont, | |
135 | bfd_elf_generic_reloc, "R_386_TLS_DESC_CALL", | |
136 | FALSE, 0, 0, FALSE), | |
137 | HOWTO(R_386_TLS_DESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
138 | bfd_elf_generic_reloc, "R_386_TLS_DESC", | |
139 | TRUE, 0xffffffff, 0xffffffff, FALSE), | |
cbe950e9 L |
140 | HOWTO(R_386_IRELATIVE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, |
141 | bfd_elf_generic_reloc, "R_386_IRELATIVE", | |
142 | TRUE, 0xffffffff, 0xffffffff, FALSE), | |
02a86693 L |
143 | HOWTO(R_386_GOT32X, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, |
144 | bfd_elf_generic_reloc, "R_386_GOT32X", | |
145 | TRUE, 0xffffffff, 0xffffffff, FALSE), | |
13ae64f3 JJ |
146 | |
147 | /* Another gap. */ | |
02a86693 | 148 | #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset) |
c74be520 | 149 | #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2) |
252b5132 RH |
150 | |
151 | /* GNU extension to record C++ vtable hierarchy. */ | |
252b5132 RH |
152 | HOWTO (R_386_GNU_VTINHERIT, /* type */ |
153 | 0, /* rightshift */ | |
154 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
155 | 0, /* bitsize */ | |
b34976b6 | 156 | FALSE, /* pc_relative */ |
252b5132 RH |
157 | 0, /* bitpos */ |
158 | complain_overflow_dont, /* complain_on_overflow */ | |
159 | NULL, /* special_function */ | |
160 | "R_386_GNU_VTINHERIT", /* name */ | |
b34976b6 | 161 | FALSE, /* partial_inplace */ |
252b5132 RH |
162 | 0, /* src_mask */ |
163 | 0, /* dst_mask */ | |
b34976b6 | 164 | FALSE), /* pcrel_offset */ |
252b5132 RH |
165 | |
166 | /* GNU extension to record C++ vtable member usage. */ | |
252b5132 RH |
167 | HOWTO (R_386_GNU_VTENTRY, /* type */ |
168 | 0, /* rightshift */ | |
169 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
170 | 0, /* bitsize */ | |
b34976b6 | 171 | FALSE, /* pc_relative */ |
252b5132 RH |
172 | 0, /* bitpos */ |
173 | complain_overflow_dont, /* complain_on_overflow */ | |
174 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
175 | "R_386_GNU_VTENTRY", /* name */ | |
b34976b6 | 176 | FALSE, /* partial_inplace */ |
252b5132 RH |
177 | 0, /* src_mask */ |
178 | 0, /* dst_mask */ | |
b34976b6 | 179 | FALSE) /* pcrel_offset */ |
dc47f327 | 180 | |
55fd94b0 | 181 | #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset) |
dc47f327 AM |
182 | |
183 | }; | |
184 | ||
252b5132 | 185 | #ifdef DEBUG_GEN_RELOC |
55fd94b0 AM |
186 | #define TRACE(str) \ |
187 | fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str) | |
252b5132 RH |
188 | #else |
189 | #define TRACE(str) | |
190 | #endif | |
191 | ||
192 | static reloc_howto_type * | |
55fd94b0 AM |
193 | elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
194 | bfd_reloc_code_real_type code) | |
252b5132 RH |
195 | { |
196 | switch (code) | |
197 | { | |
198 | case BFD_RELOC_NONE: | |
199 | TRACE ("BFD_RELOC_NONE"); | |
55fd94b0 | 200 | return &elf_howto_table[R_386_NONE]; |
252b5132 RH |
201 | |
202 | case BFD_RELOC_32: | |
203 | TRACE ("BFD_RELOC_32"); | |
55fd94b0 | 204 | return &elf_howto_table[R_386_32]; |
252b5132 RH |
205 | |
206 | case BFD_RELOC_CTOR: | |
207 | TRACE ("BFD_RELOC_CTOR"); | |
55fd94b0 | 208 | return &elf_howto_table[R_386_32]; |
252b5132 RH |
209 | |
210 | case BFD_RELOC_32_PCREL: | |
211 | TRACE ("BFD_RELOC_PC32"); | |
55fd94b0 | 212 | return &elf_howto_table[R_386_PC32]; |
252b5132 RH |
213 | |
214 | case BFD_RELOC_386_GOT32: | |
215 | TRACE ("BFD_RELOC_386_GOT32"); | |
55fd94b0 | 216 | return &elf_howto_table[R_386_GOT32]; |
252b5132 RH |
217 | |
218 | case BFD_RELOC_386_PLT32: | |
219 | TRACE ("BFD_RELOC_386_PLT32"); | |
55fd94b0 | 220 | return &elf_howto_table[R_386_PLT32]; |
252b5132 RH |
221 | |
222 | case BFD_RELOC_386_COPY: | |
223 | TRACE ("BFD_RELOC_386_COPY"); | |
55fd94b0 | 224 | return &elf_howto_table[R_386_COPY]; |
252b5132 RH |
225 | |
226 | case BFD_RELOC_386_GLOB_DAT: | |
227 | TRACE ("BFD_RELOC_386_GLOB_DAT"); | |
55fd94b0 | 228 | return &elf_howto_table[R_386_GLOB_DAT]; |
252b5132 RH |
229 | |
230 | case BFD_RELOC_386_JUMP_SLOT: | |
231 | TRACE ("BFD_RELOC_386_JUMP_SLOT"); | |
55fd94b0 | 232 | return &elf_howto_table[R_386_JUMP_SLOT]; |
252b5132 RH |
233 | |
234 | case BFD_RELOC_386_RELATIVE: | |
235 | TRACE ("BFD_RELOC_386_RELATIVE"); | |
55fd94b0 | 236 | return &elf_howto_table[R_386_RELATIVE]; |
252b5132 RH |
237 | |
238 | case BFD_RELOC_386_GOTOFF: | |
239 | TRACE ("BFD_RELOC_386_GOTOFF"); | |
55fd94b0 | 240 | return &elf_howto_table[R_386_GOTOFF]; |
252b5132 RH |
241 | |
242 | case BFD_RELOC_386_GOTPC: | |
243 | TRACE ("BFD_RELOC_386_GOTPC"); | |
55fd94b0 | 244 | return &elf_howto_table[R_386_GOTPC]; |
252b5132 | 245 | |
37e55690 JJ |
246 | /* These relocs are a GNU extension. */ |
247 | case BFD_RELOC_386_TLS_TPOFF: | |
248 | TRACE ("BFD_RELOC_386_TLS_TPOFF"); | |
55fd94b0 | 249 | return &elf_howto_table[R_386_TLS_TPOFF - R_386_ext_offset]; |
37e55690 JJ |
250 | |
251 | case BFD_RELOC_386_TLS_IE: | |
252 | TRACE ("BFD_RELOC_386_TLS_IE"); | |
55fd94b0 | 253 | return &elf_howto_table[R_386_TLS_IE - R_386_ext_offset]; |
37e55690 JJ |
254 | |
255 | case BFD_RELOC_386_TLS_GOTIE: | |
256 | TRACE ("BFD_RELOC_386_TLS_GOTIE"); | |
55fd94b0 | 257 | return &elf_howto_table[R_386_TLS_GOTIE - R_386_ext_offset]; |
37e55690 | 258 | |
13ae64f3 JJ |
259 | case BFD_RELOC_386_TLS_LE: |
260 | TRACE ("BFD_RELOC_386_TLS_LE"); | |
55fd94b0 | 261 | return &elf_howto_table[R_386_TLS_LE - R_386_ext_offset]; |
13ae64f3 JJ |
262 | |
263 | case BFD_RELOC_386_TLS_GD: | |
264 | TRACE ("BFD_RELOC_386_TLS_GD"); | |
55fd94b0 | 265 | return &elf_howto_table[R_386_TLS_GD - R_386_ext_offset]; |
13ae64f3 JJ |
266 | |
267 | case BFD_RELOC_386_TLS_LDM: | |
268 | TRACE ("BFD_RELOC_386_TLS_LDM"); | |
55fd94b0 | 269 | return &elf_howto_table[R_386_TLS_LDM - R_386_ext_offset]; |
13ae64f3 | 270 | |
252b5132 RH |
271 | case BFD_RELOC_16: |
272 | TRACE ("BFD_RELOC_16"); | |
55fd94b0 | 273 | return &elf_howto_table[R_386_16 - R_386_ext_offset]; |
252b5132 RH |
274 | |
275 | case BFD_RELOC_16_PCREL: | |
276 | TRACE ("BFD_RELOC_16_PCREL"); | |
55fd94b0 | 277 | return &elf_howto_table[R_386_PC16 - R_386_ext_offset]; |
252b5132 RH |
278 | |
279 | case BFD_RELOC_8: | |
280 | TRACE ("BFD_RELOC_8"); | |
55fd94b0 | 281 | return &elf_howto_table[R_386_8 - R_386_ext_offset]; |
252b5132 RH |
282 | |
283 | case BFD_RELOC_8_PCREL: | |
284 | TRACE ("BFD_RELOC_8_PCREL"); | |
55fd94b0 | 285 | return &elf_howto_table[R_386_PC8 - R_386_ext_offset]; |
252b5132 | 286 | |
13ae64f3 JJ |
287 | /* Common with Sun TLS implementation. */ |
288 | case BFD_RELOC_386_TLS_LDO_32: | |
289 | TRACE ("BFD_RELOC_386_TLS_LDO_32"); | |
55fd94b0 | 290 | return &elf_howto_table[R_386_TLS_LDO_32 - R_386_tls_offset]; |
13ae64f3 JJ |
291 | |
292 | case BFD_RELOC_386_TLS_IE_32: | |
293 | TRACE ("BFD_RELOC_386_TLS_IE_32"); | |
55fd94b0 | 294 | return &elf_howto_table[R_386_TLS_IE_32 - R_386_tls_offset]; |
13ae64f3 JJ |
295 | |
296 | case BFD_RELOC_386_TLS_LE_32: | |
297 | TRACE ("BFD_RELOC_386_TLS_LE_32"); | |
55fd94b0 | 298 | return &elf_howto_table[R_386_TLS_LE_32 - R_386_tls_offset]; |
13ae64f3 JJ |
299 | |
300 | case BFD_RELOC_386_TLS_DTPMOD32: | |
301 | TRACE ("BFD_RELOC_386_TLS_DTPMOD32"); | |
55fd94b0 | 302 | return &elf_howto_table[R_386_TLS_DTPMOD32 - R_386_tls_offset]; |
13ae64f3 JJ |
303 | |
304 | case BFD_RELOC_386_TLS_DTPOFF32: | |
305 | TRACE ("BFD_RELOC_386_TLS_DTPOFF32"); | |
55fd94b0 | 306 | return &elf_howto_table[R_386_TLS_DTPOFF32 - R_386_tls_offset]; |
13ae64f3 JJ |
307 | |
308 | case BFD_RELOC_386_TLS_TPOFF32: | |
309 | TRACE ("BFD_RELOC_386_TLS_TPOFF32"); | |
55fd94b0 | 310 | return &elf_howto_table[R_386_TLS_TPOFF32 - R_386_tls_offset]; |
13ae64f3 | 311 | |
1788fc08 L |
312 | case BFD_RELOC_SIZE32: |
313 | TRACE ("BFD_RELOC_SIZE32"); | |
314 | return &elf_howto_table[R_386_SIZE32 - R_386_tls_offset]; | |
315 | ||
67a4f2b7 AO |
316 | case BFD_RELOC_386_TLS_GOTDESC: |
317 | TRACE ("BFD_RELOC_386_TLS_GOTDESC"); | |
318 | return &elf_howto_table[R_386_TLS_GOTDESC - R_386_tls_offset]; | |
319 | ||
320 | case BFD_RELOC_386_TLS_DESC_CALL: | |
321 | TRACE ("BFD_RELOC_386_TLS_DESC_CALL"); | |
322 | return &elf_howto_table[R_386_TLS_DESC_CALL - R_386_tls_offset]; | |
323 | ||
324 | case BFD_RELOC_386_TLS_DESC: | |
325 | TRACE ("BFD_RELOC_386_TLS_DESC"); | |
326 | return &elf_howto_table[R_386_TLS_DESC - R_386_tls_offset]; | |
327 | ||
cbe950e9 L |
328 | case BFD_RELOC_386_IRELATIVE: |
329 | TRACE ("BFD_RELOC_386_IRELATIVE"); | |
2a750708 | 330 | return &elf_howto_table[R_386_IRELATIVE - R_386_tls_offset]; |
cbe950e9 | 331 | |
02a86693 L |
332 | case BFD_RELOC_386_GOT32X: |
333 | TRACE ("BFD_RELOC_386_GOT32X"); | |
334 | return &elf_howto_table[R_386_GOT32X - R_386_tls_offset]; | |
335 | ||
252b5132 RH |
336 | case BFD_RELOC_VTABLE_INHERIT: |
337 | TRACE ("BFD_RELOC_VTABLE_INHERIT"); | |
55fd94b0 | 338 | return &elf_howto_table[R_386_GNU_VTINHERIT - R_386_vt_offset]; |
252b5132 RH |
339 | |
340 | case BFD_RELOC_VTABLE_ENTRY: | |
341 | TRACE ("BFD_RELOC_VTABLE_ENTRY"); | |
55fd94b0 | 342 | return &elf_howto_table[R_386_GNU_VTENTRY - R_386_vt_offset]; |
252b5132 RH |
343 | |
344 | default: | |
345 | break; | |
346 | } | |
347 | ||
348 | TRACE ("Unknown"); | |
349 | return 0; | |
350 | } | |
351 | ||
157090f7 AM |
352 | static reloc_howto_type * |
353 | elf_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
354 | const char *r_name) | |
355 | { | |
356 | unsigned int i; | |
357 | ||
358 | for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++) | |
359 | if (elf_howto_table[i].name != NULL | |
360 | && strcasecmp (elf_howto_table[i].name, r_name) == 0) | |
361 | return &elf_howto_table[i]; | |
362 | ||
363 | return NULL; | |
364 | } | |
365 | ||
142411ca L |
366 | static reloc_howto_type * |
367 | elf_i386_rtype_to_howto (bfd *abfd, unsigned r_type) | |
252b5132 | 368 | { |
dc47f327 AM |
369 | unsigned int indx; |
370 | ||
371 | if ((indx = r_type) >= R_386_standard | |
372 | && ((indx = r_type - R_386_ext_offset) - R_386_standard | |
373 | >= R_386_ext - R_386_standard) | |
13ae64f3 | 374 | && ((indx = r_type - R_386_tls_offset) - R_386_ext |
c74be520 L |
375 | >= R_386_ext2 - R_386_ext) |
376 | && ((indx = r_type - R_386_vt_offset) - R_386_ext2 | |
377 | >= R_386_vt - R_386_ext2)) | |
252b5132 | 378 | { |
695344c0 | 379 | /* xgettext:c-format */ |
4eca0228 AM |
380 | _bfd_error_handler (_("%B: invalid relocation type %d"), |
381 | abfd, (int) r_type); | |
55fd94b0 | 382 | indx = R_386_NONE; |
252b5132 | 383 | } |
06614111 NC |
384 | /* PR 17512: file: 0f67f69d. */ |
385 | if (elf_howto_table [indx].type != r_type) | |
386 | return NULL; | |
142411ca L |
387 | return &elf_howto_table[indx]; |
388 | } | |
389 | ||
390 | static void | |
391 | elf_i386_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, | |
392 | arelent *cache_ptr, | |
393 | Elf_Internal_Rela *dst) | |
394 | { | |
395 | unsigned int r_type = ELF32_R_TYPE (dst->r_info); | |
396 | cache_ptr->howto = elf_i386_rtype_to_howto (abfd, r_type); | |
252b5132 RH |
397 | } |
398 | ||
399 | /* Return whether a symbol name implies a local label. The UnixWare | |
400 | 2.1 cc generates temporary symbols that start with .X, so we | |
401 | recognize them here. FIXME: do other SVR4 compilers also use .X?. | |
402 | If so, we should move the .X recognition into | |
403 | _bfd_elf_is_local_label_name. */ | |
404 | ||
b34976b6 | 405 | static bfd_boolean |
55fd94b0 | 406 | elf_i386_is_local_label_name (bfd *abfd, const char *name) |
252b5132 RH |
407 | { |
408 | if (name[0] == '.' && name[1] == 'X') | |
b34976b6 | 409 | return TRUE; |
252b5132 RH |
410 | |
411 | return _bfd_elf_is_local_label_name (abfd, name); | |
412 | } | |
413 | \f | |
38701953 | 414 | /* Support for core dump NOTE sections. */ |
61adc1a4 | 415 | |
b34976b6 | 416 | static bfd_boolean |
55fd94b0 | 417 | elf_i386_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
38701953 AM |
418 | { |
419 | int offset; | |
eea6121a | 420 | size_t size; |
38701953 | 421 | |
61adc1a4 | 422 | if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0) |
38701953 | 423 | { |
61adc1a4 NC |
424 | int pr_version = bfd_get_32 (abfd, note->descdata); |
425 | ||
426 | if (pr_version != 1) | |
427 | return FALSE; | |
428 | ||
429 | /* pr_cursig */ | |
228e534f | 430 | elf_tdata (abfd)->core->signal = bfd_get_32 (abfd, note->descdata + 20); |
61adc1a4 NC |
431 | |
432 | /* pr_pid */ | |
228e534f | 433 | elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); |
61adc1a4 NC |
434 | |
435 | /* pr_reg */ | |
436 | offset = 28; | |
eea6121a | 437 | size = bfd_get_32 (abfd, note->descdata + 8); |
61adc1a4 NC |
438 | } |
439 | else | |
440 | { | |
441 | switch (note->descsz) | |
442 | { | |
443 | default: | |
444 | return FALSE; | |
38701953 | 445 | |
61adc1a4 NC |
446 | case 144: /* Linux/i386 */ |
447 | /* pr_cursig */ | |
228e534f | 448 | elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); |
38701953 | 449 | |
61adc1a4 | 450 | /* pr_pid */ |
228e534f | 451 | elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); |
38701953 | 452 | |
61adc1a4 NC |
453 | /* pr_reg */ |
454 | offset = 72; | |
eea6121a | 455 | size = 68; |
38701953 | 456 | |
61adc1a4 NC |
457 | break; |
458 | } | |
38701953 AM |
459 | } |
460 | ||
461 | /* Make a ".reg/999" section. */ | |
462 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
eea6121a | 463 | size, note->descpos + offset); |
38701953 AM |
464 | } |
465 | ||
b34976b6 | 466 | static bfd_boolean |
55fd94b0 | 467 | elf_i386_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
38701953 | 468 | { |
61adc1a4 | 469 | if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0) |
38701953 | 470 | { |
61adc1a4 NC |
471 | int pr_version = bfd_get_32 (abfd, note->descdata); |
472 | ||
473 | if (pr_version != 1) | |
b34976b6 | 474 | return FALSE; |
38701953 | 475 | |
228e534f | 476 | elf_tdata (abfd)->core->program |
61adc1a4 | 477 | = _bfd_elfcore_strndup (abfd, note->descdata + 8, 17); |
228e534f | 478 | elf_tdata (abfd)->core->command |
61adc1a4 NC |
479 | = _bfd_elfcore_strndup (abfd, note->descdata + 25, 81); |
480 | } | |
481 | else | |
482 | { | |
483 | switch (note->descsz) | |
484 | { | |
485 | default: | |
486 | return FALSE; | |
487 | ||
488 | case 124: /* Linux/i386 elf_prpsinfo. */ | |
228e534f | 489 | elf_tdata (abfd)->core->pid |
261b8d08 | 490 | = bfd_get_32 (abfd, note->descdata + 12); |
228e534f | 491 | elf_tdata (abfd)->core->program |
61adc1a4 | 492 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); |
228e534f | 493 | elf_tdata (abfd)->core->command |
61adc1a4 NC |
494 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); |
495 | } | |
38701953 AM |
496 | } |
497 | ||
498 | /* Note that for some reason, a spurious space is tacked | |
499 | onto the end of the args in some (at least one anyway) | |
500 | implementations, so strip it off if it exists. */ | |
38701953 | 501 | { |
228e534f | 502 | char *command = elf_tdata (abfd)->core->command; |
38701953 AM |
503 | int n = strlen (command); |
504 | ||
505 | if (0 < n && command[n - 1] == ' ') | |
506 | command[n - 1] = '\0'; | |
507 | } | |
508 | ||
b34976b6 | 509 | return TRUE; |
38701953 AM |
510 | } |
511 | \f | |
512 | /* Functions for the i386 ELF linker. | |
513 | ||
514 | In order to gain some understanding of code in this file without | |
515 | knowing all the intricate details of the linker, note the | |
516 | following: | |
517 | ||
518 | Functions named elf_i386_* are called by external routines, other | |
519 | functions are only called locally. elf_i386_* functions appear | |
520 | in this file more or less in the order in which they are called | |
521 | from external routines. eg. elf_i386_check_relocs is called | |
522 | early in the link process, elf_i386_finish_dynamic_sections is | |
523 | one of the last functions. */ | |
524 | ||
f604c2a2 | 525 | /* The size in bytes of an entry in the lazy procedure linkage table. */ |
252b5132 | 526 | |
f604c2a2 | 527 | #define LAZY_PLT_ENTRY_SIZE 16 |
252b5132 | 528 | |
f604c2a2 L |
529 | /* The size in bytes of an entry in the non-lazy procedure linkage |
530 | table. */ | |
252b5132 | 531 | |
f604c2a2 L |
532 | #define NON_LAZY_PLT_ENTRY_SIZE 8 |
533 | ||
534 | /* The first entry in an absolute lazy procedure linkage table looks | |
535 | like this. See the SVR4 ABI i386 supplement to see how this works. | |
536 | Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */ | |
537 | ||
538 | static const bfd_byte elf_i386_lazy_plt0_entry[12] = | |
252b5132 RH |
539 | { |
540 | 0xff, 0x35, /* pushl contents of address */ | |
541 | 0, 0, 0, 0, /* replaced with address of .got + 4. */ | |
542 | 0xff, 0x25, /* jmp indirect */ | |
eac338cf | 543 | 0, 0, 0, 0 /* replaced with address of .got + 8. */ |
252b5132 RH |
544 | }; |
545 | ||
f604c2a2 L |
546 | /* Subsequent entries in an absolute lazy procedure linkage table look |
547 | like this. */ | |
252b5132 | 548 | |
f604c2a2 | 549 | static const bfd_byte elf_i386_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
252b5132 RH |
550 | { |
551 | 0xff, 0x25, /* jmp indirect */ | |
552 | 0, 0, 0, 0, /* replaced with address of this symbol in .got. */ | |
553 | 0x68, /* pushl immediate */ | |
554 | 0, 0, 0, 0, /* replaced with offset into relocation table. */ | |
555 | 0xe9, /* jmp relative */ | |
556 | 0, 0, 0, 0 /* replaced with offset to start of .plt. */ | |
557 | }; | |
558 | ||
f604c2a2 L |
559 | /* The first entry in a PIC lazy procedure linkage table look like |
560 | this. Will be padded to LAZY_PLT_ENTRY_SIZE with | |
561 | lazy_plt->plt0_pad_byte. */ | |
252b5132 | 562 | |
f604c2a2 | 563 | static const bfd_byte elf_i386_pic_lazy_plt0_entry[12] = |
252b5132 RH |
564 | { |
565 | 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */ | |
eac338cf | 566 | 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */ |
252b5132 RH |
567 | }; |
568 | ||
f604c2a2 L |
569 | /* Subsequent entries in a PIC lazy procedure linkage table look like |
570 | this. */ | |
252b5132 | 571 | |
f604c2a2 | 572 | static const bfd_byte elf_i386_pic_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
252b5132 RH |
573 | { |
574 | 0xff, 0xa3, /* jmp *offset(%ebx) */ | |
575 | 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */ | |
576 | 0x68, /* pushl immediate */ | |
577 | 0, 0, 0, 0, /* replaced with offset into relocation table. */ | |
578 | 0xe9, /* jmp relative */ | |
579 | 0, 0, 0, 0 /* replaced with offset to start of .plt. */ | |
580 | }; | |
581 | ||
f604c2a2 | 582 | /* Entries in the non-lazy procedure linkage table look like this. */ |
dd7e64d4 | 583 | |
f604c2a2 | 584 | static const bfd_byte elf_i386_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] = |
dd7e64d4 L |
585 | { |
586 | 0xff, 0x25, /* jmp indirect */ | |
587 | 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */ | |
588 | 0x66, 0x90 /* xchg %ax,%ax */ | |
589 | }; | |
590 | ||
f604c2a2 L |
591 | /* Entries in the PIC non-lazy procedure linkage table look like |
592 | this. */ | |
dd7e64d4 | 593 | |
f604c2a2 | 594 | static const bfd_byte elf_i386_pic_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] = |
dd7e64d4 L |
595 | { |
596 | 0xff, 0xa3, /* jmp *offset(%ebx) */ | |
597 | 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */ | |
598 | 0x66, 0x90 /* xchg %ax,%ax */ | |
599 | }; | |
600 | ||
ee2fdd6f L |
601 | /* The first entry in an absolute IBT-enabled lazy procedure linkage |
602 | table looks like this. */ | |
603 | ||
604 | static const bfd_byte elf_i386_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] = | |
605 | { | |
606 | 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */ | |
607 | 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */ | |
608 | 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */ | |
609 | }; | |
610 | ||
611 | /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage | |
612 | table look like this. Subsequent entries for a PIC IBT-enabled lazy | |
613 | procedure linkage table are the same. */ | |
614 | ||
615 | static const bfd_byte elf_i386_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] = | |
616 | { | |
617 | 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */ | |
618 | 0x68, 0, 0, 0, 0, /* pushl immediate */ | |
619 | 0xe9, 0, 0, 0, 0, /* jmp relative */ | |
620 | 0x66, 0x90 /* xchg %ax,%ax */ | |
621 | }; | |
622 | ||
623 | /* The first entry in a PIC IBT-enabled lazy procedure linkage table | |
624 | look like. */ | |
625 | ||
626 | static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] = | |
627 | { | |
628 | 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */ | |
629 | 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */ | |
630 | 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */ | |
631 | }; | |
632 | ||
633 | /* Entries for branches with IBT-enabled in the absolute non-lazey | |
634 | procedure linkage table look like this. They have the same size | |
635 | as the lazy PLT entry. */ | |
636 | ||
637 | static const bfd_byte elf_i386_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] = | |
638 | { | |
639 | 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */ | |
640 | 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */ | |
641 | 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */ | |
642 | }; | |
643 | ||
644 | /* Entries for branches with IBT-enabled in the PIC non-lazey procedure | |
645 | linkage table look like this. They have the same size as the lazy | |
646 | PLT entry. */ | |
647 | ||
648 | static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] = | |
649 | { | |
650 | 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */ | |
651 | 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */ | |
652 | 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */ | |
653 | }; | |
654 | ||
f604c2a2 | 655 | /* .eh_frame covering the lazy .plt section. */ |
e41b3a13 | 656 | |
f604c2a2 | 657 | static const bfd_byte elf_i386_eh_frame_lazy_plt[] = |
e41b3a13 JJ |
658 | { |
659 | #define PLT_CIE_LENGTH 20 | |
660 | #define PLT_FDE_LENGTH 36 | |
661 | #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8 | |
662 | #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12 | |
663 | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ | |
664 | 0, 0, 0, 0, /* CIE ID */ | |
665 | 1, /* CIE version */ | |
666 | 'z', 'R', 0, /* Augmentation string */ | |
667 | 1, /* Code alignment factor */ | |
668 | 0x7c, /* Data alignment factor */ | |
669 | 8, /* Return address column */ | |
670 | 1, /* Augmentation size */ | |
671 | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ | |
672 | DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */ | |
673 | DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */ | |
674 | DW_CFA_nop, DW_CFA_nop, | |
675 | ||
676 | PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */ | |
677 | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ | |
678 | 0, 0, 0, 0, /* R_386_PC32 .plt goes here */ | |
679 | 0, 0, 0, 0, /* .plt size goes here */ | |
680 | 0, /* Augmentation size */ | |
681 | DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */ | |
682 | DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */ | |
683 | DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */ | |
684 | DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */ | |
685 | DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */ | |
686 | 11, /* Block length */ | |
687 | DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */ | |
688 | DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */ | |
689 | DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge, | |
28ede8be | 690 | DW_OP_lit2, DW_OP_shl, DW_OP_plus, |
e41b3a13 JJ |
691 | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop |
692 | }; | |
693 | ||
ee2fdd6f L |
694 | /* .eh_frame covering the lazy .plt section with IBT-enabled. */ |
695 | ||
696 | static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt[] = | |
697 | { | |
698 | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ | |
699 | 0, 0, 0, 0, /* CIE ID */ | |
700 | 1, /* CIE version */ | |
701 | 'z', 'R', 0, /* Augmentation string */ | |
702 | 1, /* Code alignment factor */ | |
703 | 0x7c, /* Data alignment factor */ | |
704 | 8, /* Return address column */ | |
705 | 1, /* Augmentation size */ | |
706 | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ | |
707 | DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */ | |
708 | DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */ | |
709 | DW_CFA_nop, DW_CFA_nop, | |
710 | ||
711 | PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */ | |
712 | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ | |
713 | 0, 0, 0, 0, /* R_386_PC32 .plt goes here */ | |
714 | 0, 0, 0, 0, /* .plt size goes here */ | |
715 | 0, /* Augmentation size */ | |
716 | DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */ | |
717 | DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */ | |
718 | DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */ | |
719 | DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */ | |
720 | DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */ | |
721 | 11, /* Block length */ | |
722 | DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */ | |
723 | DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */ | |
724 | DW_OP_lit15, DW_OP_and, DW_OP_lit9, DW_OP_ge, | |
725 | DW_OP_lit2, DW_OP_shl, DW_OP_plus, | |
726 | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop | |
727 | }; | |
728 | ||
f604c2a2 | 729 | /* .eh_frame covering the non-lazy .plt section. */ |
fff53dae | 730 | |
f604c2a2 | 731 | static const bfd_byte elf_i386_eh_frame_non_lazy_plt[] = |
fff53dae L |
732 | { |
733 | #define PLT_GOT_FDE_LENGTH 16 | |
734 | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ | |
735 | 0, 0, 0, 0, /* CIE ID */ | |
736 | 1, /* CIE version */ | |
737 | 'z', 'R', 0, /* Augmentation string */ | |
738 | 1, /* Code alignment factor */ | |
739 | 0x7c, /* Data alignment factor */ | |
740 | 8, /* Return address column */ | |
741 | 1, /* Augmentation size */ | |
742 | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ | |
743 | DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */ | |
744 | DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */ | |
745 | DW_CFA_nop, DW_CFA_nop, | |
746 | ||
747 | PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */ | |
748 | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ | |
f604c2a2 L |
749 | 0, 0, 0, 0, /* the start of non-lazy .plt goes here */ |
750 | 0, 0, 0, 0, /* non-lazy .plt size goes here */ | |
fff53dae L |
751 | 0, /* Augmentation size */ |
752 | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop | |
753 | }; | |
754 | ||
25e762b9 | 755 | /* These are the standard parameters. */ |
765e526c | 756 | static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt = |
25e762b9 | 757 | { |
f604c2a2 L |
758 | elf_i386_lazy_plt0_entry, /* plt0_entry */ |
759 | sizeof (elf_i386_lazy_plt0_entry), /* plt0_entry_size */ | |
f604c2a2 L |
760 | elf_i386_lazy_plt_entry, /* plt_entry */ |
761 | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ | |
765e526c L |
762 | 2, /* plt0_got1_offset */ |
763 | 8, /* plt0_got2_offset */ | |
764 | 0, /* plt0_got2_insn_end */ | |
25e762b9 RM |
765 | 2, /* plt_got_offset */ |
766 | 7, /* plt_reloc_offset */ | |
767 | 12, /* plt_plt_offset */ | |
765e526c L |
768 | 0, /* plt_got_insn_size */ |
769 | 0, /* plt_plt_insn_end */ | |
25e762b9 | 770 | 6, /* plt_lazy_offset */ |
f604c2a2 L |
771 | elf_i386_pic_lazy_plt0_entry, /* pic_plt0_entry */ |
772 | elf_i386_pic_lazy_plt_entry, /* pic_plt_entry */ | |
773 | elf_i386_eh_frame_lazy_plt, /* eh_frame_plt */ | |
774 | sizeof (elf_i386_eh_frame_lazy_plt) /* eh_frame_plt_size */ | |
775 | }; | |
776 | ||
765e526c | 777 | static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt = |
f604c2a2 L |
778 | { |
779 | elf_i386_non_lazy_plt_entry, /* plt_entry */ | |
780 | elf_i386_pic_non_lazy_plt_entry, /* pic_plt_entry */ | |
781 | NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ | |
782 | 2, /* plt_got_offset */ | |
765e526c | 783 | 0, /* plt_got_insn_size */ |
f604c2a2 L |
784 | elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */ |
785 | sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */ | |
25e762b9 | 786 | }; |
ee2fdd6f | 787 | |
765e526c | 788 | static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt = |
ee2fdd6f L |
789 | { |
790 | elf_i386_lazy_ibt_plt0_entry, /* plt0_entry */ | |
791 | sizeof (elf_i386_lazy_ibt_plt0_entry), /* plt0_entry_size */ | |
ee2fdd6f L |
792 | elf_i386_lazy_ibt_plt_entry, /* plt_entry */ |
793 | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ | |
765e526c L |
794 | 2, /* plt0_got1_offset */ |
795 | 8, /* plt0_got2_offset */ | |
796 | 0, /* plt0_got2_insn_end */ | |
ee2fdd6f L |
797 | 4+2, /* plt_got_offset */ |
798 | 4+1, /* plt_reloc_offset */ | |
799 | 4+6, /* plt_plt_offset */ | |
765e526c L |
800 | 0, /* plt_got_insn_size */ |
801 | 0, /* plt_plt_insn_end */ | |
ee2fdd6f L |
802 | 0, /* plt_lazy_offset */ |
803 | elf_i386_pic_lazy_ibt_plt0_entry, /* pic_plt0_entry */ | |
804 | elf_i386_lazy_ibt_plt_entry, /* pic_plt_entry */ | |
805 | elf_i386_eh_frame_lazy_ibt_plt, /* eh_frame_plt */ | |
806 | sizeof (elf_i386_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */ | |
807 | }; | |
808 | ||
765e526c | 809 | static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt = |
ee2fdd6f L |
810 | { |
811 | elf_i386_non_lazy_ibt_plt_entry, /* plt_entry */ | |
812 | elf_i386_pic_non_lazy_ibt_plt_entry,/* pic_plt_entry */ | |
813 | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ | |
814 | 4+2, /* plt_got_offset */ | |
765e526c | 815 | 0, /* plt_got_insn_size */ |
ee2fdd6f L |
816 | elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */ |
817 | sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */ | |
818 | }; | |
25e762b9 RM |
819 | \f |
820 | ||
eac338cf PB |
821 | /* On VxWorks, the .rel.plt.unloaded section has absolute relocations |
822 | for the PLTResolve stub and then for each PLT entry. */ | |
823 | #define PLTRESOLVE_RELOCS_SHLIB 0 | |
824 | #define PLTRESOLVE_RELOCS 2 | |
825 | #define PLT_NON_JUMP_SLOT_RELOCS 2 | |
826 | ||
23209a78 RM |
827 | /* Architecture-specific backend data for i386. */ |
828 | ||
829 | struct elf_i386_backend_data | |
830 | { | |
831 | /* Value used to fill the unused bytes of the first PLT entry. */ | |
832 | bfd_byte plt0_pad_byte; | |
833 | ||
f604c2a2 L |
834 | /* Target system. */ |
835 | enum | |
836 | { | |
837 | is_normal, | |
838 | is_vxworks, | |
839 | is_nacl | |
840 | } os; | |
23209a78 RM |
841 | }; |
842 | ||
843 | #define get_elf_i386_backend_data(abfd) \ | |
844 | ((const struct elf_i386_backend_data *) \ | |
845 | get_elf_backend_data (abfd)->arch_data) | |
846 | ||
847 | /* These are the standard parameters. */ | |
848 | static const struct elf_i386_backend_data elf_i386_arch_bed = | |
849 | { | |
850 | 0, /* plt0_pad_byte */ | |
f604c2a2 | 851 | is_normal /* os */ |
23209a78 RM |
852 | }; |
853 | ||
854 | #define elf_backend_arch_data &elf_i386_arch_bed | |
855 | ||
0afcef53 | 856 | /* Values in tls_type of x86 ELF linker hash entry. */ |
37e55690 JJ |
857 | #define GOT_TLS_IE 4 |
858 | #define GOT_TLS_IE_POS 5 | |
859 | #define GOT_TLS_IE_NEG 6 | |
860 | #define GOT_TLS_IE_BOTH 7 | |
67a4f2b7 AO |
861 | #define GOT_TLS_GDESC 8 |
862 | #define GOT_TLS_GD_BOTH_P(type) \ | |
863 | ((type) == (GOT_TLS_GD | GOT_TLS_GDESC)) | |
864 | #define GOT_TLS_GD_P(type) \ | |
865 | ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type)) | |
866 | #define GOT_TLS_GDESC_P(type) \ | |
867 | ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type)) | |
868 | #define GOT_TLS_GD_ANY_P(type) \ | |
869 | (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type)) | |
67a4f2b7 | 870 | |
0ffa91dd NC |
871 | #define is_i386_elf(bfd) \ |
872 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
873 | && elf_tdata (bfd) != NULL \ | |
4dfe6ac6 | 874 | && elf_object_id (bfd) == I386_ELF_DATA) |
0ffa91dd | 875 | |
67a4f2b7 | 876 | #define elf_i386_compute_jump_table_size(htab) \ |
998d811a | 877 | ((htab)->elf.srelplt->reloc_count * 4) |
67a4f2b7 | 878 | |
142411ca L |
879 | /* Return TRUE if the TLS access code sequence support transition |
880 | from R_TYPE. */ | |
881 | ||
882 | static bfd_boolean | |
bedfd056 | 883 | elf_i386_check_tls_transition (asection *sec, |
142411ca L |
884 | bfd_byte *contents, |
885 | Elf_Internal_Shdr *symtab_hdr, | |
886 | struct elf_link_hash_entry **sym_hashes, | |
887 | unsigned int r_type, | |
888 | const Elf_Internal_Rela *rel, | |
889 | const Elf_Internal_Rela *relend) | |
13ae64f3 | 890 | { |
6eaa7fb5 | 891 | unsigned int val, type, reg; |
142411ca L |
892 | unsigned long r_symndx; |
893 | struct elf_link_hash_entry *h; | |
894 | bfd_vma offset; | |
6eaa7fb5 | 895 | bfd_byte *call; |
1d4af308 | 896 | bfd_boolean indirect_call; |
142411ca | 897 | |
142411ca | 898 | offset = rel->r_offset; |
13ae64f3 | 899 | switch (r_type) |
142411ca L |
900 | { |
901 | case R_386_TLS_GD: | |
902 | case R_386_TLS_LDM: | |
903 | if (offset < 2 || (rel + 1) >= relend) | |
904 | return FALSE; | |
905 | ||
6eaa7fb5 L |
906 | indirect_call = FALSE; |
907 | call = contents + offset + 4; | |
908 | val = *(call - 5); | |
909 | type = *(call - 6); | |
142411ca L |
910 | if (r_type == R_386_TLS_GD) |
911 | { | |
09e8c3bf | 912 | /* Check transition from GD access model. Only |
6eaa7fb5 L |
913 | leal foo@tlsgd(,%ebx,1), %eax |
914 | call ___tls_get_addr@PLT | |
915 | or | |
916 | leal foo@tlsgd(%ebx) %eax | |
917 | call ___tls_get_addr@PLT | |
918 | nop | |
919 | or | |
920 | leal foo@tlsgd(%reg), %eax | |
921 | call *___tls_get_addr@GOT(%reg) | |
922 | which may be converted to | |
923 | addr32 call ___tls_get_addr | |
142411ca | 924 | can transit to different access model. */ |
6eaa7fb5 L |
925 | if ((offset + 10) > sec->size |
926 | || (type != 0x8d && type != 0x04)) | |
142411ca L |
927 | return FALSE; |
928 | ||
142411ca L |
929 | if (type == 0x04) |
930 | { | |
6eaa7fb5 L |
931 | /* leal foo@tlsgd(,%ebx,1), %eax |
932 | call ___tls_get_addr@PLT */ | |
142411ca L |
933 | if (offset < 3) |
934 | return FALSE; | |
935 | ||
6eaa7fb5 L |
936 | if (*(call - 7) != 0x8d |
937 | || val != 0x1d | |
938 | || call[0] != 0xe8) | |
142411ca L |
939 | return FALSE; |
940 | } | |
941 | else | |
942 | { | |
6eaa7fb5 L |
943 | /* This must be |
944 | leal foo@tlsgd(%ebx), %eax | |
945 | call ___tls_get_addr@PLT | |
946 | nop | |
947 | or | |
948 | leal foo@tlsgd(%reg), %eax | |
949 | call *___tls_get_addr@GOT(%reg) | |
950 | which may be converted to | |
951 | addr32 call ___tls_get_addr | |
952 | ||
953 | %eax can't be used as the GOT base register since it | |
954 | is used to pass parameter to ___tls_get_addr. */ | |
955 | reg = val & 7; | |
956 | if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0) | |
142411ca L |
957 | return FALSE; |
958 | ||
6eaa7fb5 L |
959 | indirect_call = call[0] == 0xff; |
960 | if (!(reg == 3 && call[0] == 0xe8 && call[5] == 0x90) | |
961 | && !(call[0] == 0x67 && call[1] == 0xe8) | |
962 | && !(indirect_call | |
963 | && (call[1] & 0xf8) == 0x90 | |
964 | && (call[1] & 0x7) == reg)) | |
142411ca L |
965 | return FALSE; |
966 | } | |
967 | } | |
968 | else | |
969 | { | |
970 | /* Check transition from LD access model. Only | |
6eaa7fb5 L |
971 | leal foo@tlsldm(%ebx), %eax |
972 | call ___tls_get_addr@PLT | |
973 | or | |
974 | leal foo@tlsldm(%reg), %eax | |
975 | call *___tls_get_addr@GOT(%reg) | |
976 | which may be converted to | |
977 | addr32 call ___tls_get_addr | |
142411ca L |
978 | can transit to different access model. */ |
979 | if (type != 0x8d || (offset + 9) > sec->size) | |
980 | return FALSE; | |
981 | ||
6eaa7fb5 L |
982 | /* %eax can't be used as the GOT base register since it is |
983 | used to pass parameter to ___tls_get_addr. */ | |
984 | reg = val & 7; | |
985 | if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0) | |
142411ca | 986 | return FALSE; |
142411ca | 987 | |
6eaa7fb5 L |
988 | indirect_call = call[0] == 0xff; |
989 | if (!(reg == 3 && call[0] == 0xe8) | |
990 | && !(call[0] == 0x67 && call[1] == 0xe8) | |
991 | && !(indirect_call | |
992 | && (call[1] & 0xf8) == 0x90 | |
993 | && (call[1] & 0x7) == reg)) | |
994 | return FALSE; | |
995 | } | |
142411ca L |
996 | |
997 | r_symndx = ELF32_R_SYM (rel[1].r_info); | |
998 | if (r_symndx < symtab_hdr->sh_info) | |
999 | return FALSE; | |
1000 | ||
1001 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1d4af308 | 1002 | if (h == NULL |
0afcef53 | 1003 | || !((struct elf_x86_link_hash_entry *) h)->tls_get_addr) |
6eaa7fb5 L |
1004 | return FALSE; |
1005 | else if (indirect_call) | |
1006 | return (ELF32_R_TYPE (rel[1].r_info) == R_386_GOT32X); | |
1007 | else | |
1008 | return (ELF32_R_TYPE (rel[1].r_info) == R_386_PC32 | |
1009 | || ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32); | |
142411ca L |
1010 | |
1011 | case R_386_TLS_IE: | |
1012 | /* Check transition from IE access model: | |
1013 | movl foo@indntpoff(%rip), %eax | |
1014 | movl foo@indntpoff(%rip), %reg | |
1015 | addl foo@indntpoff(%rip), %reg | |
1016 | */ | |
1017 | ||
1018 | if (offset < 1 || (offset + 4) > sec->size) | |
1019 | return FALSE; | |
1020 | ||
1021 | /* Check "movl foo@tpoff(%rip), %eax" first. */ | |
1022 | val = bfd_get_8 (abfd, contents + offset - 1); | |
1023 | if (val == 0xa1) | |
1024 | return TRUE; | |
1025 | ||
1026 | if (offset < 2) | |
1027 | return FALSE; | |
1028 | ||
1029 | /* Check movl|addl foo@tpoff(%rip), %reg. */ | |
1030 | type = bfd_get_8 (abfd, contents + offset - 2); | |
1031 | return ((type == 0x8b || type == 0x03) | |
1032 | && (val & 0xc7) == 0x05); | |
1033 | ||
1034 | case R_386_TLS_GOTIE: | |
1035 | case R_386_TLS_IE_32: | |
1036 | /* Check transition from {IE_32,GOTIE} access model: | |
1037 | subl foo@{tpoff,gontoff}(%reg1), %reg2 | |
1038 | movl foo@{tpoff,gontoff}(%reg1), %reg2 | |
1039 | addl foo@{tpoff,gontoff}(%reg1), %reg2 | |
1040 | */ | |
1041 | ||
1042 | if (offset < 2 || (offset + 4) > sec->size) | |
1043 | return FALSE; | |
1044 | ||
1045 | val = bfd_get_8 (abfd, contents + offset - 1); | |
1046 | if ((val & 0xc0) != 0x80 || (val & 7) == 4) | |
1047 | return FALSE; | |
1048 | ||
1049 | type = bfd_get_8 (abfd, contents + offset - 2); | |
1050 | return type == 0x8b || type == 0x2b || type == 0x03; | |
1051 | ||
1052 | case R_386_TLS_GOTDESC: | |
1053 | /* Check transition from GDesc access model: | |
1054 | leal x@tlsdesc(%ebx), %eax | |
1055 | ||
1056 | Make sure it's a leal adding ebx to a 32-bit offset | |
1057 | into any register, although it's probably almost always | |
1058 | going to be eax. */ | |
1059 | ||
1060 | if (offset < 2 || (offset + 4) > sec->size) | |
1061 | return FALSE; | |
1062 | ||
1063 | if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d) | |
1064 | return FALSE; | |
1065 | ||
1066 | val = bfd_get_8 (abfd, contents + offset - 1); | |
1067 | return (val & 0xc7) == 0x83; | |
1068 | ||
1069 | case R_386_TLS_DESC_CALL: | |
1070 | /* Check transition from GDesc access model: | |
6eaa7fb5 | 1071 | call *x@tlsdesc(%eax) |
142411ca L |
1072 | */ |
1073 | if (offset + 2 <= sec->size) | |
1074 | { | |
6eaa7fb5 L |
1075 | /* Make sure that it's a call *x@tlsdesc(%eax). */ |
1076 | call = contents + offset; | |
1077 | return call[0] == 0xff && call[1] == 0x10; | |
142411ca L |
1078 | } |
1079 | ||
1080 | return FALSE; | |
1081 | ||
1082 | default: | |
1083 | abort (); | |
1084 | } | |
1085 | } | |
1086 | ||
1087 | /* Return TRUE if the TLS access transition is OK or no transition | |
1088 | will be performed. Update R_TYPE if there is a transition. */ | |
1089 | ||
1090 | static bfd_boolean | |
1091 | elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd, | |
1092 | asection *sec, bfd_byte *contents, | |
1093 | Elf_Internal_Shdr *symtab_hdr, | |
1094 | struct elf_link_hash_entry **sym_hashes, | |
1095 | unsigned int *r_type, int tls_type, | |
1096 | const Elf_Internal_Rela *rel, | |
1097 | const Elf_Internal_Rela *relend, | |
4c544807 | 1098 | struct elf_link_hash_entry *h, |
bedfd056 L |
1099 | unsigned long r_symndx, |
1100 | bfd_boolean from_relocate_section) | |
142411ca L |
1101 | { |
1102 | unsigned int from_type = *r_type; | |
1103 | unsigned int to_type = from_type; | |
1104 | bfd_boolean check = TRUE; | |
1105 | ||
bb1cb422 L |
1106 | /* Skip TLS transition for functions. */ |
1107 | if (h != NULL | |
1108 | && (h->type == STT_FUNC | |
1109 | || h->type == STT_GNU_IFUNC)) | |
1110 | return TRUE; | |
1111 | ||
142411ca | 1112 | switch (from_type) |
13ae64f3 JJ |
1113 | { |
1114 | case R_386_TLS_GD: | |
67a4f2b7 AO |
1115 | case R_386_TLS_GOTDESC: |
1116 | case R_386_TLS_DESC_CALL: | |
13ae64f3 | 1117 | case R_386_TLS_IE_32: |
37e55690 JJ |
1118 | case R_386_TLS_IE: |
1119 | case R_386_TLS_GOTIE: | |
0e1862bb | 1120 | if (bfd_link_executable (info)) |
142411ca L |
1121 | { |
1122 | if (h == NULL) | |
1123 | to_type = R_386_TLS_LE_32; | |
1124 | else if (from_type != R_386_TLS_IE | |
1125 | && from_type != R_386_TLS_GOTIE) | |
1126 | to_type = R_386_TLS_IE_32; | |
1127 | } | |
1128 | ||
bedfd056 L |
1129 | /* When we are called from elf_i386_relocate_section, there may |
1130 | be additional transitions based on TLS_TYPE. */ | |
1131 | if (from_relocate_section) | |
142411ca L |
1132 | { |
1133 | unsigned int new_to_type = to_type; | |
1134 | ||
0e1862bb | 1135 | if (bfd_link_executable (info) |
142411ca L |
1136 | && h != NULL |
1137 | && h->dynindx == -1 | |
1138 | && (tls_type & GOT_TLS_IE)) | |
1139 | new_to_type = R_386_TLS_LE_32; | |
1140 | ||
1141 | if (to_type == R_386_TLS_GD | |
1142 | || to_type == R_386_TLS_GOTDESC | |
1143 | || to_type == R_386_TLS_DESC_CALL) | |
1144 | { | |
1145 | if (tls_type == GOT_TLS_IE_POS) | |
1146 | new_to_type = R_386_TLS_GOTIE; | |
1147 | else if (tls_type & GOT_TLS_IE) | |
1148 | new_to_type = R_386_TLS_IE_32; | |
1149 | } | |
1150 | ||
1151 | /* We checked the transition before when we were called from | |
1152 | elf_i386_check_relocs. We only want to check the new | |
1153 | transition which hasn't been checked before. */ | |
1154 | check = new_to_type != to_type && from_type == to_type; | |
1155 | to_type = new_to_type; | |
1156 | } | |
1157 | ||
1158 | break; | |
1159 | ||
13ae64f3 | 1160 | case R_386_TLS_LDM: |
0e1862bb | 1161 | if (bfd_link_executable (info)) |
142411ca L |
1162 | to_type = R_386_TLS_LE_32; |
1163 | break; | |
1164 | ||
1165 | default: | |
1166 | return TRUE; | |
1167 | } | |
1168 | ||
1169 | /* Return TRUE if there is no transition. */ | |
1170 | if (from_type == to_type) | |
1171 | return TRUE; | |
1172 | ||
1173 | /* Check if the transition can be performed. */ | |
1174 | if (check | |
bedfd056 | 1175 | && ! elf_i386_check_tls_transition (sec, contents, |
142411ca L |
1176 | symtab_hdr, sym_hashes, |
1177 | from_type, rel, relend)) | |
1178 | { | |
2f629d23 | 1179 | reloc_howto_type *from, *to; |
4c544807 | 1180 | const char *name; |
142411ca L |
1181 | |
1182 | from = elf_i386_rtype_to_howto (abfd, from_type); | |
1183 | to = elf_i386_rtype_to_howto (abfd, to_type); | |
1184 | ||
4c544807 L |
1185 | if (h) |
1186 | name = h->root.root.string; | |
1187 | else | |
1188 | { | |
0afcef53 | 1189 | struct elf_x86_link_hash_table *htab; |
4dfe6ac6 | 1190 | |
0afcef53 | 1191 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 NC |
1192 | if (htab == NULL) |
1193 | name = "*unknown*"; | |
1194 | else | |
1195 | { | |
1196 | Elf_Internal_Sym *isym; | |
1197 | ||
1198 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, | |
1199 | abfd, r_symndx); | |
1200 | name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); | |
1201 | } | |
4c544807 L |
1202 | } |
1203 | ||
4eca0228 | 1204 | _bfd_error_handler |
695344c0 | 1205 | /* xgettext:c-format */ |
d42c267e | 1206 | (_("%B: TLS transition from %s to %s against `%s' at %#Lx " |
142411ca | 1207 | "in section `%A' failed"), |
c08bb8dd | 1208 | abfd, from->name, to->name, name, |
d42c267e | 1209 | rel->r_offset, sec); |
142411ca L |
1210 | bfd_set_error (bfd_error_bad_value); |
1211 | return FALSE; | |
13ae64f3 JJ |
1212 | } |
1213 | ||
142411ca L |
1214 | *r_type = to_type; |
1215 | return TRUE; | |
13ae64f3 JJ |
1216 | } |
1217 | ||
c175a657 L |
1218 | /* With the local symbol, foo, we convert |
1219 | mov foo@GOT[(%reg1)], %reg2 | |
1220 | to | |
1221 | lea foo[@GOTOFF(%reg1)], %reg2 | |
1222 | and convert | |
1223 | call/jmp *foo@GOT[(%reg)] | |
1224 | to | |
1225 | nop call foo/jmp foo nop | |
1226 | When PIC is false, convert | |
1227 | test %reg1, foo@GOT[(%reg2)] | |
1228 | to | |
1229 | test $foo, %reg1 | |
1230 | and convert | |
1231 | binop foo@GOT[(%reg1)], %reg2 | |
1232 | to | |
1233 | binop $foo, %reg2 | |
1234 | where binop is one of adc, add, and, cmp, or, sbb, sub, xor | |
1235 | instructions. */ | |
1236 | ||
1237 | static | |
1238 | bfd_boolean | |
1239 | elf_i386_convert_load_reloc (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, | |
1240 | bfd_byte *contents, | |
1241 | Elf_Internal_Rela *irel, | |
1242 | struct elf_link_hash_entry *h, | |
1243 | bfd_boolean *converted, | |
1244 | struct bfd_link_info *link_info) | |
1245 | { | |
0afcef53 | 1246 | struct elf_x86_link_hash_table *htab; |
c175a657 L |
1247 | unsigned int opcode; |
1248 | unsigned int modrm; | |
1249 | bfd_boolean baseless; | |
1250 | Elf_Internal_Sym *isym; | |
1251 | unsigned int addend; | |
1252 | unsigned int nop; | |
1253 | bfd_vma nop_offset; | |
1254 | bfd_boolean is_pic; | |
1255 | bfd_boolean to_reloc_32; | |
1256 | unsigned int r_type; | |
1257 | unsigned int r_symndx; | |
1258 | bfd_vma roff = irel->r_offset; | |
1259 | ||
1260 | if (roff < 2) | |
1261 | return TRUE; | |
1262 | ||
7d4d9709 | 1263 | /* Addend for R_386_GOT32X relocations must be 0. */ |
c175a657 L |
1264 | addend = bfd_get_32 (abfd, contents + roff); |
1265 | if (addend != 0) | |
1266 | return TRUE; | |
1267 | ||
0afcef53 | 1268 | htab = elf_x86_hash_table (link_info, I386_ELF_DATA); |
c175a657 L |
1269 | is_pic = bfd_link_pic (link_info); |
1270 | ||
1271 | r_type = ELF32_R_TYPE (irel->r_info); | |
1272 | r_symndx = ELF32_R_SYM (irel->r_info); | |
1273 | ||
1274 | modrm = bfd_get_8 (abfd, contents + roff - 1); | |
1275 | baseless = (modrm & 0xc7) == 0x5; | |
1276 | ||
7d4d9709 | 1277 | if (baseless && is_pic) |
c175a657 L |
1278 | { |
1279 | /* For PIC, disallow R_386_GOT32X without a base register | |
7d4d9709 | 1280 | since we don't know what the GOT base is. */ |
c175a657 L |
1281 | const char *name; |
1282 | ||
1283 | if (h == NULL) | |
1284 | { | |
1285 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, | |
1286 | r_symndx); | |
1287 | name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); | |
1288 | } | |
1289 | else | |
1290 | name = h->root.root.string; | |
1291 | ||
4eca0228 | 1292 | _bfd_error_handler |
695344c0 | 1293 | /* xgettext:c-format */ |
63a5468a AM |
1294 | (_("%B: direct GOT relocation R_386_GOT32X against `%s' without base" |
1295 | " register can not be used when making a shared object"), | |
c175a657 L |
1296 | abfd, name); |
1297 | return FALSE; | |
1298 | } | |
1299 | ||
1300 | opcode = bfd_get_8 (abfd, contents + roff - 2); | |
1301 | ||
c175a657 L |
1302 | /* Convert to R_386_32 if PIC is false or there is no base |
1303 | register. */ | |
1304 | to_reloc_32 = !is_pic || baseless; | |
1305 | ||
7d4d9709 L |
1306 | /* Try to convert R_386_GOT32X. Get the symbol referred to by the |
1307 | reloc. */ | |
c175a657 L |
1308 | if (h == NULL) |
1309 | { | |
1310 | if (opcode == 0x0ff) | |
1311 | /* Convert "call/jmp *foo@GOT[(%reg)]". */ | |
1312 | goto convert_branch; | |
1313 | else | |
1314 | /* Convert "mov foo@GOT[(%reg1)], %reg2", | |
1315 | "test %reg1, foo@GOT(%reg2)" and | |
1316 | "binop foo@GOT[(%reg1)], %reg2". */ | |
1317 | goto convert_load; | |
1318 | } | |
1319 | ||
1320 | /* Undefined weak symbol is only bound locally in executable | |
1321 | and its reference is resolved as 0. */ | |
0afcef53 L |
1322 | if (UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info, I386_ELF_DATA, TRUE, |
1323 | elf_x86_hash_entry (h))) | |
c175a657 L |
1324 | { |
1325 | if (opcode == 0xff) | |
1326 | { | |
1327 | /* No direct branch to 0 for PIC. */ | |
1328 | if (is_pic) | |
1329 | return TRUE; | |
1330 | else | |
1331 | goto convert_branch; | |
1332 | } | |
1333 | else | |
1334 | { | |
1335 | /* We can convert load of address 0 to R_386_32. */ | |
1336 | to_reloc_32 = TRUE; | |
1337 | goto convert_load; | |
1338 | } | |
1339 | } | |
1340 | ||
1341 | if (opcode == 0xff) | |
1342 | { | |
1343 | /* We have "call/jmp *foo@GOT[(%reg)]". */ | |
1344 | if ((h->root.type == bfd_link_hash_defined | |
1345 | || h->root.type == bfd_link_hash_defweak) | |
1346 | && SYMBOL_REFERENCES_LOCAL (link_info, h)) | |
1347 | { | |
1348 | /* The function is locally defined. */ | |
1349 | convert_branch: | |
1350 | /* Convert R_386_GOT32X to R_386_PC32. */ | |
1351 | if (modrm == 0x15 || (modrm & 0xf8) == 0x90) | |
1352 | { | |
0afcef53 L |
1353 | struct elf_x86_link_hash_entry *eh |
1354 | = (struct elf_x86_link_hash_entry *) h; | |
6eaa7fb5 | 1355 | |
c175a657 L |
1356 | /* Convert to "nop call foo". ADDR_PREFIX_OPCODE |
1357 | is a nop prefix. */ | |
1358 | modrm = 0xe8; | |
6eaa7fb5 L |
1359 | /* To support TLS optimization, always use addr32 prefix |
1360 | for "call *___tls_get_addr@GOT(%reg)". */ | |
1d4af308 | 1361 | if (eh && eh->tls_get_addr) |
c175a657 | 1362 | { |
6eaa7fb5 L |
1363 | nop = 0x67; |
1364 | nop_offset = irel->r_offset - 2; | |
c175a657 L |
1365 | } |
1366 | else | |
6eaa7fb5 L |
1367 | { |
1368 | nop = link_info->call_nop_byte; | |
1369 | if (link_info->call_nop_as_suffix) | |
1370 | { | |
1371 | nop_offset = roff + 3; | |
1372 | irel->r_offset -= 1; | |
1373 | } | |
1374 | else | |
1375 | nop_offset = roff - 2; | |
1376 | } | |
c175a657 L |
1377 | } |
1378 | else | |
1379 | { | |
1380 | /* Convert to "jmp foo nop". */ | |
1381 | modrm = 0xe9; | |
1382 | nop = NOP_OPCODE; | |
1383 | nop_offset = roff + 3; | |
1384 | irel->r_offset -= 1; | |
1385 | } | |
1386 | ||
1387 | bfd_put_8 (abfd, nop, contents + nop_offset); | |
1388 | bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1); | |
1389 | /* When converting to PC-relative relocation, we | |
1390 | need to adjust addend by -4. */ | |
1391 | bfd_put_32 (abfd, -4, contents + irel->r_offset); | |
1392 | irel->r_info = ELF32_R_INFO (r_symndx, R_386_PC32); | |
1393 | ||
1394 | *converted = TRUE; | |
1395 | } | |
1396 | } | |
1397 | else | |
1398 | { | |
1399 | /* We have "mov foo@GOT[(%re1g)], %reg2", | |
1400 | "test %reg1, foo@GOT(%reg2)" and | |
1401 | "binop foo@GOT[(%reg1)], %reg2". | |
1402 | ||
1403 | Avoid optimizing _DYNAMIC since ld.so may use its | |
1404 | link-time address. */ | |
1405 | if (h == htab->elf.hdynamic) | |
1406 | return TRUE; | |
1407 | ||
1408 | /* def_regular is set by an assignment in a linker script in | |
cbd0eecf L |
1409 | bfd_elf_record_link_assignment. start_stop is set on |
1410 | __start_SECNAME/__stop_SECNAME which mark section SECNAME. */ | |
1411 | if (h->start_stop | |
1412 | || ((h->def_regular | |
1413 | || h->root.type == bfd_link_hash_defined | |
1414 | || h->root.type == bfd_link_hash_defweak) | |
1415 | && SYMBOL_REFERENCES_LOCAL (link_info, h))) | |
c175a657 L |
1416 | { |
1417 | convert_load: | |
1418 | if (opcode == 0x8b) | |
1419 | { | |
1420 | if (to_reloc_32) | |
1421 | { | |
1422 | /* Convert "mov foo@GOT[(%reg1)], %reg2" to | |
1423 | "mov $foo, %reg2" with R_386_32. */ | |
1424 | r_type = R_386_32; | |
1425 | modrm = 0xc0 | (modrm & 0x38) >> 3; | |
1426 | bfd_put_8 (abfd, modrm, contents + roff - 1); | |
1427 | opcode = 0xc7; | |
1428 | } | |
1429 | else | |
1430 | { | |
1431 | /* Convert "mov foo@GOT(%reg1), %reg2" to | |
1432 | "lea foo@GOTOFF(%reg1), %reg2". */ | |
1433 | r_type = R_386_GOTOFF; | |
1434 | opcode = 0x8d; | |
1435 | } | |
1436 | } | |
1437 | else | |
1438 | { | |
1439 | /* Only R_386_32 is supported. */ | |
1440 | if (!to_reloc_32) | |
1441 | return TRUE; | |
1442 | ||
1443 | if (opcode == 0x85) | |
1444 | { | |
1445 | /* Convert "test %reg1, foo@GOT(%reg2)" to | |
1446 | "test $foo, %reg1". */ | |
1447 | modrm = 0xc0 | (modrm & 0x38) >> 3; | |
1448 | opcode = 0xf7; | |
1449 | } | |
1450 | else | |
1451 | { | |
1452 | /* Convert "binop foo@GOT(%reg1), %reg2" to | |
1453 | "binop $foo, %reg2". */ | |
1454 | modrm = (0xc0 | |
1455 | | (modrm & 0x38) >> 3 | |
1456 | | (opcode & 0x3c)); | |
1457 | opcode = 0x81; | |
1458 | } | |
1459 | bfd_put_8 (abfd, modrm, contents + roff - 1); | |
1460 | r_type = R_386_32; | |
1461 | } | |
1462 | ||
1463 | bfd_put_8 (abfd, opcode, contents + roff - 2); | |
1464 | irel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
1465 | ||
1466 | *converted = TRUE; | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | return TRUE; | |
1471 | } | |
1472 | ||
c1d11331 L |
1473 | /* Rename some of the generic section flags to better document how they |
1474 | are used here. */ | |
c337a162 L |
1475 | #define need_convert_load sec_flg0 |
1476 | #define check_relocs_failed sec_flg1 | |
c1d11331 | 1477 | |
252b5132 | 1478 | /* Look through the relocs for a section during the first phase, and |
0ac8d2ca AM |
1479 | calculate needed space in the global offset table, procedure linkage |
1480 | table, and dynamic reloc sections. */ | |
252b5132 | 1481 | |
b34976b6 | 1482 | static bfd_boolean |
55fd94b0 AM |
1483 | elf_i386_check_relocs (bfd *abfd, |
1484 | struct bfd_link_info *info, | |
1485 | asection *sec, | |
1486 | const Elf_Internal_Rela *relocs) | |
252b5132 | 1487 | { |
0afcef53 | 1488 | struct elf_x86_link_hash_table *htab; |
252b5132 RH |
1489 | Elf_Internal_Shdr *symtab_hdr; |
1490 | struct elf_link_hash_entry **sym_hashes; | |
252b5132 RH |
1491 | const Elf_Internal_Rela *rel; |
1492 | const Elf_Internal_Rela *rel_end; | |
252b5132 | 1493 | asection *sreloc; |
bedfd056 | 1494 | bfd_byte *contents; |
252b5132 | 1495 | |
0e1862bb | 1496 | if (bfd_link_relocatable (info)) |
b34976b6 | 1497 | return TRUE; |
252b5132 | 1498 | |
081b1afe L |
1499 | /* Don't do anything special with non-loaded, non-alloced sections. |
1500 | In particular, any relocs in such sections should not affect GOT | |
1501 | and PLT reference counting (ie. we don't allow them to create GOT | |
1502 | or PLT entries), there's no possibility or desire to optimize TLS | |
1503 | relocs, and there's not much point in propagating relocs to shared | |
1504 | libs that the dynamic linker won't relocate. */ | |
1505 | if ((sec->flags & SEC_ALLOC) == 0) | |
1506 | return TRUE; | |
1507 | ||
0ffa91dd NC |
1508 | BFD_ASSERT (is_i386_elf (abfd)); |
1509 | ||
0afcef53 | 1510 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 | 1511 | if (htab == NULL) |
c337a162 L |
1512 | { |
1513 | sec->check_relocs_failed = 1; | |
1514 | return FALSE; | |
1515 | } | |
4dfe6ac6 | 1516 | |
bedfd056 L |
1517 | /* Get the section contents. */ |
1518 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
1519 | contents = elf_section_data (sec)->this_hdr.contents; | |
1520 | else if (!bfd_malloc_and_get_section (abfd, sec, &contents)) | |
1521 | { | |
1522 | sec->check_relocs_failed = 1; | |
1523 | return FALSE; | |
1524 | } | |
1525 | ||
0ffa91dd | 1526 | symtab_hdr = &elf_symtab_hdr (abfd); |
252b5132 | 1527 | sym_hashes = elf_sym_hashes (abfd); |
252b5132 | 1528 | |
252b5132 RH |
1529 | sreloc = NULL; |
1530 | ||
1531 | rel_end = relocs + sec->reloc_count; | |
1532 | for (rel = relocs; rel < rel_end; rel++) | |
1533 | { | |
13ae64f3 | 1534 | unsigned int r_type; |
d42c267e | 1535 | unsigned int r_symndx; |
252b5132 | 1536 | struct elf_link_hash_entry *h; |
0afcef53 | 1537 | struct elf_x86_link_hash_entry *eh; |
4c544807 L |
1538 | Elf_Internal_Sym *isym; |
1539 | const char *name; | |
06a6a421 | 1540 | bfd_boolean size_reloc; |
252b5132 RH |
1541 | |
1542 | r_symndx = ELF32_R_SYM (rel->r_info); | |
13ae64f3 | 1543 | r_type = ELF32_R_TYPE (rel->r_info); |
252b5132 | 1544 | |
d9bc7a44 | 1545 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
f5f31454 | 1546 | { |
695344c0 | 1547 | /* xgettext:c-format */ |
4eca0228 AM |
1548 | _bfd_error_handler (_("%B: bad symbol index: %d"), |
1549 | abfd, r_symndx); | |
c337a162 | 1550 | goto error_return; |
f5f31454 L |
1551 | } |
1552 | ||
252b5132 | 1553 | if (r_symndx < symtab_hdr->sh_info) |
c25bc9fc L |
1554 | { |
1555 | /* A local symbol. */ | |
c2e61a4e L |
1556 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
1557 | abfd, r_symndx); | |
1558 | if (isym == NULL) | |
c337a162 | 1559 | goto error_return; |
c25bc9fc L |
1560 | |
1561 | /* Check relocation against local STT_GNU_IFUNC symbol. */ | |
c25bc9fc L |
1562 | if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
1563 | { | |
0afcef53 | 1564 | h = _bfd_elf_x86_get_local_sym_hash (htab, abfd, rel, TRUE); |
c25bc9fc | 1565 | if (h == NULL) |
c337a162 | 1566 | goto error_return; |
6bbec505 | 1567 | |
c25bc9fc | 1568 | /* Fake a STT_GNU_IFUNC symbol. */ |
6322e5c5 L |
1569 | h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr, |
1570 | isym, NULL); | |
c25bc9fc L |
1571 | h->type = STT_GNU_IFUNC; |
1572 | h->def_regular = 1; | |
1573 | h->ref_regular = 1; | |
1574 | h->forced_local = 1; | |
1575 | h->root.type = bfd_link_hash_defined; | |
1576 | } | |
1577 | else | |
1578 | h = NULL; | |
1579 | } | |
252b5132 | 1580 | else |
71cb9464 | 1581 | { |
4c544807 | 1582 | isym = NULL; |
71cb9464 L |
1583 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
1584 | while (h->root.type == bfd_link_hash_indirect | |
1585 | || h->root.type == bfd_link_hash_warning) | |
1586 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
c25bc9fc | 1587 | } |
cbe950e9 | 1588 | |
0afcef53 | 1589 | eh = (struct elf_x86_link_hash_entry *) h; |
c25bc9fc L |
1590 | if (h != NULL) |
1591 | { | |
f604c2a2 L |
1592 | if (r_type == R_386_GOTOFF) |
1593 | eh->gotoff_ref = 1; | |
cbe950e9 | 1594 | |
ad1e85de L |
1595 | /* It is referenced by a non-shared object. */ |
1596 | h->ref_regular = 1; | |
bc4e12de | 1597 | h->root.non_ir_ref_regular = 1; |
13a2df29 L |
1598 | |
1599 | if (h->type == STT_GNU_IFUNC) | |
1600 | elf_tdata (info->output_bfd)->has_gnu_symbols | |
1601 | |= elf_gnu_symbol_ifunc; | |
71cb9464 | 1602 | } |
252b5132 | 1603 | |
bedfd056 | 1604 | if (! elf_i386_tls_transition (info, abfd, sec, contents, |
142411ca L |
1605 | symtab_hdr, sym_hashes, |
1606 | &r_type, GOT_UNKNOWN, | |
bedfd056 | 1607 | rel, rel_end, h, r_symndx, FALSE)) |
c337a162 | 1608 | goto error_return; |
13ae64f3 JJ |
1609 | |
1610 | switch (r_type) | |
252b5132 | 1611 | { |
37e55690 | 1612 | case R_386_TLS_LDM: |
0afcef53 | 1613 | htab->tls_ld_or_ldm_got.refcount += 1; |
37e55690 JJ |
1614 | goto create_got; |
1615 | ||
1616 | case R_386_PLT32: | |
1617 | /* This symbol requires a procedure linkage table entry. We | |
1618 | actually build the entry in adjust_dynamic_symbol, | |
1619 | because this might be a case of linking PIC code which is | |
1620 | never referenced by a dynamic object, in which case we | |
1621 | don't need to generate a procedure linkage table entry | |
1622 | after all. */ | |
1623 | ||
1624 | /* If this is a local symbol, we resolve it directly without | |
1625 | creating a procedure linkage table entry. */ | |
1626 | if (h == NULL) | |
1627 | continue; | |
1628 | ||
aec6b87e | 1629 | eh->has_got_reloc = 1; |
f5385ebf | 1630 | h->needs_plt = 1; |
37e55690 JJ |
1631 | h->plt.refcount += 1; |
1632 | break; | |
1633 | ||
6a3e1bae | 1634 | case R_386_SIZE32: |
06a6a421 | 1635 | size_reloc = TRUE; |
6a3e1bae L |
1636 | goto do_size; |
1637 | ||
13ae64f3 | 1638 | case R_386_TLS_IE_32: |
37e55690 JJ |
1639 | case R_386_TLS_IE: |
1640 | case R_386_TLS_GOTIE: | |
0e1862bb | 1641 | if (!bfd_link_executable (info)) |
13ae64f3 | 1642 | info->flags |= DF_STATIC_TLS; |
37e55690 JJ |
1643 | /* Fall through */ |
1644 | ||
252b5132 | 1645 | case R_386_GOT32: |
02a86693 | 1646 | case R_386_GOT32X: |
13ae64f3 | 1647 | case R_386_TLS_GD: |
67a4f2b7 AO |
1648 | case R_386_TLS_GOTDESC: |
1649 | case R_386_TLS_DESC_CALL: | |
252b5132 | 1650 | /* This symbol requires a global offset table entry. */ |
13ae64f3 JJ |
1651 | { |
1652 | int tls_type, old_tls_type; | |
1653 | ||
1654 | switch (r_type) | |
1655 | { | |
1656 | default: | |
02a86693 L |
1657 | case R_386_GOT32: |
1658 | case R_386_GOT32X: | |
1659 | tls_type = GOT_NORMAL; | |
1660 | break; | |
13ae64f3 | 1661 | case R_386_TLS_GD: tls_type = GOT_TLS_GD; break; |
67a4f2b7 AO |
1662 | case R_386_TLS_GOTDESC: |
1663 | case R_386_TLS_DESC_CALL: | |
1664 | tls_type = GOT_TLS_GDESC; break; | |
37e55690 JJ |
1665 | case R_386_TLS_IE_32: |
1666 | if (ELF32_R_TYPE (rel->r_info) == r_type) | |
1667 | tls_type = GOT_TLS_IE_NEG; | |
1668 | else | |
ebcfb3c0 JJ |
1669 | /* If this is a GD->IE transition, we may use either of |
1670 | R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */ | |
37e55690 JJ |
1671 | tls_type = GOT_TLS_IE; |
1672 | break; | |
1673 | case R_386_TLS_IE: | |
1674 | case R_386_TLS_GOTIE: | |
1675 | tls_type = GOT_TLS_IE_POS; break; | |
13ae64f3 JJ |
1676 | } |
1677 | ||
1678 | if (h != NULL) | |
1679 | { | |
1680 | h->got.refcount += 1; | |
0afcef53 | 1681 | old_tls_type = elf_x86_hash_entry (h)->tls_type; |
13ae64f3 JJ |
1682 | } |
1683 | else | |
1684 | { | |
1685 | bfd_signed_vma *local_got_refcounts; | |
1686 | ||
1687 | /* This is a global offset table entry for a local symbol. */ | |
1688 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
1689 | if (local_got_refcounts == NULL) | |
1690 | { | |
1691 | bfd_size_type size; | |
1692 | ||
1693 | size = symtab_hdr->sh_info; | |
67a4f2b7 AO |
1694 | size *= (sizeof (bfd_signed_vma) |
1695 | + sizeof (bfd_vma) + sizeof(char)); | |
a50b1753 NC |
1696 | local_got_refcounts = (bfd_signed_vma *) |
1697 | bfd_zalloc (abfd, size); | |
13ae64f3 | 1698 | if (local_got_refcounts == NULL) |
c337a162 | 1699 | goto error_return; |
13ae64f3 | 1700 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
0afcef53 | 1701 | elf_x86_local_tlsdesc_gotent (abfd) |
67a4f2b7 | 1702 | = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info); |
0afcef53 | 1703 | elf_x86_local_got_tls_type (abfd) |
67a4f2b7 | 1704 | = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info); |
13ae64f3 JJ |
1705 | } |
1706 | local_got_refcounts[r_symndx] += 1; | |
0afcef53 | 1707 | old_tls_type = elf_x86_local_got_tls_type (abfd) [r_symndx]; |
13ae64f3 JJ |
1708 | } |
1709 | ||
37e55690 JJ |
1710 | if ((old_tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_IE)) |
1711 | tls_type |= old_tls_type; | |
13ae64f3 JJ |
1712 | /* If a TLS symbol is accessed using IE at least once, |
1713 | there is no point to use dynamic model for it. */ | |
ebcfb3c0 | 1714 | else if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN |
67a4f2b7 | 1715 | && (! GOT_TLS_GD_ANY_P (old_tls_type) |
37e55690 | 1716 | || (tls_type & GOT_TLS_IE) == 0)) |
13ae64f3 | 1717 | { |
67a4f2b7 | 1718 | if ((old_tls_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (tls_type)) |
37e55690 | 1719 | tls_type = old_tls_type; |
67a4f2b7 AO |
1720 | else if (GOT_TLS_GD_ANY_P (old_tls_type) |
1721 | && GOT_TLS_GD_ANY_P (tls_type)) | |
1722 | tls_type |= old_tls_type; | |
13ae64f3 JJ |
1723 | else |
1724 | { | |
09a24cbf | 1725 | if (h) |
4c544807 L |
1726 | name = h->root.root.string; |
1727 | else | |
1728 | name = bfd_elf_sym_name (abfd, symtab_hdr, isym, | |
1729 | NULL); | |
4eca0228 | 1730 | _bfd_error_handler |
695344c0 | 1731 | /* xgettext:c-format */ |
d003868e | 1732 | (_("%B: `%s' accessed both as normal and " |
55fd94b0 | 1733 | "thread local symbol"), |
4c544807 | 1734 | abfd, name); |
68c4a57e | 1735 | bfd_set_error (bfd_error_bad_value); |
c337a162 | 1736 | goto error_return; |
13ae64f3 JJ |
1737 | } |
1738 | } | |
1739 | ||
1740 | if (old_tls_type != tls_type) | |
1741 | { | |
1742 | if (h != NULL) | |
0afcef53 | 1743 | elf_x86_hash_entry (h)->tls_type = tls_type; |
13ae64f3 | 1744 | else |
0afcef53 | 1745 | elf_x86_local_got_tls_type (abfd) [r_symndx] = tls_type; |
13ae64f3 JJ |
1746 | } |
1747 | } | |
0ac8d2ca AM |
1748 | /* Fall through */ |
1749 | ||
1750 | case R_386_GOTOFF: | |
1751 | case R_386_GOTPC: | |
13ae64f3 | 1752 | create_got: |
37e55690 | 1753 | if (r_type != R_386_TLS_IE) |
aec6b87e L |
1754 | { |
1755 | if (eh != NULL) | |
1756 | eh->has_got_reloc = 1; | |
1757 | break; | |
1758 | } | |
37e55690 | 1759 | /* Fall through */ |
252b5132 | 1760 | |
37e55690 JJ |
1761 | case R_386_TLS_LE_32: |
1762 | case R_386_TLS_LE: | |
aec6b87e L |
1763 | if (eh != NULL) |
1764 | eh->has_got_reloc = 1; | |
0e1862bb | 1765 | if (bfd_link_executable (info)) |
37e55690 | 1766 | break; |
bffbf940 | 1767 | info->flags |= DF_STATIC_TLS; |
aec6b87e | 1768 | goto do_relocation; |
252b5132 RH |
1769 | |
1770 | case R_386_32: | |
1771 | case R_386_PC32: | |
aec6b87e L |
1772 | if (eh != NULL && (sec->flags & SEC_CODE) != 0) |
1773 | eh->has_non_got_reloc = 1; | |
1774 | do_relocation: | |
bf52d7c7 L |
1775 | /* We are called after all symbols have been resolved. Only |
1776 | relocation against STT_GNU_IFUNC symbol must go through | |
1777 | PLT. */ | |
d1ed1c7d L |
1778 | if (h != NULL |
1779 | && (bfd_link_executable (info) | |
bf52d7c7 | 1780 | || h->type == STT_GNU_IFUNC)) |
6725bdbf | 1781 | { |
12d0ee4a | 1782 | /* If this reloc is in a read-only section, we might |
ebe50bae AM |
1783 | need a copy reloc. We can't check reliably at this |
1784 | stage whether the section is read-only, as input | |
1785 | sections have not yet been mapped to output sections. | |
1786 | Tentatively set the flag for now, and correct in | |
1787 | adjust_dynamic_symbol. */ | |
f5385ebf | 1788 | h->non_got_ref = 1; |
12d0ee4a | 1789 | |
233cc9c1 L |
1790 | /* We may need a .plt entry if the symbol is a function |
1791 | defined in a shared lib or is a STT_GNU_IFUNC function | |
1792 | referenced from the code or read-only section. */ | |
34bb2571 L |
1793 | if (!h->def_regular |
1794 | || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) | |
233cc9c1 L |
1795 | h->plt.refcount += 1; |
1796 | ||
4b627c18 L |
1797 | if (r_type == R_386_PC32) |
1798 | { | |
1799 | /* Since something like ".long foo - ." may be used | |
1800 | as pointer, make sure that PLT is used if foo is | |
1801 | a function defined in a shared library. */ | |
1802 | if ((sec->flags & SEC_CODE) == 0) | |
1803 | h->pointer_equality_needed = 1; | |
74437ea2 L |
1804 | else if (h->type == STT_GNU_IFUNC |
1805 | && bfd_link_pic (info)) | |
1806 | { | |
6322e5c5 L |
1807 | _bfd_error_handler |
1808 | /* xgettext:c-format */ | |
1809 | (_("%B: unsupported non-PIC call to IFUNC `%s'"), | |
1810 | abfd, h->root.root.string); | |
74437ea2 L |
1811 | bfd_set_error (bfd_error_bad_value); |
1812 | goto error_return; | |
1813 | } | |
4b627c18 L |
1814 | } |
1815 | else | |
04ebc307 L |
1816 | { |
1817 | h->pointer_equality_needed = 1; | |
1818 | /* R_386_32 can be resolved at run-time. */ | |
1819 | if (r_type == R_386_32 | |
1820 | && (sec->flags & SEC_READONLY) == 0) | |
1821 | eh->func_pointer_refcount += 1; | |
1822 | } | |
6725bdbf | 1823 | } |
7843f00e | 1824 | |
06a6a421 | 1825 | size_reloc = FALSE; |
6a3e1bae | 1826 | do_size: |
252b5132 | 1827 | /* If we are creating a shared library, and this is a reloc |
f69da49f AM |
1828 | against a global symbol, or a non PC relative reloc |
1829 | against a local symbol, then we need to copy the reloc | |
1830 | into the shared library. However, if we are linking with | |
1831 | -Bsymbolic, we do not need to copy a reloc against a | |
1832 | global symbol which is defined in an object we are | |
1833 | including in the link (i.e., DEF_REGULAR is set). At | |
1834 | this point we have not seen all the input files, so it is | |
1835 | possible that DEF_REGULAR is not set now but will be set | |
1f655a09 L |
1836 | later (it is never cleared). In case of a weak definition, |
1837 | DEF_REGULAR may be cleared later by a strong definition in | |
ebe50bae | 1838 | a shared library. We account for that possibility below by |
1f655a09 L |
1839 | storing information in the relocs_copied field of the hash |
1840 | table entry. A similar situation occurs when creating | |
1841 | shared libraries and symbol visibility changes render the | |
12d0ee4a | 1842 | symbol local. |
56882138 | 1843 | |
12d0ee4a AM |
1844 | If on the other hand, we are creating an executable, we |
1845 | may need to keep relocations for symbols satisfied by a | |
1846 | dynamic library if we manage to avoid copy relocs for the | |
233cc9c1 L |
1847 | symbol. |
1848 | ||
1849 | Generate dynamic pointer relocation against STT_GNU_IFUNC | |
1850 | symbol in the non-code section. */ | |
081b1afe L |
1851 | if ((bfd_link_pic (info) |
1852 | && (r_type != R_386_PC32 | |
1853 | || (h != NULL | |
1854 | && (! (bfd_link_pie (info) | |
1855 | || SYMBOLIC_BIND (info, h)) | |
1856 | || h->root.type == bfd_link_hash_defweak | |
1857 | || !h->def_regular)))) | |
233cc9c1 L |
1858 | || (h != NULL |
1859 | && h->type == STT_GNU_IFUNC | |
1860 | && r_type == R_386_32 | |
1861 | && (sec->flags & SEC_CODE) == 0) | |
081b1afe L |
1862 | || (ELIMINATE_COPY_RELOCS |
1863 | && !bfd_link_pic (info) | |
1864 | && h != NULL | |
1865 | && (h->root.type == bfd_link_hash_defweak | |
1866 | || !h->def_regular))) | |
252b5132 | 1867 | { |
e03a8ed8 L |
1868 | struct elf_dyn_relocs *p; |
1869 | struct elf_dyn_relocs **head; | |
ec338859 | 1870 | |
12d0ee4a AM |
1871 | /* We must copy these reloc types into the output file. |
1872 | Create a reloc section in dynobj and make room for | |
1873 | this reloc. */ | |
252b5132 RH |
1874 | if (sreloc == NULL) |
1875 | { | |
83bac4b0 NC |
1876 | sreloc = _bfd_elf_make_dynamic_reloc_section |
1877 | (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ FALSE); | |
1878 | ||
252b5132 | 1879 | if (sreloc == NULL) |
c337a162 | 1880 | goto error_return; |
252b5132 RH |
1881 | } |
1882 | ||
0c715baa AM |
1883 | /* If this is a global symbol, we count the number of |
1884 | relocations we need for this symbol. */ | |
1885 | if (h != NULL) | |
252b5132 | 1886 | { |
d5597ebc | 1887 | head = &eh->dyn_relocs; |
0c715baa AM |
1888 | } |
1889 | else | |
1890 | { | |
ec338859 AM |
1891 | /* Track dynamic relocs needed for local syms too. |
1892 | We really need local syms available to do this | |
1893 | easily. Oh well. */ | |
87d72d41 | 1894 | void **vpp; |
ec338859 | 1895 | asection *s; |
87d72d41 AM |
1896 | |
1897 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, | |
1898 | abfd, r_symndx); | |
1899 | if (isym == NULL) | |
c337a162 | 1900 | goto error_return; |
87d72d41 AM |
1901 | |
1902 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
ec338859 | 1903 | if (s == NULL) |
87d72d41 | 1904 | s = sec; |
ec338859 | 1905 | |
e81d3500 | 1906 | vpp = &elf_section_data (s)->local_dynrel; |
e03a8ed8 | 1907 | head = (struct elf_dyn_relocs **)vpp; |
ec338859 AM |
1908 | } |
1909 | ||
1910 | p = *head; | |
1911 | if (p == NULL || p->sec != sec) | |
1912 | { | |
1913 | bfd_size_type amt = sizeof *p; | |
a50b1753 NC |
1914 | p = (struct elf_dyn_relocs *) bfd_alloc (htab->elf.dynobj, |
1915 | amt); | |
ec338859 | 1916 | if (p == NULL) |
c337a162 | 1917 | goto error_return; |
ec338859 AM |
1918 | p->next = *head; |
1919 | *head = p; | |
1920 | p->sec = sec; | |
1921 | p->count = 0; | |
1922 | p->pc_count = 0; | |
252b5132 | 1923 | } |
ec338859 AM |
1924 | |
1925 | p->count += 1; | |
06a6a421 L |
1926 | /* Count size relocation as PC-relative relocation. */ |
1927 | if (r_type == R_386_PC32 || size_reloc) | |
ec338859 | 1928 | p->pc_count += 1; |
252b5132 | 1929 | } |
252b5132 RH |
1930 | break; |
1931 | ||
1932 | /* This relocation describes the C++ object vtable hierarchy. | |
1933 | Reconstruct it for later use during GC. */ | |
1934 | case R_386_GNU_VTINHERIT: | |
d17e0c6e | 1935 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
c337a162 | 1936 | goto error_return; |
252b5132 RH |
1937 | break; |
1938 | ||
1939 | /* This relocation describes which C++ vtable entries are actually | |
1940 | used. Record for later use during GC. */ | |
1941 | case R_386_GNU_VTENTRY: | |
c6aa130f MS |
1942 | BFD_ASSERT (h != NULL); |
1943 | if (h != NULL | |
1944 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) | |
c337a162 | 1945 | goto error_return; |
252b5132 RH |
1946 | break; |
1947 | ||
1948 | default: | |
1949 | break; | |
1950 | } | |
dd7e64d4 | 1951 | |
52bf37dd | 1952 | if (r_type == R_386_GOT32X |
c1d11331 | 1953 | && (h == NULL || h->type != STT_GNU_IFUNC)) |
02a86693 | 1954 | sec->need_convert_load = 1; |
252b5132 RH |
1955 | } |
1956 | ||
bedfd056 L |
1957 | if (elf_section_data (sec)->this_hdr.contents != contents) |
1958 | { | |
1959 | if (!info->keep_memory) | |
1960 | free (contents); | |
1961 | else | |
1962 | { | |
1963 | /* Cache the section contents for elf_link_input_bfd. */ | |
1964 | elf_section_data (sec)->this_hdr.contents = contents; | |
1965 | } | |
1966 | } | |
1967 | ||
b34976b6 | 1968 | return TRUE; |
c337a162 L |
1969 | |
1970 | error_return: | |
bedfd056 L |
1971 | if (elf_section_data (sec)->this_hdr.contents != contents) |
1972 | free (contents); | |
c337a162 L |
1973 | sec->check_relocs_failed = 1; |
1974 | return FALSE; | |
252b5132 RH |
1975 | } |
1976 | ||
1977 | /* Return the section that should be marked against GC for a given | |
1978 | relocation. */ | |
1979 | ||
1980 | static asection * | |
55fd94b0 | 1981 | elf_i386_gc_mark_hook (asection *sec, |
07adf181 | 1982 | struct bfd_link_info *info, |
55fd94b0 AM |
1983 | Elf_Internal_Rela *rel, |
1984 | struct elf_link_hash_entry *h, | |
1985 | Elf_Internal_Sym *sym) | |
252b5132 RH |
1986 | { |
1987 | if (h != NULL) | |
07adf181 AM |
1988 | switch (ELF32_R_TYPE (rel->r_info)) |
1989 | { | |
1990 | case R_386_GNU_VTINHERIT: | |
1991 | case R_386_GNU_VTENTRY: | |
1992 | return NULL; | |
1993 | } | |
1994 | ||
1995 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
252b5132 RH |
1996 | } |
1997 | ||
252b5132 RH |
1998 | /* Adjust a symbol defined by a dynamic object and referenced by a |
1999 | regular object. The current definition is in some section of the | |
2000 | dynamic object, but we're not including those sections. We have to | |
2001 | change the definition to something the rest of the link can | |
2002 | understand. */ | |
2003 | ||
b34976b6 | 2004 | static bfd_boolean |
55fd94b0 AM |
2005 | elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info, |
2006 | struct elf_link_hash_entry *h) | |
252b5132 | 2007 | { |
0afcef53 | 2008 | struct elf_x86_link_hash_table *htab; |
5474d94f | 2009 | asection *s, *srel; |
0afcef53 | 2010 | struct elf_x86_link_hash_entry *eh; |
5ca5bb35 | 2011 | struct elf_dyn_relocs *p; |
252b5132 | 2012 | |
cbe950e9 L |
2013 | /* STT_GNU_IFUNC symbol must go through PLT. */ |
2014 | if (h->type == STT_GNU_IFUNC) | |
2015 | { | |
73bcf233 L |
2016 | /* All local STT_GNU_IFUNC references must be treate as local |
2017 | calls via local PLT. */ | |
5ca5bb35 L |
2018 | if (h->ref_regular |
2019 | && SYMBOL_CALLS_LOCAL (info, h)) | |
2020 | { | |
73bcf233 | 2021 | bfd_size_type pc_count = 0, count = 0; |
5ca5bb35 L |
2022 | struct elf_dyn_relocs **pp; |
2023 | ||
0afcef53 | 2024 | eh = (struct elf_x86_link_hash_entry *) h; |
5ca5bb35 L |
2025 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) |
2026 | { | |
2027 | pc_count += p->pc_count; | |
2028 | p->count -= p->pc_count; | |
2029 | p->pc_count = 0; | |
73bcf233 | 2030 | count += p->count; |
5ca5bb35 L |
2031 | if (p->count == 0) |
2032 | *pp = p->next; | |
2033 | else | |
2034 | pp = &p->next; | |
2035 | } | |
2036 | ||
73bcf233 | 2037 | if (pc_count || count) |
5ca5bb35 | 2038 | { |
5ca5bb35 | 2039 | h->non_got_ref = 1; |
233cc9c1 L |
2040 | if (pc_count) |
2041 | { | |
2042 | /* Increment PLT reference count only for PC-relative | |
2043 | references. */ | |
2044 | h->needs_plt = 1; | |
2045 | if (h->plt.refcount <= 0) | |
2046 | h->plt.refcount = 1; | |
2047 | else | |
2048 | h->plt.refcount += 1; | |
2049 | } | |
5ca5bb35 L |
2050 | } |
2051 | } | |
2052 | ||
cbe950e9 L |
2053 | if (h->plt.refcount <= 0) |
2054 | { | |
2055 | h->plt.offset = (bfd_vma) -1; | |
2056 | h->needs_plt = 0; | |
2057 | } | |
2058 | return TRUE; | |
2059 | } | |
2060 | ||
252b5132 RH |
2061 | /* If this is a function, put it in the procedure linkage table. We |
2062 | will fill in the contents of the procedure linkage table later, | |
2063 | when we know the address of the .got section. */ | |
2064 | if (h->type == STT_FUNC | |
f5385ebf | 2065 | || h->needs_plt) |
252b5132 | 2066 | { |
6725bdbf | 2067 | if (h->plt.refcount <= 0 |
9c7a29a3 AM |
2068 | || SYMBOL_CALLS_LOCAL (info, h) |
2069 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
2070 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
2071 | { |
2072 | /* This case can occur if we saw a PLT32 reloc in an input | |
dd5724d5 AM |
2073 | file, but the symbol was never referred to by a dynamic |
2074 | object, or if all references were garbage collected. In | |
2075 | such a case, we don't actually need to build a procedure | |
2076 | linkage table, and we can just do a PC32 reloc instead. */ | |
bbd7ec4a | 2077 | h->plt.offset = (bfd_vma) -1; |
f5385ebf | 2078 | h->needs_plt = 0; |
252b5132 RH |
2079 | } |
2080 | ||
b34976b6 | 2081 | return TRUE; |
252b5132 | 2082 | } |
6725bdbf AM |
2083 | else |
2084 | /* It's possible that we incorrectly decided a .plt reloc was | |
2085 | needed for an R_386_PC32 reloc to a non-function sym in | |
2086 | check_relocs. We can't decide accurately between function and | |
2087 | non-function syms in check-relocs; Objects loaded later in | |
2088 | the link may change h->type. So fix it now. */ | |
bbd7ec4a | 2089 | h->plt.offset = (bfd_vma) -1; |
252b5132 | 2090 | |
0afcef53 | 2091 | eh = (struct elf_x86_link_hash_entry *) h; |
a5b4ee94 | 2092 | |
252b5132 RH |
2093 | /* If this is a weak symbol, and there is a real definition, the |
2094 | processor independent code will have arranged for us to see the | |
2095 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 2096 | if (h->u.weakdef != NULL) |
252b5132 | 2097 | { |
f6e332e6 AM |
2098 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
2099 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
2100 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
2101 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
a5b4ee94 L |
2102 | if (ELIMINATE_COPY_RELOCS |
2103 | || info->nocopyreloc | |
2104 | || SYMBOL_NO_COPYRELOC (info, eh)) | |
f6e332e6 | 2105 | h->non_got_ref = h->u.weakdef->non_got_ref; |
b34976b6 | 2106 | return TRUE; |
252b5132 RH |
2107 | } |
2108 | ||
2109 | /* This is a reference to a symbol defined by a dynamic object which | |
2110 | is not a function. */ | |
2111 | ||
2112 | /* If we are creating a shared library, we must presume that the | |
2113 | only references to the symbol are via the global offset table. | |
2114 | For such cases we need not do anything here; the relocations will | |
2115 | be handled correctly by relocate_section. */ | |
0e1862bb | 2116 | if (!bfd_link_executable (info)) |
b34976b6 | 2117 | return TRUE; |
252b5132 | 2118 | |
7843f00e | 2119 | /* If there are no references to this symbol that do not use the |
d5597ebc L |
2120 | GOT nor R_386_GOTOFF relocation, we don't need to generate a copy |
2121 | reloc. */ | |
d5597ebc | 2122 | if (!h->non_got_ref && !eh->gotoff_ref) |
b34976b6 | 2123 | return TRUE; |
7843f00e | 2124 | |
8bd621d8 | 2125 | /* If -z nocopyreloc was given, we won't generate them either. */ |
a5b4ee94 | 2126 | if (info->nocopyreloc || SYMBOL_NO_COPYRELOC (info, eh)) |
8bd621d8 | 2127 | { |
f5385ebf | 2128 | h->non_got_ref = 0; |
b34976b6 | 2129 | return TRUE; |
8bd621d8 AM |
2130 | } |
2131 | ||
0afcef53 | 2132 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 NC |
2133 | if (htab == NULL) |
2134 | return FALSE; | |
643796e3 | 2135 | |
d5597ebc L |
2136 | /* If there aren't any dynamic relocs in read-only sections nor |
2137 | R_386_GOTOFF relocation, then we can keep the dynamic relocs and | |
2138 | avoid the copy reloc. This doesn't work on VxWorks, where we can | |
2139 | not have dynamic relocations (other than copy and jump slot | |
2140 | relocations) in an executable. */ | |
23209a78 | 2141 | if (ELIMINATE_COPY_RELOCS |
d5597ebc | 2142 | && !eh->gotoff_ref |
f604c2a2 | 2143 | && get_elf_i386_backend_data (info->output_bfd)->os != is_vxworks) |
ebe50bae | 2144 | { |
a23b6845 AM |
2145 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
2146 | { | |
2147 | s = p->sec->output_section; | |
2148 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
2149 | break; | |
2150 | } | |
2151 | ||
a23b6845 AM |
2152 | if (p == NULL) |
2153 | { | |
f5385ebf | 2154 | h->non_got_ref = 0; |
a23b6845 AM |
2155 | return TRUE; |
2156 | } | |
ebe50bae AM |
2157 | } |
2158 | ||
252b5132 RH |
2159 | /* We must allocate the symbol in our .dynbss section, which will |
2160 | become part of the .bss section of the executable. There will be | |
2161 | an entry for this symbol in the .dynsym section. The dynamic | |
2162 | object will contain position independent code, so all references | |
2163 | from the dynamic object to this symbol will go through the global | |
2164 | offset table. The dynamic linker will use the .dynsym entry to | |
2165 | determine the address it must put in the global offset table, so | |
2166 | both the dynamic object and the regular object will refer to the | |
2167 | same memory location for the variable. */ | |
2168 | ||
252b5132 RH |
2169 | /* We must generate a R_386_COPY reloc to tell the dynamic linker to |
2170 | copy the initial value out of the dynamic object and into the | |
0ac8d2ca | 2171 | runtime process image. */ |
5474d94f AM |
2172 | if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
2173 | { | |
2174 | s = htab->elf.sdynrelro; | |
2175 | srel = htab->elf.sreldynrelro; | |
2176 | } | |
2177 | else | |
2178 | { | |
2179 | s = htab->elf.sdynbss; | |
2180 | srel = htab->elf.srelbss; | |
2181 | } | |
1d7e9d18 | 2182 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
252b5132 | 2183 | { |
5474d94f | 2184 | srel->size += sizeof (Elf32_External_Rel); |
f5385ebf | 2185 | h->needs_copy = 1; |
252b5132 RH |
2186 | } |
2187 | ||
6cabe1ea | 2188 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
252b5132 RH |
2189 | } |
2190 | ||
6725bdbf | 2191 | /* Allocate space in .plt, .got and associated reloc sections for |
0c715baa | 2192 | dynamic relocs. */ |
6725bdbf | 2193 | |
b34976b6 | 2194 | static bfd_boolean |
eb4ff4d6 | 2195 | elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
6725bdbf AM |
2196 | { |
2197 | struct bfd_link_info *info; | |
0afcef53 L |
2198 | struct elf_x86_link_hash_table *htab; |
2199 | struct elf_x86_link_hash_entry *eh; | |
e03a8ed8 | 2200 | struct elf_dyn_relocs *p; |
25e762b9 | 2201 | unsigned plt_entry_size; |
aec6b87e | 2202 | bfd_boolean resolved_to_zero; |
f604c2a2 | 2203 | const struct elf_i386_backend_data *bed; |
6725bdbf | 2204 | |
e92d460e | 2205 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 2206 | return TRUE; |
6725bdbf | 2207 | |
0afcef53 | 2208 | eh = (struct elf_x86_link_hash_entry *) h; |
e92d460e | 2209 | |
6725bdbf | 2210 | info = (struct bfd_link_info *) inf; |
0afcef53 | 2211 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 NC |
2212 | if (htab == NULL) |
2213 | return FALSE; | |
6725bdbf | 2214 | |
f604c2a2 L |
2215 | bed = get_elf_i386_backend_data (info->output_bfd); |
2216 | ||
765e526c | 2217 | plt_entry_size = htab->plt.plt_entry_size; |
25e762b9 | 2218 | |
e62b9723 | 2219 | resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, |
0afcef53 | 2220 | I386_ELF_DATA, |
e62b9723 L |
2221 | eh->has_got_reloc, |
2222 | eh); | |
aec6b87e | 2223 | |
04ebc307 L |
2224 | /* Clear the reference count of function pointer relocations if |
2225 | symbol isn't a normal function. */ | |
2226 | if (h->type != STT_FUNC) | |
2227 | eh->func_pointer_refcount = 0; | |
2228 | ||
dd7e64d4 L |
2229 | /* We can't use the GOT PLT if pointer equality is needed since |
2230 | finish_dynamic_symbol won't clear symbol value and the dynamic | |
2231 | linker won't update the GOT slot. We will get into an infinite | |
2232 | loop at run-time. */ | |
2233 | if (htab->plt_got != NULL | |
2234 | && h->type != STT_GNU_IFUNC | |
2235 | && !h->pointer_equality_needed | |
2236 | && h->plt.refcount > 0 | |
2237 | && h->got.refcount > 0) | |
2238 | { | |
2239 | /* Don't use the regular PLT if there are both GOT and GOTPLT | |
2240 | reloctions. */ | |
2241 | h->plt.offset = (bfd_vma) -1; | |
2242 | ||
2243 | /* Use the GOT PLT. */ | |
2244 | eh->plt_got.refcount = 1; | |
2245 | } | |
2246 | ||
cbe950e9 L |
2247 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
2248 | here if it is defined and referenced in a non-shared object. */ | |
2249 | if (h->type == STT_GNU_IFUNC | |
2250 | && h->def_regular) | |
ee2fdd6f L |
2251 | { |
2252 | if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h, &eh->dyn_relocs, | |
2253 | &htab->readonly_dynrelocs_against_ifunc, | |
2254 | plt_entry_size, | |
765e526c | 2255 | (htab->plt.has_plt0 |
0afcef53 | 2256 | * plt_entry_size), |
ee2fdd6f L |
2257 | 4, TRUE)) |
2258 | { | |
2259 | asection *s = htab->plt_second; | |
2260 | if (h->plt.offset != (bfd_vma) -1 && s != NULL) | |
2261 | { | |
2262 | /* Use the second PLT section if it is created. */ | |
2263 | eh->plt_second.offset = s->size; | |
2264 | ||
2265 | /* Make room for this entry in the second PLT section. */ | |
765e526c | 2266 | s->size += htab->non_lazy_plt->plt_entry_size; |
ee2fdd6f L |
2267 | } |
2268 | ||
2269 | return TRUE; | |
2270 | } | |
2271 | else | |
2272 | return FALSE; | |
2273 | } | |
04ebc307 L |
2274 | /* Don't create the PLT entry if there are only function pointer |
2275 | relocations which can be resolved at run-time. */ | |
cbe950e9 | 2276 | else if (htab->elf.dynamic_sections_created |
04ebc307 L |
2277 | && (h->plt.refcount > eh->func_pointer_refcount |
2278 | || eh->plt_got.refcount > 0)) | |
6725bdbf | 2279 | { |
dc2be3d2 | 2280 | bfd_boolean use_plt_got = eh->plt_got.refcount > 0; |
25070364 | 2281 | |
04ebc307 L |
2282 | /* Clear the reference count of function pointer relocations |
2283 | if PLT is used. */ | |
2284 | eh->func_pointer_refcount = 0; | |
2285 | ||
5a15f56f AM |
2286 | /* Make sure this symbol is output as a dynamic symbol. |
2287 | Undefined weak syms won't yet be marked as dynamic. */ | |
2288 | if (h->dynindx == -1 | |
aec6b87e | 2289 | && !h->forced_local |
0dc9a308 L |
2290 | && !resolved_to_zero |
2291 | && h->root.type == bfd_link_hash_undefweak) | |
5a15f56f | 2292 | { |
c152c796 | 2293 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 2294 | return FALSE; |
5a15f56f AM |
2295 | } |
2296 | ||
0e1862bb | 2297 | if (bfd_link_pic (info) |
4e795f50 | 2298 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
ced53ee5 | 2299 | { |
6de2ae4a | 2300 | asection *s = htab->elf.splt; |
ee2fdd6f | 2301 | asection *second_s = htab->plt_second; |
dd7e64d4 | 2302 | asection *got_s = htab->plt_got; |
6725bdbf | 2303 | |
7c1e8d3e L |
2304 | /* If this is the first .plt entry, make room for the special |
2305 | first entry. The .plt section is used by prelink to undo | |
2306 | prelinking for dynamic relocations. */ | |
2307 | if (s->size == 0) | |
765e526c | 2308 | s->size = htab->plt.has_plt0 * plt_entry_size; |
7c1e8d3e | 2309 | |
dd7e64d4 L |
2310 | if (use_plt_got) |
2311 | eh->plt_got.offset = got_s->size; | |
2312 | else | |
ee2fdd6f L |
2313 | { |
2314 | h->plt.offset = s->size; | |
2315 | if (second_s) | |
2316 | eh->plt_second.offset = second_s->size; | |
2317 | } | |
6725bdbf | 2318 | |
ced53ee5 AM |
2319 | /* If this symbol is not defined in a regular file, and we are |
2320 | not generating a shared library, then set the symbol to this | |
2321 | location in the .plt. This is required to make function | |
2322 | pointers compare as equal between the normal executable and | |
2323 | the shared library. */ | |
0e1862bb | 2324 | if (! bfd_link_pic (info) |
f5385ebf | 2325 | && !h->def_regular) |
ced53ee5 | 2326 | { |
dd7e64d4 L |
2327 | if (use_plt_got) |
2328 | { | |
2329 | /* We need to make a call to the entry of the GOT PLT | |
2330 | instead of regular PLT entry. */ | |
2331 | h->root.u.def.section = got_s; | |
2332 | h->root.u.def.value = eh->plt_got.offset; | |
2333 | } | |
2334 | else | |
2335 | { | |
ee2fdd6f L |
2336 | if (second_s) |
2337 | { | |
2338 | /* We need to make a call to the entry of the | |
2339 | second PLT instead of regular PLT entry. */ | |
2340 | h->root.u.def.section = second_s; | |
2341 | h->root.u.def.value = eh->plt_second.offset; | |
2342 | } | |
2343 | else | |
2344 | { | |
2345 | h->root.u.def.section = s; | |
2346 | h->root.u.def.value = h->plt.offset; | |
2347 | } | |
dd7e64d4 | 2348 | } |
ced53ee5 | 2349 | } |
6725bdbf | 2350 | |
ced53ee5 | 2351 | /* Make room for this entry. */ |
dd7e64d4 | 2352 | if (use_plt_got) |
765e526c | 2353 | got_s->size += htab->non_lazy_plt->plt_entry_size; |
dd7e64d4 L |
2354 | else |
2355 | { | |
2356 | s->size += plt_entry_size; | |
ee2fdd6f | 2357 | if (second_s) |
765e526c | 2358 | second_s->size += htab->non_lazy_plt->plt_entry_size; |
6725bdbf | 2359 | |
dd7e64d4 L |
2360 | /* We also need to make an entry in the .got.plt section, |
2361 | which will be placed in the .got section by the linker | |
2362 | script. */ | |
2363 | htab->elf.sgotplt->size += 4; | |
6725bdbf | 2364 | |
aec6b87e L |
2365 | /* There should be no PLT relocation against resolved |
2366 | undefined weak symbol in executable. */ | |
2367 | if (!resolved_to_zero) | |
2368 | { | |
2369 | /* We also need to make an entry in the .rel.plt | |
2370 | section. */ | |
2371 | htab->elf.srelplt->size += sizeof (Elf32_External_Rel); | |
2372 | htab->elf.srelplt->reloc_count++; | |
2373 | } | |
dd7e64d4 | 2374 | } |
eac338cf | 2375 | |
f604c2a2 | 2376 | if (bed->os == is_vxworks && !bfd_link_pic (info)) |
eac338cf PB |
2377 | { |
2378 | /* VxWorks has a second set of relocations for each PLT entry | |
2379 | in executables. They go in a separate relocation section, | |
2380 | which is processed by the kernel loader. */ | |
2381 | ||
2382 | /* There are two relocations for the initial PLT entry: an | |
2383 | R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an | |
2384 | R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */ | |
2385 | ||
765e526c | 2386 | asection *srelplt2 = htab->srelplt2; |
25e762b9 | 2387 | if (h->plt.offset == plt_entry_size) |
0afcef53 | 2388 | srelplt2->size += (sizeof (Elf32_External_Rel) * 2); |
eac338cf PB |
2389 | |
2390 | /* There are two extra relocations for each subsequent PLT entry: | |
2391 | an R_386_32 relocation for the GOT entry, and an R_386_32 | |
2392 | relocation for the PLT entry. */ | |
2393 | ||
0afcef53 | 2394 | srelplt2->size += (sizeof (Elf32_External_Rel) * 2); |
eac338cf | 2395 | } |
6725bdbf | 2396 | } |
ced53ee5 AM |
2397 | else |
2398 | { | |
13f42277 | 2399 | eh->plt_got.offset = (bfd_vma) -1; |
51b64d56 | 2400 | h->plt.offset = (bfd_vma) -1; |
f5385ebf | 2401 | h->needs_plt = 0; |
ced53ee5 | 2402 | } |
6725bdbf AM |
2403 | } |
2404 | else | |
2405 | { | |
13f42277 | 2406 | eh->plt_got.offset = (bfd_vma) -1; |
51b64d56 | 2407 | h->plt.offset = (bfd_vma) -1; |
f5385ebf | 2408 | h->needs_plt = 0; |
6725bdbf AM |
2409 | } |
2410 | ||
67a4f2b7 AO |
2411 | eh->tlsdesc_got = (bfd_vma) -1; |
2412 | ||
37e55690 | 2413 | /* If R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the binary, |
13ae64f3 JJ |
2414 | make it a R_386_TLS_LE_32 requiring no TLS entry. */ |
2415 | if (h->got.refcount > 0 | |
0e1862bb | 2416 | && bfd_link_executable (info) |
13ae64f3 | 2417 | && h->dynindx == -1 |
0afcef53 | 2418 | && (elf_x86_hash_entry (h)->tls_type & GOT_TLS_IE)) |
cedb70c5 | 2419 | h->got.offset = (bfd_vma) -1; |
13ae64f3 | 2420 | else if (h->got.refcount > 0) |
6725bdbf | 2421 | { |
0ac8d2ca | 2422 | asection *s; |
b34976b6 | 2423 | bfd_boolean dyn; |
0afcef53 | 2424 | int tls_type = elf_x86_hash_entry (h)->tls_type; |
6725bdbf | 2425 | |
5a15f56f | 2426 | /* Make sure this symbol is output as a dynamic symbol. |
0dc9a308 | 2427 | Undefined weak syms won't yet be marked as dynamic. */ |
5a15f56f | 2428 | if (h->dynindx == -1 |
aec6b87e | 2429 | && !h->forced_local |
e133d005 | 2430 | && !resolved_to_zero |
0dc9a308 | 2431 | && h->root.type == bfd_link_hash_undefweak) |
5a15f56f | 2432 | { |
c152c796 | 2433 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 2434 | return FALSE; |
5a15f56f AM |
2435 | } |
2436 | ||
6de2ae4a | 2437 | s = htab->elf.sgot; |
67a4f2b7 AO |
2438 | if (GOT_TLS_GDESC_P (tls_type)) |
2439 | { | |
6de2ae4a | 2440 | eh->tlsdesc_got = htab->elf.sgotplt->size |
67a4f2b7 | 2441 | - elf_i386_compute_jump_table_size (htab); |
6de2ae4a | 2442 | htab->elf.sgotplt->size += 8; |
67a4f2b7 AO |
2443 | h->got.offset = (bfd_vma) -2; |
2444 | } | |
2445 | if (! GOT_TLS_GDESC_P (tls_type) | |
2446 | || GOT_TLS_GD_P (tls_type)) | |
2447 | { | |
2448 | h->got.offset = s->size; | |
2449 | s->size += 4; | |
2450 | /* R_386_TLS_GD needs 2 consecutive GOT slots. */ | |
2451 | if (GOT_TLS_GD_P (tls_type) || tls_type == GOT_TLS_IE_BOTH) | |
2452 | s->size += 4; | |
2453 | } | |
ebe50bae | 2454 | dyn = htab->elf.dynamic_sections_created; |
13ae64f3 | 2455 | /* R_386_TLS_IE_32 needs one dynamic relocation, |
37e55690 JJ |
2456 | R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation, |
2457 | (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we | |
2458 | need two), R_386_TLS_GD needs one if local symbol and two if | |
aec6b87e L |
2459 | global. No dynamic relocation against resolved undefined weak |
2460 | symbol in executable. */ | |
37e55690 | 2461 | if (tls_type == GOT_TLS_IE_BOTH) |
6de2ae4a | 2462 | htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel); |
67a4f2b7 | 2463 | else if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1) |
37e55690 | 2464 | || (tls_type & GOT_TLS_IE)) |
6de2ae4a | 2465 | htab->elf.srelgot->size += sizeof (Elf32_External_Rel); |
67a4f2b7 | 2466 | else if (GOT_TLS_GD_P (tls_type)) |
6de2ae4a | 2467 | htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rel); |
67a4f2b7 | 2468 | else if (! GOT_TLS_GDESC_P (tls_type) |
aec6b87e L |
2469 | && ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
2470 | && !resolved_to_zero) | |
67a4f2b7 | 2471 | || h->root.type != bfd_link_hash_undefweak) |
0e1862bb | 2472 | && (bfd_link_pic (info) |
ef5aade5 | 2473 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
6de2ae4a | 2474 | htab->elf.srelgot->size += sizeof (Elf32_External_Rel); |
67a4f2b7 | 2475 | if (GOT_TLS_GDESC_P (tls_type)) |
6de2ae4a | 2476 | htab->elf.srelplt->size += sizeof (Elf32_External_Rel); |
6725bdbf AM |
2477 | } |
2478 | else | |
51b64d56 | 2479 | h->got.offset = (bfd_vma) -1; |
6725bdbf | 2480 | |
5a15f56f | 2481 | if (eh->dyn_relocs == NULL) |
b34976b6 | 2482 | return TRUE; |
5a15f56f | 2483 | |
0c715baa AM |
2484 | /* In the shared -Bsymbolic case, discard space allocated for |
2485 | dynamic pc-relative relocs against symbols which turn out to be | |
2486 | defined in regular objects. For the normal shared case, discard | |
0ac8d2ca AM |
2487 | space for pc-relative relocs that have become local due to symbol |
2488 | visibility changes. */ | |
0c715baa | 2489 | |
0e1862bb | 2490 | if (bfd_link_pic (info)) |
5a15f56f | 2491 | { |
09695f56 AM |
2492 | /* The only reloc that uses pc_count is R_386_PC32, which will |
2493 | appear on a call or on something like ".long foo - .". We | |
2494 | want calls to protected symbols to resolve directly to the | |
2495 | function rather than going via the plt. If people want | |
2496 | function pointer comparisons to work as expected then they | |
2497 | should avoid writing assembly like ".long foo - .". */ | |
2498 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
5a15f56f | 2499 | { |
e03a8ed8 | 2500 | struct elf_dyn_relocs **pp; |
0c715baa AM |
2501 | |
2502 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
2503 | { | |
c3ce498c L |
2504 | p->count -= p->pc_count; |
2505 | p->pc_count = 0; | |
0c715baa AM |
2506 | if (p->count == 0) |
2507 | *pp = p->next; | |
2508 | else | |
2509 | pp = &p->next; | |
2510 | } | |
5a15f56f | 2511 | } |
4e795f50 | 2512 | |
f604c2a2 | 2513 | if (bed->os == is_vxworks) |
3348747a | 2514 | { |
e03a8ed8 | 2515 | struct elf_dyn_relocs **pp; |
3348747a NS |
2516 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) |
2517 | { | |
2518 | if (strcmp (p->sec->output_section->name, ".tls_vars") == 0) | |
2519 | *pp = p->next; | |
2520 | else | |
2521 | pp = &p->next; | |
2522 | } | |
2523 | } | |
2524 | ||
4e795f50 | 2525 | /* Also discard relocs on undefined weak syms with non-default |
aec6b87e | 2526 | visibility or in PIE. */ |
22d606e9 | 2527 | if (eh->dyn_relocs != NULL |
c353e543 | 2528 | && h->root.type == bfd_link_hash_undefweak) |
22d606e9 | 2529 | { |
aec6b87e L |
2530 | /* Undefined weak symbol is never bound locally in shared |
2531 | library. */ | |
2532 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
2533 | || resolved_to_zero) | |
2534 | { | |
2535 | if (h->non_got_ref) | |
2536 | { | |
2537 | /* Keep dynamic non-GOT/non-PLT relocation so that we | |
2538 | can branch to 0 without PLT. */ | |
2539 | struct elf_dyn_relocs **pp; | |
2540 | ||
2541 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
2542 | if (p->pc_count == 0) | |
2543 | *pp = p->next; | |
2544 | else | |
2545 | { | |
2546 | /* Remove non-R_386_PC32 relocation. */ | |
2547 | p->count = p->pc_count; | |
2548 | pp = &p->next; | |
2549 | } | |
22d606e9 | 2550 | |
aec6b87e L |
2551 | if (eh->dyn_relocs != NULL) |
2552 | { | |
2553 | /* Make sure undefined weak symbols are output | |
2554 | as dynamic symbols in PIEs for dynamic non-GOT | |
2555 | non-PLT reloations. */ | |
2556 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
2557 | return FALSE; | |
2558 | } | |
2559 | } | |
2560 | else | |
2561 | eh->dyn_relocs = NULL; | |
2562 | } | |
22d606e9 AM |
2563 | else if (h->dynindx == -1 |
2564 | && !h->forced_local) | |
2565 | { | |
2566 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
2567 | return FALSE; | |
2568 | } | |
2569 | } | |
0c715baa | 2570 | } |
a23b6845 | 2571 | else if (ELIMINATE_COPY_RELOCS) |
0c715baa AM |
2572 | { |
2573 | /* For the non-shared case, discard space for relocs against | |
2574 | symbols which turn out to need copy relocs or are not | |
04ebc307 L |
2575 | dynamic. Keep dynamic relocations for run-time function |
2576 | pointer initialization. */ | |
0c715baa | 2577 | |
aec6b87e L |
2578 | if ((!h->non_got_ref |
2579 | || eh->func_pointer_refcount > 0 | |
2580 | || (h->root.type == bfd_link_hash_undefweak | |
2581 | && !resolved_to_zero)) | |
f5385ebf AM |
2582 | && ((h->def_dynamic |
2583 | && !h->def_regular) | |
ebe50bae | 2584 | || (htab->elf.dynamic_sections_created |
0c715baa AM |
2585 | && (h->root.type == bfd_link_hash_undefweak |
2586 | || h->root.type == bfd_link_hash_undefined)))) | |
2587 | { | |
2588 | /* Make sure this symbol is output as a dynamic symbol. | |
2589 | Undefined weak syms won't yet be marked as dynamic. */ | |
2590 | if (h->dynindx == -1 | |
aec6b87e | 2591 | && !h->forced_local |
0dc9a308 L |
2592 | && !resolved_to_zero |
2593 | && h->root.type == bfd_link_hash_undefweak) | |
0c715baa | 2594 | { |
c152c796 | 2595 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 2596 | return FALSE; |
0c715baa | 2597 | } |
5a15f56f | 2598 | |
0c715baa AM |
2599 | /* If that succeeded, we know we'll be keeping all the |
2600 | relocs. */ | |
2601 | if (h->dynindx != -1) | |
2602 | goto keep; | |
2603 | } | |
2604 | ||
2605 | eh->dyn_relocs = NULL; | |
04ebc307 | 2606 | eh->func_pointer_refcount = 0; |
0c715baa | 2607 | |
ec338859 | 2608 | keep: ; |
5a15f56f AM |
2609 | } |
2610 | ||
0c715baa AM |
2611 | /* Finally, allocate space. */ |
2612 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
12d0ee4a | 2613 | { |
e7c33416 NC |
2614 | asection *sreloc; |
2615 | ||
cbe950e9 | 2616 | sreloc = elf_section_data (p->sec)->sreloc; |
e7c33416 NC |
2617 | |
2618 | BFD_ASSERT (sreloc != NULL); | |
eea6121a | 2619 | sreloc->size += p->count * sizeof (Elf32_External_Rel); |
12d0ee4a AM |
2620 | } |
2621 | ||
b34976b6 | 2622 | return TRUE; |
6725bdbf AM |
2623 | } |
2624 | ||
c25bc9fc L |
2625 | /* Allocate space in .plt, .got and associated reloc sections for |
2626 | local dynamic relocs. */ | |
2627 | ||
2628 | static bfd_boolean | |
2629 | elf_i386_allocate_local_dynrelocs (void **slot, void *inf) | |
2630 | { | |
2631 | struct elf_link_hash_entry *h | |
2632 | = (struct elf_link_hash_entry *) *slot; | |
2633 | ||
2634 | if (h->type != STT_GNU_IFUNC | |
2635 | || !h->def_regular | |
2636 | || !h->ref_regular | |
2637 | || !h->forced_local | |
2638 | || h->root.type != bfd_link_hash_defined) | |
2639 | abort (); | |
2640 | ||
2641 | return elf_i386_allocate_dynrelocs (h, inf); | |
2642 | } | |
2643 | ||
c175a657 | 2644 | /* Convert load via the GOT slot to load immediate. */ |
daa67607 L |
2645 | |
2646 | static bfd_boolean | |
02a86693 | 2647 | elf_i386_convert_load (bfd *abfd, asection *sec, |
a6af384b | 2648 | struct bfd_link_info *link_info) |
daa67607 | 2649 | { |
0afcef53 | 2650 | struct elf_x86_link_hash_table *htab; |
daa67607 L |
2651 | Elf_Internal_Shdr *symtab_hdr; |
2652 | Elf_Internal_Rela *internal_relocs; | |
2653 | Elf_Internal_Rela *irel, *irelend; | |
2654 | bfd_byte *contents; | |
c175a657 | 2655 | bfd_boolean changed; |
daa67607 L |
2656 | bfd_signed_vma *local_got_refcounts; |
2657 | ||
2658 | /* Don't even try to convert non-ELF outputs. */ | |
2659 | if (!is_elf_hash_table (link_info->hash)) | |
2660 | return FALSE; | |
2661 | ||
c1d11331 | 2662 | /* Nothing to do if there is no need or no output. */ |
daa67607 | 2663 | if ((sec->flags & (SEC_CODE | SEC_RELOC)) != (SEC_CODE | SEC_RELOC) |
02a86693 | 2664 | || sec->need_convert_load == 0 |
c8831961 | 2665 | || bfd_is_abs_section (sec->output_section)) |
daa67607 L |
2666 | return TRUE; |
2667 | ||
2668 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2669 | ||
2670 | /* Load the relocations for this section. */ | |
2671 | internal_relocs = (_bfd_elf_link_read_relocs | |
2672 | (abfd, sec, NULL, (Elf_Internal_Rela *) NULL, | |
2673 | link_info->keep_memory)); | |
2674 | if (internal_relocs == NULL) | |
2675 | return FALSE; | |
2676 | ||
c175a657 | 2677 | changed = FALSE; |
0afcef53 | 2678 | htab = elf_x86_hash_table (link_info, I386_ELF_DATA); |
daa67607 L |
2679 | local_got_refcounts = elf_local_got_refcounts (abfd); |
2680 | ||
2681 | /* Get the section contents. */ | |
2682 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
2683 | contents = elf_section_data (sec)->this_hdr.contents; | |
2684 | else | |
2685 | { | |
2686 | if (!bfd_malloc_and_get_section (abfd, sec, &contents)) | |
2687 | goto error_return; | |
2688 | } | |
2689 | ||
2690 | irelend = internal_relocs + sec->reloc_count; | |
2691 | for (irel = internal_relocs; irel < irelend; irel++) | |
2692 | { | |
2693 | unsigned int r_type = ELF32_R_TYPE (irel->r_info); | |
c175a657 | 2694 | unsigned int r_symndx; |
daa67607 | 2695 | struct elf_link_hash_entry *h; |
c175a657 | 2696 | bfd_boolean converted; |
daa67607 | 2697 | |
7d4d9709 L |
2698 | /* Don't convert R_386_GOT32 since we can't tell if it is applied |
2699 | to "mov $foo@GOT, %reg" which isn't a load via GOT. */ | |
2700 | if (r_type != R_386_GOT32X) | |
daa67607 L |
2701 | continue; |
2702 | ||
c175a657 | 2703 | r_symndx = ELF32_R_SYM (irel->r_info); |
02a86693 | 2704 | if (r_symndx < symtab_hdr->sh_info) |
0afcef53 L |
2705 | h = _bfd_elf_x86_get_local_sym_hash (htab, sec->owner, |
2706 | (const Elf_Internal_Rela *) irel, | |
2707 | FALSE); | |
c175a657 | 2708 | else |
02a86693 | 2709 | { |
c175a657 L |
2710 | h = elf_sym_hashes (abfd)[r_symndx - symtab_hdr->sh_info]; |
2711 | while (h->root.type == bfd_link_hash_indirect | |
2712 | || h->root.type == bfd_link_hash_warning) | |
2713 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
daa67607 L |
2714 | } |
2715 | ||
02a86693 | 2716 | /* STT_GNU_IFUNC must keep GOT32 relocations. */ |
c175a657 | 2717 | if (h != NULL && h->type == STT_GNU_IFUNC) |
02a86693 L |
2718 | continue; |
2719 | ||
c175a657 L |
2720 | converted = FALSE; |
2721 | if (!elf_i386_convert_load_reloc (abfd, symtab_hdr, contents, | |
2722 | irel, h, &converted, link_info)) | |
2723 | goto error_return; | |
bae420ef | 2724 | |
c175a657 | 2725 | if (converted) |
02a86693 | 2726 | { |
c175a657 L |
2727 | changed = converted; |
2728 | if (h) | |
02a86693 | 2729 | { |
c175a657 L |
2730 | if (h->got.refcount > 0) |
2731 | h->got.refcount -= 1; | |
02a86693 | 2732 | } |
c175a657 | 2733 | else |
02a86693 | 2734 | { |
c175a657 L |
2735 | if (local_got_refcounts != NULL |
2736 | && local_got_refcounts[r_symndx] > 0) | |
2737 | local_got_refcounts[r_symndx] -= 1; | |
02a86693 | 2738 | } |
daa67607 L |
2739 | } |
2740 | } | |
2741 | ||
2742 | if (contents != NULL | |
2743 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2744 | { | |
c175a657 | 2745 | if (!changed && !link_info->keep_memory) |
daa67607 L |
2746 | free (contents); |
2747 | else | |
2748 | { | |
2749 | /* Cache the section contents for elf_link_input_bfd. */ | |
2750 | elf_section_data (sec)->this_hdr.contents = contents; | |
2751 | } | |
2752 | } | |
2753 | ||
2754 | if (elf_section_data (sec)->relocs != internal_relocs) | |
2755 | { | |
c175a657 | 2756 | if (!changed) |
daa67607 L |
2757 | free (internal_relocs); |
2758 | else | |
2759 | elf_section_data (sec)->relocs = internal_relocs; | |
2760 | } | |
2761 | ||
2762 | return TRUE; | |
2763 | ||
2764 | error_return: | |
2765 | if (contents != NULL | |
2766 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2767 | free (contents); | |
2768 | if (internal_relocs != NULL | |
2769 | && elf_section_data (sec)->relocs != internal_relocs) | |
2770 | free (internal_relocs); | |
2771 | return FALSE; | |
2772 | } | |
2773 | ||
252b5132 RH |
2774 | /* Set the sizes of the dynamic sections. */ |
2775 | ||
b34976b6 | 2776 | static bfd_boolean |
23209a78 | 2777 | elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) |
252b5132 | 2778 | { |
0afcef53 | 2779 | struct elf_x86_link_hash_table *htab; |
252b5132 RH |
2780 | bfd *dynobj; |
2781 | asection *s; | |
b34976b6 | 2782 | bfd_boolean relocs; |
0c715baa | 2783 | bfd *ibfd; |
252b5132 | 2784 | |
0afcef53 | 2785 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 NC |
2786 | if (htab == NULL) |
2787 | return FALSE; | |
ebe50bae | 2788 | dynobj = htab->elf.dynobj; |
ffb2e45b AM |
2789 | if (dynobj == NULL) |
2790 | abort (); | |
252b5132 | 2791 | |
0c715baa AM |
2792 | /* Set up .got offsets for local syms, and space for local dynamic |
2793 | relocs. */ | |
c72f2fb2 | 2794 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
161d71a6 L |
2795 | { |
2796 | bfd_signed_vma *local_got; | |
2797 | bfd_signed_vma *end_local_got; | |
13ae64f3 | 2798 | char *local_tls_type; |
67a4f2b7 | 2799 | bfd_vma *local_tlsdesc_gotent; |
161d71a6 L |
2800 | bfd_size_type locsymcount; |
2801 | Elf_Internal_Shdr *symtab_hdr; | |
2802 | asection *srel; | |
6725bdbf | 2803 | |
0ffa91dd | 2804 | if (! is_i386_elf (ibfd)) |
161d71a6 | 2805 | continue; |
6725bdbf | 2806 | |
0c715baa AM |
2807 | for (s = ibfd->sections; s != NULL; s = s->next) |
2808 | { | |
e03a8ed8 | 2809 | struct elf_dyn_relocs *p; |
0c715baa | 2810 | |
02a86693 | 2811 | if (!elf_i386_convert_load (ibfd, s, info)) |
daa67607 L |
2812 | return FALSE; |
2813 | ||
e03a8ed8 | 2814 | for (p = ((struct elf_dyn_relocs *) |
e81d3500 | 2815 | elf_section_data (s)->local_dynrel); |
ec338859 AM |
2816 | p != NULL; |
2817 | p = p->next) | |
0c715baa | 2818 | { |
ec338859 AM |
2819 | if (!bfd_is_abs_section (p->sec) |
2820 | && bfd_is_abs_section (p->sec->output_section)) | |
2821 | { | |
2822 | /* Input section has been discarded, either because | |
2823 | it is a copy of a linkonce section or due to | |
2824 | linker script /DISCARD/, so we'll be discarding | |
2825 | the relocs too. */ | |
2826 | } | |
f604c2a2 L |
2827 | else if ((get_elf_i386_backend_data (output_bfd)->os |
2828 | == is_vxworks) | |
3348747a NS |
2829 | && strcmp (p->sec->output_section->name, |
2830 | ".tls_vars") == 0) | |
2831 | { | |
2832 | /* Relocations in vxworks .tls_vars sections are | |
2833 | handled specially by the loader. */ | |
2834 | } | |
248866a8 | 2835 | else if (p->count != 0) |
ec338859 AM |
2836 | { |
2837 | srel = elf_section_data (p->sec)->sreloc; | |
eea6121a | 2838 | srel->size += p->count * sizeof (Elf32_External_Rel); |
4b819e1f L |
2839 | if ((p->sec->output_section->flags & SEC_READONLY) != 0 |
2840 | && (info->flags & DF_TEXTREL) == 0) | |
b70321a2 L |
2841 | { |
2842 | info->flags |= DF_TEXTREL; | |
0e1862bb | 2843 | if ((info->warn_shared_textrel && bfd_link_pic (info)) |
1952c5cd | 2844 | || info->error_textrel) |
695344c0 | 2845 | /* xgettext:c-format */ |
1952c5cd | 2846 | info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"), |
b70321a2 | 2847 | p->sec->owner, p->sec); |
b70321a2 | 2848 | } |
ec338859 | 2849 | } |
0c715baa AM |
2850 | } |
2851 | } | |
2852 | ||
2853 | local_got = elf_local_got_refcounts (ibfd); | |
161d71a6 L |
2854 | if (!local_got) |
2855 | continue; | |
6725bdbf | 2856 | |
0ffa91dd | 2857 | symtab_hdr = &elf_symtab_hdr (ibfd); |
161d71a6 L |
2858 | locsymcount = symtab_hdr->sh_info; |
2859 | end_local_got = local_got + locsymcount; | |
0afcef53 L |
2860 | local_tls_type = elf_x86_local_got_tls_type (ibfd); |
2861 | local_tlsdesc_gotent = elf_x86_local_tlsdesc_gotent (ibfd); | |
6de2ae4a L |
2862 | s = htab->elf.sgot; |
2863 | srel = htab->elf.srelgot; | |
67a4f2b7 AO |
2864 | for (; local_got < end_local_got; |
2865 | ++local_got, ++local_tls_type, ++local_tlsdesc_gotent) | |
161d71a6 | 2866 | { |
67a4f2b7 | 2867 | *local_tlsdesc_gotent = (bfd_vma) -1; |
161d71a6 | 2868 | if (*local_got > 0) |
6725bdbf | 2869 | { |
67a4f2b7 AO |
2870 | if (GOT_TLS_GDESC_P (*local_tls_type)) |
2871 | { | |
6de2ae4a | 2872 | *local_tlsdesc_gotent = htab->elf.sgotplt->size |
67a4f2b7 | 2873 | - elf_i386_compute_jump_table_size (htab); |
6de2ae4a | 2874 | htab->elf.sgotplt->size += 8; |
67a4f2b7 AO |
2875 | *local_got = (bfd_vma) -2; |
2876 | } | |
2877 | if (! GOT_TLS_GDESC_P (*local_tls_type) | |
2878 | || GOT_TLS_GD_P (*local_tls_type)) | |
2879 | { | |
2880 | *local_got = s->size; | |
2881 | s->size += 4; | |
2882 | if (GOT_TLS_GD_P (*local_tls_type) | |
2883 | || *local_tls_type == GOT_TLS_IE_BOTH) | |
2884 | s->size += 4; | |
2885 | } | |
0e1862bb | 2886 | if (bfd_link_pic (info) |
67a4f2b7 | 2887 | || GOT_TLS_GD_ANY_P (*local_tls_type) |
37e55690 JJ |
2888 | || (*local_tls_type & GOT_TLS_IE)) |
2889 | { | |
2890 | if (*local_tls_type == GOT_TLS_IE_BOTH) | |
eea6121a | 2891 | srel->size += 2 * sizeof (Elf32_External_Rel); |
67a4f2b7 AO |
2892 | else if (GOT_TLS_GD_P (*local_tls_type) |
2893 | || ! GOT_TLS_GDESC_P (*local_tls_type)) | |
eea6121a | 2894 | srel->size += sizeof (Elf32_External_Rel); |
67a4f2b7 | 2895 | if (GOT_TLS_GDESC_P (*local_tls_type)) |
6de2ae4a | 2896 | htab->elf.srelplt->size += sizeof (Elf32_External_Rel); |
37e55690 | 2897 | } |
6725bdbf | 2898 | } |
161d71a6 L |
2899 | else |
2900 | *local_got = (bfd_vma) -1; | |
6725bdbf | 2901 | } |
252b5132 | 2902 | } |
6725bdbf | 2903 | |
0afcef53 | 2904 | if (htab->tls_ld_or_ldm_got.refcount > 0) |
13ae64f3 JJ |
2905 | { |
2906 | /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM | |
2907 | relocs. */ | |
0afcef53 | 2908 | htab->tls_ld_or_ldm_got.offset = htab->elf.sgot->size; |
6de2ae4a L |
2909 | htab->elf.sgot->size += 8; |
2910 | htab->elf.srelgot->size += sizeof (Elf32_External_Rel); | |
13ae64f3 JJ |
2911 | } |
2912 | else | |
0afcef53 | 2913 | htab->tls_ld_or_ldm_got.offset = -1; |
13ae64f3 | 2914 | |
0c715baa AM |
2915 | /* Allocate global sym .plt and .got entries, and space for global |
2916 | sym dynamic relocs. */ | |
eb4ff4d6 | 2917 | elf_link_hash_traverse (&htab->elf, elf_i386_allocate_dynrelocs, info); |
252b5132 | 2918 | |
c25bc9fc L |
2919 | /* Allocate .plt and .got entries, and space for local symbols. */ |
2920 | htab_traverse (htab->loc_hash_table, | |
2921 | elf_i386_allocate_local_dynrelocs, | |
2922 | info); | |
2923 | ||
67a4f2b7 AO |
2924 | /* For every jump slot reserved in the sgotplt, reloc_count is |
2925 | incremented. However, when we reserve space for TLS descriptors, | |
2926 | it's not incremented, so in order to compute the space reserved | |
2927 | for them, it suffices to multiply the reloc count by the jump | |
e1f98742 | 2928 | slot size. |
caa0075c | 2929 | |
e1f98742 L |
2930 | PR ld/13302: We start next_irelative_index at the end of .rela.plt |
2931 | so that R_386_IRELATIVE entries come last. */ | |
6de2ae4a | 2932 | if (htab->elf.srelplt) |
e1f98742 | 2933 | { |
765e526c L |
2934 | htab->next_tls_desc_index = htab->elf.srelplt->reloc_count; |
2935 | htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4; | |
e1f98742 L |
2936 | htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1; |
2937 | } | |
2938 | else if (htab->elf.irelplt) | |
2939 | htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1; | |
2940 | ||
67a4f2b7 | 2941 | |
a7b16ceb L |
2942 | if (htab->elf.sgotplt) |
2943 | { | |
2944 | /* Don't allocate .got.plt section if there are no GOT nor PLT | |
9a2a56cc | 2945 | entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */ |
9d4b2dba L |
2946 | if ((htab->elf.hgot == NULL |
2947 | || !htab->elf.hgot->ref_regular_nonweak) | |
e28df02b L |
2948 | && (htab->elf.sgotplt->size |
2949 | == get_elf_backend_data (output_bfd)->got_header_size) | |
a7b16ceb L |
2950 | && (htab->elf.splt == NULL |
2951 | || htab->elf.splt->size == 0) | |
2952 | && (htab->elf.sgot == NULL | |
2953 | || htab->elf.sgot->size == 0) | |
2954 | && (htab->elf.iplt == NULL | |
2955 | || htab->elf.iplt->size == 0) | |
2956 | && (htab->elf.igotplt == NULL | |
2957 | || htab->elf.igotplt->size == 0)) | |
2958 | htab->elf.sgotplt->size = 0; | |
2959 | } | |
2960 | ||
fff53dae L |
2961 | if (_bfd_elf_eh_frame_present (info)) |
2962 | { | |
2963 | if (htab->plt_eh_frame != NULL | |
2964 | && htab->elf.splt != NULL | |
2965 | && htab->elf.splt->size != 0 | |
2966 | && !bfd_is_abs_section (htab->elf.splt->output_section)) | |
765e526c | 2967 | htab->plt_eh_frame->size = htab->plt.eh_frame_plt_size; |
fff53dae L |
2968 | |
2969 | if (htab->plt_got_eh_frame != NULL | |
2970 | && htab->plt_got != NULL | |
2971 | && htab->plt_got->size != 0 | |
2972 | && !bfd_is_abs_section (htab->plt_got->output_section)) | |
2973 | htab->plt_got_eh_frame->size | |
765e526c | 2974 | = htab->non_lazy_plt->eh_frame_plt_size; |
ee2fdd6f L |
2975 | |
2976 | /* Unwind info for the second PLT and .plt.got sections are | |
2977 | identical. */ | |
2978 | if (htab->plt_second_eh_frame != NULL | |
2979 | && htab->plt_second != NULL | |
2980 | && htab->plt_second->size != 0 | |
2981 | && !bfd_is_abs_section (htab->plt_second->output_section)) | |
2982 | htab->plt_second_eh_frame->size | |
765e526c | 2983 | = htab->non_lazy_plt->eh_frame_plt_size; |
fff53dae | 2984 | } |
9a2a56cc | 2985 | |
5a15f56f AM |
2986 | /* We now have determined the sizes of the various dynamic sections. |
2987 | Allocate memory for them. */ | |
b34976b6 | 2988 | relocs = FALSE; |
252b5132 RH |
2989 | for (s = dynobj->sections; s != NULL; s = s->next) |
2990 | { | |
eac338cf PB |
2991 | bfd_boolean strip_section = TRUE; |
2992 | ||
252b5132 RH |
2993 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
2994 | continue; | |
2995 | ||
6de2ae4a | 2996 | if (s == htab->elf.splt |
9a2a56cc | 2997 | || s == htab->elf.sgot) |
252b5132 | 2998 | { |
6725bdbf AM |
2999 | /* Strip this section if we don't need it; see the |
3000 | comment below. */ | |
eac338cf PB |
3001 | /* We'd like to strip these sections if they aren't needed, but if |
3002 | we've exported dynamic symbols from them we must leave them. | |
3003 | It's too late to tell BFD to get rid of the symbols. */ | |
3004 | ||
7325306f | 3005 | if (htab->elf.hplt != NULL) |
eac338cf | 3006 | strip_section = FALSE; |
252b5132 | 3007 | } |
9a2a56cc AM |
3008 | else if (s == htab->elf.sgotplt |
3009 | || s == htab->elf.iplt | |
3010 | || s == htab->elf.igotplt | |
ee2fdd6f | 3011 | || s == htab->plt_second |
dd7e64d4 | 3012 | || s == htab->plt_got |
9a2a56cc | 3013 | || s == htab->plt_eh_frame |
fff53dae | 3014 | || s == htab->plt_got_eh_frame |
ee2fdd6f | 3015 | || s == htab->plt_second_eh_frame |
5474d94f AM |
3016 | || s == htab->elf.sdynbss |
3017 | || s == htab->elf.sdynrelro) | |
9a2a56cc AM |
3018 | { |
3019 | /* Strip these too. */ | |
3020 | } | |
0112cd26 | 3021 | else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rel")) |
252b5132 | 3022 | { |
6de2ae4a L |
3023 | if (s->size != 0 |
3024 | && s != htab->elf.srelplt | |
765e526c | 3025 | && s != htab->srelplt2) |
b34976b6 | 3026 | relocs = TRUE; |
252b5132 | 3027 | |
0ac8d2ca AM |
3028 | /* We use the reloc_count field as a counter if we need |
3029 | to copy relocs into the output file. */ | |
5ae0bfb6 | 3030 | s->reloc_count = 0; |
252b5132 | 3031 | } |
6725bdbf | 3032 | else |
252b5132 RH |
3033 | { |
3034 | /* It's not one of our sections, so don't allocate space. */ | |
3035 | continue; | |
3036 | } | |
3037 | ||
c456f082 | 3038 | if (s->size == 0) |
252b5132 | 3039 | { |
0ac8d2ca AM |
3040 | /* If we don't need this section, strip it from the |
3041 | output file. This is mostly to handle .rel.bss and | |
3042 | .rel.plt. We must create both sections in | |
3043 | create_dynamic_sections, because they must be created | |
3044 | before the linker maps input sections to output | |
3045 | sections. The linker does that before | |
3046 | adjust_dynamic_symbol is called, and it is that | |
3047 | function which decides whether anything needs to go | |
3048 | into these sections. */ | |
c456f082 AM |
3049 | if (strip_section) |
3050 | s->flags |= SEC_EXCLUDE; | |
252b5132 RH |
3051 | continue; |
3052 | } | |
3053 | ||
c456f082 AM |
3054 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
3055 | continue; | |
3056 | ||
f69da49f AM |
3057 | /* Allocate memory for the section contents. We use bfd_zalloc |
3058 | here in case unused entries are not reclaimed before the | |
3059 | section's contents are written out. This should not happen, | |
3060 | but this way if it does, we get a R_386_NONE reloc instead | |
3061 | of garbage. */ | |
a50b1753 | 3062 | s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size); |
6725bdbf | 3063 | if (s->contents == NULL) |
b34976b6 | 3064 | return FALSE; |
252b5132 RH |
3065 | } |
3066 | ||
e41b3a13 | 3067 | if (htab->plt_eh_frame != NULL |
9a2a56cc AM |
3068 | && htab->plt_eh_frame->contents != NULL) |
3069 | { | |
f129e49f | 3070 | memcpy (htab->plt_eh_frame->contents, |
765e526c | 3071 | htab->plt.eh_frame_plt, |
f129e49f | 3072 | htab->plt_eh_frame->size); |
9a2a56cc AM |
3073 | bfd_put_32 (dynobj, htab->elf.splt->size, |
3074 | htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET); | |
3075 | } | |
e41b3a13 | 3076 | |
fff53dae L |
3077 | if (htab->plt_got_eh_frame != NULL |
3078 | && htab->plt_got_eh_frame->contents != NULL) | |
3079 | { | |
3080 | memcpy (htab->plt_got_eh_frame->contents, | |
765e526c | 3081 | htab->non_lazy_plt->eh_frame_plt, |
fff53dae L |
3082 | htab->plt_got_eh_frame->size); |
3083 | bfd_put_32 (dynobj, htab->plt_got->size, | |
3084 | (htab->plt_got_eh_frame->contents | |
3085 | + PLT_FDE_LEN_OFFSET)); | |
3086 | } | |
3087 | ||
ee2fdd6f L |
3088 | if (htab->plt_second_eh_frame != NULL |
3089 | && htab->plt_second_eh_frame->contents != NULL) | |
3090 | { | |
3091 | memcpy (htab->plt_second_eh_frame->contents, | |
765e526c | 3092 | htab->non_lazy_plt->eh_frame_plt, |
ee2fdd6f L |
3093 | htab->plt_second_eh_frame->size); |
3094 | bfd_put_32 (dynobj, htab->plt_second->size, | |
3095 | (htab->plt_second_eh_frame->contents | |
3096 | + PLT_FDE_LEN_OFFSET)); | |
3097 | } | |
3098 | ||
ebe50bae | 3099 | if (htab->elf.dynamic_sections_created) |
252b5132 RH |
3100 | { |
3101 | /* Add some entries to the .dynamic section. We fill in the | |
3102 | values later, in elf_i386_finish_dynamic_sections, but we | |
3103 | must add the entries now so that we get the correct size for | |
3104 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
3105 | dynamic linker and used by the debugger. */ | |
dc810e39 | 3106 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 3107 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 3108 | |
0e1862bb | 3109 | if (bfd_link_executable (info)) |
252b5132 | 3110 | { |
dc810e39 | 3111 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 3112 | return FALSE; |
252b5132 RH |
3113 | } |
3114 | ||
6de2ae4a | 3115 | if (htab->elf.splt->size != 0) |
252b5132 | 3116 | { |
7c1e8d3e L |
3117 | /* DT_PLTGOT is used by prelink even if there is no PLT |
3118 | relocation. */ | |
3119 | if (!add_dynamic_entry (DT_PLTGOT, 0)) | |
b34976b6 | 3120 | return FALSE; |
97d343d4 | 3121 | } |
7c1e8d3e | 3122 | |
97d343d4 L |
3123 | if (htab->elf.srelplt->size != 0) |
3124 | { | |
3125 | if (!add_dynamic_entry (DT_PLTRELSZ, 0) | |
3126 | || !add_dynamic_entry (DT_PLTREL, DT_REL) | |
3127 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
3128 | return FALSE; | |
252b5132 RH |
3129 | } |
3130 | ||
3131 | if (relocs) | |
3132 | { | |
dc810e39 AM |
3133 | if (!add_dynamic_entry (DT_REL, 0) |
3134 | || !add_dynamic_entry (DT_RELSZ, 0) | |
3135 | || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel))) | |
b34976b6 | 3136 | return FALSE; |
252b5132 | 3137 | |
0c715baa AM |
3138 | /* If any dynamic relocs apply to a read-only section, |
3139 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 3140 | if ((info->flags & DF_TEXTREL) == 0) |
eb4ff4d6 | 3141 | elf_link_hash_traverse (&htab->elf, |
0afcef53 L |
3142 | _bfd_x86_elf_readonly_dynrelocs, |
3143 | info); | |
0c715baa AM |
3144 | |
3145 | if ((info->flags & DF_TEXTREL) != 0) | |
3146 | { | |
2df3368d | 3147 | if (htab->readonly_dynrelocs_against_ifunc) |
8efa2874 L |
3148 | { |
3149 | info->callbacks->einfo | |
3150 | (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n")); | |
3151 | bfd_set_error (bfd_error_bad_value); | |
3152 | return FALSE; | |
3153 | } | |
3154 | ||
0c715baa | 3155 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 3156 | return FALSE; |
0c715baa | 3157 | } |
252b5132 | 3158 | } |
f604c2a2 | 3159 | if (get_elf_i386_backend_data (output_bfd)->os == is_vxworks |
7a2b07ff NS |
3160 | && !elf_vxworks_add_dynamic_entries (output_bfd, info)) |
3161 | return FALSE; | |
252b5132 | 3162 | } |
dc810e39 | 3163 | #undef add_dynamic_entry |
252b5132 | 3164 | |
b34976b6 | 3165 | return TRUE; |
252b5132 RH |
3166 | } |
3167 | ||
38701953 AM |
3168 | /* Set the correct type for an x86 ELF section. We do this by the |
3169 | section name, which is a hack, but ought to work. */ | |
3170 | ||
b34976b6 | 3171 | static bfd_boolean |
55fd94b0 AM |
3172 | elf_i386_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, |
3173 | Elf_Internal_Shdr *hdr, | |
3174 | asection *sec) | |
38701953 | 3175 | { |
91d6fa6a | 3176 | const char *name; |
38701953 AM |
3177 | |
3178 | name = bfd_get_section_name (abfd, sec); | |
3179 | ||
3180 | /* This is an ugly, but unfortunately necessary hack that is | |
3181 | needed when producing EFI binaries on x86. It tells | |
3182 | elf.c:elf_fake_sections() not to consider ".reloc" as a section | |
3183 | containing ELF relocation info. We need this hack in order to | |
3184 | be able to generate ELF binaries that can be translated into | |
3185 | EFI applications (which are essentially COFF objects). Those | |
3186 | files contain a COFF ".reloc" section inside an ELFNN object, | |
3187 | which would normally cause BFD to segfault because it would | |
3188 | attempt to interpret this section as containing relocation | |
3189 | entries for section "oc". With this hack enabled, ".reloc" | |
3190 | will be treated as a normal data section, which will avoid the | |
3191 | segfault. However, you won't be able to create an ELFNN binary | |
3192 | with a section named "oc" that needs relocations, but that's | |
3193 | the kind of ugly side-effects you get when detecting section | |
3194 | types based on their names... In practice, this limitation is | |
3195 | unlikely to bite. */ | |
3196 | if (strcmp (name, ".reloc") == 0) | |
3197 | hdr->sh_type = SHT_PROGBITS; | |
3198 | ||
b34976b6 | 3199 | return TRUE; |
38701953 AM |
3200 | } |
3201 | ||
13ae64f3 JJ |
3202 | /* Return the relocation value for @tpoff relocation |
3203 | if STT_TLS virtual address is ADDRESS. */ | |
3204 | ||
3205 | static bfd_vma | |
eb4ff4d6 | 3206 | elf_i386_tpoff (struct bfd_link_info *info, bfd_vma address) |
13ae64f3 | 3207 | { |
e1918d23 | 3208 | struct elf_link_hash_table *htab = elf_hash_table (info); |
7dc98aea RO |
3209 | const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd); |
3210 | bfd_vma static_tls_size; | |
13ae64f3 | 3211 | |
e1918d23 AM |
3212 | /* If tls_sec is NULL, we should have signalled an error already. */ |
3213 | if (htab->tls_sec == NULL) | |
6a30718d | 3214 | return 0; |
7dc98aea RO |
3215 | |
3216 | /* Consider special static TLS alignment requirements. */ | |
3217 | static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment); | |
3218 | return static_tls_size + htab->tls_sec->vma - address; | |
13ae64f3 JJ |
3219 | } |
3220 | ||
252b5132 RH |
3221 | /* Relocate an i386 ELF section. */ |
3222 | ||
b34976b6 | 3223 | static bfd_boolean |
55fd94b0 AM |
3224 | elf_i386_relocate_section (bfd *output_bfd, |
3225 | struct bfd_link_info *info, | |
3226 | bfd *input_bfd, | |
3227 | asection *input_section, | |
3228 | bfd_byte *contents, | |
3229 | Elf_Internal_Rela *relocs, | |
3230 | Elf_Internal_Sym *local_syms, | |
3231 | asection **local_sections) | |
252b5132 | 3232 | { |
0afcef53 | 3233 | struct elf_x86_link_hash_table *htab; |
252b5132 RH |
3234 | Elf_Internal_Shdr *symtab_hdr; |
3235 | struct elf_link_hash_entry **sym_hashes; | |
3236 | bfd_vma *local_got_offsets; | |
67a4f2b7 | 3237 | bfd_vma *local_tlsdesc_gotents; |
252b5132 | 3238 | Elf_Internal_Rela *rel; |
60f2e42e | 3239 | Elf_Internal_Rela *wrel; |
252b5132 | 3240 | Elf_Internal_Rela *relend; |
3348747a | 3241 | bfd_boolean is_vxworks_tls; |
25e762b9 | 3242 | unsigned plt_entry_size; |
252b5132 | 3243 | |
0ffa91dd | 3244 | BFD_ASSERT (is_i386_elf (input_bfd)); |
6bbec505 | 3245 | |
c337a162 L |
3246 | /* Skip if check_relocs failed. */ |
3247 | if (input_section->check_relocs_failed) | |
3248 | return FALSE; | |
3249 | ||
0afcef53 | 3250 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 NC |
3251 | if (htab == NULL) |
3252 | return FALSE; | |
0ffa91dd | 3253 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
252b5132 RH |
3254 | sym_hashes = elf_sym_hashes (input_bfd); |
3255 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
0afcef53 | 3256 | local_tlsdesc_gotents = elf_x86_local_tlsdesc_gotent (input_bfd); |
3348747a NS |
3257 | /* We have to handle relocations in vxworks .tls_vars sections |
3258 | specially, because the dynamic loader is 'weird'. */ | |
f604c2a2 L |
3259 | is_vxworks_tls = ((get_elf_i386_backend_data (output_bfd)->os |
3260 | == is_vxworks) | |
0e1862bb | 3261 | && bfd_link_pic (info) |
3348747a NS |
3262 | && !strcmp (input_section->output_section->name, |
3263 | ".tls_vars")); | |
252b5132 | 3264 | |
0afcef53 | 3265 | _bfd_x86_elf_set_tls_module_base (info); |
9f03412a | 3266 | |
765e526c | 3267 | plt_entry_size = htab->plt.plt_entry_size; |
25e762b9 | 3268 | |
60f2e42e | 3269 | rel = wrel = relocs; |
252b5132 | 3270 | relend = relocs + input_section->reloc_count; |
60f2e42e | 3271 | for (; rel < relend; wrel++, rel++) |
252b5132 | 3272 | { |
13ae64f3 | 3273 | unsigned int r_type; |
252b5132 RH |
3274 | reloc_howto_type *howto; |
3275 | unsigned long r_symndx; | |
3276 | struct elf_link_hash_entry *h; | |
0afcef53 | 3277 | struct elf_x86_link_hash_entry *eh; |
252b5132 RH |
3278 | Elf_Internal_Sym *sym; |
3279 | asection *sec; | |
dd7e64d4 | 3280 | bfd_vma off, offplt, plt_offset; |
252b5132 | 3281 | bfd_vma relocation; |
b34976b6 | 3282 | bfd_boolean unresolved_reloc; |
252b5132 | 3283 | bfd_reloc_status_type r; |
1b452ec6 | 3284 | unsigned int indx; |
13ae64f3 | 3285 | int tls_type; |
1788fc08 | 3286 | bfd_vma st_size; |
dd7e64d4 | 3287 | asection *resolved_plt; |
aec6b87e | 3288 | bfd_boolean resolved_to_zero; |
e133d005 | 3289 | bfd_boolean relative_reloc; |
252b5132 RH |
3290 | |
3291 | r_type = ELF32_R_TYPE (rel->r_info); | |
55fd94b0 AM |
3292 | if (r_type == R_386_GNU_VTINHERIT |
3293 | || r_type == R_386_GNU_VTENTRY) | |
18954b29 L |
3294 | { |
3295 | if (wrel != rel) | |
3296 | *wrel = *rel; | |
3297 | continue; | |
3298 | } | |
dc47f327 | 3299 | |
55fd94b0 | 3300 | if ((indx = r_type) >= R_386_standard |
13ae64f3 JJ |
3301 | && ((indx = r_type - R_386_ext_offset) - R_386_standard |
3302 | >= R_386_ext - R_386_standard) | |
3303 | && ((indx = r_type - R_386_tls_offset) - R_386_ext | |
c74be520 | 3304 | >= R_386_ext2 - R_386_ext)) |
47aeb64c NC |
3305 | return _bfd_unrecognized_reloc (input_bfd, input_section, r_type); |
3306 | ||
1b452ec6 | 3307 | howto = elf_howto_table + indx; |
252b5132 RH |
3308 | |
3309 | r_symndx = ELF32_R_SYM (rel->r_info); | |
252b5132 RH |
3310 | h = NULL; |
3311 | sym = NULL; | |
3312 | sec = NULL; | |
b34976b6 | 3313 | unresolved_reloc = FALSE; |
252b5132 RH |
3314 | if (r_symndx < symtab_hdr->sh_info) |
3315 | { | |
3316 | sym = local_syms + r_symndx; | |
3317 | sec = local_sections[r_symndx]; | |
3318 | relocation = (sec->output_section->vma | |
3319 | + sec->output_offset | |
3320 | + sym->st_value); | |
1788fc08 | 3321 | st_size = sym->st_size; |
ab96bf03 AM |
3322 | |
3323 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION | |
3324 | && ((sec->flags & SEC_MERGE) != 0 | |
0e1862bb | 3325 | || (bfd_link_relocatable (info) |
ab96bf03 | 3326 | && sec->output_offset != 0))) |
f8df10f4 | 3327 | { |
f8df10f4 | 3328 | bfd_vma addend; |
4a335f3d | 3329 | bfd_byte *where = contents + rel->r_offset; |
f8df10f4 | 3330 | |
4a335f3d | 3331 | switch (howto->size) |
f8df10f4 | 3332 | { |
4a335f3d AM |
3333 | case 0: |
3334 | addend = bfd_get_8 (input_bfd, where); | |
3335 | if (howto->pc_relative) | |
3336 | { | |
3337 | addend = (addend ^ 0x80) - 0x80; | |
3338 | addend += 1; | |
3339 | } | |
3340 | break; | |
3341 | case 1: | |
3342 | addend = bfd_get_16 (input_bfd, where); | |
3343 | if (howto->pc_relative) | |
3344 | { | |
3345 | addend = (addend ^ 0x8000) - 0x8000; | |
3346 | addend += 2; | |
3347 | } | |
3348 | break; | |
3349 | case 2: | |
3350 | addend = bfd_get_32 (input_bfd, where); | |
3351 | if (howto->pc_relative) | |
3352 | { | |
3353 | addend = (addend ^ 0x80000000) - 0x80000000; | |
3354 | addend += 4; | |
3355 | } | |
3356 | break; | |
3357 | default: | |
3358 | abort (); | |
f8df10f4 JJ |
3359 | } |
3360 | ||
0e1862bb | 3361 | if (bfd_link_relocatable (info)) |
ab96bf03 AM |
3362 | addend += sec->output_offset; |
3363 | else | |
3364 | { | |
3365 | asection *msec = sec; | |
3366 | addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, | |
3367 | addend); | |
3368 | addend -= relocation; | |
3369 | addend += msec->output_section->vma + msec->output_offset; | |
3370 | } | |
4a335f3d AM |
3371 | |
3372 | switch (howto->size) | |
3373 | { | |
3374 | case 0: | |
16a10388 | 3375 | /* FIXME: overflow checks. */ |
4a335f3d AM |
3376 | if (howto->pc_relative) |
3377 | addend -= 1; | |
3378 | bfd_put_8 (input_bfd, addend, where); | |
4a335f3d AM |
3379 | break; |
3380 | case 1: | |
3381 | if (howto->pc_relative) | |
3382 | addend -= 2; | |
3383 | bfd_put_16 (input_bfd, addend, where); | |
4a335f3d AM |
3384 | break; |
3385 | case 2: | |
3386 | if (howto->pc_relative) | |
3387 | addend -= 4; | |
3388 | bfd_put_32 (input_bfd, addend, where); | |
3389 | break; | |
3390 | } | |
f8df10f4 | 3391 | } |
0e1862bb | 3392 | else if (!bfd_link_relocatable (info) |
1f85278f | 3393 | && ELF32_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
c25bc9fc L |
3394 | { |
3395 | /* Relocate against local STT_GNU_IFUNC symbol. */ | |
0afcef53 L |
3396 | h = _bfd_elf_x86_get_local_sym_hash (htab, input_bfd, rel, |
3397 | FALSE); | |
c25bc9fc L |
3398 | if (h == NULL) |
3399 | abort (); | |
3400 | ||
23209a78 | 3401 | /* Set STT_GNU_IFUNC symbol value. */ |
c25bc9fc L |
3402 | h->root.u.def.value = sym->st_value; |
3403 | h->root.u.def.section = sec; | |
3404 | } | |
252b5132 RH |
3405 | } |
3406 | else | |
3407 | { | |
3d540e93 | 3408 | bfd_boolean warned ATTRIBUTE_UNUSED; |
62d887d4 | 3409 | bfd_boolean ignored ATTRIBUTE_UNUSED; |
ffb2e45b | 3410 | |
b2a8e766 AM |
3411 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
3412 | r_symndx, symtab_hdr, sym_hashes, | |
3413 | h, sec, relocation, | |
62d887d4 | 3414 | unresolved_reloc, warned, ignored); |
1788fc08 | 3415 | st_size = h->size; |
252b5132 RH |
3416 | } |
3417 | ||
dbaa2011 | 3418 | if (sec != NULL && discarded_section (sec)) |
60f2e42e L |
3419 | { |
3420 | _bfd_clear_contents (howto, input_bfd, input_section, | |
3421 | contents + rel->r_offset); | |
3422 | wrel->r_offset = rel->r_offset; | |
3423 | wrel->r_info = 0; | |
3424 | wrel->r_addend = 0; | |
3425 | ||
3426 | /* For ld -r, remove relocations in debug sections against | |
3427 | sections defined in discarded sections. Not done for | |
3428 | eh_frame editing code expects to be present. */ | |
3429 | if (bfd_link_relocatable (info) | |
3430 | && (input_section->flags & SEC_DEBUGGING)) | |
3431 | wrel--; | |
3432 | ||
3433 | continue; | |
3434 | } | |
9635fe29 | 3435 | |
0e1862bb | 3436 | if (bfd_link_relocatable (info)) |
2d5da473 L |
3437 | { |
3438 | if (wrel != rel) | |
3439 | *wrel = *rel; | |
3440 | continue; | |
3441 | } | |
ab96bf03 | 3442 | |
0afcef53 | 3443 | eh = (struct elf_x86_link_hash_entry *) h; |
ee2fdd6f | 3444 | |
cbe950e9 L |
3445 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle |
3446 | it here if it is defined in a non-shared object. */ | |
3447 | if (h != NULL | |
3448 | && h->type == STT_GNU_IFUNC | |
3449 | && h->def_regular) | |
3450 | { | |
ee2fdd6f | 3451 | asection *gotplt, *base_got; |
cbe950e9 | 3452 | bfd_vma plt_index; |
4c544807 | 3453 | const char *name; |
cbe950e9 | 3454 | |
97dc35c8 L |
3455 | if ((input_section->flags & SEC_ALLOC) == 0) |
3456 | { | |
3457 | /* Dynamic relocs are not propagated for SEC_DEBUGGING | |
3458 | sections because such sections are not SEC_ALLOC and | |
3459 | thus ld.so will not process them. */ | |
3460 | if ((input_section->flags & SEC_DEBUGGING) != 0) | |
0eace210 | 3461 | continue; |
97dc35c8 L |
3462 | abort (); |
3463 | } | |
cbe950e9 L |
3464 | |
3465 | /* STT_GNU_IFUNC symbol must go through PLT. */ | |
6de2ae4a | 3466 | if (htab->elf.splt != NULL) |
cbe950e9 | 3467 | { |
ee2fdd6f L |
3468 | if (htab->plt_second != NULL) |
3469 | { | |
3470 | resolved_plt = htab->plt_second; | |
3471 | plt_offset = eh->plt_second.offset; | |
3472 | } | |
3473 | else | |
3474 | { | |
3475 | resolved_plt = htab->elf.splt; | |
3476 | plt_offset = h->plt.offset; | |
3477 | } | |
6de2ae4a | 3478 | gotplt = htab->elf.sgotplt; |
cbe950e9 L |
3479 | } |
3480 | else | |
3481 | { | |
ee2fdd6f L |
3482 | resolved_plt = htab->elf.iplt; |
3483 | plt_offset = h->plt.offset; | |
6de2ae4a | 3484 | gotplt = htab->elf.igotplt; |
cbe950e9 L |
3485 | } |
3486 | ||
cbe950e9 L |
3487 | switch (r_type) |
3488 | { | |
3489 | default: | |
233cc9c1 | 3490 | break; |
cbe950e9 L |
3491 | |
3492 | case R_386_GOT32: | |
02a86693 | 3493 | case R_386_GOT32X: |
6de2ae4a | 3494 | base_got = htab->elf.sgot; |
cbe950e9 L |
3495 | off = h->got.offset; |
3496 | ||
7afd84dc | 3497 | if (base_got == NULL) |
cbe950e9 L |
3498 | abort (); |
3499 | ||
7afd84dc | 3500 | if (off == (bfd_vma) -1) |
cbe950e9 | 3501 | { |
7afd84dc L |
3502 | /* We can't use h->got.offset here to save state, or |
3503 | even just remember the offset, as finish_dynamic_symbol | |
3504 | would use that as offset into .got. */ | |
6bbec505 | 3505 | |
233cc9c1 L |
3506 | if (h->plt.offset == (bfd_vma) -1) |
3507 | abort (); | |
3508 | ||
6de2ae4a | 3509 | if (htab->elf.splt != NULL) |
7afd84dc | 3510 | { |
f604c2a2 | 3511 | plt_index = (h->plt.offset / plt_entry_size |
765e526c | 3512 | - htab->plt.has_plt0); |
7afd84dc | 3513 | off = (plt_index + 3) * 4; |
6de2ae4a | 3514 | base_got = htab->elf.sgotplt; |
7afd84dc | 3515 | } |
cbe950e9 L |
3516 | else |
3517 | { | |
25e762b9 | 3518 | plt_index = h->plt.offset / plt_entry_size; |
7afd84dc | 3519 | off = plt_index * 4; |
6de2ae4a | 3520 | base_got = htab->elf.igotplt; |
7afd84dc L |
3521 | } |
3522 | ||
3523 | if (h->dynindx == -1 | |
3524 | || h->forced_local | |
3525 | || info->symbolic) | |
3526 | { | |
3527 | /* This references the local defitionion. We must | |
3528 | initialize this entry in the global offset table. | |
3529 | Since the offset must always be a multiple of 8, | |
3530 | we use the least significant bit to record | |
3531 | whether we have initialized it already. | |
3532 | ||
3533 | When doing a dynamic link, we create a .rela.got | |
3534 | relocation entry to initialize the value. This | |
3535 | is done in the finish_dynamic_symbol routine. */ | |
3536 | if ((off & 1) != 0) | |
3537 | off &= ~1; | |
3538 | else | |
3539 | { | |
3540 | bfd_put_32 (output_bfd, relocation, | |
3541 | base_got->contents + off); | |
3542 | h->got.offset |= 1; | |
3543 | } | |
cbe950e9 | 3544 | } |
cbe950e9 | 3545 | |
7afd84dc | 3546 | relocation = off; |
7afd84dc L |
3547 | } |
3548 | else | |
ca8c86ef L |
3549 | relocation = (base_got->output_section->vma |
3550 | + base_got->output_offset + off | |
3551 | - gotplt->output_section->vma | |
3552 | - gotplt->output_offset); | |
3553 | ||
2a568401 L |
3554 | if (rel->r_offset > 1 |
3555 | && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5 | |
3556 | && *(contents + rel->r_offset - 2) != 0x8d) | |
712ec279 L |
3557 | { |
3558 | if (bfd_link_pic (info)) | |
3559 | goto disallow_got32; | |
3560 | ||
3561 | /* Add the GOT base if there is no base register. */ | |
3562 | relocation += (gotplt->output_section->vma | |
3563 | + gotplt->output_offset); | |
3564 | } | |
3565 | else if (htab->elf.splt == NULL) | |
3566 | { | |
3567 | /* Adjust for static executables. */ | |
3568 | relocation += gotplt->output_offset; | |
3569 | } | |
0018b0a3 | 3570 | |
cbe950e9 | 3571 | goto do_relocation; |
233cc9c1 L |
3572 | } |
3573 | ||
3574 | if (h->plt.offset == (bfd_vma) -1) | |
3575 | { | |
3576 | /* Handle static pointers of STT_GNU_IFUNC symbols. */ | |
3577 | if (r_type == R_386_32 | |
3578 | && (input_section->flags & SEC_CODE) == 0) | |
3579 | goto do_ifunc_pointer; | |
3580 | goto bad_ifunc_reloc; | |
3581 | } | |
3582 | ||
ee2fdd6f L |
3583 | relocation = (resolved_plt->output_section->vma |
3584 | + resolved_plt->output_offset + plt_offset); | |
233cc9c1 L |
3585 | |
3586 | switch (r_type) | |
3587 | { | |
3588 | default: | |
3589 | bad_ifunc_reloc: | |
3590 | if (h->root.root.string) | |
3591 | name = h->root.root.string; | |
3592 | else | |
3593 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, | |
3594 | NULL); | |
4eca0228 | 3595 | _bfd_error_handler |
695344c0 | 3596 | /* xgettext:c-format */ |
233cc9c1 L |
3597 | (_("%B: relocation %s against STT_GNU_IFUNC " |
3598 | "symbol `%s' isn't supported"), input_bfd, | |
3599 | howto->name, name); | |
3600 | bfd_set_error (bfd_error_bad_value); | |
3601 | return FALSE; | |
3602 | ||
3603 | case R_386_32: | |
3604 | /* Generate dynamic relcoation only when there is a | |
3605 | non-GOT reference in a shared object. */ | |
3606 | if ((bfd_link_pic (info) && h->non_got_ref) | |
3607 | || h->plt.offset == (bfd_vma) -1) | |
3608 | { | |
3609 | Elf_Internal_Rela outrel; | |
3610 | asection *sreloc; | |
3611 | bfd_vma offset; | |
3612 | ||
3613 | do_ifunc_pointer: | |
3614 | /* Need a dynamic relocation to get the real function | |
3615 | adddress. */ | |
3616 | offset = _bfd_elf_section_offset (output_bfd, | |
3617 | info, | |
3618 | input_section, | |
3619 | rel->r_offset); | |
3620 | if (offset == (bfd_vma) -1 | |
3621 | || offset == (bfd_vma) -2) | |
3622 | abort (); | |
3623 | ||
3624 | outrel.r_offset = (input_section->output_section->vma | |
3625 | + input_section->output_offset | |
3626 | + offset); | |
3627 | ||
3628 | if (h->dynindx == -1 | |
3629 | || h->forced_local | |
3630 | || bfd_link_executable (info)) | |
3631 | { | |
6322e5c5 L |
3632 | info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"), |
3633 | h->root.root.string, | |
3634 | h->root.u.def.section->owner); | |
3635 | ||
233cc9c1 L |
3636 | /* This symbol is resolved locally. */ |
3637 | outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE); | |
3638 | bfd_put_32 (output_bfd, | |
3639 | (h->root.u.def.value | |
3640 | + h->root.u.def.section->output_section->vma | |
3641 | + h->root.u.def.section->output_offset), | |
3642 | contents + offset); | |
3643 | } | |
3644 | else | |
3645 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); | |
3646 | ||
3647 | /* Dynamic relocations are stored in | |
3648 | 1. .rel.ifunc section in PIC object. | |
3649 | 2. .rel.got section in dynamic executable. | |
3650 | 3. .rel.iplt section in static executable. */ | |
3651 | if (bfd_link_pic (info)) | |
3652 | sreloc = htab->elf.irelifunc; | |
3653 | else if (htab->elf.splt != NULL) | |
3654 | sreloc = htab->elf.srelgot; | |
3655 | else | |
3656 | sreloc = htab->elf.irelplt; | |
3657 | elf_append_rel (output_bfd, sreloc, &outrel); | |
3658 | ||
3659 | /* If this reloc is against an external symbol, we | |
3660 | do not want to fiddle with the addend. Otherwise, | |
3661 | we need to include the symbol value so that it | |
3662 | becomes an addend for the dynamic reloc. For an | |
3663 | internal symbol, we have updated addend. */ | |
3664 | continue; | |
3665 | } | |
3666 | /* FALLTHROUGH */ | |
3667 | case R_386_PC32: | |
3668 | case R_386_PLT32: | |
3669 | goto do_relocation; | |
cbe950e9 L |
3670 | |
3671 | case R_386_GOTOFF: | |
3672 | relocation -= (gotplt->output_section->vma | |
3673 | + gotplt->output_offset); | |
3674 | goto do_relocation; | |
3675 | } | |
3676 | } | |
3677 | ||
aec6b87e | 3678 | resolved_to_zero = (eh != NULL |
e62b9723 | 3679 | && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, |
0afcef53 | 3680 | I386_ELF_DATA, |
e62b9723 L |
3681 | eh->has_got_reloc, |
3682 | eh)); | |
aec6b87e | 3683 | |
252b5132 RH |
3684 | switch (r_type) |
3685 | { | |
02a86693 L |
3686 | case R_386_GOT32X: |
3687 | /* Avoid optimizing _DYNAMIC since ld.so may use its | |
3688 | link-time address. */ | |
3689 | if (h == htab->elf.hdynamic) | |
3690 | goto r_386_got32; | |
3691 | ||
3692 | if (bfd_link_pic (info)) | |
3693 | { | |
3694 | /* It is OK to convert mov to lea and convert indirect | |
3695 | branch to direct branch. It is OK to convert adc, | |
3696 | add, and, cmp, or, sbb, sub, test, xor only when PIC | |
3697 | is false. */ | |
02e2aef8 L |
3698 | unsigned int opcode, addend; |
3699 | addend = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3700 | if (addend != 0) | |
3701 | goto r_386_got32; | |
3702 | opcode = bfd_get_8 (input_bfd, contents + rel->r_offset - 2); | |
02a86693 L |
3703 | if (opcode != 0x8b && opcode != 0xff) |
3704 | goto r_386_got32; | |
3705 | } | |
3706 | ||
3707 | /* Resolve "mov GOT[(%reg)], %reg", | |
3708 | "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]" | |
3709 | and "binop foo@GOT[(%reg)], %reg". */ | |
3710 | if (h == NULL | |
3711 | || (h->plt.offset == (bfd_vma) -1 | |
3712 | && h->got.offset == (bfd_vma) -1) | |
3713 | || htab->elf.sgotplt == NULL) | |
3714 | abort (); | |
3715 | ||
3716 | offplt = (htab->elf.sgotplt->output_section->vma | |
3717 | + htab->elf.sgotplt->output_offset); | |
3718 | ||
3719 | /* It is relative to .got.plt section. */ | |
3720 | if (h->got.offset != (bfd_vma) -1) | |
32875eb1 L |
3721 | /* Use GOT entry. Mask off the least significant bit in |
3722 | GOT offset which may be set by R_386_GOT32 processing | |
3723 | below. */ | |
02a86693 L |
3724 | relocation = (htab->elf.sgot->output_section->vma |
3725 | + htab->elf.sgot->output_offset | |
32875eb1 | 3726 | + (h->got.offset & ~1) - offplt); |
02a86693 L |
3727 | else |
3728 | /* Use GOTPLT entry. */ | |
f604c2a2 | 3729 | relocation = (h->plt.offset / plt_entry_size |
765e526c | 3730 | - htab->plt.has_plt0 + 3) * 4; |
02a86693 L |
3731 | |
3732 | if (!bfd_link_pic (info)) | |
3733 | { | |
3734 | /* If not PIC, add the .got.plt section address for | |
a3718e9e | 3735 | baseless addressing. */ |
02a86693 | 3736 | unsigned int modrm; |
02e2aef8 | 3737 | modrm = bfd_get_8 (input_bfd, contents + rel->r_offset - 1); |
02a86693 L |
3738 | if ((modrm & 0xc7) == 0x5) |
3739 | relocation += offplt; | |
3740 | } | |
3741 | ||
3742 | unresolved_reloc = FALSE; | |
3743 | break; | |
3744 | ||
252b5132 | 3745 | case R_386_GOT32: |
02a86693 | 3746 | r_386_got32: |
252b5132 RH |
3747 | /* Relocation is to the entry for this symbol in the global |
3748 | offset table. */ | |
6de2ae4a | 3749 | if (htab->elf.sgot == NULL) |
ffb2e45b | 3750 | abort (); |
252b5132 | 3751 | |
e133d005 | 3752 | relative_reloc = FALSE; |
252b5132 RH |
3753 | if (h != NULL) |
3754 | { | |
b34976b6 | 3755 | bfd_boolean dyn; |
252b5132 RH |
3756 | |
3757 | off = h->got.offset; | |
ebe50bae | 3758 | dyn = htab->elf.dynamic_sections_created; |
0e1862bb L |
3759 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, |
3760 | bfd_link_pic (info), | |
3761 | h) | |
3762 | || (bfd_link_pic (info) | |
586119b3 | 3763 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
ef5aade5 L |
3764 | || (ELF_ST_VISIBILITY (h->other) |
3765 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
3766 | { |
3767 | /* This is actually a static link, or it is a | |
3768 | -Bsymbolic link and the symbol is defined | |
3769 | locally, or the symbol was forced to be local | |
3770 | because of a version file. We must initialize | |
3771 | this entry in the global offset table. Since the | |
3772 | offset must always be a multiple of 4, we use the | |
3773 | least significant bit to record whether we have | |
3774 | initialized it already. | |
3775 | ||
3776 | When doing a dynamic link, we create a .rel.got | |
3777 | relocation entry to initialize the value. This | |
3778 | is done in the finish_dynamic_symbol routine. */ | |
3779 | if ((off & 1) != 0) | |
3780 | off &= ~1; | |
3781 | else | |
3782 | { | |
3783 | bfd_put_32 (output_bfd, relocation, | |
6de2ae4a | 3784 | htab->elf.sgot->contents + off); |
252b5132 | 3785 | h->got.offset |= 1; |
e133d005 L |
3786 | |
3787 | if (h->dynindx == -1 | |
3788 | && !h->forced_local | |
3789 | && h->root.type != bfd_link_hash_undefweak | |
0dc9a308 | 3790 | && bfd_link_pic (info)) |
e133d005 L |
3791 | { |
3792 | /* PR ld/21402: If this symbol isn't dynamic | |
0dc9a308 | 3793 | in PIC, generate R_386_RELATIVE here. */ |
e133d005 L |
3794 | eh->no_finish_dynamic_symbol = 1; |
3795 | relative_reloc = TRUE; | |
3796 | } | |
252b5132 RH |
3797 | } |
3798 | } | |
8c694914 | 3799 | else |
b34976b6 | 3800 | unresolved_reloc = FALSE; |
252b5132 RH |
3801 | } |
3802 | else | |
3803 | { | |
ffb2e45b AM |
3804 | if (local_got_offsets == NULL) |
3805 | abort (); | |
252b5132 RH |
3806 | |
3807 | off = local_got_offsets[r_symndx]; | |
3808 | ||
3809 | /* The offset must always be a multiple of 4. We use | |
83be169b AM |
3810 | the least significant bit to record whether we have |
3811 | already generated the necessary reloc. */ | |
252b5132 RH |
3812 | if ((off & 1) != 0) |
3813 | off &= ~1; | |
3814 | else | |
3815 | { | |
6725bdbf | 3816 | bfd_put_32 (output_bfd, relocation, |
6de2ae4a | 3817 | htab->elf.sgot->contents + off); |
e133d005 | 3818 | local_got_offsets[r_symndx] |= 1; |
252b5132 | 3819 | |
0e1862bb | 3820 | if (bfd_link_pic (info)) |
e133d005 | 3821 | relative_reloc = TRUE; |
252b5132 | 3822 | } |
252b5132 RH |
3823 | } |
3824 | ||
e133d005 L |
3825 | if (relative_reloc) |
3826 | { | |
3827 | asection *s; | |
3828 | Elf_Internal_Rela outrel; | |
3829 | ||
3830 | s = htab->elf.srelgot; | |
3831 | if (s == NULL) | |
3832 | abort (); | |
3833 | ||
3834 | outrel.r_offset = (htab->elf.sgot->output_section->vma | |
3835 | + htab->elf.sgot->output_offset | |
3836 | + off); | |
3837 | outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE); | |
3838 | elf_append_rel (output_bfd, s, &outrel); | |
3839 | } | |
3840 | ||
ffb2e45b AM |
3841 | if (off >= (bfd_vma) -2) |
3842 | abort (); | |
3843 | ||
74d7f0aa L |
3844 | relocation = (htab->elf.sgot->output_section->vma |
3845 | + htab->elf.sgot->output_offset + off); | |
2a568401 L |
3846 | if (rel->r_offset > 1 |
3847 | && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5 | |
3848 | && *(contents + rel->r_offset - 2) != 0x8d) | |
74d7f0aa L |
3849 | { |
3850 | if (bfd_link_pic (info)) | |
3851 | { | |
3852 | /* For PIC, disallow R_386_GOT32 without a base | |
2a568401 L |
3853 | register, except for "lea foo@GOT, %reg", since |
3854 | we don't know what the GOT base is. */ | |
74d7f0aa L |
3855 | const char *name; |
3856 | ||
712ec279 | 3857 | disallow_got32: |
a5def14f | 3858 | if (h == NULL || h->root.root.string == NULL) |
74d7f0aa L |
3859 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, |
3860 | NULL); | |
3861 | else | |
3862 | name = h->root.root.string; | |
3863 | ||
4eca0228 | 3864 | _bfd_error_handler |
695344c0 | 3865 | /* xgettext:c-format */ |
63a5468a AM |
3866 | (_("%B: direct GOT relocation %s against `%s'" |
3867 | " without base register can not be used" | |
3868 | " when making a shared object"), | |
712ec279 | 3869 | input_bfd, howto->name, name); |
74d7f0aa L |
3870 | bfd_set_error (bfd_error_bad_value); |
3871 | return FALSE; | |
3872 | } | |
3873 | } | |
3874 | else | |
3875 | { | |
3876 | /* Subtract the .got.plt section address only with a base | |
3877 | register. */ | |
3878 | relocation -= (htab->elf.sgotplt->output_section->vma | |
3879 | + htab->elf.sgotplt->output_offset); | |
3880 | } | |
3881 | ||
252b5132 RH |
3882 | break; |
3883 | ||
3884 | case R_386_GOTOFF: | |
3885 | /* Relocation is relative to the start of the global offset | |
3886 | table. */ | |
3887 | ||
3d949995 L |
3888 | /* Check to make sure it isn't a protected function or data |
3889 | symbol for shared library since it may not be local when | |
3890 | used as function address or with copy relocation. We also | |
e3c0e327 | 3891 | need to make sure that a symbol is referenced locally. */ |
0e1862bb | 3892 | if (!bfd_link_executable (info) && h) |
90f487df | 3893 | { |
41bed6dd L |
3894 | if (!h->def_regular) |
3895 | { | |
3896 | const char *v; | |
3897 | ||
3898 | switch (ELF_ST_VISIBILITY (h->other)) | |
3899 | { | |
3900 | case STV_HIDDEN: | |
3901 | v = _("hidden symbol"); | |
3902 | break; | |
3903 | case STV_INTERNAL: | |
3904 | v = _("internal symbol"); | |
3905 | break; | |
3906 | case STV_PROTECTED: | |
3907 | v = _("protected symbol"); | |
3908 | break; | |
3909 | default: | |
3910 | v = _("symbol"); | |
3911 | break; | |
3912 | } | |
3913 | ||
4eca0228 | 3914 | _bfd_error_handler |
695344c0 | 3915 | /* xgettext:c-format */ |
63a5468a AM |
3916 | (_("%B: relocation R_386_GOTOFF against undefined %s" |
3917 | " `%s' can not be used when making a shared object"), | |
41bed6dd L |
3918 | input_bfd, v, h->root.root.string); |
3919 | bfd_set_error (bfd_error_bad_value); | |
3920 | return FALSE; | |
3921 | } | |
d5597ebc | 3922 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
3d949995 L |
3923 | && (h->type == STT_FUNC |
3924 | || h->type == STT_OBJECT) | |
41bed6dd L |
3925 | && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED) |
3926 | { | |
4eca0228 | 3927 | _bfd_error_handler |
695344c0 | 3928 | /* xgettext:c-format */ |
63a5468a AM |
3929 | (_("%B: relocation R_386_GOTOFF against protected %s" |
3930 | " `%s' can not be used when making a shared object"), | |
3d949995 L |
3931 | input_bfd, |
3932 | h->type == STT_FUNC ? "function" : "data", | |
3933 | h->root.root.string); | |
41bed6dd L |
3934 | bfd_set_error (bfd_error_bad_value); |
3935 | return FALSE; | |
3936 | } | |
90f487df L |
3937 | } |
3938 | ||
8c37241b JJ |
3939 | /* Note that sgot is not involved in this |
3940 | calculation. We always want the start of .got.plt. If we | |
3941 | defined _GLOBAL_OFFSET_TABLE_ in a different way, as is | |
252b5132 RH |
3942 | permitted by the ABI, we might have to change this |
3943 | calculation. */ | |
6de2ae4a L |
3944 | relocation -= htab->elf.sgotplt->output_section->vma |
3945 | + htab->elf.sgotplt->output_offset; | |
252b5132 RH |
3946 | break; |
3947 | ||
3948 | case R_386_GOTPC: | |
3949 | /* Use global offset table as symbol value. */ | |
6de2ae4a L |
3950 | relocation = htab->elf.sgotplt->output_section->vma |
3951 | + htab->elf.sgotplt->output_offset; | |
b34976b6 | 3952 | unresolved_reloc = FALSE; |
252b5132 RH |
3953 | break; |
3954 | ||
3955 | case R_386_PLT32: | |
3956 | /* Relocation is to the entry for this symbol in the | |
3957 | procedure linkage table. */ | |
3958 | ||
dd5724d5 | 3959 | /* Resolve a PLT32 reloc against a local symbol directly, |
83be169b | 3960 | without using the procedure linkage table. */ |
252b5132 RH |
3961 | if (h == NULL) |
3962 | break; | |
3963 | ||
dd7e64d4 L |
3964 | if ((h->plt.offset == (bfd_vma) -1 |
3965 | && eh->plt_got.offset == (bfd_vma) -1) | |
6de2ae4a | 3966 | || htab->elf.splt == NULL) |
252b5132 RH |
3967 | { |
3968 | /* We didn't make a PLT entry for this symbol. This | |
83be169b AM |
3969 | happens when statically linking PIC code, or when |
3970 | using -Bsymbolic. */ | |
252b5132 RH |
3971 | break; |
3972 | } | |
3973 | ||
dd7e64d4 L |
3974 | if (h->plt.offset != (bfd_vma) -1) |
3975 | { | |
ee2fdd6f L |
3976 | if (htab->plt_second != NULL) |
3977 | { | |
3978 | resolved_plt = htab->plt_second; | |
3979 | plt_offset = eh->plt_second.offset; | |
3980 | } | |
3981 | else | |
3982 | { | |
3983 | resolved_plt = htab->elf.splt; | |
3984 | plt_offset = h->plt.offset; | |
3985 | } | |
dd7e64d4 L |
3986 | } |
3987 | else | |
3988 | { | |
3989 | resolved_plt = htab->plt_got; | |
3990 | plt_offset = eh->plt_got.offset; | |
3991 | } | |
3992 | ||
3993 | relocation = (resolved_plt->output_section->vma | |
3994 | + resolved_plt->output_offset | |
3995 | + plt_offset); | |
b34976b6 | 3996 | unresolved_reloc = FALSE; |
252b5132 RH |
3997 | break; |
3998 | ||
1788fc08 | 3999 | case R_386_SIZE32: |
1788fc08 L |
4000 | /* Set to symbol size. */ |
4001 | relocation = st_size; | |
4002 | /* Fall through. */ | |
4003 | ||
252b5132 RH |
4004 | case R_386_32: |
4005 | case R_386_PC32: | |
3348747a NS |
4006 | if ((input_section->flags & SEC_ALLOC) == 0 |
4007 | || is_vxworks_tls) | |
ec338859 AM |
4008 | break; |
4009 | ||
aec6b87e L |
4010 | /* Copy dynamic function pointer relocations. Don't generate |
4011 | dynamic relocations against resolved undefined weak symbols | |
4012 | in PIE, except for R_386_PC32. */ | |
0e1862bb | 4013 | if ((bfd_link_pic (info) |
ef5aade5 | 4014 | && (h == NULL |
aec6b87e L |
4015 | || ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
4016 | && (!resolved_to_zero | |
4017 | || r_type == R_386_PC32)) | |
4018 | || h->root.type != bfd_link_hash_undefweak)) | |
1788fc08 | 4019 | && ((r_type != R_386_PC32 && r_type != R_386_SIZE32) |
f6c52c13 | 4020 | || !SYMBOL_CALLS_LOCAL (info, h))) |
a23b6845 | 4021 | || (ELIMINATE_COPY_RELOCS |
0e1862bb | 4022 | && !bfd_link_pic (info) |
12d0ee4a AM |
4023 | && h != NULL |
4024 | && h->dynindx != -1 | |
aec6b87e L |
4025 | && (!h->non_got_ref |
4026 | || eh->func_pointer_refcount > 0 | |
4027 | || (h->root.type == bfd_link_hash_undefweak | |
4028 | && !resolved_to_zero)) | |
bae420ef L |
4029 | && ((h->def_dynamic && !h->def_regular) |
4030 | /* Undefined weak symbol is bound locally when | |
4031 | PIC is false. */ | |
4032 | || h->root.type == bfd_link_hash_undefweak))) | |
252b5132 | 4033 | { |
947216bf | 4034 | Elf_Internal_Rela outrel; |
b34976b6 | 4035 | bfd_boolean skip, relocate; |
0c715baa | 4036 | asection *sreloc; |
252b5132 RH |
4037 | |
4038 | /* When generating a shared object, these relocations | |
4039 | are copied into the output file to be resolved at run | |
4040 | time. */ | |
4041 | ||
b34976b6 AM |
4042 | skip = FALSE; |
4043 | relocate = FALSE; | |
252b5132 | 4044 | |
c629eae0 JJ |
4045 | outrel.r_offset = |
4046 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
4047 | rel->r_offset); | |
4048 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 4049 | skip = TRUE; |
0bb2d96a | 4050 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 4051 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
4052 | outrel.r_offset += (input_section->output_section->vma |
4053 | + input_section->output_offset); | |
4054 | ||
4055 | if (skip) | |
0bb2d96a | 4056 | memset (&outrel, 0, sizeof outrel); |
5a15f56f AM |
4057 | else if (h != NULL |
4058 | && h->dynindx != -1 | |
4059 | && (r_type == R_386_PC32 | |
4e0c91e4 L |
4060 | || !(bfd_link_executable (info) |
4061 | || SYMBOLIC_BIND (info, h)) | |
f5385ebf | 4062 | || !h->def_regular)) |
0bb2d96a | 4063 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
252b5132 RH |
4064 | else |
4065 | { | |
5a15f56f | 4066 | /* This symbol is local, or marked to become local. */ |
b34976b6 | 4067 | relocate = TRUE; |
5a15f56f | 4068 | outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE); |
252b5132 RH |
4069 | } |
4070 | ||
cbe950e9 | 4071 | sreloc = elf_section_data (input_section)->sreloc; |
e7c33416 | 4072 | |
62d78908 L |
4073 | if (sreloc == NULL || sreloc->contents == NULL) |
4074 | { | |
4075 | r = bfd_reloc_notsupported; | |
4076 | goto check_relocation_error; | |
4077 | } | |
0c715baa | 4078 | |
59d6ffb2 | 4079 | elf_append_rel (output_bfd, sreloc, &outrel); |
252b5132 RH |
4080 | |
4081 | /* If this reloc is against an external symbol, we do | |
4082 | not want to fiddle with the addend. Otherwise, we | |
4083 | need to include the symbol value so that it becomes | |
4084 | an addend for the dynamic reloc. */ | |
0f88be7a | 4085 | if (! relocate) |
252b5132 RH |
4086 | continue; |
4087 | } | |
252b5132 RH |
4088 | break; |
4089 | ||
37e55690 | 4090 | case R_386_TLS_IE: |
0e1862bb | 4091 | if (!bfd_link_executable (info)) |
37e55690 | 4092 | { |
947216bf | 4093 | Elf_Internal_Rela outrel; |
37e55690 | 4094 | asection *sreloc; |
37e55690 JJ |
4095 | |
4096 | outrel.r_offset = rel->r_offset | |
4097 | + input_section->output_section->vma | |
4098 | + input_section->output_offset; | |
4099 | outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE); | |
4100 | sreloc = elf_section_data (input_section)->sreloc; | |
4101 | if (sreloc == NULL) | |
4102 | abort (); | |
59d6ffb2 | 4103 | elf_append_rel (output_bfd, sreloc, &outrel); |
37e55690 JJ |
4104 | } |
4105 | /* Fall through */ | |
4106 | ||
13ae64f3 | 4107 | case R_386_TLS_GD: |
67a4f2b7 AO |
4108 | case R_386_TLS_GOTDESC: |
4109 | case R_386_TLS_DESC_CALL: | |
13ae64f3 | 4110 | case R_386_TLS_IE_32: |
37e55690 | 4111 | case R_386_TLS_GOTIE: |
13ae64f3 JJ |
4112 | tls_type = GOT_UNKNOWN; |
4113 | if (h == NULL && local_got_offsets) | |
0afcef53 | 4114 | tls_type = elf_x86_local_got_tls_type (input_bfd) [r_symndx]; |
13ae64f3 | 4115 | else if (h != NULL) |
0afcef53 | 4116 | tls_type = elf_x86_hash_entry(h)->tls_type; |
37e55690 JJ |
4117 | if (tls_type == GOT_TLS_IE) |
4118 | tls_type = GOT_TLS_IE_NEG; | |
142411ca L |
4119 | |
4120 | if (! elf_i386_tls_transition (info, input_bfd, | |
4121 | input_section, contents, | |
4122 | symtab_hdr, sym_hashes, | |
4123 | &r_type, tls_type, rel, | |
bedfd056 | 4124 | relend, h, r_symndx, TRUE)) |
142411ca | 4125 | return FALSE; |
13ae64f3 JJ |
4126 | |
4127 | if (r_type == R_386_TLS_LE_32) | |
4128 | { | |
82e51918 | 4129 | BFD_ASSERT (! unresolved_reloc); |
13ae64f3 JJ |
4130 | if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD) |
4131 | { | |
142411ca | 4132 | unsigned int type; |
13ae64f3 JJ |
4133 | bfd_vma roff; |
4134 | ||
4135 | /* GD->LE transition. */ | |
6eaa7fb5 | 4136 | type = *(contents + rel->r_offset - 2); |
13ae64f3 JJ |
4137 | if (type == 0x04) |
4138 | { | |
6eaa7fb5 L |
4139 | /* Change |
4140 | leal foo@tlsgd(,%ebx,1), %eax | |
4141 | call ___tls_get_addr@PLT | |
4142 | into: | |
4143 | movl %gs:0, %eax | |
4144 | subl $foo@tpoff, %eax | |
13ae64f3 | 4145 | (6 byte form of subl). */ |
142411ca | 4146 | roff = rel->r_offset + 5; |
13ae64f3 JJ |
4147 | } |
4148 | else | |
4149 | { | |
6eaa7fb5 L |
4150 | /* Change |
4151 | leal foo@tlsgd(%ebx), %eax | |
4152 | call ___tls_get_addr@PLT | |
4153 | nop | |
4154 | or | |
4155 | leal foo@tlsgd(%reg), %eax | |
4156 | call *___tls_get_addr@GOT(%reg) | |
4157 | which may be converted to | |
4158 | addr32 call ___tls_get_addr | |
4159 | into: | |
4160 | movl %gs:0, %eax; subl $foo@tpoff, %eax | |
142411ca | 4161 | (6 byte form of subl). */ |
142411ca | 4162 | roff = rel->r_offset + 6; |
13ae64f3 | 4163 | } |
6eaa7fb5 L |
4164 | memcpy (contents + roff - 8, |
4165 | "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12); | |
eb4ff4d6 | 4166 | bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation), |
13ae64f3 | 4167 | contents + roff); |
6eaa7fb5 | 4168 | /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */ |
13ae64f3 | 4169 | rel++; |
60f2e42e | 4170 | wrel++; |
13ae64f3 JJ |
4171 | continue; |
4172 | } | |
67a4f2b7 AO |
4173 | else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC) |
4174 | { | |
4175 | /* GDesc -> LE transition. | |
4176 | It's originally something like: | |
4177 | leal x@tlsdesc(%ebx), %eax | |
4178 | ||
4179 | leal x@ntpoff, %eax | |
4180 | ||
4181 | Registers other than %eax may be set up here. */ | |
4182 | ||
142411ca | 4183 | unsigned int val; |
67a4f2b7 AO |
4184 | bfd_vma roff; |
4185 | ||
67a4f2b7 | 4186 | roff = rel->r_offset; |
67a4f2b7 | 4187 | val = bfd_get_8 (input_bfd, contents + roff - 1); |
67a4f2b7 AO |
4188 | |
4189 | /* Now modify the instruction as appropriate. */ | |
4190 | /* aoliva FIXME: remove the above and xor the byte | |
4191 | below with 0x86. */ | |
4192 | bfd_put_8 (output_bfd, val ^ 0x86, | |
4193 | contents + roff - 1); | |
eb4ff4d6 | 4194 | bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation), |
67a4f2b7 AO |
4195 | contents + roff); |
4196 | continue; | |
4197 | } | |
4198 | else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL) | |
4199 | { | |
4200 | /* GDesc -> LE transition. | |
4201 | It's originally: | |
4202 | call *(%eax) | |
4203 | Turn it into: | |
142411ca | 4204 | xchg %ax,%ax */ |
67a4f2b7 | 4205 | |
67a4f2b7 | 4206 | bfd_vma roff; |
6bbec505 | 4207 | |
67a4f2b7 | 4208 | roff = rel->r_offset; |
10efb593 | 4209 | bfd_put_8 (output_bfd, 0x66, contents + roff); |
67a4f2b7 AO |
4210 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1); |
4211 | continue; | |
4212 | } | |
37e55690 | 4213 | else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_IE) |
13ae64f3 | 4214 | { |
142411ca | 4215 | unsigned int val; |
13ae64f3 JJ |
4216 | |
4217 | /* IE->LE transition: | |
37e55690 JJ |
4218 | Originally it can be one of: |
4219 | movl foo, %eax | |
4220 | movl foo, %reg | |
4221 | addl foo, %reg | |
4222 | We change it into: | |
4223 | movl $foo, %eax | |
4224 | movl $foo, %reg | |
4225 | addl $foo, %reg. */ | |
37e55690 | 4226 | val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1); |
37e55690 JJ |
4227 | if (val == 0xa1) |
4228 | { | |
4229 | /* movl foo, %eax. */ | |
55fd94b0 AM |
4230 | bfd_put_8 (output_bfd, 0xb8, |
4231 | contents + rel->r_offset - 1); | |
37e55690 | 4232 | } |
299bf759 | 4233 | else |
37e55690 | 4234 | { |
142411ca L |
4235 | unsigned int type; |
4236 | ||
55fd94b0 AM |
4237 | type = bfd_get_8 (input_bfd, |
4238 | contents + rel->r_offset - 2); | |
299bf759 | 4239 | switch (type) |
26e41594 | 4240 | { |
299bf759 L |
4241 | case 0x8b: |
4242 | /* movl */ | |
299bf759 L |
4243 | bfd_put_8 (output_bfd, 0xc7, |
4244 | contents + rel->r_offset - 2); | |
4245 | bfd_put_8 (output_bfd, | |
4246 | 0xc0 | ((val >> 3) & 7), | |
4247 | contents + rel->r_offset - 1); | |
4248 | break; | |
4249 | case 0x03: | |
4250 | /* addl */ | |
299bf759 L |
4251 | bfd_put_8 (output_bfd, 0x81, |
4252 | contents + rel->r_offset - 2); | |
4253 | bfd_put_8 (output_bfd, | |
4254 | 0xc0 | ((val >> 3) & 7), | |
4255 | contents + rel->r_offset - 1); | |
4256 | break; | |
4257 | default: | |
4258 | BFD_FAIL (); | |
4259 | break; | |
26e41594 | 4260 | } |
37e55690 | 4261 | } |
eb4ff4d6 | 4262 | bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation), |
37e55690 JJ |
4263 | contents + rel->r_offset); |
4264 | continue; | |
4265 | } | |
4266 | else | |
4267 | { | |
4268 | unsigned int val, type; | |
4269 | ||
4270 | /* {IE_32,GOTIE}->LE transition: | |
4271 | Originally it can be one of: | |
13ae64f3 | 4272 | subl foo(%reg1), %reg2 |
13ae64f3 | 4273 | movl foo(%reg1), %reg2 |
37e55690 | 4274 | addl foo(%reg1), %reg2 |
13ae64f3 JJ |
4275 | We change it into: |
4276 | subl $foo, %reg2 | |
37e55690 JJ |
4277 | movl $foo, %reg2 (6 byte form) |
4278 | addl $foo, %reg2. */ | |
13ae64f3 JJ |
4279 | type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2); |
4280 | val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1); | |
13ae64f3 JJ |
4281 | if (type == 0x8b) |
4282 | { | |
4283 | /* movl */ | |
13ae64f3 JJ |
4284 | bfd_put_8 (output_bfd, 0xc7, |
4285 | contents + rel->r_offset - 2); | |
4286 | bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7), | |
4287 | contents + rel->r_offset - 1); | |
4288 | } | |
4289 | else if (type == 0x2b) | |
4290 | { | |
4291 | /* subl */ | |
13ae64f3 JJ |
4292 | bfd_put_8 (output_bfd, 0x81, |
4293 | contents + rel->r_offset - 2); | |
4294 | bfd_put_8 (output_bfd, 0xe8 | ((val >> 3) & 7), | |
4295 | contents + rel->r_offset - 1); | |
4296 | } | |
37e55690 JJ |
4297 | else if (type == 0x03) |
4298 | { | |
4299 | /* addl */ | |
4300 | bfd_put_8 (output_bfd, 0x81, | |
4301 | contents + rel->r_offset - 2); | |
4302 | bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7), | |
4303 | contents + rel->r_offset - 1); | |
4304 | } | |
13ae64f3 JJ |
4305 | else |
4306 | BFD_FAIL (); | |
37e55690 | 4307 | if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTIE) |
eb4ff4d6 | 4308 | bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation), |
37e55690 JJ |
4309 | contents + rel->r_offset); |
4310 | else | |
eb4ff4d6 | 4311 | bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation), |
37e55690 | 4312 | contents + rel->r_offset); |
13ae64f3 JJ |
4313 | continue; |
4314 | } | |
4315 | } | |
4316 | ||
6de2ae4a | 4317 | if (htab->elf.sgot == NULL) |
13ae64f3 JJ |
4318 | abort (); |
4319 | ||
4320 | if (h != NULL) | |
67a4f2b7 AO |
4321 | { |
4322 | off = h->got.offset; | |
0afcef53 | 4323 | offplt = elf_x86_hash_entry (h)->tlsdesc_got; |
67a4f2b7 | 4324 | } |
13ae64f3 JJ |
4325 | else |
4326 | { | |
4327 | if (local_got_offsets == NULL) | |
4328 | abort (); | |
4329 | ||
4330 | off = local_got_offsets[r_symndx]; | |
67a4f2b7 | 4331 | offplt = local_tlsdesc_gotents[r_symndx]; |
13ae64f3 JJ |
4332 | } |
4333 | ||
4334 | if ((off & 1) != 0) | |
4335 | off &= ~1; | |
26e41594 | 4336 | else |
13ae64f3 | 4337 | { |
947216bf | 4338 | Elf_Internal_Rela outrel; |
91d6fa6a | 4339 | int dr_type; |
67a4f2b7 | 4340 | asection *sreloc; |
13ae64f3 | 4341 | |
6de2ae4a | 4342 | if (htab->elf.srelgot == NULL) |
13ae64f3 JJ |
4343 | abort (); |
4344 | ||
67a4f2b7 AO |
4345 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
4346 | ||
4347 | if (GOT_TLS_GDESC_P (tls_type)) | |
4348 | { | |
59d6ffb2 | 4349 | bfd_byte *loc; |
67a4f2b7 AO |
4350 | outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC); |
4351 | BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8 | |
6de2ae4a L |
4352 | <= htab->elf.sgotplt->size); |
4353 | outrel.r_offset = (htab->elf.sgotplt->output_section->vma | |
4354 | + htab->elf.sgotplt->output_offset | |
67a4f2b7 AO |
4355 | + offplt |
4356 | + htab->sgotplt_jump_table_size); | |
6de2ae4a | 4357 | sreloc = htab->elf.srelplt; |
67a4f2b7 | 4358 | loc = sreloc->contents; |
765e526c | 4359 | loc += (htab->next_tls_desc_index++ |
5ae0bfb6 | 4360 | * sizeof (Elf32_External_Rel)); |
67a4f2b7 | 4361 | BFD_ASSERT (loc + sizeof (Elf32_External_Rel) |
c3b02097 | 4362 | <= sreloc->contents + sreloc->size); |
67a4f2b7 AO |
4363 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); |
4364 | if (indx == 0) | |
4365 | { | |
4366 | BFD_ASSERT (! unresolved_reloc); | |
4367 | bfd_put_32 (output_bfd, | |
0afcef53 | 4368 | relocation - _bfd_x86_elf_dtpoff_base (info), |
6de2ae4a | 4369 | htab->elf.sgotplt->contents + offplt |
67a4f2b7 AO |
4370 | + htab->sgotplt_jump_table_size + 4); |
4371 | } | |
4372 | else | |
4373 | { | |
4374 | bfd_put_32 (output_bfd, 0, | |
6de2ae4a | 4375 | htab->elf.sgotplt->contents + offplt |
67a4f2b7 AO |
4376 | + htab->sgotplt_jump_table_size + 4); |
4377 | } | |
4378 | } | |
4379 | ||
6de2ae4a | 4380 | sreloc = htab->elf.srelgot; |
67a4f2b7 | 4381 | |
6de2ae4a L |
4382 | outrel.r_offset = (htab->elf.sgot->output_section->vma |
4383 | + htab->elf.sgot->output_offset + off); | |
13ae64f3 | 4384 | |
67a4f2b7 | 4385 | if (GOT_TLS_GD_P (tls_type)) |
13ae64f3 | 4386 | dr_type = R_386_TLS_DTPMOD32; |
67a4f2b7 AO |
4387 | else if (GOT_TLS_GDESC_P (tls_type)) |
4388 | goto dr_done; | |
37e55690 JJ |
4389 | else if (tls_type == GOT_TLS_IE_POS) |
4390 | dr_type = R_386_TLS_TPOFF; | |
13ae64f3 JJ |
4391 | else |
4392 | dr_type = R_386_TLS_TPOFF32; | |
67a4f2b7 | 4393 | |
37e55690 | 4394 | if (dr_type == R_386_TLS_TPOFF && indx == 0) |
eb4ff4d6 | 4395 | bfd_put_32 (output_bfd, |
0afcef53 | 4396 | relocation - _bfd_x86_elf_dtpoff_base (info), |
6de2ae4a | 4397 | htab->elf.sgot->contents + off); |
37e55690 | 4398 | else if (dr_type == R_386_TLS_TPOFF32 && indx == 0) |
23209a78 | 4399 | bfd_put_32 (output_bfd, |
0afcef53 | 4400 | _bfd_x86_elf_dtpoff_base (info) - relocation, |
6de2ae4a | 4401 | htab->elf.sgot->contents + off); |
67a4f2b7 | 4402 | else if (dr_type != R_386_TLS_DESC) |
c366c25e | 4403 | bfd_put_32 (output_bfd, 0, |
6de2ae4a | 4404 | htab->elf.sgot->contents + off); |
13ae64f3 | 4405 | outrel.r_info = ELF32_R_INFO (indx, dr_type); |
67a4f2b7 | 4406 | |
59d6ffb2 | 4407 | elf_append_rel (output_bfd, sreloc, &outrel); |
13ae64f3 | 4408 | |
67a4f2b7 | 4409 | if (GOT_TLS_GD_P (tls_type)) |
13ae64f3 JJ |
4410 | { |
4411 | if (indx == 0) | |
4412 | { | |
82e51918 | 4413 | BFD_ASSERT (! unresolved_reloc); |
13ae64f3 | 4414 | bfd_put_32 (output_bfd, |
0afcef53 | 4415 | relocation - _bfd_x86_elf_dtpoff_base (info), |
6de2ae4a | 4416 | htab->elf.sgot->contents + off + 4); |
13ae64f3 JJ |
4417 | } |
4418 | else | |
4419 | { | |
4420 | bfd_put_32 (output_bfd, 0, | |
6de2ae4a | 4421 | htab->elf.sgot->contents + off + 4); |
13ae64f3 JJ |
4422 | outrel.r_info = ELF32_R_INFO (indx, |
4423 | R_386_TLS_DTPOFF32); | |
4424 | outrel.r_offset += 4; | |
59d6ffb2 | 4425 | elf_append_rel (output_bfd, sreloc, &outrel); |
13ae64f3 JJ |
4426 | } |
4427 | } | |
37e55690 JJ |
4428 | else if (tls_type == GOT_TLS_IE_BOTH) |
4429 | { | |
4430 | bfd_put_32 (output_bfd, | |
eb4ff4d6 | 4431 | (indx == 0 |
0afcef53 | 4432 | ? relocation - _bfd_x86_elf_dtpoff_base (info) |
eb4ff4d6 | 4433 | : 0), |
6de2ae4a | 4434 | htab->elf.sgot->contents + off + 4); |
37e55690 JJ |
4435 | outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF); |
4436 | outrel.r_offset += 4; | |
59d6ffb2 | 4437 | elf_append_rel (output_bfd, sreloc, &outrel); |
37e55690 | 4438 | } |
13ae64f3 | 4439 | |
67a4f2b7 | 4440 | dr_done: |
13ae64f3 JJ |
4441 | if (h != NULL) |
4442 | h->got.offset |= 1; | |
4443 | else | |
4444 | local_got_offsets[r_symndx] |= 1; | |
4445 | } | |
4446 | ||
67a4f2b7 AO |
4447 | if (off >= (bfd_vma) -2 |
4448 | && ! GOT_TLS_GDESC_P (tls_type)) | |
13ae64f3 | 4449 | abort (); |
67a4f2b7 AO |
4450 | if (r_type == R_386_TLS_GOTDESC |
4451 | || r_type == R_386_TLS_DESC_CALL) | |
4452 | { | |
4453 | relocation = htab->sgotplt_jump_table_size + offplt; | |
4454 | unresolved_reloc = FALSE; | |
4455 | } | |
4456 | else if (r_type == ELF32_R_TYPE (rel->r_info)) | |
13ae64f3 | 4457 | { |
6de2ae4a L |
4458 | bfd_vma g_o_t = htab->elf.sgotplt->output_section->vma |
4459 | + htab->elf.sgotplt->output_offset; | |
4460 | relocation = htab->elf.sgot->output_section->vma | |
4461 | + htab->elf.sgot->output_offset + off - g_o_t; | |
37e55690 JJ |
4462 | if ((r_type == R_386_TLS_IE || r_type == R_386_TLS_GOTIE) |
4463 | && tls_type == GOT_TLS_IE_BOTH) | |
4464 | relocation += 4; | |
4465 | if (r_type == R_386_TLS_IE) | |
8c37241b | 4466 | relocation += g_o_t; |
b34976b6 | 4467 | unresolved_reloc = FALSE; |
13ae64f3 | 4468 | } |
67a4f2b7 | 4469 | else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD) |
13ae64f3 JJ |
4470 | { |
4471 | unsigned int val, type; | |
4472 | bfd_vma roff; | |
4473 | ||
4474 | /* GD->IE transition. */ | |
6eaa7fb5 L |
4475 | type = *(contents + rel->r_offset - 2); |
4476 | val = *(contents + rel->r_offset - 1); | |
13ae64f3 JJ |
4477 | if (type == 0x04) |
4478 | { | |
6eaa7fb5 L |
4479 | /* Change |
4480 | leal foo@tlsgd(,%ebx,1), %eax | |
4481 | call ___tls_get_addr@PLT | |
4482 | into: | |
4483 | movl %gs:0, %eax | |
4484 | subl $foo@gottpoff(%ebx), %eax. */ | |
13ae64f3 | 4485 | val >>= 3; |
142411ca | 4486 | roff = rel->r_offset - 3; |
13ae64f3 JJ |
4487 | } |
4488 | else | |
4489 | { | |
6eaa7fb5 L |
4490 | /* Change |
4491 | leal foo@tlsgd(%ebx), %eax | |
4492 | call ___tls_get_addr@PLT | |
4493 | nop | |
4494 | or | |
4495 | leal foo@tlsgd(%reg), %eax | |
4496 | call *___tls_get_addr@GOT(%reg) | |
4497 | which may be converted to | |
4498 | addr32 call ___tls_get_addr | |
4499 | into: | |
4500 | movl %gs:0, %eax; | |
4501 | subl $foo@gottpoff(%reg), %eax. */ | |
13ae64f3 JJ |
4502 | roff = rel->r_offset - 2; |
4503 | } | |
4504 | memcpy (contents + roff, | |
4505 | "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12); | |
4506 | contents[roff + 7] = 0x80 | (val & 7); | |
37e55690 JJ |
4507 | /* If foo is used only with foo@gotntpoff(%reg) and |
4508 | foo@indntpoff, but not with foo@gottpoff(%reg), change | |
4509 | subl $foo@gottpoff(%reg), %eax | |
4510 | into: | |
4511 | addl $foo@gotntpoff(%reg), %eax. */ | |
ebcfb3c0 JJ |
4512 | if (tls_type == GOT_TLS_IE_POS) |
4513 | contents[roff + 6] = 0x03; | |
8c37241b | 4514 | bfd_put_32 (output_bfd, |
6de2ae4a L |
4515 | htab->elf.sgot->output_section->vma |
4516 | + htab->elf.sgot->output_offset + off | |
4517 | - htab->elf.sgotplt->output_section->vma | |
4518 | - htab->elf.sgotplt->output_offset, | |
13ae64f3 | 4519 | contents + roff + 8); |
6eaa7fb5 | 4520 | /* Skip R_386_PLT32 and R_386_GOT32X. */ |
13ae64f3 | 4521 | rel++; |
60f2e42e | 4522 | wrel++; |
13ae64f3 JJ |
4523 | continue; |
4524 | } | |
67a4f2b7 AO |
4525 | else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GOTDESC) |
4526 | { | |
4527 | /* GDesc -> IE transition. | |
4528 | It's originally something like: | |
4529 | leal x@tlsdesc(%ebx), %eax | |
4530 | ||
4531 | Change it to: | |
142411ca | 4532 | movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax |
67a4f2b7 AO |
4533 | or: |
4534 | movl x@gottpoff(%ebx), %eax # before negl %eax | |
4535 | ||
4536 | Registers other than %eax may be set up here. */ | |
4537 | ||
67a4f2b7 AO |
4538 | bfd_vma roff; |
4539 | ||
4540 | /* First, make sure it's a leal adding ebx to a 32-bit | |
4541 | offset into any register, although it's probably | |
4542 | almost always going to be eax. */ | |
4543 | roff = rel->r_offset; | |
67a4f2b7 AO |
4544 | |
4545 | /* Now modify the instruction as appropriate. */ | |
4546 | /* To turn a leal into a movl in the form we use it, it | |
4547 | suffices to change the first byte from 0x8d to 0x8b. | |
4548 | aoliva FIXME: should we decide to keep the leal, all | |
4549 | we have to do is remove the statement below, and | |
4550 | adjust the relaxation of R_386_TLS_DESC_CALL. */ | |
4551 | bfd_put_8 (output_bfd, 0x8b, contents + roff - 2); | |
4552 | ||
4553 | if (tls_type == GOT_TLS_IE_BOTH) | |
4554 | off += 4; | |
4555 | ||
4556 | bfd_put_32 (output_bfd, | |
6de2ae4a L |
4557 | htab->elf.sgot->output_section->vma |
4558 | + htab->elf.sgot->output_offset + off | |
4559 | - htab->elf.sgotplt->output_section->vma | |
4560 | - htab->elf.sgotplt->output_offset, | |
67a4f2b7 AO |
4561 | contents + roff); |
4562 | continue; | |
4563 | } | |
4564 | else if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_DESC_CALL) | |
4565 | { | |
4566 | /* GDesc -> IE transition. | |
4567 | It's originally: | |
4568 | call *(%eax) | |
4569 | ||
4570 | Change it to: | |
142411ca | 4571 | xchg %ax,%ax |
67a4f2b7 AO |
4572 | or |
4573 | negl %eax | |
4574 | depending on how we transformed the TLS_GOTDESC above. | |
4575 | */ | |
4576 | ||
67a4f2b7 AO |
4577 | bfd_vma roff; |
4578 | ||
67a4f2b7 | 4579 | roff = rel->r_offset; |
67a4f2b7 AO |
4580 | |
4581 | /* Now modify the instruction as appropriate. */ | |
4582 | if (tls_type != GOT_TLS_IE_NEG) | |
4583 | { | |
10efb593 L |
4584 | /* xchg %ax,%ax */ |
4585 | bfd_put_8 (output_bfd, 0x66, contents + roff); | |
67a4f2b7 AO |
4586 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1); |
4587 | } | |
4588 | else | |
4589 | { | |
4590 | /* negl %eax */ | |
4591 | bfd_put_8 (output_bfd, 0xf7, contents + roff); | |
4592 | bfd_put_8 (output_bfd, 0xd8, contents + roff + 1); | |
4593 | } | |
4594 | ||
4595 | continue; | |
4596 | } | |
4597 | else | |
4598 | BFD_ASSERT (FALSE); | |
13ae64f3 JJ |
4599 | break; |
4600 | ||
4601 | case R_386_TLS_LDM: | |
142411ca L |
4602 | if (! elf_i386_tls_transition (info, input_bfd, |
4603 | input_section, contents, | |
4604 | symtab_hdr, sym_hashes, | |
4605 | &r_type, GOT_UNKNOWN, rel, | |
bedfd056 | 4606 | relend, h, r_symndx, TRUE)) |
142411ca | 4607 | return FALSE; |
13ae64f3 | 4608 | |
142411ca L |
4609 | if (r_type != R_386_TLS_LDM) |
4610 | { | |
6eaa7fb5 L |
4611 | /* LD->LE transition. Change |
4612 | leal foo@tlsldm(%ebx) %eax | |
4613 | call ___tls_get_addr@PLT | |
4614 | into: | |
4615 | movl %gs:0, %eax | |
4616 | nop | |
4617 | leal 0(%esi,1), %esi | |
4618 | or change | |
4619 | leal foo@tlsldm(%reg) %eax | |
4620 | call *___tls_get_addr@GOT(%reg) | |
4621 | which may be converted to | |
4622 | addr32 call ___tls_get_addr | |
4623 | into: | |
4624 | movl %gs:0, %eax | |
4625 | leal 0(%esi), %esi */ | |
142411ca | 4626 | BFD_ASSERT (r_type == R_386_TLS_LE_32); |
6eaa7fb5 L |
4627 | if (*(contents + rel->r_offset + 4) == 0xff |
4628 | || *(contents + rel->r_offset + 4) == 0x67) | |
4629 | memcpy (contents + rel->r_offset - 2, | |
4630 | "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12); | |
4631 | else | |
4632 | memcpy (contents + rel->r_offset - 2, | |
4633 | "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11); | |
a3fadc9a | 4634 | /* Skip R_386_PC32/R_386_PLT32. */ |
13ae64f3 | 4635 | rel++; |
60f2e42e | 4636 | wrel++; |
13ae64f3 JJ |
4637 | continue; |
4638 | } | |
4639 | ||
6de2ae4a | 4640 | if (htab->elf.sgot == NULL) |
13ae64f3 JJ |
4641 | abort (); |
4642 | ||
0afcef53 | 4643 | off = htab->tls_ld_or_ldm_got.offset; |
13ae64f3 JJ |
4644 | if (off & 1) |
4645 | off &= ~1; | |
4646 | else | |
4647 | { | |
947216bf | 4648 | Elf_Internal_Rela outrel; |
13ae64f3 | 4649 | |
6de2ae4a | 4650 | if (htab->elf.srelgot == NULL) |
13ae64f3 JJ |
4651 | abort (); |
4652 | ||
6de2ae4a L |
4653 | outrel.r_offset = (htab->elf.sgot->output_section->vma |
4654 | + htab->elf.sgot->output_offset + off); | |
13ae64f3 JJ |
4655 | |
4656 | bfd_put_32 (output_bfd, 0, | |
6de2ae4a | 4657 | htab->elf.sgot->contents + off); |
13ae64f3 | 4658 | bfd_put_32 (output_bfd, 0, |
6de2ae4a | 4659 | htab->elf.sgot->contents + off + 4); |
13ae64f3 | 4660 | outrel.r_info = ELF32_R_INFO (0, R_386_TLS_DTPMOD32); |
59d6ffb2 | 4661 | elf_append_rel (output_bfd, htab->elf.srelgot, &outrel); |
0afcef53 | 4662 | htab->tls_ld_or_ldm_got.offset |= 1; |
13ae64f3 | 4663 | } |
6de2ae4a L |
4664 | relocation = htab->elf.sgot->output_section->vma |
4665 | + htab->elf.sgot->output_offset + off | |
4666 | - htab->elf.sgotplt->output_section->vma | |
4667 | - htab->elf.sgotplt->output_offset; | |
b34976b6 | 4668 | unresolved_reloc = FALSE; |
13ae64f3 JJ |
4669 | break; |
4670 | ||
4671 | case R_386_TLS_LDO_32: | |
0e1862bb L |
4672 | if (!bfd_link_executable (info) |
4673 | || (input_section->flags & SEC_CODE) == 0) | |
0afcef53 | 4674 | relocation -= _bfd_x86_elf_dtpoff_base (info); |
13ae64f3 JJ |
4675 | else |
4676 | /* When converting LDO to LE, we must negate. */ | |
eb4ff4d6 | 4677 | relocation = -elf_i386_tpoff (info, relocation); |
13ae64f3 JJ |
4678 | break; |
4679 | ||
4680 | case R_386_TLS_LE_32: | |
13ae64f3 | 4681 | case R_386_TLS_LE: |
0e1862bb | 4682 | if (!bfd_link_executable (info)) |
37e55690 | 4683 | { |
947216bf | 4684 | Elf_Internal_Rela outrel; |
37e55690 | 4685 | asection *sreloc; |
37e55690 JJ |
4686 | |
4687 | outrel.r_offset = rel->r_offset | |
4688 | + input_section->output_section->vma | |
4689 | + input_section->output_offset; | |
4690 | if (h != NULL && h->dynindx != -1) | |
4691 | indx = h->dynindx; | |
4692 | else | |
4693 | indx = 0; | |
4694 | if (r_type == R_386_TLS_LE_32) | |
4695 | outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF32); | |
4696 | else | |
4697 | outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF); | |
4698 | sreloc = elf_section_data (input_section)->sreloc; | |
4699 | if (sreloc == NULL) | |
4700 | abort (); | |
59d6ffb2 | 4701 | elf_append_rel (output_bfd, sreloc, &outrel); |
37e55690 JJ |
4702 | if (indx) |
4703 | continue; | |
4704 | else if (r_type == R_386_TLS_LE_32) | |
0afcef53 | 4705 | relocation = _bfd_x86_elf_dtpoff_base (info) - relocation; |
37e55690 | 4706 | else |
0afcef53 | 4707 | relocation -= _bfd_x86_elf_dtpoff_base (info); |
37e55690 JJ |
4708 | } |
4709 | else if (r_type == R_386_TLS_LE_32) | |
eb4ff4d6 | 4710 | relocation = elf_i386_tpoff (info, relocation); |
37e55690 | 4711 | else |
eb4ff4d6 | 4712 | relocation = -elf_i386_tpoff (info, relocation); |
13ae64f3 JJ |
4713 | break; |
4714 | ||
252b5132 RH |
4715 | default: |
4716 | break; | |
4717 | } | |
4718 | ||
239e1f3a AM |
4719 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
4720 | because such sections are not SEC_ALLOC and thus ld.so will | |
4721 | not process them. */ | |
8c694914 | 4722 | if (unresolved_reloc |
239e1f3a | 4723 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
1d5316ab AM |
4724 | && h->def_dynamic) |
4725 | && _bfd_elf_section_offset (output_bfd, info, input_section, | |
4726 | rel->r_offset) != (bfd_vma) -1) | |
6a30718d | 4727 | { |
4eca0228 | 4728 | _bfd_error_handler |
695344c0 | 4729 | /* xgettext:c-format */ |
d42c267e | 4730 | (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"), |
d003868e AM |
4731 | input_bfd, |
4732 | input_section, | |
d42c267e | 4733 | rel->r_offset, |
843fe662 | 4734 | howto->name, |
6a30718d | 4735 | h->root.root.string); |
b34976b6 | 4736 | return FALSE; |
6a30718d | 4737 | } |
83be169b | 4738 | |
cbe950e9 | 4739 | do_relocation: |
252b5132 RH |
4740 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
4741 | contents, rel->r_offset, | |
55fd94b0 | 4742 | relocation, 0); |
252b5132 | 4743 | |
62d78908 | 4744 | check_relocation_error: |
cf5c0c5b | 4745 | if (r != bfd_reloc_ok) |
252b5132 | 4746 | { |
cf5c0c5b | 4747 | const char *name; |
ffb2e45b | 4748 | |
cf5c0c5b AM |
4749 | if (h != NULL) |
4750 | name = h->root.root.string; | |
4751 | else | |
4752 | { | |
4753 | name = bfd_elf_string_from_elf_section (input_bfd, | |
4754 | symtab_hdr->sh_link, | |
4755 | sym->st_name); | |
4756 | if (name == NULL) | |
b34976b6 | 4757 | return FALSE; |
cf5c0c5b AM |
4758 | if (*name == '\0') |
4759 | name = bfd_section_name (input_bfd, sec); | |
4760 | } | |
ffb2e45b | 4761 | |
cf5c0c5b | 4762 | if (r == bfd_reloc_overflow) |
1a72702b AM |
4763 | (*info->callbacks->reloc_overflow) |
4764 | (info, (h ? &h->root : NULL), name, howto->name, | |
4765 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); | |
cf5c0c5b AM |
4766 | else |
4767 | { | |
4eca0228 | 4768 | _bfd_error_handler |
695344c0 | 4769 | /* xgettext:c-format */ |
d42c267e | 4770 | (_("%B(%A+%#Lx): reloc against `%s': error %d"), |
d003868e | 4771 | input_bfd, input_section, |
d42c267e | 4772 | rel->r_offset, name, (int) r); |
b34976b6 | 4773 | return FALSE; |
cf5c0c5b | 4774 | } |
252b5132 | 4775 | } |
60f2e42e L |
4776 | |
4777 | if (wrel != rel) | |
4778 | *wrel = *rel; | |
4779 | } | |
4780 | ||
4781 | if (wrel != rel) | |
4782 | { | |
4783 | Elf_Internal_Shdr *rel_hdr; | |
4784 | size_t deleted = rel - wrel; | |
4785 | ||
4786 | rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section); | |
4787 | rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted; | |
4788 | if (rel_hdr->sh_size == 0) | |
4789 | { | |
4790 | /* It is too late to remove an empty reloc section. Leave | |
4791 | one NONE reloc. | |
4792 | ??? What is wrong with an empty section??? */ | |
4793 | rel_hdr->sh_size = rel_hdr->sh_entsize; | |
4794 | deleted -= 1; | |
4795 | } | |
4796 | rel_hdr = _bfd_elf_single_rel_hdr (input_section); | |
4797 | rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted; | |
4798 | input_section->reloc_count -= deleted; | |
252b5132 RH |
4799 | } |
4800 | ||
b34976b6 | 4801 | return TRUE; |
252b5132 RH |
4802 | } |
4803 | ||
4804 | /* Finish up dynamic symbol handling. We set the contents of various | |
4805 | dynamic sections here. */ | |
4806 | ||
b34976b6 | 4807 | static bfd_boolean |
55fd94b0 AM |
4808 | elf_i386_finish_dynamic_symbol (bfd *output_bfd, |
4809 | struct bfd_link_info *info, | |
4810 | struct elf_link_hash_entry *h, | |
4811 | Elf_Internal_Sym *sym) | |
252b5132 | 4812 | { |
0afcef53 | 4813 | struct elf_x86_link_hash_table *htab; |
25e762b9 RM |
4814 | unsigned plt_entry_size; |
4815 | const struct elf_i386_backend_data *abed; | |
0afcef53 | 4816 | struct elf_x86_link_hash_entry *eh; |
aec6b87e | 4817 | bfd_boolean local_undefweak; |
ee2fdd6f | 4818 | bfd_boolean use_plt_second; |
252b5132 | 4819 | |
0afcef53 | 4820 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 NC |
4821 | if (htab == NULL) |
4822 | return FALSE; | |
252b5132 | 4823 | |
25e762b9 | 4824 | abed = get_elf_i386_backend_data (output_bfd); |
765e526c | 4825 | plt_entry_size = htab->plt.plt_entry_size; |
25e762b9 | 4826 | |
ee2fdd6f L |
4827 | /* Use the second PLT section only if there is .plt section. */ |
4828 | use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL; | |
4829 | ||
0afcef53 | 4830 | eh = (struct elf_x86_link_hash_entry *) h; |
e133d005 L |
4831 | if (eh->no_finish_dynamic_symbol) |
4832 | abort (); | |
dd7e64d4 | 4833 | |
aec6b87e L |
4834 | /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for |
4835 | resolved undefined weak symbols in executable so that their | |
4836 | references have value 0 at run-time. */ | |
0afcef53 | 4837 | local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, I386_ELF_DATA, |
e62b9723 L |
4838 | eh->has_got_reloc, |
4839 | eh); | |
aec6b87e | 4840 | |
252b5132 RH |
4841 | if (h->plt.offset != (bfd_vma) -1) |
4842 | { | |
ee2fdd6f | 4843 | bfd_vma plt_index, plt_offset; |
252b5132 | 4844 | bfd_vma got_offset; |
947216bf AM |
4845 | Elf_Internal_Rela rel; |
4846 | bfd_byte *loc; | |
ee2fdd6f | 4847 | asection *plt, *resolved_plt, *gotplt, *relplt; |
cbe950e9 L |
4848 | |
4849 | /* When building a static executable, use .iplt, .igot.plt and | |
4850 | .rel.iplt sections for STT_GNU_IFUNC symbols. */ | |
6de2ae4a | 4851 | if (htab->elf.splt != NULL) |
cbe950e9 | 4852 | { |
6de2ae4a L |
4853 | plt = htab->elf.splt; |
4854 | gotplt = htab->elf.sgotplt; | |
4855 | relplt = htab->elf.srelplt; | |
cbe950e9 L |
4856 | } |
4857 | else | |
4858 | { | |
6de2ae4a L |
4859 | plt = htab->elf.iplt; |
4860 | gotplt = htab->elf.igotplt; | |
4861 | relplt = htab->elf.irelplt; | |
cbe950e9 | 4862 | } |
252b5132 RH |
4863 | |
4864 | /* This symbol has an entry in the procedure linkage table. Set | |
4865 | it up. */ | |
4866 | ||
cbe950e9 | 4867 | if ((h->dynindx == -1 |
aec6b87e | 4868 | && !local_undefweak |
0e1862bb | 4869 | && !((h->forced_local || bfd_link_executable (info)) |
cbe950e9 L |
4870 | && h->def_regular |
4871 | && h->type == STT_GNU_IFUNC)) | |
4872 | || plt == NULL | |
4873 | || gotplt == NULL | |
4874 | || relplt == NULL) | |
cec7f46a | 4875 | abort (); |
252b5132 RH |
4876 | |
4877 | /* Get the index in the procedure linkage table which | |
4878 | corresponds to this symbol. This is the index of this symbol | |
4879 | in all the symbols for which we are making plt entries. The | |
cbe950e9 | 4880 | first entry in the procedure linkage table is reserved. |
252b5132 | 4881 | |
cbe950e9 | 4882 | Get the offset into the .got table of the entry that |
252b5132 | 4883 | corresponds to this function. Each .got entry is 4 bytes. |
cbe950e9 | 4884 | The first three are reserved. |
6bbec505 | 4885 | |
cbe950e9 L |
4886 | For static executables, we don't reserve anything. */ |
4887 | ||
6de2ae4a | 4888 | if (plt == htab->elf.splt) |
cbe950e9 | 4889 | { |
f604c2a2 | 4890 | got_offset = (h->plt.offset / plt_entry_size |
765e526c | 4891 | - htab->plt.has_plt0); |
e1f98742 | 4892 | got_offset = (got_offset + 3) * 4; |
cbe950e9 L |
4893 | } |
4894 | else | |
4895 | { | |
e1f98742 L |
4896 | got_offset = h->plt.offset / plt_entry_size; |
4897 | got_offset = got_offset * 4; | |
cbe950e9 | 4898 | } |
252b5132 | 4899 | |
f604c2a2 L |
4900 | /* Fill in the entry in the procedure linkage table and update |
4901 | the first slot. */ | |
765e526c | 4902 | memcpy (plt->contents + h->plt.offset, htab->plt.plt_entry, |
f604c2a2 | 4903 | plt_entry_size); |
ee2fdd6f L |
4904 | |
4905 | if (use_plt_second) | |
4906 | { | |
4907 | const bfd_byte *plt_entry; | |
4908 | if (bfd_link_pic (info)) | |
765e526c | 4909 | plt_entry = htab->non_lazy_plt->pic_plt_entry; |
ee2fdd6f | 4910 | else |
765e526c | 4911 | plt_entry = htab->non_lazy_plt->plt_entry; |
ee2fdd6f | 4912 | memcpy (htab->plt_second->contents + eh->plt_second.offset, |
765e526c | 4913 | plt_entry, htab->non_lazy_plt->plt_entry_size); |
ee2fdd6f L |
4914 | |
4915 | resolved_plt = htab->plt_second; | |
4916 | plt_offset = eh->plt_second.offset; | |
4917 | } | |
4918 | else | |
4919 | { | |
4920 | resolved_plt = plt; | |
4921 | plt_offset = h->plt.offset; | |
4922 | } | |
4923 | ||
0e1862bb | 4924 | if (! bfd_link_pic (info)) |
252b5132 | 4925 | { |
252b5132 | 4926 | bfd_put_32 (output_bfd, |
cbe950e9 L |
4927 | (gotplt->output_section->vma |
4928 | + gotplt->output_offset | |
252b5132 | 4929 | + got_offset), |
ee2fdd6f | 4930 | resolved_plt->contents + plt_offset |
765e526c | 4931 | + htab->plt.plt_got_offset); |
eac338cf | 4932 | |
f604c2a2 | 4933 | if (abed->os == is_vxworks) |
eac338cf PB |
4934 | { |
4935 | int s, k, reloc_index; | |
4936 | ||
4937 | /* Create the R_386_32 relocation referencing the GOT | |
4938 | for this PLT entry. */ | |
4939 | ||
4940 | /* S: Current slot number (zero-based). */ | |
765e526c L |
4941 | s = ((h->plt.offset - htab->plt.plt_entry_size) |
4942 | / htab->plt.plt_entry_size); | |
eac338cf | 4943 | /* K: Number of relocations for PLTResolve. */ |
0e1862bb | 4944 | if (bfd_link_pic (info)) |
eac338cf PB |
4945 | k = PLTRESOLVE_RELOCS_SHLIB; |
4946 | else | |
4947 | k = PLTRESOLVE_RELOCS; | |
4948 | /* Skip the PLTresolve relocations, and the relocations for | |
4949 | the other PLT slots. */ | |
4950 | reloc_index = k + s * PLT_NON_JUMP_SLOT_RELOCS; | |
765e526c | 4951 | loc = (htab->srelplt2->contents + reloc_index |
eac338cf PB |
4952 | * sizeof (Elf32_External_Rel)); |
4953 | ||
ee2fdd6f L |
4954 | rel.r_offset = (plt->output_section->vma |
4955 | + plt->output_offset | |
eac338cf | 4956 | + h->plt.offset + 2), |
7325306f | 4957 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32); |
eac338cf PB |
4958 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
4959 | ||
4960 | /* Create the R_386_32 relocation referencing the beginning of | |
4961 | the PLT for this GOT entry. */ | |
6de2ae4a L |
4962 | rel.r_offset = (htab->elf.sgotplt->output_section->vma |
4963 | + htab->elf.sgotplt->output_offset | |
eac338cf | 4964 | + got_offset); |
7325306f | 4965 | rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32); |
eac338cf | 4966 | bfd_elf32_swap_reloc_out (output_bfd, &rel, |
13ca3149 | 4967 | loc + sizeof (Elf32_External_Rel)); |
eac338cf | 4968 | } |
252b5132 RH |
4969 | } |
4970 | else | |
4971 | { | |
252b5132 | 4972 | bfd_put_32 (output_bfd, got_offset, |
ee2fdd6f | 4973 | resolved_plt->contents + plt_offset |
765e526c | 4974 | + htab->plt.plt_got_offset); |
252b5132 RH |
4975 | } |
4976 | ||
aec6b87e L |
4977 | /* Fill in the entry in the global offset table. Leave the entry |
4978 | as zero for undefined weak symbol in PIE. No PLT relocation | |
4979 | against undefined weak symbol in PIE. */ | |
4980 | if (!local_undefweak) | |
cbe950e9 | 4981 | { |
765e526c | 4982 | if (htab->plt.has_plt0) |
f604c2a2 L |
4983 | bfd_put_32 (output_bfd, |
4984 | (plt->output_section->vma | |
4985 | + plt->output_offset | |
4986 | + h->plt.offset | |
765e526c | 4987 | + htab->lazy_plt->plt_lazy_offset), |
f604c2a2 | 4988 | gotplt->contents + got_offset); |
252b5132 | 4989 | |
aec6b87e L |
4990 | /* Fill in the entry in the .rel.plt section. */ |
4991 | rel.r_offset = (gotplt->output_section->vma | |
4992 | + gotplt->output_offset | |
4993 | + got_offset); | |
4994 | if (h->dynindx == -1 | |
4995 | || ((bfd_link_executable (info) | |
4996 | || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
4997 | && h->def_regular | |
4998 | && h->type == STT_GNU_IFUNC)) | |
4999 | { | |
6322e5c5 L |
5000 | info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"), |
5001 | h->root.root.string, | |
5002 | h->root.u.def.section->owner); | |
5003 | ||
aec6b87e L |
5004 | /* If an STT_GNU_IFUNC symbol is locally defined, generate |
5005 | R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend | |
5006 | in the .got.plt section. */ | |
5007 | bfd_put_32 (output_bfd, | |
5008 | (h->root.u.def.value | |
5009 | + h->root.u.def.section->output_section->vma | |
5010 | + h->root.u.def.section->output_offset), | |
5011 | gotplt->contents + got_offset); | |
5012 | rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE); | |
5013 | /* R_386_IRELATIVE comes last. */ | |
5014 | plt_index = htab->next_irelative_index--; | |
5015 | } | |
5016 | else | |
5017 | { | |
5018 | rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT); | |
5019 | plt_index = htab->next_jump_slot_index++; | |
5020 | } | |
5021 | ||
5022 | loc = relplt->contents + plt_index * sizeof (Elf32_External_Rel); | |
5023 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); | |
5024 | ||
f604c2a2 L |
5025 | /* Don't fill the second and third slots in PLT entry for |
5026 | static executables nor without PLT0. */ | |
765e526c | 5027 | if (plt == htab->elf.splt && htab->plt.has_plt0) |
aec6b87e L |
5028 | { |
5029 | bfd_put_32 (output_bfd, | |
5030 | plt_index * sizeof (Elf32_External_Rel), | |
5031 | plt->contents + h->plt.offset | |
765e526c | 5032 | + htab->lazy_plt->plt_reloc_offset); |
f604c2a2 L |
5033 | bfd_put_32 (output_bfd, |
5034 | - (h->plt.offset | |
765e526c | 5035 | + htab->lazy_plt->plt_plt_offset + 4), |
f604c2a2 | 5036 | (plt->contents + h->plt.offset |
765e526c | 5037 | + htab->lazy_plt->plt_plt_offset)); |
aec6b87e | 5038 | } |
e1f98742 | 5039 | } |
dd7e64d4 L |
5040 | } |
5041 | else if (eh->plt_got.offset != (bfd_vma) -1) | |
5042 | { | |
5043 | bfd_vma got_offset, plt_offset; | |
5044 | asection *plt, *got, *gotplt; | |
5045 | const bfd_byte *got_plt_entry; | |
5046 | ||
dd7e64d4 L |
5047 | /* Set the entry in the GOT procedure linkage table. */ |
5048 | plt = htab->plt_got; | |
5049 | got = htab->elf.sgot; | |
5050 | gotplt = htab->elf.sgotplt; | |
5051 | got_offset = h->got.offset; | |
5052 | ||
5053 | if (got_offset == (bfd_vma) -1 | |
5054 | || plt == NULL | |
5055 | || got == NULL | |
5056 | || gotplt == NULL) | |
5057 | abort (); | |
5058 | ||
5059 | /* Fill in the entry in the GOT procedure linkage table. */ | |
0e1862bb | 5060 | if (! bfd_link_pic (info)) |
252b5132 | 5061 | { |
765e526c | 5062 | got_plt_entry = htab->non_lazy_plt->plt_entry; |
dd7e64d4 | 5063 | got_offset += got->output_section->vma + got->output_offset; |
252b5132 | 5064 | } |
dd7e64d4 L |
5065 | else |
5066 | { | |
765e526c | 5067 | got_plt_entry = htab->non_lazy_plt->pic_plt_entry; |
dd7e64d4 L |
5068 | got_offset += (got->output_section->vma |
5069 | + got->output_offset | |
5070 | - gotplt->output_section->vma | |
5071 | - gotplt->output_offset); | |
5072 | } | |
5073 | ||
5074 | plt_offset = eh->plt_got.offset; | |
5075 | memcpy (plt->contents + plt_offset, got_plt_entry, | |
765e526c | 5076 | htab->non_lazy_plt->plt_entry_size); |
dd7e64d4 | 5077 | bfd_put_32 (output_bfd, got_offset, |
f604c2a2 | 5078 | (plt->contents + plt_offset |
765e526c | 5079 | + htab->non_lazy_plt->plt_got_offset)); |
dd7e64d4 L |
5080 | } |
5081 | ||
aec6b87e L |
5082 | if (!local_undefweak |
5083 | && !h->def_regular | |
dd7e64d4 L |
5084 | && (h->plt.offset != (bfd_vma) -1 |
5085 | || eh->plt_got.offset != (bfd_vma) -1)) | |
5086 | { | |
5087 | /* Mark the symbol as undefined, rather than as defined in | |
5088 | the .plt section. Leave the value if there were any | |
5089 | relocations where pointer equality matters (this is a clue | |
5090 | for the dynamic linker, to make function pointer | |
5091 | comparisons work between an application and shared | |
5092 | library), otherwise set it to zero. If a function is only | |
5093 | called from a binary, there is no need to slow down | |
5094 | shared libraries because of that. */ | |
5095 | sym->st_shndx = SHN_UNDEF; | |
5096 | if (!h->pointer_equality_needed) | |
5097 | sym->st_value = 0; | |
252b5132 RH |
5098 | } |
5099 | ||
aec6b87e L |
5100 | /* Don't generate dynamic GOT relocation against undefined weak |
5101 | symbol in executable. */ | |
13ae64f3 | 5102 | if (h->got.offset != (bfd_vma) -1 |
0afcef53 L |
5103 | && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h)->tls_type) |
5104 | && (elf_x86_hash_entry(h)->tls_type & GOT_TLS_IE) == 0 | |
aec6b87e | 5105 | && !local_undefweak) |
252b5132 | 5106 | { |
947216bf | 5107 | Elf_Internal_Rela rel; |
233cc9c1 | 5108 | asection *relgot = htab->elf.srelgot; |
252b5132 RH |
5109 | |
5110 | /* This symbol has an entry in the global offset table. Set it | |
5111 | up. */ | |
5112 | ||
6de2ae4a | 5113 | if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL) |
ffb2e45b | 5114 | abort (); |
252b5132 | 5115 | |
6de2ae4a L |
5116 | rel.r_offset = (htab->elf.sgot->output_section->vma |
5117 | + htab->elf.sgot->output_offset | |
dc810e39 | 5118 | + (h->got.offset & ~(bfd_vma) 1)); |
252b5132 | 5119 | |
dd5724d5 AM |
5120 | /* If this is a static link, or it is a -Bsymbolic link and the |
5121 | symbol is defined locally or was forced to be local because | |
5122 | of a version file, we just want to emit a RELATIVE reloc. | |
252b5132 RH |
5123 | The entry in the global offset table will already have been |
5124 | initialized in the relocate_section function. */ | |
710ab287 | 5125 | if (h->def_regular |
0018b0a3 L |
5126 | && h->type == STT_GNU_IFUNC) |
5127 | { | |
233cc9c1 L |
5128 | if (h->plt.offset == (bfd_vma) -1) |
5129 | { | |
5130 | /* STT_GNU_IFUNC is referenced without PLT. */ | |
5131 | if (htab->elf.splt == NULL) | |
5132 | { | |
5133 | /* use .rel[a].iplt section to store .got relocations | |
5134 | in static executable. */ | |
5135 | relgot = htab->elf.irelplt; | |
5136 | } | |
5137 | if (SYMBOL_REFERENCES_LOCAL (info, h)) | |
5138 | { | |
6322e5c5 L |
5139 | info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"), |
5140 | h->root.root.string, | |
5141 | h->root.u.def.section->owner); | |
5142 | ||
233cc9c1 L |
5143 | bfd_put_32 (output_bfd, |
5144 | (h->root.u.def.value | |
5145 | + h->root.u.def.section->output_section->vma | |
5146 | + h->root.u.def.section->output_offset), | |
5147 | htab->elf.sgot->contents + h->got.offset); | |
5148 | rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE); | |
5149 | } | |
5150 | else | |
5151 | goto do_glob_dat; | |
5152 | } | |
5153 | else if (bfd_link_pic (info)) | |
710ab287 L |
5154 | { |
5155 | /* Generate R_386_GLOB_DAT. */ | |
5156 | goto do_glob_dat; | |
5157 | } | |
5158 | else | |
5159 | { | |
cd2b2c10 | 5160 | asection *plt; |
ee2fdd6f | 5161 | bfd_vma plt_offset; |
cd2b2c10 | 5162 | |
710ab287 L |
5163 | if (!h->pointer_equality_needed) |
5164 | abort (); | |
5165 | ||
5166 | /* For non-shared object, we can't use .got.plt, which | |
5167 | contains the real function addres if we need pointer | |
5168 | equality. We load the GOT entry with the PLT entry. */ | |
ee2fdd6f L |
5169 | if (htab->plt_second != NULL) |
5170 | { | |
5171 | plt = htab->plt_second; | |
5172 | plt_offset = eh->plt_second.offset; | |
5173 | } | |
5174 | else | |
5175 | { | |
5176 | plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt; | |
5177 | plt_offset = h->plt.offset; | |
5178 | } | |
710ab287 L |
5179 | bfd_put_32 (output_bfd, |
5180 | (plt->output_section->vma | |
ee2fdd6f | 5181 | + plt->output_offset + plt_offset), |
6de2ae4a | 5182 | htab->elf.sgot->contents + h->got.offset); |
710ab287 L |
5183 | return TRUE; |
5184 | } | |
0018b0a3 | 5185 | } |
0e1862bb | 5186 | else if (bfd_link_pic (info) |
0018b0a3 | 5187 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
dd5724d5 | 5188 | { |
6725bdbf | 5189 | BFD_ASSERT((h->got.offset & 1) != 0); |
dd5724d5 AM |
5190 | rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE); |
5191 | } | |
252b5132 RH |
5192 | else |
5193 | { | |
dd5724d5 | 5194 | BFD_ASSERT((h->got.offset & 1) == 0); |
710ab287 | 5195 | do_glob_dat: |
6725bdbf | 5196 | bfd_put_32 (output_bfd, (bfd_vma) 0, |
6de2ae4a | 5197 | htab->elf.sgot->contents + h->got.offset); |
252b5132 RH |
5198 | rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT); |
5199 | } | |
5200 | ||
233cc9c1 | 5201 | elf_append_rel (output_bfd, relgot, &rel); |
252b5132 RH |
5202 | } |
5203 | ||
f5385ebf | 5204 | if (h->needs_copy) |
252b5132 | 5205 | { |
947216bf | 5206 | Elf_Internal_Rela rel; |
5474d94f | 5207 | asection *s; |
252b5132 RH |
5208 | |
5209 | /* This symbol needs a copy reloc. Set it up. */ | |
5210 | ||
ffb2e45b AM |
5211 | if (h->dynindx == -1 |
5212 | || (h->root.type != bfd_link_hash_defined | |
5213 | && h->root.type != bfd_link_hash_defweak) | |
5474d94f AM |
5214 | || htab->elf.srelbss == NULL |
5215 | || htab->elf.sreldynrelro == NULL) | |
ffb2e45b | 5216 | abort (); |
252b5132 RH |
5217 | |
5218 | rel.r_offset = (h->root.u.def.value | |
5219 | + h->root.u.def.section->output_section->vma | |
5220 | + h->root.u.def.section->output_offset); | |
5221 | rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY); | |
afbf7e8e | 5222 | if (h->root.u.def.section == htab->elf.sdynrelro) |
5474d94f AM |
5223 | s = htab->elf.sreldynrelro; |
5224 | else | |
5225 | s = htab->elf.srelbss; | |
5226 | elf_append_rel (output_bfd, s, &rel); | |
252b5132 RH |
5227 | } |
5228 | ||
b34976b6 | 5229 | return TRUE; |
252b5132 RH |
5230 | } |
5231 | ||
c25bc9fc L |
5232 | /* Finish up local dynamic symbol handling. We set the contents of |
5233 | various dynamic sections here. */ | |
5234 | ||
5235 | static bfd_boolean | |
5236 | elf_i386_finish_local_dynamic_symbol (void **slot, void *inf) | |
5237 | { | |
5238 | struct elf_link_hash_entry *h | |
5239 | = (struct elf_link_hash_entry *) *slot; | |
5240 | struct bfd_link_info *info | |
23209a78 | 5241 | = (struct bfd_link_info *) inf; |
c25bc9fc L |
5242 | |
5243 | return elf_i386_finish_dynamic_symbol (info->output_bfd, info, | |
5244 | h, NULL); | |
5245 | } | |
5246 | ||
aec6b87e L |
5247 | /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry |
5248 | here since undefined weak symbol may not be dynamic and may not be | |
5249 | called for elf_i386_finish_dynamic_symbol. */ | |
5250 | ||
5251 | static bfd_boolean | |
5252 | elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh, | |
5253 | void *inf) | |
5254 | { | |
5255 | struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh; | |
5256 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
5257 | ||
5258 | if (h->root.type != bfd_link_hash_undefweak | |
5259 | || h->dynindx != -1) | |
5260 | return TRUE; | |
5261 | ||
5262 | return elf_i386_finish_dynamic_symbol (info->output_bfd, | |
5f0f0847 | 5263 | info, h, NULL); |
aec6b87e L |
5264 | } |
5265 | ||
38701953 AM |
5266 | /* Used to decide how to sort relocs in an optimal manner for the |
5267 | dynamic linker, before writing them out. */ | |
5268 | ||
5269 | static enum elf_reloc_type_class | |
cae1fbbb | 5270 | elf_i386_reloc_type_class (const struct bfd_link_info *info, |
7e612e98 AM |
5271 | const asection *rel_sec ATTRIBUTE_UNUSED, |
5272 | const Elf_Internal_Rela *rela) | |
38701953 | 5273 | { |
cae1fbbb L |
5274 | bfd *abfd = info->output_bfd; |
5275 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
5276 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
cae1fbbb | 5277 | |
d9e3b590 L |
5278 | if (htab->dynsym != NULL |
5279 | && htab->dynsym->contents != NULL) | |
5280 | { | |
5281 | /* Check relocation against STT_GNU_IFUNC symbol if there are | |
5282 | dynamic symbols. */ | |
5283 | unsigned long r_symndx = ELF32_R_SYM (rela->r_info); | |
c428ce9d L |
5284 | if (r_symndx != STN_UNDEF) |
5285 | { | |
5286 | Elf_Internal_Sym sym; | |
5287 | if (!bed->s->swap_symbol_in (abfd, | |
5288 | (htab->dynsym->contents | |
5289 | + r_symndx * sizeof (Elf32_External_Sym)), | |
5290 | 0, &sym)) | |
5291 | abort (); | |
d9e3b590 | 5292 | |
c428ce9d L |
5293 | if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) |
5294 | return reloc_class_ifunc; | |
5295 | } | |
d9e3b590 | 5296 | } |
cae1fbbb | 5297 | |
55fd94b0 | 5298 | switch (ELF32_R_TYPE (rela->r_info)) |
38701953 | 5299 | { |
c428ce9d L |
5300 | case R_386_IRELATIVE: |
5301 | return reloc_class_ifunc; | |
38701953 AM |
5302 | case R_386_RELATIVE: |
5303 | return reloc_class_relative; | |
5304 | case R_386_JUMP_SLOT: | |
5305 | return reloc_class_plt; | |
5306 | case R_386_COPY: | |
5307 | return reloc_class_copy; | |
5308 | default: | |
5309 | return reloc_class_normal; | |
5310 | } | |
5311 | } | |
5312 | ||
252b5132 RH |
5313 | /* Finish up the dynamic sections. */ |
5314 | ||
b34976b6 | 5315 | static bfd_boolean |
55fd94b0 AM |
5316 | elf_i386_finish_dynamic_sections (bfd *output_bfd, |
5317 | struct bfd_link_info *info) | |
252b5132 | 5318 | { |
0afcef53 | 5319 | struct elf_x86_link_hash_table *htab; |
252b5132 | 5320 | bfd *dynobj; |
252b5132 | 5321 | asection *sdyn; |
25e762b9 | 5322 | const struct elf_i386_backend_data *abed; |
252b5132 | 5323 | |
0afcef53 | 5324 | htab = elf_x86_hash_table (info, I386_ELF_DATA); |
4dfe6ac6 NC |
5325 | if (htab == NULL) |
5326 | return FALSE; | |
5327 | ||
ebe50bae | 5328 | dynobj = htab->elf.dynobj; |
3d4d4302 | 5329 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
25e762b9 | 5330 | abed = get_elf_i386_backend_data (output_bfd); |
252b5132 | 5331 | |
ebe50bae | 5332 | if (htab->elf.dynamic_sections_created) |
252b5132 | 5333 | { |
252b5132 RH |
5334 | Elf32_External_Dyn *dyncon, *dynconend; |
5335 | ||
6de2ae4a | 5336 | if (sdyn == NULL || htab->elf.sgot == NULL) |
ffb2e45b | 5337 | abort (); |
252b5132 RH |
5338 | |
5339 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 5340 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
252b5132 RH |
5341 | for (; dyncon < dynconend; dyncon++) |
5342 | { | |
5343 | Elf_Internal_Dyn dyn; | |
51b64d56 | 5344 | asection *s; |
252b5132 RH |
5345 | |
5346 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
5347 | ||
5348 | switch (dyn.d_tag) | |
5349 | { | |
5350 | default: | |
f604c2a2 | 5351 | if (abed->os == is_vxworks |
25e762b9 | 5352 | && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) |
7a2b07ff | 5353 | break; |
0ac8d2ca | 5354 | continue; |
252b5132 RH |
5355 | |
5356 | case DT_PLTGOT: | |
6de2ae4a | 5357 | s = htab->elf.sgotplt; |
8c37241b | 5358 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
6725bdbf AM |
5359 | break; |
5360 | ||
252b5132 | 5361 | case DT_JMPREL: |
6de2ae4a | 5362 | s = htab->elf.srelplt; |
6348e046 | 5363 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
252b5132 RH |
5364 | break; |
5365 | ||
5366 | case DT_PLTRELSZ: | |
6de2ae4a | 5367 | s = htab->elf.srelplt; |
eea6121a | 5368 | dyn.d_un.d_val = s->size; |
252b5132 | 5369 | break; |
252b5132 | 5370 | } |
0ac8d2ca AM |
5371 | |
5372 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
252b5132 RH |
5373 | } |
5374 | ||
6de2ae4a | 5375 | if (htab->elf.splt && htab->elf.splt->size > 0) |
252b5132 | 5376 | { |
1f78f649 L |
5377 | /* UnixWare sets the entsize of .plt to 4, although that doesn't |
5378 | really seem like the right value. */ | |
5379 | elf_section_data (htab->elf.splt->output_section) | |
5380 | ->this_hdr.sh_entsize = 4; | |
5381 | ||
765e526c | 5382 | if (htab->plt.has_plt0) |
252b5132 | 5383 | { |
f604c2a2 L |
5384 | /* Fill in the special first entry in the procedure linkage |
5385 | table. */ | |
765e526c L |
5386 | memcpy (htab->elf.splt->contents, htab->plt.plt0_entry, |
5387 | htab->lazy_plt->plt0_entry_size); | |
5388 | memset (htab->elf.splt->contents + htab->lazy_plt->plt0_entry_size, | |
25e762b9 | 5389 | abed->plt0_pad_byte, |
765e526c | 5390 | htab->plt.plt_entry_size - htab->lazy_plt->plt0_entry_size); |
f604c2a2 | 5391 | if (!bfd_link_pic (info)) |
eac338cf | 5392 | { |
f604c2a2 L |
5393 | bfd_put_32 (output_bfd, |
5394 | (htab->elf.sgotplt->output_section->vma | |
5395 | + htab->elf.sgotplt->output_offset | |
5396 | + 4), | |
5397 | htab->elf.splt->contents | |
765e526c | 5398 | + htab->lazy_plt->plt0_got1_offset); |
f604c2a2 L |
5399 | bfd_put_32 (output_bfd, |
5400 | (htab->elf.sgotplt->output_section->vma | |
5401 | + htab->elf.sgotplt->output_offset | |
5402 | + 8), | |
5403 | htab->elf.splt->contents | |
765e526c | 5404 | + htab->lazy_plt->plt0_got2_offset); |
eac338cf | 5405 | |
f604c2a2 | 5406 | if (abed->os == is_vxworks) |
1f78f649 | 5407 | { |
f604c2a2 L |
5408 | Elf_Internal_Rela rel; |
5409 | int num_plts = (htab->elf.splt->size | |
765e526c | 5410 | / htab->plt.plt_entry_size) - 1; |
f604c2a2 | 5411 | unsigned char *p; |
765e526c | 5412 | asection *srelplt2 = htab->srelplt2; |
f604c2a2 L |
5413 | |
5414 | /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ | |
5415 | + 4. On IA32 we use REL relocations so the | |
5416 | addend goes in the PLT directly. */ | |
5417 | rel.r_offset = (htab->elf.splt->output_section->vma | |
5418 | + htab->elf.splt->output_offset | |
765e526c | 5419 | + htab->lazy_plt->plt0_got1_offset); |
1f78f649 L |
5420 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
5421 | R_386_32); | |
f604c2a2 | 5422 | bfd_elf32_swap_reloc_out (output_bfd, &rel, |
0afcef53 | 5423 | srelplt2->contents); |
f604c2a2 L |
5424 | /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ |
5425 | + 8. */ | |
5426 | rel.r_offset = (htab->elf.splt->output_section->vma | |
5427 | + htab->elf.splt->output_offset | |
765e526c | 5428 | + htab->lazy_plt->plt0_got2_offset); |
f604c2a2 | 5429 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
1f78f649 | 5430 | R_386_32); |
f604c2a2 | 5431 | bfd_elf32_swap_reloc_out (output_bfd, &rel, |
0afcef53 | 5432 | srelplt2->contents + |
f604c2a2 L |
5433 | sizeof (Elf32_External_Rel)); |
5434 | /* Correct the .rel.plt.unloaded relocations. */ | |
0afcef53 | 5435 | p = srelplt2->contents; |
f604c2a2 L |
5436 | if (bfd_link_pic (info)) |
5437 | p += PLTRESOLVE_RELOCS_SHLIB * sizeof (Elf32_External_Rel); | |
5438 | else | |
5439 | p += PLTRESOLVE_RELOCS * sizeof (Elf32_External_Rel); | |
5440 | ||
5441 | for (; num_plts; num_plts--) | |
5442 | { | |
5443 | bfd_elf32_swap_reloc_in (output_bfd, p, &rel); | |
5444 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, | |
5445 | R_386_32); | |
5446 | bfd_elf32_swap_reloc_out (output_bfd, &rel, p); | |
5447 | p += sizeof (Elf32_External_Rel); | |
5448 | ||
5449 | bfd_elf32_swap_reloc_in (output_bfd, p, &rel); | |
5450 | rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, | |
5451 | R_386_32); | |
5452 | bfd_elf32_swap_reloc_out (output_bfd, &rel, p); | |
5453 | p += sizeof (Elf32_External_Rel); | |
5454 | } | |
1f78f649 | 5455 | } |
eac338cf PB |
5456 | } |
5457 | } | |
252b5132 | 5458 | } |
f604c2a2 L |
5459 | |
5460 | if (htab->plt_got != NULL && htab->plt_got->size > 0) | |
5461 | elf_section_data (htab->plt_got->output_section) | |
765e526c | 5462 | ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size; |
ee2fdd6f L |
5463 | |
5464 | if (htab->plt_second != NULL && htab->plt_second->size > 0) | |
5465 | elf_section_data (htab->plt_second->output_section) | |
765e526c | 5466 | ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size; |
252b5132 RH |
5467 | } |
5468 | ||
f604c2a2 L |
5469 | /* Fill in the first three entries in the global offset table. */ |
5470 | if (htab->elf.sgotplt && htab->elf.sgotplt->size > 0) | |
252b5132 | 5471 | { |
56d4289c L |
5472 | if (bfd_is_abs_section (htab->elf.sgotplt->output_section)) |
5473 | { | |
4eca0228 | 5474 | _bfd_error_handler |
56d4289c L |
5475 | (_("discarded output section: `%A'"), htab->elf.sgotplt); |
5476 | return FALSE; | |
5477 | } | |
5478 | ||
f604c2a2 L |
5479 | bfd_put_32 (output_bfd, |
5480 | (sdyn == NULL ? 0 | |
5481 | : sdyn->output_section->vma + sdyn->output_offset), | |
5482 | htab->elf.sgotplt->contents); | |
5483 | bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 4); | |
5484 | bfd_put_32 (output_bfd, 0, htab->elf.sgotplt->contents + 8); | |
252b5132 | 5485 | |
6de2ae4a | 5486 | elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize = 4; |
12d0ee4a | 5487 | } |
8c37241b | 5488 | |
e41b3a13 | 5489 | /* Adjust .eh_frame for .plt section. */ |
9a2a56cc AM |
5490 | if (htab->plt_eh_frame != NULL |
5491 | && htab->plt_eh_frame->contents != NULL) | |
e41b3a13 JJ |
5492 | { |
5493 | if (htab->elf.splt != NULL | |
5494 | && htab->elf.splt->size != 0 | |
5495 | && (htab->elf.splt->flags & SEC_EXCLUDE) == 0 | |
5496 | && htab->elf.splt->output_section != NULL | |
5497 | && htab->plt_eh_frame->output_section != NULL) | |
5498 | { | |
5499 | bfd_vma plt_start = htab->elf.splt->output_section->vma; | |
5500 | bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma | |
5501 | + htab->plt_eh_frame->output_offset | |
5502 | + PLT_FDE_START_OFFSET; | |
5503 | bfd_put_signed_32 (dynobj, plt_start - eh_frame_start, | |
5504 | htab->plt_eh_frame->contents | |
5505 | + PLT_FDE_START_OFFSET); | |
5506 | } | |
5507 | if (htab->plt_eh_frame->sec_info_type | |
dbaa2011 | 5508 | == SEC_INFO_TYPE_EH_FRAME) |
e41b3a13 JJ |
5509 | { |
5510 | if (! _bfd_elf_write_section_eh_frame (output_bfd, info, | |
5511 | htab->plt_eh_frame, | |
5512 | htab->plt_eh_frame->contents)) | |
5513 | return FALSE; | |
5514 | } | |
5515 | } | |
5516 | ||
fff53dae L |
5517 | /* Adjust .eh_frame for .plt.got section. */ |
5518 | if (htab->plt_got_eh_frame != NULL | |
5519 | && htab->plt_got_eh_frame->contents != NULL) | |
5520 | { | |
5521 | if (htab->plt_got != NULL | |
5522 | && htab->plt_got->size != 0 | |
5523 | && (htab->plt_got->flags & SEC_EXCLUDE) == 0 | |
5524 | && htab->plt_got->output_section != NULL | |
5525 | && htab->plt_got_eh_frame->output_section != NULL) | |
5526 | { | |
5527 | bfd_vma plt_start = htab->plt_got->output_section->vma; | |
5528 | bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma | |
5529 | + htab->plt_got_eh_frame->output_offset | |
5530 | + PLT_FDE_START_OFFSET; | |
5531 | bfd_put_signed_32 (dynobj, plt_start - eh_frame_start, | |
5532 | htab->plt_got_eh_frame->contents | |
5533 | + PLT_FDE_START_OFFSET); | |
5534 | } | |
5535 | if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME) | |
5536 | { | |
5537 | if (! _bfd_elf_write_section_eh_frame (output_bfd, info, | |
5538 | htab->plt_got_eh_frame, | |
5539 | htab->plt_got_eh_frame->contents)) | |
5540 | return FALSE; | |
5541 | } | |
5542 | } | |
5543 | ||
ee2fdd6f L |
5544 | /* Adjust .eh_frame for the second PLT section. */ |
5545 | if (htab->plt_second_eh_frame != NULL | |
5546 | && htab->plt_second_eh_frame->contents != NULL) | |
5547 | { | |
5548 | if (htab->plt_second != NULL | |
5549 | && htab->plt_second->size != 0 | |
5550 | && (htab->plt_second->flags & SEC_EXCLUDE) == 0 | |
5551 | && htab->plt_second->output_section != NULL | |
5552 | && htab->plt_second_eh_frame->output_section != NULL) | |
5553 | { | |
5554 | bfd_vma plt_start = htab->plt_second->output_section->vma; | |
5555 | bfd_vma eh_frame_start | |
5556 | = (htab->plt_second_eh_frame->output_section->vma | |
5557 | + htab->plt_second_eh_frame->output_offset | |
5558 | + PLT_FDE_START_OFFSET); | |
5559 | bfd_put_signed_32 (dynobj, plt_start - eh_frame_start, | |
5560 | htab->plt_second_eh_frame->contents | |
5561 | + PLT_FDE_START_OFFSET); | |
5562 | } | |
5563 | if (htab->plt_second_eh_frame->sec_info_type | |
5564 | == SEC_INFO_TYPE_EH_FRAME) | |
5565 | { | |
5566 | if (! _bfd_elf_write_section_eh_frame (output_bfd, info, | |
5567 | htab->plt_second_eh_frame, | |
5568 | htab->plt_second_eh_frame->contents)) | |
5569 | return FALSE; | |
5570 | } | |
5571 | } | |
5572 | ||
6de2ae4a L |
5573 | if (htab->elf.sgot && htab->elf.sgot->size > 0) |
5574 | elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4; | |
8c37241b | 5575 | |
aec6b87e L |
5576 | /* Fill PLT entries for undefined weak symbols in PIE. */ |
5577 | if (bfd_link_pie (info)) | |
5578 | bfd_hash_traverse (&info->hash->table, | |
5579 | elf_i386_pie_finish_undefweak_symbol, | |
5580 | info); | |
5581 | ||
b34976b6 | 5582 | return TRUE; |
252b5132 RH |
5583 | } |
5584 | ||
233cc9c1 L |
5585 | /* Fill PLT/GOT entries and allocate dynamic relocations for local |
5586 | STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table. | |
5587 | It has to be done before elf_link_sort_relocs is called so that | |
5588 | dynamic relocations are properly sorted. */ | |
5589 | ||
5590 | static bfd_boolean | |
5591 | elf_i386_output_arch_local_syms | |
5592 | (bfd *output_bfd ATTRIBUTE_UNUSED, | |
5593 | struct bfd_link_info *info, | |
5594 | void *flaginfo ATTRIBUTE_UNUSED, | |
5595 | int (*func) (void *, const char *, | |
5596 | Elf_Internal_Sym *, | |
5597 | asection *, | |
5598 | struct elf_link_hash_entry *) ATTRIBUTE_UNUSED) | |
5599 | { | |
0afcef53 L |
5600 | struct elf_x86_link_hash_table *htab |
5601 | = elf_x86_hash_table (info, I386_ELF_DATA); | |
233cc9c1 L |
5602 | if (htab == NULL) |
5603 | return FALSE; | |
5604 | ||
5605 | /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */ | |
5606 | htab_traverse (htab->loc_hash_table, | |
5607 | elf_i386_finish_local_dynamic_symbol, | |
5608 | info); | |
5609 | ||
5610 | return TRUE; | |
5611 | } | |
5612 | ||
f604c2a2 | 5613 | /* Forward declaration. */ |
765e526c | 5614 | static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt; |
f604c2a2 L |
5615 | |
5616 | /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all | |
5617 | dynamic relocations. */ | |
5618 | ||
5619 | static long | |
5620 | elf_i386_get_synthetic_symtab (bfd *abfd, | |
5621 | long symcount ATTRIBUTE_UNUSED, | |
5622 | asymbol **syms ATTRIBUTE_UNUSED, | |
5623 | long dynsymcount, | |
5624 | asymbol **dynsyms, | |
5625 | asymbol **ret) | |
5626 | { | |
f493882d | 5627 | long count, i, n; |
f604c2a2 | 5628 | int j; |
f604c2a2 | 5629 | bfd_byte *plt_contents; |
f493882d | 5630 | long relsize; |
765e526c L |
5631 | const struct elf_x86_lazy_plt_layout *lazy_plt; |
5632 | const struct elf_x86_non_lazy_plt_layout *non_lazy_plt; | |
5633 | const struct elf_x86_lazy_plt_layout *lazy_ibt_plt; | |
5634 | const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt; | |
f604c2a2 L |
5635 | asection *plt; |
5636 | bfd_vma got_addr; | |
f493882d L |
5637 | enum elf_x86_plt_type plt_type; |
5638 | struct elf_x86_plt plts[] = | |
3972882e | 5639 | { |
f493882d L |
5640 | { ".plt", NULL, NULL, plt_unknown, 0, 0, 0, 0 }, |
5641 | { ".plt.got", NULL, NULL, plt_non_lazy, 0, 0, 0, 0 }, | |
5642 | { ".plt.sec", NULL, NULL, plt_second, 0, 0, 0, 0 }, | |
5643 | { NULL, NULL, NULL, plt_non_lazy, 0, 0, 0, 0 } | |
f604c2a2 | 5644 | }; |
144bed8d | 5645 | |
f604c2a2 | 5646 | *ret = NULL; |
144bed8d | 5647 | |
f604c2a2 L |
5648 | if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0) |
5649 | return 0; | |
3972882e | 5650 | |
f604c2a2 L |
5651 | if (dynsymcount <= 0) |
5652 | return 0; | |
cca5b8b6 | 5653 | |
f604c2a2 L |
5654 | relsize = bfd_get_dynamic_reloc_upper_bound (abfd); |
5655 | if (relsize <= 0) | |
5656 | return -1; | |
cca5b8b6 | 5657 | |
f604c2a2 L |
5658 | non_lazy_plt = NULL; |
5659 | /* Silence GCC 6. */ | |
5660 | lazy_plt = NULL; | |
ee2fdd6f L |
5661 | non_lazy_ibt_plt = NULL; |
5662 | lazy_ibt_plt = NULL; | |
f604c2a2 | 5663 | switch (get_elf_i386_backend_data (abfd)->os) |
144bed8d | 5664 | { |
f604c2a2 L |
5665 | case is_normal: |
5666 | non_lazy_plt = &elf_i386_non_lazy_plt; | |
ee2fdd6f L |
5667 | lazy_ibt_plt = &elf_i386_lazy_ibt_plt; |
5668 | non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt; | |
f604c2a2 L |
5669 | /* Fall through */ |
5670 | case is_vxworks: | |
5671 | lazy_plt = &elf_i386_lazy_plt; | |
5672 | break; | |
5673 | case is_nacl: | |
5674 | lazy_plt = &elf_i386_nacl_plt; | |
5675 | break; | |
5676 | } | |
5677 | ||
5678 | got_addr = 0; | |
3972882e | 5679 | |
f604c2a2 L |
5680 | count = 0; |
5681 | for (j = 0; plts[j].name != NULL; j++) | |
5682 | { | |
5683 | plt = bfd_get_section_by_name (abfd, plts[j].name); | |
90efb642 | 5684 | if (plt == NULL || plt->size == 0) |
6f25f223 | 5685 | continue; |
533d0af0 | 5686 | |
f604c2a2 L |
5687 | /* Get the PLT section contents. */ |
5688 | plt_contents = (bfd_byte *) bfd_malloc (plt->size); | |
5689 | if (plt_contents == NULL) | |
5690 | break; | |
5691 | if (!bfd_get_section_contents (abfd, (asection *) plt, | |
5692 | plt_contents, 0, plt->size)) | |
5693 | { | |
5694 | free (plt_contents); | |
5695 | break; | |
5696 | } | |
5697 | ||
5698 | /* Check what kind of PLT it is. */ | |
5699 | plt_type = plt_unknown; | |
90efb642 L |
5700 | if (plts[j].type == plt_unknown |
5701 | && (plt->size >= (lazy_plt->plt0_entry_size | |
5702 | + lazy_plt->plt_entry_size))) | |
f604c2a2 L |
5703 | { |
5704 | /* Match lazy PLT first. */ | |
5705 | if (memcmp (plt_contents, lazy_plt->plt0_entry, | |
5706 | lazy_plt->plt0_got1_offset) == 0) | |
ee2fdd6f L |
5707 | { |
5708 | /* The fist entry in the lazy IBT PLT is the same as the | |
5709 | normal lazy PLT. */ | |
5710 | if (lazy_ibt_plt != NULL | |
90efb642 | 5711 | && (memcmp (plt_contents + lazy_ibt_plt->plt0_entry_size, |
ee2fdd6f L |
5712 | lazy_ibt_plt->plt_entry, |
5713 | lazy_ibt_plt->plt_got_offset) == 0)) | |
5714 | plt_type = plt_lazy | plt_second; | |
5715 | else | |
5716 | plt_type = plt_lazy; | |
5717 | } | |
f604c2a2 L |
5718 | else if (memcmp (plt_contents, lazy_plt->pic_plt0_entry, |
5719 | lazy_plt->plt0_got1_offset) == 0) | |
ee2fdd6f L |
5720 | { |
5721 | /* The fist entry in the PIC lazy IBT PLT is the same as | |
5722 | the normal PIC lazy PLT. */ | |
5723 | if (lazy_ibt_plt != NULL | |
90efb642 | 5724 | && (memcmp (plt_contents + lazy_ibt_plt->plt0_entry_size, |
ee2fdd6f L |
5725 | lazy_ibt_plt->pic_plt_entry, |
5726 | lazy_ibt_plt->plt_got_offset) == 0)) | |
5727 | plt_type = plt_lazy | plt_pic | plt_second; | |
5728 | else | |
5729 | plt_type = plt_lazy | plt_pic; | |
5730 | } | |
f604c2a2 L |
5731 | } |
5732 | ||
5733 | if (non_lazy_plt != NULL | |
90efb642 L |
5734 | && (plt_type == plt_unknown || plt_type == plt_non_lazy) |
5735 | && plt->size >= non_lazy_plt->plt_entry_size) | |
f604c2a2 L |
5736 | { |
5737 | /* Match non-lazy PLT. */ | |
5738 | if (memcmp (plt_contents, non_lazy_plt->plt_entry, | |
5739 | non_lazy_plt->plt_got_offset) == 0) | |
5740 | plt_type = plt_non_lazy; | |
5741 | else if (memcmp (plt_contents, non_lazy_plt->pic_plt_entry, | |
5742 | non_lazy_plt->plt_got_offset) == 0) | |
5743 | plt_type = plt_pic; | |
5744 | } | |
5745 | ||
ee2fdd6f | 5746 | if ((non_lazy_ibt_plt != NULL) |
90efb642 L |
5747 | && (plt_type == plt_unknown || plt_type == plt_second) |
5748 | && plt->size >= non_lazy_ibt_plt->plt_entry_size) | |
ee2fdd6f L |
5749 | { |
5750 | if (memcmp (plt_contents, | |
5751 | non_lazy_ibt_plt->plt_entry, | |
5752 | non_lazy_ibt_plt->plt_got_offset) == 0) | |
5753 | { | |
5754 | /* Match IBT PLT. */ | |
5755 | plt_type = plt_second; | |
5756 | non_lazy_plt = non_lazy_ibt_plt; | |
5757 | } | |
5758 | else if (memcmp (plt_contents, | |
5759 | non_lazy_ibt_plt->pic_plt_entry, | |
5760 | non_lazy_ibt_plt->plt_got_offset) == 0) | |
5761 | { | |
5762 | /* Match PIC IBT PLT. */ | |
5763 | plt_type = plt_second | plt_pic; | |
5764 | non_lazy_plt = non_lazy_ibt_plt; | |
5765 | } | |
5766 | } | |
5767 | ||
f604c2a2 | 5768 | if (plt_type == plt_unknown) |
37c0b6ee L |
5769 | { |
5770 | free (plt_contents); | |
5771 | continue; | |
5772 | } | |
3972882e | 5773 | |
f604c2a2 L |
5774 | plts[j].sec = plt; |
5775 | plts[j].type = plt_type; | |
ec1f73bb | 5776 | |
f604c2a2 L |
5777 | if ((plt_type & plt_lazy)) |
5778 | { | |
5779 | plts[j].plt_got_offset = lazy_plt->plt_got_offset; | |
5780 | plts[j].plt_entry_size = lazy_plt->plt_entry_size; | |
5781 | /* Skip PLT0 in lazy PLT. */ | |
5782 | i = 1; | |
5783 | } | |
5784 | else | |
5785 | { | |
5786 | plts[j].plt_got_offset = non_lazy_plt->plt_got_offset; | |
5787 | plts[j].plt_entry_size = non_lazy_plt->plt_entry_size; | |
5788 | i = 0; | |
5789 | } | |
fca6ae69 | 5790 | |
ee2fdd6f L |
5791 | /* Skip lazy PLT when the second PLT is used. */ |
5792 | if ((plt_type & (plt_lazy | plt_second)) | |
5793 | == (plt_lazy | plt_second)) | |
5794 | plts[j].count = 0; | |
5795 | else | |
5796 | { | |
5797 | n = plt->size / plts[j].plt_entry_size; | |
5798 | plts[j].count = n; | |
5799 | count += n - i; | |
5800 | } | |
f604c2a2 L |
5801 | |
5802 | plts[j].contents = plt_contents; | |
5803 | ||
5804 | /* The _GLOBAL_OFFSET_TABLE_ address is needed. */ | |
5805 | if ((plt_type & plt_pic)) | |
5806 | got_addr = (bfd_vma) -1; | |
144bed8d L |
5807 | } |
5808 | ||
f493882d L |
5809 | return _bfd_x86_elf_get_synthetic_symtab (abfd, count, relsize, |
5810 | got_addr, plts, dynsyms, | |
5811 | ret); | |
4c45e5c9 JJ |
5812 | } |
5813 | ||
f604c2a2 L |
5814 | /* Set up i386 GNU properties. Return the first relocatable ELF input |
5815 | with GNU properties if found. Otherwise, return NULL. */ | |
5816 | ||
5817 | static bfd * | |
5818 | elf_i386_link_setup_gnu_properties (struct bfd_link_info *info) | |
5819 | { | |
a6798bab | 5820 | struct elf_x86_plt_layout_table plt_layout; |
f604c2a2 | 5821 | |
a6798bab L |
5822 | plt_layout.normal_target = FALSE; |
5823 | plt_layout.is_vxworks = FALSE; | |
f604c2a2 L |
5824 | switch (get_elf_i386_backend_data (info->output_bfd)->os) |
5825 | { | |
5826 | case is_normal: | |
a6798bab L |
5827 | plt_layout.lazy_plt = &elf_i386_lazy_plt; |
5828 | plt_layout.non_lazy_plt = &elf_i386_non_lazy_plt; | |
5829 | plt_layout.lazy_ibt_plt = &elf_i386_lazy_ibt_plt; | |
5830 | plt_layout.non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt; | |
5831 | plt_layout.normal_target = TRUE; | |
f604c2a2 L |
5832 | break; |
5833 | case is_vxworks: | |
a6798bab L |
5834 | plt_layout.lazy_plt = &elf_i386_lazy_plt; |
5835 | plt_layout.non_lazy_plt = NULL; | |
5836 | plt_layout.lazy_ibt_plt = NULL; | |
5837 | plt_layout.non_lazy_ibt_plt = NULL; | |
5838 | plt_layout.is_vxworks = TRUE; | |
f604c2a2 L |
5839 | break; |
5840 | case is_nacl: | |
a6798bab L |
5841 | plt_layout.lazy_plt = &elf_i386_nacl_plt; |
5842 | plt_layout.non_lazy_plt = NULL; | |
5843 | plt_layout.lazy_ibt_plt = NULL; | |
5844 | plt_layout.non_lazy_ibt_plt = NULL; | |
f604c2a2 L |
5845 | break; |
5846 | } | |
5847 | ||
a6798bab | 5848 | return _bfd_x86_elf_link_setup_gnu_properties (info, &plt_layout); |
f604c2a2 L |
5849 | } |
5850 | ||
6d00b590 | 5851 | #define TARGET_LITTLE_SYM i386_elf32_vec |
252b5132 RH |
5852 | #define TARGET_LITTLE_NAME "elf32-i386" |
5853 | #define ELF_ARCH bfd_arch_i386 | |
ae95ffa6 | 5854 | #define ELF_TARGET_ID I386_ELF_DATA |
252b5132 RH |
5855 | #define ELF_MACHINE_CODE EM_386 |
5856 | #define ELF_MAXPAGESIZE 0x1000 | |
252b5132 RH |
5857 | |
5858 | #define elf_backend_can_gc_sections 1 | |
51b64d56 | 5859 | #define elf_backend_can_refcount 1 |
252b5132 RH |
5860 | #define elf_backend_want_got_plt 1 |
5861 | #define elf_backend_plt_readonly 1 | |
5862 | #define elf_backend_want_plt_sym 0 | |
5863 | #define elf_backend_got_header_size 12 | |
e41b3a13 | 5864 | #define elf_backend_plt_alignment 4 |
64f52338 | 5865 | #define elf_backend_dtrel_excludes_plt 1 |
f7483970 | 5866 | #define elf_backend_extern_protected_data 1 |
bedfd056 | 5867 | #define elf_backend_caches_rawsize 1 |
5474d94f | 5868 | #define elf_backend_want_dynrelro 1 |
252b5132 | 5869 | |
8c29f035 AM |
5870 | /* Support RELA for objdump of prelink objects. */ |
5871 | #define elf_info_to_howto elf_i386_info_to_howto_rel | |
dd5724d5 AM |
5872 | #define elf_info_to_howto_rel elf_i386_info_to_howto_rel |
5873 | ||
dd5724d5 | 5874 | #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name |
dd5724d5 | 5875 | #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup |
13285a1b | 5876 | #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup |
3972882e | 5877 | #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab |
dd5724d5 AM |
5878 | |
5879 | #define elf_backend_adjust_dynamic_symbol elf_i386_adjust_dynamic_symbol | |
13285a1b | 5880 | #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible |
dd5724d5 | 5881 | #define elf_backend_check_relocs elf_i386_check_relocs |
f604c2a2 | 5882 | #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections |
0ac8d2ca | 5883 | #define elf_backend_fake_sections elf_i386_fake_sections |
dd5724d5 AM |
5884 | #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections |
5885 | #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol | |
233cc9c1 | 5886 | #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms |
dd5724d5 | 5887 | #define elf_backend_gc_mark_hook elf_i386_gc_mark_hook |
c5fccbec DJ |
5888 | #define elf_backend_grok_prstatus elf_i386_grok_prstatus |
5889 | #define elf_backend_grok_psinfo elf_i386_grok_psinfo | |
db6751f2 | 5890 | #define elf_backend_reloc_type_class elf_i386_reloc_type_class |
0ac8d2ca AM |
5891 | #define elf_backend_relocate_section elf_i386_relocate_section |
5892 | #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections | |
f604c2a2 | 5893 | #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties |
dd5724d5 | 5894 | |
252b5132 | 5895 | #include "elf32-target.h" |
2bc3c89a AM |
5896 | |
5897 | /* FreeBSD support. */ | |
5898 | ||
5899 | #undef TARGET_LITTLE_SYM | |
6d00b590 | 5900 | #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec |
2bc3c89a AM |
5901 | #undef TARGET_LITTLE_NAME |
5902 | #define TARGET_LITTLE_NAME "elf32-i386-freebsd" | |
d1036acb L |
5903 | #undef ELF_OSABI |
5904 | #define ELF_OSABI ELFOSABI_FREEBSD | |
2bc3c89a AM |
5905 | |
5906 | /* The kernel recognizes executables as valid only if they carry a | |
5907 | "FreeBSD" label in the ELF header. So we put this label on all | |
5908 | executables and (for simplicity) also all other object files. */ | |
5909 | ||
2bc3c89a | 5910 | static void |
d8045f23 | 5911 | elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info) |
2bc3c89a | 5912 | { |
78245035 | 5913 | _bfd_elf_post_process_headers (abfd, info); |
2bc3c89a | 5914 | |
2bc3c89a | 5915 | #ifdef OLD_FREEBSD_ABI_LABEL |
cf7363b4 L |
5916 | { |
5917 | /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */ | |
5918 | Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); | |
5919 | memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8); | |
5920 | } | |
caf47ea6 | 5921 | #endif |
2bc3c89a AM |
5922 | } |
5923 | ||
5924 | #undef elf_backend_post_process_headers | |
d8045f23 | 5925 | #define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers |
571fe01f NC |
5926 | #undef elf32_bed |
5927 | #define elf32_bed elf32_i386_fbsd_bed | |
2bc3c89a | 5928 | |
d8045f23 NC |
5929 | #undef elf_backend_add_symbol_hook |
5930 | ||
2bc3c89a | 5931 | #include "elf32-target.h" |
eac338cf | 5932 | |
a6cc6b3b RO |
5933 | /* Solaris 2. */ |
5934 | ||
5935 | #undef TARGET_LITTLE_SYM | |
6d00b590 | 5936 | #define TARGET_LITTLE_SYM i386_elf32_sol2_vec |
a6cc6b3b RO |
5937 | #undef TARGET_LITTLE_NAME |
5938 | #define TARGET_LITTLE_NAME "elf32-i386-sol2" | |
5939 | ||
914082d1 L |
5940 | #undef elf_backend_post_process_headers |
5941 | ||
a6cc6b3b RO |
5942 | /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE |
5943 | objects won't be recognized. */ | |
5944 | #undef ELF_OSABI | |
5945 | ||
5946 | #undef elf32_bed | |
5947 | #define elf32_bed elf32_i386_sol2_bed | |
5948 | ||
7dc98aea RO |
5949 | /* The 32-bit static TLS arena size is rounded to the nearest 8-byte |
5950 | boundary. */ | |
84865015 | 5951 | #undef elf_backend_static_tls_alignment |
7dc98aea RO |
5952 | #define elf_backend_static_tls_alignment 8 |
5953 | ||
a6cc6b3b RO |
5954 | /* The Solaris 2 ABI requires a plt symbol on all platforms. |
5955 | ||
5956 | Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output | |
5957 | File, p.63. */ | |
84865015 | 5958 | #undef elf_backend_want_plt_sym |
a6cc6b3b RO |
5959 | #define elf_backend_want_plt_sym 1 |
5960 | ||
84865015 NC |
5961 | #undef elf_backend_strtab_flags |
5962 | #define elf_backend_strtab_flags SHF_STRINGS | |
5963 | ||
5522f910 NC |
5964 | /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which |
5965 | has a type >= SHT_LOOS. Returns TRUE if these fields were initialised | |
5966 | FALSE otherwise. ISECTION is the best guess matching section from the | |
5967 | input bfd IBFD, but it might be NULL. */ | |
5968 | ||
84865015 | 5969 | static bfd_boolean |
5522f910 NC |
5970 | elf32_i386_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED, |
5971 | bfd *obfd ATTRIBUTE_UNUSED, | |
5972 | const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
5973 | Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
84865015 NC |
5974 | { |
5975 | /* PR 19938: FIXME: Need to add code for setting the sh_info | |
5522f910 NC |
5976 | and sh_link fields of Solaris specific section types. */ |
5977 | return FALSE; | |
84865015 | 5978 | |
5522f910 | 5979 | /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13, |
84865015 NC |
5980 | Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation: |
5981 | ||
5982 | http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc | |
5983 | ||
5984 | The following values should be set: | |
5985 | ||
5986 | Type Link Info | |
5987 | ----------------------------------------------------------------------------- | |
5988 | SHT_SUNW_ancillary The section header index of 0 | |
5989 | [0x6fffffee] the associated string table. | |
5990 | ||
5991 | SHT_SUNW_capinfo The section header index of For a dynamic object, the | |
5992 | [0x6ffffff0] the associated symbol table. section header index of | |
5993 | the associated | |
5994 | SHT_SUNW_capchain table, | |
5995 | otherwise 0. | |
5996 | ||
5997 | SHT_SUNW_symsort The section header index of 0 | |
5998 | [0x6ffffff1] the associated symbol table. | |
5999 | ||
6000 | SHT_SUNW_tlssort The section header index of 0 | |
6001 | [0x6ffffff2] the associated symbol table. | |
6002 | ||
6003 | SHT_SUNW_LDYNSYM The section header index of One greater than the | |
6004 | [0x6ffffff3] the associated string table. symbol table index of the | |
6005 | This index is the same string last local symbol, | |
6006 | table used by the SHT_DYNSYM STB_LOCAL. Since | |
6007 | section. SHT_SUNW_LDYNSYM only | |
6008 | contains local symbols, | |
6009 | sh_info is equivalent to | |
6010 | the number of symbols in | |
6011 | the table. | |
6012 | ||
6013 | SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer | |
6014 | [0x6ffffff5] the section header index of to named strings, the | |
6015 | the associated section header index of | |
6016 | SHT_SUNW_capinfo table, the associated string | |
6017 | otherwise 0. table, otherwise 0. | |
6018 | ||
6019 | SHT_SUNW_move The section header index of 0 | |
6020 | [0x6ffffffa] the associated symbol table. | |
6021 | ||
6022 | SHT_SUNW_COMDAT 0 0 | |
6023 | [0x6ffffffb] | |
6024 | ||
6025 | SHT_SUNW_syminfo The section header index of The section header index | |
6026 | [0x6ffffffc] the associated symbol table. of the associated | |
6027 | .dynamic section. | |
6028 | ||
6029 | SHT_SUNW_verdef The section header index of The number of version | |
6030 | [0x6ffffffd] the associated string table. definitions within the | |
6031 | section. | |
6032 | ||
6033 | SHT_SUNW_verneed The section header index of The number of version | |
6034 | [0x6ffffffe] the associated string table. dependencies within the | |
6035 | section. | |
6036 | ||
6037 | SHT_SUNW_versym The section header index of 0 | |
6038 | [0x6fffffff] the associated symbol table. */ | |
84865015 NC |
6039 | } |
6040 | ||
5522f910 NC |
6041 | #undef elf_backend_copy_special_section_fields |
6042 | #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields | |
84865015 | 6043 | |
a6cc6b3b RO |
6044 | #include "elf32-target.h" |
6045 | ||
bf64a951 L |
6046 | /* Intel MCU support. */ |
6047 | ||
6048 | static bfd_boolean | |
6049 | elf32_iamcu_elf_object_p (bfd *abfd) | |
6050 | { | |
6051 | /* Set the right machine number for an IAMCU elf32 file. */ | |
6052 | bfd_default_set_arch_mach (abfd, bfd_arch_iamcu, bfd_mach_i386_iamcu); | |
6053 | return TRUE; | |
6054 | } | |
6055 | ||
6056 | #undef TARGET_LITTLE_SYM | |
6057 | #define TARGET_LITTLE_SYM iamcu_elf32_vec | |
6058 | #undef TARGET_LITTLE_NAME | |
6059 | #define TARGET_LITTLE_NAME "elf32-iamcu" | |
84865015 | 6060 | #undef ELF_ARCH |
bf64a951 L |
6061 | #define ELF_ARCH bfd_arch_iamcu |
6062 | ||
6063 | #undef ELF_MACHINE_CODE | |
6064 | #define ELF_MACHINE_CODE EM_IAMCU | |
6065 | ||
6066 | #undef ELF_OSABI | |
6067 | ||
6068 | #undef elf32_bed | |
6069 | #define elf32_bed elf32_iamcu_bed | |
6070 | ||
6071 | #undef elf_backend_object_p | |
6072 | #define elf_backend_object_p elf32_iamcu_elf_object_p | |
6073 | ||
6074 | #undef elf_backend_static_tls_alignment | |
6075 | ||
6076 | #undef elf_backend_want_plt_sym | |
6077 | #define elf_backend_want_plt_sym 0 | |
6078 | ||
84865015 | 6079 | #undef elf_backend_strtab_flags |
5522f910 | 6080 | #undef elf_backend_copy_special_section_fields |
84865015 | 6081 | |
bf64a951 L |
6082 | #include "elf32-target.h" |
6083 | ||
6084 | /* Restore defaults. */ | |
6085 | #undef ELF_ARCH | |
6086 | #define ELF_ARCH bfd_arch_i386 | |
6087 | #undef ELF_MACHINE_CODE | |
6088 | #define ELF_MACHINE_CODE EM_386 | |
6089 | ||
a27e4371 RM |
6090 | /* Native Client support. */ |
6091 | ||
6092 | #undef TARGET_LITTLE_SYM | |
6d00b590 | 6093 | #define TARGET_LITTLE_SYM i386_elf32_nacl_vec |
a27e4371 RM |
6094 | #undef TARGET_LITTLE_NAME |
6095 | #define TARGET_LITTLE_NAME "elf32-i386-nacl" | |
6096 | #undef elf32_bed | |
6097 | #define elf32_bed elf32_i386_nacl_bed | |
6098 | ||
6099 | #undef ELF_MAXPAGESIZE | |
6100 | #define ELF_MAXPAGESIZE 0x10000 | |
6101 | ||
6102 | /* Restore defaults. */ | |
6103 | #undef ELF_OSABI | |
6104 | #undef elf_backend_want_plt_sym | |
6105 | #define elf_backend_want_plt_sym 0 | |
6106 | #undef elf_backend_post_process_headers | |
a27e4371 RM |
6107 | #undef elf_backend_static_tls_alignment |
6108 | ||
6109 | /* NaCl uses substantially different PLT entries for the same effects. */ | |
6110 | ||
6111 | #undef elf_backend_plt_alignment | |
6112 | #define elf_backend_plt_alignment 5 | |
6113 | #define NACL_PLT_ENTRY_SIZE 64 | |
6114 | #define NACLMASK 0xe0 /* 32-byte alignment mask. */ | |
6115 | ||
6116 | static const bfd_byte elf_i386_nacl_plt0_entry[] = | |
6117 | { | |
6118 | 0xff, 0x35, /* pushl contents of address */ | |
6119 | 0, 0, 0, 0, /* replaced with address of .got + 4. */ | |
6120 | 0x8b, 0x0d, /* movl contents of address, %ecx */ | |
6121 | 0, 0, 0, 0, /* replaced with address of .got + 8. */ | |
6122 | 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */ | |
6123 | 0xff, 0xe1 /* jmp *%ecx */ | |
6124 | }; | |
6125 | ||
6126 | static const bfd_byte elf_i386_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] = | |
6127 | { | |
6128 | 0x8b, 0x0d, /* movl contents of address, %ecx */ | |
6129 | 0, 0, 0, 0, /* replaced with GOT slot address. */ | |
6130 | 0x83, 0xe1, NACLMASK, /* andl $NACLMASK, %ecx */ | |
6131 | 0xff, 0xe1, /* jmp *%ecx */ | |
6132 | ||
6133 | /* Pad to the next 32-byte boundary with nop instructions. */ | |
6134 | 0x90, | |
6135 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6136 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6137 | ||
6138 | /* Lazy GOT entries point here (32-byte aligned). */ | |
6139 | 0x68, /* pushl immediate */ | |
6140 | 0, 0, 0, 0, /* replaced with reloc offset. */ | |
6141 | 0xe9, /* jmp relative */ | |
6142 | 0, 0, 0, 0, /* replaced with offset to .plt. */ | |
6143 | ||
6144 | /* Pad to the next 32-byte boundary with nop instructions. */ | |
6145 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6146 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6147 | 0x90, 0x90 | |
6148 | }; | |
6149 | ||
6150 | static const bfd_byte | |
6151 | elf_i386_nacl_pic_plt0_entry[sizeof (elf_i386_nacl_plt0_entry)] = | |
6152 | { | |
6153 | 0xff, 0x73, 0x04, /* pushl 4(%ebx) */ | |
6154 | 0x8b, 0x4b, 0x08, /* mov 0x8(%ebx), %ecx */ | |
6155 | 0x83, 0xe1, 0xe0, /* and $NACLMASK, %ecx */ | |
6156 | 0xff, 0xe1, /* jmp *%ecx */ | |
caa0075c RM |
6157 | |
6158 | /* This is expected to be the same size as elf_i386_nacl_plt0_entry, | |
6159 | so pad to that size with nop instructions. */ | |
6160 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 | |
a27e4371 RM |
6161 | }; |
6162 | ||
6163 | static const bfd_byte elf_i386_nacl_pic_plt_entry[NACL_PLT_ENTRY_SIZE] = | |
6164 | { | |
6165 | 0x8b, 0x8b, /* movl offset(%ebx), %ecx */ | |
6166 | 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */ | |
6167 | 0x83, 0xe1, 0xe0, /* andl $NACLMASK, %ecx */ | |
6168 | 0xff, 0xe1, /* jmp *%ecx */ | |
6169 | ||
6170 | /* Pad to the next 32-byte boundary with nop instructions. */ | |
6171 | 0x90, | |
6172 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6173 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6174 | ||
6175 | /* Lazy GOT entries point here (32-byte aligned). */ | |
6176 | 0x68, /* pushl immediate */ | |
6177 | 0, 0, 0, 0, /* replaced with offset into relocation table. */ | |
6178 | 0xe9, /* jmp relative */ | |
6179 | 0, 0, 0, 0, /* replaced with offset to start of .plt. */ | |
6180 | ||
6181 | /* Pad to the next 32-byte boundary with nop instructions. */ | |
6182 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6183 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, | |
6184 | 0x90, 0x90 | |
6185 | }; | |
6186 | ||
6187 | static const bfd_byte elf_i386_nacl_eh_frame_plt[] = | |
6188 | { | |
6189 | #if (PLT_CIE_LENGTH != 20 \ | |
6190 | || PLT_FDE_LENGTH != 36 \ | |
6191 | || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \ | |
6192 | || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12) | |
6193 | # error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!" | |
6194 | #endif | |
6195 | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ | |
6196 | 0, 0, 0, 0, /* CIE ID */ | |
6197 | 1, /* CIE version */ | |
6198 | 'z', 'R', 0, /* Augmentation string */ | |
6199 | 1, /* Code alignment factor */ | |
6200 | 0x7c, /* Data alignment factor: -4 */ | |
6201 | 8, /* Return address column */ | |
6202 | 1, /* Augmentation size */ | |
6203 | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ | |
6204 | DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */ | |
6205 | DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */ | |
6206 | DW_CFA_nop, DW_CFA_nop, | |
6207 | ||
6208 | PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */ | |
6209 | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ | |
6210 | 0, 0, 0, 0, /* R_386_PC32 .plt goes here */ | |
6211 | 0, 0, 0, 0, /* .plt size goes here */ | |
6212 | 0, /* Augmentation size */ | |
6213 | DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */ | |
6214 | DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */ | |
6215 | DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */ | |
6216 | DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */ | |
6217 | DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */ | |
6218 | 13, /* Block length */ | |
6219 | DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */ | |
6220 | DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */ | |
6221 | DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge, | |
6222 | DW_OP_lit2, DW_OP_shl, DW_OP_plus, | |
6223 | DW_CFA_nop, DW_CFA_nop | |
6224 | }; | |
6225 | ||
765e526c | 6226 | static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt = |
a27e4371 RM |
6227 | { |
6228 | elf_i386_nacl_plt0_entry, /* plt0_entry */ | |
6229 | sizeof (elf_i386_nacl_plt0_entry), /* plt0_entry_size */ | |
a27e4371 RM |
6230 | elf_i386_nacl_plt_entry, /* plt_entry */ |
6231 | NACL_PLT_ENTRY_SIZE, /* plt_entry_size */ | |
765e526c L |
6232 | 2, /* plt0_got1_offset */ |
6233 | 8, /* plt0_got2_offset */ | |
6234 | 0, /* plt0_got2_insn_end */ | |
a27e4371 RM |
6235 | 2, /* plt_got_offset */ |
6236 | 33, /* plt_reloc_offset */ | |
6237 | 38, /* plt_plt_offset */ | |
765e526c L |
6238 | 0, /* plt_got_insn_size */ |
6239 | 0, /* plt_plt_insn_end */ | |
a27e4371 RM |
6240 | 32, /* plt_lazy_offset */ |
6241 | elf_i386_nacl_pic_plt0_entry, /* pic_plt0_entry */ | |
6242 | elf_i386_nacl_pic_plt_entry, /* pic_plt_entry */ | |
6243 | elf_i386_nacl_eh_frame_plt, /* eh_frame_plt */ | |
f604c2a2 | 6244 | sizeof (elf_i386_nacl_eh_frame_plt) /* eh_frame_plt_size */ |
a27e4371 RM |
6245 | }; |
6246 | ||
6247 | static const struct elf_i386_backend_data elf_i386_nacl_arch_bed = | |
6248 | { | |
f604c2a2 L |
6249 | 0x90, /* plt0_pad_byte: nop insn */ |
6250 | is_nacl /* os */ | |
a27e4371 RM |
6251 | }; |
6252 | ||
64b384e1 RM |
6253 | static bfd_boolean |
6254 | elf32_i386_nacl_elf_object_p (bfd *abfd) | |
6255 | { | |
6256 | /* Set the right machine number for a NaCl i386 ELF32 file. */ | |
6257 | bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386_nacl); | |
6258 | return TRUE; | |
6259 | } | |
6260 | ||
a27e4371 RM |
6261 | #undef elf_backend_arch_data |
6262 | #define elf_backend_arch_data &elf_i386_nacl_arch_bed | |
6263 | ||
64b384e1 RM |
6264 | #undef elf_backend_object_p |
6265 | #define elf_backend_object_p elf32_i386_nacl_elf_object_p | |
5a68afcf RM |
6266 | #undef elf_backend_modify_segment_map |
6267 | #define elf_backend_modify_segment_map nacl_modify_segment_map | |
6268 | #undef elf_backend_modify_program_headers | |
6269 | #define elf_backend_modify_program_headers nacl_modify_program_headers | |
887badb3 RM |
6270 | #undef elf_backend_final_write_processing |
6271 | #define elf_backend_final_write_processing nacl_final_write_processing | |
5a68afcf | 6272 | |
a27e4371 RM |
6273 | #include "elf32-target.h" |
6274 | ||
5a68afcf | 6275 | /* Restore defaults. */ |
64b384e1 | 6276 | #undef elf_backend_object_p |
5a68afcf RM |
6277 | #undef elf_backend_modify_segment_map |
6278 | #undef elf_backend_modify_program_headers | |
887badb3 | 6279 | #undef elf_backend_final_write_processing |
5a68afcf | 6280 | |
eac338cf PB |
6281 | /* VxWorks support. */ |
6282 | ||
6283 | #undef TARGET_LITTLE_SYM | |
6d00b590 | 6284 | #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec |
eac338cf PB |
6285 | #undef TARGET_LITTLE_NAME |
6286 | #define TARGET_LITTLE_NAME "elf32-i386-vxworks" | |
d1036acb | 6287 | #undef ELF_OSABI |
1587442d L |
6288 | #undef ELF_MAXPAGESIZE |
6289 | #define ELF_MAXPAGESIZE 0x1000 | |
a27e4371 RM |
6290 | #undef elf_backend_plt_alignment |
6291 | #define elf_backend_plt_alignment 4 | |
eac338cf | 6292 | |
23209a78 RM |
6293 | static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed = |
6294 | { | |
6295 | 0x90, /* plt0_pad_byte */ | |
f604c2a2 | 6296 | is_vxworks /* os */ |
23209a78 | 6297 | }; |
eac338cf | 6298 | |
23209a78 RM |
6299 | #undef elf_backend_arch_data |
6300 | #define elf_backend_arch_data &elf_i386_vxworks_arch_bed | |
eac338cf | 6301 | |
13285a1b | 6302 | #undef elf_backend_relocs_compatible |
eac338cf PB |
6303 | #undef elf_backend_add_symbol_hook |
6304 | #define elf_backend_add_symbol_hook \ | |
6305 | elf_vxworks_add_symbol_hook | |
6306 | #undef elf_backend_link_output_symbol_hook | |
6307 | #define elf_backend_link_output_symbol_hook \ | |
9c72ff84 | 6308 | elf_vxworks_link_output_symbol_hook |
eac338cf PB |
6309 | #undef elf_backend_emit_relocs |
6310 | #define elf_backend_emit_relocs elf_vxworks_emit_relocs | |
6311 | #undef elf_backend_final_write_processing | |
6312 | #define elf_backend_final_write_processing \ | |
6313 | elf_vxworks_final_write_processing | |
7dc98aea | 6314 | #undef elf_backend_static_tls_alignment |
eac338cf PB |
6315 | |
6316 | /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so | |
6317 | define it. */ | |
6318 | #undef elf_backend_want_plt_sym | |
6319 | #define elf_backend_want_plt_sym 1 | |
6320 | ||
6321 | #undef elf32_bed | |
6322 | #define elf32_bed elf32_i386_vxworks_bed | |
6323 | ||
6324 | #include "elf32-target.h" |