Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* 32-bit ELF support for ARM |
ab96bf03 | 2 | Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
d1f161ea | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
3e110533 | 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 | 20 | |
7f266840 DJ |
21 | #include "bfd.h" |
22 | #include "sysdep.h" | |
00a97672 | 23 | #include "libiberty.h" |
7f266840 DJ |
24 | #include "libbfd.h" |
25 | #include "elf-bfd.h" | |
00a97672 | 26 | #include "elf-vxworks.h" |
ee065d83 | 27 | #include "elf/arm.h" |
7f266840 DJ |
28 | |
29 | #ifndef NUM_ELEM | |
30 | #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0])) | |
31 | #endif | |
32 | ||
00a97672 RS |
33 | /* Return the relocation section associated with NAME. HTAB is the |
34 | bfd's elf32_arm_link_hash_entry. */ | |
35 | #define RELOC_SECTION(HTAB, NAME) \ | |
36 | ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME) | |
37 | ||
38 | /* Return size of a relocation entry. HTAB is the bfd's | |
39 | elf32_arm_link_hash_entry. */ | |
40 | #define RELOC_SIZE(HTAB) \ | |
41 | ((HTAB)->use_rel \ | |
42 | ? sizeof (Elf32_External_Rel) \ | |
43 | : sizeof (Elf32_External_Rela)) | |
44 | ||
45 | /* Return function to swap relocations in. HTAB is the bfd's | |
46 | elf32_arm_link_hash_entry. */ | |
47 | #define SWAP_RELOC_IN(HTAB) \ | |
48 | ((HTAB)->use_rel \ | |
49 | ? bfd_elf32_swap_reloc_in \ | |
50 | : bfd_elf32_swap_reloca_in) | |
51 | ||
52 | /* Return function to swap relocations out. HTAB is the bfd's | |
53 | elf32_arm_link_hash_entry. */ | |
54 | #define SWAP_RELOC_OUT(HTAB) \ | |
55 | ((HTAB)->use_rel \ | |
56 | ? bfd_elf32_swap_reloc_out \ | |
57 | : bfd_elf32_swap_reloca_out) | |
58 | ||
7f266840 DJ |
59 | #define elf_info_to_howto 0 |
60 | #define elf_info_to_howto_rel elf32_arm_info_to_howto | |
61 | ||
62 | #define ARM_ELF_ABI_VERSION 0 | |
63 | #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM | |
64 | ||
24718e3b | 65 | static struct elf_backend_data elf32_arm_vxworks_bed; |
00a97672 | 66 | |
7f266840 DJ |
67 | /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g. |
68 | R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO | |
69 | in that slot. */ | |
70 | ||
c19d1205 | 71 | static reloc_howto_type elf32_arm_howto_table_1[] = |
7f266840 DJ |
72 | { |
73 | /* No relocation */ | |
74 | HOWTO (R_ARM_NONE, /* type */ | |
75 | 0, /* rightshift */ | |
76 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
77 | 0, /* bitsize */ | |
78 | FALSE, /* pc_relative */ | |
79 | 0, /* bitpos */ | |
80 | complain_overflow_dont,/* complain_on_overflow */ | |
81 | bfd_elf_generic_reloc, /* special_function */ | |
82 | "R_ARM_NONE", /* name */ | |
83 | FALSE, /* partial_inplace */ | |
84 | 0, /* src_mask */ | |
85 | 0, /* dst_mask */ | |
86 | FALSE), /* pcrel_offset */ | |
87 | ||
88 | HOWTO (R_ARM_PC24, /* type */ | |
89 | 2, /* rightshift */ | |
90 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
91 | 24, /* bitsize */ | |
92 | TRUE, /* pc_relative */ | |
93 | 0, /* bitpos */ | |
94 | complain_overflow_signed,/* complain_on_overflow */ | |
95 | bfd_elf_generic_reloc, /* special_function */ | |
96 | "R_ARM_PC24", /* name */ | |
97 | FALSE, /* partial_inplace */ | |
98 | 0x00ffffff, /* src_mask */ | |
99 | 0x00ffffff, /* dst_mask */ | |
100 | TRUE), /* pcrel_offset */ | |
101 | ||
102 | /* 32 bit absolute */ | |
103 | HOWTO (R_ARM_ABS32, /* type */ | |
104 | 0, /* rightshift */ | |
105 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
106 | 32, /* bitsize */ | |
107 | FALSE, /* pc_relative */ | |
108 | 0, /* bitpos */ | |
109 | complain_overflow_bitfield,/* complain_on_overflow */ | |
110 | bfd_elf_generic_reloc, /* special_function */ | |
111 | "R_ARM_ABS32", /* name */ | |
112 | FALSE, /* partial_inplace */ | |
113 | 0xffffffff, /* src_mask */ | |
114 | 0xffffffff, /* dst_mask */ | |
115 | FALSE), /* pcrel_offset */ | |
116 | ||
117 | /* standard 32bit pc-relative reloc */ | |
118 | HOWTO (R_ARM_REL32, /* type */ | |
119 | 0, /* rightshift */ | |
120 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
121 | 32, /* bitsize */ | |
122 | TRUE, /* pc_relative */ | |
123 | 0, /* bitpos */ | |
124 | complain_overflow_bitfield,/* complain_on_overflow */ | |
125 | bfd_elf_generic_reloc, /* special_function */ | |
126 | "R_ARM_REL32", /* name */ | |
127 | FALSE, /* partial_inplace */ | |
128 | 0xffffffff, /* src_mask */ | |
129 | 0xffffffff, /* dst_mask */ | |
130 | TRUE), /* pcrel_offset */ | |
131 | ||
c19d1205 | 132 | /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */ |
4962c51a | 133 | HOWTO (R_ARM_LDR_PC_G0, /* type */ |
7f266840 DJ |
134 | 0, /* rightshift */ |
135 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
4962c51a MS |
136 | 32, /* bitsize */ |
137 | TRUE, /* pc_relative */ | |
7f266840 | 138 | 0, /* bitpos */ |
4962c51a | 139 | complain_overflow_dont,/* complain_on_overflow */ |
7f266840 | 140 | bfd_elf_generic_reloc, /* special_function */ |
4962c51a | 141 | "R_ARM_LDR_PC_G0", /* name */ |
7f266840 | 142 | FALSE, /* partial_inplace */ |
4962c51a MS |
143 | 0xffffffff, /* src_mask */ |
144 | 0xffffffff, /* dst_mask */ | |
145 | TRUE), /* pcrel_offset */ | |
7f266840 DJ |
146 | |
147 | /* 16 bit absolute */ | |
148 | HOWTO (R_ARM_ABS16, /* type */ | |
149 | 0, /* rightshift */ | |
150 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
151 | 16, /* bitsize */ | |
152 | FALSE, /* pc_relative */ | |
153 | 0, /* bitpos */ | |
154 | complain_overflow_bitfield,/* complain_on_overflow */ | |
155 | bfd_elf_generic_reloc, /* special_function */ | |
156 | "R_ARM_ABS16", /* name */ | |
157 | FALSE, /* partial_inplace */ | |
158 | 0x0000ffff, /* src_mask */ | |
159 | 0x0000ffff, /* dst_mask */ | |
160 | FALSE), /* pcrel_offset */ | |
161 | ||
162 | /* 12 bit absolute */ | |
163 | HOWTO (R_ARM_ABS12, /* type */ | |
164 | 0, /* rightshift */ | |
165 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
166 | 12, /* bitsize */ | |
167 | FALSE, /* pc_relative */ | |
168 | 0, /* bitpos */ | |
169 | complain_overflow_bitfield,/* complain_on_overflow */ | |
170 | bfd_elf_generic_reloc, /* special_function */ | |
171 | "R_ARM_ABS12", /* name */ | |
172 | FALSE, /* partial_inplace */ | |
00a97672 RS |
173 | 0x00000fff, /* src_mask */ |
174 | 0x00000fff, /* dst_mask */ | |
7f266840 DJ |
175 | FALSE), /* pcrel_offset */ |
176 | ||
177 | HOWTO (R_ARM_THM_ABS5, /* type */ | |
178 | 6, /* rightshift */ | |
179 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
180 | 5, /* bitsize */ | |
181 | FALSE, /* pc_relative */ | |
182 | 0, /* bitpos */ | |
183 | complain_overflow_bitfield,/* complain_on_overflow */ | |
184 | bfd_elf_generic_reloc, /* special_function */ | |
185 | "R_ARM_THM_ABS5", /* name */ | |
186 | FALSE, /* partial_inplace */ | |
187 | 0x000007e0, /* src_mask */ | |
188 | 0x000007e0, /* dst_mask */ | |
189 | FALSE), /* pcrel_offset */ | |
190 | ||
191 | /* 8 bit absolute */ | |
192 | HOWTO (R_ARM_ABS8, /* type */ | |
193 | 0, /* rightshift */ | |
194 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
195 | 8, /* bitsize */ | |
196 | FALSE, /* pc_relative */ | |
197 | 0, /* bitpos */ | |
198 | complain_overflow_bitfield,/* complain_on_overflow */ | |
199 | bfd_elf_generic_reloc, /* special_function */ | |
200 | "R_ARM_ABS8", /* name */ | |
201 | FALSE, /* partial_inplace */ | |
202 | 0x000000ff, /* src_mask */ | |
203 | 0x000000ff, /* dst_mask */ | |
204 | FALSE), /* pcrel_offset */ | |
205 | ||
206 | HOWTO (R_ARM_SBREL32, /* type */ | |
207 | 0, /* rightshift */ | |
208 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
209 | 32, /* bitsize */ | |
210 | FALSE, /* pc_relative */ | |
211 | 0, /* bitpos */ | |
212 | complain_overflow_dont,/* complain_on_overflow */ | |
213 | bfd_elf_generic_reloc, /* special_function */ | |
214 | "R_ARM_SBREL32", /* name */ | |
215 | FALSE, /* partial_inplace */ | |
216 | 0xffffffff, /* src_mask */ | |
217 | 0xffffffff, /* dst_mask */ | |
218 | FALSE), /* pcrel_offset */ | |
219 | ||
c19d1205 | 220 | HOWTO (R_ARM_THM_CALL, /* type */ |
7f266840 DJ |
221 | 1, /* rightshift */ |
222 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
e95de063 | 223 | 25, /* bitsize */ |
7f266840 DJ |
224 | TRUE, /* pc_relative */ |
225 | 0, /* bitpos */ | |
226 | complain_overflow_signed,/* complain_on_overflow */ | |
227 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 228 | "R_ARM_THM_CALL", /* name */ |
7f266840 DJ |
229 | FALSE, /* partial_inplace */ |
230 | 0x07ff07ff, /* src_mask */ | |
231 | 0x07ff07ff, /* dst_mask */ | |
232 | TRUE), /* pcrel_offset */ | |
233 | ||
234 | HOWTO (R_ARM_THM_PC8, /* type */ | |
235 | 1, /* rightshift */ | |
236 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
237 | 8, /* bitsize */ | |
238 | TRUE, /* pc_relative */ | |
239 | 0, /* bitpos */ | |
240 | complain_overflow_signed,/* complain_on_overflow */ | |
241 | bfd_elf_generic_reloc, /* special_function */ | |
242 | "R_ARM_THM_PC8", /* name */ | |
243 | FALSE, /* partial_inplace */ | |
244 | 0x000000ff, /* src_mask */ | |
245 | 0x000000ff, /* dst_mask */ | |
246 | TRUE), /* pcrel_offset */ | |
247 | ||
c19d1205 | 248 | HOWTO (R_ARM_BREL_ADJ, /* type */ |
7f266840 DJ |
249 | 1, /* rightshift */ |
250 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 ZW |
251 | 32, /* bitsize */ |
252 | FALSE, /* pc_relative */ | |
7f266840 DJ |
253 | 0, /* bitpos */ |
254 | complain_overflow_signed,/* complain_on_overflow */ | |
255 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 256 | "R_ARM_BREL_ADJ", /* name */ |
7f266840 | 257 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
258 | 0xffffffff, /* src_mask */ |
259 | 0xffffffff, /* dst_mask */ | |
260 | FALSE), /* pcrel_offset */ | |
7f266840 DJ |
261 | |
262 | HOWTO (R_ARM_SWI24, /* type */ | |
263 | 0, /* rightshift */ | |
264 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
265 | 0, /* bitsize */ | |
266 | FALSE, /* pc_relative */ | |
267 | 0, /* bitpos */ | |
268 | complain_overflow_signed,/* complain_on_overflow */ | |
269 | bfd_elf_generic_reloc, /* special_function */ | |
270 | "R_ARM_SWI24", /* name */ | |
271 | FALSE, /* partial_inplace */ | |
272 | 0x00000000, /* src_mask */ | |
273 | 0x00000000, /* dst_mask */ | |
274 | FALSE), /* pcrel_offset */ | |
275 | ||
276 | HOWTO (R_ARM_THM_SWI8, /* type */ | |
277 | 0, /* rightshift */ | |
278 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
279 | 0, /* bitsize */ | |
280 | FALSE, /* pc_relative */ | |
281 | 0, /* bitpos */ | |
282 | complain_overflow_signed,/* complain_on_overflow */ | |
283 | bfd_elf_generic_reloc, /* special_function */ | |
284 | "R_ARM_SWI8", /* name */ | |
285 | FALSE, /* partial_inplace */ | |
286 | 0x00000000, /* src_mask */ | |
287 | 0x00000000, /* dst_mask */ | |
288 | FALSE), /* pcrel_offset */ | |
289 | ||
290 | /* BLX instruction for the ARM. */ | |
291 | HOWTO (R_ARM_XPC25, /* type */ | |
292 | 2, /* rightshift */ | |
293 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
294 | 25, /* bitsize */ | |
295 | TRUE, /* pc_relative */ | |
296 | 0, /* bitpos */ | |
297 | complain_overflow_signed,/* complain_on_overflow */ | |
298 | bfd_elf_generic_reloc, /* special_function */ | |
299 | "R_ARM_XPC25", /* name */ | |
300 | FALSE, /* partial_inplace */ | |
301 | 0x00ffffff, /* src_mask */ | |
302 | 0x00ffffff, /* dst_mask */ | |
303 | TRUE), /* pcrel_offset */ | |
304 | ||
305 | /* BLX instruction for the Thumb. */ | |
306 | HOWTO (R_ARM_THM_XPC22, /* type */ | |
307 | 2, /* rightshift */ | |
308 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
309 | 22, /* bitsize */ | |
310 | TRUE, /* pc_relative */ | |
311 | 0, /* bitpos */ | |
312 | complain_overflow_signed,/* complain_on_overflow */ | |
313 | bfd_elf_generic_reloc, /* special_function */ | |
314 | "R_ARM_THM_XPC22", /* name */ | |
315 | FALSE, /* partial_inplace */ | |
316 | 0x07ff07ff, /* src_mask */ | |
317 | 0x07ff07ff, /* dst_mask */ | |
318 | TRUE), /* pcrel_offset */ | |
319 | ||
ba93b8ac | 320 | /* Dynamic TLS relocations. */ |
7f266840 | 321 | |
ba93b8ac DJ |
322 | HOWTO (R_ARM_TLS_DTPMOD32, /* type */ |
323 | 0, /* rightshift */ | |
324 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
325 | 32, /* bitsize */ | |
326 | FALSE, /* pc_relative */ | |
327 | 0, /* bitpos */ | |
328 | complain_overflow_bitfield,/* complain_on_overflow */ | |
329 | bfd_elf_generic_reloc, /* special_function */ | |
330 | "R_ARM_TLS_DTPMOD32", /* name */ | |
331 | TRUE, /* partial_inplace */ | |
332 | 0xffffffff, /* src_mask */ | |
333 | 0xffffffff, /* dst_mask */ | |
334 | FALSE), /* pcrel_offset */ | |
7f266840 | 335 | |
ba93b8ac DJ |
336 | HOWTO (R_ARM_TLS_DTPOFF32, /* type */ |
337 | 0, /* rightshift */ | |
338 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
339 | 32, /* bitsize */ | |
340 | FALSE, /* pc_relative */ | |
341 | 0, /* bitpos */ | |
342 | complain_overflow_bitfield,/* complain_on_overflow */ | |
343 | bfd_elf_generic_reloc, /* special_function */ | |
344 | "R_ARM_TLS_DTPOFF32", /* name */ | |
345 | TRUE, /* partial_inplace */ | |
346 | 0xffffffff, /* src_mask */ | |
347 | 0xffffffff, /* dst_mask */ | |
348 | FALSE), /* pcrel_offset */ | |
7f266840 | 349 | |
ba93b8ac DJ |
350 | HOWTO (R_ARM_TLS_TPOFF32, /* type */ |
351 | 0, /* rightshift */ | |
352 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
353 | 32, /* bitsize */ | |
354 | FALSE, /* pc_relative */ | |
355 | 0, /* bitpos */ | |
356 | complain_overflow_bitfield,/* complain_on_overflow */ | |
357 | bfd_elf_generic_reloc, /* special_function */ | |
358 | "R_ARM_TLS_TPOFF32", /* name */ | |
359 | TRUE, /* partial_inplace */ | |
360 | 0xffffffff, /* src_mask */ | |
361 | 0xffffffff, /* dst_mask */ | |
362 | FALSE), /* pcrel_offset */ | |
7f266840 DJ |
363 | |
364 | /* Relocs used in ARM Linux */ | |
365 | ||
366 | HOWTO (R_ARM_COPY, /* type */ | |
367 | 0, /* rightshift */ | |
368 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
369 | 32, /* bitsize */ | |
370 | FALSE, /* pc_relative */ | |
371 | 0, /* bitpos */ | |
372 | complain_overflow_bitfield,/* complain_on_overflow */ | |
373 | bfd_elf_generic_reloc, /* special_function */ | |
374 | "R_ARM_COPY", /* name */ | |
375 | TRUE, /* partial_inplace */ | |
376 | 0xffffffff, /* src_mask */ | |
377 | 0xffffffff, /* dst_mask */ | |
378 | FALSE), /* pcrel_offset */ | |
379 | ||
380 | HOWTO (R_ARM_GLOB_DAT, /* type */ | |
381 | 0, /* rightshift */ | |
382 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
383 | 32, /* bitsize */ | |
384 | FALSE, /* pc_relative */ | |
385 | 0, /* bitpos */ | |
386 | complain_overflow_bitfield,/* complain_on_overflow */ | |
387 | bfd_elf_generic_reloc, /* special_function */ | |
388 | "R_ARM_GLOB_DAT", /* name */ | |
389 | TRUE, /* partial_inplace */ | |
390 | 0xffffffff, /* src_mask */ | |
391 | 0xffffffff, /* dst_mask */ | |
392 | FALSE), /* pcrel_offset */ | |
393 | ||
394 | HOWTO (R_ARM_JUMP_SLOT, /* type */ | |
395 | 0, /* rightshift */ | |
396 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
397 | 32, /* bitsize */ | |
398 | FALSE, /* pc_relative */ | |
399 | 0, /* bitpos */ | |
400 | complain_overflow_bitfield,/* complain_on_overflow */ | |
401 | bfd_elf_generic_reloc, /* special_function */ | |
402 | "R_ARM_JUMP_SLOT", /* name */ | |
403 | TRUE, /* partial_inplace */ | |
404 | 0xffffffff, /* src_mask */ | |
405 | 0xffffffff, /* dst_mask */ | |
406 | FALSE), /* pcrel_offset */ | |
407 | ||
408 | HOWTO (R_ARM_RELATIVE, /* type */ | |
409 | 0, /* rightshift */ | |
410 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
411 | 32, /* bitsize */ | |
412 | FALSE, /* pc_relative */ | |
413 | 0, /* bitpos */ | |
414 | complain_overflow_bitfield,/* complain_on_overflow */ | |
415 | bfd_elf_generic_reloc, /* special_function */ | |
416 | "R_ARM_RELATIVE", /* name */ | |
417 | TRUE, /* partial_inplace */ | |
418 | 0xffffffff, /* src_mask */ | |
419 | 0xffffffff, /* dst_mask */ | |
420 | FALSE), /* pcrel_offset */ | |
421 | ||
c19d1205 | 422 | HOWTO (R_ARM_GOTOFF32, /* type */ |
7f266840 DJ |
423 | 0, /* rightshift */ |
424 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
425 | 32, /* bitsize */ | |
426 | FALSE, /* pc_relative */ | |
427 | 0, /* bitpos */ | |
428 | complain_overflow_bitfield,/* complain_on_overflow */ | |
429 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 430 | "R_ARM_GOTOFF32", /* name */ |
7f266840 DJ |
431 | TRUE, /* partial_inplace */ |
432 | 0xffffffff, /* src_mask */ | |
433 | 0xffffffff, /* dst_mask */ | |
434 | FALSE), /* pcrel_offset */ | |
435 | ||
436 | HOWTO (R_ARM_GOTPC, /* type */ | |
437 | 0, /* rightshift */ | |
438 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
439 | 32, /* bitsize */ | |
440 | TRUE, /* pc_relative */ | |
441 | 0, /* bitpos */ | |
442 | complain_overflow_bitfield,/* complain_on_overflow */ | |
443 | bfd_elf_generic_reloc, /* special_function */ | |
444 | "R_ARM_GOTPC", /* name */ | |
445 | TRUE, /* partial_inplace */ | |
446 | 0xffffffff, /* src_mask */ | |
447 | 0xffffffff, /* dst_mask */ | |
448 | TRUE), /* pcrel_offset */ | |
449 | ||
450 | HOWTO (R_ARM_GOT32, /* type */ | |
451 | 0, /* rightshift */ | |
452 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
453 | 32, /* bitsize */ | |
454 | FALSE, /* pc_relative */ | |
455 | 0, /* bitpos */ | |
456 | complain_overflow_bitfield,/* complain_on_overflow */ | |
457 | bfd_elf_generic_reloc, /* special_function */ | |
458 | "R_ARM_GOT32", /* name */ | |
459 | TRUE, /* partial_inplace */ | |
460 | 0xffffffff, /* src_mask */ | |
461 | 0xffffffff, /* dst_mask */ | |
462 | FALSE), /* pcrel_offset */ | |
463 | ||
464 | HOWTO (R_ARM_PLT32, /* type */ | |
465 | 2, /* rightshift */ | |
466 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
ce490eda | 467 | 24, /* bitsize */ |
7f266840 DJ |
468 | TRUE, /* pc_relative */ |
469 | 0, /* bitpos */ | |
470 | complain_overflow_bitfield,/* complain_on_overflow */ | |
471 | bfd_elf_generic_reloc, /* special_function */ | |
472 | "R_ARM_PLT32", /* name */ | |
ce490eda | 473 | FALSE, /* partial_inplace */ |
7f266840 DJ |
474 | 0x00ffffff, /* src_mask */ |
475 | 0x00ffffff, /* dst_mask */ | |
476 | TRUE), /* pcrel_offset */ | |
477 | ||
478 | HOWTO (R_ARM_CALL, /* type */ | |
479 | 2, /* rightshift */ | |
480 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
481 | 24, /* bitsize */ | |
482 | TRUE, /* pc_relative */ | |
483 | 0, /* bitpos */ | |
484 | complain_overflow_signed,/* complain_on_overflow */ | |
485 | bfd_elf_generic_reloc, /* special_function */ | |
486 | "R_ARM_CALL", /* name */ | |
487 | FALSE, /* partial_inplace */ | |
488 | 0x00ffffff, /* src_mask */ | |
489 | 0x00ffffff, /* dst_mask */ | |
490 | TRUE), /* pcrel_offset */ | |
491 | ||
492 | HOWTO (R_ARM_JUMP24, /* type */ | |
493 | 2, /* rightshift */ | |
494 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
495 | 24, /* bitsize */ | |
496 | TRUE, /* pc_relative */ | |
497 | 0, /* bitpos */ | |
498 | complain_overflow_signed,/* complain_on_overflow */ | |
499 | bfd_elf_generic_reloc, /* special_function */ | |
500 | "R_ARM_JUMP24", /* name */ | |
501 | FALSE, /* partial_inplace */ | |
502 | 0x00ffffff, /* src_mask */ | |
503 | 0x00ffffff, /* dst_mask */ | |
504 | TRUE), /* pcrel_offset */ | |
505 | ||
c19d1205 ZW |
506 | HOWTO (R_ARM_THM_JUMP24, /* type */ |
507 | 1, /* rightshift */ | |
508 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
509 | 24, /* bitsize */ | |
510 | TRUE, /* pc_relative */ | |
7f266840 | 511 | 0, /* bitpos */ |
c19d1205 | 512 | complain_overflow_signed,/* complain_on_overflow */ |
7f266840 | 513 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 514 | "R_ARM_THM_JUMP24", /* name */ |
7f266840 | 515 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
516 | 0x07ff2fff, /* src_mask */ |
517 | 0x07ff2fff, /* dst_mask */ | |
518 | TRUE), /* pcrel_offset */ | |
7f266840 | 519 | |
c19d1205 | 520 | HOWTO (R_ARM_BASE_ABS, /* type */ |
7f266840 | 521 | 0, /* rightshift */ |
c19d1205 ZW |
522 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
523 | 32, /* bitsize */ | |
7f266840 DJ |
524 | FALSE, /* pc_relative */ |
525 | 0, /* bitpos */ | |
526 | complain_overflow_dont,/* complain_on_overflow */ | |
527 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 528 | "R_ARM_BASE_ABS", /* name */ |
7f266840 | 529 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
530 | 0xffffffff, /* src_mask */ |
531 | 0xffffffff, /* dst_mask */ | |
7f266840 DJ |
532 | FALSE), /* pcrel_offset */ |
533 | ||
534 | HOWTO (R_ARM_ALU_PCREL7_0, /* type */ | |
535 | 0, /* rightshift */ | |
536 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
537 | 12, /* bitsize */ | |
538 | TRUE, /* pc_relative */ | |
539 | 0, /* bitpos */ | |
540 | complain_overflow_dont,/* complain_on_overflow */ | |
541 | bfd_elf_generic_reloc, /* special_function */ | |
542 | "R_ARM_ALU_PCREL_7_0", /* name */ | |
543 | FALSE, /* partial_inplace */ | |
544 | 0x00000fff, /* src_mask */ | |
545 | 0x00000fff, /* dst_mask */ | |
546 | TRUE), /* pcrel_offset */ | |
547 | ||
548 | HOWTO (R_ARM_ALU_PCREL15_8, /* type */ | |
549 | 0, /* rightshift */ | |
550 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
551 | 12, /* bitsize */ | |
552 | TRUE, /* pc_relative */ | |
553 | 8, /* bitpos */ | |
554 | complain_overflow_dont,/* complain_on_overflow */ | |
555 | bfd_elf_generic_reloc, /* special_function */ | |
556 | "R_ARM_ALU_PCREL_15_8",/* name */ | |
557 | FALSE, /* partial_inplace */ | |
558 | 0x00000fff, /* src_mask */ | |
559 | 0x00000fff, /* dst_mask */ | |
560 | TRUE), /* pcrel_offset */ | |
561 | ||
562 | HOWTO (R_ARM_ALU_PCREL23_15, /* type */ | |
563 | 0, /* rightshift */ | |
564 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
565 | 12, /* bitsize */ | |
566 | TRUE, /* pc_relative */ | |
567 | 16, /* bitpos */ | |
568 | complain_overflow_dont,/* complain_on_overflow */ | |
569 | bfd_elf_generic_reloc, /* special_function */ | |
570 | "R_ARM_ALU_PCREL_23_15",/* name */ | |
571 | FALSE, /* partial_inplace */ | |
572 | 0x00000fff, /* src_mask */ | |
573 | 0x00000fff, /* dst_mask */ | |
574 | TRUE), /* pcrel_offset */ | |
575 | ||
576 | HOWTO (R_ARM_LDR_SBREL_11_0, /* type */ | |
577 | 0, /* rightshift */ | |
578 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
579 | 12, /* bitsize */ | |
580 | FALSE, /* pc_relative */ | |
581 | 0, /* bitpos */ | |
582 | complain_overflow_dont,/* complain_on_overflow */ | |
583 | bfd_elf_generic_reloc, /* special_function */ | |
584 | "R_ARM_LDR_SBREL_11_0",/* name */ | |
585 | FALSE, /* partial_inplace */ | |
586 | 0x00000fff, /* src_mask */ | |
587 | 0x00000fff, /* dst_mask */ | |
588 | FALSE), /* pcrel_offset */ | |
589 | ||
590 | HOWTO (R_ARM_ALU_SBREL_19_12, /* type */ | |
591 | 0, /* rightshift */ | |
592 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
593 | 8, /* bitsize */ | |
594 | FALSE, /* pc_relative */ | |
595 | 12, /* bitpos */ | |
596 | complain_overflow_dont,/* complain_on_overflow */ | |
597 | bfd_elf_generic_reloc, /* special_function */ | |
598 | "R_ARM_ALU_SBREL_19_12",/* name */ | |
599 | FALSE, /* partial_inplace */ | |
600 | 0x000ff000, /* src_mask */ | |
601 | 0x000ff000, /* dst_mask */ | |
602 | FALSE), /* pcrel_offset */ | |
603 | ||
604 | HOWTO (R_ARM_ALU_SBREL_27_20, /* type */ | |
605 | 0, /* rightshift */ | |
606 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
607 | 8, /* bitsize */ | |
608 | FALSE, /* pc_relative */ | |
609 | 20, /* bitpos */ | |
610 | complain_overflow_dont,/* complain_on_overflow */ | |
611 | bfd_elf_generic_reloc, /* special_function */ | |
612 | "R_ARM_ALU_SBREL_27_20",/* name */ | |
613 | FALSE, /* partial_inplace */ | |
614 | 0x0ff00000, /* src_mask */ | |
615 | 0x0ff00000, /* dst_mask */ | |
616 | FALSE), /* pcrel_offset */ | |
617 | ||
618 | HOWTO (R_ARM_TARGET1, /* type */ | |
619 | 0, /* rightshift */ | |
620 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
621 | 32, /* bitsize */ | |
622 | FALSE, /* pc_relative */ | |
623 | 0, /* bitpos */ | |
624 | complain_overflow_dont,/* complain_on_overflow */ | |
625 | bfd_elf_generic_reloc, /* special_function */ | |
626 | "R_ARM_TARGET1", /* name */ | |
627 | FALSE, /* partial_inplace */ | |
628 | 0xffffffff, /* src_mask */ | |
629 | 0xffffffff, /* dst_mask */ | |
630 | FALSE), /* pcrel_offset */ | |
631 | ||
632 | HOWTO (R_ARM_ROSEGREL32, /* type */ | |
633 | 0, /* rightshift */ | |
634 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
635 | 32, /* bitsize */ | |
636 | FALSE, /* pc_relative */ | |
637 | 0, /* bitpos */ | |
638 | complain_overflow_dont,/* complain_on_overflow */ | |
639 | bfd_elf_generic_reloc, /* special_function */ | |
640 | "R_ARM_ROSEGREL32", /* name */ | |
641 | FALSE, /* partial_inplace */ | |
642 | 0xffffffff, /* src_mask */ | |
643 | 0xffffffff, /* dst_mask */ | |
644 | FALSE), /* pcrel_offset */ | |
645 | ||
646 | HOWTO (R_ARM_V4BX, /* type */ | |
647 | 0, /* rightshift */ | |
648 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
649 | 32, /* bitsize */ | |
650 | FALSE, /* pc_relative */ | |
651 | 0, /* bitpos */ | |
652 | complain_overflow_dont,/* complain_on_overflow */ | |
653 | bfd_elf_generic_reloc, /* special_function */ | |
654 | "R_ARM_V4BX", /* name */ | |
655 | FALSE, /* partial_inplace */ | |
656 | 0xffffffff, /* src_mask */ | |
657 | 0xffffffff, /* dst_mask */ | |
658 | FALSE), /* pcrel_offset */ | |
659 | ||
660 | HOWTO (R_ARM_TARGET2, /* type */ | |
661 | 0, /* rightshift */ | |
662 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
663 | 32, /* bitsize */ | |
664 | FALSE, /* pc_relative */ | |
665 | 0, /* bitpos */ | |
666 | complain_overflow_signed,/* complain_on_overflow */ | |
667 | bfd_elf_generic_reloc, /* special_function */ | |
668 | "R_ARM_TARGET2", /* name */ | |
669 | FALSE, /* partial_inplace */ | |
670 | 0xffffffff, /* src_mask */ | |
671 | 0xffffffff, /* dst_mask */ | |
672 | TRUE), /* pcrel_offset */ | |
673 | ||
674 | HOWTO (R_ARM_PREL31, /* type */ | |
675 | 0, /* rightshift */ | |
676 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
677 | 31, /* bitsize */ | |
678 | TRUE, /* pc_relative */ | |
679 | 0, /* bitpos */ | |
680 | complain_overflow_signed,/* complain_on_overflow */ | |
681 | bfd_elf_generic_reloc, /* special_function */ | |
682 | "R_ARM_PREL31", /* name */ | |
683 | FALSE, /* partial_inplace */ | |
684 | 0x7fffffff, /* src_mask */ | |
685 | 0x7fffffff, /* dst_mask */ | |
686 | TRUE), /* pcrel_offset */ | |
c19d1205 ZW |
687 | |
688 | HOWTO (R_ARM_MOVW_ABS_NC, /* type */ | |
689 | 0, /* rightshift */ | |
690 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
691 | 16, /* bitsize */ | |
692 | FALSE, /* pc_relative */ | |
693 | 0, /* bitpos */ | |
694 | complain_overflow_dont,/* complain_on_overflow */ | |
695 | bfd_elf_generic_reloc, /* special_function */ | |
696 | "R_ARM_MOVW_ABS_NC", /* name */ | |
697 | FALSE, /* partial_inplace */ | |
698 | 0x0000ffff, /* src_mask */ | |
699 | 0x0000ffff, /* dst_mask */ | |
700 | FALSE), /* pcrel_offset */ | |
701 | ||
702 | HOWTO (R_ARM_MOVT_ABS, /* type */ | |
703 | 0, /* rightshift */ | |
704 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
705 | 16, /* bitsize */ | |
706 | FALSE, /* pc_relative */ | |
707 | 0, /* bitpos */ | |
708 | complain_overflow_bitfield,/* complain_on_overflow */ | |
709 | bfd_elf_generic_reloc, /* special_function */ | |
710 | "R_ARM_MOVT_ABS", /* name */ | |
711 | FALSE, /* partial_inplace */ | |
712 | 0x0000ffff, /* src_mask */ | |
713 | 0x0000ffff, /* dst_mask */ | |
714 | FALSE), /* pcrel_offset */ | |
715 | ||
716 | HOWTO (R_ARM_MOVW_PREL_NC, /* type */ | |
717 | 0, /* rightshift */ | |
718 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
719 | 16, /* bitsize */ | |
720 | TRUE, /* pc_relative */ | |
721 | 0, /* bitpos */ | |
722 | complain_overflow_dont,/* complain_on_overflow */ | |
723 | bfd_elf_generic_reloc, /* special_function */ | |
724 | "R_ARM_MOVW_PREL_NC", /* name */ | |
725 | FALSE, /* partial_inplace */ | |
726 | 0x0000ffff, /* src_mask */ | |
727 | 0x0000ffff, /* dst_mask */ | |
728 | TRUE), /* pcrel_offset */ | |
729 | ||
730 | HOWTO (R_ARM_MOVT_PREL, /* type */ | |
731 | 0, /* rightshift */ | |
732 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
733 | 16, /* bitsize */ | |
734 | TRUE, /* pc_relative */ | |
735 | 0, /* bitpos */ | |
736 | complain_overflow_bitfield,/* complain_on_overflow */ | |
737 | bfd_elf_generic_reloc, /* special_function */ | |
738 | "R_ARM_MOVT_PREL", /* name */ | |
739 | FALSE, /* partial_inplace */ | |
740 | 0x0000ffff, /* src_mask */ | |
741 | 0x0000ffff, /* dst_mask */ | |
742 | TRUE), /* pcrel_offset */ | |
743 | ||
744 | HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */ | |
745 | 0, /* rightshift */ | |
746 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
747 | 16, /* bitsize */ | |
748 | FALSE, /* pc_relative */ | |
749 | 0, /* bitpos */ | |
750 | complain_overflow_dont,/* complain_on_overflow */ | |
751 | bfd_elf_generic_reloc, /* special_function */ | |
752 | "R_ARM_THM_MOVW_ABS_NC",/* name */ | |
753 | FALSE, /* partial_inplace */ | |
754 | 0x040f70ff, /* src_mask */ | |
755 | 0x040f70ff, /* dst_mask */ | |
756 | FALSE), /* pcrel_offset */ | |
757 | ||
758 | HOWTO (R_ARM_THM_MOVT_ABS, /* type */ | |
759 | 0, /* rightshift */ | |
760 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
761 | 16, /* bitsize */ | |
762 | FALSE, /* pc_relative */ | |
763 | 0, /* bitpos */ | |
764 | complain_overflow_bitfield,/* complain_on_overflow */ | |
765 | bfd_elf_generic_reloc, /* special_function */ | |
766 | "R_ARM_THM_MOVT_ABS", /* name */ | |
767 | FALSE, /* partial_inplace */ | |
768 | 0x040f70ff, /* src_mask */ | |
769 | 0x040f70ff, /* dst_mask */ | |
770 | FALSE), /* pcrel_offset */ | |
771 | ||
772 | HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */ | |
773 | 0, /* rightshift */ | |
774 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
775 | 16, /* bitsize */ | |
776 | TRUE, /* pc_relative */ | |
777 | 0, /* bitpos */ | |
778 | complain_overflow_dont,/* complain_on_overflow */ | |
779 | bfd_elf_generic_reloc, /* special_function */ | |
780 | "R_ARM_THM_MOVW_PREL_NC",/* name */ | |
781 | FALSE, /* partial_inplace */ | |
782 | 0x040f70ff, /* src_mask */ | |
783 | 0x040f70ff, /* dst_mask */ | |
784 | TRUE), /* pcrel_offset */ | |
785 | ||
786 | HOWTO (R_ARM_THM_MOVT_PREL, /* type */ | |
787 | 0, /* rightshift */ | |
788 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
789 | 16, /* bitsize */ | |
790 | TRUE, /* pc_relative */ | |
791 | 0, /* bitpos */ | |
792 | complain_overflow_bitfield,/* complain_on_overflow */ | |
793 | bfd_elf_generic_reloc, /* special_function */ | |
794 | "R_ARM_THM_MOVT_PREL", /* name */ | |
795 | FALSE, /* partial_inplace */ | |
796 | 0x040f70ff, /* src_mask */ | |
797 | 0x040f70ff, /* dst_mask */ | |
798 | TRUE), /* pcrel_offset */ | |
799 | ||
800 | HOWTO (R_ARM_THM_JUMP19, /* type */ | |
801 | 1, /* rightshift */ | |
802 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
803 | 19, /* bitsize */ | |
804 | TRUE, /* pc_relative */ | |
805 | 0, /* bitpos */ | |
806 | complain_overflow_signed,/* complain_on_overflow */ | |
807 | bfd_elf_generic_reloc, /* special_function */ | |
808 | "R_ARM_THM_JUMP19", /* name */ | |
809 | FALSE, /* partial_inplace */ | |
810 | 0x043f2fff, /* src_mask */ | |
811 | 0x043f2fff, /* dst_mask */ | |
812 | TRUE), /* pcrel_offset */ | |
813 | ||
814 | HOWTO (R_ARM_THM_JUMP6, /* type */ | |
815 | 1, /* rightshift */ | |
816 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
817 | 6, /* bitsize */ | |
818 | TRUE, /* pc_relative */ | |
819 | 0, /* bitpos */ | |
820 | complain_overflow_unsigned,/* complain_on_overflow */ | |
821 | bfd_elf_generic_reloc, /* special_function */ | |
822 | "R_ARM_THM_JUMP6", /* name */ | |
823 | FALSE, /* partial_inplace */ | |
824 | 0x02f8, /* src_mask */ | |
825 | 0x02f8, /* dst_mask */ | |
826 | TRUE), /* pcrel_offset */ | |
827 | ||
828 | /* These are declared as 13-bit signed relocations because we can | |
829 | address -4095 .. 4095(base) by altering ADDW to SUBW or vice | |
830 | versa. */ | |
831 | HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */ | |
832 | 0, /* rightshift */ | |
833 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
834 | 13, /* bitsize */ | |
835 | TRUE, /* pc_relative */ | |
836 | 0, /* bitpos */ | |
2cab6cc3 | 837 | complain_overflow_dont,/* complain_on_overflow */ |
c19d1205 ZW |
838 | bfd_elf_generic_reloc, /* special_function */ |
839 | "R_ARM_THM_ALU_PREL_11_0",/* name */ | |
840 | FALSE, /* partial_inplace */ | |
2cab6cc3 MS |
841 | 0xffffffff, /* src_mask */ |
842 | 0xffffffff, /* dst_mask */ | |
c19d1205 ZW |
843 | TRUE), /* pcrel_offset */ |
844 | ||
845 | HOWTO (R_ARM_THM_PC12, /* type */ | |
846 | 0, /* rightshift */ | |
847 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
848 | 13, /* bitsize */ | |
849 | TRUE, /* pc_relative */ | |
850 | 0, /* bitpos */ | |
2cab6cc3 | 851 | complain_overflow_dont,/* complain_on_overflow */ |
c19d1205 ZW |
852 | bfd_elf_generic_reloc, /* special_function */ |
853 | "R_ARM_THM_PC12", /* name */ | |
854 | FALSE, /* partial_inplace */ | |
2cab6cc3 MS |
855 | 0xffffffff, /* src_mask */ |
856 | 0xffffffff, /* dst_mask */ | |
c19d1205 ZW |
857 | TRUE), /* pcrel_offset */ |
858 | ||
859 | HOWTO (R_ARM_ABS32_NOI, /* type */ | |
860 | 0, /* rightshift */ | |
861 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
862 | 32, /* bitsize */ | |
863 | FALSE, /* pc_relative */ | |
864 | 0, /* bitpos */ | |
865 | complain_overflow_dont,/* complain_on_overflow */ | |
866 | bfd_elf_generic_reloc, /* special_function */ | |
867 | "R_ARM_ABS32_NOI", /* name */ | |
868 | FALSE, /* partial_inplace */ | |
869 | 0xffffffff, /* src_mask */ | |
870 | 0xffffffff, /* dst_mask */ | |
871 | FALSE), /* pcrel_offset */ | |
872 | ||
873 | HOWTO (R_ARM_REL32_NOI, /* type */ | |
874 | 0, /* rightshift */ | |
875 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
876 | 32, /* bitsize */ | |
877 | TRUE, /* pc_relative */ | |
878 | 0, /* bitpos */ | |
879 | complain_overflow_dont,/* complain_on_overflow */ | |
880 | bfd_elf_generic_reloc, /* special_function */ | |
881 | "R_ARM_REL32_NOI", /* name */ | |
882 | FALSE, /* partial_inplace */ | |
883 | 0xffffffff, /* src_mask */ | |
884 | 0xffffffff, /* dst_mask */ | |
885 | FALSE), /* pcrel_offset */ | |
7f266840 | 886 | |
4962c51a MS |
887 | /* Group relocations. */ |
888 | ||
889 | HOWTO (R_ARM_ALU_PC_G0_NC, /* type */ | |
890 | 0, /* rightshift */ | |
891 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
892 | 32, /* bitsize */ | |
893 | TRUE, /* pc_relative */ | |
894 | 0, /* bitpos */ | |
895 | complain_overflow_dont,/* complain_on_overflow */ | |
896 | bfd_elf_generic_reloc, /* special_function */ | |
897 | "R_ARM_ALU_PC_G0_NC", /* name */ | |
898 | FALSE, /* partial_inplace */ | |
899 | 0xffffffff, /* src_mask */ | |
900 | 0xffffffff, /* dst_mask */ | |
901 | TRUE), /* pcrel_offset */ | |
902 | ||
903 | HOWTO (R_ARM_ALU_PC_G0, /* type */ | |
904 | 0, /* rightshift */ | |
905 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
906 | 32, /* bitsize */ | |
907 | TRUE, /* pc_relative */ | |
908 | 0, /* bitpos */ | |
909 | complain_overflow_dont,/* complain_on_overflow */ | |
910 | bfd_elf_generic_reloc, /* special_function */ | |
911 | "R_ARM_ALU_PC_G0", /* name */ | |
912 | FALSE, /* partial_inplace */ | |
913 | 0xffffffff, /* src_mask */ | |
914 | 0xffffffff, /* dst_mask */ | |
915 | TRUE), /* pcrel_offset */ | |
916 | ||
917 | HOWTO (R_ARM_ALU_PC_G1_NC, /* type */ | |
918 | 0, /* rightshift */ | |
919 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
920 | 32, /* bitsize */ | |
921 | TRUE, /* pc_relative */ | |
922 | 0, /* bitpos */ | |
923 | complain_overflow_dont,/* complain_on_overflow */ | |
924 | bfd_elf_generic_reloc, /* special_function */ | |
925 | "R_ARM_ALU_PC_G1_NC", /* name */ | |
926 | FALSE, /* partial_inplace */ | |
927 | 0xffffffff, /* src_mask */ | |
928 | 0xffffffff, /* dst_mask */ | |
929 | TRUE), /* pcrel_offset */ | |
930 | ||
931 | HOWTO (R_ARM_ALU_PC_G1, /* type */ | |
932 | 0, /* rightshift */ | |
933 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
934 | 32, /* bitsize */ | |
935 | TRUE, /* pc_relative */ | |
936 | 0, /* bitpos */ | |
937 | complain_overflow_dont,/* complain_on_overflow */ | |
938 | bfd_elf_generic_reloc, /* special_function */ | |
939 | "R_ARM_ALU_PC_G1", /* name */ | |
940 | FALSE, /* partial_inplace */ | |
941 | 0xffffffff, /* src_mask */ | |
942 | 0xffffffff, /* dst_mask */ | |
943 | TRUE), /* pcrel_offset */ | |
944 | ||
945 | HOWTO (R_ARM_ALU_PC_G2, /* type */ | |
946 | 0, /* rightshift */ | |
947 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
948 | 32, /* bitsize */ | |
949 | TRUE, /* pc_relative */ | |
950 | 0, /* bitpos */ | |
951 | complain_overflow_dont,/* complain_on_overflow */ | |
952 | bfd_elf_generic_reloc, /* special_function */ | |
953 | "R_ARM_ALU_PC_G2", /* name */ | |
954 | FALSE, /* partial_inplace */ | |
955 | 0xffffffff, /* src_mask */ | |
956 | 0xffffffff, /* dst_mask */ | |
957 | TRUE), /* pcrel_offset */ | |
958 | ||
959 | HOWTO (R_ARM_LDR_PC_G1, /* type */ | |
960 | 0, /* rightshift */ | |
961 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
962 | 32, /* bitsize */ | |
963 | TRUE, /* pc_relative */ | |
964 | 0, /* bitpos */ | |
965 | complain_overflow_dont,/* complain_on_overflow */ | |
966 | bfd_elf_generic_reloc, /* special_function */ | |
967 | "R_ARM_LDR_PC_G1", /* name */ | |
968 | FALSE, /* partial_inplace */ | |
969 | 0xffffffff, /* src_mask */ | |
970 | 0xffffffff, /* dst_mask */ | |
971 | TRUE), /* pcrel_offset */ | |
972 | ||
973 | HOWTO (R_ARM_LDR_PC_G2, /* type */ | |
974 | 0, /* rightshift */ | |
975 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
976 | 32, /* bitsize */ | |
977 | TRUE, /* pc_relative */ | |
978 | 0, /* bitpos */ | |
979 | complain_overflow_dont,/* complain_on_overflow */ | |
980 | bfd_elf_generic_reloc, /* special_function */ | |
981 | "R_ARM_LDR_PC_G2", /* name */ | |
982 | FALSE, /* partial_inplace */ | |
983 | 0xffffffff, /* src_mask */ | |
984 | 0xffffffff, /* dst_mask */ | |
985 | TRUE), /* pcrel_offset */ | |
986 | ||
987 | HOWTO (R_ARM_LDRS_PC_G0, /* type */ | |
988 | 0, /* rightshift */ | |
989 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
990 | 32, /* bitsize */ | |
991 | TRUE, /* pc_relative */ | |
992 | 0, /* bitpos */ | |
993 | complain_overflow_dont,/* complain_on_overflow */ | |
994 | bfd_elf_generic_reloc, /* special_function */ | |
995 | "R_ARM_LDRS_PC_G0", /* name */ | |
996 | FALSE, /* partial_inplace */ | |
997 | 0xffffffff, /* src_mask */ | |
998 | 0xffffffff, /* dst_mask */ | |
999 | TRUE), /* pcrel_offset */ | |
1000 | ||
1001 | HOWTO (R_ARM_LDRS_PC_G1, /* type */ | |
1002 | 0, /* rightshift */ | |
1003 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1004 | 32, /* bitsize */ | |
1005 | TRUE, /* pc_relative */ | |
1006 | 0, /* bitpos */ | |
1007 | complain_overflow_dont,/* complain_on_overflow */ | |
1008 | bfd_elf_generic_reloc, /* special_function */ | |
1009 | "R_ARM_LDRS_PC_G1", /* name */ | |
1010 | FALSE, /* partial_inplace */ | |
1011 | 0xffffffff, /* src_mask */ | |
1012 | 0xffffffff, /* dst_mask */ | |
1013 | TRUE), /* pcrel_offset */ | |
1014 | ||
1015 | HOWTO (R_ARM_LDRS_PC_G2, /* type */ | |
1016 | 0, /* rightshift */ | |
1017 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1018 | 32, /* bitsize */ | |
1019 | TRUE, /* pc_relative */ | |
1020 | 0, /* bitpos */ | |
1021 | complain_overflow_dont,/* complain_on_overflow */ | |
1022 | bfd_elf_generic_reloc, /* special_function */ | |
1023 | "R_ARM_LDRS_PC_G2", /* name */ | |
1024 | FALSE, /* partial_inplace */ | |
1025 | 0xffffffff, /* src_mask */ | |
1026 | 0xffffffff, /* dst_mask */ | |
1027 | TRUE), /* pcrel_offset */ | |
1028 | ||
1029 | HOWTO (R_ARM_LDC_PC_G0, /* type */ | |
1030 | 0, /* rightshift */ | |
1031 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1032 | 32, /* bitsize */ | |
1033 | TRUE, /* pc_relative */ | |
1034 | 0, /* bitpos */ | |
1035 | complain_overflow_dont,/* complain_on_overflow */ | |
1036 | bfd_elf_generic_reloc, /* special_function */ | |
1037 | "R_ARM_LDC_PC_G0", /* name */ | |
1038 | FALSE, /* partial_inplace */ | |
1039 | 0xffffffff, /* src_mask */ | |
1040 | 0xffffffff, /* dst_mask */ | |
1041 | TRUE), /* pcrel_offset */ | |
1042 | ||
1043 | HOWTO (R_ARM_LDC_PC_G1, /* type */ | |
1044 | 0, /* rightshift */ | |
1045 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1046 | 32, /* bitsize */ | |
1047 | TRUE, /* pc_relative */ | |
1048 | 0, /* bitpos */ | |
1049 | complain_overflow_dont,/* complain_on_overflow */ | |
1050 | bfd_elf_generic_reloc, /* special_function */ | |
1051 | "R_ARM_LDC_PC_G1", /* name */ | |
1052 | FALSE, /* partial_inplace */ | |
1053 | 0xffffffff, /* src_mask */ | |
1054 | 0xffffffff, /* dst_mask */ | |
1055 | TRUE), /* pcrel_offset */ | |
1056 | ||
1057 | HOWTO (R_ARM_LDC_PC_G2, /* type */ | |
1058 | 0, /* rightshift */ | |
1059 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1060 | 32, /* bitsize */ | |
1061 | TRUE, /* pc_relative */ | |
1062 | 0, /* bitpos */ | |
1063 | complain_overflow_dont,/* complain_on_overflow */ | |
1064 | bfd_elf_generic_reloc, /* special_function */ | |
1065 | "R_ARM_LDC_PC_G2", /* name */ | |
1066 | FALSE, /* partial_inplace */ | |
1067 | 0xffffffff, /* src_mask */ | |
1068 | 0xffffffff, /* dst_mask */ | |
1069 | TRUE), /* pcrel_offset */ | |
1070 | ||
1071 | HOWTO (R_ARM_ALU_SB_G0_NC, /* type */ | |
1072 | 0, /* rightshift */ | |
1073 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1074 | 32, /* bitsize */ | |
1075 | TRUE, /* pc_relative */ | |
1076 | 0, /* bitpos */ | |
1077 | complain_overflow_dont,/* complain_on_overflow */ | |
1078 | bfd_elf_generic_reloc, /* special_function */ | |
1079 | "R_ARM_ALU_SB_G0_NC", /* name */ | |
1080 | FALSE, /* partial_inplace */ | |
1081 | 0xffffffff, /* src_mask */ | |
1082 | 0xffffffff, /* dst_mask */ | |
1083 | TRUE), /* pcrel_offset */ | |
1084 | ||
1085 | HOWTO (R_ARM_ALU_SB_G0, /* type */ | |
1086 | 0, /* rightshift */ | |
1087 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1088 | 32, /* bitsize */ | |
1089 | TRUE, /* pc_relative */ | |
1090 | 0, /* bitpos */ | |
1091 | complain_overflow_dont,/* complain_on_overflow */ | |
1092 | bfd_elf_generic_reloc, /* special_function */ | |
1093 | "R_ARM_ALU_SB_G0", /* name */ | |
1094 | FALSE, /* partial_inplace */ | |
1095 | 0xffffffff, /* src_mask */ | |
1096 | 0xffffffff, /* dst_mask */ | |
1097 | TRUE), /* pcrel_offset */ | |
1098 | ||
1099 | HOWTO (R_ARM_ALU_SB_G1_NC, /* type */ | |
1100 | 0, /* rightshift */ | |
1101 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1102 | 32, /* bitsize */ | |
1103 | TRUE, /* pc_relative */ | |
1104 | 0, /* bitpos */ | |
1105 | complain_overflow_dont,/* complain_on_overflow */ | |
1106 | bfd_elf_generic_reloc, /* special_function */ | |
1107 | "R_ARM_ALU_SB_G1_NC", /* name */ | |
1108 | FALSE, /* partial_inplace */ | |
1109 | 0xffffffff, /* src_mask */ | |
1110 | 0xffffffff, /* dst_mask */ | |
1111 | TRUE), /* pcrel_offset */ | |
1112 | ||
1113 | HOWTO (R_ARM_ALU_SB_G1, /* type */ | |
1114 | 0, /* rightshift */ | |
1115 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1116 | 32, /* bitsize */ | |
1117 | TRUE, /* pc_relative */ | |
1118 | 0, /* bitpos */ | |
1119 | complain_overflow_dont,/* complain_on_overflow */ | |
1120 | bfd_elf_generic_reloc, /* special_function */ | |
1121 | "R_ARM_ALU_SB_G1", /* name */ | |
1122 | FALSE, /* partial_inplace */ | |
1123 | 0xffffffff, /* src_mask */ | |
1124 | 0xffffffff, /* dst_mask */ | |
1125 | TRUE), /* pcrel_offset */ | |
1126 | ||
1127 | HOWTO (R_ARM_ALU_SB_G2, /* type */ | |
1128 | 0, /* rightshift */ | |
1129 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1130 | 32, /* bitsize */ | |
1131 | TRUE, /* pc_relative */ | |
1132 | 0, /* bitpos */ | |
1133 | complain_overflow_dont,/* complain_on_overflow */ | |
1134 | bfd_elf_generic_reloc, /* special_function */ | |
1135 | "R_ARM_ALU_SB_G2", /* name */ | |
1136 | FALSE, /* partial_inplace */ | |
1137 | 0xffffffff, /* src_mask */ | |
1138 | 0xffffffff, /* dst_mask */ | |
1139 | TRUE), /* pcrel_offset */ | |
1140 | ||
1141 | HOWTO (R_ARM_LDR_SB_G0, /* type */ | |
1142 | 0, /* rightshift */ | |
1143 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1144 | 32, /* bitsize */ | |
1145 | TRUE, /* pc_relative */ | |
1146 | 0, /* bitpos */ | |
1147 | complain_overflow_dont,/* complain_on_overflow */ | |
1148 | bfd_elf_generic_reloc, /* special_function */ | |
1149 | "R_ARM_LDR_SB_G0", /* name */ | |
1150 | FALSE, /* partial_inplace */ | |
1151 | 0xffffffff, /* src_mask */ | |
1152 | 0xffffffff, /* dst_mask */ | |
1153 | TRUE), /* pcrel_offset */ | |
1154 | ||
1155 | HOWTO (R_ARM_LDR_SB_G1, /* type */ | |
1156 | 0, /* rightshift */ | |
1157 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1158 | 32, /* bitsize */ | |
1159 | TRUE, /* pc_relative */ | |
1160 | 0, /* bitpos */ | |
1161 | complain_overflow_dont,/* complain_on_overflow */ | |
1162 | bfd_elf_generic_reloc, /* special_function */ | |
1163 | "R_ARM_LDR_SB_G1", /* name */ | |
1164 | FALSE, /* partial_inplace */ | |
1165 | 0xffffffff, /* src_mask */ | |
1166 | 0xffffffff, /* dst_mask */ | |
1167 | TRUE), /* pcrel_offset */ | |
1168 | ||
1169 | HOWTO (R_ARM_LDR_SB_G2, /* type */ | |
1170 | 0, /* rightshift */ | |
1171 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1172 | 32, /* bitsize */ | |
1173 | TRUE, /* pc_relative */ | |
1174 | 0, /* bitpos */ | |
1175 | complain_overflow_dont,/* complain_on_overflow */ | |
1176 | bfd_elf_generic_reloc, /* special_function */ | |
1177 | "R_ARM_LDR_SB_G2", /* name */ | |
1178 | FALSE, /* partial_inplace */ | |
1179 | 0xffffffff, /* src_mask */ | |
1180 | 0xffffffff, /* dst_mask */ | |
1181 | TRUE), /* pcrel_offset */ | |
1182 | ||
1183 | HOWTO (R_ARM_LDRS_SB_G0, /* type */ | |
1184 | 0, /* rightshift */ | |
1185 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1186 | 32, /* bitsize */ | |
1187 | TRUE, /* pc_relative */ | |
1188 | 0, /* bitpos */ | |
1189 | complain_overflow_dont,/* complain_on_overflow */ | |
1190 | bfd_elf_generic_reloc, /* special_function */ | |
1191 | "R_ARM_LDRS_SB_G0", /* name */ | |
1192 | FALSE, /* partial_inplace */ | |
1193 | 0xffffffff, /* src_mask */ | |
1194 | 0xffffffff, /* dst_mask */ | |
1195 | TRUE), /* pcrel_offset */ | |
1196 | ||
1197 | HOWTO (R_ARM_LDRS_SB_G1, /* type */ | |
1198 | 0, /* rightshift */ | |
1199 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1200 | 32, /* bitsize */ | |
1201 | TRUE, /* pc_relative */ | |
1202 | 0, /* bitpos */ | |
1203 | complain_overflow_dont,/* complain_on_overflow */ | |
1204 | bfd_elf_generic_reloc, /* special_function */ | |
1205 | "R_ARM_LDRS_SB_G1", /* name */ | |
1206 | FALSE, /* partial_inplace */ | |
1207 | 0xffffffff, /* src_mask */ | |
1208 | 0xffffffff, /* dst_mask */ | |
1209 | TRUE), /* pcrel_offset */ | |
1210 | ||
1211 | HOWTO (R_ARM_LDRS_SB_G2, /* type */ | |
1212 | 0, /* rightshift */ | |
1213 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1214 | 32, /* bitsize */ | |
1215 | TRUE, /* pc_relative */ | |
1216 | 0, /* bitpos */ | |
1217 | complain_overflow_dont,/* complain_on_overflow */ | |
1218 | bfd_elf_generic_reloc, /* special_function */ | |
1219 | "R_ARM_LDRS_SB_G2", /* name */ | |
1220 | FALSE, /* partial_inplace */ | |
1221 | 0xffffffff, /* src_mask */ | |
1222 | 0xffffffff, /* dst_mask */ | |
1223 | TRUE), /* pcrel_offset */ | |
1224 | ||
1225 | HOWTO (R_ARM_LDC_SB_G0, /* type */ | |
1226 | 0, /* rightshift */ | |
1227 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1228 | 32, /* bitsize */ | |
1229 | TRUE, /* pc_relative */ | |
1230 | 0, /* bitpos */ | |
1231 | complain_overflow_dont,/* complain_on_overflow */ | |
1232 | bfd_elf_generic_reloc, /* special_function */ | |
1233 | "R_ARM_LDC_SB_G0", /* name */ | |
1234 | FALSE, /* partial_inplace */ | |
1235 | 0xffffffff, /* src_mask */ | |
1236 | 0xffffffff, /* dst_mask */ | |
1237 | TRUE), /* pcrel_offset */ | |
1238 | ||
1239 | HOWTO (R_ARM_LDC_SB_G1, /* type */ | |
1240 | 0, /* rightshift */ | |
1241 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1242 | 32, /* bitsize */ | |
1243 | TRUE, /* pc_relative */ | |
1244 | 0, /* bitpos */ | |
1245 | complain_overflow_dont,/* complain_on_overflow */ | |
1246 | bfd_elf_generic_reloc, /* special_function */ | |
1247 | "R_ARM_LDC_SB_G1", /* name */ | |
1248 | FALSE, /* partial_inplace */ | |
1249 | 0xffffffff, /* src_mask */ | |
1250 | 0xffffffff, /* dst_mask */ | |
1251 | TRUE), /* pcrel_offset */ | |
1252 | ||
1253 | HOWTO (R_ARM_LDC_SB_G2, /* type */ | |
1254 | 0, /* rightshift */ | |
1255 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1256 | 32, /* bitsize */ | |
1257 | TRUE, /* pc_relative */ | |
1258 | 0, /* bitpos */ | |
1259 | complain_overflow_dont,/* complain_on_overflow */ | |
1260 | bfd_elf_generic_reloc, /* special_function */ | |
1261 | "R_ARM_LDC_SB_G2", /* name */ | |
1262 | FALSE, /* partial_inplace */ | |
1263 | 0xffffffff, /* src_mask */ | |
1264 | 0xffffffff, /* dst_mask */ | |
1265 | TRUE), /* pcrel_offset */ | |
1266 | ||
1267 | /* End of group relocations. */ | |
c19d1205 | 1268 | |
c19d1205 ZW |
1269 | HOWTO (R_ARM_MOVW_BREL_NC, /* type */ |
1270 | 0, /* rightshift */ | |
1271 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1272 | 16, /* bitsize */ | |
1273 | FALSE, /* pc_relative */ | |
1274 | 0, /* bitpos */ | |
1275 | complain_overflow_dont,/* complain_on_overflow */ | |
1276 | bfd_elf_generic_reloc, /* special_function */ | |
1277 | "R_ARM_MOVW_BREL_NC", /* name */ | |
1278 | FALSE, /* partial_inplace */ | |
1279 | 0x0000ffff, /* src_mask */ | |
1280 | 0x0000ffff, /* dst_mask */ | |
1281 | FALSE), /* pcrel_offset */ | |
1282 | ||
1283 | HOWTO (R_ARM_MOVT_BREL, /* type */ | |
1284 | 0, /* rightshift */ | |
1285 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1286 | 16, /* bitsize */ | |
1287 | FALSE, /* pc_relative */ | |
1288 | 0, /* bitpos */ | |
1289 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1290 | bfd_elf_generic_reloc, /* special_function */ | |
1291 | "R_ARM_MOVT_BREL", /* name */ | |
1292 | FALSE, /* partial_inplace */ | |
1293 | 0x0000ffff, /* src_mask */ | |
1294 | 0x0000ffff, /* dst_mask */ | |
1295 | FALSE), /* pcrel_offset */ | |
1296 | ||
1297 | HOWTO (R_ARM_MOVW_BREL, /* type */ | |
1298 | 0, /* rightshift */ | |
1299 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1300 | 16, /* bitsize */ | |
1301 | FALSE, /* pc_relative */ | |
1302 | 0, /* bitpos */ | |
1303 | complain_overflow_dont,/* complain_on_overflow */ | |
1304 | bfd_elf_generic_reloc, /* special_function */ | |
1305 | "R_ARM_MOVW_BREL", /* name */ | |
1306 | FALSE, /* partial_inplace */ | |
1307 | 0x0000ffff, /* src_mask */ | |
1308 | 0x0000ffff, /* dst_mask */ | |
1309 | FALSE), /* pcrel_offset */ | |
1310 | ||
1311 | HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */ | |
1312 | 0, /* rightshift */ | |
1313 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1314 | 16, /* bitsize */ | |
1315 | FALSE, /* pc_relative */ | |
1316 | 0, /* bitpos */ | |
1317 | complain_overflow_dont,/* complain_on_overflow */ | |
1318 | bfd_elf_generic_reloc, /* special_function */ | |
1319 | "R_ARM_THM_MOVW_BREL_NC",/* name */ | |
1320 | FALSE, /* partial_inplace */ | |
1321 | 0x040f70ff, /* src_mask */ | |
1322 | 0x040f70ff, /* dst_mask */ | |
1323 | FALSE), /* pcrel_offset */ | |
1324 | ||
1325 | HOWTO (R_ARM_THM_MOVT_BREL, /* type */ | |
1326 | 0, /* rightshift */ | |
1327 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1328 | 16, /* bitsize */ | |
1329 | FALSE, /* pc_relative */ | |
1330 | 0, /* bitpos */ | |
1331 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1332 | bfd_elf_generic_reloc, /* special_function */ | |
1333 | "R_ARM_THM_MOVT_BREL", /* name */ | |
1334 | FALSE, /* partial_inplace */ | |
1335 | 0x040f70ff, /* src_mask */ | |
1336 | 0x040f70ff, /* dst_mask */ | |
1337 | FALSE), /* pcrel_offset */ | |
1338 | ||
1339 | HOWTO (R_ARM_THM_MOVW_BREL, /* type */ | |
1340 | 0, /* rightshift */ | |
1341 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1342 | 16, /* bitsize */ | |
1343 | FALSE, /* pc_relative */ | |
1344 | 0, /* bitpos */ | |
1345 | complain_overflow_dont,/* complain_on_overflow */ | |
1346 | bfd_elf_generic_reloc, /* special_function */ | |
1347 | "R_ARM_THM_MOVW_BREL", /* name */ | |
1348 | FALSE, /* partial_inplace */ | |
1349 | 0x040f70ff, /* src_mask */ | |
1350 | 0x040f70ff, /* dst_mask */ | |
1351 | FALSE), /* pcrel_offset */ | |
1352 | ||
1353 | EMPTY_HOWTO (90), /* unallocated */ | |
1354 | EMPTY_HOWTO (91), | |
1355 | EMPTY_HOWTO (92), | |
1356 | EMPTY_HOWTO (93), | |
1357 | ||
1358 | HOWTO (R_ARM_PLT32_ABS, /* type */ | |
1359 | 0, /* rightshift */ | |
1360 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1361 | 32, /* bitsize */ | |
1362 | FALSE, /* pc_relative */ | |
1363 | 0, /* bitpos */ | |
1364 | complain_overflow_dont,/* complain_on_overflow */ | |
1365 | bfd_elf_generic_reloc, /* special_function */ | |
1366 | "R_ARM_PLT32_ABS", /* name */ | |
1367 | FALSE, /* partial_inplace */ | |
1368 | 0xffffffff, /* src_mask */ | |
1369 | 0xffffffff, /* dst_mask */ | |
1370 | FALSE), /* pcrel_offset */ | |
1371 | ||
1372 | HOWTO (R_ARM_GOT_ABS, /* type */ | |
1373 | 0, /* rightshift */ | |
1374 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1375 | 32, /* bitsize */ | |
1376 | FALSE, /* pc_relative */ | |
1377 | 0, /* bitpos */ | |
1378 | complain_overflow_dont,/* complain_on_overflow */ | |
1379 | bfd_elf_generic_reloc, /* special_function */ | |
1380 | "R_ARM_GOT_ABS", /* name */ | |
1381 | FALSE, /* partial_inplace */ | |
1382 | 0xffffffff, /* src_mask */ | |
1383 | 0xffffffff, /* dst_mask */ | |
1384 | FALSE), /* pcrel_offset */ | |
1385 | ||
1386 | HOWTO (R_ARM_GOT_PREL, /* type */ | |
1387 | 0, /* rightshift */ | |
1388 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1389 | 32, /* bitsize */ | |
1390 | TRUE, /* pc_relative */ | |
1391 | 0, /* bitpos */ | |
1392 | complain_overflow_dont, /* complain_on_overflow */ | |
1393 | bfd_elf_generic_reloc, /* special_function */ | |
1394 | "R_ARM_GOT_PREL", /* name */ | |
1395 | FALSE, /* partial_inplace */ | |
1396 | 0xffffffff, /* src_mask */ | |
1397 | 0xffffffff, /* dst_mask */ | |
1398 | TRUE), /* pcrel_offset */ | |
1399 | ||
1400 | HOWTO (R_ARM_GOT_BREL12, /* type */ | |
1401 | 0, /* rightshift */ | |
1402 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1403 | 12, /* bitsize */ | |
1404 | FALSE, /* pc_relative */ | |
1405 | 0, /* bitpos */ | |
1406 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1407 | bfd_elf_generic_reloc, /* special_function */ | |
1408 | "R_ARM_GOT_BREL12", /* name */ | |
1409 | FALSE, /* partial_inplace */ | |
1410 | 0x00000fff, /* src_mask */ | |
1411 | 0x00000fff, /* dst_mask */ | |
1412 | FALSE), /* pcrel_offset */ | |
1413 | ||
1414 | HOWTO (R_ARM_GOTOFF12, /* type */ | |
1415 | 0, /* rightshift */ | |
1416 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1417 | 12, /* bitsize */ | |
1418 | FALSE, /* pc_relative */ | |
1419 | 0, /* bitpos */ | |
1420 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1421 | bfd_elf_generic_reloc, /* special_function */ | |
1422 | "R_ARM_GOTOFF12", /* name */ | |
1423 | FALSE, /* partial_inplace */ | |
1424 | 0x00000fff, /* src_mask */ | |
1425 | 0x00000fff, /* dst_mask */ | |
1426 | FALSE), /* pcrel_offset */ | |
1427 | ||
1428 | EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */ | |
1429 | ||
1430 | /* GNU extension to record C++ vtable member usage */ | |
1431 | HOWTO (R_ARM_GNU_VTENTRY, /* type */ | |
ba93b8ac DJ |
1432 | 0, /* rightshift */ |
1433 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1434 | 0, /* bitsize */ |
ba93b8ac DJ |
1435 | FALSE, /* pc_relative */ |
1436 | 0, /* bitpos */ | |
c19d1205 ZW |
1437 | complain_overflow_dont, /* complain_on_overflow */ |
1438 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
1439 | "R_ARM_GNU_VTENTRY", /* name */ | |
1440 | FALSE, /* partial_inplace */ | |
1441 | 0, /* src_mask */ | |
1442 | 0, /* dst_mask */ | |
1443 | FALSE), /* pcrel_offset */ | |
1444 | ||
1445 | /* GNU extension to record C++ vtable hierarchy */ | |
1446 | HOWTO (R_ARM_GNU_VTINHERIT, /* type */ | |
1447 | 0, /* rightshift */ | |
1448 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1449 | 0, /* bitsize */ | |
1450 | FALSE, /* pc_relative */ | |
1451 | 0, /* bitpos */ | |
1452 | complain_overflow_dont, /* complain_on_overflow */ | |
1453 | NULL, /* special_function */ | |
1454 | "R_ARM_GNU_VTINHERIT", /* name */ | |
1455 | FALSE, /* partial_inplace */ | |
1456 | 0, /* src_mask */ | |
1457 | 0, /* dst_mask */ | |
1458 | FALSE), /* pcrel_offset */ | |
1459 | ||
1460 | HOWTO (R_ARM_THM_JUMP11, /* type */ | |
1461 | 1, /* rightshift */ | |
1462 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1463 | 11, /* bitsize */ | |
1464 | TRUE, /* pc_relative */ | |
1465 | 0, /* bitpos */ | |
1466 | complain_overflow_signed, /* complain_on_overflow */ | |
1467 | bfd_elf_generic_reloc, /* special_function */ | |
1468 | "R_ARM_THM_JUMP11", /* name */ | |
1469 | FALSE, /* partial_inplace */ | |
1470 | 0x000007ff, /* src_mask */ | |
1471 | 0x000007ff, /* dst_mask */ | |
1472 | TRUE), /* pcrel_offset */ | |
1473 | ||
1474 | HOWTO (R_ARM_THM_JUMP8, /* type */ | |
1475 | 1, /* rightshift */ | |
1476 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1477 | 8, /* bitsize */ | |
1478 | TRUE, /* pc_relative */ | |
1479 | 0, /* bitpos */ | |
1480 | complain_overflow_signed, /* complain_on_overflow */ | |
1481 | bfd_elf_generic_reloc, /* special_function */ | |
1482 | "R_ARM_THM_JUMP8", /* name */ | |
1483 | FALSE, /* partial_inplace */ | |
1484 | 0x000000ff, /* src_mask */ | |
1485 | 0x000000ff, /* dst_mask */ | |
1486 | TRUE), /* pcrel_offset */ | |
ba93b8ac | 1487 | |
c19d1205 ZW |
1488 | /* TLS relocations */ |
1489 | HOWTO (R_ARM_TLS_GD32, /* type */ | |
ba93b8ac DJ |
1490 | 0, /* rightshift */ |
1491 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1492 | 32, /* bitsize */ | |
1493 | FALSE, /* pc_relative */ | |
1494 | 0, /* bitpos */ | |
1495 | complain_overflow_bitfield,/* complain_on_overflow */ | |
c19d1205 ZW |
1496 | NULL, /* special_function */ |
1497 | "R_ARM_TLS_GD32", /* name */ | |
ba93b8ac DJ |
1498 | TRUE, /* partial_inplace */ |
1499 | 0xffffffff, /* src_mask */ | |
1500 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1501 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1502 | |
ba93b8ac DJ |
1503 | HOWTO (R_ARM_TLS_LDM32, /* type */ |
1504 | 0, /* rightshift */ | |
1505 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1506 | 32, /* bitsize */ | |
1507 | FALSE, /* pc_relative */ | |
1508 | 0, /* bitpos */ | |
1509 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1510 | bfd_elf_generic_reloc, /* special_function */ | |
1511 | "R_ARM_TLS_LDM32", /* name */ | |
1512 | TRUE, /* partial_inplace */ | |
1513 | 0xffffffff, /* src_mask */ | |
1514 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1515 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1516 | |
c19d1205 | 1517 | HOWTO (R_ARM_TLS_LDO32, /* type */ |
ba93b8ac DJ |
1518 | 0, /* rightshift */ |
1519 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1520 | 32, /* bitsize */ | |
1521 | FALSE, /* pc_relative */ | |
1522 | 0, /* bitpos */ | |
1523 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1524 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 1525 | "R_ARM_TLS_LDO32", /* name */ |
ba93b8ac DJ |
1526 | TRUE, /* partial_inplace */ |
1527 | 0xffffffff, /* src_mask */ | |
1528 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1529 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1530 | |
ba93b8ac DJ |
1531 | HOWTO (R_ARM_TLS_IE32, /* type */ |
1532 | 0, /* rightshift */ | |
1533 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1534 | 32, /* bitsize */ | |
1535 | FALSE, /* pc_relative */ | |
1536 | 0, /* bitpos */ | |
1537 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1538 | NULL, /* special_function */ | |
1539 | "R_ARM_TLS_IE32", /* name */ | |
1540 | TRUE, /* partial_inplace */ | |
1541 | 0xffffffff, /* src_mask */ | |
1542 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1543 | FALSE), /* pcrel_offset */ |
7f266840 | 1544 | |
c19d1205 | 1545 | HOWTO (R_ARM_TLS_LE32, /* type */ |
7f266840 DJ |
1546 | 0, /* rightshift */ |
1547 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1548 | 32, /* bitsize */ |
7f266840 DJ |
1549 | FALSE, /* pc_relative */ |
1550 | 0, /* bitpos */ | |
c19d1205 ZW |
1551 | complain_overflow_bitfield,/* complain_on_overflow */ |
1552 | bfd_elf_generic_reloc, /* special_function */ | |
1553 | "R_ARM_TLS_LE32", /* name */ | |
1554 | TRUE, /* partial_inplace */ | |
1555 | 0xffffffff, /* src_mask */ | |
1556 | 0xffffffff, /* dst_mask */ | |
1557 | FALSE), /* pcrel_offset */ | |
7f266840 | 1558 | |
c19d1205 ZW |
1559 | HOWTO (R_ARM_TLS_LDO12, /* type */ |
1560 | 0, /* rightshift */ | |
1561 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1562 | 12, /* bitsize */ | |
1563 | FALSE, /* pc_relative */ | |
7f266840 | 1564 | 0, /* bitpos */ |
c19d1205 | 1565 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1566 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1567 | "R_ARM_TLS_LDO12", /* name */ |
7f266840 | 1568 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1569 | 0x00000fff, /* src_mask */ |
1570 | 0x00000fff, /* dst_mask */ | |
1571 | FALSE), /* pcrel_offset */ | |
7f266840 | 1572 | |
c19d1205 ZW |
1573 | HOWTO (R_ARM_TLS_LE12, /* type */ |
1574 | 0, /* rightshift */ | |
1575 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1576 | 12, /* bitsize */ | |
1577 | FALSE, /* pc_relative */ | |
7f266840 | 1578 | 0, /* bitpos */ |
c19d1205 | 1579 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1580 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1581 | "R_ARM_TLS_LE12", /* name */ |
7f266840 | 1582 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1583 | 0x00000fff, /* src_mask */ |
1584 | 0x00000fff, /* dst_mask */ | |
1585 | FALSE), /* pcrel_offset */ | |
7f266840 | 1586 | |
c19d1205 | 1587 | HOWTO (R_ARM_TLS_IE12GP, /* type */ |
7f266840 DJ |
1588 | 0, /* rightshift */ |
1589 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 ZW |
1590 | 12, /* bitsize */ |
1591 | FALSE, /* pc_relative */ | |
7f266840 | 1592 | 0, /* bitpos */ |
c19d1205 | 1593 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1594 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1595 | "R_ARM_TLS_IE12GP", /* name */ |
7f266840 | 1596 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1597 | 0x00000fff, /* src_mask */ |
1598 | 0x00000fff, /* dst_mask */ | |
1599 | FALSE), /* pcrel_offset */ | |
1600 | }; | |
1601 | ||
1602 | /* 112-127 private relocations | |
1603 | 128 R_ARM_ME_TOO, obsolete | |
1604 | 129-255 unallocated in AAELF. | |
7f266840 | 1605 | |
c19d1205 ZW |
1606 | 249-255 extended, currently unused, relocations: */ |
1607 | ||
4962c51a | 1608 | static reloc_howto_type elf32_arm_howto_table_2[4] = |
7f266840 DJ |
1609 | { |
1610 | HOWTO (R_ARM_RREL32, /* type */ | |
1611 | 0, /* rightshift */ | |
1612 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1613 | 0, /* bitsize */ | |
1614 | FALSE, /* pc_relative */ | |
1615 | 0, /* bitpos */ | |
1616 | complain_overflow_dont,/* complain_on_overflow */ | |
1617 | bfd_elf_generic_reloc, /* special_function */ | |
1618 | "R_ARM_RREL32", /* name */ | |
1619 | FALSE, /* partial_inplace */ | |
1620 | 0, /* src_mask */ | |
1621 | 0, /* dst_mask */ | |
1622 | FALSE), /* pcrel_offset */ | |
1623 | ||
1624 | HOWTO (R_ARM_RABS32, /* type */ | |
1625 | 0, /* rightshift */ | |
1626 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1627 | 0, /* bitsize */ | |
1628 | FALSE, /* pc_relative */ | |
1629 | 0, /* bitpos */ | |
1630 | complain_overflow_dont,/* complain_on_overflow */ | |
1631 | bfd_elf_generic_reloc, /* special_function */ | |
1632 | "R_ARM_RABS32", /* name */ | |
1633 | FALSE, /* partial_inplace */ | |
1634 | 0, /* src_mask */ | |
1635 | 0, /* dst_mask */ | |
1636 | FALSE), /* pcrel_offset */ | |
1637 | ||
1638 | HOWTO (R_ARM_RPC24, /* type */ | |
1639 | 0, /* rightshift */ | |
1640 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1641 | 0, /* bitsize */ | |
1642 | FALSE, /* pc_relative */ | |
1643 | 0, /* bitpos */ | |
1644 | complain_overflow_dont,/* complain_on_overflow */ | |
1645 | bfd_elf_generic_reloc, /* special_function */ | |
1646 | "R_ARM_RPC24", /* name */ | |
1647 | FALSE, /* partial_inplace */ | |
1648 | 0, /* src_mask */ | |
1649 | 0, /* dst_mask */ | |
1650 | FALSE), /* pcrel_offset */ | |
1651 | ||
1652 | HOWTO (R_ARM_RBASE, /* type */ | |
1653 | 0, /* rightshift */ | |
1654 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1655 | 0, /* bitsize */ | |
1656 | FALSE, /* pc_relative */ | |
1657 | 0, /* bitpos */ | |
1658 | complain_overflow_dont,/* complain_on_overflow */ | |
1659 | bfd_elf_generic_reloc, /* special_function */ | |
1660 | "R_ARM_RBASE", /* name */ | |
1661 | FALSE, /* partial_inplace */ | |
1662 | 0, /* src_mask */ | |
1663 | 0, /* dst_mask */ | |
1664 | FALSE) /* pcrel_offset */ | |
1665 | }; | |
1666 | ||
1667 | static reloc_howto_type * | |
1668 | elf32_arm_howto_from_type (unsigned int r_type) | |
1669 | { | |
c19d1205 ZW |
1670 | if (r_type < NUM_ELEM (elf32_arm_howto_table_1)) |
1671 | return &elf32_arm_howto_table_1[r_type]; | |
ba93b8ac | 1672 | |
c19d1205 ZW |
1673 | if (r_type >= R_ARM_RREL32 |
1674 | && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2)) | |
4962c51a | 1675 | return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32]; |
7f266840 | 1676 | |
c19d1205 | 1677 | return NULL; |
7f266840 DJ |
1678 | } |
1679 | ||
1680 | static void | |
1681 | elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, | |
1682 | Elf_Internal_Rela * elf_reloc) | |
1683 | { | |
1684 | unsigned int r_type; | |
1685 | ||
1686 | r_type = ELF32_R_TYPE (elf_reloc->r_info); | |
1687 | bfd_reloc->howto = elf32_arm_howto_from_type (r_type); | |
1688 | } | |
1689 | ||
1690 | struct elf32_arm_reloc_map | |
1691 | { | |
1692 | bfd_reloc_code_real_type bfd_reloc_val; | |
1693 | unsigned char elf_reloc_val; | |
1694 | }; | |
1695 | ||
1696 | /* All entries in this list must also be present in elf32_arm_howto_table. */ | |
1697 | static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = | |
1698 | { | |
1699 | {BFD_RELOC_NONE, R_ARM_NONE}, | |
1700 | {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24}, | |
39b41c9c PB |
1701 | {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL}, |
1702 | {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24}, | |
7f266840 DJ |
1703 | {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25}, |
1704 | {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22}, | |
1705 | {BFD_RELOC_32, R_ARM_ABS32}, | |
1706 | {BFD_RELOC_32_PCREL, R_ARM_REL32}, | |
1707 | {BFD_RELOC_8, R_ARM_ABS8}, | |
1708 | {BFD_RELOC_16, R_ARM_ABS16}, | |
1709 | {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12}, | |
1710 | {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5}, | |
c19d1205 ZW |
1711 | {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24}, |
1712 | {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL}, | |
1713 | {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11}, | |
1714 | {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19}, | |
1715 | {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8}, | |
1716 | {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6}, | |
7f266840 DJ |
1717 | {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT}, |
1718 | {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT}, | |
1719 | {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE}, | |
c19d1205 | 1720 | {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32}, |
7f266840 DJ |
1721 | {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC}, |
1722 | {BFD_RELOC_ARM_GOT32, R_ARM_GOT32}, | |
1723 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1724 | {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1}, | |
1725 | {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32}, | |
1726 | {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32}, | |
1727 | {BFD_RELOC_ARM_PREL31, R_ARM_PREL31}, | |
ba93b8ac DJ |
1728 | {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}, |
1729 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1730 | {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32}, | |
1731 | {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32}, | |
1732 | {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32}, | |
1733 | {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32}, | |
1734 | {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32}, | |
1735 | {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32}, | |
1736 | {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, | |
1737 | {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, | |
c19d1205 ZW |
1738 | {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT}, |
1739 | {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY}, | |
b6895b4f PB |
1740 | {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC}, |
1741 | {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS}, | |
1742 | {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC}, | |
1743 | {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL}, | |
1744 | {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC}, | |
1745 | {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS}, | |
1746 | {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC}, | |
1747 | {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL}, | |
4962c51a MS |
1748 | {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC}, |
1749 | {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0}, | |
1750 | {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC}, | |
1751 | {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1}, | |
1752 | {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2}, | |
1753 | {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0}, | |
1754 | {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1}, | |
1755 | {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2}, | |
1756 | {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0}, | |
1757 | {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1}, | |
1758 | {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2}, | |
1759 | {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0}, | |
1760 | {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1}, | |
1761 | {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2}, | |
1762 | {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC}, | |
1763 | {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0}, | |
1764 | {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC}, | |
1765 | {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1}, | |
1766 | {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2}, | |
1767 | {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0}, | |
1768 | {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1}, | |
1769 | {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2}, | |
1770 | {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0}, | |
1771 | {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1}, | |
1772 | {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2}, | |
1773 | {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0}, | |
1774 | {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1}, | |
1775 | {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2} | |
7f266840 DJ |
1776 | }; |
1777 | ||
1778 | static reloc_howto_type * | |
f1c71a59 ZW |
1779 | elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1780 | bfd_reloc_code_real_type code) | |
7f266840 DJ |
1781 | { |
1782 | unsigned int i; | |
c19d1205 ZW |
1783 | for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++) |
1784 | if (elf32_arm_reloc_map[i].bfd_reloc_val == code) | |
1785 | return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val); | |
7f266840 | 1786 | |
c19d1205 | 1787 | return NULL; |
7f266840 DJ |
1788 | } |
1789 | ||
157090f7 AM |
1790 | static reloc_howto_type * |
1791 | elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1792 | const char *r_name) | |
1793 | { | |
1794 | unsigned int i; | |
1795 | ||
1796 | for (i = 0; | |
1797 | i < (sizeof (elf32_arm_howto_table_1) | |
1798 | / sizeof (elf32_arm_howto_table_1[0])); | |
1799 | i++) | |
1800 | if (elf32_arm_howto_table_1[i].name != NULL | |
1801 | && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0) | |
1802 | return &elf32_arm_howto_table_1[i]; | |
1803 | ||
1804 | for (i = 0; | |
1805 | i < (sizeof (elf32_arm_howto_table_2) | |
1806 | / sizeof (elf32_arm_howto_table_2[0])); | |
1807 | i++) | |
1808 | if (elf32_arm_howto_table_2[i].name != NULL | |
1809 | && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0) | |
1810 | return &elf32_arm_howto_table_2[i]; | |
1811 | ||
1812 | return NULL; | |
1813 | } | |
1814 | ||
7f266840 DJ |
1815 | /* Support for core dump NOTE sections */ |
1816 | static bfd_boolean | |
f1c71a59 | 1817 | elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
7f266840 DJ |
1818 | { |
1819 | int offset; | |
1820 | size_t size; | |
1821 | ||
1822 | switch (note->descsz) | |
1823 | { | |
1824 | default: | |
1825 | return FALSE; | |
1826 | ||
1827 | case 148: /* Linux/ARM 32-bit*/ | |
1828 | /* pr_cursig */ | |
1829 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
1830 | ||
1831 | /* pr_pid */ | |
1832 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
1833 | ||
1834 | /* pr_reg */ | |
1835 | offset = 72; | |
1836 | size = 72; | |
1837 | ||
1838 | break; | |
1839 | } | |
1840 | ||
1841 | /* Make a ".reg/999" section. */ | |
1842 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1843 | size, note->descpos + offset); | |
1844 | } | |
1845 | ||
1846 | static bfd_boolean | |
f1c71a59 | 1847 | elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
7f266840 DJ |
1848 | { |
1849 | switch (note->descsz) | |
1850 | { | |
1851 | default: | |
1852 | return FALSE; | |
1853 | ||
1854 | case 124: /* Linux/ARM elf_prpsinfo */ | |
1855 | elf_tdata (abfd)->core_program | |
1856 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); | |
1857 | elf_tdata (abfd)->core_command | |
1858 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); | |
1859 | } | |
1860 | ||
1861 | /* Note that for some reason, a spurious space is tacked | |
1862 | onto the end of the args in some (at least one anyway) | |
1863 | implementations, so strip it off if it exists. */ | |
1864 | ||
1865 | { | |
1866 | char *command = elf_tdata (abfd)->core_command; | |
1867 | int n = strlen (command); | |
1868 | ||
1869 | if (0 < n && command[n - 1] == ' ') | |
1870 | command[n - 1] = '\0'; | |
1871 | } | |
1872 | ||
1873 | return TRUE; | |
1874 | } | |
1875 | ||
1876 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec | |
1877 | #define TARGET_LITTLE_NAME "elf32-littlearm" | |
1878 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vec | |
1879 | #define TARGET_BIG_NAME "elf32-bigarm" | |
1880 | ||
1881 | #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus | |
1882 | #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo | |
1883 | ||
252b5132 RH |
1884 | typedef unsigned long int insn32; |
1885 | typedef unsigned short int insn16; | |
1886 | ||
3a4a14e9 PB |
1887 | /* In lieu of proper flags, assume all EABIv4 or later objects are |
1888 | interworkable. */ | |
57e8b36a | 1889 | #define INTERWORK_FLAG(abfd) \ |
3a4a14e9 | 1890 | (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \ |
85a84e7a | 1891 | || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)) |
9b485d32 | 1892 | |
252b5132 RH |
1893 | /* The linker script knows the section names for placement. |
1894 | The entry_names are used to do simple name mangling on the stubs. | |
1895 | Given a function name, and its type, the stub can be found. The | |
9b485d32 | 1896 | name can be changed. The only requirement is the %s be present. */ |
252b5132 RH |
1897 | #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" |
1898 | #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" | |
1899 | ||
1900 | #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" | |
1901 | #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" | |
1902 | ||
c7b8f16e JB |
1903 | #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer" |
1904 | #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x" | |
1905 | ||
252b5132 RH |
1906 | /* The name of the dynamic interpreter. This is put in the .interp |
1907 | section. */ | |
1908 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
1909 | ||
5e681ec4 PB |
1910 | #ifdef FOUR_WORD_PLT |
1911 | ||
252b5132 RH |
1912 | /* The first entry in a procedure linkage table looks like |
1913 | this. It is set up so that any shared library function that is | |
59f2c4e7 | 1914 | called before the relocation has been set up calls the dynamic |
9b485d32 | 1915 | linker first. */ |
e5a52504 | 1916 | static const bfd_vma elf32_arm_plt0_entry [] = |
5e681ec4 PB |
1917 | { |
1918 | 0xe52de004, /* str lr, [sp, #-4]! */ | |
1919 | 0xe59fe010, /* ldr lr, [pc, #16] */ | |
1920 | 0xe08fe00e, /* add lr, pc, lr */ | |
1921 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1922 | }; | |
1923 | ||
1924 | /* Subsequent entries in a procedure linkage table look like | |
1925 | this. */ | |
e5a52504 | 1926 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1927 | { |
1928 | 0xe28fc600, /* add ip, pc, #NN */ | |
1929 | 0xe28cca00, /* add ip, ip, #NN */ | |
1930 | 0xe5bcf000, /* ldr pc, [ip, #NN]! */ | |
1931 | 0x00000000, /* unused */ | |
1932 | }; | |
1933 | ||
1934 | #else | |
1935 | ||
5e681ec4 PB |
1936 | /* The first entry in a procedure linkage table looks like |
1937 | this. It is set up so that any shared library function that is | |
1938 | called before the relocation has been set up calls the dynamic | |
1939 | linker first. */ | |
e5a52504 | 1940 | static const bfd_vma elf32_arm_plt0_entry [] = |
917583ad | 1941 | { |
5e681ec4 PB |
1942 | 0xe52de004, /* str lr, [sp, #-4]! */ |
1943 | 0xe59fe004, /* ldr lr, [pc, #4] */ | |
1944 | 0xe08fe00e, /* add lr, pc, lr */ | |
1945 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1946 | 0x00000000, /* &GOT[0] - . */ | |
917583ad | 1947 | }; |
252b5132 RH |
1948 | |
1949 | /* Subsequent entries in a procedure linkage table look like | |
1950 | this. */ | |
e5a52504 | 1951 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1952 | { |
1953 | 0xe28fc600, /* add ip, pc, #0xNN00000 */ | |
1954 | 0xe28cca00, /* add ip, ip, #0xNN000 */ | |
1955 | 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ | |
1956 | }; | |
1957 | ||
1958 | #endif | |
252b5132 | 1959 | |
00a97672 RS |
1960 | /* The format of the first entry in the procedure linkage table |
1961 | for a VxWorks executable. */ | |
1962 | static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] = | |
1963 | { | |
1964 | 0xe52dc008, /* str ip,[sp,#-8]! */ | |
1965 | 0xe59fc000, /* ldr ip,[pc] */ | |
1966 | 0xe59cf008, /* ldr pc,[ip,#8] */ | |
1967 | 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */ | |
1968 | }; | |
1969 | ||
1970 | /* The format of subsequent entries in a VxWorks executable. */ | |
1971 | static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] = | |
1972 | { | |
1973 | 0xe59fc000, /* ldr ip,[pc] */ | |
1974 | 0xe59cf000, /* ldr pc,[ip] */ | |
1975 | 0x00000000, /* .long @got */ | |
1976 | 0xe59fc000, /* ldr ip,[pc] */ | |
1977 | 0xea000000, /* b _PLT */ | |
1978 | 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ | |
1979 | }; | |
1980 | ||
1981 | /* The format of entries in a VxWorks shared library. */ | |
1982 | static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] = | |
1983 | { | |
1984 | 0xe59fc000, /* ldr ip,[pc] */ | |
1985 | 0xe79cf009, /* ldr pc,[ip,r9] */ | |
1986 | 0x00000000, /* .long @got */ | |
1987 | 0xe59fc000, /* ldr ip,[pc] */ | |
1988 | 0xe599f008, /* ldr pc,[r9,#8] */ | |
1989 | 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ | |
1990 | }; | |
1991 | ||
b7693d02 DJ |
1992 | /* An initial stub used if the PLT entry is referenced from Thumb code. */ |
1993 | #define PLT_THUMB_STUB_SIZE 4 | |
1994 | static const bfd_vma elf32_arm_plt_thumb_stub [] = | |
1995 | { | |
1996 | 0x4778, /* bx pc */ | |
1997 | 0x46c0 /* nop */ | |
1998 | }; | |
1999 | ||
e5a52504 MM |
2000 | /* The entries in a PLT when using a DLL-based target with multiple |
2001 | address spaces. */ | |
2002 | static const bfd_vma elf32_arm_symbian_plt_entry [] = | |
2003 | { | |
83a358aa | 2004 | 0xe51ff004, /* ldr pc, [pc, #-4] */ |
e5a52504 MM |
2005 | 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ |
2006 | }; | |
2007 | ||
e489d0ae PB |
2008 | /* Used to build a map of a section. This is required for mixed-endian |
2009 | code/data. */ | |
2010 | ||
2011 | typedef struct elf32_elf_section_map | |
2012 | { | |
2013 | bfd_vma vma; | |
2014 | char type; | |
2015 | } | |
2016 | elf32_arm_section_map; | |
2017 | ||
c7b8f16e JB |
2018 | /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */ |
2019 | ||
2020 | typedef enum | |
2021 | { | |
2022 | VFP11_ERRATUM_BRANCH_TO_ARM_VENEER, | |
2023 | VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER, | |
2024 | VFP11_ERRATUM_ARM_VENEER, | |
2025 | VFP11_ERRATUM_THUMB_VENEER | |
2026 | } | |
2027 | elf32_vfp11_erratum_type; | |
2028 | ||
2029 | typedef struct elf32_vfp11_erratum_list | |
2030 | { | |
2031 | struct elf32_vfp11_erratum_list *next; | |
2032 | bfd_vma vma; | |
2033 | union | |
2034 | { | |
2035 | struct | |
2036 | { | |
2037 | struct elf32_vfp11_erratum_list *veneer; | |
2038 | unsigned int vfp_insn; | |
2039 | } b; | |
2040 | struct | |
2041 | { | |
2042 | struct elf32_vfp11_erratum_list *branch; | |
2043 | unsigned int id; | |
2044 | } v; | |
2045 | } u; | |
2046 | elf32_vfp11_erratum_type type; | |
2047 | } | |
2048 | elf32_vfp11_erratum_list; | |
2049 | ||
8e3de13a | 2050 | typedef struct _arm_elf_section_data |
e489d0ae PB |
2051 | { |
2052 | struct bfd_elf_section_data elf; | |
8e3de13a | 2053 | unsigned int mapcount; |
c7b8f16e | 2054 | unsigned int mapsize; |
e489d0ae | 2055 | elf32_arm_section_map *map; |
c7b8f16e JB |
2056 | unsigned int erratumcount; |
2057 | elf32_vfp11_erratum_list *erratumlist; | |
8e3de13a NC |
2058 | } |
2059 | _arm_elf_section_data; | |
e489d0ae PB |
2060 | |
2061 | #define elf32_arm_section_data(sec) \ | |
8e3de13a | 2062 | ((_arm_elf_section_data *) elf_section_data (sec)) |
e489d0ae | 2063 | |
ba93b8ac DJ |
2064 | /* The size of the thread control block. */ |
2065 | #define TCB_SIZE 8 | |
2066 | ||
ee065d83 PB |
2067 | #define NUM_KNOWN_ATTRIBUTES 32 |
2068 | ||
2069 | typedef struct aeabi_attribute | |
2070 | { | |
2071 | int type; | |
2072 | unsigned int i; | |
2073 | char *s; | |
2074 | } aeabi_attribute; | |
2075 | ||
2076 | typedef struct aeabi_attribute_list | |
2077 | { | |
2078 | struct aeabi_attribute_list *next; | |
2079 | int tag; | |
2080 | aeabi_attribute attr; | |
2081 | } aeabi_attribute_list; | |
2082 | ||
ba93b8ac DJ |
2083 | struct elf32_arm_obj_tdata |
2084 | { | |
2085 | struct elf_obj_tdata root; | |
2086 | ||
2087 | /* tls_type for each local got entry. */ | |
2088 | char *local_got_tls_type; | |
ee065d83 PB |
2089 | |
2090 | aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES]; | |
2091 | aeabi_attribute_list *other_eabi_attributes; | |
bf21ed78 MS |
2092 | |
2093 | /* Zero to warn when linking objects with incompatible enum sizes. */ | |
2094 | int no_enum_size_warning; | |
ba93b8ac DJ |
2095 | }; |
2096 | ||
2097 | #define elf32_arm_tdata(abfd) \ | |
2098 | ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any) | |
2099 | ||
2100 | #define elf32_arm_local_got_tls_type(abfd) \ | |
2101 | (elf32_arm_tdata (abfd)->local_got_tls_type) | |
2102 | ||
2103 | static bfd_boolean | |
2104 | elf32_arm_mkobject (bfd *abfd) | |
2105 | { | |
ba93b8ac | 2106 | if (abfd->tdata.any == NULL) |
62d7a5f6 AM |
2107 | { |
2108 | bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata); | |
2109 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2110 | if (abfd->tdata.any == NULL) | |
2111 | return FALSE; | |
2112 | } | |
2113 | return bfd_elf_mkobject (abfd); | |
ba93b8ac DJ |
2114 | } |
2115 | ||
252b5132 RH |
2116 | /* The ARM linker needs to keep track of the number of relocs that it |
2117 | decides to copy in check_relocs for each symbol. This is so that | |
2118 | it can discard PC relative relocs if it doesn't need them when | |
2119 | linking with -Bsymbolic. We store the information in a field | |
2120 | extending the regular ELF linker hash table. */ | |
2121 | ||
ba93b8ac DJ |
2122 | /* This structure keeps track of the number of relocs we have copied |
2123 | for a given symbol. */ | |
5e681ec4 | 2124 | struct elf32_arm_relocs_copied |
917583ad NC |
2125 | { |
2126 | /* Next section. */ | |
5e681ec4 | 2127 | struct elf32_arm_relocs_copied * next; |
917583ad NC |
2128 | /* A section in dynobj. */ |
2129 | asection * section; | |
2130 | /* Number of relocs copied in this section. */ | |
2131 | bfd_size_type count; | |
ba93b8ac DJ |
2132 | /* Number of PC-relative relocs copied in this section. */ |
2133 | bfd_size_type pc_count; | |
917583ad | 2134 | }; |
252b5132 | 2135 | |
ba93b8ac DJ |
2136 | #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent)) |
2137 | ||
ba96a88f | 2138 | /* Arm ELF linker hash entry. */ |
252b5132 | 2139 | struct elf32_arm_link_hash_entry |
917583ad NC |
2140 | { |
2141 | struct elf_link_hash_entry root; | |
252b5132 | 2142 | |
917583ad | 2143 | /* Number of PC relative relocs copied for this symbol. */ |
5e681ec4 | 2144 | struct elf32_arm_relocs_copied * relocs_copied; |
b7693d02 DJ |
2145 | |
2146 | /* We reference count Thumb references to a PLT entry separately, | |
2147 | so that we can emit the Thumb trampoline only if needed. */ | |
2148 | bfd_signed_vma plt_thumb_refcount; | |
2149 | ||
2150 | /* Since PLT entries have variable size if the Thumb prologue is | |
2151 | used, we need to record the index into .got.plt instead of | |
2152 | recomputing it from the PLT offset. */ | |
2153 | bfd_signed_vma plt_got_offset; | |
ba93b8ac DJ |
2154 | |
2155 | #define GOT_UNKNOWN 0 | |
2156 | #define GOT_NORMAL 1 | |
2157 | #define GOT_TLS_GD 2 | |
2158 | #define GOT_TLS_IE 4 | |
2159 | unsigned char tls_type; | |
a4fd1a8e PB |
2160 | |
2161 | /* The symbol marking the real symbol location for exported thumb | |
2162 | symbols with Arm stubs. */ | |
2163 | struct elf_link_hash_entry *export_glue; | |
917583ad | 2164 | }; |
252b5132 | 2165 | |
252b5132 | 2166 | /* Traverse an arm ELF linker hash table. */ |
252b5132 RH |
2167 | #define elf32_arm_link_hash_traverse(table, func, info) \ |
2168 | (elf_link_hash_traverse \ | |
2169 | (&(table)->root, \ | |
b7693d02 | 2170 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
252b5132 RH |
2171 | (info))) |
2172 | ||
2173 | /* Get the ARM elf linker hash table from a link_info structure. */ | |
2174 | #define elf32_arm_hash_table(info) \ | |
2175 | ((struct elf32_arm_link_hash_table *) ((info)->hash)) | |
2176 | ||
9b485d32 | 2177 | /* ARM ELF linker hash table. */ |
252b5132 | 2178 | struct elf32_arm_link_hash_table |
917583ad NC |
2179 | { |
2180 | /* The main hash table. */ | |
2181 | struct elf_link_hash_table root; | |
252b5132 | 2182 | |
4cc11e76 | 2183 | /* The size in bytes of the section containing the Thumb-to-ARM glue. */ |
dc810e39 | 2184 | bfd_size_type thumb_glue_size; |
252b5132 | 2185 | |
4cc11e76 | 2186 | /* The size in bytes of the section containing the ARM-to-Thumb glue. */ |
dc810e39 | 2187 | bfd_size_type arm_glue_size; |
252b5132 | 2188 | |
c7b8f16e JB |
2189 | /* The size in bytes of the section containing glue for VFP11 erratum |
2190 | veneers. */ | |
2191 | bfd_size_type vfp11_erratum_glue_size; | |
2192 | ||
4cc11e76 | 2193 | /* An arbitrary input BFD chosen to hold the glue sections. */ |
917583ad | 2194 | bfd * bfd_of_glue_owner; |
ba96a88f | 2195 | |
e489d0ae PB |
2196 | /* Nonzero to output a BE8 image. */ |
2197 | int byteswap_code; | |
2198 | ||
9c504268 | 2199 | /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. |
87bc043a | 2200 | Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */ |
9c504268 PB |
2201 | int target1_is_rel; |
2202 | ||
eb043451 PB |
2203 | /* The relocation to use for R_ARM_TARGET2 relocations. */ |
2204 | int target2_reloc; | |
2205 | ||
319850b4 JB |
2206 | /* Nonzero to fix BX instructions for ARMv4 targets. */ |
2207 | int fix_v4bx; | |
2208 | ||
33bfe774 JB |
2209 | /* Nonzero if the ARM/Thumb BLX instructions are available for use. */ |
2210 | int use_blx; | |
2211 | ||
c7b8f16e JB |
2212 | /* What sort of code sequences we should look for which may trigger the |
2213 | VFP11 denorm erratum. */ | |
2214 | bfd_arm_vfp11_fix vfp11_fix; | |
2215 | ||
2216 | /* Global counter for the number of fixes we have emitted. */ | |
2217 | int num_vfp11_fixes; | |
2218 | ||
27e55c4d PB |
2219 | /* Nonzero to force PIC branch veneers. */ |
2220 | int pic_veneer; | |
2221 | ||
e5a52504 MM |
2222 | /* The number of bytes in the initial entry in the PLT. */ |
2223 | bfd_size_type plt_header_size; | |
2224 | ||
2225 | /* The number of bytes in the subsequent PLT etries. */ | |
2226 | bfd_size_type plt_entry_size; | |
2227 | ||
00a97672 RS |
2228 | /* True if the target system is VxWorks. */ |
2229 | int vxworks_p; | |
2230 | ||
e5a52504 MM |
2231 | /* True if the target system is Symbian OS. */ |
2232 | int symbian_p; | |
2233 | ||
4e7fd91e PB |
2234 | /* True if the target uses REL relocations. */ |
2235 | int use_rel; | |
2236 | ||
5e681ec4 PB |
2237 | /* Short-cuts to get to dynamic linker sections. */ |
2238 | asection *sgot; | |
2239 | asection *sgotplt; | |
2240 | asection *srelgot; | |
2241 | asection *splt; | |
2242 | asection *srelplt; | |
2243 | asection *sdynbss; | |
2244 | asection *srelbss; | |
2245 | ||
00a97672 RS |
2246 | /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */ |
2247 | asection *srelplt2; | |
2248 | ||
ba93b8ac DJ |
2249 | /* Data for R_ARM_TLS_LDM32 relocations. */ |
2250 | union { | |
2251 | bfd_signed_vma refcount; | |
2252 | bfd_vma offset; | |
2253 | } tls_ldm_got; | |
2254 | ||
5e681ec4 PB |
2255 | /* Small local sym to section mapping cache. */ |
2256 | struct sym_sec_cache sym_sec; | |
b7693d02 DJ |
2257 | |
2258 | /* For convenience in allocate_dynrelocs. */ | |
2259 | bfd * obfd; | |
917583ad | 2260 | }; |
252b5132 | 2261 | |
780a67af NC |
2262 | /* Create an entry in an ARM ELF linker hash table. */ |
2263 | ||
2264 | static struct bfd_hash_entry * | |
57e8b36a NC |
2265 | elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, |
2266 | struct bfd_hash_table * table, | |
2267 | const char * string) | |
780a67af NC |
2268 | { |
2269 | struct elf32_arm_link_hash_entry * ret = | |
2270 | (struct elf32_arm_link_hash_entry *) entry; | |
2271 | ||
2272 | /* Allocate the structure if it has not already been allocated by a | |
2273 | subclass. */ | |
2274 | if (ret == (struct elf32_arm_link_hash_entry *) NULL) | |
57e8b36a NC |
2275 | ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); |
2276 | if (ret == NULL) | |
780a67af NC |
2277 | return (struct bfd_hash_entry *) ret; |
2278 | ||
2279 | /* Call the allocation method of the superclass. */ | |
2280 | ret = ((struct elf32_arm_link_hash_entry *) | |
2281 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
2282 | table, string)); | |
57e8b36a | 2283 | if (ret != NULL) |
b7693d02 DJ |
2284 | { |
2285 | ret->relocs_copied = NULL; | |
ba93b8ac | 2286 | ret->tls_type = GOT_UNKNOWN; |
b7693d02 DJ |
2287 | ret->plt_thumb_refcount = 0; |
2288 | ret->plt_got_offset = -1; | |
a4fd1a8e | 2289 | ret->export_glue = NULL; |
b7693d02 | 2290 | } |
780a67af NC |
2291 | |
2292 | return (struct bfd_hash_entry *) ret; | |
2293 | } | |
2294 | ||
00a97672 RS |
2295 | /* Return true if NAME is the name of the relocation section associated |
2296 | with S. */ | |
2297 | ||
2298 | static bfd_boolean | |
2299 | reloc_section_p (struct elf32_arm_link_hash_table *htab, | |
2300 | const char *name, asection *s) | |
2301 | { | |
2302 | if (htab->use_rel) | |
0112cd26 | 2303 | return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0; |
00a97672 | 2304 | else |
0112cd26 | 2305 | return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0; |
00a97672 RS |
2306 | } |
2307 | ||
2308 | /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up | |
5e681ec4 PB |
2309 | shortcuts to them in our hash table. */ |
2310 | ||
2311 | static bfd_boolean | |
57e8b36a | 2312 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
2313 | { |
2314 | struct elf32_arm_link_hash_table *htab; | |
2315 | ||
e5a52504 MM |
2316 | htab = elf32_arm_hash_table (info); |
2317 | /* BPABI objects never have a GOT, or associated sections. */ | |
2318 | if (htab->symbian_p) | |
2319 | return TRUE; | |
2320 | ||
5e681ec4 PB |
2321 | if (! _bfd_elf_create_got_section (dynobj, info)) |
2322 | return FALSE; | |
2323 | ||
5e681ec4 PB |
2324 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
2325 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
2326 | if (!htab->sgot || !htab->sgotplt) | |
2327 | abort (); | |
2328 | ||
00a97672 RS |
2329 | htab->srelgot = bfd_make_section_with_flags (dynobj, |
2330 | RELOC_SECTION (htab, ".got"), | |
3496cb2a L |
2331 | (SEC_ALLOC | SEC_LOAD |
2332 | | SEC_HAS_CONTENTS | |
2333 | | SEC_IN_MEMORY | |
2334 | | SEC_LINKER_CREATED | |
2335 | | SEC_READONLY)); | |
5e681ec4 | 2336 | if (htab->srelgot == NULL |
5e681ec4 PB |
2337 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) |
2338 | return FALSE; | |
2339 | return TRUE; | |
2340 | } | |
2341 | ||
00a97672 RS |
2342 | /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and |
2343 | .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our | |
5e681ec4 PB |
2344 | hash table. */ |
2345 | ||
2346 | static bfd_boolean | |
57e8b36a | 2347 | elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
2348 | { |
2349 | struct elf32_arm_link_hash_table *htab; | |
2350 | ||
2351 | htab = elf32_arm_hash_table (info); | |
2352 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
2353 | return FALSE; | |
2354 | ||
2355 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
2356 | return FALSE; | |
2357 | ||
2358 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 RS |
2359 | htab->srelplt = bfd_get_section_by_name (dynobj, |
2360 | RELOC_SECTION (htab, ".plt")); | |
5e681ec4 PB |
2361 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
2362 | if (!info->shared) | |
00a97672 RS |
2363 | htab->srelbss = bfd_get_section_by_name (dynobj, |
2364 | RELOC_SECTION (htab, ".bss")); | |
2365 | ||
2366 | if (htab->vxworks_p) | |
2367 | { | |
2368 | if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2)) | |
2369 | return FALSE; | |
2370 | ||
2371 | if (info->shared) | |
2372 | { | |
2373 | htab->plt_header_size = 0; | |
2374 | htab->plt_entry_size | |
2375 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry); | |
2376 | } | |
2377 | else | |
2378 | { | |
2379 | htab->plt_header_size | |
2380 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry); | |
2381 | htab->plt_entry_size | |
2382 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry); | |
2383 | } | |
2384 | } | |
5e681ec4 | 2385 | |
e5a52504 MM |
2386 | if (!htab->splt |
2387 | || !htab->srelplt | |
2388 | || !htab->sdynbss | |
5e681ec4 PB |
2389 | || (!info->shared && !htab->srelbss)) |
2390 | abort (); | |
2391 | ||
2392 | return TRUE; | |
2393 | } | |
2394 | ||
2395 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
2396 | ||
2397 | static void | |
fcfa13d2 | 2398 | elf32_arm_copy_indirect_symbol (struct bfd_link_info *info, |
5e681ec4 PB |
2399 | struct elf_link_hash_entry *dir, |
2400 | struct elf_link_hash_entry *ind) | |
2401 | { | |
2402 | struct elf32_arm_link_hash_entry *edir, *eind; | |
2403 | ||
2404 | edir = (struct elf32_arm_link_hash_entry *) dir; | |
2405 | eind = (struct elf32_arm_link_hash_entry *) ind; | |
2406 | ||
2407 | if (eind->relocs_copied != NULL) | |
2408 | { | |
2409 | if (edir->relocs_copied != NULL) | |
2410 | { | |
2411 | struct elf32_arm_relocs_copied **pp; | |
2412 | struct elf32_arm_relocs_copied *p; | |
2413 | ||
fcfa13d2 | 2414 | /* Add reloc counts against the indirect sym to the direct sym |
5e681ec4 PB |
2415 | list. Merge any entries against the same section. */ |
2416 | for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) | |
2417 | { | |
2418 | struct elf32_arm_relocs_copied *q; | |
2419 | ||
2420 | for (q = edir->relocs_copied; q != NULL; q = q->next) | |
2421 | if (q->section == p->section) | |
2422 | { | |
ba93b8ac | 2423 | q->pc_count += p->pc_count; |
5e681ec4 PB |
2424 | q->count += p->count; |
2425 | *pp = p->next; | |
2426 | break; | |
2427 | } | |
2428 | if (q == NULL) | |
2429 | pp = &p->next; | |
2430 | } | |
2431 | *pp = edir->relocs_copied; | |
2432 | } | |
2433 | ||
2434 | edir->relocs_copied = eind->relocs_copied; | |
2435 | eind->relocs_copied = NULL; | |
2436 | } | |
2437 | ||
b34b2d70 | 2438 | if (ind->root.type == bfd_link_hash_indirect) |
ba93b8ac | 2439 | { |
b34b2d70 DJ |
2440 | /* Copy over PLT info. */ |
2441 | edir->plt_thumb_refcount += eind->plt_thumb_refcount; | |
2442 | eind->plt_thumb_refcount = 0; | |
2443 | ||
2444 | if (dir->got.refcount <= 0) | |
2445 | { | |
2446 | edir->tls_type = eind->tls_type; | |
2447 | eind->tls_type = GOT_UNKNOWN; | |
2448 | } | |
ba93b8ac DJ |
2449 | } |
2450 | ||
fcfa13d2 | 2451 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
5e681ec4 PB |
2452 | } |
2453 | ||
9b485d32 | 2454 | /* Create an ARM elf linker hash table. */ |
252b5132 RH |
2455 | |
2456 | static struct bfd_link_hash_table * | |
57e8b36a | 2457 | elf32_arm_link_hash_table_create (bfd *abfd) |
252b5132 RH |
2458 | { |
2459 | struct elf32_arm_link_hash_table *ret; | |
dc810e39 | 2460 | bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); |
252b5132 | 2461 | |
57e8b36a NC |
2462 | ret = bfd_malloc (amt); |
2463 | if (ret == NULL) | |
252b5132 RH |
2464 | return NULL; |
2465 | ||
57e8b36a | 2466 | if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, |
66eb6687 AM |
2467 | elf32_arm_link_hash_newfunc, |
2468 | sizeof (struct elf32_arm_link_hash_entry))) | |
252b5132 | 2469 | { |
e2d34d7d | 2470 | free (ret); |
252b5132 RH |
2471 | return NULL; |
2472 | } | |
2473 | ||
5e681ec4 PB |
2474 | ret->sgot = NULL; |
2475 | ret->sgotplt = NULL; | |
2476 | ret->srelgot = NULL; | |
2477 | ret->splt = NULL; | |
2478 | ret->srelplt = NULL; | |
2479 | ret->sdynbss = NULL; | |
2480 | ret->srelbss = NULL; | |
00a97672 | 2481 | ret->srelplt2 = NULL; |
252b5132 RH |
2482 | ret->thumb_glue_size = 0; |
2483 | ret->arm_glue_size = 0; | |
c7b8f16e JB |
2484 | ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE; |
2485 | ret->vfp11_erratum_glue_size = 0; | |
2486 | ret->num_vfp11_fixes = 0; | |
252b5132 | 2487 | ret->bfd_of_glue_owner = NULL; |
e489d0ae | 2488 | ret->byteswap_code = 0; |
9c504268 | 2489 | ret->target1_is_rel = 0; |
eb043451 | 2490 | ret->target2_reloc = R_ARM_NONE; |
e5a52504 MM |
2491 | #ifdef FOUR_WORD_PLT |
2492 | ret->plt_header_size = 16; | |
2493 | ret->plt_entry_size = 16; | |
2494 | #else | |
2495 | ret->plt_header_size = 20; | |
2496 | ret->plt_entry_size = 12; | |
2497 | #endif | |
33bfe774 JB |
2498 | ret->fix_v4bx = 0; |
2499 | ret->use_blx = 0; | |
00a97672 | 2500 | ret->vxworks_p = 0; |
e5a52504 | 2501 | ret->symbian_p = 0; |
4e7fd91e | 2502 | ret->use_rel = 1; |
5e681ec4 | 2503 | ret->sym_sec.abfd = NULL; |
b7693d02 | 2504 | ret->obfd = abfd; |
ba93b8ac | 2505 | ret->tls_ldm_got.refcount = 0; |
252b5132 RH |
2506 | |
2507 | return &ret->root.root; | |
2508 | } | |
2509 | ||
9b485d32 NC |
2510 | /* Locate the Thumb encoded calling stub for NAME. */ |
2511 | ||
252b5132 | 2512 | static struct elf_link_hash_entry * |
57e8b36a NC |
2513 | find_thumb_glue (struct bfd_link_info *link_info, |
2514 | const char *name, | |
f2a9dd69 | 2515 | char **error_message) |
252b5132 RH |
2516 | { |
2517 | char *tmp_name; | |
2518 | struct elf_link_hash_entry *hash; | |
2519 | struct elf32_arm_link_hash_table *hash_table; | |
2520 | ||
2521 | /* We need a pointer to the armelf specific hash table. */ | |
2522 | hash_table = elf32_arm_hash_table (link_info); | |
2523 | ||
57e8b36a NC |
2524 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2525 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2526 | |
2527 | BFD_ASSERT (tmp_name); | |
2528 | ||
2529 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2530 | ||
2531 | hash = elf_link_hash_lookup | |
b34976b6 | 2532 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2533 | |
2534 | if (hash == NULL) | |
f2a9dd69 DJ |
2535 | asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"), |
2536 | tmp_name, name); | |
252b5132 RH |
2537 | |
2538 | free (tmp_name); | |
2539 | ||
2540 | return hash; | |
2541 | } | |
2542 | ||
9b485d32 NC |
2543 | /* Locate the ARM encoded calling stub for NAME. */ |
2544 | ||
252b5132 | 2545 | static struct elf_link_hash_entry * |
57e8b36a NC |
2546 | find_arm_glue (struct bfd_link_info *link_info, |
2547 | const char *name, | |
f2a9dd69 | 2548 | char **error_message) |
252b5132 RH |
2549 | { |
2550 | char *tmp_name; | |
2551 | struct elf_link_hash_entry *myh; | |
2552 | struct elf32_arm_link_hash_table *hash_table; | |
2553 | ||
2554 | /* We need a pointer to the elfarm specific hash table. */ | |
2555 | hash_table = elf32_arm_hash_table (link_info); | |
2556 | ||
57e8b36a NC |
2557 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2558 | + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2559 | |
2560 | BFD_ASSERT (tmp_name); | |
2561 | ||
2562 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2563 | ||
2564 | myh = elf_link_hash_lookup | |
b34976b6 | 2565 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2566 | |
2567 | if (myh == NULL) | |
f2a9dd69 DJ |
2568 | asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"), |
2569 | tmp_name, name); | |
252b5132 RH |
2570 | |
2571 | free (tmp_name); | |
2572 | ||
2573 | return myh; | |
2574 | } | |
2575 | ||
8f6277f5 | 2576 | /* ARM->Thumb glue (static images): |
252b5132 RH |
2577 | |
2578 | .arm | |
2579 | __func_from_arm: | |
2580 | ldr r12, __func_addr | |
2581 | bx r12 | |
2582 | __func_addr: | |
8f6277f5 | 2583 | .word func @ behave as if you saw a ARM_32 reloc. |
252b5132 | 2584 | |
8f6277f5 PB |
2585 | (relocatable images) |
2586 | .arm | |
2587 | __func_from_arm: | |
2588 | ldr r12, __func_offset | |
2589 | add r12, r12, pc | |
2590 | bx r12 | |
2591 | __func_offset: | |
2592 | .word func - . | |
2593 | */ | |
2594 | ||
2595 | #define ARM2THUMB_STATIC_GLUE_SIZE 12 | |
252b5132 RH |
2596 | static const insn32 a2t1_ldr_insn = 0xe59fc000; |
2597 | static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; | |
2598 | static const insn32 a2t3_func_addr_insn = 0x00000001; | |
2599 | ||
8f6277f5 PB |
2600 | #define ARM2THUMB_PIC_GLUE_SIZE 16 |
2601 | static const insn32 a2t1p_ldr_insn = 0xe59fc004; | |
2602 | static const insn32 a2t2p_add_pc_insn = 0xe08cc00f; | |
2603 | static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c; | |
2604 | ||
9b485d32 | 2605 | /* Thumb->ARM: Thumb->(non-interworking aware) ARM |
252b5132 RH |
2606 | |
2607 | .thumb .thumb | |
2608 | .align 2 .align 2 | |
2609 | __func_from_thumb: __func_from_thumb: | |
2610 | bx pc push {r6, lr} | |
2611 | nop ldr r6, __func_addr | |
2612 | .arm mov lr, pc | |
2613 | __func_change_to_arm: bx r6 | |
2614 | b func .arm | |
2615 | __func_back_to_thumb: | |
2616 | ldmia r13! {r6, lr} | |
2617 | bx lr | |
2618 | __func_addr: | |
9b485d32 | 2619 | .word func */ |
252b5132 RH |
2620 | |
2621 | #define THUMB2ARM_GLUE_SIZE 8 | |
2622 | static const insn16 t2a1_bx_pc_insn = 0x4778; | |
2623 | static const insn16 t2a2_noop_insn = 0x46c0; | |
2624 | static const insn32 t2a3_b_insn = 0xea000000; | |
2625 | ||
c7b8f16e JB |
2626 | #define VFP11_ERRATUM_VENEER_SIZE 8 |
2627 | ||
7e392df6 | 2628 | #ifndef ELFARM_NABI_C_INCLUDED |
b34976b6 | 2629 | bfd_boolean |
57e8b36a | 2630 | bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) |
252b5132 RH |
2631 | { |
2632 | asection * s; | |
2633 | bfd_byte * foo; | |
2634 | struct elf32_arm_link_hash_table * globals; | |
2635 | ||
2636 | globals = elf32_arm_hash_table (info); | |
2637 | ||
2638 | BFD_ASSERT (globals != NULL); | |
2639 | ||
2640 | if (globals->arm_glue_size != 0) | |
2641 | { | |
2642 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2643 | ||
dc810e39 AM |
2644 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
2645 | ARM2THUMB_GLUE_SECTION_NAME); | |
252b5132 RH |
2646 | |
2647 | BFD_ASSERT (s != NULL); | |
2648 | ||
57e8b36a | 2649 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); |
252b5132 | 2650 | |
2f475487 | 2651 | BFD_ASSERT (s->size == globals->arm_glue_size); |
252b5132 RH |
2652 | s->contents = foo; |
2653 | } | |
2654 | ||
2655 | if (globals->thumb_glue_size != 0) | |
2656 | { | |
2657 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2658 | ||
2659 | s = bfd_get_section_by_name | |
2660 | (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2661 | ||
2662 | BFD_ASSERT (s != NULL); | |
2663 | ||
57e8b36a | 2664 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); |
252b5132 | 2665 | |
2f475487 | 2666 | BFD_ASSERT (s->size == globals->thumb_glue_size); |
252b5132 RH |
2667 | s->contents = foo; |
2668 | } | |
c7b8f16e JB |
2669 | |
2670 | if (globals->vfp11_erratum_glue_size != 0) | |
2671 | { | |
2672 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2673 | ||
2674 | s = bfd_get_section_by_name | |
2675 | (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME); | |
2676 | ||
2677 | BFD_ASSERT (s != NULL); | |
2678 | ||
2679 | foo = bfd_alloc (globals->bfd_of_glue_owner, | |
2680 | globals->vfp11_erratum_glue_size); | |
2681 | ||
2682 | BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size); | |
2683 | s->contents = foo; | |
2684 | } | |
252b5132 | 2685 | |
b34976b6 | 2686 | return TRUE; |
252b5132 RH |
2687 | } |
2688 | ||
a4fd1a8e PB |
2689 | /* Allocate space and symbols for calling a Thumb function from Arm mode. |
2690 | returns the symbol identifying teh stub. */ | |
2691 | static struct elf_link_hash_entry * | |
57e8b36a NC |
2692 | record_arm_to_thumb_glue (struct bfd_link_info * link_info, |
2693 | struct elf_link_hash_entry * h) | |
252b5132 RH |
2694 | { |
2695 | const char * name = h->root.root.string; | |
63b0f745 | 2696 | asection * s; |
252b5132 RH |
2697 | char * tmp_name; |
2698 | struct elf_link_hash_entry * myh; | |
14a793b2 | 2699 | struct bfd_link_hash_entry * bh; |
252b5132 | 2700 | struct elf32_arm_link_hash_table * globals; |
dc810e39 | 2701 | bfd_vma val; |
2f475487 | 2702 | bfd_size_type size; |
252b5132 RH |
2703 | |
2704 | globals = elf32_arm_hash_table (link_info); | |
2705 | ||
2706 | BFD_ASSERT (globals != NULL); | |
2707 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2708 | ||
2709 | s = bfd_get_section_by_name | |
2710 | (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); | |
2711 | ||
252b5132 RH |
2712 | BFD_ASSERT (s != NULL); |
2713 | ||
57e8b36a | 2714 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
252b5132 RH |
2715 | |
2716 | BFD_ASSERT (tmp_name); | |
2717 | ||
2718 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2719 | ||
2720 | myh = elf_link_hash_lookup | |
b34976b6 | 2721 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2722 | |
2723 | if (myh != NULL) | |
2724 | { | |
9b485d32 | 2725 | /* We've already seen this guy. */ |
252b5132 | 2726 | free (tmp_name); |
a4fd1a8e | 2727 | return myh; |
252b5132 RH |
2728 | } |
2729 | ||
57e8b36a NC |
2730 | /* The only trick here is using hash_table->arm_glue_size as the value. |
2731 | Even though the section isn't allocated yet, this is where we will be | |
2732 | putting it. */ | |
14a793b2 | 2733 | bh = NULL; |
dc810e39 AM |
2734 | val = globals->arm_glue_size + 1; |
2735 | _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, | |
2736 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2737 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2738 | |
b7693d02 DJ |
2739 | myh = (struct elf_link_hash_entry *) bh; |
2740 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
2741 | myh->forced_local = 1; | |
2742 | ||
252b5132 RH |
2743 | free (tmp_name); |
2744 | ||
27e55c4d PB |
2745 | if (link_info->shared || globals->root.is_relocatable_executable |
2746 | || globals->pic_veneer) | |
2f475487 | 2747 | size = ARM2THUMB_PIC_GLUE_SIZE; |
8f6277f5 | 2748 | else |
2f475487 AM |
2749 | size = ARM2THUMB_STATIC_GLUE_SIZE; |
2750 | ||
2751 | s->size += size; | |
2752 | globals->arm_glue_size += size; | |
252b5132 | 2753 | |
a4fd1a8e | 2754 | return myh; |
252b5132 RH |
2755 | } |
2756 | ||
2757 | static void | |
57e8b36a NC |
2758 | record_thumb_to_arm_glue (struct bfd_link_info *link_info, |
2759 | struct elf_link_hash_entry *h) | |
252b5132 RH |
2760 | { |
2761 | const char *name = h->root.root.string; | |
63b0f745 | 2762 | asection *s; |
252b5132 RH |
2763 | char *tmp_name; |
2764 | struct elf_link_hash_entry *myh; | |
14a793b2 | 2765 | struct bfd_link_hash_entry *bh; |
252b5132 | 2766 | struct elf32_arm_link_hash_table *hash_table; |
dc810e39 | 2767 | bfd_vma val; |
252b5132 RH |
2768 | |
2769 | hash_table = elf32_arm_hash_table (link_info); | |
2770 | ||
2771 | BFD_ASSERT (hash_table != NULL); | |
2772 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); | |
2773 | ||
2774 | s = bfd_get_section_by_name | |
2775 | (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2776 | ||
2777 | BFD_ASSERT (s != NULL); | |
2778 | ||
57e8b36a NC |
2779 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2780 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2781 | |
2782 | BFD_ASSERT (tmp_name); | |
2783 | ||
2784 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2785 | ||
2786 | myh = elf_link_hash_lookup | |
b34976b6 | 2787 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2788 | |
2789 | if (myh != NULL) | |
2790 | { | |
9b485d32 | 2791 | /* We've already seen this guy. */ |
252b5132 | 2792 | free (tmp_name); |
9b485d32 | 2793 | return; |
252b5132 RH |
2794 | } |
2795 | ||
14a793b2 | 2796 | bh = NULL; |
dc810e39 AM |
2797 | val = hash_table->thumb_glue_size + 1; |
2798 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2799 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2800 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2801 | |
9b485d32 | 2802 | /* If we mark it 'Thumb', the disassembler will do a better job. */ |
14a793b2 | 2803 | myh = (struct elf_link_hash_entry *) bh; |
b7693d02 DJ |
2804 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); |
2805 | myh->forced_local = 1; | |
252b5132 RH |
2806 | |
2807 | free (tmp_name); | |
2808 | ||
252b5132 RH |
2809 | #define CHANGE_TO_ARM "__%s_change_to_arm" |
2810 | #define BACK_FROM_ARM "__%s_back_from_arm" | |
2811 | ||
9b485d32 | 2812 | /* Allocate another symbol to mark where we switch to Arm mode. */ |
57e8b36a NC |
2813 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2814 | + strlen (CHANGE_TO_ARM) + 1); | |
252b5132 RH |
2815 | |
2816 | BFD_ASSERT (tmp_name); | |
2817 | ||
2818 | sprintf (tmp_name, CHANGE_TO_ARM, name); | |
2819 | ||
14a793b2 | 2820 | bh = NULL; |
dc810e39 AM |
2821 | val = hash_table->thumb_glue_size + 4, |
2822 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2823 | tmp_name, BSF_LOCAL, s, val, | |
b34976b6 | 2824 | NULL, TRUE, FALSE, &bh); |
252b5132 RH |
2825 | |
2826 | free (tmp_name); | |
2827 | ||
2f475487 | 2828 | s->size += THUMB2ARM_GLUE_SIZE; |
252b5132 RH |
2829 | hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; |
2830 | ||
2831 | return; | |
2832 | } | |
2833 | ||
c7b8f16e JB |
2834 | |
2835 | /* Add an entry to the code/data map for section SEC. */ | |
2836 | ||
2837 | static void | |
2838 | elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma) | |
2839 | { | |
2840 | struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec); | |
2841 | unsigned int newidx; | |
2842 | ||
2843 | if (sec_data->map == NULL) | |
2844 | { | |
2845 | sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map)); | |
2846 | sec_data->mapcount = 0; | |
2847 | sec_data->mapsize = 1; | |
2848 | } | |
2849 | ||
2850 | newidx = sec_data->mapcount++; | |
2851 | ||
2852 | if (sec_data->mapcount > sec_data->mapsize) | |
2853 | { | |
2854 | sec_data->mapsize *= 2; | |
2855 | sec_data->map = bfd_realloc (sec_data->map, sec_data->mapsize | |
2856 | * sizeof (elf32_arm_section_map)); | |
2857 | } | |
2858 | ||
2859 | sec_data->map[newidx].vma = vma; | |
2860 | sec_data->map[newidx].type = type; | |
2861 | } | |
2862 | ||
2863 | ||
2864 | /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode | |
2865 | veneers are handled for now. */ | |
2866 | ||
2867 | static bfd_vma | |
2868 | record_vfp11_erratum_veneer (struct bfd_link_info *link_info, | |
2869 | elf32_vfp11_erratum_list *branch, | |
2870 | bfd *branch_bfd, | |
2871 | asection *branch_sec, | |
2872 | unsigned int offset) | |
2873 | { | |
2874 | asection *s; | |
2875 | struct elf32_arm_link_hash_table *hash_table; | |
2876 | char *tmp_name; | |
2877 | struct elf_link_hash_entry *myh; | |
2878 | struct bfd_link_hash_entry *bh; | |
2879 | bfd_vma val; | |
2880 | struct _arm_elf_section_data *sec_data; | |
2881 | int errcount; | |
2882 | elf32_vfp11_erratum_list *newerr; | |
2883 | ||
2884 | hash_table = elf32_arm_hash_table (link_info); | |
2885 | ||
2886 | BFD_ASSERT (hash_table != NULL); | |
2887 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); | |
2888 | ||
2889 | s = bfd_get_section_by_name | |
2890 | (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME); | |
2891 | ||
2892 | sec_data = elf32_arm_section_data (s); | |
2893 | ||
2894 | BFD_ASSERT (s != NULL); | |
2895 | ||
2896 | tmp_name = bfd_malloc ((bfd_size_type) strlen | |
2897 | (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10); | |
2898 | ||
2899 | BFD_ASSERT (tmp_name); | |
2900 | ||
2901 | sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME, | |
2902 | hash_table->num_vfp11_fixes); | |
2903 | ||
2904 | myh = elf_link_hash_lookup | |
2905 | (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE); | |
2906 | ||
2907 | BFD_ASSERT (myh == NULL); | |
2908 | ||
2909 | bh = NULL; | |
2910 | val = hash_table->vfp11_erratum_glue_size; | |
2911 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2912 | tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val, | |
2913 | NULL, TRUE, FALSE, &bh); | |
2914 | ||
2915 | myh = (struct elf_link_hash_entry *) bh; | |
2916 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
2917 | myh->forced_local = 1; | |
2918 | ||
2919 | /* Link veneer back to calling location. */ | |
2920 | errcount = ++(sec_data->erratumcount); | |
2921 | newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list)); | |
2922 | ||
2923 | newerr->type = VFP11_ERRATUM_ARM_VENEER; | |
2924 | newerr->vma = -1; | |
2925 | newerr->u.v.branch = branch; | |
2926 | newerr->u.v.id = hash_table->num_vfp11_fixes; | |
2927 | branch->u.b.veneer = newerr; | |
2928 | ||
2929 | newerr->next = sec_data->erratumlist; | |
2930 | sec_data->erratumlist = newerr; | |
2931 | ||
2932 | /* A symbol for the return from the veneer. */ | |
2933 | sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r", | |
2934 | hash_table->num_vfp11_fixes); | |
2935 | ||
2936 | myh = elf_link_hash_lookup | |
2937 | (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE); | |
2938 | ||
2939 | if (myh != NULL) | |
2940 | abort (); | |
2941 | ||
2942 | bh = NULL; | |
2943 | val = offset + 4; | |
2944 | _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL, | |
2945 | branch_sec, val, NULL, TRUE, FALSE, &bh); | |
2946 | ||
2947 | myh = (struct elf_link_hash_entry *) bh; | |
2948 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
2949 | myh->forced_local = 1; | |
2950 | ||
2951 | free (tmp_name); | |
2952 | ||
2953 | /* Generate a mapping symbol for the veneer section, and explicitly add an | |
2954 | entry for that symbol to the code/data map for the section. */ | |
2955 | if (hash_table->vfp11_erratum_glue_size == 0) | |
2956 | { | |
2957 | bh = NULL; | |
2958 | /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it | |
2959 | ever requires this erratum fix. */ | |
2960 | _bfd_generic_link_add_one_symbol (link_info, | |
2961 | hash_table->bfd_of_glue_owner, "$a", | |
2962 | BSF_LOCAL, s, 0, NULL, | |
2963 | TRUE, FALSE, &bh); | |
2964 | ||
2965 | myh = (struct elf_link_hash_entry *) bh; | |
2966 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
2967 | myh->forced_local = 1; | |
2968 | ||
2969 | /* The elf32_arm_init_maps function only cares about symbols from input | |
2970 | BFDs. We must make a note of this generated mapping symbol | |
2971 | ourselves so that code byteswapping works properly in | |
2972 | elf32_arm_write_section. */ | |
2973 | elf32_arm_section_map_add (s, 'a', 0); | |
2974 | } | |
2975 | ||
2976 | s->size += VFP11_ERRATUM_VENEER_SIZE; | |
2977 | hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE; | |
2978 | hash_table->num_vfp11_fixes++; | |
2979 | ||
2980 | /* The offset of the veneer. */ | |
2981 | return val; | |
2982 | } | |
2983 | ||
8afb0e02 NC |
2984 | /* Add the glue sections to ABFD. This function is called from the |
2985 | linker scripts in ld/emultempl/{armelf}.em. */ | |
9b485d32 | 2986 | |
b34976b6 | 2987 | bfd_boolean |
57e8b36a NC |
2988 | bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, |
2989 | struct bfd_link_info *info) | |
252b5132 | 2990 | { |
252b5132 RH |
2991 | flagword flags; |
2992 | asection *sec; | |
2993 | ||
8afb0e02 NC |
2994 | /* If we are only performing a partial |
2995 | link do not bother adding the glue. */ | |
1049f94e | 2996 | if (info->relocatable) |
b34976b6 | 2997 | return TRUE; |
252b5132 | 2998 | |
252b5132 RH |
2999 | sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
3000 | ||
3001 | if (sec == NULL) | |
3002 | { | |
57db232e NC |
3003 | /* Note: we do not include the flag SEC_LINKER_CREATED, as this |
3004 | will prevent elf_link_input_bfd() from processing the contents | |
3005 | of this section. */ | |
2f475487 AM |
3006 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
3007 | | SEC_CODE | SEC_READONLY); | |
252b5132 | 3008 | |
3496cb2a L |
3009 | sec = bfd_make_section_with_flags (abfd, |
3010 | ARM2THUMB_GLUE_SECTION_NAME, | |
3011 | flags); | |
252b5132 RH |
3012 | |
3013 | if (sec == NULL | |
252b5132 | 3014 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 3015 | return FALSE; |
9a5aca8c | 3016 | |
57db232e NC |
3017 | /* Set the gc mark to prevent the section from being removed by garbage |
3018 | collection, despite the fact that no relocs refer to this section. */ | |
3019 | sec->gc_mark = 1; | |
252b5132 RH |
3020 | } |
3021 | ||
3022 | sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); | |
3023 | ||
3024 | if (sec == NULL) | |
3025 | { | |
2f475487 AM |
3026 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
3027 | | SEC_CODE | SEC_READONLY); | |
252b5132 | 3028 | |
3496cb2a L |
3029 | sec = bfd_make_section_with_flags (abfd, |
3030 | THUMB2ARM_GLUE_SECTION_NAME, | |
3031 | flags); | |
252b5132 RH |
3032 | |
3033 | if (sec == NULL | |
252b5132 | 3034 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 3035 | return FALSE; |
9a5aca8c | 3036 | |
57db232e | 3037 | sec->gc_mark = 1; |
252b5132 RH |
3038 | } |
3039 | ||
c7b8f16e JB |
3040 | sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME); |
3041 | ||
3042 | if (sec == NULL) | |
3043 | { | |
3044 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3045 | | SEC_CODE | SEC_READONLY); | |
3046 | ||
3047 | sec = bfd_make_section_with_flags (abfd, | |
3048 | VFP11_ERRATUM_VENEER_SECTION_NAME, | |
3049 | flags); | |
3050 | ||
3051 | if (sec == NULL | |
3052 | || !bfd_set_section_alignment (abfd, sec, 2)) | |
3053 | return FALSE; | |
3054 | ||
3055 | sec->gc_mark = 1; | |
3056 | } | |
3057 | ||
b34976b6 | 3058 | return TRUE; |
8afb0e02 NC |
3059 | } |
3060 | ||
3061 | /* Select a BFD to be used to hold the sections used by the glue code. | |
3062 | This function is called from the linker scripts in ld/emultempl/ | |
3063 | {armelf/pe}.em */ | |
3064 | ||
b34976b6 | 3065 | bfd_boolean |
57e8b36a | 3066 | bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) |
8afb0e02 NC |
3067 | { |
3068 | struct elf32_arm_link_hash_table *globals; | |
3069 | ||
3070 | /* If we are only performing a partial link | |
3071 | do not bother getting a bfd to hold the glue. */ | |
1049f94e | 3072 | if (info->relocatable) |
b34976b6 | 3073 | return TRUE; |
8afb0e02 | 3074 | |
b7693d02 DJ |
3075 | /* Make sure we don't attach the glue sections to a dynamic object. */ |
3076 | BFD_ASSERT (!(abfd->flags & DYNAMIC)); | |
3077 | ||
8afb0e02 NC |
3078 | globals = elf32_arm_hash_table (info); |
3079 | ||
3080 | BFD_ASSERT (globals != NULL); | |
3081 | ||
3082 | if (globals->bfd_of_glue_owner != NULL) | |
b34976b6 | 3083 | return TRUE; |
8afb0e02 | 3084 | |
252b5132 RH |
3085 | /* Save the bfd for later use. */ |
3086 | globals->bfd_of_glue_owner = abfd; | |
cedb70c5 | 3087 | |
b34976b6 | 3088 | return TRUE; |
252b5132 RH |
3089 | } |
3090 | ||
39b41c9c PB |
3091 | static void check_use_blx(struct elf32_arm_link_hash_table *globals) |
3092 | { | |
3093 | if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2) | |
3094 | globals->use_blx = 1; | |
3095 | } | |
3096 | ||
b34976b6 | 3097 | bfd_boolean |
57e8b36a | 3098 | bfd_elf32_arm_process_before_allocation (bfd *abfd, |
d504ffc8 | 3099 | struct bfd_link_info *link_info) |
252b5132 RH |
3100 | { |
3101 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 3102 | Elf_Internal_Rela *internal_relocs = NULL; |
252b5132 RH |
3103 | Elf_Internal_Rela *irel, *irelend; |
3104 | bfd_byte *contents = NULL; | |
252b5132 RH |
3105 | |
3106 | asection *sec; | |
3107 | struct elf32_arm_link_hash_table *globals; | |
3108 | ||
3109 | /* If we are only performing a partial link do not bother | |
3110 | to construct any glue. */ | |
1049f94e | 3111 | if (link_info->relocatable) |
b34976b6 | 3112 | return TRUE; |
252b5132 RH |
3113 | |
3114 | /* Here we have a bfd that is to be included on the link. We have a hook | |
3115 | to do reloc rummaging, before section sizes are nailed down. */ | |
252b5132 | 3116 | globals = elf32_arm_hash_table (link_info); |
39b41c9c | 3117 | check_use_blx (globals); |
252b5132 RH |
3118 | |
3119 | BFD_ASSERT (globals != NULL); | |
3120 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
3121 | ||
d504ffc8 | 3122 | if (globals->byteswap_code && !bfd_big_endian (abfd)) |
e489d0ae | 3123 | { |
d003868e AM |
3124 | _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), |
3125 | abfd); | |
e489d0ae PB |
3126 | return FALSE; |
3127 | } | |
f21f3fe0 | 3128 | |
252b5132 RH |
3129 | /* Rummage around all the relocs and map the glue vectors. */ |
3130 | sec = abfd->sections; | |
3131 | ||
3132 | if (sec == NULL) | |
b34976b6 | 3133 | return TRUE; |
252b5132 RH |
3134 | |
3135 | for (; sec != NULL; sec = sec->next) | |
3136 | { | |
3137 | if (sec->reloc_count == 0) | |
3138 | continue; | |
3139 | ||
2f475487 AM |
3140 | if ((sec->flags & SEC_EXCLUDE) != 0) |
3141 | continue; | |
3142 | ||
252b5132 | 3143 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
252b5132 | 3144 | |
9b485d32 | 3145 | /* Load the relocs. */ |
6cdc0ccc | 3146 | internal_relocs |
57e8b36a | 3147 | = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, |
45d6a902 | 3148 | (Elf_Internal_Rela *) NULL, FALSE); |
252b5132 | 3149 | |
6cdc0ccc AM |
3150 | if (internal_relocs == NULL) |
3151 | goto error_return; | |
252b5132 | 3152 | |
6cdc0ccc AM |
3153 | irelend = internal_relocs + sec->reloc_count; |
3154 | for (irel = internal_relocs; irel < irelend; irel++) | |
252b5132 RH |
3155 | { |
3156 | long r_type; | |
3157 | unsigned long r_index; | |
252b5132 RH |
3158 | |
3159 | struct elf_link_hash_entry *h; | |
3160 | ||
3161 | r_type = ELF32_R_TYPE (irel->r_info); | |
3162 | r_index = ELF32_R_SYM (irel->r_info); | |
3163 | ||
9b485d32 | 3164 | /* These are the only relocation types we care about. */ |
ba96a88f | 3165 | if ( r_type != R_ARM_PC24 |
b7693d02 | 3166 | && r_type != R_ARM_PLT32 |
5b5bb741 PB |
3167 | && r_type != R_ARM_CALL |
3168 | && r_type != R_ARM_JUMP24 | |
c19d1205 | 3169 | && r_type != R_ARM_THM_CALL) |
252b5132 RH |
3170 | continue; |
3171 | ||
3172 | /* Get the section contents if we haven't done so already. */ | |
3173 | if (contents == NULL) | |
3174 | { | |
3175 | /* Get cached copy if it exists. */ | |
3176 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
3177 | contents = elf_section_data (sec)->this_hdr.contents; | |
3178 | else | |
3179 | { | |
3180 | /* Go get them off disk. */ | |
57e8b36a | 3181 | if (! bfd_malloc_and_get_section (abfd, sec, &contents)) |
252b5132 RH |
3182 | goto error_return; |
3183 | } | |
3184 | } | |
3185 | ||
a7c10850 | 3186 | /* If the relocation is not against a symbol it cannot concern us. */ |
252b5132 RH |
3187 | h = NULL; |
3188 | ||
9b485d32 | 3189 | /* We don't care about local symbols. */ |
252b5132 RH |
3190 | if (r_index < symtab_hdr->sh_info) |
3191 | continue; | |
3192 | ||
9b485d32 | 3193 | /* This is an external symbol. */ |
252b5132 RH |
3194 | r_index -= symtab_hdr->sh_info; |
3195 | h = (struct elf_link_hash_entry *) | |
3196 | elf_sym_hashes (abfd)[r_index]; | |
3197 | ||
3198 | /* If the relocation is against a static symbol it must be within | |
3199 | the current section and so cannot be a cross ARM/Thumb relocation. */ | |
3200 | if (h == NULL) | |
3201 | continue; | |
3202 | ||
d504ffc8 DJ |
3203 | /* If the call will go through a PLT entry then we do not need |
3204 | glue. */ | |
3205 | if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1) | |
b7693d02 DJ |
3206 | continue; |
3207 | ||
252b5132 RH |
3208 | switch (r_type) |
3209 | { | |
3210 | case R_ARM_PC24: | |
c6596c5e | 3211 | case R_ARM_PLT32: |
5b5bb741 PB |
3212 | case R_ARM_CALL: |
3213 | case R_ARM_JUMP24: | |
252b5132 | 3214 | /* This one is a call from arm code. We need to look up |
2f0ca46a | 3215 | the target of the call. If it is a thumb target, we |
252b5132 | 3216 | insert glue. */ |
39b41c9c PB |
3217 | if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC |
3218 | && !(r_type == R_ARM_CALL && globals->use_blx)) | |
252b5132 RH |
3219 | record_arm_to_thumb_glue (link_info, h); |
3220 | break; | |
3221 | ||
c19d1205 | 3222 | case R_ARM_THM_CALL: |
f21f3fe0 | 3223 | /* This one is a call from thumb code. We look |
2f0ca46a | 3224 | up the target of the call. If it is not a thumb |
bcbdc74c | 3225 | target, we insert glue. */ |
39b41c9c | 3226 | if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx) |
252b5132 RH |
3227 | record_thumb_to_arm_glue (link_info, h); |
3228 | break; | |
3229 | ||
3230 | default: | |
c6596c5e | 3231 | abort (); |
252b5132 RH |
3232 | } |
3233 | } | |
6cdc0ccc AM |
3234 | |
3235 | if (contents != NULL | |
3236 | && elf_section_data (sec)->this_hdr.contents != contents) | |
3237 | free (contents); | |
3238 | contents = NULL; | |
3239 | ||
3240 | if (internal_relocs != NULL | |
3241 | && elf_section_data (sec)->relocs != internal_relocs) | |
3242 | free (internal_relocs); | |
3243 | internal_relocs = NULL; | |
252b5132 RH |
3244 | } |
3245 | ||
b34976b6 | 3246 | return TRUE; |
9a5aca8c | 3247 | |
252b5132 | 3248 | error_return: |
6cdc0ccc AM |
3249 | if (contents != NULL |
3250 | && elf_section_data (sec)->this_hdr.contents != contents) | |
3251 | free (contents); | |
3252 | if (internal_relocs != NULL | |
3253 | && elf_section_data (sec)->relocs != internal_relocs) | |
3254 | free (internal_relocs); | |
9a5aca8c | 3255 | |
b34976b6 | 3256 | return FALSE; |
252b5132 | 3257 | } |
7e392df6 | 3258 | #endif |
252b5132 | 3259 | |
eb043451 | 3260 | |
c7b8f16e JB |
3261 | /* Initialise maps of ARM/Thumb/data for input BFDs. */ |
3262 | ||
3263 | void | |
3264 | bfd_elf32_arm_init_maps (bfd *abfd) | |
3265 | { | |
3266 | Elf_Internal_Sym *isymbuf; | |
3267 | Elf_Internal_Shdr *hdr; | |
3268 | unsigned int i, localsyms; | |
3269 | ||
3270 | if ((abfd->flags & DYNAMIC) != 0) | |
3271 | return; | |
3272 | ||
3273 | hdr = &elf_tdata (abfd)->symtab_hdr; | |
3274 | localsyms = hdr->sh_info; | |
3275 | ||
3276 | /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field | |
3277 | should contain the number of local symbols, which should come before any | |
3278 | global symbols. Mapping symbols are always local. */ | |
3279 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, | |
3280 | NULL); | |
3281 | ||
3282 | /* No internal symbols read? Skip this BFD. */ | |
3283 | if (isymbuf == NULL) | |
3284 | return; | |
3285 | ||
3286 | for (i = 0; i < localsyms; i++) | |
3287 | { | |
3288 | Elf_Internal_Sym *isym = &isymbuf[i]; | |
3289 | asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
3290 | const char *name; | |
3291 | ||
3292 | if (sec != NULL | |
3293 | && ELF_ST_BIND (isym->st_info) == STB_LOCAL) | |
3294 | { | |
3295 | name = bfd_elf_string_from_elf_section (abfd, | |
3296 | hdr->sh_link, isym->st_name); | |
3297 | ||
3298 | if (bfd_is_arm_special_symbol_name (name, | |
3299 | BFD_ARM_SPECIAL_SYM_TYPE_MAP)) | |
3300 | elf32_arm_section_map_add (sec, name[1], isym->st_value); | |
3301 | } | |
3302 | } | |
3303 | } | |
3304 | ||
3305 | ||
3306 | void | |
3307 | bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info) | |
3308 | { | |
3309 | struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); | |
3310 | aeabi_attribute *out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
3311 | ||
3312 | /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */ | |
3313 | if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7) | |
3314 | { | |
3315 | switch (globals->vfp11_fix) | |
3316 | { | |
3317 | case BFD_ARM_VFP11_FIX_DEFAULT: | |
3318 | case BFD_ARM_VFP11_FIX_NONE: | |
3319 | globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE; | |
3320 | break; | |
3321 | ||
3322 | default: | |
3323 | /* Give a warning, but do as the user requests anyway. */ | |
3324 | (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum " | |
3325 | "workaround is not necessary for target architecture"), obfd); | |
3326 | } | |
3327 | } | |
3328 | else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT) | |
3329 | /* For earlier architectures, we might need the workaround, but do not | |
3330 | enable it by default. If users is running with broken hardware, they | |
3331 | must enable the erratum fix explicitly. */ | |
3332 | globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE; | |
3333 | } | |
3334 | ||
3335 | ||
3336 | enum bfd_arm_vfp11_pipe { | |
3337 | VFP11_FMAC, | |
3338 | VFP11_LS, | |
3339 | VFP11_DS, | |
3340 | VFP11_BAD | |
3341 | }; | |
3342 | ||
3343 | /* Return a VFP register number. This is encoded as RX:X for single-precision | |
3344 | registers, or X:RX for double-precision registers, where RX is the group of | |
3345 | four bits in the instruction encoding and X is the single extension bit. | |
3346 | RX and X fields are specified using their lowest (starting) bit. The return | |
3347 | value is: | |
3348 | ||
3349 | 0...31: single-precision registers s0...s31 | |
3350 | 32...63: double-precision registers d0...d31. | |
3351 | ||
3352 | Although X should be zero for VFP11 (encoding d0...d15 only), we might | |
3353 | encounter VFP3 instructions, so we allow the full range for DP registers. */ | |
3354 | ||
3355 | static unsigned int | |
3356 | bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx, | |
3357 | unsigned int x) | |
3358 | { | |
3359 | if (is_double) | |
3360 | return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32; | |
3361 | else | |
3362 | return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1); | |
3363 | } | |
3364 | ||
3365 | /* Set bits in *WMASK according to a register number REG as encoded by | |
3366 | bfd_arm_vfp11_regno(). Ignore d16-d31. */ | |
3367 | ||
3368 | static void | |
3369 | bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg) | |
3370 | { | |
3371 | if (reg < 32) | |
3372 | *wmask |= 1 << reg; | |
3373 | else if (reg < 48) | |
3374 | *wmask |= 3 << ((reg - 32) * 2); | |
3375 | } | |
3376 | ||
3377 | /* Return TRUE if WMASK overwrites anything in REGS. */ | |
3378 | ||
3379 | static bfd_boolean | |
3380 | bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs) | |
3381 | { | |
3382 | int i; | |
3383 | ||
3384 | for (i = 0; i < numregs; i++) | |
3385 | { | |
3386 | unsigned int reg = regs[i]; | |
3387 | ||
3388 | if (reg < 32 && (wmask & (1 << reg)) != 0) | |
3389 | return TRUE; | |
3390 | ||
3391 | reg -= 32; | |
3392 | ||
3393 | if (reg >= 16) | |
3394 | continue; | |
3395 | ||
3396 | if ((wmask & (3 << (reg * 2))) != 0) | |
3397 | return TRUE; | |
3398 | } | |
3399 | ||
3400 | return FALSE; | |
3401 | } | |
3402 | ||
3403 | /* In this function, we're interested in two things: finding input registers | |
3404 | for VFP data-processing instructions, and finding the set of registers which | |
3405 | arbitrary VFP instructions may write to. We use a 32-bit unsigned int to | |
3406 | hold the written set, so FLDM etc. are easy to deal with (we're only | |
3407 | interested in 32 SP registers or 16 dp registers, due to the VFP version | |
3408 | implemented by the chip in question). DP registers are marked by setting | |
3409 | both SP registers in the write mask). */ | |
3410 | ||
3411 | static enum bfd_arm_vfp11_pipe | |
3412 | bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs, | |
3413 | int *numregs) | |
3414 | { | |
3415 | enum bfd_arm_vfp11_pipe pipe = VFP11_BAD; | |
3416 | bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0; | |
3417 | ||
3418 | if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */ | |
3419 | { | |
3420 | unsigned int pqrs; | |
3421 | unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22); | |
3422 | unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5); | |
3423 | ||
3424 | pqrs = ((insn & 0x00800000) >> 20) | |
3425 | | ((insn & 0x00300000) >> 19) | |
3426 | | ((insn & 0x00000040) >> 6); | |
3427 | ||
3428 | switch (pqrs) | |
3429 | { | |
3430 | case 0: /* fmac[sd]. */ | |
3431 | case 1: /* fnmac[sd]. */ | |
3432 | case 2: /* fmsc[sd]. */ | |
3433 | case 3: /* fnmsc[sd]. */ | |
3434 | pipe = VFP11_FMAC; | |
3435 | bfd_arm_vfp11_write_mask (destmask, fd); | |
3436 | regs[0] = fd; | |
3437 | regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */ | |
3438 | regs[2] = fm; | |
3439 | *numregs = 3; | |
3440 | break; | |
3441 | ||
3442 | case 4: /* fmul[sd]. */ | |
3443 | case 5: /* fnmul[sd]. */ | |
3444 | case 6: /* fadd[sd]. */ | |
3445 | case 7: /* fsub[sd]. */ | |
3446 | pipe = VFP11_FMAC; | |
3447 | goto vfp_binop; | |
3448 | ||
3449 | case 8: /* fdiv[sd]. */ | |
3450 | pipe = VFP11_DS; | |
3451 | vfp_binop: | |
3452 | bfd_arm_vfp11_write_mask (destmask, fd); | |
3453 | regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */ | |
3454 | regs[1] = fm; | |
3455 | *numregs = 2; | |
3456 | break; | |
3457 | ||
3458 | case 15: /* extended opcode. */ | |
3459 | { | |
3460 | unsigned int extn = ((insn >> 15) & 0x1e) | |
3461 | | ((insn >> 7) & 1); | |
3462 | ||
3463 | switch (extn) | |
3464 | { | |
3465 | case 0: /* fcpy[sd]. */ | |
3466 | case 1: /* fabs[sd]. */ | |
3467 | case 2: /* fneg[sd]. */ | |
3468 | case 8: /* fcmp[sd]. */ | |
3469 | case 9: /* fcmpe[sd]. */ | |
3470 | case 10: /* fcmpz[sd]. */ | |
3471 | case 11: /* fcmpez[sd]. */ | |
3472 | case 16: /* fuito[sd]. */ | |
3473 | case 17: /* fsito[sd]. */ | |
3474 | case 24: /* ftoui[sd]. */ | |
3475 | case 25: /* ftouiz[sd]. */ | |
3476 | case 26: /* ftosi[sd]. */ | |
3477 | case 27: /* ftosiz[sd]. */ | |
3478 | /* These instructions will not bounce due to underflow. */ | |
3479 | *numregs = 0; | |
3480 | pipe = VFP11_FMAC; | |
3481 | break; | |
3482 | ||
3483 | case 3: /* fsqrt[sd]. */ | |
3484 | /* fsqrt cannot underflow, but it can (perhaps) overwrite | |
3485 | registers to cause the erratum in previous instructions. */ | |
3486 | bfd_arm_vfp11_write_mask (destmask, fd); | |
3487 | pipe = VFP11_DS; | |
3488 | break; | |
3489 | ||
3490 | case 15: /* fcvt{ds,sd}. */ | |
3491 | { | |
3492 | int rnum = 0; | |
3493 | ||
3494 | bfd_arm_vfp11_write_mask (destmask, fd); | |
3495 | ||
3496 | /* Only FCVTSD can underflow. */ | |
3497 | if ((insn & 0x100) != 0) | |
3498 | regs[rnum++] = fm; | |
3499 | ||
3500 | *numregs = rnum; | |
3501 | ||
3502 | pipe = VFP11_FMAC; | |
3503 | } | |
3504 | break; | |
3505 | ||
3506 | default: | |
3507 | return VFP11_BAD; | |
3508 | } | |
3509 | } | |
3510 | break; | |
3511 | ||
3512 | default: | |
3513 | return VFP11_BAD; | |
3514 | } | |
3515 | } | |
3516 | /* Two-register transfer. */ | |
3517 | else if ((insn & 0x0fe00ed0) == 0x0c400a10) | |
3518 | { | |
3519 | unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5); | |
3520 | ||
3521 | if ((insn & 0x100000) == 0) | |
3522 | { | |
3523 | if (is_double) | |
3524 | bfd_arm_vfp11_write_mask (destmask, fm); | |
3525 | else | |
3526 | { | |
3527 | bfd_arm_vfp11_write_mask (destmask, fm); | |
3528 | bfd_arm_vfp11_write_mask (destmask, fm + 1); | |
3529 | } | |
3530 | } | |
3531 | ||
3532 | pipe = VFP11_LS; | |
3533 | } | |
3534 | else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */ | |
3535 | { | |
3536 | int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22); | |
3537 | unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1); | |
3538 | ||
3539 | switch (puw) | |
3540 | { | |
3541 | case 0: /* Two-reg transfer. We should catch these above. */ | |
3542 | abort (); | |
3543 | ||
3544 | case 2: /* fldm[sdx]. */ | |
3545 | case 3: | |
3546 | case 5: | |
3547 | { | |
3548 | unsigned int i, offset = insn & 0xff; | |
3549 | ||
3550 | if (is_double) | |
3551 | offset >>= 1; | |
3552 | ||
3553 | for (i = fd; i < fd + offset; i++) | |
3554 | bfd_arm_vfp11_write_mask (destmask, i); | |
3555 | } | |
3556 | break; | |
3557 | ||
3558 | case 4: /* fld[sd]. */ | |
3559 | case 6: | |
3560 | bfd_arm_vfp11_write_mask (destmask, fd); | |
3561 | break; | |
3562 | ||
3563 | default: | |
3564 | return VFP11_BAD; | |
3565 | } | |
3566 | ||
3567 | pipe = VFP11_LS; | |
3568 | } | |
3569 | /* Single-register transfer. Note L==0. */ | |
3570 | else if ((insn & 0x0f100e10) == 0x0e000a10) | |
3571 | { | |
3572 | unsigned int opcode = (insn >> 21) & 7; | |
3573 | unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7); | |
3574 | ||
3575 | switch (opcode) | |
3576 | { | |
3577 | case 0: /* fmsr/fmdlr. */ | |
3578 | case 1: /* fmdhr. */ | |
3579 | /* Mark fmdhr and fmdlr as writing to the whole of the DP | |
3580 | destination register. I don't know if this is exactly right, | |
3581 | but it is the conservative choice. */ | |
3582 | bfd_arm_vfp11_write_mask (destmask, fn); | |
3583 | break; | |
3584 | ||
3585 | case 7: /* fmxr. */ | |
3586 | break; | |
3587 | } | |
3588 | ||
3589 | pipe = VFP11_LS; | |
3590 | } | |
3591 | ||
3592 | return pipe; | |
3593 | } | |
3594 | ||
3595 | ||
3596 | static int elf32_arm_compare_mapping (const void * a, const void * b); | |
3597 | ||
3598 | ||
3599 | /* Look for potentially-troublesome code sequences which might trigger the | |
3600 | VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet | |
3601 | (available from ARM) for details of the erratum. A short version is | |
3602 | described in ld.texinfo. */ | |
3603 | ||
3604 | bfd_boolean | |
3605 | bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info) | |
3606 | { | |
3607 | asection *sec; | |
3608 | bfd_byte *contents = NULL; | |
3609 | int state = 0; | |
3610 | int regs[3], numregs = 0; | |
3611 | struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); | |
3612 | int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR); | |
3613 | ||
3614 | /* We use a simple FSM to match troublesome VFP11 instruction sequences. | |
3615 | The states transition as follows: | |
3616 | ||
3617 | 0 -> 1 (vector) or 0 -> 2 (scalar) | |
3618 | A VFP FMAC-pipeline instruction has been seen. Fill | |
3619 | regs[0]..regs[numregs-1] with its input operands. Remember this | |
3620 | instruction in 'first_fmac'. | |
3621 | ||
3622 | 1 -> 2 | |
3623 | Any instruction, except for a VFP instruction which overwrites | |
3624 | regs[*]. | |
3625 | ||
3626 | 1 -> 3 [ -> 0 ] or | |
3627 | 2 -> 3 [ -> 0 ] | |
3628 | A VFP instruction has been seen which overwrites any of regs[*]. | |
3629 | We must make a veneer! Reset state to 0 before examining next | |
3630 | instruction. | |
3631 | ||
3632 | 2 -> 0 | |
3633 | If we fail to match anything in state 2, reset to state 0 and reset | |
3634 | the instruction pointer to the instruction after 'first_fmac'. | |
3635 | ||
3636 | If the VFP11 vector mode is in use, there must be at least two unrelated | |
3637 | instructions between anti-dependent VFP11 instructions to properly avoid | |
3638 | triggering the erratum, hence the use of the extra state 1. | |
3639 | */ | |
3640 | ||
3641 | /* If we are only performing a partial link do not bother | |
3642 | to construct any glue. */ | |
3643 | if (link_info->relocatable) | |
3644 | return TRUE; | |
3645 | ||
3646 | /* We should have chosen a fix type by the time we get here. */ | |
3647 | BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT); | |
3648 | ||
3649 | if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE) | |
3650 | return TRUE; | |
3651 | ||
3652 | for (sec = abfd->sections; sec != NULL; sec = sec->next) | |
3653 | { | |
3654 | unsigned int i, span, first_fmac = 0, veneer_of_insn = 0; | |
3655 | struct _arm_elf_section_data *sec_data; | |
3656 | ||
3657 | /* If we don't have executable progbits, we're not interested in this | |
3658 | section. Also skip if section is to be excluded. */ | |
3659 | if (elf_section_type (sec) != SHT_PROGBITS | |
3660 | || (elf_section_flags (sec) & SHF_EXECINSTR) == 0 | |
3661 | || (sec->flags & SEC_EXCLUDE) != 0 | |
3662 | || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0) | |
3663 | continue; | |
3664 | ||
3665 | sec_data = elf32_arm_section_data (sec); | |
3666 | ||
3667 | if (sec_data->mapcount == 0) | |
3668 | continue; | |
3669 | ||
3670 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
3671 | contents = elf_section_data (sec)->this_hdr.contents; | |
3672 | else if (! bfd_malloc_and_get_section (abfd, sec, &contents)) | |
3673 | goto error_return; | |
3674 | ||
3675 | qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map), | |
3676 | elf32_arm_compare_mapping); | |
3677 | ||
3678 | for (span = 0; span < sec_data->mapcount; span++) | |
3679 | { | |
3680 | unsigned int span_start = sec_data->map[span].vma; | |
3681 | unsigned int span_end = (span == sec_data->mapcount - 1) | |
3682 | ? sec->size : sec_data->map[span + 1].vma; | |
3683 | char span_type = sec_data->map[span].type; | |
3684 | ||
3685 | /* FIXME: Only ARM mode is supported at present. We may need to | |
3686 | support Thumb-2 mode also at some point. */ | |
3687 | if (span_type != 'a') | |
3688 | continue; | |
3689 | ||
3690 | for (i = span_start; i < span_end;) | |
3691 | { | |
3692 | unsigned int next_i = i + 4; | |
3693 | unsigned int insn = bfd_big_endian (abfd) | |
3694 | ? (contents[i] << 24) | |
3695 | | (contents[i + 1] << 16) | |
3696 | | (contents[i + 2] << 8) | |
3697 | | contents[i + 3] | |
3698 | : (contents[i + 3] << 24) | |
3699 | | (contents[i + 2] << 16) | |
3700 | | (contents[i + 1] << 8) | |
3701 | | contents[i]; | |
3702 | unsigned int writemask = 0; | |
3703 | enum bfd_arm_vfp11_pipe pipe; | |
3704 | ||
3705 | switch (state) | |
3706 | { | |
3707 | case 0: | |
3708 | pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs, | |
3709 | &numregs); | |
3710 | /* I'm assuming the VFP11 erratum can trigger with denorm | |
3711 | operands on either the FMAC or the DS pipeline. This might | |
3712 | lead to slightly overenthusiastic veneer insertion. */ | |
3713 | if (pipe == VFP11_FMAC || pipe == VFP11_DS) | |
3714 | { | |
3715 | state = use_vector ? 1 : 2; | |
3716 | first_fmac = i; | |
3717 | veneer_of_insn = insn; | |
3718 | } | |
3719 | break; | |
3720 | ||
3721 | case 1: | |
3722 | { | |
3723 | int other_regs[3], other_numregs; | |
3724 | pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, | |
3725 | other_regs, | |
3726 | &other_numregs); | |
3727 | if (pipe != VFP11_BAD | |
3728 | && bfd_arm_vfp11_antidependency (writemask, regs, | |
3729 | numregs)) | |
3730 | state = 3; | |
3731 | else | |
3732 | state = 2; | |
3733 | } | |
3734 | break; | |
3735 | ||
3736 | case 2: | |
3737 | { | |
3738 | int other_regs[3], other_numregs; | |
3739 | pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, | |
3740 | other_regs, | |
3741 | &other_numregs); | |
3742 | if (pipe != VFP11_BAD | |
3743 | && bfd_arm_vfp11_antidependency (writemask, regs, | |
3744 | numregs)) | |
3745 | state = 3; | |
3746 | else | |
3747 | { | |
3748 | state = 0; | |
3749 | next_i = first_fmac + 4; | |
3750 | } | |
3751 | } | |
3752 | break; | |
3753 | ||
3754 | case 3: | |
3755 | abort (); /* Should be unreachable. */ | |
3756 | } | |
3757 | ||
3758 | if (state == 3) | |
3759 | { | |
3760 | elf32_vfp11_erratum_list *newerr | |
3761 | = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list)); | |
3762 | int errcount; | |
3763 | ||
3764 | errcount = ++(elf32_arm_section_data (sec)->erratumcount); | |
3765 | ||
3766 | newerr->u.b.vfp_insn = veneer_of_insn; | |
3767 | ||
3768 | switch (span_type) | |
3769 | { | |
3770 | case 'a': | |
3771 | newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER; | |
3772 | break; | |
3773 | ||
3774 | default: | |
3775 | abort (); | |
3776 | } | |
3777 | ||
3778 | record_vfp11_erratum_veneer (link_info, newerr, abfd, sec, | |
3779 | first_fmac); | |
3780 | ||
3781 | newerr->vma = -1; | |
3782 | ||
3783 | newerr->next = sec_data->erratumlist; | |
3784 | sec_data->erratumlist = newerr; | |
3785 | ||
3786 | state = 0; | |
3787 | } | |
3788 | ||
3789 | i = next_i; | |
3790 | } | |
3791 | } | |
3792 | ||
3793 | if (contents != NULL | |
3794 | && elf_section_data (sec)->this_hdr.contents != contents) | |
3795 | free (contents); | |
3796 | contents = NULL; | |
3797 | } | |
3798 | ||
3799 | return TRUE; | |
3800 | ||
3801 | error_return: | |
3802 | if (contents != NULL | |
3803 | && elf_section_data (sec)->this_hdr.contents != contents) | |
3804 | free (contents); | |
3805 | ||
3806 | return FALSE; | |
3807 | } | |
3808 | ||
3809 | /* Find virtual-memory addresses for VFP11 erratum veneers and return locations | |
3810 | after sections have been laid out, using specially-named symbols. */ | |
3811 | ||
3812 | void | |
3813 | bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd, | |
3814 | struct bfd_link_info *link_info) | |
3815 | { | |
3816 | asection *sec; | |
3817 | struct elf32_arm_link_hash_table *globals; | |
3818 | char *tmp_name; | |
3819 | ||
3820 | if (link_info->relocatable) | |
3821 | return; | |
3822 | ||
3823 | globals = elf32_arm_hash_table (link_info); | |
3824 | ||
3825 | tmp_name = bfd_malloc ((bfd_size_type) strlen | |
3826 | (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10); | |
3827 | ||
3828 | for (sec = abfd->sections; sec != NULL; sec = sec->next) | |
3829 | { | |
3830 | struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec); | |
3831 | elf32_vfp11_erratum_list *errnode = sec_data->erratumlist; | |
3832 | ||
3833 | for (; errnode != NULL; errnode = errnode->next) | |
3834 | { | |
3835 | struct elf_link_hash_entry *myh; | |
3836 | bfd_vma vma; | |
3837 | ||
3838 | switch (errnode->type) | |
3839 | { | |
3840 | case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER: | |
3841 | case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER: | |
3842 | /* Find veneer symbol. */ | |
3843 | sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME, | |
3844 | errnode->u.b.veneer->u.v.id); | |
3845 | ||
3846 | myh = elf_link_hash_lookup | |
3847 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); | |
3848 | ||
3849 | if (myh == NULL) | |
3850 | (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer " | |
3851 | "`%s'"), abfd, tmp_name); | |
3852 | ||
3853 | vma = myh->root.u.def.section->output_section->vma | |
3854 | + myh->root.u.def.section->output_offset | |
3855 | + myh->root.u.def.value; | |
3856 | ||
3857 | errnode->u.b.veneer->vma = vma; | |
3858 | break; | |
3859 | ||
3860 | case VFP11_ERRATUM_ARM_VENEER: | |
3861 | case VFP11_ERRATUM_THUMB_VENEER: | |
3862 | /* Find return location. */ | |
3863 | sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r", | |
3864 | errnode->u.v.id); | |
3865 | ||
3866 | myh = elf_link_hash_lookup | |
3867 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); | |
3868 | ||
3869 | if (myh == NULL) | |
3870 | (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer " | |
3871 | "`%s'"), abfd, tmp_name); | |
3872 | ||
3873 | vma = myh->root.u.def.section->output_section->vma | |
3874 | + myh->root.u.def.section->output_offset | |
3875 | + myh->root.u.def.value; | |
3876 | ||
3877 | errnode->u.v.branch->vma = vma; | |
3878 | break; | |
3879 | ||
3880 | default: | |
3881 | abort (); | |
3882 | } | |
3883 | } | |
3884 | } | |
3885 | ||
3886 | free (tmp_name); | |
3887 | } | |
3888 | ||
3889 | ||
eb043451 PB |
3890 | /* Set target relocation values needed during linking. */ |
3891 | ||
3892 | void | |
bf21ed78 MS |
3893 | bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd, |
3894 | struct bfd_link_info *link_info, | |
eb043451 | 3895 | int target1_is_rel, |
319850b4 | 3896 | char * target2_type, |
33bfe774 | 3897 | int fix_v4bx, |
c7b8f16e | 3898 | int use_blx, |
bf21ed78 | 3899 | bfd_arm_vfp11_fix vfp11_fix, |
27e55c4d | 3900 | int no_enum_warn, int pic_veneer) |
eb043451 PB |
3901 | { |
3902 | struct elf32_arm_link_hash_table *globals; | |
3903 | ||
3904 | globals = elf32_arm_hash_table (link_info); | |
3905 | ||
3906 | globals->target1_is_rel = target1_is_rel; | |
3907 | if (strcmp (target2_type, "rel") == 0) | |
3908 | globals->target2_reloc = R_ARM_REL32; | |
eeac373a PB |
3909 | else if (strcmp (target2_type, "abs") == 0) |
3910 | globals->target2_reloc = R_ARM_ABS32; | |
eb043451 PB |
3911 | else if (strcmp (target2_type, "got-rel") == 0) |
3912 | globals->target2_reloc = R_ARM_GOT_PREL; | |
3913 | else | |
3914 | { | |
3915 | _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."), | |
3916 | target2_type); | |
3917 | } | |
319850b4 | 3918 | globals->fix_v4bx = fix_v4bx; |
33bfe774 | 3919 | globals->use_blx |= use_blx; |
c7b8f16e | 3920 | globals->vfp11_fix = vfp11_fix; |
27e55c4d | 3921 | globals->pic_veneer = pic_veneer; |
bf21ed78 MS |
3922 | |
3923 | elf32_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; | |
eb043451 | 3924 | } |
eb043451 | 3925 | |
252b5132 RH |
3926 | /* The thumb form of a long branch is a bit finicky, because the offset |
3927 | encoding is split over two fields, each in it's own instruction. They | |
f21f3fe0 | 3928 | can occur in any order. So given a thumb form of long branch, and an |
252b5132 | 3929 | offset, insert the offset into the thumb branch and return finished |
f21f3fe0 | 3930 | instruction. |
252b5132 | 3931 | |
f21f3fe0 | 3932 | It takes two thumb instructions to encode the target address. Each has |
4cc11e76 | 3933 | 11 bits to invest. The upper 11 bits are stored in one (identified by |
f21f3fe0 UD |
3934 | H-0.. see below), the lower 11 bits are stored in the other (identified |
3935 | by H-1). | |
252b5132 | 3936 | |
f21f3fe0 | 3937 | Combine together and shifted left by 1 (it's a half word address) and |
252b5132 RH |
3938 | there you have it. |
3939 | ||
3940 | Op: 1111 = F, | |
3941 | H-0, upper address-0 = 000 | |
3942 | Op: 1111 = F, | |
3943 | H-1, lower address-0 = 800 | |
3944 | ||
f21f3fe0 | 3945 | They can be ordered either way, but the arm tools I've seen always put |
252b5132 RH |
3946 | the lower one first. It probably doesn't matter. krk@cygnus.com |
3947 | ||
3948 | XXX: Actually the order does matter. The second instruction (H-1) | |
3949 | moves the computed address into the PC, so it must be the second one | |
3950 | in the sequence. The problem, however is that whilst little endian code | |
3951 | stores the instructions in HI then LOW order, big endian code does the | |
dfc5f959 | 3952 | reverse. nickc@cygnus.com. */ |
252b5132 | 3953 | |
dfc5f959 NC |
3954 | #define LOW_HI_ORDER 0xF800F000 |
3955 | #define HI_LOW_ORDER 0xF000F800 | |
252b5132 RH |
3956 | |
3957 | static insn32 | |
57e8b36a | 3958 | insert_thumb_branch (insn32 br_insn, int rel_off) |
252b5132 RH |
3959 | { |
3960 | unsigned int low_bits; | |
3961 | unsigned int high_bits; | |
3962 | ||
252b5132 RH |
3963 | BFD_ASSERT ((rel_off & 1) != 1); |
3964 | ||
dfc5f959 NC |
3965 | rel_off >>= 1; /* Half word aligned address. */ |
3966 | low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ | |
3967 | high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ | |
252b5132 RH |
3968 | |
3969 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) | |
3970 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; | |
3971 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) | |
3972 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; | |
3973 | else | |
9b485d32 | 3974 | /* FIXME: abort is probably not the right call. krk@cygnus.com */ |
57e8b36a | 3975 | abort (); /* Error - not a valid branch instruction form. */ |
252b5132 | 3976 | |
252b5132 RH |
3977 | return br_insn; |
3978 | } | |
3979 | ||
52ab56c2 PB |
3980 | |
3981 | /* Store an Arm insn into an output section not processed by | |
3982 | elf32_arm_write_section. */ | |
3983 | ||
3984 | static void | |
3985 | put_arm_insn (struct elf32_arm_link_hash_table *htab, | |
3986 | bfd * output_bfd, bfd_vma val, void * ptr) | |
3987 | { | |
3988 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
3989 | bfd_putl32 (val, ptr); | |
3990 | else | |
3991 | bfd_putb32 (val, ptr); | |
3992 | } | |
3993 | ||
3994 | ||
3995 | /* Store a 16-bit Thumb insn into an output section not processed by | |
3996 | elf32_arm_write_section. */ | |
3997 | ||
3998 | static void | |
3999 | put_thumb_insn (struct elf32_arm_link_hash_table *htab, | |
4000 | bfd * output_bfd, bfd_vma val, void * ptr) | |
4001 | { | |
4002 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
4003 | bfd_putl16 (val, ptr); | |
4004 | else | |
4005 | bfd_putb16 (val, ptr); | |
4006 | } | |
4007 | ||
4008 | ||
9b485d32 NC |
4009 | /* Thumb code calling an ARM function. */ |
4010 | ||
252b5132 | 4011 | static int |
57e8b36a NC |
4012 | elf32_thumb_to_arm_stub (struct bfd_link_info * info, |
4013 | const char * name, | |
4014 | bfd * input_bfd, | |
4015 | bfd * output_bfd, | |
4016 | asection * input_section, | |
4017 | bfd_byte * hit_data, | |
4018 | asection * sym_sec, | |
4019 | bfd_vma offset, | |
4020 | bfd_signed_vma addend, | |
f2a9dd69 DJ |
4021 | bfd_vma val, |
4022 | char **error_message) | |
252b5132 | 4023 | { |
bcbdc74c | 4024 | asection * s = 0; |
dc810e39 | 4025 | bfd_vma my_offset; |
252b5132 RH |
4026 | unsigned long int tmp; |
4027 | long int ret_offset; | |
bcbdc74c NC |
4028 | struct elf_link_hash_entry * myh; |
4029 | struct elf32_arm_link_hash_table * globals; | |
252b5132 | 4030 | |
f2a9dd69 | 4031 | myh = find_thumb_glue (info, name, error_message); |
252b5132 | 4032 | if (myh == NULL) |
b34976b6 | 4033 | return FALSE; |
252b5132 RH |
4034 | |
4035 | globals = elf32_arm_hash_table (info); | |
4036 | ||
4037 | BFD_ASSERT (globals != NULL); | |
4038 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
4039 | ||
4040 | my_offset = myh->root.u.def.value; | |
4041 | ||
4042 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
4043 | THUMB2ARM_GLUE_SECTION_NAME); | |
4044 | ||
4045 | BFD_ASSERT (s != NULL); | |
4046 | BFD_ASSERT (s->contents != NULL); | |
4047 | BFD_ASSERT (s->output_section != NULL); | |
4048 | ||
4049 | if ((my_offset & 0x01) == 0x01) | |
4050 | { | |
4051 | if (sym_sec != NULL | |
4052 | && sym_sec->owner != NULL | |
4053 | && !INTERWORK_FLAG (sym_sec->owner)) | |
4054 | { | |
8f615d07 | 4055 | (*_bfd_error_handler) |
d003868e AM |
4056 | (_("%B(%s): warning: interworking not enabled.\n" |
4057 | " first occurrence: %B: thumb call to arm"), | |
4058 | sym_sec->owner, input_bfd, name); | |
252b5132 | 4059 | |
b34976b6 | 4060 | return FALSE; |
252b5132 RH |
4061 | } |
4062 | ||
4063 | --my_offset; | |
4064 | myh->root.u.def.value = my_offset; | |
4065 | ||
52ab56c2 PB |
4066 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn, |
4067 | s->contents + my_offset); | |
252b5132 | 4068 | |
52ab56c2 PB |
4069 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn, |
4070 | s->contents + my_offset + 2); | |
252b5132 RH |
4071 | |
4072 | ret_offset = | |
9b485d32 NC |
4073 | /* Address of destination of the stub. */ |
4074 | ((bfd_signed_vma) val) | |
252b5132 | 4075 | - ((bfd_signed_vma) |
57e8b36a NC |
4076 | /* Offset from the start of the current section |
4077 | to the start of the stubs. */ | |
9b485d32 NC |
4078 | (s->output_offset |
4079 | /* Offset of the start of this stub from the start of the stubs. */ | |
4080 | + my_offset | |
4081 | /* Address of the start of the current section. */ | |
4082 | + s->output_section->vma) | |
4083 | /* The branch instruction is 4 bytes into the stub. */ | |
4084 | + 4 | |
4085 | /* ARM branches work from the pc of the instruction + 8. */ | |
4086 | + 8); | |
252b5132 | 4087 | |
52ab56c2 PB |
4088 | put_arm_insn (globals, output_bfd, |
4089 | (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), | |
4090 | s->contents + my_offset + 4); | |
252b5132 RH |
4091 | } |
4092 | ||
4093 | BFD_ASSERT (my_offset <= globals->thumb_glue_size); | |
4094 | ||
427bfd90 NC |
4095 | /* Now go back and fix up the original BL insn to point to here. */ |
4096 | ret_offset = | |
4097 | /* Address of where the stub is located. */ | |
4098 | (s->output_section->vma + s->output_offset + my_offset) | |
4099 | /* Address of where the BL is located. */ | |
57e8b36a NC |
4100 | - (input_section->output_section->vma + input_section->output_offset |
4101 | + offset) | |
427bfd90 NC |
4102 | /* Addend in the relocation. */ |
4103 | - addend | |
4104 | /* Biassing for PC-relative addressing. */ | |
4105 | - 8; | |
252b5132 RH |
4106 | |
4107 | tmp = bfd_get_32 (input_bfd, hit_data | |
4108 | - input_section->vma); | |
4109 | ||
4110 | bfd_put_32 (output_bfd, | |
dc810e39 | 4111 | (bfd_vma) insert_thumb_branch (tmp, ret_offset), |
252b5132 RH |
4112 | hit_data - input_section->vma); |
4113 | ||
b34976b6 | 4114 | return TRUE; |
252b5132 RH |
4115 | } |
4116 | ||
a4fd1a8e | 4117 | /* Populate an Arm to Thumb stub. Returns the stub symbol. */ |
9b485d32 | 4118 | |
a4fd1a8e PB |
4119 | static struct elf_link_hash_entry * |
4120 | elf32_arm_create_thumb_stub (struct bfd_link_info * info, | |
4121 | const char * name, | |
4122 | bfd * input_bfd, | |
4123 | bfd * output_bfd, | |
4124 | asection * sym_sec, | |
4125 | bfd_vma val, | |
f2a9dd69 DJ |
4126 | asection *s, |
4127 | char **error_message) | |
252b5132 | 4128 | { |
dc810e39 | 4129 | bfd_vma my_offset; |
252b5132 | 4130 | long int ret_offset; |
bcbdc74c NC |
4131 | struct elf_link_hash_entry * myh; |
4132 | struct elf32_arm_link_hash_table * globals; | |
252b5132 | 4133 | |
f2a9dd69 | 4134 | myh = find_arm_glue (info, name, error_message); |
252b5132 | 4135 | if (myh == NULL) |
a4fd1a8e | 4136 | return NULL; |
252b5132 RH |
4137 | |
4138 | globals = elf32_arm_hash_table (info); | |
4139 | ||
4140 | BFD_ASSERT (globals != NULL); | |
4141 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
4142 | ||
4143 | my_offset = myh->root.u.def.value; | |
252b5132 RH |
4144 | |
4145 | if ((my_offset & 0x01) == 0x01) | |
4146 | { | |
4147 | if (sym_sec != NULL | |
4148 | && sym_sec->owner != NULL | |
4149 | && !INTERWORK_FLAG (sym_sec->owner)) | |
4150 | { | |
8f615d07 | 4151 | (*_bfd_error_handler) |
d003868e AM |
4152 | (_("%B(%s): warning: interworking not enabled.\n" |
4153 | " first occurrence: %B: arm call to thumb"), | |
4154 | sym_sec->owner, input_bfd, name); | |
252b5132 | 4155 | } |
9b485d32 | 4156 | |
252b5132 RH |
4157 | --my_offset; |
4158 | myh->root.u.def.value = my_offset; | |
4159 | ||
27e55c4d PB |
4160 | if (info->shared || globals->root.is_relocatable_executable |
4161 | || globals->pic_veneer) | |
8f6277f5 PB |
4162 | { |
4163 | /* For relocatable objects we can't use absolute addresses, | |
4164 | so construct the address from a relative offset. */ | |
4165 | /* TODO: If the offset is small it's probably worth | |
4166 | constructing the address with adds. */ | |
52ab56c2 PB |
4167 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn, |
4168 | s->contents + my_offset); | |
4169 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn, | |
4170 | s->contents + my_offset + 4); | |
4171 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn, | |
4172 | s->contents + my_offset + 8); | |
8f6277f5 PB |
4173 | /* Adjust the offset by 4 for the position of the add, |
4174 | and 8 for the pipeline offset. */ | |
4175 | ret_offset = (val - (s->output_offset | |
4176 | + s->output_section->vma | |
4177 | + my_offset + 12)) | |
4178 | | 1; | |
4179 | bfd_put_32 (output_bfd, ret_offset, | |
4180 | s->contents + my_offset + 12); | |
4181 | } | |
4182 | else | |
4183 | { | |
52ab56c2 PB |
4184 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn, |
4185 | s->contents + my_offset); | |
252b5132 | 4186 | |
52ab56c2 PB |
4187 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn, |
4188 | s->contents + my_offset + 4); | |
252b5132 | 4189 | |
8f6277f5 PB |
4190 | /* It's a thumb address. Add the low order bit. */ |
4191 | bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, | |
4192 | s->contents + my_offset + 8); | |
4193 | } | |
252b5132 RH |
4194 | } |
4195 | ||
4196 | BFD_ASSERT (my_offset <= globals->arm_glue_size); | |
4197 | ||
a4fd1a8e PB |
4198 | return myh; |
4199 | } | |
4200 | ||
4201 | /* Arm code calling a Thumb function. */ | |
4202 | ||
4203 | static int | |
4204 | elf32_arm_to_thumb_stub (struct bfd_link_info * info, | |
4205 | const char * name, | |
4206 | bfd * input_bfd, | |
4207 | bfd * output_bfd, | |
4208 | asection * input_section, | |
4209 | bfd_byte * hit_data, | |
4210 | asection * sym_sec, | |
4211 | bfd_vma offset, | |
4212 | bfd_signed_vma addend, | |
f2a9dd69 DJ |
4213 | bfd_vma val, |
4214 | char **error_message) | |
a4fd1a8e PB |
4215 | { |
4216 | unsigned long int tmp; | |
4217 | bfd_vma my_offset; | |
4218 | asection * s; | |
4219 | long int ret_offset; | |
4220 | struct elf_link_hash_entry * myh; | |
4221 | struct elf32_arm_link_hash_table * globals; | |
4222 | ||
4223 | globals = elf32_arm_hash_table (info); | |
4224 | ||
4225 | BFD_ASSERT (globals != NULL); | |
4226 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
4227 | ||
4228 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
4229 | ARM2THUMB_GLUE_SECTION_NAME); | |
4230 | BFD_ASSERT (s != NULL); | |
4231 | BFD_ASSERT (s->contents != NULL); | |
4232 | BFD_ASSERT (s->output_section != NULL); | |
4233 | ||
4234 | myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd, | |
f2a9dd69 | 4235 | sym_sec, val, s, error_message); |
a4fd1a8e PB |
4236 | if (!myh) |
4237 | return FALSE; | |
4238 | ||
4239 | my_offset = myh->root.u.def.value; | |
252b5132 RH |
4240 | tmp = bfd_get_32 (input_bfd, hit_data); |
4241 | tmp = tmp & 0xFF000000; | |
4242 | ||
9b485d32 | 4243 | /* Somehow these are both 4 too far, so subtract 8. */ |
dc810e39 AM |
4244 | ret_offset = (s->output_offset |
4245 | + my_offset | |
4246 | + s->output_section->vma | |
4247 | - (input_section->output_offset | |
4248 | + input_section->output_section->vma | |
4249 | + offset + addend) | |
4250 | - 8); | |
9a5aca8c | 4251 | |
252b5132 RH |
4252 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); |
4253 | ||
dc810e39 | 4254 | bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); |
252b5132 | 4255 | |
b34976b6 | 4256 | return TRUE; |
252b5132 RH |
4257 | } |
4258 | ||
a4fd1a8e PB |
4259 | /* Populate Arm stub for an exported Thumb function. */ |
4260 | ||
4261 | static bfd_boolean | |
4262 | elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf) | |
4263 | { | |
4264 | struct bfd_link_info * info = (struct bfd_link_info *) inf; | |
4265 | asection * s; | |
4266 | struct elf_link_hash_entry * myh; | |
4267 | struct elf32_arm_link_hash_entry *eh; | |
4268 | struct elf32_arm_link_hash_table * globals; | |
4269 | asection *sec; | |
4270 | bfd_vma val; | |
f2a9dd69 | 4271 | char *error_message; |
a4fd1a8e PB |
4272 | |
4273 | eh = elf32_arm_hash_entry(h); | |
4274 | /* Allocate stubs for exported Thumb functions on v4t. */ | |
4275 | if (eh->export_glue == NULL) | |
4276 | return TRUE; | |
4277 | ||
4278 | globals = elf32_arm_hash_table (info); | |
4279 | ||
4280 | BFD_ASSERT (globals != NULL); | |
4281 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
4282 | ||
4283 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
4284 | ARM2THUMB_GLUE_SECTION_NAME); | |
4285 | BFD_ASSERT (s != NULL); | |
4286 | BFD_ASSERT (s->contents != NULL); | |
4287 | BFD_ASSERT (s->output_section != NULL); | |
4288 | ||
4289 | sec = eh->export_glue->root.u.def.section; | |
0eaedd0e PB |
4290 | |
4291 | BFD_ASSERT (sec->output_section != NULL); | |
4292 | ||
a4fd1a8e PB |
4293 | val = eh->export_glue->root.u.def.value + sec->output_offset |
4294 | + sec->output_section->vma; | |
4295 | myh = elf32_arm_create_thumb_stub (info, h->root.root.string, | |
4296 | h->root.u.def.section->owner, | |
f2a9dd69 DJ |
4297 | globals->obfd, sec, val, s, |
4298 | &error_message); | |
a4fd1a8e PB |
4299 | BFD_ASSERT (myh); |
4300 | return TRUE; | |
4301 | } | |
4302 | ||
4303 | /* Generate Arm stubs for exported Thumb symbols. */ | |
4304 | static void | |
4305 | elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
4306 | struct bfd_link_info *link_info) | |
4307 | { | |
4308 | struct elf32_arm_link_hash_table * globals; | |
4309 | ||
4310 | if (!link_info) | |
4311 | return; | |
4312 | ||
4313 | globals = elf32_arm_hash_table (link_info); | |
84c08195 PB |
4314 | /* If blx is available then exported Thumb symbols are OK and there is |
4315 | nothing to do. */ | |
a4fd1a8e PB |
4316 | if (globals->use_blx) |
4317 | return; | |
4318 | ||
4319 | elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub, | |
4320 | link_info); | |
4321 | } | |
4322 | ||
eb043451 PB |
4323 | /* Some relocations map to different relocations depending on the |
4324 | target. Return the real relocation. */ | |
4325 | static int | |
4326 | arm_real_reloc_type (struct elf32_arm_link_hash_table * globals, | |
4327 | int r_type) | |
4328 | { | |
4329 | switch (r_type) | |
4330 | { | |
4331 | case R_ARM_TARGET1: | |
4332 | if (globals->target1_is_rel) | |
4333 | return R_ARM_REL32; | |
4334 | else | |
4335 | return R_ARM_ABS32; | |
4336 | ||
4337 | case R_ARM_TARGET2: | |
4338 | return globals->target2_reloc; | |
4339 | ||
4340 | default: | |
4341 | return r_type; | |
4342 | } | |
4343 | } | |
eb043451 | 4344 | |
ba93b8ac DJ |
4345 | /* Return the base VMA address which should be subtracted from real addresses |
4346 | when resolving @dtpoff relocation. | |
4347 | This is PT_TLS segment p_vaddr. */ | |
4348 | ||
4349 | static bfd_vma | |
4350 | dtpoff_base (struct bfd_link_info *info) | |
4351 | { | |
4352 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
4353 | if (elf_hash_table (info)->tls_sec == NULL) | |
4354 | return 0; | |
4355 | return elf_hash_table (info)->tls_sec->vma; | |
4356 | } | |
4357 | ||
4358 | /* Return the relocation value for @tpoff relocation | |
4359 | if STT_TLS virtual address is ADDRESS. */ | |
4360 | ||
4361 | static bfd_vma | |
4362 | tpoff (struct bfd_link_info *info, bfd_vma address) | |
4363 | { | |
4364 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
4365 | bfd_vma base; | |
4366 | ||
4367 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
4368 | if (htab->tls_sec == NULL) | |
4369 | return 0; | |
4370 | base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power); | |
4371 | return address - htab->tls_sec->vma + base; | |
4372 | } | |
4373 | ||
00a97672 RS |
4374 | /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA. |
4375 | VALUE is the relocation value. */ | |
4376 | ||
4377 | static bfd_reloc_status_type | |
4378 | elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value) | |
4379 | { | |
4380 | if (value > 0xfff) | |
4381 | return bfd_reloc_overflow; | |
4382 | ||
4383 | value |= bfd_get_32 (abfd, data) & 0xfffff000; | |
4384 | bfd_put_32 (abfd, value, data); | |
4385 | return bfd_reloc_ok; | |
4386 | } | |
4387 | ||
4962c51a MS |
4388 | /* For a given value of n, calculate the value of G_n as required to |
4389 | deal with group relocations. We return it in the form of an | |
4390 | encoded constant-and-rotation, together with the final residual. If n is | |
4391 | specified as less than zero, then final_residual is filled with the | |
4392 | input value and no further action is performed. */ | |
4393 | ||
4394 | static bfd_vma | |
4395 | calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual) | |
4396 | { | |
4397 | int current_n; | |
4398 | bfd_vma g_n; | |
4399 | bfd_vma encoded_g_n = 0; | |
4400 | bfd_vma residual = value; /* Also known as Y_n. */ | |
4401 | ||
4402 | for (current_n = 0; current_n <= n; current_n++) | |
4403 | { | |
4404 | int shift; | |
4405 | ||
4406 | /* Calculate which part of the value to mask. */ | |
4407 | if (residual == 0) | |
4408 | shift = 0; | |
4409 | else | |
4410 | { | |
4411 | int msb; | |
4412 | ||
4413 | /* Determine the most significant bit in the residual and | |
4414 | align the resulting value to a 2-bit boundary. */ | |
4415 | for (msb = 30; msb >= 0; msb -= 2) | |
4416 | if (residual & (3 << msb)) | |
4417 | break; | |
4418 | ||
4419 | /* The desired shift is now (msb - 6), or zero, whichever | |
4420 | is the greater. */ | |
4421 | shift = msb - 6; | |
4422 | if (shift < 0) | |
4423 | shift = 0; | |
4424 | } | |
4425 | ||
4426 | /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */ | |
4427 | g_n = residual & (0xff << shift); | |
4428 | encoded_g_n = (g_n >> shift) | |
4429 | | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8); | |
4430 | ||
4431 | /* Calculate the residual for the next time around. */ | |
4432 | residual &= ~g_n; | |
4433 | } | |
4434 | ||
4435 | *final_residual = residual; | |
4436 | ||
4437 | return encoded_g_n; | |
4438 | } | |
4439 | ||
4440 | /* Given an ARM instruction, determine whether it is an ADD or a SUB. | |
4441 | Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */ | |
4442 | static int | |
4443 | identify_add_or_sub(bfd_vma insn) | |
4444 | { | |
4445 | int opcode = insn & 0x1e00000; | |
4446 | ||
4447 | if (opcode == 1 << 23) /* ADD */ | |
4448 | return 1; | |
4449 | ||
4450 | if (opcode == 1 << 22) /* SUB */ | |
4451 | return -1; | |
4452 | ||
4453 | return 0; | |
4454 | } | |
4455 | ||
e95de063 MS |
4456 | /* Determine if we're dealing with a Thumb-2 object. */ |
4457 | ||
4458 | static int using_thumb2 (struct elf32_arm_link_hash_table *globals) | |
4459 | { | |
4460 | int arch = elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch); | |
4461 | return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7; | |
4462 | } | |
4463 | ||
252b5132 | 4464 | /* Perform a relocation as part of a final link. */ |
9b485d32 | 4465 | |
252b5132 | 4466 | static bfd_reloc_status_type |
57e8b36a NC |
4467 | elf32_arm_final_link_relocate (reloc_howto_type * howto, |
4468 | bfd * input_bfd, | |
4469 | bfd * output_bfd, | |
4470 | asection * input_section, | |
4471 | bfd_byte * contents, | |
4472 | Elf_Internal_Rela * rel, | |
4473 | bfd_vma value, | |
4474 | struct bfd_link_info * info, | |
4475 | asection * sym_sec, | |
4476 | const char * sym_name, | |
4477 | int sym_flags, | |
0945cdfd | 4478 | struct elf_link_hash_entry * h, |
f2a9dd69 DJ |
4479 | bfd_boolean * unresolved_reloc_p, |
4480 | char **error_message) | |
252b5132 RH |
4481 | { |
4482 | unsigned long r_type = howto->type; | |
4483 | unsigned long r_symndx; | |
4484 | bfd_byte * hit_data = contents + rel->r_offset; | |
4485 | bfd * dynobj = NULL; | |
4486 | Elf_Internal_Shdr * symtab_hdr; | |
4487 | struct elf_link_hash_entry ** sym_hashes; | |
4488 | bfd_vma * local_got_offsets; | |
4489 | asection * sgot = NULL; | |
4490 | asection * splt = NULL; | |
4491 | asection * sreloc = NULL; | |
252b5132 | 4492 | bfd_vma addend; |
ba96a88f NC |
4493 | bfd_signed_vma signed_addend; |
4494 | struct elf32_arm_link_hash_table * globals; | |
f21f3fe0 | 4495 | |
9c504268 PB |
4496 | globals = elf32_arm_hash_table (info); |
4497 | ||
9c504268 PB |
4498 | /* Some relocation type map to different relocations depending on the |
4499 | target. We pick the right one here. */ | |
eb043451 PB |
4500 | r_type = arm_real_reloc_type (globals, r_type); |
4501 | if (r_type != howto->type) | |
4502 | howto = elf32_arm_howto_from_type (r_type); | |
9c504268 | 4503 | |
cac15327 NC |
4504 | /* If the start address has been set, then set the EF_ARM_HASENTRY |
4505 | flag. Setting this more than once is redundant, but the cost is | |
4506 | not too high, and it keeps the code simple. | |
99e4ae17 | 4507 | |
cac15327 NC |
4508 | The test is done here, rather than somewhere else, because the |
4509 | start address is only set just before the final link commences. | |
4510 | ||
4511 | Note - if the user deliberately sets a start address of 0, the | |
4512 | flag will not be set. */ | |
4513 | if (bfd_get_start_address (output_bfd) != 0) | |
4514 | elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; | |
99e4ae17 | 4515 | |
252b5132 RH |
4516 | dynobj = elf_hash_table (info)->dynobj; |
4517 | if (dynobj) | |
4518 | { | |
4519 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
4520 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
4521 | } | |
4522 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
4523 | sym_hashes = elf_sym_hashes (input_bfd); | |
4524 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
4525 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4526 | ||
4e7fd91e | 4527 | if (globals->use_rel) |
ba96a88f | 4528 | { |
4e7fd91e PB |
4529 | addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; |
4530 | ||
4531 | if (addend & ((howto->src_mask + 1) >> 1)) | |
4532 | { | |
4533 | signed_addend = -1; | |
4534 | signed_addend &= ~ howto->src_mask; | |
4535 | signed_addend |= addend; | |
4536 | } | |
4537 | else | |
4538 | signed_addend = addend; | |
ba96a88f NC |
4539 | } |
4540 | else | |
4e7fd91e | 4541 | addend = signed_addend = rel->r_addend; |
f21f3fe0 | 4542 | |
252b5132 RH |
4543 | switch (r_type) |
4544 | { | |
4545 | case R_ARM_NONE: | |
28a094c2 DJ |
4546 | /* We don't need to find a value for this symbol. It's just a |
4547 | marker. */ | |
4548 | *unresolved_reloc_p = FALSE; | |
252b5132 RH |
4549 | return bfd_reloc_ok; |
4550 | ||
00a97672 RS |
4551 | case R_ARM_ABS12: |
4552 | if (!globals->vxworks_p) | |
4553 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
4554 | ||
252b5132 RH |
4555 | case R_ARM_PC24: |
4556 | case R_ARM_ABS32: | |
bb224fc3 | 4557 | case R_ARM_ABS32_NOI: |
252b5132 | 4558 | case R_ARM_REL32: |
bb224fc3 | 4559 | case R_ARM_REL32_NOI: |
5b5bb741 PB |
4560 | case R_ARM_CALL: |
4561 | case R_ARM_JUMP24: | |
dfc5f959 | 4562 | case R_ARM_XPC25: |
eb043451 | 4563 | case R_ARM_PREL31: |
7359ea65 | 4564 | case R_ARM_PLT32: |
7359ea65 DJ |
4565 | /* Handle relocations which should use the PLT entry. ABS32/REL32 |
4566 | will use the symbol's value, which may point to a PLT entry, but we | |
4567 | don't need to handle that here. If we created a PLT entry, all | |
4568 | branches in this object should go to it. */ | |
bb224fc3 MS |
4569 | if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32 |
4570 | && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI) | |
7359ea65 | 4571 | && h != NULL |
c84cd8ee | 4572 | && splt != NULL |
7359ea65 DJ |
4573 | && h->plt.offset != (bfd_vma) -1) |
4574 | { | |
c84cd8ee DJ |
4575 | /* If we've created a .plt section, and assigned a PLT entry to |
4576 | this function, it should not be known to bind locally. If | |
4577 | it were, we would have cleared the PLT entry. */ | |
7359ea65 DJ |
4578 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); |
4579 | ||
4580 | value = (splt->output_section->vma | |
4581 | + splt->output_offset | |
4582 | + h->plt.offset); | |
0945cdfd | 4583 | *unresolved_reloc_p = FALSE; |
7359ea65 DJ |
4584 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
4585 | contents, rel->r_offset, value, | |
00a97672 | 4586 | rel->r_addend); |
7359ea65 DJ |
4587 | } |
4588 | ||
67687978 PB |
4589 | /* When generating a shared object or relocatable executable, these |
4590 | relocations are copied into the output file to be resolved at | |
4591 | run time. */ | |
4592 | if ((info->shared || globals->root.is_relocatable_executable) | |
7359ea65 | 4593 | && (input_section->flags & SEC_ALLOC) |
bb224fc3 | 4594 | && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI) |
ee06dc07 | 4595 | || !SYMBOL_CALLS_LOCAL (info, h)) |
7359ea65 DJ |
4596 | && (h == NULL |
4597 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
4598 | || h->root.type != bfd_link_hash_undefweak) | |
4599 | && r_type != R_ARM_PC24 | |
5b5bb741 PB |
4600 | && r_type != R_ARM_CALL |
4601 | && r_type != R_ARM_JUMP24 | |
ee06dc07 | 4602 | && r_type != R_ARM_PREL31 |
7359ea65 | 4603 | && r_type != R_ARM_PLT32) |
252b5132 | 4604 | { |
947216bf AM |
4605 | Elf_Internal_Rela outrel; |
4606 | bfd_byte *loc; | |
b34976b6 | 4607 | bfd_boolean skip, relocate; |
f21f3fe0 | 4608 | |
0945cdfd DJ |
4609 | *unresolved_reloc_p = FALSE; |
4610 | ||
252b5132 RH |
4611 | if (sreloc == NULL) |
4612 | { | |
4613 | const char * name; | |
f21f3fe0 | 4614 | |
252b5132 RH |
4615 | name = (bfd_elf_string_from_elf_section |
4616 | (input_bfd, | |
4617 | elf_elfheader (input_bfd)->e_shstrndx, | |
4618 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
4619 | if (name == NULL) | |
4620 | return bfd_reloc_notsupported; | |
f21f3fe0 | 4621 | |
00a97672 | 4622 | BFD_ASSERT (reloc_section_p (globals, name, input_section)); |
f21f3fe0 | 4623 | |
252b5132 RH |
4624 | sreloc = bfd_get_section_by_name (dynobj, name); |
4625 | BFD_ASSERT (sreloc != NULL); | |
4626 | } | |
f21f3fe0 | 4627 | |
b34976b6 AM |
4628 | skip = FALSE; |
4629 | relocate = FALSE; | |
f21f3fe0 | 4630 | |
00a97672 | 4631 | outrel.r_addend = addend; |
c629eae0 JJ |
4632 | outrel.r_offset = |
4633 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
4634 | rel->r_offset); | |
4635 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 4636 | skip = TRUE; |
0bb2d96a | 4637 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 4638 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
4639 | outrel.r_offset += (input_section->output_section->vma |
4640 | + input_section->output_offset); | |
f21f3fe0 | 4641 | |
252b5132 | 4642 | if (skip) |
0bb2d96a | 4643 | memset (&outrel, 0, sizeof outrel); |
5e681ec4 PB |
4644 | else if (h != NULL |
4645 | && h->dynindx != -1 | |
7359ea65 | 4646 | && (!info->shared |
5e681ec4 | 4647 | || !info->symbolic |
f5385ebf | 4648 | || !h->def_regular)) |
5e681ec4 | 4649 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
252b5132 RH |
4650 | else |
4651 | { | |
a16385dc MM |
4652 | int symbol; |
4653 | ||
5e681ec4 | 4654 | /* This symbol is local, or marked to become local. */ |
b7693d02 DJ |
4655 | if (sym_flags == STT_ARM_TFUNC) |
4656 | value |= 1; | |
a16385dc | 4657 | if (globals->symbian_p) |
6366ff1e | 4658 | { |
74541ad4 AM |
4659 | asection *osec; |
4660 | ||
6366ff1e MM |
4661 | /* On Symbian OS, the data segment and text segement |
4662 | can be relocated independently. Therefore, we | |
4663 | must indicate the segment to which this | |
4664 | relocation is relative. The BPABI allows us to | |
4665 | use any symbol in the right segment; we just use | |
4666 | the section symbol as it is convenient. (We | |
4667 | cannot use the symbol given by "h" directly as it | |
74541ad4 AM |
4668 | will not appear in the dynamic symbol table.) |
4669 | ||
4670 | Note that the dynamic linker ignores the section | |
4671 | symbol value, so we don't subtract osec->vma | |
4672 | from the emitted reloc addend. */ | |
10dbd1f3 | 4673 | if (sym_sec) |
74541ad4 | 4674 | osec = sym_sec->output_section; |
10dbd1f3 | 4675 | else |
74541ad4 AM |
4676 | osec = input_section->output_section; |
4677 | symbol = elf_section_data (osec)->dynindx; | |
4678 | if (symbol == 0) | |
4679 | { | |
4680 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
4681 | ||
4682 | if ((osec->flags & SEC_READONLY) == 0 | |
4683 | && htab->data_index_section != NULL) | |
4684 | osec = htab->data_index_section; | |
4685 | else | |
4686 | osec = htab->text_index_section; | |
4687 | symbol = elf_section_data (osec)->dynindx; | |
4688 | } | |
6366ff1e MM |
4689 | BFD_ASSERT (symbol != 0); |
4690 | } | |
a16385dc MM |
4691 | else |
4692 | /* On SVR4-ish systems, the dynamic loader cannot | |
4693 | relocate the text and data segments independently, | |
4694 | so the symbol does not matter. */ | |
4695 | symbol = 0; | |
4696 | outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE); | |
00a97672 RS |
4697 | if (globals->use_rel) |
4698 | relocate = TRUE; | |
4699 | else | |
4700 | outrel.r_addend += value; | |
252b5132 | 4701 | } |
f21f3fe0 | 4702 | |
947216bf | 4703 | loc = sreloc->contents; |
00a97672 RS |
4704 | loc += sreloc->reloc_count++ * RELOC_SIZE (globals); |
4705 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
9a5aca8c | 4706 | |
f21f3fe0 | 4707 | /* If this reloc is against an external symbol, we do not want to |
252b5132 | 4708 | fiddle with the addend. Otherwise, we need to include the symbol |
9b485d32 | 4709 | value so that it becomes an addend for the dynamic reloc. */ |
252b5132 RH |
4710 | if (! relocate) |
4711 | return bfd_reloc_ok; | |
9a5aca8c | 4712 | |
f21f3fe0 | 4713 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
252b5132 RH |
4714 | contents, rel->r_offset, value, |
4715 | (bfd_vma) 0); | |
4716 | } | |
4717 | else switch (r_type) | |
4718 | { | |
00a97672 RS |
4719 | case R_ARM_ABS12: |
4720 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
4721 | ||
dfc5f959 | 4722 | case R_ARM_XPC25: /* Arm BLX instruction. */ |
5b5bb741 PB |
4723 | case R_ARM_CALL: |
4724 | case R_ARM_JUMP24: | |
dfc5f959 | 4725 | case R_ARM_PC24: /* Arm B/BL instruction */ |
7359ea65 | 4726 | case R_ARM_PLT32: |
dfc5f959 | 4727 | if (r_type == R_ARM_XPC25) |
252b5132 | 4728 | { |
dfc5f959 NC |
4729 | /* Check for Arm calling Arm function. */ |
4730 | /* FIXME: Should we translate the instruction into a BL | |
4731 | instruction instead ? */ | |
4732 | if (sym_flags != STT_ARM_TFUNC) | |
d003868e AM |
4733 | (*_bfd_error_handler) |
4734 | (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), | |
4735 | input_bfd, | |
4736 | h ? h->root.root.string : "(local)"); | |
dfc5f959 | 4737 | } |
39b41c9c | 4738 | else if (r_type != R_ARM_CALL || !globals->use_blx) |
dfc5f959 NC |
4739 | { |
4740 | /* Check for Arm calling Thumb function. */ | |
4741 | if (sym_flags == STT_ARM_TFUNC) | |
4742 | { | |
f2a9dd69 DJ |
4743 | if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd, |
4744 | output_bfd, input_section, | |
4745 | hit_data, sym_sec, rel->r_offset, | |
4746 | signed_addend, value, | |
4747 | error_message)) | |
4748 | return bfd_reloc_ok; | |
4749 | else | |
4750 | return bfd_reloc_dangerous; | |
dfc5f959 | 4751 | } |
252b5132 | 4752 | } |
ba96a88f | 4753 | |
dea514f5 PB |
4754 | /* The ARM ELF ABI says that this reloc is computed as: S - P + A |
4755 | where: | |
4756 | S is the address of the symbol in the relocation. | |
4757 | P is address of the instruction being relocated. | |
4758 | A is the addend (extracted from the instruction) in bytes. | |
4759 | ||
4760 | S is held in 'value'. | |
4761 | P is the base address of the section containing the | |
4762 | instruction plus the offset of the reloc into that | |
4763 | section, ie: | |
4764 | (input_section->output_section->vma + | |
4765 | input_section->output_offset + | |
4766 | rel->r_offset). | |
4767 | A is the addend, converted into bytes, ie: | |
4768 | (signed_addend * 4) | |
4769 | ||
4770 | Note: None of these operations have knowledge of the pipeline | |
4771 | size of the processor, thus it is up to the assembler to | |
4772 | encode this information into the addend. */ | |
4773 | value -= (input_section->output_section->vma | |
4774 | + input_section->output_offset); | |
4775 | value -= rel->r_offset; | |
4e7fd91e PB |
4776 | if (globals->use_rel) |
4777 | value += (signed_addend << howto->size); | |
4778 | else | |
4779 | /* RELA addends do not have to be adjusted by howto->size. */ | |
4780 | value += signed_addend; | |
23080146 | 4781 | |
dcb5e6e6 NC |
4782 | signed_addend = value; |
4783 | signed_addend >>= howto->rightshift; | |
9a5aca8c | 4784 | |
59f2c4e7 NC |
4785 | /* It is not an error for an undefined weak reference to be |
4786 | out of range. Any program that branches to such a symbol | |
9a5aca8c AM |
4787 | is going to crash anyway, so there is no point worrying |
4788 | about getting the destination exactly right. */ | |
59f2c4e7 NC |
4789 | if (! h || h->root.type != bfd_link_hash_undefweak) |
4790 | { | |
9b485d32 | 4791 | /* Perform a signed range check. */ |
dcb5e6e6 | 4792 | if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) |
59f2c4e7 NC |
4793 | || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) |
4794 | return bfd_reloc_overflow; | |
4795 | } | |
9a5aca8c | 4796 | |
39b41c9c PB |
4797 | addend = (value & 2); |
4798 | ||
4799 | value = (signed_addend & howto->dst_mask) | |
4800 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); | |
4801 | ||
4802 | /* Set the H bit in the BLX instruction. */ | |
4803 | if (sym_flags == STT_ARM_TFUNC) | |
4804 | { | |
4805 | if (addend) | |
4806 | value |= (1 << 24); | |
4807 | else | |
4808 | value &= ~(bfd_vma)(1 << 24); | |
4809 | } | |
4810 | if (r_type == R_ARM_CALL) | |
4811 | { | |
4812 | /* Select the correct instruction (BL or BLX). */ | |
4813 | if (sym_flags == STT_ARM_TFUNC) | |
4814 | value |= (1 << 28); | |
4815 | else | |
4816 | { | |
4817 | value &= ~(bfd_vma)(1 << 28); | |
4818 | value |= (1 << 24); | |
4819 | } | |
4820 | } | |
252b5132 | 4821 | break; |
f21f3fe0 | 4822 | |
252b5132 RH |
4823 | case R_ARM_ABS32: |
4824 | value += addend; | |
4825 | if (sym_flags == STT_ARM_TFUNC) | |
4826 | value |= 1; | |
4827 | break; | |
f21f3fe0 | 4828 | |
bb224fc3 MS |
4829 | case R_ARM_ABS32_NOI: |
4830 | value += addend; | |
4831 | break; | |
4832 | ||
252b5132 | 4833 | case R_ARM_REL32: |
a8bc6c78 PB |
4834 | value += addend; |
4835 | if (sym_flags == STT_ARM_TFUNC) | |
4836 | value |= 1; | |
252b5132 | 4837 | value -= (input_section->output_section->vma |
62efb346 | 4838 | + input_section->output_offset + rel->r_offset); |
252b5132 | 4839 | break; |
eb043451 | 4840 | |
bb224fc3 MS |
4841 | case R_ARM_REL32_NOI: |
4842 | value += addend; | |
4843 | value -= (input_section->output_section->vma | |
4844 | + input_section->output_offset + rel->r_offset); | |
4845 | break; | |
4846 | ||
eb043451 PB |
4847 | case R_ARM_PREL31: |
4848 | value -= (input_section->output_section->vma | |
4849 | + input_section->output_offset + rel->r_offset); | |
4850 | value += signed_addend; | |
4851 | if (! h || h->root.type != bfd_link_hash_undefweak) | |
4852 | { | |
4853 | /* Check for overflow */ | |
4854 | if ((value ^ (value >> 1)) & (1 << 30)) | |
4855 | return bfd_reloc_overflow; | |
4856 | } | |
4857 | value &= 0x7fffffff; | |
4858 | value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000); | |
4859 | if (sym_flags == STT_ARM_TFUNC) | |
4860 | value |= 1; | |
4861 | break; | |
252b5132 | 4862 | } |
f21f3fe0 | 4863 | |
252b5132 RH |
4864 | bfd_put_32 (input_bfd, value, hit_data); |
4865 | return bfd_reloc_ok; | |
4866 | ||
4867 | case R_ARM_ABS8: | |
4868 | value += addend; | |
4869 | if ((long) value > 0x7f || (long) value < -0x80) | |
4870 | return bfd_reloc_overflow; | |
4871 | ||
4872 | bfd_put_8 (input_bfd, value, hit_data); | |
4873 | return bfd_reloc_ok; | |
4874 | ||
4875 | case R_ARM_ABS16: | |
4876 | value += addend; | |
4877 | ||
4878 | if ((long) value > 0x7fff || (long) value < -0x8000) | |
4879 | return bfd_reloc_overflow; | |
4880 | ||
4881 | bfd_put_16 (input_bfd, value, hit_data); | |
4882 | return bfd_reloc_ok; | |
4883 | ||
252b5132 | 4884 | case R_ARM_THM_ABS5: |
9b485d32 | 4885 | /* Support ldr and str instructions for the thumb. */ |
4e7fd91e PB |
4886 | if (globals->use_rel) |
4887 | { | |
4888 | /* Need to refetch addend. */ | |
4889 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
4890 | /* ??? Need to determine shift amount from operand size. */ | |
4891 | addend >>= howto->rightshift; | |
4892 | } | |
252b5132 RH |
4893 | value += addend; |
4894 | ||
4895 | /* ??? Isn't value unsigned? */ | |
4896 | if ((long) value > 0x1f || (long) value < -0x10) | |
4897 | return bfd_reloc_overflow; | |
4898 | ||
4899 | /* ??? Value needs to be properly shifted into place first. */ | |
4900 | value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; | |
4901 | bfd_put_16 (input_bfd, value, hit_data); | |
4902 | return bfd_reloc_ok; | |
4903 | ||
2cab6cc3 MS |
4904 | case R_ARM_THM_ALU_PREL_11_0: |
4905 | /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */ | |
4906 | { | |
4907 | bfd_vma insn; | |
4908 | bfd_signed_vma relocation; | |
4909 | ||
4910 | insn = (bfd_get_16 (input_bfd, hit_data) << 16) | |
4911 | | bfd_get_16 (input_bfd, hit_data + 2); | |
4912 | ||
4913 | if (globals->use_rel) | |
4914 | { | |
4915 | signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4) | |
4916 | | ((insn & (1 << 26)) >> 15); | |
4917 | if (insn & 0xf00000) | |
4918 | signed_addend = -signed_addend; | |
4919 | } | |
4920 | ||
4921 | relocation = value + signed_addend; | |
4922 | relocation -= (input_section->output_section->vma | |
4923 | + input_section->output_offset | |
4924 | + rel->r_offset); | |
4925 | ||
4926 | value = abs (relocation); | |
4927 | ||
4928 | if (value >= 0x1000) | |
4929 | return bfd_reloc_overflow; | |
4930 | ||
4931 | insn = (insn & 0xfb0f8f00) | (value & 0xff) | |
4932 | | ((value & 0x700) << 4) | |
4933 | | ((value & 0x800) << 15); | |
4934 | if (relocation < 0) | |
4935 | insn |= 0xa00000; | |
4936 | ||
4937 | bfd_put_16 (input_bfd, insn >> 16, hit_data); | |
4938 | bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); | |
4939 | ||
4940 | return bfd_reloc_ok; | |
4941 | } | |
4942 | ||
4943 | case R_ARM_THM_PC12: | |
4944 | /* Corresponds to: ldr.w reg, [pc, #offset]. */ | |
4945 | { | |
4946 | bfd_vma insn; | |
4947 | bfd_signed_vma relocation; | |
4948 | ||
4949 | insn = (bfd_get_16 (input_bfd, hit_data) << 16) | |
4950 | | bfd_get_16 (input_bfd, hit_data + 2); | |
4951 | ||
4952 | if (globals->use_rel) | |
4953 | { | |
4954 | signed_addend = insn & 0xfff; | |
4955 | if (!(insn & (1 << 23))) | |
4956 | signed_addend = -signed_addend; | |
4957 | } | |
4958 | ||
4959 | relocation = value + signed_addend; | |
4960 | relocation -= (input_section->output_section->vma | |
4961 | + input_section->output_offset | |
4962 | + rel->r_offset); | |
4963 | ||
4964 | value = abs (relocation); | |
4965 | ||
4966 | if (value >= 0x1000) | |
4967 | return bfd_reloc_overflow; | |
4968 | ||
4969 | insn = (insn & 0xff7ff000) | value; | |
4970 | if (relocation >= 0) | |
4971 | insn |= (1 << 23); | |
4972 | ||
4973 | bfd_put_16 (input_bfd, insn >> 16, hit_data); | |
4974 | bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); | |
4975 | ||
4976 | return bfd_reloc_ok; | |
4977 | } | |
4978 | ||
dfc5f959 | 4979 | case R_ARM_THM_XPC22: |
c19d1205 | 4980 | case R_ARM_THM_CALL: |
dfc5f959 | 4981 | /* Thumb BL (branch long instruction). */ |
252b5132 | 4982 | { |
b34976b6 | 4983 | bfd_vma relocation; |
e95de063 | 4984 | bfd_vma reloc_sign; |
b34976b6 AM |
4985 | bfd_boolean overflow = FALSE; |
4986 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
4987 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
e95de063 MS |
4988 | bfd_signed_vma reloc_signed_max; |
4989 | bfd_signed_vma reloc_signed_min; | |
b34976b6 | 4990 | bfd_vma check; |
252b5132 | 4991 | bfd_signed_vma signed_check; |
e95de063 MS |
4992 | int bitsize; |
4993 | int thumb2 = using_thumb2 (globals); | |
252b5132 | 4994 | |
e95de063 MS |
4995 | /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible |
4996 | with Thumb-1) involving the J1 and J2 bits. */ | |
4e7fd91e PB |
4997 | if (globals->use_rel) |
4998 | { | |
e95de063 MS |
4999 | bfd_vma s = (upper_insn & (1 << 10)) >> 10; |
5000 | bfd_vma upper = upper_insn & 0x3ff; | |
5001 | bfd_vma lower = lower_insn & 0x7ff; | |
5002 | bfd_vma j1 = (lower_insn & (1 << 13)) >> 13; | |
5003 | bfd_vma j2 = (lower_insn & (1 << 11)) >> 11; | |
5004 | bfd_vma i1 = j1 ^ s ? 0 : 1; | |
5005 | bfd_vma i2 = j2 ^ s ? 0 : 1; | |
5006 | ||
5007 | addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1); | |
5008 | /* Sign extend. */ | |
5009 | addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24); | |
5010 | ||
4e7fd91e PB |
5011 | signed_addend = addend; |
5012 | } | |
cb1afa5c | 5013 | |
dfc5f959 NC |
5014 | if (r_type == R_ARM_THM_XPC22) |
5015 | { | |
5016 | /* Check for Thumb to Thumb call. */ | |
5017 | /* FIXME: Should we translate the instruction into a BL | |
5018 | instruction instead ? */ | |
5019 | if (sym_flags == STT_ARM_TFUNC) | |
d003868e AM |
5020 | (*_bfd_error_handler) |
5021 | (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), | |
5022 | input_bfd, | |
5023 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
5024 | } |
5025 | else | |
252b5132 | 5026 | { |
dfc5f959 NC |
5027 | /* If it is not a call to Thumb, assume call to Arm. |
5028 | If it is a call relative to a section name, then it is not a | |
b7693d02 DJ |
5029 | function call at all, but rather a long jump. Calls through |
5030 | the PLT do not require stubs. */ | |
5031 | if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION | |
5032 | && (h == NULL || splt == NULL | |
5033 | || h->plt.offset == (bfd_vma) -1)) | |
dfc5f959 | 5034 | { |
39b41c9c PB |
5035 | if (globals->use_blx) |
5036 | { | |
5037 | /* Convert BL to BLX. */ | |
5038 | lower_insn = (lower_insn & ~0x1000) | 0x0800; | |
5039 | } | |
5040 | else if (elf32_thumb_to_arm_stub | |
dfc5f959 | 5041 | (info, sym_name, input_bfd, output_bfd, input_section, |
f2a9dd69 DJ |
5042 | hit_data, sym_sec, rel->r_offset, signed_addend, value, |
5043 | error_message)) | |
dfc5f959 NC |
5044 | return bfd_reloc_ok; |
5045 | else | |
5046 | return bfd_reloc_dangerous; | |
5047 | } | |
39b41c9c PB |
5048 | else if (sym_flags == STT_ARM_TFUNC && globals->use_blx) |
5049 | { | |
5050 | /* Make sure this is a BL. */ | |
5051 | lower_insn |= 0x1800; | |
5052 | } | |
252b5132 | 5053 | } |
f21f3fe0 | 5054 | |
b7693d02 DJ |
5055 | /* Handle calls via the PLT. */ |
5056 | if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) | |
5057 | { | |
5058 | value = (splt->output_section->vma | |
5059 | + splt->output_offset | |
5060 | + h->plt.offset); | |
33bfe774 JB |
5061 | if (globals->use_blx) |
5062 | { | |
5063 | /* If the Thumb BLX instruction is available, convert the | |
5064 | BL to a BLX instruction to call the ARM-mode PLT entry. */ | |
39b41c9c | 5065 | lower_insn = (lower_insn & ~0x1000) | 0x0800; |
33bfe774 JB |
5066 | } |
5067 | else | |
5068 | /* Target the Thumb stub before the ARM PLT entry. */ | |
5069 | value -= PLT_THUMB_STUB_SIZE; | |
0945cdfd | 5070 | *unresolved_reloc_p = FALSE; |
b7693d02 DJ |
5071 | } |
5072 | ||
ba96a88f | 5073 | relocation = value + signed_addend; |
f21f3fe0 | 5074 | |
252b5132 | 5075 | relocation -= (input_section->output_section->vma |
ba96a88f NC |
5076 | + input_section->output_offset |
5077 | + rel->r_offset); | |
9a5aca8c | 5078 | |
252b5132 RH |
5079 | check = relocation >> howto->rightshift; |
5080 | ||
5081 | /* If this is a signed value, the rightshift just dropped | |
5082 | leading 1 bits (assuming twos complement). */ | |
5083 | if ((bfd_signed_vma) relocation >= 0) | |
5084 | signed_check = check; | |
5085 | else | |
5086 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
5087 | ||
e95de063 MS |
5088 | /* Calculate the permissable maximum and minimum values for |
5089 | this relocation according to whether we're relocating for | |
5090 | Thumb-2 or not. */ | |
5091 | bitsize = howto->bitsize; | |
5092 | if (!thumb2) | |
5093 | bitsize -= 2; | |
5094 | reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift; | |
5095 | reloc_signed_min = ~reloc_signed_max; | |
5096 | ||
252b5132 | 5097 | /* Assumes two's complement. */ |
ba96a88f | 5098 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
b34976b6 | 5099 | overflow = TRUE; |
252b5132 | 5100 | |
39b41c9c | 5101 | if ((lower_insn & 0x1800) == 0x0800) |
c62e1cc3 NC |
5102 | /* For a BLX instruction, make sure that the relocation is rounded up |
5103 | to a word boundary. This follows the semantics of the instruction | |
5104 | which specifies that bit 1 of the target address will come from bit | |
5105 | 1 of the base address. */ | |
5106 | relocation = (relocation + 2) & ~ 3; | |
cb1afa5c | 5107 | |
e95de063 MS |
5108 | /* Put RELOCATION back into the insn. Assumes two's complement. |
5109 | We use the Thumb-2 encoding, which is safe even if dealing with | |
5110 | a Thumb-1 instruction by virtue of our overflow check above. */ | |
5111 | reloc_sign = (signed_check < 0) ? 1 : 0; | |
5112 | upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | |
5113 | | ((relocation >> 12) & 0x3ff) | |
5114 | | (reloc_sign << 10); | |
5115 | lower_insn = (lower_insn & ~(bfd_vma) 0x2fff) | |
5116 | | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13) | |
5117 | | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11) | |
5118 | | ((relocation >> 1) & 0x7ff); | |
c62e1cc3 | 5119 | |
252b5132 RH |
5120 | /* Put the relocated value back in the object file: */ |
5121 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
5122 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
5123 | ||
5124 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
5125 | } | |
5126 | break; | |
5127 | ||
c19d1205 ZW |
5128 | case R_ARM_THM_JUMP24: |
5129 | /* Thumb32 unconditional branch instruction. */ | |
5130 | { | |
5131 | bfd_vma relocation; | |
5132 | bfd_boolean overflow = FALSE; | |
5133 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
5134 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
5135 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
5136 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
5137 | bfd_vma check; | |
5138 | bfd_signed_vma signed_check; | |
5139 | ||
5140 | /* Need to refetch the addend, reconstruct the top three bits, and glue the | |
5141 | two pieces together. */ | |
5142 | if (globals->use_rel) | |
5143 | { | |
5144 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
5145 | bfd_vma hi = (upper_insn & 0x03ff); | |
5146 | bfd_vma I1 = (lower_insn & 0x2000) >> 13; | |
5147 | bfd_vma I2 = (lower_insn & 0x0800) >> 11; | |
5148 | bfd_vma lo = (lower_insn & 0x07ff); | |
5149 | ||
5150 | I1 = !(I1 ^ S); | |
5151 | I2 = !(I2 ^ S); | |
5152 | S = !S; | |
5153 | ||
5154 | signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1); | |
5155 | signed_addend -= (1 << 24); /* Sign extend. */ | |
5156 | } | |
5157 | ||
5158 | /* ??? Should handle interworking? GCC might someday try to | |
5159 | use this for tail calls. */ | |
5160 | ||
5161 | relocation = value + signed_addend; | |
5162 | relocation -= (input_section->output_section->vma | |
5163 | + input_section->output_offset | |
5164 | + rel->r_offset); | |
5165 | ||
5166 | check = relocation >> howto->rightshift; | |
5167 | ||
5168 | /* If this is a signed value, the rightshift just dropped | |
5169 | leading 1 bits (assuming twos complement). */ | |
5170 | if ((bfd_signed_vma) relocation >= 0) | |
5171 | signed_check = check; | |
5172 | else | |
5173 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
5174 | ||
5175 | /* Assumes two's complement. */ | |
5176 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
5177 | overflow = TRUE; | |
5178 | ||
5179 | /* Put RELOCATION back into the insn. */ | |
5180 | { | |
5181 | bfd_vma S = (relocation & 0x01000000) >> 24; | |
5182 | bfd_vma I1 = (relocation & 0x00800000) >> 23; | |
5183 | bfd_vma I2 = (relocation & 0x00400000) >> 22; | |
5184 | bfd_vma hi = (relocation & 0x003ff000) >> 12; | |
5185 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
5186 | ||
5187 | I1 = !(I1 ^ S); | |
5188 | I2 = !(I2 ^ S); | |
5189 | ||
5190 | upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi; | |
5191 | lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo; | |
5192 | } | |
5193 | ||
5194 | /* Put the relocated value back in the object file: */ | |
5195 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
5196 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
5197 | ||
5198 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
5199 | } | |
5200 | ||
5201 | case R_ARM_THM_JUMP19: | |
5202 | /* Thumb32 conditional branch instruction. */ | |
5203 | { | |
5204 | bfd_vma relocation; | |
5205 | bfd_boolean overflow = FALSE; | |
5206 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
5207 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
5208 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
5209 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
5210 | bfd_vma check; | |
5211 | bfd_signed_vma signed_check; | |
5212 | ||
5213 | /* Need to refetch the addend, reconstruct the top three bits, | |
5214 | and squish the two 11 bit pieces together. */ | |
5215 | if (globals->use_rel) | |
5216 | { | |
5217 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
5218 | bfd_vma upper = (upper_insn & 0x001f); | |
5219 | bfd_vma J1 = (lower_insn & 0x2000) >> 13; | |
5220 | bfd_vma J2 = (lower_insn & 0x0800) >> 11; | |
5221 | bfd_vma lower = (lower_insn & 0x07ff); | |
5222 | ||
5223 | upper |= J2 << 6; | |
5224 | upper |= J1 << 7; | |
5225 | upper |= ~S << 8; | |
5226 | upper -= 0x0100; /* Sign extend. */ | |
5227 | ||
5228 | addend = (upper << 12) | (lower << 1); | |
5229 | signed_addend = addend; | |
5230 | } | |
5231 | ||
5232 | /* ??? Should handle interworking? GCC might someday try to | |
5233 | use this for tail calls. */ | |
5234 | ||
5235 | relocation = value + signed_addend; | |
5236 | relocation -= (input_section->output_section->vma | |
5237 | + input_section->output_offset | |
5238 | + rel->r_offset); | |
5239 | ||
5240 | check = relocation >> howto->rightshift; | |
5241 | ||
5242 | /* If this is a signed value, the rightshift just dropped | |
5243 | leading 1 bits (assuming twos complement). */ | |
5244 | if ((bfd_signed_vma) relocation >= 0) | |
5245 | signed_check = check; | |
5246 | else | |
5247 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
5248 | ||
5249 | /* Assumes two's complement. */ | |
5250 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
5251 | overflow = TRUE; | |
5252 | ||
5253 | /* Put RELOCATION back into the insn. */ | |
5254 | { | |
5255 | bfd_vma S = (relocation & 0x00100000) >> 20; | |
5256 | bfd_vma J2 = (relocation & 0x00080000) >> 19; | |
5257 | bfd_vma J1 = (relocation & 0x00040000) >> 18; | |
5258 | bfd_vma hi = (relocation & 0x0003f000) >> 12; | |
5259 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
5260 | ||
5261 | upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi; | |
5262 | lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo; | |
5263 | } | |
5264 | ||
5265 | /* Put the relocated value back in the object file: */ | |
5266 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
5267 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
5268 | ||
5269 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
5270 | } | |
5271 | ||
5272 | case R_ARM_THM_JUMP11: | |
5273 | case R_ARM_THM_JUMP8: | |
5274 | case R_ARM_THM_JUMP6: | |
51c5503b NC |
5275 | /* Thumb B (branch) instruction). */ |
5276 | { | |
6cf9e9fe | 5277 | bfd_signed_vma relocation; |
51c5503b NC |
5278 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; |
5279 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
51c5503b NC |
5280 | bfd_signed_vma signed_check; |
5281 | ||
c19d1205 ZW |
5282 | /* CZB cannot jump backward. */ |
5283 | if (r_type == R_ARM_THM_JUMP6) | |
5284 | reloc_signed_min = 0; | |
5285 | ||
4e7fd91e | 5286 | if (globals->use_rel) |
6cf9e9fe | 5287 | { |
4e7fd91e PB |
5288 | /* Need to refetch addend. */ |
5289 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
5290 | if (addend & ((howto->src_mask + 1) >> 1)) | |
5291 | { | |
5292 | signed_addend = -1; | |
5293 | signed_addend &= ~ howto->src_mask; | |
5294 | signed_addend |= addend; | |
5295 | } | |
5296 | else | |
5297 | signed_addend = addend; | |
5298 | /* The value in the insn has been right shifted. We need to | |
5299 | undo this, so that we can perform the address calculation | |
5300 | in terms of bytes. */ | |
5301 | signed_addend <<= howto->rightshift; | |
6cf9e9fe | 5302 | } |
6cf9e9fe | 5303 | relocation = value + signed_addend; |
51c5503b NC |
5304 | |
5305 | relocation -= (input_section->output_section->vma | |
5306 | + input_section->output_offset | |
5307 | + rel->r_offset); | |
5308 | ||
6cf9e9fe NC |
5309 | relocation >>= howto->rightshift; |
5310 | signed_check = relocation; | |
c19d1205 ZW |
5311 | |
5312 | if (r_type == R_ARM_THM_JUMP6) | |
5313 | relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3); | |
5314 | else | |
5315 | relocation &= howto->dst_mask; | |
51c5503b | 5316 | relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); |
cedb70c5 | 5317 | |
51c5503b NC |
5318 | bfd_put_16 (input_bfd, relocation, hit_data); |
5319 | ||
5320 | /* Assumes two's complement. */ | |
5321 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
5322 | return bfd_reloc_overflow; | |
5323 | ||
5324 | return bfd_reloc_ok; | |
5325 | } | |
cedb70c5 | 5326 | |
8375c36b PB |
5327 | case R_ARM_ALU_PCREL7_0: |
5328 | case R_ARM_ALU_PCREL15_8: | |
5329 | case R_ARM_ALU_PCREL23_15: | |
5330 | { | |
5331 | bfd_vma insn; | |
5332 | bfd_vma relocation; | |
5333 | ||
5334 | insn = bfd_get_32 (input_bfd, hit_data); | |
4e7fd91e PB |
5335 | if (globals->use_rel) |
5336 | { | |
5337 | /* Extract the addend. */ | |
5338 | addend = (insn & 0xff) << ((insn & 0xf00) >> 7); | |
5339 | signed_addend = addend; | |
5340 | } | |
8375c36b PB |
5341 | relocation = value + signed_addend; |
5342 | ||
5343 | relocation -= (input_section->output_section->vma | |
5344 | + input_section->output_offset | |
5345 | + rel->r_offset); | |
5346 | insn = (insn & ~0xfff) | |
5347 | | ((howto->bitpos << 7) & 0xf00) | |
5348 | | ((relocation >> howto->bitpos) & 0xff); | |
5349 | bfd_put_32 (input_bfd, value, hit_data); | |
5350 | } | |
5351 | return bfd_reloc_ok; | |
5352 | ||
252b5132 RH |
5353 | case R_ARM_GNU_VTINHERIT: |
5354 | case R_ARM_GNU_VTENTRY: | |
5355 | return bfd_reloc_ok; | |
5356 | ||
c19d1205 | 5357 | case R_ARM_GOTOFF32: |
252b5132 RH |
5358 | /* Relocation is relative to the start of the |
5359 | global offset table. */ | |
5360 | ||
5361 | BFD_ASSERT (sgot != NULL); | |
5362 | if (sgot == NULL) | |
5363 | return bfd_reloc_notsupported; | |
9a5aca8c | 5364 | |
cedb70c5 | 5365 | /* If we are addressing a Thumb function, we need to adjust the |
ee29b9fb RE |
5366 | address by one, so that attempts to call the function pointer will |
5367 | correctly interpret it as Thumb code. */ | |
5368 | if (sym_flags == STT_ARM_TFUNC) | |
5369 | value += 1; | |
5370 | ||
252b5132 RH |
5371 | /* Note that sgot->output_offset is not involved in this |
5372 | calculation. We always want the start of .got. If we | |
5373 | define _GLOBAL_OFFSET_TABLE in a different way, as is | |
5374 | permitted by the ABI, we might have to change this | |
9b485d32 | 5375 | calculation. */ |
252b5132 | 5376 | value -= sgot->output_section->vma; |
f21f3fe0 | 5377 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 5378 | contents, rel->r_offset, value, |
00a97672 | 5379 | rel->r_addend); |
252b5132 RH |
5380 | |
5381 | case R_ARM_GOTPC: | |
a7c10850 | 5382 | /* Use global offset table as symbol value. */ |
252b5132 | 5383 | BFD_ASSERT (sgot != NULL); |
f21f3fe0 | 5384 | |
252b5132 RH |
5385 | if (sgot == NULL) |
5386 | return bfd_reloc_notsupported; | |
5387 | ||
0945cdfd | 5388 | *unresolved_reloc_p = FALSE; |
252b5132 | 5389 | value = sgot->output_section->vma; |
f21f3fe0 | 5390 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 5391 | contents, rel->r_offset, value, |
00a97672 | 5392 | rel->r_addend); |
f21f3fe0 | 5393 | |
252b5132 | 5394 | case R_ARM_GOT32: |
eb043451 | 5395 | case R_ARM_GOT_PREL: |
252b5132 | 5396 | /* Relocation is to the entry for this symbol in the |
9b485d32 | 5397 | global offset table. */ |
252b5132 RH |
5398 | if (sgot == NULL) |
5399 | return bfd_reloc_notsupported; | |
f21f3fe0 | 5400 | |
252b5132 RH |
5401 | if (h != NULL) |
5402 | { | |
5403 | bfd_vma off; | |
5e681ec4 | 5404 | bfd_boolean dyn; |
f21f3fe0 | 5405 | |
252b5132 RH |
5406 | off = h->got.offset; |
5407 | BFD_ASSERT (off != (bfd_vma) -1); | |
5e681ec4 | 5408 | dyn = globals->root.dynamic_sections_created; |
f21f3fe0 | 5409 | |
5e681ec4 | 5410 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
50d6c878 | 5411 | || (info->shared |
5e681ec4 PB |
5412 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
5413 | || (ELF_ST_VISIBILITY (h->other) | |
5414 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
5415 | { |
5416 | /* This is actually a static link, or it is a -Bsymbolic link | |
5417 | and the symbol is defined locally. We must initialize this | |
5418 | entry in the global offset table. Since the offset must | |
5419 | always be a multiple of 4, we use the least significant bit | |
5420 | to record whether we have initialized it already. | |
f21f3fe0 | 5421 | |
00a97672 | 5422 | When doing a dynamic link, we create a .rel(a).got relocation |
f21f3fe0 | 5423 | entry to initialize the value. This is done in the |
9b485d32 | 5424 | finish_dynamic_symbol routine. */ |
252b5132 RH |
5425 | if ((off & 1) != 0) |
5426 | off &= ~1; | |
5427 | else | |
5428 | { | |
ee29b9fb RE |
5429 | /* If we are addressing a Thumb function, we need to |
5430 | adjust the address by one, so that attempts to | |
5431 | call the function pointer will correctly | |
5432 | interpret it as Thumb code. */ | |
5433 | if (sym_flags == STT_ARM_TFUNC) | |
5434 | value |= 1; | |
5435 | ||
252b5132 RH |
5436 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
5437 | h->got.offset |= 1; | |
5438 | } | |
5439 | } | |
0945cdfd DJ |
5440 | else |
5441 | *unresolved_reloc_p = FALSE; | |
f21f3fe0 | 5442 | |
252b5132 RH |
5443 | value = sgot->output_offset + off; |
5444 | } | |
5445 | else | |
5446 | { | |
5447 | bfd_vma off; | |
f21f3fe0 | 5448 | |
252b5132 RH |
5449 | BFD_ASSERT (local_got_offsets != NULL && |
5450 | local_got_offsets[r_symndx] != (bfd_vma) -1); | |
f21f3fe0 | 5451 | |
252b5132 | 5452 | off = local_got_offsets[r_symndx]; |
f21f3fe0 | 5453 | |
252b5132 RH |
5454 | /* The offset must always be a multiple of 4. We use the |
5455 | least significant bit to record whether we have already | |
9b485d32 | 5456 | generated the necessary reloc. */ |
252b5132 RH |
5457 | if ((off & 1) != 0) |
5458 | off &= ~1; | |
5459 | else | |
5460 | { | |
b7693d02 DJ |
5461 | /* If we are addressing a Thumb function, we need to |
5462 | adjust the address by one, so that attempts to | |
5463 | call the function pointer will correctly | |
5464 | interpret it as Thumb code. */ | |
5465 | if (sym_flags == STT_ARM_TFUNC) | |
5466 | value |= 1; | |
5467 | ||
00a97672 RS |
5468 | if (globals->use_rel) |
5469 | bfd_put_32 (output_bfd, value, sgot->contents + off); | |
f21f3fe0 | 5470 | |
252b5132 RH |
5471 | if (info->shared) |
5472 | { | |
5473 | asection * srelgot; | |
947216bf AM |
5474 | Elf_Internal_Rela outrel; |
5475 | bfd_byte *loc; | |
f21f3fe0 | 5476 | |
00a97672 RS |
5477 | srelgot = (bfd_get_section_by_name |
5478 | (dynobj, RELOC_SECTION (globals, ".got"))); | |
252b5132 | 5479 | BFD_ASSERT (srelgot != NULL); |
f21f3fe0 | 5480 | |
00a97672 | 5481 | outrel.r_addend = addend + value; |
252b5132 | 5482 | outrel.r_offset = (sgot->output_section->vma |
f21f3fe0 | 5483 | + sgot->output_offset |
252b5132 RH |
5484 | + off); |
5485 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
947216bf | 5486 | loc = srelgot->contents; |
00a97672 RS |
5487 | loc += srelgot->reloc_count++ * RELOC_SIZE (globals); |
5488 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
252b5132 | 5489 | } |
f21f3fe0 | 5490 | |
252b5132 RH |
5491 | local_got_offsets[r_symndx] |= 1; |
5492 | } | |
f21f3fe0 | 5493 | |
252b5132 RH |
5494 | value = sgot->output_offset + off; |
5495 | } | |
eb043451 PB |
5496 | if (r_type != R_ARM_GOT32) |
5497 | value += sgot->output_section->vma; | |
9a5aca8c | 5498 | |
f21f3fe0 | 5499 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 5500 | contents, rel->r_offset, value, |
00a97672 | 5501 | rel->r_addend); |
f21f3fe0 | 5502 | |
ba93b8ac DJ |
5503 | case R_ARM_TLS_LDO32: |
5504 | value = value - dtpoff_base (info); | |
5505 | ||
5506 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
5507 | contents, rel->r_offset, value, |
5508 | rel->r_addend); | |
ba93b8ac DJ |
5509 | |
5510 | case R_ARM_TLS_LDM32: | |
5511 | { | |
5512 | bfd_vma off; | |
5513 | ||
5514 | if (globals->sgot == NULL) | |
5515 | abort (); | |
5516 | ||
5517 | off = globals->tls_ldm_got.offset; | |
5518 | ||
5519 | if ((off & 1) != 0) | |
5520 | off &= ~1; | |
5521 | else | |
5522 | { | |
5523 | /* If we don't know the module number, create a relocation | |
5524 | for it. */ | |
5525 | if (info->shared) | |
5526 | { | |
5527 | Elf_Internal_Rela outrel; | |
5528 | bfd_byte *loc; | |
5529 | ||
5530 | if (globals->srelgot == NULL) | |
5531 | abort (); | |
5532 | ||
00a97672 | 5533 | outrel.r_addend = 0; |
ba93b8ac DJ |
5534 | outrel.r_offset = (globals->sgot->output_section->vma |
5535 | + globals->sgot->output_offset + off); | |
5536 | outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32); | |
5537 | ||
00a97672 RS |
5538 | if (globals->use_rel) |
5539 | bfd_put_32 (output_bfd, outrel.r_addend, | |
5540 | globals->sgot->contents + off); | |
ba93b8ac DJ |
5541 | |
5542 | loc = globals->srelgot->contents; | |
00a97672 RS |
5543 | loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals); |
5544 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac DJ |
5545 | } |
5546 | else | |
5547 | bfd_put_32 (output_bfd, 1, globals->sgot->contents + off); | |
5548 | ||
5549 | globals->tls_ldm_got.offset |= 1; | |
5550 | } | |
5551 | ||
5552 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
5553 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
5554 | ||
5555 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
5556 | contents, rel->r_offset, value, | |
00a97672 | 5557 | rel->r_addend); |
ba93b8ac DJ |
5558 | } |
5559 | ||
5560 | case R_ARM_TLS_GD32: | |
5561 | case R_ARM_TLS_IE32: | |
5562 | { | |
5563 | bfd_vma off; | |
5564 | int indx; | |
5565 | char tls_type; | |
5566 | ||
5567 | if (globals->sgot == NULL) | |
5568 | abort (); | |
5569 | ||
5570 | indx = 0; | |
5571 | if (h != NULL) | |
5572 | { | |
5573 | bfd_boolean dyn; | |
5574 | dyn = globals->root.dynamic_sections_created; | |
5575 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
5576 | && (!info->shared | |
5577 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
5578 | { | |
5579 | *unresolved_reloc_p = FALSE; | |
5580 | indx = h->dynindx; | |
5581 | } | |
5582 | off = h->got.offset; | |
5583 | tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type; | |
5584 | } | |
5585 | else | |
5586 | { | |
5587 | if (local_got_offsets == NULL) | |
5588 | abort (); | |
5589 | off = local_got_offsets[r_symndx]; | |
5590 | tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx]; | |
5591 | } | |
5592 | ||
5593 | if (tls_type == GOT_UNKNOWN) | |
5594 | abort (); | |
5595 | ||
5596 | if ((off & 1) != 0) | |
5597 | off &= ~1; | |
5598 | else | |
5599 | { | |
5600 | bfd_boolean need_relocs = FALSE; | |
5601 | Elf_Internal_Rela outrel; | |
5602 | bfd_byte *loc = NULL; | |
5603 | int cur_off = off; | |
5604 | ||
5605 | /* The GOT entries have not been initialized yet. Do it | |
5606 | now, and emit any relocations. If both an IE GOT and a | |
5607 | GD GOT are necessary, we emit the GD first. */ | |
5608 | ||
5609 | if ((info->shared || indx != 0) | |
5610 | && (h == NULL | |
5611 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5612 | || h->root.type != bfd_link_hash_undefweak)) | |
5613 | { | |
5614 | need_relocs = TRUE; | |
5615 | if (globals->srelgot == NULL) | |
5616 | abort (); | |
5617 | loc = globals->srelgot->contents; | |
00a97672 | 5618 | loc += globals->srelgot->reloc_count * RELOC_SIZE (globals); |
ba93b8ac DJ |
5619 | } |
5620 | ||
5621 | if (tls_type & GOT_TLS_GD) | |
5622 | { | |
5623 | if (need_relocs) | |
5624 | { | |
00a97672 | 5625 | outrel.r_addend = 0; |
ba93b8ac | 5626 | outrel.r_offset = (globals->sgot->output_section->vma |
00a97672 RS |
5627 | + globals->sgot->output_offset |
5628 | + cur_off); | |
ba93b8ac | 5629 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32); |
ba93b8ac | 5630 | |
00a97672 RS |
5631 | if (globals->use_rel) |
5632 | bfd_put_32 (output_bfd, outrel.r_addend, | |
5633 | globals->sgot->contents + cur_off); | |
5634 | ||
5635 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 5636 | globals->srelgot->reloc_count++; |
00a97672 | 5637 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
5638 | |
5639 | if (indx == 0) | |
5640 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
5641 | globals->sgot->contents + cur_off + 4); | |
5642 | else | |
5643 | { | |
00a97672 | 5644 | outrel.r_addend = 0; |
ba93b8ac DJ |
5645 | outrel.r_info = ELF32_R_INFO (indx, |
5646 | R_ARM_TLS_DTPOFF32); | |
5647 | outrel.r_offset += 4; | |
00a97672 RS |
5648 | |
5649 | if (globals->use_rel) | |
5650 | bfd_put_32 (output_bfd, outrel.r_addend, | |
5651 | globals->sgot->contents + cur_off + 4); | |
5652 | ||
5653 | ||
5654 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 5655 | globals->srelgot->reloc_count++; |
00a97672 | 5656 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
5657 | } |
5658 | } | |
5659 | else | |
5660 | { | |
5661 | /* If we are not emitting relocations for a | |
5662 | general dynamic reference, then we must be in a | |
5663 | static link or an executable link with the | |
5664 | symbol binding locally. Mark it as belonging | |
5665 | to module 1, the executable. */ | |
5666 | bfd_put_32 (output_bfd, 1, | |
5667 | globals->sgot->contents + cur_off); | |
5668 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
5669 | globals->sgot->contents + cur_off + 4); | |
5670 | } | |
5671 | ||
5672 | cur_off += 8; | |
5673 | } | |
5674 | ||
5675 | if (tls_type & GOT_TLS_IE) | |
5676 | { | |
5677 | if (need_relocs) | |
5678 | { | |
00a97672 RS |
5679 | if (indx == 0) |
5680 | outrel.r_addend = value - dtpoff_base (info); | |
5681 | else | |
5682 | outrel.r_addend = 0; | |
ba93b8ac DJ |
5683 | outrel.r_offset = (globals->sgot->output_section->vma |
5684 | + globals->sgot->output_offset | |
5685 | + cur_off); | |
5686 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32); | |
5687 | ||
00a97672 RS |
5688 | if (globals->use_rel) |
5689 | bfd_put_32 (output_bfd, outrel.r_addend, | |
ba93b8ac DJ |
5690 | globals->sgot->contents + cur_off); |
5691 | ||
00a97672 | 5692 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); |
ba93b8ac | 5693 | globals->srelgot->reloc_count++; |
00a97672 | 5694 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
5695 | } |
5696 | else | |
5697 | bfd_put_32 (output_bfd, tpoff (info, value), | |
5698 | globals->sgot->contents + cur_off); | |
5699 | cur_off += 4; | |
5700 | } | |
5701 | ||
5702 | if (h != NULL) | |
5703 | h->got.offset |= 1; | |
5704 | else | |
5705 | local_got_offsets[r_symndx] |= 1; | |
5706 | } | |
5707 | ||
5708 | if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32) | |
5709 | off += 8; | |
5710 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
5711 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
5712 | ||
5713 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
5714 | contents, rel->r_offset, value, | |
00a97672 | 5715 | rel->r_addend); |
ba93b8ac DJ |
5716 | } |
5717 | ||
5718 | case R_ARM_TLS_LE32: | |
5719 | if (info->shared) | |
5720 | { | |
5721 | (*_bfd_error_handler) | |
5722 | (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"), | |
5723 | input_bfd, input_section, | |
5724 | (long) rel->r_offset, howto->name); | |
5725 | return FALSE; | |
5726 | } | |
5727 | else | |
5728 | value = tpoff (info, value); | |
5729 | ||
5730 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
5731 | contents, rel->r_offset, value, |
5732 | rel->r_addend); | |
ba93b8ac | 5733 | |
319850b4 JB |
5734 | case R_ARM_V4BX: |
5735 | if (globals->fix_v4bx) | |
5736 | { | |
5737 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
5738 | ||
5739 | /* Ensure that we have a BX instruction. */ | |
5740 | BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10); | |
5741 | ||
5742 | /* Preserve Rm (lowest four bits) and the condition code | |
5743 | (highest four bits). Other bits encode MOV PC,Rm. */ | |
5744 | insn = (insn & 0xf000000f) | 0x01a0f000; | |
5745 | ||
5746 | bfd_put_32 (input_bfd, insn, hit_data); | |
5747 | } | |
5748 | return bfd_reloc_ok; | |
5749 | ||
b6895b4f PB |
5750 | case R_ARM_MOVW_ABS_NC: |
5751 | case R_ARM_MOVT_ABS: | |
5752 | case R_ARM_MOVW_PREL_NC: | |
5753 | case R_ARM_MOVT_PREL: | |
92f5d02b MS |
5754 | /* Until we properly support segment-base-relative addressing then |
5755 | we assume the segment base to be zero, as for the group relocations. | |
5756 | Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC | |
5757 | and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */ | |
5758 | case R_ARM_MOVW_BREL_NC: | |
5759 | case R_ARM_MOVW_BREL: | |
5760 | case R_ARM_MOVT_BREL: | |
b6895b4f PB |
5761 | { |
5762 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
5763 | ||
5764 | if (globals->use_rel) | |
5765 | { | |
5766 | addend = ((insn >> 4) & 0xf000) | (insn & 0xfff); | |
5767 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
5768 | } | |
92f5d02b | 5769 | |
b6895b4f | 5770 | value += signed_addend; |
b6895b4f PB |
5771 | |
5772 | if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL) | |
5773 | value -= (input_section->output_section->vma | |
5774 | + input_section->output_offset + rel->r_offset); | |
5775 | ||
92f5d02b MS |
5776 | if (r_type == R_ARM_MOVW_BREL && value >= 0x10000) |
5777 | return bfd_reloc_overflow; | |
5778 | ||
5779 | if (sym_flags == STT_ARM_TFUNC) | |
5780 | value |= 1; | |
5781 | ||
5782 | if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL | |
5783 | || r_type == R_ARM_MOVT_BREL) | |
b6895b4f PB |
5784 | value >>= 16; |
5785 | ||
5786 | insn &= 0xfff0f000; | |
5787 | insn |= value & 0xfff; | |
5788 | insn |= (value & 0xf000) << 4; | |
5789 | bfd_put_32 (input_bfd, insn, hit_data); | |
5790 | } | |
5791 | return bfd_reloc_ok; | |
5792 | ||
5793 | case R_ARM_THM_MOVW_ABS_NC: | |
5794 | case R_ARM_THM_MOVT_ABS: | |
5795 | case R_ARM_THM_MOVW_PREL_NC: | |
5796 | case R_ARM_THM_MOVT_PREL: | |
92f5d02b MS |
5797 | /* Until we properly support segment-base-relative addressing then |
5798 | we assume the segment base to be zero, as for the above relocations. | |
5799 | Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as | |
5800 | R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics | |
5801 | as R_ARM_THM_MOVT_ABS. */ | |
5802 | case R_ARM_THM_MOVW_BREL_NC: | |
5803 | case R_ARM_THM_MOVW_BREL: | |
5804 | case R_ARM_THM_MOVT_BREL: | |
b6895b4f PB |
5805 | { |
5806 | bfd_vma insn; | |
5807 | ||
5808 | insn = bfd_get_16 (input_bfd, hit_data) << 16; | |
5809 | insn |= bfd_get_16 (input_bfd, hit_data + 2); | |
5810 | ||
5811 | if (globals->use_rel) | |
5812 | { | |
5813 | addend = ((insn >> 4) & 0xf000) | |
5814 | | ((insn >> 15) & 0x0800) | |
5815 | | ((insn >> 4) & 0x0700) | |
5816 | | (insn & 0x00ff); | |
5817 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
5818 | } | |
92f5d02b | 5819 | |
b6895b4f | 5820 | value += signed_addend; |
b6895b4f PB |
5821 | |
5822 | if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL) | |
5823 | value -= (input_section->output_section->vma | |
5824 | + input_section->output_offset + rel->r_offset); | |
5825 | ||
92f5d02b MS |
5826 | if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000) |
5827 | return bfd_reloc_overflow; | |
5828 | ||
5829 | if (sym_flags == STT_ARM_TFUNC) | |
5830 | value |= 1; | |
5831 | ||
5832 | if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL | |
5833 | || r_type == R_ARM_THM_MOVT_BREL) | |
b6895b4f PB |
5834 | value >>= 16; |
5835 | ||
5836 | insn &= 0xfbf08f00; | |
5837 | insn |= (value & 0xf000) << 4; | |
5838 | insn |= (value & 0x0800) << 15; | |
5839 | insn |= (value & 0x0700) << 4; | |
5840 | insn |= (value & 0x00ff); | |
5841 | ||
5842 | bfd_put_16 (input_bfd, insn >> 16, hit_data); | |
5843 | bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); | |
5844 | } | |
5845 | return bfd_reloc_ok; | |
5846 | ||
4962c51a MS |
5847 | case R_ARM_ALU_PC_G0_NC: |
5848 | case R_ARM_ALU_PC_G1_NC: | |
5849 | case R_ARM_ALU_PC_G0: | |
5850 | case R_ARM_ALU_PC_G1: | |
5851 | case R_ARM_ALU_PC_G2: | |
5852 | case R_ARM_ALU_SB_G0_NC: | |
5853 | case R_ARM_ALU_SB_G1_NC: | |
5854 | case R_ARM_ALU_SB_G0: | |
5855 | case R_ARM_ALU_SB_G1: | |
5856 | case R_ARM_ALU_SB_G2: | |
5857 | { | |
5858 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
5859 | bfd_vma pc = input_section->output_section->vma | |
5860 | + input_section->output_offset + rel->r_offset; | |
5861 | /* sb should be the origin of the *segment* containing the symbol. | |
5862 | It is not clear how to obtain this OS-dependent value, so we | |
5863 | make an arbitrary choice of zero. */ | |
5864 | bfd_vma sb = 0; | |
5865 | bfd_vma residual; | |
5866 | bfd_vma g_n; | |
5867 | bfd_signed_vma signed_value; | |
5868 | int group = 0; | |
5869 | ||
5870 | /* Determine which group of bits to select. */ | |
5871 | switch (r_type) | |
5872 | { | |
5873 | case R_ARM_ALU_PC_G0_NC: | |
5874 | case R_ARM_ALU_PC_G0: | |
5875 | case R_ARM_ALU_SB_G0_NC: | |
5876 | case R_ARM_ALU_SB_G0: | |
5877 | group = 0; | |
5878 | break; | |
5879 | ||
5880 | case R_ARM_ALU_PC_G1_NC: | |
5881 | case R_ARM_ALU_PC_G1: | |
5882 | case R_ARM_ALU_SB_G1_NC: | |
5883 | case R_ARM_ALU_SB_G1: | |
5884 | group = 1; | |
5885 | break; | |
5886 | ||
5887 | case R_ARM_ALU_PC_G2: | |
5888 | case R_ARM_ALU_SB_G2: | |
5889 | group = 2; | |
5890 | break; | |
5891 | ||
5892 | default: | |
5893 | abort(); | |
5894 | } | |
5895 | ||
5896 | /* If REL, extract the addend from the insn. If RELA, it will | |
5897 | have already been fetched for us. */ | |
5898 | if (globals->use_rel) | |
5899 | { | |
5900 | int negative; | |
5901 | bfd_vma constant = insn & 0xff; | |
5902 | bfd_vma rotation = (insn & 0xf00) >> 8; | |
5903 | ||
5904 | if (rotation == 0) | |
5905 | signed_addend = constant; | |
5906 | else | |
5907 | { | |
5908 | /* Compensate for the fact that in the instruction, the | |
5909 | rotation is stored in multiples of 2 bits. */ | |
5910 | rotation *= 2; | |
5911 | ||
5912 | /* Rotate "constant" right by "rotation" bits. */ | |
5913 | signed_addend = (constant >> rotation) | | |
5914 | (constant << (8 * sizeof (bfd_vma) - rotation)); | |
5915 | } | |
5916 | ||
5917 | /* Determine if the instruction is an ADD or a SUB. | |
5918 | (For REL, this determines the sign of the addend.) */ | |
5919 | negative = identify_add_or_sub (insn); | |
5920 | if (negative == 0) | |
5921 | { | |
5922 | (*_bfd_error_handler) | |
5923 | (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"), | |
5924 | input_bfd, input_section, | |
5925 | (long) rel->r_offset, howto->name); | |
5926 | return bfd_reloc_overflow; | |
5927 | } | |
5928 | ||
5929 | signed_addend *= negative; | |
5930 | } | |
5931 | ||
5932 | /* Compute the value (X) to go in the place. */ | |
5933 | if (r_type == R_ARM_ALU_PC_G0_NC | |
5934 | || r_type == R_ARM_ALU_PC_G1_NC | |
5935 | || r_type == R_ARM_ALU_PC_G0 | |
5936 | || r_type == R_ARM_ALU_PC_G1 | |
5937 | || r_type == R_ARM_ALU_PC_G2) | |
5938 | /* PC relative. */ | |
5939 | signed_value = value - pc + signed_addend; | |
5940 | else | |
5941 | /* Section base relative. */ | |
5942 | signed_value = value - sb + signed_addend; | |
5943 | ||
5944 | /* If the target symbol is a Thumb function, then set the | |
5945 | Thumb bit in the address. */ | |
5946 | if (sym_flags == STT_ARM_TFUNC) | |
5947 | signed_value |= 1; | |
5948 | ||
5949 | /* Calculate the value of the relevant G_n, in encoded | |
5950 | constant-with-rotation format. */ | |
5951 | g_n = calculate_group_reloc_mask (abs (signed_value), group, | |
5952 | &residual); | |
5953 | ||
5954 | /* Check for overflow if required. */ | |
5955 | if ((r_type == R_ARM_ALU_PC_G0 | |
5956 | || r_type == R_ARM_ALU_PC_G1 | |
5957 | || r_type == R_ARM_ALU_PC_G2 | |
5958 | || r_type == R_ARM_ALU_SB_G0 | |
5959 | || r_type == R_ARM_ALU_SB_G1 | |
5960 | || r_type == R_ARM_ALU_SB_G2) && residual != 0) | |
5961 | { | |
5962 | (*_bfd_error_handler) | |
5963 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
5964 | input_bfd, input_section, | |
5965 | (long) rel->r_offset, abs (signed_value), howto->name); | |
5966 | return bfd_reloc_overflow; | |
5967 | } | |
5968 | ||
5969 | /* Mask out the value and the ADD/SUB part of the opcode; take care | |
5970 | not to destroy the S bit. */ | |
5971 | insn &= 0xff1ff000; | |
5972 | ||
5973 | /* Set the opcode according to whether the value to go in the | |
5974 | place is negative. */ | |
5975 | if (signed_value < 0) | |
5976 | insn |= 1 << 22; | |
5977 | else | |
5978 | insn |= 1 << 23; | |
5979 | ||
5980 | /* Encode the offset. */ | |
5981 | insn |= g_n; | |
5982 | ||
5983 | bfd_put_32 (input_bfd, insn, hit_data); | |
5984 | } | |
5985 | return bfd_reloc_ok; | |
5986 | ||
5987 | case R_ARM_LDR_PC_G0: | |
5988 | case R_ARM_LDR_PC_G1: | |
5989 | case R_ARM_LDR_PC_G2: | |
5990 | case R_ARM_LDR_SB_G0: | |
5991 | case R_ARM_LDR_SB_G1: | |
5992 | case R_ARM_LDR_SB_G2: | |
5993 | { | |
5994 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
5995 | bfd_vma pc = input_section->output_section->vma | |
5996 | + input_section->output_offset + rel->r_offset; | |
5997 | bfd_vma sb = 0; /* See note above. */ | |
5998 | bfd_vma residual; | |
5999 | bfd_signed_vma signed_value; | |
6000 | int group = 0; | |
6001 | ||
6002 | /* Determine which groups of bits to calculate. */ | |
6003 | switch (r_type) | |
6004 | { | |
6005 | case R_ARM_LDR_PC_G0: | |
6006 | case R_ARM_LDR_SB_G0: | |
6007 | group = 0; | |
6008 | break; | |
6009 | ||
6010 | case R_ARM_LDR_PC_G1: | |
6011 | case R_ARM_LDR_SB_G1: | |
6012 | group = 1; | |
6013 | break; | |
6014 | ||
6015 | case R_ARM_LDR_PC_G2: | |
6016 | case R_ARM_LDR_SB_G2: | |
6017 | group = 2; | |
6018 | break; | |
6019 | ||
6020 | default: | |
6021 | abort(); | |
6022 | } | |
6023 | ||
6024 | /* If REL, extract the addend from the insn. If RELA, it will | |
6025 | have already been fetched for us. */ | |
6026 | if (globals->use_rel) | |
6027 | { | |
6028 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
6029 | signed_addend = negative * (insn & 0xfff); | |
6030 | } | |
6031 | ||
6032 | /* Compute the value (X) to go in the place. */ | |
6033 | if (r_type == R_ARM_LDR_PC_G0 | |
6034 | || r_type == R_ARM_LDR_PC_G1 | |
6035 | || r_type == R_ARM_LDR_PC_G2) | |
6036 | /* PC relative. */ | |
6037 | signed_value = value - pc + signed_addend; | |
6038 | else | |
6039 | /* Section base relative. */ | |
6040 | signed_value = value - sb + signed_addend; | |
6041 | ||
6042 | /* Calculate the value of the relevant G_{n-1} to obtain | |
6043 | the residual at that stage. */ | |
6044 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
6045 | ||
6046 | /* Check for overflow. */ | |
6047 | if (residual >= 0x1000) | |
6048 | { | |
6049 | (*_bfd_error_handler) | |
6050 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
6051 | input_bfd, input_section, | |
6052 | (long) rel->r_offset, abs (signed_value), howto->name); | |
6053 | return bfd_reloc_overflow; | |
6054 | } | |
6055 | ||
6056 | /* Mask out the value and U bit. */ | |
6057 | insn &= 0xff7ff000; | |
6058 | ||
6059 | /* Set the U bit if the value to go in the place is non-negative. */ | |
6060 | if (signed_value >= 0) | |
6061 | insn |= 1 << 23; | |
6062 | ||
6063 | /* Encode the offset. */ | |
6064 | insn |= residual; | |
6065 | ||
6066 | bfd_put_32 (input_bfd, insn, hit_data); | |
6067 | } | |
6068 | return bfd_reloc_ok; | |
6069 | ||
6070 | case R_ARM_LDRS_PC_G0: | |
6071 | case R_ARM_LDRS_PC_G1: | |
6072 | case R_ARM_LDRS_PC_G2: | |
6073 | case R_ARM_LDRS_SB_G0: | |
6074 | case R_ARM_LDRS_SB_G1: | |
6075 | case R_ARM_LDRS_SB_G2: | |
6076 | { | |
6077 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
6078 | bfd_vma pc = input_section->output_section->vma | |
6079 | + input_section->output_offset + rel->r_offset; | |
6080 | bfd_vma sb = 0; /* See note above. */ | |
6081 | bfd_vma residual; | |
6082 | bfd_signed_vma signed_value; | |
6083 | int group = 0; | |
6084 | ||
6085 | /* Determine which groups of bits to calculate. */ | |
6086 | switch (r_type) | |
6087 | { | |
6088 | case R_ARM_LDRS_PC_G0: | |
6089 | case R_ARM_LDRS_SB_G0: | |
6090 | group = 0; | |
6091 | break; | |
6092 | ||
6093 | case R_ARM_LDRS_PC_G1: | |
6094 | case R_ARM_LDRS_SB_G1: | |
6095 | group = 1; | |
6096 | break; | |
6097 | ||
6098 | case R_ARM_LDRS_PC_G2: | |
6099 | case R_ARM_LDRS_SB_G2: | |
6100 | group = 2; | |
6101 | break; | |
6102 | ||
6103 | default: | |
6104 | abort(); | |
6105 | } | |
6106 | ||
6107 | /* If REL, extract the addend from the insn. If RELA, it will | |
6108 | have already been fetched for us. */ | |
6109 | if (globals->use_rel) | |
6110 | { | |
6111 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
6112 | signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf)); | |
6113 | } | |
6114 | ||
6115 | /* Compute the value (X) to go in the place. */ | |
6116 | if (r_type == R_ARM_LDRS_PC_G0 | |
6117 | || r_type == R_ARM_LDRS_PC_G1 | |
6118 | || r_type == R_ARM_LDRS_PC_G2) | |
6119 | /* PC relative. */ | |
6120 | signed_value = value - pc + signed_addend; | |
6121 | else | |
6122 | /* Section base relative. */ | |
6123 | signed_value = value - sb + signed_addend; | |
6124 | ||
6125 | /* Calculate the value of the relevant G_{n-1} to obtain | |
6126 | the residual at that stage. */ | |
6127 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
6128 | ||
6129 | /* Check for overflow. */ | |
6130 | if (residual >= 0x100) | |
6131 | { | |
6132 | (*_bfd_error_handler) | |
6133 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
6134 | input_bfd, input_section, | |
6135 | (long) rel->r_offset, abs (signed_value), howto->name); | |
6136 | return bfd_reloc_overflow; | |
6137 | } | |
6138 | ||
6139 | /* Mask out the value and U bit. */ | |
6140 | insn &= 0xff7ff0f0; | |
6141 | ||
6142 | /* Set the U bit if the value to go in the place is non-negative. */ | |
6143 | if (signed_value >= 0) | |
6144 | insn |= 1 << 23; | |
6145 | ||
6146 | /* Encode the offset. */ | |
6147 | insn |= ((residual & 0xf0) << 4) | (residual & 0xf); | |
6148 | ||
6149 | bfd_put_32 (input_bfd, insn, hit_data); | |
6150 | } | |
6151 | return bfd_reloc_ok; | |
6152 | ||
6153 | case R_ARM_LDC_PC_G0: | |
6154 | case R_ARM_LDC_PC_G1: | |
6155 | case R_ARM_LDC_PC_G2: | |
6156 | case R_ARM_LDC_SB_G0: | |
6157 | case R_ARM_LDC_SB_G1: | |
6158 | case R_ARM_LDC_SB_G2: | |
6159 | { | |
6160 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
6161 | bfd_vma pc = input_section->output_section->vma | |
6162 | + input_section->output_offset + rel->r_offset; | |
6163 | bfd_vma sb = 0; /* See note above. */ | |
6164 | bfd_vma residual; | |
6165 | bfd_signed_vma signed_value; | |
6166 | int group = 0; | |
6167 | ||
6168 | /* Determine which groups of bits to calculate. */ | |
6169 | switch (r_type) | |
6170 | { | |
6171 | case R_ARM_LDC_PC_G0: | |
6172 | case R_ARM_LDC_SB_G0: | |
6173 | group = 0; | |
6174 | break; | |
6175 | ||
6176 | case R_ARM_LDC_PC_G1: | |
6177 | case R_ARM_LDC_SB_G1: | |
6178 | group = 1; | |
6179 | break; | |
6180 | ||
6181 | case R_ARM_LDC_PC_G2: | |
6182 | case R_ARM_LDC_SB_G2: | |
6183 | group = 2; | |
6184 | break; | |
6185 | ||
6186 | default: | |
6187 | abort(); | |
6188 | } | |
6189 | ||
6190 | /* If REL, extract the addend from the insn. If RELA, it will | |
6191 | have already been fetched for us. */ | |
6192 | if (globals->use_rel) | |
6193 | { | |
6194 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
6195 | signed_addend = negative * ((insn & 0xff) << 2); | |
6196 | } | |
6197 | ||
6198 | /* Compute the value (X) to go in the place. */ | |
6199 | if (r_type == R_ARM_LDC_PC_G0 | |
6200 | || r_type == R_ARM_LDC_PC_G1 | |
6201 | || r_type == R_ARM_LDC_PC_G2) | |
6202 | /* PC relative. */ | |
6203 | signed_value = value - pc + signed_addend; | |
6204 | else | |
6205 | /* Section base relative. */ | |
6206 | signed_value = value - sb + signed_addend; | |
6207 | ||
6208 | /* Calculate the value of the relevant G_{n-1} to obtain | |
6209 | the residual at that stage. */ | |
6210 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
6211 | ||
6212 | /* Check for overflow. (The absolute value to go in the place must be | |
6213 | divisible by four and, after having been divided by four, must | |
6214 | fit in eight bits.) */ | |
6215 | if ((residual & 0x3) != 0 || residual >= 0x400) | |
6216 | { | |
6217 | (*_bfd_error_handler) | |
6218 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
6219 | input_bfd, input_section, | |
6220 | (long) rel->r_offset, abs (signed_value), howto->name); | |
6221 | return bfd_reloc_overflow; | |
6222 | } | |
6223 | ||
6224 | /* Mask out the value and U bit. */ | |
6225 | insn &= 0xff7fff00; | |
6226 | ||
6227 | /* Set the U bit if the value to go in the place is non-negative. */ | |
6228 | if (signed_value >= 0) | |
6229 | insn |= 1 << 23; | |
6230 | ||
6231 | /* Encode the offset. */ | |
6232 | insn |= residual >> 2; | |
6233 | ||
6234 | bfd_put_32 (input_bfd, insn, hit_data); | |
6235 | } | |
6236 | return bfd_reloc_ok; | |
6237 | ||
252b5132 RH |
6238 | default: |
6239 | return bfd_reloc_notsupported; | |
6240 | } | |
6241 | } | |
6242 | ||
ee065d83 PB |
6243 | |
6244 | static int | |
6245 | uleb128_size (unsigned int i) | |
6246 | { | |
6247 | int size; | |
6248 | size = 1; | |
6249 | while (i >= 0x80) | |
6250 | { | |
6251 | i >>= 7; | |
6252 | size++; | |
6253 | } | |
6254 | return size; | |
6255 | } | |
6256 | ||
6257 | /* Return TRUE if the attribute has the default value (0/""). */ | |
6258 | static bfd_boolean | |
6259 | is_default_attr (aeabi_attribute *attr) | |
6260 | { | |
6261 | if ((attr->type & 1) && attr->i != 0) | |
6262 | return FALSE; | |
6263 | if ((attr->type & 2) && attr->s && *attr->s) | |
6264 | return FALSE; | |
6265 | ||
6266 | return TRUE; | |
6267 | } | |
6268 | ||
6269 | /* Return the size of a single attribute. */ | |
6270 | static bfd_vma | |
6271 | eabi_attr_size(int tag, aeabi_attribute *attr) | |
6272 | { | |
6273 | bfd_vma size; | |
6274 | ||
6275 | if (is_default_attr (attr)) | |
6276 | return 0; | |
6277 | ||
6278 | size = uleb128_size (tag); | |
6279 | if (attr->type & 1) | |
6280 | size += uleb128_size (attr->i); | |
6281 | if (attr->type & 2) | |
6282 | size += strlen ((char *)attr->s) + 1; | |
6283 | return size; | |
6284 | } | |
6285 | ||
6286 | /* Returns the size of the eabi object attributess section. */ | |
6287 | bfd_vma | |
6288 | elf32_arm_eabi_attr_size (bfd *abfd) | |
6289 | { | |
6290 | bfd_vma size; | |
6291 | aeabi_attribute *attr; | |
6292 | aeabi_attribute_list *list; | |
6293 | int i; | |
6294 | ||
6295 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
6296 | size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */ | |
6297 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
6298 | size += eabi_attr_size (i, &attr[i]); | |
6299 | ||
6300 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
6301 | list; | |
6302 | list = list->next) | |
6303 | size += eabi_attr_size (list->tag, &list->attr); | |
6304 | ||
6305 | return size; | |
6306 | } | |
6307 | ||
6308 | static bfd_byte * | |
6309 | write_uleb128 (bfd_byte *p, unsigned int val) | |
6310 | { | |
6311 | bfd_byte c; | |
6312 | do | |
6313 | { | |
6314 | c = val & 0x7f; | |
6315 | val >>= 7; | |
6316 | if (val) | |
6317 | c |= 0x80; | |
6318 | *(p++) = c; | |
6319 | } | |
6320 | while (val); | |
6321 | return p; | |
6322 | } | |
6323 | ||
6324 | /* Write attribute ATTR to butter P, and return a pointer to the following | |
6325 | byte. */ | |
6326 | static bfd_byte * | |
6327 | write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr) | |
6328 | { | |
6329 | /* Suppress default entries. */ | |
6330 | if (is_default_attr(attr)) | |
6331 | return p; | |
6332 | ||
6333 | p = write_uleb128 (p, tag); | |
6334 | if (attr->type & 1) | |
6335 | p = write_uleb128 (p, attr->i); | |
6336 | if (attr->type & 2) | |
6337 | { | |
6338 | int len; | |
6339 | ||
6340 | len = strlen (attr->s) + 1; | |
6341 | memcpy (p, attr->s, len); | |
6342 | p += len; | |
6343 | } | |
6344 | ||
6345 | return p; | |
6346 | } | |
6347 | ||
6348 | /* Write the contents of the eabi attributes section to p. */ | |
6349 | void | |
6350 | elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size) | |
6351 | { | |
6352 | bfd_byte *p; | |
6353 | aeabi_attribute *attr; | |
6354 | aeabi_attribute_list *list; | |
6355 | int i; | |
6356 | ||
6357 | p = contents; | |
6358 | *(p++) = 'A'; | |
6359 | bfd_put_32 (abfd, size - 1, p); | |
6360 | p += 4; | |
6361 | memcpy (p, "aeabi", 6); | |
6362 | p += 6; | |
6363 | *(p++) = Tag_File; | |
6364 | bfd_put_32 (abfd, size - 11, p); | |
6365 | p += 4; | |
6366 | ||
6367 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
6368 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
6369 | p = write_eabi_attribute (p, i, &attr[i]); | |
6370 | ||
6371 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
6372 | list; | |
6373 | list = list->next) | |
6374 | p = write_eabi_attribute (p, list->tag, &list->attr); | |
6375 | } | |
6376 | ||
6377 | /* Override final_link to handle EABI object attribute sections. */ | |
6378 | ||
6379 | static bfd_boolean | |
6380 | elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info) | |
6381 | { | |
6382 | asection *o; | |
6383 | struct bfd_link_order *p; | |
6384 | asection *attr_section = NULL; | |
6385 | bfd_byte *contents; | |
6386 | bfd_vma size = 0; | |
6387 | ||
6388 | /* elf32_arm_merge_private_bfd_data will already have merged the | |
6389 | object attributes. Remove the input sections from the link, and set | |
6390 | the contents of the output secton. */ | |
6391 | for (o = abfd->sections; o != NULL; o = o->next) | |
6392 | { | |
6393 | if (strcmp (o->name, ".ARM.attributes") == 0) | |
6394 | { | |
6395 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
6396 | { | |
6397 | asection *input_section; | |
6398 | ||
6399 | if (p->type != bfd_indirect_link_order) | |
6400 | continue; | |
6401 | input_section = p->u.indirect.section; | |
6402 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
6403 | elf_link_input_bfd ignores this section. */ | |
6404 | input_section->flags &= ~SEC_HAS_CONTENTS; | |
6405 | } | |
6406 | ||
6407 | size = elf32_arm_eabi_attr_size (abfd); | |
6408 | bfd_set_section_size (abfd, o, size); | |
6409 | attr_section = o; | |
6410 | /* Skip this section later on. */ | |
6411 | o->map_head.link_order = NULL; | |
6412 | } | |
6413 | } | |
6414 | /* Invoke the ELF linker to do all the work. */ | |
6415 | if (!bfd_elf_final_link (abfd, info)) | |
6416 | return FALSE; | |
6417 | ||
6418 | if (attr_section) | |
6419 | { | |
6420 | contents = bfd_malloc(size); | |
6421 | if (contents == NULL) | |
6422 | return FALSE; | |
6423 | elf32_arm_set_eabi_attr_contents (abfd, contents, size); | |
6424 | bfd_set_section_contents (abfd, attr_section, contents, 0, size); | |
6425 | free (contents); | |
6426 | } | |
6427 | return TRUE; | |
6428 | } | |
6429 | ||
6430 | ||
98c1d4aa NC |
6431 | /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ |
6432 | static void | |
57e8b36a NC |
6433 | arm_add_to_rel (bfd * abfd, |
6434 | bfd_byte * address, | |
6435 | reloc_howto_type * howto, | |
6436 | bfd_signed_vma increment) | |
98c1d4aa | 6437 | { |
98c1d4aa NC |
6438 | bfd_signed_vma addend; |
6439 | ||
c19d1205 | 6440 | if (howto->type == R_ARM_THM_CALL) |
98c1d4aa | 6441 | { |
9a5aca8c AM |
6442 | int upper_insn, lower_insn; |
6443 | int upper, lower; | |
98c1d4aa | 6444 | |
9a5aca8c AM |
6445 | upper_insn = bfd_get_16 (abfd, address); |
6446 | lower_insn = bfd_get_16 (abfd, address + 2); | |
6447 | upper = upper_insn & 0x7ff; | |
6448 | lower = lower_insn & 0x7ff; | |
6449 | ||
6450 | addend = (upper << 12) | (lower << 1); | |
ddda4409 | 6451 | addend += increment; |
9a5aca8c | 6452 | addend >>= 1; |
98c1d4aa | 6453 | |
9a5aca8c AM |
6454 | upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); |
6455 | lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); | |
6456 | ||
dc810e39 AM |
6457 | bfd_put_16 (abfd, (bfd_vma) upper_insn, address); |
6458 | bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); | |
9a5aca8c AM |
6459 | } |
6460 | else | |
6461 | { | |
6462 | bfd_vma contents; | |
6463 | ||
6464 | contents = bfd_get_32 (abfd, address); | |
6465 | ||
6466 | /* Get the (signed) value from the instruction. */ | |
6467 | addend = contents & howto->src_mask; | |
6468 | if (addend & ((howto->src_mask + 1) >> 1)) | |
6469 | { | |
6470 | bfd_signed_vma mask; | |
6471 | ||
6472 | mask = -1; | |
6473 | mask &= ~ howto->src_mask; | |
6474 | addend |= mask; | |
6475 | } | |
6476 | ||
6477 | /* Add in the increment, (which is a byte value). */ | |
6478 | switch (howto->type) | |
6479 | { | |
6480 | default: | |
6481 | addend += increment; | |
6482 | break; | |
6483 | ||
6484 | case R_ARM_PC24: | |
c6596c5e | 6485 | case R_ARM_PLT32: |
5b5bb741 PB |
6486 | case R_ARM_CALL: |
6487 | case R_ARM_JUMP24: | |
9a5aca8c | 6488 | addend <<= howto->size; |
dc810e39 | 6489 | addend += increment; |
9a5aca8c AM |
6490 | |
6491 | /* Should we check for overflow here ? */ | |
6492 | ||
6493 | /* Drop any undesired bits. */ | |
6494 | addend >>= howto->rightshift; | |
6495 | break; | |
6496 | } | |
6497 | ||
6498 | contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
6499 | ||
6500 | bfd_put_32 (abfd, contents, address); | |
ddda4409 | 6501 | } |
98c1d4aa | 6502 | } |
252b5132 | 6503 | |
ba93b8ac DJ |
6504 | #define IS_ARM_TLS_RELOC(R_TYPE) \ |
6505 | ((R_TYPE) == R_ARM_TLS_GD32 \ | |
6506 | || (R_TYPE) == R_ARM_TLS_LDO32 \ | |
6507 | || (R_TYPE) == R_ARM_TLS_LDM32 \ | |
6508 | || (R_TYPE) == R_ARM_TLS_DTPOFF32 \ | |
6509 | || (R_TYPE) == R_ARM_TLS_DTPMOD32 \ | |
6510 | || (R_TYPE) == R_ARM_TLS_TPOFF32 \ | |
6511 | || (R_TYPE) == R_ARM_TLS_LE32 \ | |
6512 | || (R_TYPE) == R_ARM_TLS_IE32) | |
6513 | ||
252b5132 | 6514 | /* Relocate an ARM ELF section. */ |
b34976b6 | 6515 | static bfd_boolean |
57e8b36a NC |
6516 | elf32_arm_relocate_section (bfd * output_bfd, |
6517 | struct bfd_link_info * info, | |
6518 | bfd * input_bfd, | |
6519 | asection * input_section, | |
6520 | bfd_byte * contents, | |
6521 | Elf_Internal_Rela * relocs, | |
6522 | Elf_Internal_Sym * local_syms, | |
6523 | asection ** local_sections) | |
252b5132 | 6524 | { |
b34976b6 AM |
6525 | Elf_Internal_Shdr *symtab_hdr; |
6526 | struct elf_link_hash_entry **sym_hashes; | |
6527 | Elf_Internal_Rela *rel; | |
6528 | Elf_Internal_Rela *relend; | |
6529 | const char *name; | |
b32d3aa2 | 6530 | struct elf32_arm_link_hash_table * globals; |
252b5132 | 6531 | |
4e7fd91e | 6532 | globals = elf32_arm_hash_table (info); |
b491616a | 6533 | |
252b5132 RH |
6534 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
6535 | sym_hashes = elf_sym_hashes (input_bfd); | |
6536 | ||
6537 | rel = relocs; | |
6538 | relend = relocs + input_section->reloc_count; | |
6539 | for (; rel < relend; rel++) | |
6540 | { | |
ba96a88f NC |
6541 | int r_type; |
6542 | reloc_howto_type * howto; | |
6543 | unsigned long r_symndx; | |
6544 | Elf_Internal_Sym * sym; | |
6545 | asection * sec; | |
252b5132 | 6546 | struct elf_link_hash_entry * h; |
ba96a88f NC |
6547 | bfd_vma relocation; |
6548 | bfd_reloc_status_type r; | |
6549 | arelent bfd_reloc; | |
ba93b8ac | 6550 | char sym_type; |
0945cdfd | 6551 | bfd_boolean unresolved_reloc = FALSE; |
f2a9dd69 | 6552 | char *error_message = NULL; |
f21f3fe0 | 6553 | |
252b5132 | 6554 | r_symndx = ELF32_R_SYM (rel->r_info); |
ba96a88f | 6555 | r_type = ELF32_R_TYPE (rel->r_info); |
b32d3aa2 | 6556 | r_type = arm_real_reloc_type (globals, r_type); |
252b5132 | 6557 | |
ba96a88f NC |
6558 | if ( r_type == R_ARM_GNU_VTENTRY |
6559 | || r_type == R_ARM_GNU_VTINHERIT) | |
252b5132 RH |
6560 | continue; |
6561 | ||
b32d3aa2 | 6562 | bfd_reloc.howto = elf32_arm_howto_from_type (r_type); |
ba96a88f | 6563 | howto = bfd_reloc.howto; |
252b5132 | 6564 | |
252b5132 RH |
6565 | h = NULL; |
6566 | sym = NULL; | |
6567 | sec = NULL; | |
9b485d32 | 6568 | |
252b5132 RH |
6569 | if (r_symndx < symtab_hdr->sh_info) |
6570 | { | |
6571 | sym = local_syms + r_symndx; | |
ba93b8ac | 6572 | sym_type = ELF32_ST_TYPE (sym->st_info); |
252b5132 | 6573 | sec = local_sections[r_symndx]; |
4e7fd91e | 6574 | if (globals->use_rel) |
f8df10f4 | 6575 | { |
4e7fd91e PB |
6576 | relocation = (sec->output_section->vma |
6577 | + sec->output_offset | |
6578 | + sym->st_value); | |
ab96bf03 AM |
6579 | if (!info->relocatable |
6580 | && (sec->flags & SEC_MERGE) | |
6581 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
f8df10f4 | 6582 | { |
4e7fd91e PB |
6583 | asection *msec; |
6584 | bfd_vma addend, value; | |
6585 | ||
6586 | if (howto->rightshift) | |
6587 | { | |
6588 | (*_bfd_error_handler) | |
6589 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), | |
6590 | input_bfd, input_section, | |
6591 | (long) rel->r_offset, howto->name); | |
6592 | return FALSE; | |
6593 | } | |
f8df10f4 | 6594 | |
4e7fd91e | 6595 | value = bfd_get_32 (input_bfd, contents + rel->r_offset); |
f8df10f4 | 6596 | |
4e7fd91e PB |
6597 | /* Get the (signed) value from the instruction. */ |
6598 | addend = value & howto->src_mask; | |
6599 | if (addend & ((howto->src_mask + 1) >> 1)) | |
6600 | { | |
6601 | bfd_signed_vma mask; | |
f8df10f4 | 6602 | |
4e7fd91e PB |
6603 | mask = -1; |
6604 | mask &= ~ howto->src_mask; | |
6605 | addend |= mask; | |
6606 | } | |
6607 | msec = sec; | |
6608 | addend = | |
6609 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) | |
6610 | - relocation; | |
6611 | addend += msec->output_section->vma + msec->output_offset; | |
6612 | value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
6613 | bfd_put_32 (input_bfd, value, contents + rel->r_offset); | |
f8df10f4 | 6614 | } |
f8df10f4 | 6615 | } |
4e7fd91e PB |
6616 | else |
6617 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
252b5132 RH |
6618 | } |
6619 | else | |
6620 | { | |
560e09e9 | 6621 | bfd_boolean warned; |
560e09e9 | 6622 | |
b2a8e766 AM |
6623 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
6624 | r_symndx, symtab_hdr, sym_hashes, | |
6625 | h, sec, relocation, | |
6626 | unresolved_reloc, warned); | |
ba93b8ac DJ |
6627 | |
6628 | sym_type = h->type; | |
252b5132 RH |
6629 | } |
6630 | ||
ab96bf03 AM |
6631 | if (sec != NULL && elf_discarded_section (sec)) |
6632 | { | |
6633 | /* For relocs against symbols from removed linkonce sections, | |
6634 | or sections discarded by a linker script, we just want the | |
6635 | section contents zeroed. Avoid any special processing. */ | |
6636 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); | |
6637 | rel->r_info = 0; | |
6638 | rel->r_addend = 0; | |
6639 | continue; | |
6640 | } | |
6641 | ||
6642 | if (info->relocatable) | |
6643 | { | |
6644 | /* This is a relocatable link. We don't have to change | |
6645 | anything, unless the reloc is against a section symbol, | |
6646 | in which case we have to adjust according to where the | |
6647 | section symbol winds up in the output section. */ | |
6648 | if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
6649 | { | |
6650 | if (globals->use_rel) | |
6651 | arm_add_to_rel (input_bfd, contents + rel->r_offset, | |
6652 | howto, (bfd_signed_vma) sec->output_offset); | |
6653 | else | |
6654 | rel->r_addend += sec->output_offset; | |
6655 | } | |
6656 | continue; | |
6657 | } | |
6658 | ||
252b5132 RH |
6659 | if (h != NULL) |
6660 | name = h->root.root.string; | |
6661 | else | |
6662 | { | |
6663 | name = (bfd_elf_string_from_elf_section | |
6664 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
6665 | if (name == NULL || *name == '\0') | |
6666 | name = bfd_section_name (input_bfd, sec); | |
6667 | } | |
f21f3fe0 | 6668 | |
ba93b8ac DJ |
6669 | if (r_symndx != 0 |
6670 | && r_type != R_ARM_NONE | |
6671 | && (h == NULL | |
6672 | || h->root.type == bfd_link_hash_defined | |
6673 | || h->root.type == bfd_link_hash_defweak) | |
6674 | && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
6675 | { | |
6676 | (*_bfd_error_handler) | |
6677 | ((sym_type == STT_TLS | |
6678 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") | |
6679 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), | |
6680 | input_bfd, | |
6681 | input_section, | |
6682 | (long) rel->r_offset, | |
6683 | howto->name, | |
6684 | name); | |
6685 | } | |
6686 | ||
252b5132 RH |
6687 | r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, |
6688 | input_section, contents, rel, | |
6689 | relocation, info, sec, name, | |
6690 | (h ? ELF_ST_TYPE (h->type) : | |
0945cdfd | 6691 | ELF_ST_TYPE (sym->st_info)), h, |
f2a9dd69 | 6692 | &unresolved_reloc, &error_message); |
0945cdfd DJ |
6693 | |
6694 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections | |
6695 | because such sections are not SEC_ALLOC and thus ld.so will | |
6696 | not process them. */ | |
6697 | if (unresolved_reloc | |
6698 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
6699 | && h->def_dynamic)) | |
6700 | { | |
6701 | (*_bfd_error_handler) | |
843fe662 L |
6702 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
6703 | input_bfd, | |
6704 | input_section, | |
6705 | (long) rel->r_offset, | |
6706 | howto->name, | |
6707 | h->root.root.string); | |
0945cdfd DJ |
6708 | return FALSE; |
6709 | } | |
252b5132 RH |
6710 | |
6711 | if (r != bfd_reloc_ok) | |
6712 | { | |
252b5132 RH |
6713 | switch (r) |
6714 | { | |
6715 | case bfd_reloc_overflow: | |
cf919dfd PB |
6716 | /* If the overflowing reloc was to an undefined symbol, |
6717 | we have already printed one error message and there | |
6718 | is no point complaining again. */ | |
6719 | if ((! h || | |
6720 | h->root.type != bfd_link_hash_undefined) | |
6721 | && (!((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
6722 | (info, (h ? &h->root : NULL), name, howto->name, |
6723 | (bfd_vma) 0, input_bfd, input_section, | |
6724 | rel->r_offset)))) | |
b34976b6 | 6725 | return FALSE; |
252b5132 RH |
6726 | break; |
6727 | ||
6728 | case bfd_reloc_undefined: | |
6729 | if (!((*info->callbacks->undefined_symbol) | |
6730 | (info, name, input_bfd, input_section, | |
b34976b6 AM |
6731 | rel->r_offset, TRUE))) |
6732 | return FALSE; | |
252b5132 RH |
6733 | break; |
6734 | ||
6735 | case bfd_reloc_outofrange: | |
f2a9dd69 | 6736 | error_message = _("out of range"); |
252b5132 RH |
6737 | goto common_error; |
6738 | ||
6739 | case bfd_reloc_notsupported: | |
f2a9dd69 | 6740 | error_message = _("unsupported relocation"); |
252b5132 RH |
6741 | goto common_error; |
6742 | ||
6743 | case bfd_reloc_dangerous: | |
f2a9dd69 | 6744 | /* error_message should already be set. */ |
252b5132 RH |
6745 | goto common_error; |
6746 | ||
6747 | default: | |
f2a9dd69 | 6748 | error_message = _("unknown error"); |
252b5132 RH |
6749 | /* fall through */ |
6750 | ||
6751 | common_error: | |
f2a9dd69 DJ |
6752 | BFD_ASSERT (error_message != NULL); |
6753 | if (!((*info->callbacks->reloc_dangerous) | |
6754 | (info, error_message, input_bfd, input_section, | |
252b5132 | 6755 | rel->r_offset))) |
b34976b6 | 6756 | return FALSE; |
252b5132 RH |
6757 | break; |
6758 | } | |
6759 | } | |
6760 | } | |
6761 | ||
b34976b6 | 6762 | return TRUE; |
252b5132 RH |
6763 | } |
6764 | ||
ee065d83 PB |
6765 | /* Allocate/find an object attribute. */ |
6766 | static aeabi_attribute * | |
6767 | elf32_arm_new_eabi_attr (bfd *abfd, int tag) | |
6768 | { | |
6769 | aeabi_attribute *attr; | |
6770 | aeabi_attribute_list *list; | |
6771 | aeabi_attribute_list *p; | |
6772 | aeabi_attribute_list **lastp; | |
6773 | ||
6774 | ||
6775 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
6776 | { | |
6777 | /* Knwon tags are preallocated. */ | |
6778 | attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag]; | |
6779 | } | |
6780 | else | |
6781 | { | |
6782 | /* Create a new tag. */ | |
6783 | list = (aeabi_attribute_list *) | |
6784 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
6785 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
6786 | list->tag = tag; | |
6787 | /* Keep the tag list in order. */ | |
6788 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
6789 | for (p = *lastp; p; p = p->next) | |
6790 | { | |
6791 | if (tag < p->tag) | |
6792 | break; | |
6793 | lastp = &p->next; | |
6794 | } | |
6795 | list->next = *lastp; | |
6796 | *lastp = list; | |
6797 | attr = &list->attr; | |
6798 | } | |
6799 | ||
6800 | return attr; | |
6801 | } | |
6802 | ||
39b41c9c PB |
6803 | int |
6804 | elf32_arm_get_eabi_attr_int (bfd *abfd, int tag) | |
6805 | { | |
6806 | aeabi_attribute_list *p; | |
6807 | ||
6808 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
6809 | { | |
6810 | /* Knwon tags are preallocated. */ | |
6811 | return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i; | |
6812 | } | |
6813 | else | |
6814 | { | |
6815 | for (p = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
6816 | p; | |
6817 | p = p->next) | |
6818 | { | |
6819 | if (tag == p->tag) | |
6820 | return p->attr.i; | |
6821 | if (tag < p->tag) | |
6822 | break; | |
6823 | } | |
6824 | return 0; | |
6825 | } | |
6826 | } | |
6827 | ||
ee065d83 PB |
6828 | void |
6829 | elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i) | |
6830 | { | |
6831 | aeabi_attribute *attr; | |
6832 | ||
6833 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
6834 | attr->type = 1; | |
6835 | attr->i = i; | |
6836 | } | |
6837 | ||
6838 | static char * | |
6839 | attr_strdup (bfd *abfd, const char * s) | |
6840 | { | |
6841 | char * p; | |
6842 | int len; | |
6843 | ||
6844 | len = strlen (s) + 1; | |
6845 | p = (char *)bfd_alloc(abfd, len); | |
6846 | return memcpy (p, s, len); | |
6847 | } | |
6848 | ||
6849 | void | |
6850 | elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s) | |
6851 | { | |
6852 | aeabi_attribute *attr; | |
6853 | ||
6854 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
6855 | attr->type = 2; | |
6856 | attr->s = attr_strdup (abfd, s); | |
6857 | } | |
6858 | ||
6859 | void | |
6860 | elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s) | |
6861 | { | |
6862 | aeabi_attribute_list *list; | |
6863 | aeabi_attribute_list *p; | |
6864 | aeabi_attribute_list **lastp; | |
6865 | ||
6866 | list = (aeabi_attribute_list *) | |
6867 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
6868 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
6869 | list->tag = Tag_compatibility; | |
6870 | list->attr.type = 3; | |
6871 | list->attr.i = i; | |
6872 | list->attr.s = attr_strdup (abfd, s); | |
6873 | ||
6874 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
6875 | for (p = *lastp; p; p = p->next) | |
6876 | { | |
6877 | int cmp; | |
6878 | if (p->tag != Tag_compatibility) | |
6879 | break; | |
6880 | cmp = strcmp(s, p->attr.s); | |
6881 | if (cmp < 0 || (cmp == 0 && i < p->attr.i)) | |
6882 | break; | |
6883 | lastp = &p->next; | |
6884 | } | |
6885 | list->next = *lastp; | |
6886 | *lastp = list; | |
6887 | } | |
6888 | ||
c178919b NC |
6889 | /* Set the right machine number. */ |
6890 | ||
6891 | static bfd_boolean | |
57e8b36a | 6892 | elf32_arm_object_p (bfd *abfd) |
c178919b | 6893 | { |
5a6c6817 | 6894 | unsigned int mach; |
57e8b36a | 6895 | |
5a6c6817 | 6896 | mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); |
c178919b | 6897 | |
5a6c6817 NC |
6898 | if (mach != bfd_mach_arm_unknown) |
6899 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); | |
6900 | ||
6901 | else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) | |
6902 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); | |
e16bb312 | 6903 | |
e16bb312 | 6904 | else |
5a6c6817 | 6905 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
c178919b NC |
6906 | |
6907 | return TRUE; | |
6908 | } | |
6909 | ||
fc830a83 | 6910 | /* Function to keep ARM specific flags in the ELF header. */ |
3c9458e9 | 6911 | |
b34976b6 | 6912 | static bfd_boolean |
57e8b36a | 6913 | elf32_arm_set_private_flags (bfd *abfd, flagword flags) |
252b5132 RH |
6914 | { |
6915 | if (elf_flags_init (abfd) | |
6916 | && elf_elfheader (abfd)->e_flags != flags) | |
6917 | { | |
fc830a83 NC |
6918 | if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) |
6919 | { | |
fd2ec330 | 6920 | if (flags & EF_ARM_INTERWORK) |
d003868e AM |
6921 | (*_bfd_error_handler) |
6922 | (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), | |
6923 | abfd); | |
fc830a83 | 6924 | else |
d003868e AM |
6925 | _bfd_error_handler |
6926 | (_("Warning: Clearing the interworking flag of %B due to outside request"), | |
6927 | abfd); | |
fc830a83 | 6928 | } |
252b5132 RH |
6929 | } |
6930 | else | |
6931 | { | |
6932 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 | 6933 | elf_flags_init (abfd) = TRUE; |
252b5132 RH |
6934 | } |
6935 | ||
b34976b6 | 6936 | return TRUE; |
252b5132 RH |
6937 | } |
6938 | ||
ee065d83 PB |
6939 | /* Copy the eabi object attribute from IBFD to OBFD. */ |
6940 | static void | |
6941 | copy_eabi_attributes (bfd *ibfd, bfd *obfd) | |
6942 | { | |
6943 | aeabi_attribute *in_attr; | |
6944 | aeabi_attribute *out_attr; | |
6945 | aeabi_attribute_list *list; | |
6946 | int i; | |
6947 | ||
004ae526 PB |
6948 | in_attr = &elf32_arm_tdata (ibfd)->known_eabi_attributes[4]; |
6949 | out_attr = &elf32_arm_tdata (obfd)->known_eabi_attributes[4]; | |
ee065d83 PB |
6950 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) |
6951 | { | |
6952 | out_attr->i = in_attr->i; | |
6953 | if (in_attr->s && *in_attr->s) | |
6954 | out_attr->s = attr_strdup (obfd, in_attr->s); | |
6955 | in_attr++; | |
6956 | out_attr++; | |
6957 | } | |
6958 | ||
6959 | for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
6960 | list; | |
6961 | list = list->next) | |
6962 | { | |
6963 | in_attr = &list->attr; | |
6964 | switch (in_attr->type) | |
6965 | { | |
6966 | case 1: | |
6967 | elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i); | |
6968 | break; | |
6969 | case 2: | |
6970 | elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s); | |
6971 | break; | |
6972 | case 3: | |
6973 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
6974 | break; | |
6975 | default: | |
6976 | abort(); | |
6977 | } | |
6978 | } | |
6979 | } | |
6980 | ||
6981 | ||
fc830a83 | 6982 | /* Copy backend specific data from one object module to another. */ |
9b485d32 | 6983 | |
b34976b6 | 6984 | static bfd_boolean |
57e8b36a | 6985 | elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 RH |
6986 | { |
6987 | flagword in_flags; | |
6988 | flagword out_flags; | |
6989 | ||
fc830a83 | 6990 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
252b5132 | 6991 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
b34976b6 | 6992 | return TRUE; |
252b5132 | 6993 | |
fc830a83 | 6994 | in_flags = elf_elfheader (ibfd)->e_flags; |
252b5132 RH |
6995 | out_flags = elf_elfheader (obfd)->e_flags; |
6996 | ||
fc830a83 NC |
6997 | if (elf_flags_init (obfd) |
6998 | && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN | |
6999 | && in_flags != out_flags) | |
252b5132 | 7000 | { |
252b5132 | 7001 | /* Cannot mix APCS26 and APCS32 code. */ |
fd2ec330 | 7002 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
b34976b6 | 7003 | return FALSE; |
252b5132 RH |
7004 | |
7005 | /* Cannot mix float APCS and non-float APCS code. */ | |
fd2ec330 | 7006 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
b34976b6 | 7007 | return FALSE; |
252b5132 RH |
7008 | |
7009 | /* If the src and dest have different interworking flags | |
7010 | then turn off the interworking bit. */ | |
fd2ec330 | 7011 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
252b5132 | 7012 | { |
fd2ec330 | 7013 | if (out_flags & EF_ARM_INTERWORK) |
d003868e AM |
7014 | _bfd_error_handler |
7015 | (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), | |
7016 | obfd, ibfd); | |
252b5132 | 7017 | |
fd2ec330 | 7018 | in_flags &= ~EF_ARM_INTERWORK; |
252b5132 | 7019 | } |
1006ba19 PB |
7020 | |
7021 | /* Likewise for PIC, though don't warn for this case. */ | |
fd2ec330 PB |
7022 | if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) |
7023 | in_flags &= ~EF_ARM_PIC; | |
252b5132 RH |
7024 | } |
7025 | ||
7026 | elf_elfheader (obfd)->e_flags = in_flags; | |
b34976b6 | 7027 | elf_flags_init (obfd) = TRUE; |
252b5132 | 7028 | |
94a3258f PB |
7029 | /* Also copy the EI_OSABI field. */ |
7030 | elf_elfheader (obfd)->e_ident[EI_OSABI] = | |
7031 | elf_elfheader (ibfd)->e_ident[EI_OSABI]; | |
7032 | ||
ee065d83 PB |
7033 | /* Copy EABI object attributes. */ |
7034 | copy_eabi_attributes (ibfd, obfd); | |
7035 | ||
7036 | return TRUE; | |
7037 | } | |
7038 | ||
7039 | /* Values for Tag_ABI_PCS_R9_use. */ | |
7040 | enum | |
7041 | { | |
7042 | AEABI_R9_V6, | |
7043 | AEABI_R9_SB, | |
7044 | AEABI_R9_TLS, | |
7045 | AEABI_R9_unused | |
7046 | }; | |
7047 | ||
7048 | /* Values for Tag_ABI_PCS_RW_data. */ | |
7049 | enum | |
7050 | { | |
7051 | AEABI_PCS_RW_data_absolute, | |
7052 | AEABI_PCS_RW_data_PCrel, | |
7053 | AEABI_PCS_RW_data_SBrel, | |
7054 | AEABI_PCS_RW_data_unused | |
7055 | }; | |
7056 | ||
7057 | /* Values for Tag_ABI_enum_size. */ | |
7058 | enum | |
7059 | { | |
7060 | AEABI_enum_unused, | |
7061 | AEABI_enum_short, | |
7062 | AEABI_enum_wide, | |
7063 | AEABI_enum_forced_wide | |
7064 | }; | |
7065 | ||
7066 | /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there | |
7067 | are conflicting attributes. */ | |
7068 | static bfd_boolean | |
7069 | elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd) | |
7070 | { | |
7071 | aeabi_attribute *in_attr; | |
7072 | aeabi_attribute *out_attr; | |
7073 | aeabi_attribute_list *in_list; | |
7074 | aeabi_attribute_list *out_list; | |
7075 | /* Some tags have 0 = don't care, 1 = strong requirement, | |
7076 | 2 = weak requirement. */ | |
7077 | static const int order_312[3] = {3, 1, 2}; | |
7078 | int i; | |
7079 | ||
004ae526 | 7080 | if (!elf32_arm_tdata (obfd)->known_eabi_attributes[0].i) |
ee065d83 PB |
7081 | { |
7082 | /* This is the first object. Copy the attributes. */ | |
7083 | copy_eabi_attributes (ibfd, obfd); | |
004ae526 PB |
7084 | |
7085 | /* Use the Tag_null value to indicate the attributes have been | |
7086 | initialized. */ | |
7087 | elf32_arm_tdata (obfd)->known_eabi_attributes[0].i = 1; | |
7088 | ||
ee065d83 PB |
7089 | return TRUE; |
7090 | } | |
7091 | ||
ee065d83 PB |
7092 | in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes; |
7093 | out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
7094 | /* This needs to happen before Tag_ABI_FP_number_model is merged. */ | |
7095 | if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i) | |
7096 | { | |
7097 | /* Ignore mismatches if teh object doesn't use floating point. */ | |
7098 | if (out_attr[Tag_ABI_FP_number_model].i == 0) | |
7099 | out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i; | |
7100 | else if (in_attr[Tag_ABI_FP_number_model].i != 0) | |
7101 | { | |
7102 | _bfd_error_handler | |
7103 | (_("ERROR: %B uses VFP register arguments, %B does not"), | |
7104 | ibfd, obfd); | |
7105 | return FALSE; | |
7106 | } | |
7107 | } | |
7108 | ||
7109 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
7110 | { | |
7111 | /* Merge this attribute with existing attributes. */ | |
7112 | switch (i) | |
7113 | { | |
7114 | case Tag_CPU_raw_name: | |
7115 | case Tag_CPU_name: | |
004ae526 PB |
7116 | /* Use whichever has the greatest architecture requirements. We |
7117 | won't necessarily have both the above tags, so make sure input | |
7118 | name is non-NULL. */ | |
7119 | if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i | |
7120 | && in_attr[i].s) | |
ee065d83 PB |
7121 | out_attr[i].s = attr_strdup(obfd, in_attr[i].s); |
7122 | break; | |
7123 | ||
7124 | case Tag_ABI_optimization_goals: | |
7125 | case Tag_ABI_FP_optimization_goals: | |
7126 | /* Use the first value seen. */ | |
7127 | break; | |
7128 | ||
7129 | case Tag_CPU_arch: | |
7130 | case Tag_ARM_ISA_use: | |
7131 | case Tag_THUMB_ISA_use: | |
7132 | case Tag_VFP_arch: | |
7133 | case Tag_WMMX_arch: | |
7134 | case Tag_NEON_arch: | |
7135 | /* ??? Do NEON and WMMX conflict? */ | |
7136 | case Tag_ABI_FP_rounding: | |
7137 | case Tag_ABI_FP_denormal: | |
7138 | case Tag_ABI_FP_exceptions: | |
7139 | case Tag_ABI_FP_user_exceptions: | |
7140 | case Tag_ABI_FP_number_model: | |
7141 | case Tag_ABI_align8_preserved: | |
7142 | case Tag_ABI_HardFP_use: | |
7143 | /* Use the largest value specified. */ | |
7144 | if (in_attr[i].i > out_attr[i].i) | |
7145 | out_attr[i].i = in_attr[i].i; | |
7146 | break; | |
7147 | ||
7148 | case Tag_CPU_arch_profile: | |
7149 | /* Warn if conflicting architecture profiles used. */ | |
7150 | if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i) | |
7151 | { | |
7152 | _bfd_error_handler | |
7153 | (_("ERROR: %B: Conflicting architecture profiles %c/%c"), | |
7154 | ibfd, in_attr[i].i, out_attr[i].i); | |
7155 | return FALSE; | |
7156 | } | |
7157 | if (in_attr[i].i) | |
7158 | out_attr[i].i = in_attr[i].i; | |
7159 | break; | |
7160 | case Tag_PCS_config: | |
7161 | if (out_attr[i].i == 0) | |
7162 | out_attr[i].i = in_attr[i].i; | |
7163 | else if (in_attr[i].i != 0 && out_attr[i].i != 0) | |
7164 | { | |
7165 | /* It's sometimes ok to mix different configs, so this is only | |
7166 | a warning. */ | |
7167 | _bfd_error_handler | |
7168 | (_("Warning: %B: Conflicting platform configuration"), ibfd); | |
7169 | } | |
7170 | break; | |
7171 | case Tag_ABI_PCS_R9_use: | |
004ae526 PB |
7172 | if (in_attr[i].i != out_attr[i].i |
7173 | && out_attr[i].i != AEABI_R9_unused | |
ee065d83 PB |
7174 | && in_attr[i].i != AEABI_R9_unused) |
7175 | { | |
7176 | _bfd_error_handler | |
7177 | (_("ERROR: %B: Conflicting use of R9"), ibfd); | |
7178 | return FALSE; | |
7179 | } | |
7180 | if (out_attr[i].i == AEABI_R9_unused) | |
7181 | out_attr[i].i = in_attr[i].i; | |
7182 | break; | |
7183 | case Tag_ABI_PCS_RW_data: | |
7184 | if (in_attr[i].i == AEABI_PCS_RW_data_SBrel | |
7185 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB | |
7186 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused) | |
7187 | { | |
7188 | _bfd_error_handler | |
7189 | (_("ERROR: %B: SB relative addressing conflicts with use of R9"), | |
7190 | ibfd); | |
7191 | return FALSE; | |
7192 | } | |
7193 | /* Use the smallest value specified. */ | |
7194 | if (in_attr[i].i < out_attr[i].i) | |
7195 | out_attr[i].i = in_attr[i].i; | |
7196 | break; | |
7197 | case Tag_ABI_PCS_RO_data: | |
7198 | /* Use the smallest value specified. */ | |
7199 | if (in_attr[i].i < out_attr[i].i) | |
7200 | out_attr[i].i = in_attr[i].i; | |
7201 | break; | |
7202 | case Tag_ABI_PCS_GOT_use: | |
7203 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
7204 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
7205 | out_attr[i].i = in_attr[i].i; | |
7206 | break; | |
7207 | case Tag_ABI_PCS_wchar_t: | |
7208 | if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i) | |
7209 | { | |
7210 | _bfd_error_handler | |
7211 | (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd); | |
7212 | return FALSE; | |
7213 | } | |
7214 | if (in_attr[i].i) | |
7215 | out_attr[i].i = in_attr[i].i; | |
7216 | break; | |
7217 | case Tag_ABI_align8_needed: | |
7218 | /* ??? Check against Tag_ABI_align8_preserved. */ | |
7219 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
7220 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
7221 | out_attr[i].i = in_attr[i].i; | |
7222 | break; | |
7223 | case Tag_ABI_enum_size: | |
7224 | if (in_attr[i].i != AEABI_enum_unused) | |
7225 | { | |
7226 | if (out_attr[i].i == AEABI_enum_unused | |
7227 | || out_attr[i].i == AEABI_enum_forced_wide) | |
7228 | { | |
7229 | /* The existing object is compatible with anything. | |
7230 | Use whatever requirements the new object has. */ | |
7231 | out_attr[i].i = in_attr[i].i; | |
7232 | } | |
7233 | else if (in_attr[i].i != AEABI_enum_forced_wide | |
bf21ed78 MS |
7234 | && out_attr[i].i != in_attr[i].i |
7235 | && !elf32_arm_tdata (obfd)->no_enum_size_warning) | |
ee065d83 | 7236 | { |
bf21ed78 MS |
7237 | const char *aeabi_enum_names[] = |
7238 | { "", "variable-size", "32-bit", "" }; | |
ee065d83 | 7239 | _bfd_error_handler |
bf21ed78 MS |
7240 | (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"), |
7241 | ibfd, aeabi_enum_names[in_attr[i].i], | |
7242 | aeabi_enum_names[out_attr[i].i]); | |
ee065d83 PB |
7243 | } |
7244 | } | |
7245 | break; | |
7246 | case Tag_ABI_VFP_args: | |
7247 | /* Aready done. */ | |
7248 | break; | |
7249 | case Tag_ABI_WMMX_args: | |
7250 | if (in_attr[i].i != out_attr[i].i) | |
7251 | { | |
7252 | _bfd_error_handler | |
7253 | (_("ERROR: %B uses iWMMXt register arguments, %B does not"), | |
7254 | ibfd, obfd); | |
7255 | return FALSE; | |
7256 | } | |
7257 | break; | |
7258 | default: /* All known attributes should be explicitly covered. */ | |
7259 | abort (); | |
7260 | } | |
7261 | } | |
7262 | ||
7263 | in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
7264 | out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
7265 | while (in_list && in_list->tag == Tag_compatibility) | |
7266 | { | |
7267 | in_attr = &in_list->attr; | |
7268 | if (in_attr->i == 0) | |
7269 | continue; | |
7270 | if (in_attr->i == 1) | |
7271 | { | |
7272 | _bfd_error_handler | |
7273 | (_("ERROR: %B: Must be processed by '%s' toolchain"), | |
7274 | ibfd, in_attr->s); | |
7275 | return FALSE; | |
7276 | } | |
7277 | if (!out_list || out_list->tag != Tag_compatibility | |
7278 | || strcmp (in_attr->s, out_list->attr.s) != 0) | |
7279 | { | |
7280 | /* Add this compatibility tag to the output. */ | |
7281 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
7282 | continue; | |
7283 | } | |
7284 | out_attr = &out_list->attr; | |
7285 | /* Check all the input tags with the same identifier. */ | |
7286 | for (;;) | |
7287 | { | |
7288 | if (out_list->tag != Tag_compatibility | |
7289 | || in_attr->i != out_attr->i | |
7290 | || strcmp (in_attr->s, out_attr->s) != 0) | |
7291 | { | |
7292 | _bfd_error_handler | |
7293 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
7294 | ibfd, in_attr->s, in_attr->i); | |
7295 | return FALSE; | |
7296 | } | |
7297 | in_list = in_list->next; | |
7298 | if (in_list->tag != Tag_compatibility | |
7299 | || strcmp (in_attr->s, in_list->attr.s) != 0) | |
7300 | break; | |
7301 | in_attr = &in_list->attr; | |
7302 | out_list = out_list->next; | |
7303 | if (out_list) | |
7304 | out_attr = &out_list->attr; | |
7305 | } | |
7306 | ||
7307 | /* Check the output doesn't have extra tags with this identifier. */ | |
7308 | if (out_list && out_list->tag == Tag_compatibility | |
7309 | && strcmp (in_attr->s, out_list->attr.s) == 0) | |
7310 | { | |
7311 | _bfd_error_handler | |
7312 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
7313 | ibfd, in_attr->s, out_list->attr.i); | |
7314 | return FALSE; | |
7315 | } | |
7316 | } | |
7317 | ||
7318 | for (; in_list; in_list = in_list->next) | |
7319 | { | |
7320 | if ((in_list->tag & 128) < 64) | |
eb111b1f BE |
7321 | { |
7322 | _bfd_error_handler | |
7323 | (_("Warning: %B: Unknown EABI object attribute %d"), | |
7324 | ibfd, in_list->tag); | |
7325 | break; | |
7326 | } | |
ee065d83 | 7327 | } |
b34976b6 | 7328 | return TRUE; |
252b5132 RH |
7329 | } |
7330 | ||
3a4a14e9 PB |
7331 | |
7332 | /* Return TRUE if the two EABI versions are incompatible. */ | |
7333 | ||
7334 | static bfd_boolean | |
7335 | elf32_arm_versions_compatible (unsigned iver, unsigned over) | |
7336 | { | |
7337 | /* v4 and v5 are the same spec before and after it was released, | |
7338 | so allow mixing them. */ | |
7339 | if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5) | |
7340 | || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4)) | |
7341 | return TRUE; | |
7342 | ||
7343 | return (iver == over); | |
7344 | } | |
7345 | ||
252b5132 RH |
7346 | /* Merge backend specific data from an object file to the output |
7347 | object file when linking. */ | |
9b485d32 | 7348 | |
b34976b6 | 7349 | static bfd_boolean |
57e8b36a | 7350 | elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
252b5132 RH |
7351 | { |
7352 | flagword out_flags; | |
7353 | flagword in_flags; | |
b34976b6 | 7354 | bfd_boolean flags_compatible = TRUE; |
cf919dfd | 7355 | asection *sec; |
252b5132 | 7356 | |
9b485d32 | 7357 | /* Check if we have the same endianess. */ |
82e51918 | 7358 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 7359 | return FALSE; |
1fe494a5 | 7360 | |
252b5132 RH |
7361 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
7362 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 7363 | return TRUE; |
252b5132 | 7364 | |
ee065d83 PB |
7365 | if (!elf32_arm_merge_eabi_attributes (ibfd, obfd)) |
7366 | return FALSE; | |
7367 | ||
252b5132 RH |
7368 | /* The input BFD must have had its flags initialised. */ |
7369 | /* The following seems bogus to me -- The flags are initialized in | |
7370 | the assembler but I don't think an elf_flags_init field is | |
9b485d32 | 7371 | written into the object. */ |
252b5132 RH |
7372 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
7373 | ||
7374 | in_flags = elf_elfheader (ibfd)->e_flags; | |
7375 | out_flags = elf_elfheader (obfd)->e_flags; | |
7376 | ||
7377 | if (!elf_flags_init (obfd)) | |
7378 | { | |
fe077fa6 NC |
7379 | /* If the input is the default architecture and had the default |
7380 | flags then do not bother setting the flags for the output | |
7381 | architecture, instead allow future merges to do this. If no | |
7382 | future merges ever set these flags then they will retain their | |
7383 | uninitialised values, which surprise surprise, correspond | |
252b5132 | 7384 | to the default values. */ |
fe077fa6 NC |
7385 | if (bfd_get_arch_info (ibfd)->the_default |
7386 | && elf_elfheader (ibfd)->e_flags == 0) | |
b34976b6 | 7387 | return TRUE; |
252b5132 | 7388 | |
b34976b6 | 7389 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
7390 | elf_elfheader (obfd)->e_flags = in_flags; |
7391 | ||
7392 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
7393 | && bfd_get_arch_info (obfd)->the_default) | |
7394 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); | |
7395 | ||
b34976b6 | 7396 | return TRUE; |
252b5132 RH |
7397 | } |
7398 | ||
5a6c6817 NC |
7399 | /* Determine what should happen if the input ARM architecture |
7400 | does not match the output ARM architecture. */ | |
7401 | if (! bfd_arm_merge_machines (ibfd, obfd)) | |
7402 | return FALSE; | |
e16bb312 | 7403 | |
1006ba19 | 7404 | /* Identical flags must be compatible. */ |
252b5132 | 7405 | if (in_flags == out_flags) |
b34976b6 | 7406 | return TRUE; |
252b5132 | 7407 | |
35a0f415 DJ |
7408 | /* Check to see if the input BFD actually contains any sections. If |
7409 | not, its flags may not have been initialised either, but it | |
8e3de13a | 7410 | cannot actually cause any incompatiblity. Do not short-circuit |
35a0f415 | 7411 | dynamic objects; their section list may be emptied by |
d1f161ea | 7412 | elf_link_add_object_symbols. |
35a0f415 | 7413 | |
d1f161ea NC |
7414 | Also check to see if there are no code sections in the input. |
7415 | In this case there is no need to check for code specific flags. | |
7416 | XXX - do we need to worry about floating-point format compatability | |
7417 | in data sections ? */ | |
35a0f415 | 7418 | if (!(ibfd->flags & DYNAMIC)) |
cf919dfd | 7419 | { |
35a0f415 | 7420 | bfd_boolean null_input_bfd = TRUE; |
d1f161ea | 7421 | bfd_boolean only_data_sections = TRUE; |
35a0f415 DJ |
7422 | |
7423 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
cf919dfd | 7424 | { |
35a0f415 DJ |
7425 | /* Ignore synthetic glue sections. */ |
7426 | if (strcmp (sec->name, ".glue_7") | |
7427 | && strcmp (sec->name, ".glue_7t")) | |
7428 | { | |
d1f161ea NC |
7429 | if ((bfd_get_section_flags (ibfd, sec) |
7430 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
7431 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
7432 | only_data_sections = FALSE; | |
7433 | ||
35a0f415 DJ |
7434 | null_input_bfd = FALSE; |
7435 | break; | |
7436 | } | |
cf919dfd | 7437 | } |
d1f161ea NC |
7438 | |
7439 | if (null_input_bfd || only_data_sections) | |
35a0f415 | 7440 | return TRUE; |
cf919dfd | 7441 | } |
cf919dfd | 7442 | |
252b5132 | 7443 | /* Complain about various flag mismatches. */ |
3a4a14e9 PB |
7444 | if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags), |
7445 | EF_ARM_EABI_VERSION (out_flags))) | |
fc830a83 | 7446 | { |
d003868e | 7447 | _bfd_error_handler |
3656d5e3 | 7448 | (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"), |
d003868e AM |
7449 | ibfd, obfd, |
7450 | (in_flags & EF_ARM_EABIMASK) >> 24, | |
7451 | (out_flags & EF_ARM_EABIMASK) >> 24); | |
b34976b6 | 7452 | return FALSE; |
fc830a83 | 7453 | } |
252b5132 | 7454 | |
1006ba19 | 7455 | /* Not sure what needs to be checked for EABI versions >= 1. */ |
00a97672 RS |
7456 | /* VxWorks libraries do not use these flags. */ |
7457 | if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed | |
7458 | && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed | |
7459 | && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) | |
1006ba19 | 7460 | { |
fd2ec330 | 7461 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
1006ba19 | 7462 | { |
d003868e AM |
7463 | _bfd_error_handler |
7464 | (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), | |
7465 | ibfd, obfd, | |
7466 | in_flags & EF_ARM_APCS_26 ? 26 : 32, | |
7467 | out_flags & EF_ARM_APCS_26 ? 26 : 32); | |
b34976b6 | 7468 | flags_compatible = FALSE; |
1006ba19 | 7469 | } |
252b5132 | 7470 | |
fd2ec330 | 7471 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
1006ba19 | 7472 | { |
5eefb65f | 7473 | if (in_flags & EF_ARM_APCS_FLOAT) |
d003868e AM |
7474 | _bfd_error_handler |
7475 | (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), | |
7476 | ibfd, obfd); | |
5eefb65f | 7477 | else |
d003868e AM |
7478 | _bfd_error_handler |
7479 | (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), | |
7480 | ibfd, obfd); | |
63b0f745 | 7481 | |
b34976b6 | 7482 | flags_compatible = FALSE; |
1006ba19 | 7483 | } |
252b5132 | 7484 | |
96a846ea | 7485 | if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) |
1006ba19 | 7486 | { |
96a846ea | 7487 | if (in_flags & EF_ARM_VFP_FLOAT) |
d003868e AM |
7488 | _bfd_error_handler |
7489 | (_("ERROR: %B uses VFP instructions, whereas %B does not"), | |
7490 | ibfd, obfd); | |
5eefb65f | 7491 | else |
d003868e AM |
7492 | _bfd_error_handler |
7493 | (_("ERROR: %B uses FPA instructions, whereas %B does not"), | |
7494 | ibfd, obfd); | |
fde78edd NC |
7495 | |
7496 | flags_compatible = FALSE; | |
7497 | } | |
7498 | ||
7499 | if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) | |
7500 | { | |
7501 | if (in_flags & EF_ARM_MAVERICK_FLOAT) | |
d003868e AM |
7502 | _bfd_error_handler |
7503 | (_("ERROR: %B uses Maverick instructions, whereas %B does not"), | |
7504 | ibfd, obfd); | |
fde78edd | 7505 | else |
d003868e AM |
7506 | _bfd_error_handler |
7507 | (_("ERROR: %B does not use Maverick instructions, whereas %B does"), | |
7508 | ibfd, obfd); | |
63b0f745 | 7509 | |
b34976b6 | 7510 | flags_compatible = FALSE; |
1006ba19 | 7511 | } |
96a846ea RE |
7512 | |
7513 | #ifdef EF_ARM_SOFT_FLOAT | |
7514 | if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) | |
7515 | { | |
7516 | /* We can allow interworking between code that is VFP format | |
7517 | layout, and uses either soft float or integer regs for | |
7518 | passing floating point arguments and results. We already | |
7519 | know that the APCS_FLOAT flags match; similarly for VFP | |
7520 | flags. */ | |
7521 | if ((in_flags & EF_ARM_APCS_FLOAT) != 0 | |
7522 | || (in_flags & EF_ARM_VFP_FLOAT) == 0) | |
7523 | { | |
7524 | if (in_flags & EF_ARM_SOFT_FLOAT) | |
d003868e AM |
7525 | _bfd_error_handler |
7526 | (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), | |
7527 | ibfd, obfd); | |
96a846ea | 7528 | else |
d003868e AM |
7529 | _bfd_error_handler |
7530 | (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), | |
7531 | ibfd, obfd); | |
96a846ea | 7532 | |
b34976b6 | 7533 | flags_compatible = FALSE; |
96a846ea RE |
7534 | } |
7535 | } | |
ee43f35e | 7536 | #endif |
252b5132 | 7537 | |
1006ba19 | 7538 | /* Interworking mismatch is only a warning. */ |
fd2ec330 | 7539 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
8f615d07 | 7540 | { |
e3c8793a NC |
7541 | if (in_flags & EF_ARM_INTERWORK) |
7542 | { | |
d003868e AM |
7543 | _bfd_error_handler |
7544 | (_("Warning: %B supports interworking, whereas %B does not"), | |
7545 | ibfd, obfd); | |
e3c8793a NC |
7546 | } |
7547 | else | |
7548 | { | |
d003868e AM |
7549 | _bfd_error_handler |
7550 | (_("Warning: %B does not support interworking, whereas %B does"), | |
7551 | ibfd, obfd); | |
e3c8793a | 7552 | } |
8f615d07 | 7553 | } |
252b5132 | 7554 | } |
63b0f745 | 7555 | |
1006ba19 | 7556 | return flags_compatible; |
252b5132 RH |
7557 | } |
7558 | ||
9b485d32 NC |
7559 | /* Display the flags field. */ |
7560 | ||
b34976b6 | 7561 | static bfd_boolean |
57e8b36a | 7562 | elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) |
252b5132 | 7563 | { |
fc830a83 NC |
7564 | FILE * file = (FILE *) ptr; |
7565 | unsigned long flags; | |
252b5132 RH |
7566 | |
7567 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
7568 | ||
7569 | /* Print normal ELF private data. */ | |
7570 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
7571 | ||
fc830a83 | 7572 | flags = elf_elfheader (abfd)->e_flags; |
9b485d32 NC |
7573 | /* Ignore init flag - it may not be set, despite the flags field |
7574 | containing valid data. */ | |
252b5132 RH |
7575 | |
7576 | /* xgettext:c-format */ | |
9b485d32 | 7577 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
252b5132 | 7578 | |
fc830a83 NC |
7579 | switch (EF_ARM_EABI_VERSION (flags)) |
7580 | { | |
7581 | case EF_ARM_EABI_UNKNOWN: | |
4cc11e76 | 7582 | /* The following flag bits are GNU extensions and not part of the |
fc830a83 NC |
7583 | official ARM ELF extended ABI. Hence they are only decoded if |
7584 | the EABI version is not set. */ | |
fd2ec330 | 7585 | if (flags & EF_ARM_INTERWORK) |
9b485d32 | 7586 | fprintf (file, _(" [interworking enabled]")); |
9a5aca8c | 7587 | |
fd2ec330 | 7588 | if (flags & EF_ARM_APCS_26) |
6c571f00 | 7589 | fprintf (file, " [APCS-26]"); |
fc830a83 | 7590 | else |
6c571f00 | 7591 | fprintf (file, " [APCS-32]"); |
9a5aca8c | 7592 | |
96a846ea RE |
7593 | if (flags & EF_ARM_VFP_FLOAT) |
7594 | fprintf (file, _(" [VFP float format]")); | |
fde78edd NC |
7595 | else if (flags & EF_ARM_MAVERICK_FLOAT) |
7596 | fprintf (file, _(" [Maverick float format]")); | |
96a846ea RE |
7597 | else |
7598 | fprintf (file, _(" [FPA float format]")); | |
7599 | ||
fd2ec330 | 7600 | if (flags & EF_ARM_APCS_FLOAT) |
9b485d32 | 7601 | fprintf (file, _(" [floats passed in float registers]")); |
9a5aca8c | 7602 | |
fd2ec330 | 7603 | if (flags & EF_ARM_PIC) |
9b485d32 | 7604 | fprintf (file, _(" [position independent]")); |
fc830a83 | 7605 | |
fd2ec330 | 7606 | if (flags & EF_ARM_NEW_ABI) |
9b485d32 | 7607 | fprintf (file, _(" [new ABI]")); |
9a5aca8c | 7608 | |
fd2ec330 | 7609 | if (flags & EF_ARM_OLD_ABI) |
9b485d32 | 7610 | fprintf (file, _(" [old ABI]")); |
9a5aca8c | 7611 | |
fd2ec330 | 7612 | if (flags & EF_ARM_SOFT_FLOAT) |
9b485d32 | 7613 | fprintf (file, _(" [software FP]")); |
9a5aca8c | 7614 | |
96a846ea RE |
7615 | flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT |
7616 | | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI | |
fde78edd NC |
7617 | | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT |
7618 | | EF_ARM_MAVERICK_FLOAT); | |
fc830a83 | 7619 | break; |
9a5aca8c | 7620 | |
fc830a83 | 7621 | case EF_ARM_EABI_VER1: |
9b485d32 | 7622 | fprintf (file, _(" [Version1 EABI]")); |
9a5aca8c | 7623 | |
fc830a83 | 7624 | if (flags & EF_ARM_SYMSARESORTED) |
9b485d32 | 7625 | fprintf (file, _(" [sorted symbol table]")); |
fc830a83 | 7626 | else |
9b485d32 | 7627 | fprintf (file, _(" [unsorted symbol table]")); |
9a5aca8c | 7628 | |
fc830a83 NC |
7629 | flags &= ~ EF_ARM_SYMSARESORTED; |
7630 | break; | |
9a5aca8c | 7631 | |
fd2ec330 PB |
7632 | case EF_ARM_EABI_VER2: |
7633 | fprintf (file, _(" [Version2 EABI]")); | |
7634 | ||
7635 | if (flags & EF_ARM_SYMSARESORTED) | |
7636 | fprintf (file, _(" [sorted symbol table]")); | |
7637 | else | |
7638 | fprintf (file, _(" [unsorted symbol table]")); | |
7639 | ||
7640 | if (flags & EF_ARM_DYNSYMSUSESEGIDX) | |
7641 | fprintf (file, _(" [dynamic symbols use segment index]")); | |
7642 | ||
7643 | if (flags & EF_ARM_MAPSYMSFIRST) | |
7644 | fprintf (file, _(" [mapping symbols precede others]")); | |
7645 | ||
99e4ae17 | 7646 | flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX |
fd2ec330 PB |
7647 | | EF_ARM_MAPSYMSFIRST); |
7648 | break; | |
7649 | ||
d507cf36 PB |
7650 | case EF_ARM_EABI_VER3: |
7651 | fprintf (file, _(" [Version3 EABI]")); | |
8cb51566 PB |
7652 | break; |
7653 | ||
7654 | case EF_ARM_EABI_VER4: | |
7655 | fprintf (file, _(" [Version4 EABI]")); | |
3a4a14e9 | 7656 | goto eabi; |
d507cf36 | 7657 | |
3a4a14e9 PB |
7658 | case EF_ARM_EABI_VER5: |
7659 | fprintf (file, _(" [Version5 EABI]")); | |
7660 | eabi: | |
d507cf36 PB |
7661 | if (flags & EF_ARM_BE8) |
7662 | fprintf (file, _(" [BE8]")); | |
7663 | ||
7664 | if (flags & EF_ARM_LE8) | |
7665 | fprintf (file, _(" [LE8]")); | |
7666 | ||
7667 | flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); | |
7668 | break; | |
7669 | ||
fc830a83 | 7670 | default: |
9b485d32 | 7671 | fprintf (file, _(" <EABI version unrecognised>")); |
fc830a83 NC |
7672 | break; |
7673 | } | |
252b5132 | 7674 | |
fc830a83 | 7675 | flags &= ~ EF_ARM_EABIMASK; |
252b5132 | 7676 | |
fc830a83 | 7677 | if (flags & EF_ARM_RELEXEC) |
9b485d32 | 7678 | fprintf (file, _(" [relocatable executable]")); |
252b5132 | 7679 | |
fc830a83 | 7680 | if (flags & EF_ARM_HASENTRY) |
9b485d32 | 7681 | fprintf (file, _(" [has entry point]")); |
252b5132 | 7682 | |
fc830a83 NC |
7683 | flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); |
7684 | ||
7685 | if (flags) | |
9b485d32 | 7686 | fprintf (file, _("<Unrecognised flag bits set>")); |
9a5aca8c | 7687 | |
252b5132 RH |
7688 | fputc ('\n', file); |
7689 | ||
b34976b6 | 7690 | return TRUE; |
252b5132 RH |
7691 | } |
7692 | ||
7693 | static int | |
57e8b36a | 7694 | elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
252b5132 | 7695 | { |
2f0ca46a NC |
7696 | switch (ELF_ST_TYPE (elf_sym->st_info)) |
7697 | { | |
7698 | case STT_ARM_TFUNC: | |
7699 | return ELF_ST_TYPE (elf_sym->st_info); | |
ce855c42 | 7700 | |
2f0ca46a NC |
7701 | case STT_ARM_16BIT: |
7702 | /* If the symbol is not an object, return the STT_ARM_16BIT flag. | |
7703 | This allows us to distinguish between data used by Thumb instructions | |
7704 | and non-data (which is probably code) inside Thumb regions of an | |
7705 | executable. */ | |
1a0eb693 | 7706 | if (type != STT_OBJECT && type != STT_TLS) |
2f0ca46a NC |
7707 | return ELF_ST_TYPE (elf_sym->st_info); |
7708 | break; | |
9a5aca8c | 7709 | |
ce855c42 NC |
7710 | default: |
7711 | break; | |
2f0ca46a NC |
7712 | } |
7713 | ||
7714 | return type; | |
252b5132 | 7715 | } |
f21f3fe0 | 7716 | |
252b5132 | 7717 | static asection * |
07adf181 AM |
7718 | elf32_arm_gc_mark_hook (asection *sec, |
7719 | struct bfd_link_info *info, | |
7720 | Elf_Internal_Rela *rel, | |
7721 | struct elf_link_hash_entry *h, | |
7722 | Elf_Internal_Sym *sym) | |
252b5132 RH |
7723 | { |
7724 | if (h != NULL) | |
07adf181 | 7725 | switch (ELF32_R_TYPE (rel->r_info)) |
252b5132 RH |
7726 | { |
7727 | case R_ARM_GNU_VTINHERIT: | |
7728 | case R_ARM_GNU_VTENTRY: | |
07adf181 AM |
7729 | return NULL; |
7730 | } | |
9ad5cbcf | 7731 | |
07adf181 | 7732 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); |
252b5132 RH |
7733 | } |
7734 | ||
780a67af NC |
7735 | /* Update the got entry reference counts for the section being removed. */ |
7736 | ||
b34976b6 | 7737 | static bfd_boolean |
ba93b8ac DJ |
7738 | elf32_arm_gc_sweep_hook (bfd * abfd, |
7739 | struct bfd_link_info * info, | |
7740 | asection * sec, | |
7741 | const Elf_Internal_Rela * relocs) | |
252b5132 | 7742 | { |
5e681ec4 PB |
7743 | Elf_Internal_Shdr *symtab_hdr; |
7744 | struct elf_link_hash_entry **sym_hashes; | |
7745 | bfd_signed_vma *local_got_refcounts; | |
7746 | const Elf_Internal_Rela *rel, *relend; | |
eb043451 PB |
7747 | struct elf32_arm_link_hash_table * globals; |
7748 | ||
7749 | globals = elf32_arm_hash_table (info); | |
5e681ec4 PB |
7750 | |
7751 | elf_section_data (sec)->local_dynrel = NULL; | |
7752 | ||
7753 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
7754 | sym_hashes = elf_sym_hashes (abfd); | |
7755 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
7756 | ||
7757 | relend = relocs + sec->reloc_count; | |
7758 | for (rel = relocs; rel < relend; rel++) | |
eb043451 | 7759 | { |
3eb128b2 AM |
7760 | unsigned long r_symndx; |
7761 | struct elf_link_hash_entry *h = NULL; | |
eb043451 | 7762 | int r_type; |
5e681ec4 | 7763 | |
3eb128b2 AM |
7764 | r_symndx = ELF32_R_SYM (rel->r_info); |
7765 | if (r_symndx >= symtab_hdr->sh_info) | |
7766 | { | |
7767 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
7768 | while (h->root.type == bfd_link_hash_indirect | |
7769 | || h->root.type == bfd_link_hash_warning) | |
7770 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7771 | } | |
7772 | ||
eb043451 | 7773 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 7774 | r_type = arm_real_reloc_type (globals, r_type); |
eb043451 PB |
7775 | switch (r_type) |
7776 | { | |
7777 | case R_ARM_GOT32: | |
eb043451 | 7778 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
7779 | case R_ARM_TLS_GD32: |
7780 | case R_ARM_TLS_IE32: | |
3eb128b2 | 7781 | if (h != NULL) |
eb043451 | 7782 | { |
eb043451 PB |
7783 | if (h->got.refcount > 0) |
7784 | h->got.refcount -= 1; | |
7785 | } | |
7786 | else if (local_got_refcounts != NULL) | |
7787 | { | |
7788 | if (local_got_refcounts[r_symndx] > 0) | |
7789 | local_got_refcounts[r_symndx] -= 1; | |
7790 | } | |
7791 | break; | |
7792 | ||
ba93b8ac DJ |
7793 | case R_ARM_TLS_LDM32: |
7794 | elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; | |
7795 | break; | |
7796 | ||
eb043451 | 7797 | case R_ARM_ABS32: |
bb224fc3 | 7798 | case R_ARM_ABS32_NOI: |
eb043451 | 7799 | case R_ARM_REL32: |
bb224fc3 | 7800 | case R_ARM_REL32_NOI: |
eb043451 PB |
7801 | case R_ARM_PC24: |
7802 | case R_ARM_PLT32: | |
5b5bb741 PB |
7803 | case R_ARM_CALL: |
7804 | case R_ARM_JUMP24: | |
eb043451 | 7805 | case R_ARM_PREL31: |
c19d1205 | 7806 | case R_ARM_THM_CALL: |
b6895b4f PB |
7807 | case R_ARM_MOVW_ABS_NC: |
7808 | case R_ARM_MOVT_ABS: | |
7809 | case R_ARM_MOVW_PREL_NC: | |
7810 | case R_ARM_MOVT_PREL: | |
7811 | case R_ARM_THM_MOVW_ABS_NC: | |
7812 | case R_ARM_THM_MOVT_ABS: | |
7813 | case R_ARM_THM_MOVW_PREL_NC: | |
7814 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 DJ |
7815 | /* Should the interworking branches be here also? */ |
7816 | ||
3eb128b2 | 7817 | if (h != NULL) |
eb043451 PB |
7818 | { |
7819 | struct elf32_arm_link_hash_entry *eh; | |
7820 | struct elf32_arm_relocs_copied **pp; | |
7821 | struct elf32_arm_relocs_copied *p; | |
5e681ec4 | 7822 | |
b7693d02 | 7823 | eh = (struct elf32_arm_link_hash_entry *) h; |
5e681ec4 | 7824 | |
eb043451 | 7825 | if (h->plt.refcount > 0) |
b7693d02 DJ |
7826 | { |
7827 | h->plt.refcount -= 1; | |
c19d1205 | 7828 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL) |
b7693d02 DJ |
7829 | eh->plt_thumb_refcount--; |
7830 | } | |
5e681ec4 | 7831 | |
eb043451 | 7832 | if (r_type == R_ARM_ABS32 |
bb224fc3 MS |
7833 | || r_type == R_ARM_REL32 |
7834 | || r_type == R_ARM_ABS32_NOI | |
7835 | || r_type == R_ARM_REL32_NOI) | |
eb043451 | 7836 | { |
eb043451 PB |
7837 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; |
7838 | pp = &p->next) | |
7839 | if (p->section == sec) | |
7840 | { | |
7841 | p->count -= 1; | |
bb224fc3 MS |
7842 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32 |
7843 | || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI) | |
ba93b8ac | 7844 | p->pc_count -= 1; |
eb043451 PB |
7845 | if (p->count == 0) |
7846 | *pp = p->next; | |
7847 | break; | |
7848 | } | |
7849 | } | |
7850 | } | |
7851 | break; | |
5e681ec4 | 7852 | |
eb043451 PB |
7853 | default: |
7854 | break; | |
7855 | } | |
7856 | } | |
5e681ec4 | 7857 | |
b34976b6 | 7858 | return TRUE; |
252b5132 RH |
7859 | } |
7860 | ||
780a67af NC |
7861 | /* Look through the relocs for a section during the first phase. */ |
7862 | ||
b34976b6 | 7863 | static bfd_boolean |
57e8b36a NC |
7864 | elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, |
7865 | asection *sec, const Elf_Internal_Rela *relocs) | |
252b5132 | 7866 | { |
b34976b6 AM |
7867 | Elf_Internal_Shdr *symtab_hdr; |
7868 | struct elf_link_hash_entry **sym_hashes; | |
7869 | struct elf_link_hash_entry **sym_hashes_end; | |
7870 | const Elf_Internal_Rela *rel; | |
7871 | const Elf_Internal_Rela *rel_end; | |
7872 | bfd *dynobj; | |
5e681ec4 | 7873 | asection *sreloc; |
b34976b6 | 7874 | bfd_vma *local_got_offsets; |
5e681ec4 | 7875 | struct elf32_arm_link_hash_table *htab; |
9a5aca8c | 7876 | |
1049f94e | 7877 | if (info->relocatable) |
b34976b6 | 7878 | return TRUE; |
9a5aca8c | 7879 | |
5e681ec4 PB |
7880 | htab = elf32_arm_hash_table (info); |
7881 | sreloc = NULL; | |
9a5aca8c | 7882 | |
67687978 PB |
7883 | /* Create dynamic sections for relocatable executables so that we can |
7884 | copy relocations. */ | |
7885 | if (htab->root.is_relocatable_executable | |
7886 | && ! htab->root.dynamic_sections_created) | |
7887 | { | |
7888 | if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) | |
7889 | return FALSE; | |
7890 | } | |
7891 | ||
252b5132 RH |
7892 | dynobj = elf_hash_table (info)->dynobj; |
7893 | local_got_offsets = elf_local_got_offsets (abfd); | |
f21f3fe0 | 7894 | |
252b5132 RH |
7895 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
7896 | sym_hashes = elf_sym_hashes (abfd); | |
9b485d32 NC |
7897 | sym_hashes_end = sym_hashes |
7898 | + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); | |
7899 | ||
252b5132 RH |
7900 | if (!elf_bad_symtab (abfd)) |
7901 | sym_hashes_end -= symtab_hdr->sh_info; | |
9b485d32 | 7902 | |
252b5132 RH |
7903 | rel_end = relocs + sec->reloc_count; |
7904 | for (rel = relocs; rel < rel_end; rel++) | |
7905 | { | |
7906 | struct elf_link_hash_entry *h; | |
b7693d02 | 7907 | struct elf32_arm_link_hash_entry *eh; |
252b5132 | 7908 | unsigned long r_symndx; |
eb043451 | 7909 | int r_type; |
9a5aca8c | 7910 | |
252b5132 | 7911 | r_symndx = ELF32_R_SYM (rel->r_info); |
eb043451 | 7912 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 7913 | r_type = arm_real_reloc_type (htab, r_type); |
ba93b8ac DJ |
7914 | |
7915 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
7916 | { | |
7917 | (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd, | |
7918 | r_symndx); | |
7919 | return FALSE; | |
7920 | } | |
7921 | ||
252b5132 RH |
7922 | if (r_symndx < symtab_hdr->sh_info) |
7923 | h = NULL; | |
7924 | else | |
973a3492 L |
7925 | { |
7926 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
7927 | while (h->root.type == bfd_link_hash_indirect | |
7928 | || h->root.type == bfd_link_hash_warning) | |
7929 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7930 | } | |
9a5aca8c | 7931 | |
b7693d02 DJ |
7932 | eh = (struct elf32_arm_link_hash_entry *) h; |
7933 | ||
eb043451 | 7934 | switch (r_type) |
252b5132 | 7935 | { |
5e681ec4 | 7936 | case R_ARM_GOT32: |
eb043451 | 7937 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
7938 | case R_ARM_TLS_GD32: |
7939 | case R_ARM_TLS_IE32: | |
5e681ec4 | 7940 | /* This symbol requires a global offset table entry. */ |
ba93b8ac DJ |
7941 | { |
7942 | int tls_type, old_tls_type; | |
5e681ec4 | 7943 | |
ba93b8ac DJ |
7944 | switch (r_type) |
7945 | { | |
7946 | case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break; | |
7947 | case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break; | |
7948 | default: tls_type = GOT_NORMAL; break; | |
7949 | } | |
252b5132 | 7950 | |
ba93b8ac DJ |
7951 | if (h != NULL) |
7952 | { | |
7953 | h->got.refcount++; | |
7954 | old_tls_type = elf32_arm_hash_entry (h)->tls_type; | |
7955 | } | |
7956 | else | |
7957 | { | |
7958 | bfd_signed_vma *local_got_refcounts; | |
7959 | ||
7960 | /* This is a global offset table entry for a local symbol. */ | |
7961 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
7962 | if (local_got_refcounts == NULL) | |
7963 | { | |
7964 | bfd_size_type size; | |
7965 | ||
7966 | size = symtab_hdr->sh_info; | |
7967 | size *= (sizeof (bfd_signed_vma) + sizeof(char)); | |
7968 | local_got_refcounts = bfd_zalloc (abfd, size); | |
7969 | if (local_got_refcounts == NULL) | |
7970 | return FALSE; | |
7971 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
7972 | elf32_arm_local_got_tls_type (abfd) | |
7973 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
7974 | } | |
7975 | local_got_refcounts[r_symndx] += 1; | |
7976 | old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx]; | |
7977 | } | |
7978 | ||
7979 | /* We will already have issued an error message if there is a | |
7980 | TLS / non-TLS mismatch, based on the symbol type. We don't | |
7981 | support any linker relaxations. So just combine any TLS | |
7982 | types needed. */ | |
7983 | if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL | |
7984 | && tls_type != GOT_NORMAL) | |
7985 | tls_type |= old_tls_type; | |
7986 | ||
7987 | if (old_tls_type != tls_type) | |
7988 | { | |
7989 | if (h != NULL) | |
7990 | elf32_arm_hash_entry (h)->tls_type = tls_type; | |
7991 | else | |
7992 | elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
7993 | } | |
7994 | } | |
7995 | /* Fall through */ | |
7996 | ||
7997 | case R_ARM_TLS_LDM32: | |
7998 | if (r_type == R_ARM_TLS_LDM32) | |
7999 | htab->tls_ldm_got.refcount++; | |
8000 | /* Fall through */ | |
252b5132 | 8001 | |
c19d1205 | 8002 | case R_ARM_GOTOFF32: |
5e681ec4 PB |
8003 | case R_ARM_GOTPC: |
8004 | if (htab->sgot == NULL) | |
8005 | { | |
8006 | if (htab->root.dynobj == NULL) | |
8007 | htab->root.dynobj = abfd; | |
8008 | if (!create_got_section (htab->root.dynobj, info)) | |
8009 | return FALSE; | |
8010 | } | |
252b5132 RH |
8011 | break; |
8012 | ||
00a97672 RS |
8013 | case R_ARM_ABS12: |
8014 | /* VxWorks uses dynamic R_ARM_ABS12 relocations for | |
8015 | ldr __GOTT_INDEX__ offsets. */ | |
8016 | if (!htab->vxworks_p) | |
8017 | break; | |
8018 | /* Fall through */ | |
8019 | ||
252b5132 | 8020 | case R_ARM_ABS32: |
bb224fc3 | 8021 | case R_ARM_ABS32_NOI: |
252b5132 | 8022 | case R_ARM_REL32: |
bb224fc3 | 8023 | case R_ARM_REL32_NOI: |
252b5132 | 8024 | case R_ARM_PC24: |
7359ea65 | 8025 | case R_ARM_PLT32: |
5b5bb741 PB |
8026 | case R_ARM_CALL: |
8027 | case R_ARM_JUMP24: | |
eb043451 | 8028 | case R_ARM_PREL31: |
c19d1205 | 8029 | case R_ARM_THM_CALL: |
b6895b4f PB |
8030 | case R_ARM_MOVW_ABS_NC: |
8031 | case R_ARM_MOVT_ABS: | |
8032 | case R_ARM_MOVW_PREL_NC: | |
8033 | case R_ARM_MOVT_PREL: | |
8034 | case R_ARM_THM_MOVW_ABS_NC: | |
8035 | case R_ARM_THM_MOVT_ABS: | |
8036 | case R_ARM_THM_MOVW_PREL_NC: | |
8037 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 | 8038 | /* Should the interworking branches be listed here? */ |
7359ea65 | 8039 | if (h != NULL) |
5e681ec4 PB |
8040 | { |
8041 | /* If this reloc is in a read-only section, we might | |
8042 | need a copy reloc. We can't check reliably at this | |
8043 | stage whether the section is read-only, as input | |
8044 | sections have not yet been mapped to output sections. | |
8045 | Tentatively set the flag for now, and correct in | |
8046 | adjust_dynamic_symbol. */ | |
7359ea65 | 8047 | if (!info->shared) |
f5385ebf | 8048 | h->non_got_ref = 1; |
7359ea65 | 8049 | |
5e681ec4 | 8050 | /* We may need a .plt entry if the function this reloc |
c84cd8ee DJ |
8051 | refers to is in a different object. We can't tell for |
8052 | sure yet, because something later might force the | |
8053 | symbol local. */ | |
bb224fc3 MS |
8054 | if (r_type != R_ARM_ABS32 |
8055 | && r_type != R_ARM_REL32 | |
8056 | && r_type != R_ARM_ABS32_NOI | |
8057 | && r_type != R_ARM_REL32_NOI) | |
f5385ebf | 8058 | h->needs_plt = 1; |
4f199be3 DJ |
8059 | |
8060 | /* If we create a PLT entry, this relocation will reference | |
8061 | it, even if it's an ABS32 relocation. */ | |
8062 | h->plt.refcount += 1; | |
b7693d02 | 8063 | |
c19d1205 | 8064 | if (r_type == R_ARM_THM_CALL) |
b7693d02 | 8065 | eh->plt_thumb_refcount += 1; |
5e681ec4 PB |
8066 | } |
8067 | ||
67687978 PB |
8068 | /* If we are creating a shared library or relocatable executable, |
8069 | and this is a reloc against a global symbol, or a non PC | |
8070 | relative reloc against a local symbol, then we need to copy | |
8071 | the reloc into the shared library. However, if we are linking | |
8072 | with -Bsymbolic, we do not need to copy a reloc against a | |
252b5132 RH |
8073 | global symbol which is defined in an object we are |
8074 | including in the link (i.e., DEF_REGULAR is set). At | |
8075 | this point we have not seen all the input files, so it is | |
8076 | possible that DEF_REGULAR is not set now but will be set | |
8077 | later (it is never cleared). We account for that | |
8078 | possibility below by storing information in the | |
5e681ec4 | 8079 | relocs_copied field of the hash table entry. */ |
67687978 | 8080 | if ((info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 8081 | && (sec->flags & SEC_ALLOC) != 0 |
bb224fc3 | 8082 | && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI) |
71a976dd DJ |
8083 | || (h != NULL && ! h->needs_plt |
8084 | && (! info->symbolic || ! h->def_regular)))) | |
252b5132 | 8085 | { |
5e681ec4 PB |
8086 | struct elf32_arm_relocs_copied *p, **head; |
8087 | ||
252b5132 RH |
8088 | /* When creating a shared object, we must copy these |
8089 | reloc types into the output file. We create a reloc | |
8090 | section in dynobj and make room for this reloc. */ | |
8091 | if (sreloc == NULL) | |
8092 | { | |
8093 | const char * name; | |
8094 | ||
8095 | name = (bfd_elf_string_from_elf_section | |
8096 | (abfd, | |
8097 | elf_elfheader (abfd)->e_shstrndx, | |
8098 | elf_section_data (sec)->rel_hdr.sh_name)); | |
8099 | if (name == NULL) | |
b34976b6 | 8100 | return FALSE; |
252b5132 | 8101 | |
00a97672 | 8102 | BFD_ASSERT (reloc_section_p (htab, name, sec)); |
252b5132 RH |
8103 | |
8104 | sreloc = bfd_get_section_by_name (dynobj, name); | |
8105 | if (sreloc == NULL) | |
8106 | { | |
8107 | flagword flags; | |
8108 | ||
252b5132 RH |
8109 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
8110 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
e5a52504 MM |
8111 | if ((sec->flags & SEC_ALLOC) != 0 |
8112 | /* BPABI objects never have dynamic | |
8113 | relocations mapped. */ | |
8114 | && !htab->symbian_p) | |
252b5132 | 8115 | flags |= SEC_ALLOC | SEC_LOAD; |
3496cb2a L |
8116 | sreloc = bfd_make_section_with_flags (dynobj, |
8117 | name, | |
8118 | flags); | |
252b5132 | 8119 | if (sreloc == NULL |
252b5132 | 8120 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
b34976b6 | 8121 | return FALSE; |
252b5132 | 8122 | } |
5e681ec4 PB |
8123 | |
8124 | elf_section_data (sec)->sreloc = sreloc; | |
252b5132 RH |
8125 | } |
8126 | ||
5e681ec4 PB |
8127 | /* If this is a global symbol, we count the number of |
8128 | relocations we need for this symbol. */ | |
8129 | if (h != NULL) | |
252b5132 | 8130 | { |
5e681ec4 PB |
8131 | head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; |
8132 | } | |
8133 | else | |
8134 | { | |
8135 | /* Track dynamic relocs needed for local syms too. | |
8136 | We really need local syms available to do this | |
8137 | easily. Oh well. */ | |
57e8b36a | 8138 | |
5e681ec4 | 8139 | asection *s; |
6edfbbad DJ |
8140 | void *vpp; |
8141 | ||
5e681ec4 PB |
8142 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
8143 | sec, r_symndx); | |
8144 | if (s == NULL) | |
8145 | return FALSE; | |
57e8b36a | 8146 | |
6edfbbad DJ |
8147 | vpp = &elf_section_data (s)->local_dynrel; |
8148 | head = (struct elf32_arm_relocs_copied **) vpp; | |
5e681ec4 | 8149 | } |
57e8b36a | 8150 | |
5e681ec4 PB |
8151 | p = *head; |
8152 | if (p == NULL || p->section != sec) | |
8153 | { | |
8154 | bfd_size_type amt = sizeof *p; | |
57e8b36a | 8155 | |
5e681ec4 | 8156 | p = bfd_alloc (htab->root.dynobj, amt); |
252b5132 | 8157 | if (p == NULL) |
5e681ec4 PB |
8158 | return FALSE; |
8159 | p->next = *head; | |
8160 | *head = p; | |
8161 | p->section = sec; | |
8162 | p->count = 0; | |
ba93b8ac | 8163 | p->pc_count = 0; |
252b5132 | 8164 | } |
57e8b36a | 8165 | |
bb224fc3 | 8166 | if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI) |
ba93b8ac | 8167 | p->pc_count += 1; |
71a976dd | 8168 | p->count += 1; |
252b5132 RH |
8169 | } |
8170 | break; | |
8171 | ||
8172 | /* This relocation describes the C++ object vtable hierarchy. | |
8173 | Reconstruct it for later use during GC. */ | |
8174 | case R_ARM_GNU_VTINHERIT: | |
c152c796 | 8175 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 8176 | return FALSE; |
252b5132 | 8177 | break; |
9a5aca8c | 8178 | |
252b5132 RH |
8179 | /* This relocation describes which C++ vtable entries are actually |
8180 | used. Record for later use during GC. */ | |
8181 | case R_ARM_GNU_VTENTRY: | |
c152c796 | 8182 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
b34976b6 | 8183 | return FALSE; |
252b5132 RH |
8184 | break; |
8185 | } | |
8186 | } | |
f21f3fe0 | 8187 | |
b34976b6 | 8188 | return TRUE; |
252b5132 RH |
8189 | } |
8190 | ||
6a5bb875 PB |
8191 | /* Unwinding tables are not referenced directly. This pass marks them as |
8192 | required if the corresponding code section is marked. */ | |
8193 | ||
8194 | static bfd_boolean | |
8195 | elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info, | |
8196 | elf_gc_mark_hook_fn gc_mark_hook) | |
8197 | { | |
8198 | bfd *sub; | |
8199 | Elf_Internal_Shdr **elf_shdrp; | |
8200 | bfd_boolean again; | |
8201 | ||
8202 | /* Marking EH data may cause additional code sections to be marked, | |
8203 | requiring multiple passes. */ | |
8204 | again = TRUE; | |
8205 | while (again) | |
8206 | { | |
8207 | again = FALSE; | |
8208 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) | |
8209 | { | |
8210 | asection *o; | |
8211 | ||
8212 | if (bfd_get_flavour (sub) != bfd_target_elf_flavour) | |
8213 | continue; | |
8214 | ||
8215 | elf_shdrp = elf_elfsections (sub); | |
8216 | for (o = sub->sections; o != NULL; o = o->next) | |
8217 | { | |
8218 | Elf_Internal_Shdr *hdr; | |
8219 | hdr = &elf_section_data (o)->this_hdr; | |
8220 | if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link | |
8221 | && !o->gc_mark | |
8222 | && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark) | |
8223 | { | |
8224 | again = TRUE; | |
8225 | if (!_bfd_elf_gc_mark (info, o, gc_mark_hook)) | |
8226 | return FALSE; | |
8227 | } | |
8228 | } | |
8229 | } | |
8230 | } | |
8231 | ||
8232 | return TRUE; | |
8233 | } | |
8234 | ||
3c9458e9 NC |
8235 | /* Treat mapping symbols as special target symbols. */ |
8236 | ||
8237 | static bfd_boolean | |
8238 | elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym) | |
8239 | { | |
b0796911 PB |
8240 | return bfd_is_arm_special_symbol_name (sym->name, |
8241 | BFD_ARM_SPECIAL_SYM_TYPE_ANY); | |
3c9458e9 NC |
8242 | } |
8243 | ||
0367ecfb NC |
8244 | /* This is a copy of elf_find_function() from elf.c except that |
8245 | ARM mapping symbols are ignored when looking for function names | |
8246 | and STT_ARM_TFUNC is considered to a function type. */ | |
252b5132 | 8247 | |
0367ecfb NC |
8248 | static bfd_boolean |
8249 | arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, | |
8250 | asection * section, | |
8251 | asymbol ** symbols, | |
8252 | bfd_vma offset, | |
8253 | const char ** filename_ptr, | |
8254 | const char ** functionname_ptr) | |
8255 | { | |
8256 | const char * filename = NULL; | |
8257 | asymbol * func = NULL; | |
8258 | bfd_vma low_func = 0; | |
8259 | asymbol ** p; | |
252b5132 RH |
8260 | |
8261 | for (p = symbols; *p != NULL; p++) | |
8262 | { | |
8263 | elf_symbol_type *q; | |
8264 | ||
8265 | q = (elf_symbol_type *) *p; | |
8266 | ||
252b5132 RH |
8267 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) |
8268 | { | |
8269 | default: | |
8270 | break; | |
8271 | case STT_FILE: | |
8272 | filename = bfd_asymbol_name (&q->symbol); | |
8273 | break; | |
252b5132 RH |
8274 | case STT_FUNC: |
8275 | case STT_ARM_TFUNC: | |
9d2da7ca | 8276 | case STT_NOTYPE: |
b0796911 | 8277 | /* Skip mapping symbols. */ |
0367ecfb | 8278 | if ((q->symbol.flags & BSF_LOCAL) |
b0796911 PB |
8279 | && bfd_is_arm_special_symbol_name (q->symbol.name, |
8280 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
0367ecfb NC |
8281 | continue; |
8282 | /* Fall through. */ | |
6b40fcba | 8283 | if (bfd_get_section (&q->symbol) == section |
252b5132 RH |
8284 | && q->symbol.value >= low_func |
8285 | && q->symbol.value <= offset) | |
8286 | { | |
8287 | func = (asymbol *) q; | |
8288 | low_func = q->symbol.value; | |
8289 | } | |
8290 | break; | |
8291 | } | |
8292 | } | |
8293 | ||
8294 | if (func == NULL) | |
b34976b6 | 8295 | return FALSE; |
252b5132 | 8296 | |
0367ecfb NC |
8297 | if (filename_ptr) |
8298 | *filename_ptr = filename; | |
8299 | if (functionname_ptr) | |
8300 | *functionname_ptr = bfd_asymbol_name (func); | |
8301 | ||
8302 | return TRUE; | |
8303 | } | |
8304 | ||
8305 | ||
8306 | /* Find the nearest line to a particular section and offset, for error | |
8307 | reporting. This code is a duplicate of the code in elf.c, except | |
8308 | that it uses arm_elf_find_function. */ | |
8309 | ||
8310 | static bfd_boolean | |
8311 | elf32_arm_find_nearest_line (bfd * abfd, | |
8312 | asection * section, | |
8313 | asymbol ** symbols, | |
8314 | bfd_vma offset, | |
8315 | const char ** filename_ptr, | |
8316 | const char ** functionname_ptr, | |
8317 | unsigned int * line_ptr) | |
8318 | { | |
8319 | bfd_boolean found = FALSE; | |
8320 | ||
8321 | /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ | |
8322 | ||
8323 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, | |
8324 | filename_ptr, functionname_ptr, | |
8325 | line_ptr, 0, | |
8326 | & elf_tdata (abfd)->dwarf2_find_line_info)) | |
8327 | { | |
8328 | if (!*functionname_ptr) | |
8329 | arm_elf_find_function (abfd, section, symbols, offset, | |
8330 | *filename_ptr ? NULL : filename_ptr, | |
8331 | functionname_ptr); | |
f21f3fe0 | 8332 | |
0367ecfb NC |
8333 | return TRUE; |
8334 | } | |
8335 | ||
8336 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, | |
8337 | & found, filename_ptr, | |
8338 | functionname_ptr, line_ptr, | |
8339 | & elf_tdata (abfd)->line_info)) | |
8340 | return FALSE; | |
8341 | ||
8342 | if (found && (*functionname_ptr || *line_ptr)) | |
8343 | return TRUE; | |
8344 | ||
8345 | if (symbols == NULL) | |
8346 | return FALSE; | |
8347 | ||
8348 | if (! arm_elf_find_function (abfd, section, symbols, offset, | |
8349 | filename_ptr, functionname_ptr)) | |
8350 | return FALSE; | |
8351 | ||
8352 | *line_ptr = 0; | |
b34976b6 | 8353 | return TRUE; |
252b5132 RH |
8354 | } |
8355 | ||
4ab527b0 FF |
8356 | static bfd_boolean |
8357 | elf32_arm_find_inliner_info (bfd * abfd, | |
8358 | const char ** filename_ptr, | |
8359 | const char ** functionname_ptr, | |
8360 | unsigned int * line_ptr) | |
8361 | { | |
8362 | bfd_boolean found; | |
8363 | found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr, | |
8364 | functionname_ptr, line_ptr, | |
8365 | & elf_tdata (abfd)->dwarf2_find_line_info); | |
8366 | return found; | |
8367 | } | |
8368 | ||
252b5132 RH |
8369 | /* Adjust a symbol defined by a dynamic object and referenced by a |
8370 | regular object. The current definition is in some section of the | |
8371 | dynamic object, but we're not including those sections. We have to | |
8372 | change the definition to something the rest of the link can | |
8373 | understand. */ | |
8374 | ||
b34976b6 | 8375 | static bfd_boolean |
57e8b36a NC |
8376 | elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, |
8377 | struct elf_link_hash_entry * h) | |
252b5132 RH |
8378 | { |
8379 | bfd * dynobj; | |
8380 | asection * s; | |
8381 | unsigned int power_of_two; | |
b7693d02 | 8382 | struct elf32_arm_link_hash_entry * eh; |
67687978 | 8383 | struct elf32_arm_link_hash_table *globals; |
252b5132 | 8384 | |
67687978 | 8385 | globals = elf32_arm_hash_table (info); |
252b5132 RH |
8386 | dynobj = elf_hash_table (info)->dynobj; |
8387 | ||
8388 | /* Make sure we know what is going on here. */ | |
8389 | BFD_ASSERT (dynobj != NULL | |
f5385ebf | 8390 | && (h->needs_plt |
f6e332e6 | 8391 | || h->u.weakdef != NULL |
f5385ebf AM |
8392 | || (h->def_dynamic |
8393 | && h->ref_regular | |
8394 | && !h->def_regular))); | |
252b5132 | 8395 | |
b7693d02 DJ |
8396 | eh = (struct elf32_arm_link_hash_entry *) h; |
8397 | ||
252b5132 RH |
8398 | /* If this is a function, put it in the procedure linkage table. We |
8399 | will fill in the contents of the procedure linkage table later, | |
8400 | when we know the address of the .got section. */ | |
b7693d02 | 8401 | if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC |
f5385ebf | 8402 | || h->needs_plt) |
252b5132 | 8403 | { |
5e681ec4 PB |
8404 | if (h->plt.refcount <= 0 |
8405 | || SYMBOL_CALLS_LOCAL (info, h) | |
8406 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
8407 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
8408 | { |
8409 | /* This case can occur if we saw a PLT32 reloc in an input | |
5e681ec4 PB |
8410 | file, but the symbol was never referred to by a dynamic |
8411 | object, or if all references were garbage collected. In | |
8412 | such a case, we don't actually need to build a procedure | |
8413 | linkage table, and we can just do a PC24 reloc instead. */ | |
8414 | h->plt.offset = (bfd_vma) -1; | |
b7693d02 | 8415 | eh->plt_thumb_refcount = 0; |
f5385ebf | 8416 | h->needs_plt = 0; |
252b5132 RH |
8417 | } |
8418 | ||
b34976b6 | 8419 | return TRUE; |
252b5132 | 8420 | } |
5e681ec4 | 8421 | else |
b7693d02 DJ |
8422 | { |
8423 | /* It's possible that we incorrectly decided a .plt reloc was | |
8424 | needed for an R_ARM_PC24 or similar reloc to a non-function sym | |
8425 | in check_relocs. We can't decide accurately between function | |
8426 | and non-function syms in check-relocs; Objects loaded later in | |
8427 | the link may change h->type. So fix it now. */ | |
8428 | h->plt.offset = (bfd_vma) -1; | |
8429 | eh->plt_thumb_refcount = 0; | |
8430 | } | |
252b5132 RH |
8431 | |
8432 | /* If this is a weak symbol, and there is a real definition, the | |
8433 | processor independent code will have arranged for us to see the | |
8434 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 8435 | if (h->u.weakdef != NULL) |
252b5132 | 8436 | { |
f6e332e6 AM |
8437 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
8438 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
8439 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
8440 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
b34976b6 | 8441 | return TRUE; |
252b5132 RH |
8442 | } |
8443 | ||
ba93b8ac DJ |
8444 | /* If there are no non-GOT references, we do not need a copy |
8445 | relocation. */ | |
8446 | if (!h->non_got_ref) | |
8447 | return TRUE; | |
8448 | ||
252b5132 RH |
8449 | /* This is a reference to a symbol defined by a dynamic object which |
8450 | is not a function. */ | |
8451 | ||
8452 | /* If we are creating a shared library, we must presume that the | |
8453 | only references to the symbol are via the global offset table. | |
8454 | For such cases we need not do anything here; the relocations will | |
67687978 PB |
8455 | be handled correctly by relocate_section. Relocatable executables |
8456 | can reference data in shared objects directly, so we don't need to | |
8457 | do anything here. */ | |
8458 | if (info->shared || globals->root.is_relocatable_executable) | |
b34976b6 | 8459 | return TRUE; |
252b5132 | 8460 | |
909272ee AM |
8461 | if (h->size == 0) |
8462 | { | |
8463 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
8464 | h->root.root.string); | |
8465 | return TRUE; | |
8466 | } | |
8467 | ||
252b5132 RH |
8468 | /* We must allocate the symbol in our .dynbss section, which will |
8469 | become part of the .bss section of the executable. There will be | |
8470 | an entry for this symbol in the .dynsym section. The dynamic | |
8471 | object will contain position independent code, so all references | |
8472 | from the dynamic object to this symbol will go through the global | |
8473 | offset table. The dynamic linker will use the .dynsym entry to | |
8474 | determine the address it must put in the global offset table, so | |
8475 | both the dynamic object and the regular object will refer to the | |
8476 | same memory location for the variable. */ | |
252b5132 RH |
8477 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
8478 | BFD_ASSERT (s != NULL); | |
8479 | ||
8480 | /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to | |
8481 | copy the initial value out of the dynamic object and into the | |
8482 | runtime process image. We need to remember the offset into the | |
00a97672 | 8483 | .rel(a).bss section we are going to use. */ |
252b5132 RH |
8484 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
8485 | { | |
8486 | asection *srel; | |
8487 | ||
00a97672 | 8488 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss")); |
252b5132 | 8489 | BFD_ASSERT (srel != NULL); |
00a97672 | 8490 | srel->size += RELOC_SIZE (globals); |
f5385ebf | 8491 | h->needs_copy = 1; |
252b5132 RH |
8492 | } |
8493 | ||
8494 | /* We need to figure out the alignment required for this symbol. I | |
8495 | have no idea how ELF linkers handle this. */ | |
8496 | power_of_two = bfd_log2 (h->size); | |
8497 | if (power_of_two > 3) | |
8498 | power_of_two = 3; | |
8499 | ||
8500 | /* Apply the required alignment. */ | |
eea6121a | 8501 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
252b5132 RH |
8502 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
8503 | { | |
8504 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 8505 | return FALSE; |
252b5132 RH |
8506 | } |
8507 | ||
8508 | /* Define the symbol as being at this point in the section. */ | |
8509 | h->root.u.def.section = s; | |
eea6121a | 8510 | h->root.u.def.value = s->size; |
252b5132 RH |
8511 | |
8512 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 8513 | s->size += h->size; |
252b5132 | 8514 | |
b34976b6 | 8515 | return TRUE; |
252b5132 RH |
8516 | } |
8517 | ||
5e681ec4 PB |
8518 | /* Allocate space in .plt, .got and associated reloc sections for |
8519 | dynamic relocs. */ | |
8520 | ||
8521 | static bfd_boolean | |
57e8b36a | 8522 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
5e681ec4 PB |
8523 | { |
8524 | struct bfd_link_info *info; | |
8525 | struct elf32_arm_link_hash_table *htab; | |
8526 | struct elf32_arm_link_hash_entry *eh; | |
8527 | struct elf32_arm_relocs_copied *p; | |
8528 | ||
b7693d02 DJ |
8529 | eh = (struct elf32_arm_link_hash_entry *) h; |
8530 | ||
5e681ec4 PB |
8531 | if (h->root.type == bfd_link_hash_indirect) |
8532 | return TRUE; | |
8533 | ||
8534 | if (h->root.type == bfd_link_hash_warning) | |
8535 | /* When warning symbols are created, they **replace** the "real" | |
8536 | entry in the hash table, thus we never get to see the real | |
8537 | symbol in a hash traversal. So look at it now. */ | |
8538 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
8539 | ||
8540 | info = (struct bfd_link_info *) inf; | |
8541 | htab = elf32_arm_hash_table (info); | |
8542 | ||
8543 | if (htab->root.dynamic_sections_created | |
8544 | && h->plt.refcount > 0) | |
8545 | { | |
8546 | /* Make sure this symbol is output as a dynamic symbol. | |
8547 | Undefined weak syms won't yet be marked as dynamic. */ | |
8548 | if (h->dynindx == -1 | |
f5385ebf | 8549 | && !h->forced_local) |
5e681ec4 | 8550 | { |
c152c796 | 8551 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
8552 | return FALSE; |
8553 | } | |
8554 | ||
8555 | if (info->shared | |
7359ea65 | 8556 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
5e681ec4 PB |
8557 | { |
8558 | asection *s = htab->splt; | |
8559 | ||
8560 | /* If this is the first .plt entry, make room for the special | |
8561 | first entry. */ | |
eea6121a | 8562 | if (s->size == 0) |
e5a52504 | 8563 | s->size += htab->plt_header_size; |
5e681ec4 | 8564 | |
eea6121a | 8565 | h->plt.offset = s->size; |
5e681ec4 | 8566 | |
b7693d02 DJ |
8567 | /* If we will insert a Thumb trampoline before this PLT, leave room |
8568 | for it. */ | |
33bfe774 | 8569 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) |
b7693d02 DJ |
8570 | { |
8571 | h->plt.offset += PLT_THUMB_STUB_SIZE; | |
8572 | s->size += PLT_THUMB_STUB_SIZE; | |
8573 | } | |
8574 | ||
5e681ec4 PB |
8575 | /* If this symbol is not defined in a regular file, and we are |
8576 | not generating a shared library, then set the symbol to this | |
8577 | location in the .plt. This is required to make function | |
8578 | pointers compare as equal between the normal executable and | |
8579 | the shared library. */ | |
8580 | if (! info->shared | |
f5385ebf | 8581 | && !h->def_regular) |
5e681ec4 PB |
8582 | { |
8583 | h->root.u.def.section = s; | |
8584 | h->root.u.def.value = h->plt.offset; | |
b7693d02 DJ |
8585 | |
8586 | /* Make sure the function is not marked as Thumb, in case | |
8587 | it is the target of an ABS32 relocation, which will | |
8588 | point to the PLT entry. */ | |
8589 | if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) | |
8590 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); | |
5e681ec4 PB |
8591 | } |
8592 | ||
8593 | /* Make room for this entry. */ | |
e5a52504 | 8594 | s->size += htab->plt_entry_size; |
5e681ec4 | 8595 | |
e5a52504 | 8596 | if (!htab->symbian_p) |
b7693d02 DJ |
8597 | { |
8598 | /* We also need to make an entry in the .got.plt section, which | |
8599 | will be placed in the .got section by the linker script. */ | |
8600 | eh->plt_got_offset = htab->sgotplt->size; | |
8601 | htab->sgotplt->size += 4; | |
8602 | } | |
5e681ec4 | 8603 | |
00a97672 RS |
8604 | /* We also need to make an entry in the .rel(a).plt section. */ |
8605 | htab->srelplt->size += RELOC_SIZE (htab); | |
8606 | ||
8607 | /* VxWorks executables have a second set of relocations for | |
8608 | each PLT entry. They go in a separate relocation section, | |
8609 | which is processed by the kernel loader. */ | |
8610 | if (htab->vxworks_p && !info->shared) | |
8611 | { | |
8612 | /* There is a relocation for the initial PLT entry: | |
8613 | an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */ | |
8614 | if (h->plt.offset == htab->plt_header_size) | |
8615 | htab->srelplt2->size += RELOC_SIZE (htab); | |
8616 | ||
8617 | /* There are two extra relocations for each subsequent | |
8618 | PLT entry: an R_ARM_32 relocation for the GOT entry, | |
8619 | and an R_ARM_32 relocation for the PLT entry. */ | |
8620 | htab->srelplt2->size += RELOC_SIZE (htab) * 2; | |
8621 | } | |
5e681ec4 PB |
8622 | } |
8623 | else | |
8624 | { | |
8625 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 8626 | h->needs_plt = 0; |
5e681ec4 PB |
8627 | } |
8628 | } | |
8629 | else | |
8630 | { | |
8631 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 8632 | h->needs_plt = 0; |
5e681ec4 PB |
8633 | } |
8634 | ||
8635 | if (h->got.refcount > 0) | |
8636 | { | |
8637 | asection *s; | |
8638 | bfd_boolean dyn; | |
ba93b8ac DJ |
8639 | int tls_type = elf32_arm_hash_entry (h)->tls_type; |
8640 | int indx; | |
5e681ec4 PB |
8641 | |
8642 | /* Make sure this symbol is output as a dynamic symbol. | |
8643 | Undefined weak syms won't yet be marked as dynamic. */ | |
8644 | if (h->dynindx == -1 | |
f5385ebf | 8645 | && !h->forced_local) |
5e681ec4 | 8646 | { |
c152c796 | 8647 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
8648 | return FALSE; |
8649 | } | |
8650 | ||
e5a52504 MM |
8651 | if (!htab->symbian_p) |
8652 | { | |
8653 | s = htab->sgot; | |
8654 | h->got.offset = s->size; | |
ba93b8ac DJ |
8655 | |
8656 | if (tls_type == GOT_UNKNOWN) | |
8657 | abort (); | |
8658 | ||
8659 | if (tls_type == GOT_NORMAL) | |
8660 | /* Non-TLS symbols need one GOT slot. */ | |
8661 | s->size += 4; | |
8662 | else | |
8663 | { | |
8664 | if (tls_type & GOT_TLS_GD) | |
8665 | /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */ | |
8666 | s->size += 8; | |
8667 | if (tls_type & GOT_TLS_IE) | |
8668 | /* R_ARM_TLS_IE32 needs one GOT slot. */ | |
8669 | s->size += 4; | |
8670 | } | |
8671 | ||
e5a52504 | 8672 | dyn = htab->root.dynamic_sections_created; |
ba93b8ac DJ |
8673 | |
8674 | indx = 0; | |
8675 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
8676 | && (!info->shared | |
8677 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
8678 | indx = h->dynindx; | |
8679 | ||
8680 | if (tls_type != GOT_NORMAL | |
8681 | && (info->shared || indx != 0) | |
8682 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8683 | || h->root.type != bfd_link_hash_undefweak)) | |
8684 | { | |
8685 | if (tls_type & GOT_TLS_IE) | |
00a97672 | 8686 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
8687 | |
8688 | if (tls_type & GOT_TLS_GD) | |
00a97672 | 8689 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
8690 | |
8691 | if ((tls_type & GOT_TLS_GD) && indx != 0) | |
00a97672 | 8692 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
8693 | } |
8694 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8695 | || h->root.type != bfd_link_hash_undefweak) | |
8696 | && (info->shared | |
8697 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
00a97672 | 8698 | htab->srelgot->size += RELOC_SIZE (htab); |
e5a52504 | 8699 | } |
5e681ec4 PB |
8700 | } |
8701 | else | |
8702 | h->got.offset = (bfd_vma) -1; | |
8703 | ||
a4fd1a8e PB |
8704 | /* Allocate stubs for exported Thumb functions on v4t. */ |
8705 | if (!htab->use_blx && h->dynindx != -1 | |
0eaedd0e | 8706 | && h->def_regular |
a4fd1a8e PB |
8707 | && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC |
8708 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
8709 | { | |
8710 | struct elf_link_hash_entry * th; | |
8711 | struct bfd_link_hash_entry * bh; | |
8712 | struct elf_link_hash_entry * myh; | |
8713 | char name[1024]; | |
8714 | asection *s; | |
8715 | bh = NULL; | |
8716 | /* Create a new symbol to regist the real location of the function. */ | |
8717 | s = h->root.u.def.section; | |
8718 | sprintf(name, "__real_%s", h->root.root.string); | |
8719 | _bfd_generic_link_add_one_symbol (info, s->owner, | |
8720 | name, BSF_GLOBAL, s, | |
8721 | h->root.u.def.value, | |
8722 | NULL, TRUE, FALSE, &bh); | |
8723 | ||
8724 | myh = (struct elf_link_hash_entry *) bh; | |
8725 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); | |
8726 | myh->forced_local = 1; | |
8727 | eh->export_glue = myh; | |
8728 | th = record_arm_to_thumb_glue (info, h); | |
8729 | /* Point the symbol at the stub. */ | |
8730 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); | |
8731 | h->root.u.def.section = th->root.u.def.section; | |
8732 | h->root.u.def.value = th->root.u.def.value & ~1; | |
8733 | } | |
8734 | ||
5e681ec4 PB |
8735 | if (eh->relocs_copied == NULL) |
8736 | return TRUE; | |
8737 | ||
8738 | /* In the shared -Bsymbolic case, discard space allocated for | |
8739 | dynamic pc-relative relocs against symbols which turn out to be | |
8740 | defined in regular objects. For the normal shared case, discard | |
8741 | space for pc-relative relocs that have become local due to symbol | |
8742 | visibility changes. */ | |
8743 | ||
67687978 | 8744 | if (info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 8745 | { |
bb224fc3 MS |
8746 | /* The only reloc thats uses pc_count are R_ARM_REL32 and |
8747 | R_ARM_REL32_NOI, which will appear on something like | |
8748 | ".long foo - .". We want calls to protected symbols to resolve | |
8749 | directly to the function rather than going via the plt. If people | |
8750 | want function pointer comparisons to work as expected then they | |
8751 | should avoid writing assembly like ".long foo - .". */ | |
ba93b8ac DJ |
8752 | if (SYMBOL_CALLS_LOCAL (info, h)) |
8753 | { | |
8754 | struct elf32_arm_relocs_copied **pp; | |
8755 | ||
8756 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; ) | |
8757 | { | |
8758 | p->count -= p->pc_count; | |
8759 | p->pc_count = 0; | |
8760 | if (p->count == 0) | |
8761 | *pp = p->next; | |
8762 | else | |
8763 | pp = &p->next; | |
8764 | } | |
8765 | } | |
8766 | ||
8767 | /* Also discard relocs on undefined weak syms with non-default | |
7359ea65 | 8768 | visibility. */ |
22d606e9 | 8769 | if (eh->relocs_copied != NULL |
5e681ec4 | 8770 | && h->root.type == bfd_link_hash_undefweak) |
22d606e9 AM |
8771 | { |
8772 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
8773 | eh->relocs_copied = NULL; | |
8774 | ||
8775 | /* Make sure undefined weak symbols are output as a dynamic | |
8776 | symbol in PIEs. */ | |
8777 | else if (h->dynindx == -1 | |
8778 | && !h->forced_local) | |
8779 | { | |
8780 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
8781 | return FALSE; | |
8782 | } | |
8783 | } | |
8784 | ||
67687978 PB |
8785 | else if (htab->root.is_relocatable_executable && h->dynindx == -1 |
8786 | && h->root.type == bfd_link_hash_new) | |
8787 | { | |
8788 | /* Output absolute symbols so that we can create relocations | |
8789 | against them. For normal symbols we output a relocation | |
8790 | against the section that contains them. */ | |
8791 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
8792 | return FALSE; | |
8793 | } | |
8794 | ||
5e681ec4 PB |
8795 | } |
8796 | else | |
8797 | { | |
8798 | /* For the non-shared case, discard space for relocs against | |
8799 | symbols which turn out to need copy relocs or are not | |
8800 | dynamic. */ | |
8801 | ||
f5385ebf AM |
8802 | if (!h->non_got_ref |
8803 | && ((h->def_dynamic | |
8804 | && !h->def_regular) | |
5e681ec4 PB |
8805 | || (htab->root.dynamic_sections_created |
8806 | && (h->root.type == bfd_link_hash_undefweak | |
8807 | || h->root.type == bfd_link_hash_undefined)))) | |
8808 | { | |
8809 | /* Make sure this symbol is output as a dynamic symbol. | |
8810 | Undefined weak syms won't yet be marked as dynamic. */ | |
8811 | if (h->dynindx == -1 | |
f5385ebf | 8812 | && !h->forced_local) |
5e681ec4 | 8813 | { |
c152c796 | 8814 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
8815 | return FALSE; |
8816 | } | |
8817 | ||
8818 | /* If that succeeded, we know we'll be keeping all the | |
8819 | relocs. */ | |
8820 | if (h->dynindx != -1) | |
8821 | goto keep; | |
8822 | } | |
8823 | ||
8824 | eh->relocs_copied = NULL; | |
8825 | ||
8826 | keep: ; | |
8827 | } | |
8828 | ||
8829 | /* Finally, allocate space. */ | |
8830 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
8831 | { | |
8832 | asection *sreloc = elf_section_data (p->section)->sreloc; | |
00a97672 | 8833 | sreloc->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
8834 | } |
8835 | ||
8836 | return TRUE; | |
8837 | } | |
8838 | ||
08d1f311 DJ |
8839 | /* Find any dynamic relocs that apply to read-only sections. */ |
8840 | ||
8841 | static bfd_boolean | |
8842 | elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf) | |
8843 | { | |
8844 | struct elf32_arm_link_hash_entry *eh; | |
8845 | struct elf32_arm_relocs_copied *p; | |
8846 | ||
8847 | if (h->root.type == bfd_link_hash_warning) | |
8848 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
8849 | ||
8850 | eh = (struct elf32_arm_link_hash_entry *) h; | |
8851 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
8852 | { | |
8853 | asection *s = p->section; | |
8854 | ||
8855 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
8856 | { | |
8857 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
8858 | ||
8859 | info->flags |= DF_TEXTREL; | |
8860 | ||
8861 | /* Not an error, just cut short the traversal. */ | |
8862 | return FALSE; | |
8863 | } | |
8864 | } | |
8865 | return TRUE; | |
8866 | } | |
8867 | ||
d504ffc8 DJ |
8868 | void |
8869 | bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info, | |
8870 | int byteswap_code) | |
8871 | { | |
8872 | struct elf32_arm_link_hash_table *globals; | |
8873 | ||
8874 | globals = elf32_arm_hash_table (info); | |
8875 | globals->byteswap_code = byteswap_code; | |
8876 | } | |
8877 | ||
252b5132 RH |
8878 | /* Set the sizes of the dynamic sections. */ |
8879 | ||
b34976b6 | 8880 | static bfd_boolean |
57e8b36a NC |
8881 | elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, |
8882 | struct bfd_link_info * info) | |
252b5132 RH |
8883 | { |
8884 | bfd * dynobj; | |
8885 | asection * s; | |
b34976b6 AM |
8886 | bfd_boolean plt; |
8887 | bfd_boolean relocs; | |
5e681ec4 PB |
8888 | bfd *ibfd; |
8889 | struct elf32_arm_link_hash_table *htab; | |
252b5132 | 8890 | |
5e681ec4 | 8891 | htab = elf32_arm_hash_table (info); |
252b5132 RH |
8892 | dynobj = elf_hash_table (info)->dynobj; |
8893 | BFD_ASSERT (dynobj != NULL); | |
39b41c9c | 8894 | check_use_blx (htab); |
252b5132 RH |
8895 | |
8896 | if (elf_hash_table (info)->dynamic_sections_created) | |
8897 | { | |
8898 | /* Set the contents of the .interp section to the interpreter. */ | |
893c4fe2 | 8899 | if (info->executable) |
252b5132 RH |
8900 | { |
8901 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
8902 | BFD_ASSERT (s != NULL); | |
eea6121a | 8903 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
252b5132 RH |
8904 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
8905 | } | |
8906 | } | |
5e681ec4 PB |
8907 | |
8908 | /* Set up .got offsets for local syms, and space for local dynamic | |
8909 | relocs. */ | |
8910 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
252b5132 | 8911 | { |
5e681ec4 PB |
8912 | bfd_signed_vma *local_got; |
8913 | bfd_signed_vma *end_local_got; | |
8914 | char *local_tls_type; | |
8915 | bfd_size_type locsymcount; | |
8916 | Elf_Internal_Shdr *symtab_hdr; | |
8917 | asection *srel; | |
8918 | ||
8919 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
8920 | continue; | |
8921 | ||
8922 | for (s = ibfd->sections; s != NULL; s = s->next) | |
8923 | { | |
8924 | struct elf32_arm_relocs_copied *p; | |
8925 | ||
6edfbbad | 8926 | for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) |
5e681ec4 PB |
8927 | { |
8928 | if (!bfd_is_abs_section (p->section) | |
8929 | && bfd_is_abs_section (p->section->output_section)) | |
8930 | { | |
8931 | /* Input section has been discarded, either because | |
8932 | it is a copy of a linkonce section or due to | |
8933 | linker script /DISCARD/, so we'll be discarding | |
8934 | the relocs too. */ | |
8935 | } | |
8936 | else if (p->count != 0) | |
8937 | { | |
8938 | srel = elf_section_data (p->section)->sreloc; | |
00a97672 | 8939 | srel->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
8940 | if ((p->section->output_section->flags & SEC_READONLY) != 0) |
8941 | info->flags |= DF_TEXTREL; | |
8942 | } | |
8943 | } | |
8944 | } | |
8945 | ||
8946 | local_got = elf_local_got_refcounts (ibfd); | |
8947 | if (!local_got) | |
8948 | continue; | |
8949 | ||
8950 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
8951 | locsymcount = symtab_hdr->sh_info; | |
8952 | end_local_got = local_got + locsymcount; | |
ba93b8ac | 8953 | local_tls_type = elf32_arm_local_got_tls_type (ibfd); |
5e681ec4 PB |
8954 | s = htab->sgot; |
8955 | srel = htab->srelgot; | |
8956 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) | |
8957 | { | |
8958 | if (*local_got > 0) | |
8959 | { | |
eea6121a | 8960 | *local_got = s->size; |
ba93b8ac DJ |
8961 | if (*local_tls_type & GOT_TLS_GD) |
8962 | /* TLS_GD relocs need an 8-byte structure in the GOT. */ | |
8963 | s->size += 8; | |
8964 | if (*local_tls_type & GOT_TLS_IE) | |
8965 | s->size += 4; | |
8966 | if (*local_tls_type == GOT_NORMAL) | |
8967 | s->size += 4; | |
8968 | ||
8969 | if (info->shared || *local_tls_type == GOT_TLS_GD) | |
00a97672 | 8970 | srel->size += RELOC_SIZE (htab); |
5e681ec4 PB |
8971 | } |
8972 | else | |
8973 | *local_got = (bfd_vma) -1; | |
8974 | } | |
252b5132 RH |
8975 | } |
8976 | ||
ba93b8ac DJ |
8977 | if (htab->tls_ldm_got.refcount > 0) |
8978 | { | |
8979 | /* Allocate two GOT entries and one dynamic relocation (if necessary) | |
8980 | for R_ARM_TLS_LDM32 relocations. */ | |
8981 | htab->tls_ldm_got.offset = htab->sgot->size; | |
8982 | htab->sgot->size += 8; | |
8983 | if (info->shared) | |
00a97672 | 8984 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
8985 | } |
8986 | else | |
8987 | htab->tls_ldm_got.offset = -1; | |
8988 | ||
5e681ec4 PB |
8989 | /* Allocate global sym .plt and .got entries, and space for global |
8990 | sym dynamic relocs. */ | |
57e8b36a | 8991 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); |
252b5132 | 8992 | |
d504ffc8 DJ |
8993 | /* Here we rummage through the found bfds to collect glue information. */ |
8994 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
c7b8f16e JB |
8995 | { |
8996 | /* Initialise mapping tables for code/data. */ | |
8997 | bfd_elf32_arm_init_maps (ibfd); | |
8998 | ||
8999 | if (!bfd_elf32_arm_process_before_allocation (ibfd, info) | |
9000 | || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info)) | |
9001 | /* xgettext:c-format */ | |
9002 | _bfd_error_handler (_("Errors encountered processing file %s"), | |
9003 | ibfd->filename); | |
9004 | } | |
d504ffc8 | 9005 | |
252b5132 RH |
9006 | /* The check_relocs and adjust_dynamic_symbol entry points have |
9007 | determined the sizes of the various dynamic sections. Allocate | |
9008 | memory for them. */ | |
b34976b6 AM |
9009 | plt = FALSE; |
9010 | relocs = FALSE; | |
252b5132 RH |
9011 | for (s = dynobj->sections; s != NULL; s = s->next) |
9012 | { | |
9013 | const char * name; | |
252b5132 RH |
9014 | |
9015 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
9016 | continue; | |
9017 | ||
9018 | /* It's OK to base decisions on the section name, because none | |
9019 | of the dynobj section names depend upon the input files. */ | |
9020 | name = bfd_get_section_name (dynobj, s); | |
9021 | ||
24a1ba0f | 9022 | if (strcmp (name, ".plt") == 0) |
252b5132 | 9023 | { |
c456f082 AM |
9024 | /* Remember whether there is a PLT. */ |
9025 | plt = s->size != 0; | |
252b5132 | 9026 | } |
0112cd26 | 9027 | else if (CONST_STRNEQ (name, ".rel")) |
252b5132 | 9028 | { |
c456f082 | 9029 | if (s->size != 0) |
252b5132 | 9030 | { |
252b5132 | 9031 | /* Remember whether there are any reloc sections other |
00a97672 RS |
9032 | than .rel(a).plt and .rela.plt.unloaded. */ |
9033 | if (s != htab->srelplt && s != htab->srelplt2) | |
b34976b6 | 9034 | relocs = TRUE; |
252b5132 RH |
9035 | |
9036 | /* We use the reloc_count field as a counter if we need | |
9037 | to copy relocs into the output file. */ | |
9038 | s->reloc_count = 0; | |
9039 | } | |
9040 | } | |
0112cd26 | 9041 | else if (! CONST_STRNEQ (name, ".got") |
c456f082 | 9042 | && strcmp (name, ".dynbss") != 0) |
252b5132 RH |
9043 | { |
9044 | /* It's not one of our sections, so don't allocate space. */ | |
9045 | continue; | |
9046 | } | |
9047 | ||
c456f082 | 9048 | if (s->size == 0) |
252b5132 | 9049 | { |
c456f082 | 9050 | /* If we don't need this section, strip it from the |
00a97672 RS |
9051 | output file. This is mostly to handle .rel(a).bss and |
9052 | .rel(a).plt. We must create both sections in | |
c456f082 AM |
9053 | create_dynamic_sections, because they must be created |
9054 | before the linker maps input sections to output | |
9055 | sections. The linker does that before | |
9056 | adjust_dynamic_symbol is called, and it is that | |
9057 | function which decides whether anything needs to go | |
9058 | into these sections. */ | |
8423293d | 9059 | s->flags |= SEC_EXCLUDE; |
252b5132 RH |
9060 | continue; |
9061 | } | |
9062 | ||
c456f082 AM |
9063 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
9064 | continue; | |
9065 | ||
252b5132 | 9066 | /* Allocate memory for the section contents. */ |
eea6121a | 9067 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
c456f082 | 9068 | if (s->contents == NULL) |
b34976b6 | 9069 | return FALSE; |
252b5132 RH |
9070 | } |
9071 | ||
9072 | if (elf_hash_table (info)->dynamic_sections_created) | |
9073 | { | |
9074 | /* Add some entries to the .dynamic section. We fill in the | |
9075 | values later, in elf32_arm_finish_dynamic_sections, but we | |
9076 | must add the entries now so that we get the correct size for | |
9077 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
9078 | dynamic linker and used by the debugger. */ | |
dc810e39 | 9079 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 9080 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 9081 | |
8532796c | 9082 | if (info->executable) |
252b5132 | 9083 | { |
dc810e39 | 9084 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 9085 | return FALSE; |
252b5132 RH |
9086 | } |
9087 | ||
9088 | if (plt) | |
9089 | { | |
dc810e39 AM |
9090 | if ( !add_dynamic_entry (DT_PLTGOT, 0) |
9091 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
00a97672 RS |
9092 | || !add_dynamic_entry (DT_PLTREL, |
9093 | htab->use_rel ? DT_REL : DT_RELA) | |
dc810e39 | 9094 | || !add_dynamic_entry (DT_JMPREL, 0)) |
b34976b6 | 9095 | return FALSE; |
252b5132 RH |
9096 | } |
9097 | ||
9098 | if (relocs) | |
9099 | { | |
00a97672 RS |
9100 | if (htab->use_rel) |
9101 | { | |
9102 | if (!add_dynamic_entry (DT_REL, 0) | |
9103 | || !add_dynamic_entry (DT_RELSZ, 0) | |
9104 | || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab))) | |
9105 | return FALSE; | |
9106 | } | |
9107 | else | |
9108 | { | |
9109 | if (!add_dynamic_entry (DT_RELA, 0) | |
9110 | || !add_dynamic_entry (DT_RELASZ, 0) | |
9111 | || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab))) | |
9112 | return FALSE; | |
9113 | } | |
252b5132 RH |
9114 | } |
9115 | ||
08d1f311 DJ |
9116 | /* If any dynamic relocs apply to a read-only section, |
9117 | then we need a DT_TEXTREL entry. */ | |
9118 | if ((info->flags & DF_TEXTREL) == 0) | |
9119 | elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, | |
9120 | (PTR) info); | |
9121 | ||
99e4ae17 | 9122 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 9123 | { |
dc810e39 | 9124 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 9125 | return FALSE; |
252b5132 RH |
9126 | } |
9127 | } | |
8532796c | 9128 | #undef add_dynamic_entry |
252b5132 | 9129 | |
b34976b6 | 9130 | return TRUE; |
252b5132 RH |
9131 | } |
9132 | ||
252b5132 RH |
9133 | /* Finish up dynamic symbol handling. We set the contents of various |
9134 | dynamic sections here. */ | |
9135 | ||
b34976b6 | 9136 | static bfd_boolean |
57e8b36a NC |
9137 | elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, |
9138 | struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) | |
252b5132 RH |
9139 | { |
9140 | bfd * dynobj; | |
e5a52504 | 9141 | struct elf32_arm_link_hash_table *htab; |
b7693d02 | 9142 | struct elf32_arm_link_hash_entry *eh; |
252b5132 RH |
9143 | |
9144 | dynobj = elf_hash_table (info)->dynobj; | |
e5a52504 | 9145 | htab = elf32_arm_hash_table (info); |
b7693d02 | 9146 | eh = (struct elf32_arm_link_hash_entry *) h; |
252b5132 RH |
9147 | |
9148 | if (h->plt.offset != (bfd_vma) -1) | |
9149 | { | |
9150 | asection * splt; | |
252b5132 | 9151 | asection * srel; |
e5a52504 | 9152 | bfd_byte *loc; |
24a1ba0f | 9153 | bfd_vma plt_index; |
947216bf | 9154 | Elf_Internal_Rela rel; |
252b5132 RH |
9155 | |
9156 | /* This symbol has an entry in the procedure linkage table. Set | |
9157 | it up. */ | |
9158 | ||
9159 | BFD_ASSERT (h->dynindx != -1); | |
9160 | ||
9161 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 | 9162 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt")); |
e5a52504 | 9163 | BFD_ASSERT (splt != NULL && srel != NULL); |
252b5132 | 9164 | |
e5a52504 MM |
9165 | /* Fill in the entry in the procedure linkage table. */ |
9166 | if (htab->symbian_p) | |
9167 | { | |
52ab56c2 PB |
9168 | put_arm_insn (htab, output_bfd, |
9169 | elf32_arm_symbian_plt_entry[0], | |
9170 | splt->contents + h->plt.offset); | |
9171 | bfd_put_32 (output_bfd, | |
9172 | elf32_arm_symbian_plt_entry[1], | |
9173 | splt->contents + h->plt.offset + 4); | |
e5a52504 MM |
9174 | |
9175 | /* Fill in the entry in the .rel.plt section. */ | |
2a1b9a48 MM |
9176 | rel.r_offset = (splt->output_section->vma |
9177 | + splt->output_offset | |
52ab56c2 | 9178 | + h->plt.offset + 4); |
e5a52504 | 9179 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
b7693d02 DJ |
9180 | |
9181 | /* Get the index in the procedure linkage table which | |
9182 | corresponds to this symbol. This is the index of this symbol | |
9183 | in all the symbols for which we are making plt entries. The | |
9184 | first entry in the procedure linkage table is reserved. */ | |
9185 | plt_index = ((h->plt.offset - htab->plt_header_size) | |
9186 | / htab->plt_entry_size); | |
e5a52504 MM |
9187 | } |
9188 | else | |
9189 | { | |
00a97672 | 9190 | bfd_vma got_offset, got_address, plt_address; |
e5a52504 MM |
9191 | bfd_vma got_displacement; |
9192 | asection * sgot; | |
52ab56c2 | 9193 | bfd_byte * ptr; |
e5a52504 MM |
9194 | |
9195 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
9196 | BFD_ASSERT (sgot != NULL); | |
9197 | ||
b7693d02 DJ |
9198 | /* Get the offset into the .got.plt table of the entry that |
9199 | corresponds to this function. */ | |
9200 | got_offset = eh->plt_got_offset; | |
9201 | ||
9202 | /* Get the index in the procedure linkage table which | |
9203 | corresponds to this symbol. This is the index of this symbol | |
9204 | in all the symbols for which we are making plt entries. The | |
9205 | first three entries in .got.plt are reserved; after that | |
9206 | symbols appear in the same order as in .plt. */ | |
9207 | plt_index = (got_offset - 12) / 4; | |
e5a52504 | 9208 | |
00a97672 RS |
9209 | /* Calculate the address of the GOT entry. */ |
9210 | got_address = (sgot->output_section->vma | |
9211 | + sgot->output_offset | |
9212 | + got_offset); | |
5e681ec4 | 9213 | |
00a97672 RS |
9214 | /* ...and the address of the PLT entry. */ |
9215 | plt_address = (splt->output_section->vma | |
9216 | + splt->output_offset | |
9217 | + h->plt.offset); | |
5e681ec4 | 9218 | |
52ab56c2 | 9219 | ptr = htab->splt->contents + h->plt.offset; |
00a97672 RS |
9220 | if (htab->vxworks_p && info->shared) |
9221 | { | |
9222 | unsigned int i; | |
9223 | bfd_vma val; | |
9224 | ||
52ab56c2 | 9225 | for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4) |
00a97672 RS |
9226 | { |
9227 | val = elf32_arm_vxworks_shared_plt_entry[i]; | |
9228 | if (i == 2) | |
9229 | val |= got_address - sgot->output_section->vma; | |
9230 | if (i == 5) | |
9231 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
9232 | if (i == 2 || i == 5) |
9233 | bfd_put_32 (output_bfd, val, ptr); | |
9234 | else | |
9235 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
9236 | } |
9237 | } | |
9238 | else if (htab->vxworks_p) | |
b7693d02 | 9239 | { |
00a97672 RS |
9240 | unsigned int i; |
9241 | bfd_vma val; | |
9242 | ||
9243 | for (i = 0; i != htab->plt_entry_size / 4; i++) | |
9244 | { | |
9245 | val = elf32_arm_vxworks_exec_plt_entry[i]; | |
9246 | if (i == 2) | |
9247 | val |= got_address; | |
9248 | if (i == 4) | |
9249 | val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2); | |
9250 | if (i == 5) | |
9251 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
9252 | if (i == 2 || i == 5) |
9253 | bfd_put_32 (output_bfd, val, ptr); | |
9254 | else | |
9255 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
9256 | } |
9257 | ||
9258 | loc = (htab->srelplt2->contents | |
9259 | + (plt_index * 2 + 1) * RELOC_SIZE (htab)); | |
9260 | ||
9261 | /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation | |
9262 | referencing the GOT for this PLT entry. */ | |
9263 | rel.r_offset = plt_address + 8; | |
9264 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
9265 | rel.r_addend = got_offset; | |
9266 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
9267 | loc += RELOC_SIZE (htab); | |
9268 | ||
9269 | /* Create the R_ARM_ABS32 relocation referencing the | |
9270 | beginning of the PLT for this GOT entry. */ | |
9271 | rel.r_offset = got_address; | |
9272 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
9273 | rel.r_addend = 0; | |
9274 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
b7693d02 | 9275 | } |
00a97672 RS |
9276 | else |
9277 | { | |
9278 | /* Calculate the displacement between the PLT slot and the | |
9279 | entry in the GOT. The eight-byte offset accounts for the | |
9280 | value produced by adding to pc in the first instruction | |
9281 | of the PLT stub. */ | |
9282 | got_displacement = got_address - (plt_address + 8); | |
b7693d02 | 9283 | |
00a97672 RS |
9284 | BFD_ASSERT ((got_displacement & 0xf0000000) == 0); |
9285 | ||
9286 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) | |
9287 | { | |
52ab56c2 PB |
9288 | put_thumb_insn (htab, output_bfd, |
9289 | elf32_arm_plt_thumb_stub[0], ptr - 4); | |
9290 | put_thumb_insn (htab, output_bfd, | |
9291 | elf32_arm_plt_thumb_stub[1], ptr - 2); | |
00a97672 RS |
9292 | } |
9293 | ||
52ab56c2 PB |
9294 | put_arm_insn (htab, output_bfd, |
9295 | elf32_arm_plt_entry[0] | |
9296 | | ((got_displacement & 0x0ff00000) >> 20), | |
9297 | ptr + 0); | |
9298 | put_arm_insn (htab, output_bfd, | |
9299 | elf32_arm_plt_entry[1] | |
9300 | | ((got_displacement & 0x000ff000) >> 12), | |
9301 | ptr+ 4); | |
9302 | put_arm_insn (htab, output_bfd, | |
9303 | elf32_arm_plt_entry[2] | |
9304 | | (got_displacement & 0x00000fff), | |
9305 | ptr + 8); | |
5e681ec4 | 9306 | #ifdef FOUR_WORD_PLT |
52ab56c2 | 9307 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12); |
5e681ec4 | 9308 | #endif |
00a97672 | 9309 | } |
252b5132 | 9310 | |
e5a52504 MM |
9311 | /* Fill in the entry in the global offset table. */ |
9312 | bfd_put_32 (output_bfd, | |
9313 | (splt->output_section->vma | |
9314 | + splt->output_offset), | |
9315 | sgot->contents + got_offset); | |
9316 | ||
00a97672 RS |
9317 | /* Fill in the entry in the .rel(a).plt section. */ |
9318 | rel.r_addend = 0; | |
9319 | rel.r_offset = got_address; | |
e5a52504 MM |
9320 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); |
9321 | } | |
57e8b36a | 9322 | |
00a97672 RS |
9323 | loc = srel->contents + plt_index * RELOC_SIZE (htab); |
9324 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 | 9325 | |
f5385ebf | 9326 | if (!h->def_regular) |
252b5132 RH |
9327 | { |
9328 | /* Mark the symbol as undefined, rather than as defined in | |
9329 | the .plt section. Leave the value alone. */ | |
9330 | sym->st_shndx = SHN_UNDEF; | |
d982ba73 PB |
9331 | /* If the symbol is weak, we do need to clear the value. |
9332 | Otherwise, the PLT entry would provide a definition for | |
9333 | the symbol even if the symbol wasn't defined anywhere, | |
9334 | and so the symbol would never be NULL. */ | |
f5385ebf | 9335 | if (!h->ref_regular_nonweak) |
d982ba73 | 9336 | sym->st_value = 0; |
252b5132 RH |
9337 | } |
9338 | } | |
9339 | ||
ba93b8ac DJ |
9340 | if (h->got.offset != (bfd_vma) -1 |
9341 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 | |
9342 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) | |
252b5132 RH |
9343 | { |
9344 | asection * sgot; | |
9345 | asection * srel; | |
947216bf AM |
9346 | Elf_Internal_Rela rel; |
9347 | bfd_byte *loc; | |
00a97672 | 9348 | bfd_vma offset; |
252b5132 RH |
9349 | |
9350 | /* This symbol has an entry in the global offset table. Set it | |
9351 | up. */ | |
252b5132 | 9352 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
00a97672 | 9353 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got")); |
252b5132 RH |
9354 | BFD_ASSERT (sgot != NULL && srel != NULL); |
9355 | ||
00a97672 RS |
9356 | offset = (h->got.offset & ~(bfd_vma) 1); |
9357 | rel.r_addend = 0; | |
252b5132 RH |
9358 | rel.r_offset = (sgot->output_section->vma |
9359 | + sgot->output_offset | |
00a97672 | 9360 | + offset); |
252b5132 | 9361 | |
5e681ec4 PB |
9362 | /* If this is a static link, or it is a -Bsymbolic link and the |
9363 | symbol is defined locally or was forced to be local because | |
9364 | of a version file, we just want to emit a RELATIVE reloc. | |
9365 | The entry in the global offset table will already have been | |
9366 | initialized in the relocate_section function. */ | |
252b5132 | 9367 | if (info->shared |
5e681ec4 PB |
9368 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
9369 | { | |
9370 | BFD_ASSERT((h->got.offset & 1) != 0); | |
9371 | rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
00a97672 RS |
9372 | if (!htab->use_rel) |
9373 | { | |
9374 | rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset); | |
9375 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); | |
9376 | } | |
5e681ec4 | 9377 | } |
252b5132 RH |
9378 | else |
9379 | { | |
5e681ec4 | 9380 | BFD_ASSERT((h->got.offset & 1) == 0); |
00a97672 | 9381 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); |
252b5132 RH |
9382 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
9383 | } | |
9384 | ||
00a97672 RS |
9385 | loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab); |
9386 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
9387 | } |
9388 | ||
f5385ebf | 9389 | if (h->needs_copy) |
252b5132 RH |
9390 | { |
9391 | asection * s; | |
947216bf AM |
9392 | Elf_Internal_Rela rel; |
9393 | bfd_byte *loc; | |
252b5132 RH |
9394 | |
9395 | /* This symbol needs a copy reloc. Set it up. */ | |
252b5132 RH |
9396 | BFD_ASSERT (h->dynindx != -1 |
9397 | && (h->root.type == bfd_link_hash_defined | |
9398 | || h->root.type == bfd_link_hash_defweak)); | |
9399 | ||
9400 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
00a97672 | 9401 | RELOC_SECTION (htab, ".bss")); |
252b5132 RH |
9402 | BFD_ASSERT (s != NULL); |
9403 | ||
00a97672 | 9404 | rel.r_addend = 0; |
252b5132 RH |
9405 | rel.r_offset = (h->root.u.def.value |
9406 | + h->root.u.def.section->output_section->vma | |
9407 | + h->root.u.def.section->output_offset); | |
9408 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); | |
00a97672 RS |
9409 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); |
9410 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
9411 | } |
9412 | ||
00a97672 RS |
9413 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks, |
9414 | the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative | |
9415 | to the ".got" section. */ | |
252b5132 | 9416 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
00a97672 | 9417 | || (!htab->vxworks_p && h == htab->root.hgot)) |
252b5132 RH |
9418 | sym->st_shndx = SHN_ABS; |
9419 | ||
b34976b6 | 9420 | return TRUE; |
252b5132 RH |
9421 | } |
9422 | ||
9423 | /* Finish up the dynamic sections. */ | |
9424 | ||
b34976b6 | 9425 | static bfd_boolean |
57e8b36a | 9426 | elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) |
252b5132 RH |
9427 | { |
9428 | bfd * dynobj; | |
9429 | asection * sgot; | |
9430 | asection * sdyn; | |
9431 | ||
9432 | dynobj = elf_hash_table (info)->dynobj; | |
9433 | ||
9434 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
229fcec5 | 9435 | BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); |
252b5132 RH |
9436 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
9437 | ||
9438 | if (elf_hash_table (info)->dynamic_sections_created) | |
9439 | { | |
9440 | asection *splt; | |
9441 | Elf32_External_Dyn *dyncon, *dynconend; | |
229fcec5 | 9442 | struct elf32_arm_link_hash_table *htab; |
252b5132 | 9443 | |
229fcec5 | 9444 | htab = elf32_arm_hash_table (info); |
252b5132 | 9445 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
24a1ba0f | 9446 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
252b5132 RH |
9447 | |
9448 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 9449 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
9b485d32 | 9450 | |
252b5132 RH |
9451 | for (; dyncon < dynconend; dyncon++) |
9452 | { | |
9453 | Elf_Internal_Dyn dyn; | |
9454 | const char * name; | |
9455 | asection * s; | |
9456 | ||
9457 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
9458 | ||
9459 | switch (dyn.d_tag) | |
9460 | { | |
229fcec5 MM |
9461 | unsigned int type; |
9462 | ||
252b5132 RH |
9463 | default: |
9464 | break; | |
9465 | ||
229fcec5 MM |
9466 | case DT_HASH: |
9467 | name = ".hash"; | |
9468 | goto get_vma_if_bpabi; | |
9469 | case DT_STRTAB: | |
9470 | name = ".dynstr"; | |
9471 | goto get_vma_if_bpabi; | |
9472 | case DT_SYMTAB: | |
9473 | name = ".dynsym"; | |
9474 | goto get_vma_if_bpabi; | |
c0042f5d MM |
9475 | case DT_VERSYM: |
9476 | name = ".gnu.version"; | |
9477 | goto get_vma_if_bpabi; | |
9478 | case DT_VERDEF: | |
9479 | name = ".gnu.version_d"; | |
9480 | goto get_vma_if_bpabi; | |
9481 | case DT_VERNEED: | |
9482 | name = ".gnu.version_r"; | |
9483 | goto get_vma_if_bpabi; | |
9484 | ||
252b5132 RH |
9485 | case DT_PLTGOT: |
9486 | name = ".got"; | |
9487 | goto get_vma; | |
9488 | case DT_JMPREL: | |
00a97672 | 9489 | name = RELOC_SECTION (htab, ".plt"); |
252b5132 RH |
9490 | get_vma: |
9491 | s = bfd_get_section_by_name (output_bfd, name); | |
9492 | BFD_ASSERT (s != NULL); | |
229fcec5 MM |
9493 | if (!htab->symbian_p) |
9494 | dyn.d_un.d_ptr = s->vma; | |
9495 | else | |
9496 | /* In the BPABI, tags in the PT_DYNAMIC section point | |
9497 | at the file offset, not the memory address, for the | |
9498 | convenience of the post linker. */ | |
9499 | dyn.d_un.d_ptr = s->filepos; | |
252b5132 RH |
9500 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
9501 | break; | |
9502 | ||
229fcec5 MM |
9503 | get_vma_if_bpabi: |
9504 | if (htab->symbian_p) | |
9505 | goto get_vma; | |
9506 | break; | |
9507 | ||
252b5132 | 9508 | case DT_PLTRELSZ: |
00a97672 RS |
9509 | s = bfd_get_section_by_name (output_bfd, |
9510 | RELOC_SECTION (htab, ".plt")); | |
252b5132 | 9511 | BFD_ASSERT (s != NULL); |
eea6121a | 9512 | dyn.d_un.d_val = s->size; |
252b5132 RH |
9513 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
9514 | break; | |
229fcec5 | 9515 | |
252b5132 | 9516 | case DT_RELSZ: |
00a97672 | 9517 | case DT_RELASZ: |
229fcec5 MM |
9518 | if (!htab->symbian_p) |
9519 | { | |
9520 | /* My reading of the SVR4 ABI indicates that the | |
9521 | procedure linkage table relocs (DT_JMPREL) should be | |
9522 | included in the overall relocs (DT_REL). This is | |
9523 | what Solaris does. However, UnixWare can not handle | |
9524 | that case. Therefore, we override the DT_RELSZ entry | |
9525 | here to make it not include the JMPREL relocs. Since | |
00a97672 | 9526 | the linker script arranges for .rel(a).plt to follow all |
229fcec5 MM |
9527 | other relocation sections, we don't have to worry |
9528 | about changing the DT_REL entry. */ | |
00a97672 RS |
9529 | s = bfd_get_section_by_name (output_bfd, |
9530 | RELOC_SECTION (htab, ".plt")); | |
229fcec5 MM |
9531 | if (s != NULL) |
9532 | dyn.d_un.d_val -= s->size; | |
9533 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
9534 | break; | |
9535 | } | |
9536 | /* Fall through */ | |
9537 | ||
9538 | case DT_REL: | |
9539 | case DT_RELA: | |
229fcec5 MM |
9540 | /* In the BPABI, the DT_REL tag must point at the file |
9541 | offset, not the VMA, of the first relocation | |
9542 | section. So, we use code similar to that in | |
9543 | elflink.c, but do not check for SHF_ALLOC on the | |
9544 | relcoation section, since relocations sections are | |
9545 | never allocated under the BPABI. The comments above | |
9546 | about Unixware notwithstanding, we include all of the | |
9547 | relocations here. */ | |
9548 | if (htab->symbian_p) | |
9549 | { | |
9550 | unsigned int i; | |
9551 | type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) | |
9552 | ? SHT_REL : SHT_RELA); | |
9553 | dyn.d_un.d_val = 0; | |
9554 | for (i = 1; i < elf_numsections (output_bfd); i++) | |
9555 | { | |
9556 | Elf_Internal_Shdr *hdr | |
9557 | = elf_elfsections (output_bfd)[i]; | |
9558 | if (hdr->sh_type == type) | |
9559 | { | |
9560 | if (dyn.d_tag == DT_RELSZ | |
9561 | || dyn.d_tag == DT_RELASZ) | |
9562 | dyn.d_un.d_val += hdr->sh_size; | |
de52dba4 AM |
9563 | else if ((ufile_ptr) hdr->sh_offset |
9564 | <= dyn.d_un.d_val - 1) | |
229fcec5 MM |
9565 | dyn.d_un.d_val = hdr->sh_offset; |
9566 | } | |
9567 | } | |
9568 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
9569 | } | |
252b5132 | 9570 | break; |
88f7bcd5 NC |
9571 | |
9572 | /* Set the bottom bit of DT_INIT/FINI if the | |
9573 | corresponding function is Thumb. */ | |
9574 | case DT_INIT: | |
9575 | name = info->init_function; | |
9576 | goto get_sym; | |
9577 | case DT_FINI: | |
9578 | name = info->fini_function; | |
9579 | get_sym: | |
9580 | /* If it wasn't set by elf_bfd_final_link | |
4cc11e76 | 9581 | then there is nothing to adjust. */ |
88f7bcd5 NC |
9582 | if (dyn.d_un.d_val != 0) |
9583 | { | |
9584 | struct elf_link_hash_entry * eh; | |
9585 | ||
9586 | eh = elf_link_hash_lookup (elf_hash_table (info), name, | |
b34976b6 | 9587 | FALSE, FALSE, TRUE); |
88f7bcd5 NC |
9588 | if (eh != (struct elf_link_hash_entry *) NULL |
9589 | && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) | |
9590 | { | |
9591 | dyn.d_un.d_val |= 1; | |
b34976b6 | 9592 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
88f7bcd5 NC |
9593 | } |
9594 | } | |
9595 | break; | |
252b5132 RH |
9596 | } |
9597 | } | |
9598 | ||
24a1ba0f | 9599 | /* Fill in the first entry in the procedure linkage table. */ |
e5a52504 | 9600 | if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) |
f7a74f8c | 9601 | { |
00a97672 RS |
9602 | const bfd_vma *plt0_entry; |
9603 | bfd_vma got_address, plt_address, got_displacement; | |
9604 | ||
9605 | /* Calculate the addresses of the GOT and PLT. */ | |
9606 | got_address = sgot->output_section->vma + sgot->output_offset; | |
9607 | plt_address = splt->output_section->vma + splt->output_offset; | |
9608 | ||
9609 | if (htab->vxworks_p) | |
9610 | { | |
9611 | /* The VxWorks GOT is relocated by the dynamic linker. | |
9612 | Therefore, we must emit relocations rather than simply | |
9613 | computing the values now. */ | |
9614 | Elf_Internal_Rela rel; | |
9615 | ||
9616 | plt0_entry = elf32_arm_vxworks_exec_plt0_entry; | |
52ab56c2 PB |
9617 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
9618 | splt->contents + 0); | |
9619 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
9620 | splt->contents + 4); | |
9621 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
9622 | splt->contents + 8); | |
00a97672 RS |
9623 | bfd_put_32 (output_bfd, got_address, splt->contents + 12); |
9624 | ||
9625 | /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */ | |
9626 | rel.r_offset = plt_address + 12; | |
9627 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
9628 | rel.r_addend = 0; | |
9629 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, | |
9630 | htab->srelplt2->contents); | |
9631 | } | |
9632 | else | |
9633 | { | |
9634 | got_displacement = got_address - (plt_address + 16); | |
9635 | ||
9636 | plt0_entry = elf32_arm_plt0_entry; | |
52ab56c2 PB |
9637 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
9638 | splt->contents + 0); | |
9639 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
9640 | splt->contents + 4); | |
9641 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
9642 | splt->contents + 8); | |
9643 | put_arm_insn (htab, output_bfd, plt0_entry[3], | |
9644 | splt->contents + 12); | |
5e681ec4 | 9645 | |
5e681ec4 | 9646 | #ifdef FOUR_WORD_PLT |
00a97672 RS |
9647 | /* The displacement value goes in the otherwise-unused |
9648 | last word of the second entry. */ | |
9649 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); | |
5e681ec4 | 9650 | #else |
00a97672 | 9651 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); |
5e681ec4 | 9652 | #endif |
00a97672 | 9653 | } |
f7a74f8c | 9654 | } |
252b5132 RH |
9655 | |
9656 | /* UnixWare sets the entsize of .plt to 4, although that doesn't | |
9657 | really seem like the right value. */ | |
74541ad4 AM |
9658 | if (splt->output_section->owner == output_bfd) |
9659 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; | |
00a97672 RS |
9660 | |
9661 | if (htab->vxworks_p && !info->shared && htab->splt->size > 0) | |
9662 | { | |
9663 | /* Correct the .rel(a).plt.unloaded relocations. They will have | |
9664 | incorrect symbol indexes. */ | |
9665 | int num_plts; | |
eed62c48 | 9666 | unsigned char *p; |
00a97672 RS |
9667 | |
9668 | num_plts = ((htab->splt->size - htab->plt_header_size) | |
9669 | / htab->plt_entry_size); | |
9670 | p = htab->srelplt2->contents + RELOC_SIZE (htab); | |
9671 | ||
9672 | for (; num_plts; num_plts--) | |
9673 | { | |
9674 | Elf_Internal_Rela rel; | |
9675 | ||
9676 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
9677 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
9678 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
9679 | p += RELOC_SIZE (htab); | |
9680 | ||
9681 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
9682 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
9683 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
9684 | p += RELOC_SIZE (htab); | |
9685 | } | |
9686 | } | |
252b5132 RH |
9687 | } |
9688 | ||
9689 | /* Fill in the first three entries in the global offset table. */ | |
229fcec5 | 9690 | if (sgot) |
252b5132 | 9691 | { |
229fcec5 MM |
9692 | if (sgot->size > 0) |
9693 | { | |
9694 | if (sdyn == NULL) | |
9695 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
9696 | else | |
9697 | bfd_put_32 (output_bfd, | |
9698 | sdyn->output_section->vma + sdyn->output_offset, | |
9699 | sgot->contents); | |
9700 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
9701 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
9702 | } | |
252b5132 | 9703 | |
229fcec5 MM |
9704 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
9705 | } | |
252b5132 | 9706 | |
b34976b6 | 9707 | return TRUE; |
252b5132 RH |
9708 | } |
9709 | ||
ba96a88f | 9710 | static void |
57e8b36a | 9711 | elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) |
ba96a88f | 9712 | { |
9b485d32 | 9713 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ |
e489d0ae | 9714 | struct elf32_arm_link_hash_table *globals; |
ba96a88f NC |
9715 | |
9716 | i_ehdrp = elf_elfheader (abfd); | |
9717 | ||
94a3258f PB |
9718 | if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN) |
9719 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM; | |
9720 | else | |
9721 | i_ehdrp->e_ident[EI_OSABI] = 0; | |
ba96a88f | 9722 | i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION; |
e489d0ae | 9723 | |
93204d3a PB |
9724 | if (link_info) |
9725 | { | |
9726 | globals = elf32_arm_hash_table (link_info); | |
9727 | if (globals->byteswap_code) | |
9728 | i_ehdrp->e_flags |= EF_ARM_BE8; | |
9729 | } | |
ba96a88f NC |
9730 | } |
9731 | ||
99e4ae17 | 9732 | static enum elf_reloc_type_class |
57e8b36a | 9733 | elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) |
99e4ae17 | 9734 | { |
f51e552e | 9735 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
99e4ae17 AJ |
9736 | { |
9737 | case R_ARM_RELATIVE: | |
9738 | return reloc_class_relative; | |
9739 | case R_ARM_JUMP_SLOT: | |
9740 | return reloc_class_plt; | |
9741 | case R_ARM_COPY: | |
9742 | return reloc_class_copy; | |
9743 | default: | |
9744 | return reloc_class_normal; | |
9745 | } | |
9746 | } | |
9747 | ||
e16bb312 NC |
9748 | /* Set the right machine number for an Arm ELF file. */ |
9749 | ||
9750 | static bfd_boolean | |
57e8b36a | 9751 | elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) |
e16bb312 NC |
9752 | { |
9753 | if (hdr->sh_type == SHT_NOTE) | |
9754 | *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
9755 | ||
9756 | return TRUE; | |
9757 | } | |
9758 | ||
e489d0ae | 9759 | static void |
57e8b36a | 9760 | elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) |
e16bb312 | 9761 | { |
5a6c6817 | 9762 | bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); |
e16bb312 NC |
9763 | } |
9764 | ||
40a18ebd NC |
9765 | /* Return TRUE if this is an unwinding table entry. */ |
9766 | ||
9767 | static bfd_boolean | |
9768 | is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name) | |
9769 | { | |
0112cd26 NC |
9770 | return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind) |
9771 | || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once)); | |
40a18ebd NC |
9772 | } |
9773 | ||
9774 | ||
9775 | /* Set the type and flags for an ARM section. We do this by | |
9776 | the section name, which is a hack, but ought to work. */ | |
9777 | ||
9778 | static bfd_boolean | |
9779 | elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec) | |
9780 | { | |
9781 | const char * name; | |
9782 | ||
9783 | name = bfd_get_section_name (abfd, sec); | |
9784 | ||
9785 | if (is_arm_elf_unwind_section_name (abfd, name)) | |
9786 | { | |
9787 | hdr->sh_type = SHT_ARM_EXIDX; | |
9788 | hdr->sh_flags |= SHF_LINK_ORDER; | |
9789 | } | |
ee065d83 PB |
9790 | else if (strcmp(name, ".ARM.attributes") == 0) |
9791 | { | |
9792 | hdr->sh_type = SHT_ARM_ATTRIBUTES; | |
9793 | } | |
40a18ebd NC |
9794 | return TRUE; |
9795 | } | |
9796 | ||
ee065d83 PB |
9797 | /* Parse an Arm EABI attributes section. */ |
9798 | static void | |
9799 | elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) | |
9800 | { | |
9801 | bfd_byte *contents; | |
9802 | bfd_byte *p; | |
9803 | bfd_vma len; | |
9804 | ||
9805 | contents = bfd_malloc (hdr->sh_size); | |
9806 | if (!contents) | |
9807 | return; | |
9808 | if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0, | |
9809 | hdr->sh_size)) | |
9810 | { | |
9811 | free (contents); | |
9812 | return; | |
9813 | } | |
9814 | p = contents; | |
9815 | if (*(p++) == 'A') | |
9816 | { | |
9817 | len = hdr->sh_size - 1; | |
9818 | while (len > 0) | |
9819 | { | |
9820 | int namelen; | |
9821 | bfd_vma section_len; | |
9822 | ||
9823 | section_len = bfd_get_32 (abfd, p); | |
9824 | p += 4; | |
9825 | if (section_len > len) | |
9826 | section_len = len; | |
9827 | len -= section_len; | |
9828 | namelen = strlen ((char *)p) + 1; | |
9829 | section_len -= namelen + 4; | |
9830 | if (strcmp((char *)p, "aeabi") != 0) | |
9831 | { | |
9832 | /* Vendor section. Ignore it. */ | |
9833 | p += namelen + section_len; | |
9834 | } | |
9835 | else | |
9836 | { | |
9837 | p += namelen; | |
9838 | while (section_len > 0) | |
9839 | { | |
9840 | int tag; | |
9841 | unsigned int n; | |
9842 | unsigned int val; | |
9843 | bfd_vma subsection_len; | |
9844 | bfd_byte *end; | |
9845 | ||
9846 | tag = read_unsigned_leb128 (abfd, p, &n); | |
9847 | p += n; | |
9848 | subsection_len = bfd_get_32 (abfd, p); | |
9849 | p += 4; | |
9850 | if (subsection_len > section_len) | |
9851 | subsection_len = section_len; | |
9852 | section_len -= subsection_len; | |
9853 | subsection_len -= n + 4; | |
9854 | end = p + subsection_len; | |
9855 | switch (tag) | |
9856 | { | |
9857 | case Tag_File: | |
9858 | while (p < end) | |
9859 | { | |
9860 | bfd_boolean is_string; | |
9861 | ||
9862 | tag = read_unsigned_leb128 (abfd, p, &n); | |
9863 | p += n; | |
9864 | if (tag == 4 || tag == 5) | |
9865 | is_string = 1; | |
9866 | else if (tag < 32) | |
9867 | is_string = 0; | |
9868 | else | |
9869 | is_string = (tag & 1) != 0; | |
9870 | if (tag == Tag_compatibility) | |
9871 | { | |
9872 | val = read_unsigned_leb128 (abfd, p, &n); | |
9873 | p += n; | |
9874 | elf32_arm_add_eabi_attr_compat (abfd, val, | |
9875 | (char *)p); | |
9876 | p += strlen ((char *)p) + 1; | |
9877 | } | |
9878 | else if (is_string) | |
9879 | { | |
9880 | elf32_arm_add_eabi_attr_string (abfd, tag, | |
9881 | (char *)p); | |
9882 | p += strlen ((char *)p) + 1; | |
9883 | } | |
9884 | else | |
9885 | { | |
9886 | val = read_unsigned_leb128 (abfd, p, &n); | |
9887 | p += n; | |
9888 | elf32_arm_add_eabi_attr_int (abfd, tag, val); | |
9889 | } | |
9890 | } | |
9891 | break; | |
9892 | case Tag_Section: | |
9893 | case Tag_Symbol: | |
9894 | /* Don't have anywhere convenient to attach these. | |
9895 | Fall through for now. */ | |
9896 | default: | |
9897 | /* Ignore things we don't kow about. */ | |
9898 | p += subsection_len; | |
9899 | subsection_len = 0; | |
9900 | break; | |
9901 | } | |
9902 | } | |
9903 | } | |
9904 | } | |
9905 | } | |
9906 | free (contents); | |
9907 | } | |
9908 | ||
6dc132d9 L |
9909 | /* Handle an ARM specific section when reading an object file. This is |
9910 | called when bfd_section_from_shdr finds a section with an unknown | |
9911 | type. */ | |
40a18ebd NC |
9912 | |
9913 | static bfd_boolean | |
9914 | elf32_arm_section_from_shdr (bfd *abfd, | |
9915 | Elf_Internal_Shdr * hdr, | |
6dc132d9 L |
9916 | const char *name, |
9917 | int shindex) | |
40a18ebd NC |
9918 | { |
9919 | /* There ought to be a place to keep ELF backend specific flags, but | |
9920 | at the moment there isn't one. We just keep track of the | |
9921 | sections by their name, instead. Fortunately, the ABI gives | |
9922 | names for all the ARM specific sections, so we will probably get | |
9923 | away with this. */ | |
9924 | switch (hdr->sh_type) | |
9925 | { | |
9926 | case SHT_ARM_EXIDX: | |
0951f019 RE |
9927 | case SHT_ARM_PREEMPTMAP: |
9928 | case SHT_ARM_ATTRIBUTES: | |
40a18ebd NC |
9929 | break; |
9930 | ||
9931 | default: | |
9932 | return FALSE; | |
9933 | } | |
9934 | ||
6dc132d9 | 9935 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
40a18ebd NC |
9936 | return FALSE; |
9937 | ||
ee065d83 PB |
9938 | if (hdr->sh_type == SHT_ARM_ATTRIBUTES) |
9939 | elf32_arm_parse_attributes(abfd, hdr); | |
40a18ebd NC |
9940 | return TRUE; |
9941 | } | |
e489d0ae | 9942 | |
8e3de13a NC |
9943 | /* A structure used to record a list of sections, independently |
9944 | of the next and prev fields in the asection structure. */ | |
9945 | typedef struct section_list | |
9946 | { | |
9947 | asection * sec; | |
9948 | struct section_list * next; | |
9949 | struct section_list * prev; | |
9950 | } | |
9951 | section_list; | |
9952 | ||
9953 | /* Unfortunately we need to keep a list of sections for which | |
9954 | an _arm_elf_section_data structure has been allocated. This | |
9955 | is because it is possible for functions like elf32_arm_write_section | |
9956 | to be called on a section which has had an elf_data_structure | |
9957 | allocated for it (and so the used_by_bfd field is valid) but | |
9958 | for which the ARM extended version of this structure - the | |
9959 | _arm_elf_section_data structure - has not been allocated. */ | |
9960 | static section_list * sections_with_arm_elf_section_data = NULL; | |
9961 | ||
9962 | static void | |
957c6e41 | 9963 | record_section_with_arm_elf_section_data (asection * sec) |
8e3de13a NC |
9964 | { |
9965 | struct section_list * entry; | |
9966 | ||
957c6e41 | 9967 | entry = bfd_malloc (sizeof (* entry)); |
8e3de13a NC |
9968 | if (entry == NULL) |
9969 | return; | |
9970 | entry->sec = sec; | |
9971 | entry->next = sections_with_arm_elf_section_data; | |
9972 | entry->prev = NULL; | |
9973 | if (entry->next != NULL) | |
9974 | entry->next->prev = entry; | |
9975 | sections_with_arm_elf_section_data = entry; | |
9976 | } | |
9977 | ||
44444f50 NC |
9978 | static struct section_list * |
9979 | find_arm_elf_section_entry (asection * sec) | |
8e3de13a NC |
9980 | { |
9981 | struct section_list * entry; | |
bd4aae00 | 9982 | static struct section_list * last_entry = NULL; |
8e3de13a | 9983 | |
bd4aae00 NC |
9984 | /* This is a short cut for the typical case where the sections are added |
9985 | to the sections_with_arm_elf_section_data list in forward order and | |
9986 | then looked up here in backwards order. This makes a real difference | |
9987 | to the ld-srec/sec64k.exp linker test. */ | |
44444f50 | 9988 | entry = sections_with_arm_elf_section_data; |
bd4aae00 NC |
9989 | if (last_entry != NULL) |
9990 | { | |
9991 | if (last_entry->sec == sec) | |
44444f50 NC |
9992 | entry = last_entry; |
9993 | else if (last_entry->next != NULL | |
9994 | && last_entry->next->sec == sec) | |
9995 | entry = last_entry->next; | |
bd4aae00 | 9996 | } |
44444f50 NC |
9997 | |
9998 | for (; entry; entry = entry->next) | |
8e3de13a | 9999 | if (entry->sec == sec) |
44444f50 | 10000 | break; |
bd4aae00 | 10001 | |
44444f50 NC |
10002 | if (entry) |
10003 | /* Record the entry prior to this one - it is the entry we are most | |
10004 | likely to want to locate next time. Also this way if we have been | |
10005 | called from unrecord_section_with_arm_elf_section_data() we will not | |
10006 | be caching a pointer that is about to be freed. */ | |
10007 | last_entry = entry->prev; | |
10008 | ||
10009 | return entry; | |
10010 | } | |
10011 | ||
10012 | static _arm_elf_section_data * | |
10013 | get_arm_elf_section_data (asection * sec) | |
10014 | { | |
10015 | struct section_list * entry; | |
10016 | ||
10017 | entry = find_arm_elf_section_entry (sec); | |
10018 | ||
10019 | if (entry) | |
10020 | return elf32_arm_section_data (entry->sec); | |
10021 | else | |
10022 | return NULL; | |
8e3de13a NC |
10023 | } |
10024 | ||
10025 | static void | |
10026 | unrecord_section_with_arm_elf_section_data (asection * sec) | |
10027 | { | |
10028 | struct section_list * entry; | |
10029 | ||
44444f50 NC |
10030 | entry = find_arm_elf_section_entry (sec); |
10031 | ||
10032 | if (entry) | |
10033 | { | |
10034 | if (entry->prev != NULL) | |
10035 | entry->prev->next = entry->next; | |
10036 | if (entry->next != NULL) | |
10037 | entry->next->prev = entry->prev; | |
10038 | if (entry == sections_with_arm_elf_section_data) | |
10039 | sections_with_arm_elf_section_data = entry->next; | |
10040 | free (entry); | |
10041 | } | |
8e3de13a NC |
10042 | } |
10043 | ||
e489d0ae | 10044 | |
4e617b1e PB |
10045 | typedef struct |
10046 | { | |
10047 | void *finfo; | |
10048 | struct bfd_link_info *info; | |
10049 | int plt_shndx; | |
10050 | bfd_vma plt_offset; | |
10051 | bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *, | |
10052 | asection *, struct elf_link_hash_entry *); | |
10053 | } output_arch_syminfo; | |
10054 | ||
10055 | enum map_symbol_type | |
10056 | { | |
10057 | ARM_MAP_ARM, | |
10058 | ARM_MAP_THUMB, | |
10059 | ARM_MAP_DATA | |
10060 | }; | |
10061 | ||
10062 | ||
10063 | /* Output a single PLT mapping symbol. */ | |
10064 | ||
10065 | static bfd_boolean | |
10066 | elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi, | |
10067 | enum map_symbol_type type, | |
10068 | bfd_vma offset) | |
10069 | { | |
10070 | static const char *names[3] = {"$a", "$t", "$d"}; | |
10071 | struct elf32_arm_link_hash_table *htab; | |
10072 | Elf_Internal_Sym sym; | |
10073 | ||
10074 | htab = elf32_arm_hash_table (osi->info); | |
10075 | sym.st_value = osi->plt_offset + offset; | |
10076 | sym.st_size = 0; | |
10077 | sym.st_other = 0; | |
10078 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
10079 | sym.st_shndx = osi->plt_shndx; | |
10080 | if (!osi->func (osi->finfo, names[type], &sym, htab->splt, NULL)) | |
10081 | return FALSE; | |
10082 | return TRUE; | |
10083 | } | |
10084 | ||
10085 | ||
10086 | /* Output mapping symbols for PLT entries associated with H. */ | |
10087 | ||
10088 | static bfd_boolean | |
10089 | elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf) | |
10090 | { | |
10091 | output_arch_syminfo *osi = (output_arch_syminfo *) inf; | |
10092 | struct elf32_arm_link_hash_table *htab; | |
10093 | struct elf32_arm_link_hash_entry *eh; | |
10094 | bfd_vma addr; | |
10095 | ||
10096 | htab = elf32_arm_hash_table (osi->info); | |
10097 | ||
10098 | if (h->root.type == bfd_link_hash_indirect) | |
10099 | return TRUE; | |
10100 | ||
10101 | if (h->root.type == bfd_link_hash_warning) | |
10102 | /* When warning symbols are created, they **replace** the "real" | |
10103 | entry in the hash table, thus we never get to see the real | |
10104 | symbol in a hash traversal. So look at it now. */ | |
10105 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
10106 | ||
10107 | if (h->plt.offset == (bfd_vma) -1) | |
10108 | return TRUE; | |
10109 | ||
10110 | eh = (struct elf32_arm_link_hash_entry *) h; | |
10111 | addr = h->plt.offset; | |
10112 | if (htab->symbian_p) | |
10113 | { | |
10114 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
10115 | return FALSE; | |
10116 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4)) | |
10117 | return FALSE; | |
10118 | } | |
10119 | else if (htab->vxworks_p) | |
10120 | { | |
10121 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
10122 | return FALSE; | |
10123 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8)) | |
10124 | return FALSE; | |
10125 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12)) | |
10126 | return FALSE; | |
10127 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20)) | |
10128 | return FALSE; | |
10129 | } | |
10130 | else | |
10131 | { | |
10132 | bfd_boolean thumb_stub; | |
10133 | ||
10134 | thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx; | |
10135 | if (thumb_stub) | |
10136 | { | |
10137 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4)) | |
10138 | return FALSE; | |
10139 | } | |
10140 | #ifdef FOUR_WORD_PLT | |
10141 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
10142 | return FALSE; | |
10143 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12)) | |
10144 | return FALSE; | |
10145 | #else | |
10146 | /* A three-word PLT with no Thumb thunk contains only Arm code, | |
10147 | so only need to output a mapping symbol for the first PLT entry and | |
10148 | entries with thumb thunks. */ | |
10149 | if (thumb_stub || addr == 20) | |
10150 | { | |
10151 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
10152 | return FALSE; | |
10153 | } | |
10154 | #endif | |
10155 | } | |
10156 | ||
10157 | return TRUE; | |
10158 | } | |
10159 | ||
10160 | ||
10161 | /* Output mapping symbols for the PLT. */ | |
10162 | ||
10163 | static bfd_boolean | |
10164 | elf32_arm_output_arch_local_syms (bfd *output_bfd, | |
10165 | struct bfd_link_info *info, | |
10166 | void *finfo, bfd_boolean (*func) (void *, const char *, | |
10167 | Elf_Internal_Sym *, | |
10168 | asection *, | |
10169 | struct elf_link_hash_entry *)) | |
10170 | { | |
10171 | output_arch_syminfo osi; | |
10172 | struct elf32_arm_link_hash_table *htab; | |
10173 | ||
10174 | htab = elf32_arm_hash_table (info); | |
10175 | if (!htab->splt || htab->splt->size == 0) | |
10176 | return TRUE; | |
10177 | ||
10178 | check_use_blx(htab); | |
10179 | osi.finfo = finfo; | |
10180 | osi.info = info; | |
10181 | osi.func = func; | |
10182 | osi.plt_shndx = _bfd_elf_section_from_bfd_section (output_bfd, | |
10183 | htab->splt->output_section); | |
10184 | osi.plt_offset = htab->splt->output_section->vma; | |
10185 | ||
10186 | /* Output mapping symbols for the plt header. SymbianOS does not have a | |
10187 | plt header. */ | |
10188 | if (htab->vxworks_p) | |
10189 | { | |
10190 | /* VxWorks shared libraries have no PLT header. */ | |
10191 | if (!info->shared) | |
10192 | { | |
10193 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
10194 | return FALSE; | |
10195 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12)) | |
10196 | return FALSE; | |
10197 | } | |
10198 | } | |
10199 | else if (!htab->symbian_p) | |
10200 | { | |
10201 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
10202 | return FALSE; | |
10203 | #ifndef FOUR_WORD_PLT | |
10204 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16)) | |
10205 | return FALSE; | |
10206 | #endif | |
10207 | } | |
10208 | ||
10209 | elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi); | |
10210 | return TRUE; | |
10211 | } | |
10212 | ||
e489d0ae PB |
10213 | /* Allocate target specific section data. */ |
10214 | ||
10215 | static bfd_boolean | |
10216 | elf32_arm_new_section_hook (bfd *abfd, asection *sec) | |
10217 | { | |
f592407e AM |
10218 | if (!sec->used_by_bfd) |
10219 | { | |
10220 | _arm_elf_section_data *sdata; | |
10221 | bfd_size_type amt = sizeof (*sdata); | |
e489d0ae | 10222 | |
f592407e AM |
10223 | sdata = bfd_zalloc (abfd, amt); |
10224 | if (sdata == NULL) | |
10225 | return FALSE; | |
10226 | sec->used_by_bfd = sdata; | |
10227 | } | |
e489d0ae | 10228 | |
957c6e41 | 10229 | record_section_with_arm_elf_section_data (sec); |
8e3de13a | 10230 | |
e489d0ae PB |
10231 | return _bfd_elf_new_section_hook (abfd, sec); |
10232 | } | |
10233 | ||
10234 | ||
10235 | /* Used to order a list of mapping symbols by address. */ | |
10236 | ||
10237 | static int | |
10238 | elf32_arm_compare_mapping (const void * a, const void * b) | |
10239 | { | |
10240 | return ((const elf32_arm_section_map *) a)->vma | |
10241 | > ((const elf32_arm_section_map *) b)->vma; | |
10242 | } | |
10243 | ||
10244 | ||
10245 | /* Do code byteswapping. Return FALSE afterwards so that the section is | |
10246 | written out as normal. */ | |
10247 | ||
10248 | static bfd_boolean | |
c7b8f16e JB |
10249 | elf32_arm_write_section (bfd *output_bfd, |
10250 | struct bfd_link_info *link_info, asection *sec, | |
e489d0ae PB |
10251 | bfd_byte *contents) |
10252 | { | |
c7b8f16e | 10253 | int mapcount, errcount; |
8e3de13a | 10254 | _arm_elf_section_data *arm_data; |
c7b8f16e | 10255 | struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); |
e489d0ae | 10256 | elf32_arm_section_map *map; |
c7b8f16e | 10257 | elf32_vfp11_erratum_list *errnode; |
e489d0ae PB |
10258 | bfd_vma ptr; |
10259 | bfd_vma end; | |
c7b8f16e | 10260 | bfd_vma offset = sec->output_section->vma + sec->output_offset; |
e489d0ae PB |
10261 | bfd_byte tmp; |
10262 | int i; | |
57e8b36a | 10263 | |
8e3de13a NC |
10264 | /* If this section has not been allocated an _arm_elf_section_data |
10265 | structure then we cannot record anything. */ | |
10266 | arm_data = get_arm_elf_section_data (sec); | |
10267 | if (arm_data == NULL) | |
10268 | return FALSE; | |
10269 | ||
10270 | mapcount = arm_data->mapcount; | |
10271 | map = arm_data->map; | |
c7b8f16e JB |
10272 | errcount = arm_data->erratumcount; |
10273 | ||
10274 | if (errcount != 0) | |
10275 | { | |
10276 | unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0; | |
10277 | ||
10278 | for (errnode = arm_data->erratumlist; errnode != 0; | |
10279 | errnode = errnode->next) | |
10280 | { | |
10281 | bfd_vma index = errnode->vma - offset; | |
10282 | ||
10283 | switch (errnode->type) | |
10284 | { | |
10285 | case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER: | |
10286 | { | |
10287 | bfd_vma branch_to_veneer; | |
10288 | /* Original condition code of instruction, plus bit mask for | |
10289 | ARM B instruction. */ | |
10290 | unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000) | |
10291 | | 0x0a000000; | |
10292 | ||
10293 | /* The instruction is before the label. */ | |
10294 | index -= 4; | |
10295 | ||
10296 | /* Above offset included in -4 below. */ | |
10297 | branch_to_veneer = errnode->u.b.veneer->vma | |
10298 | - errnode->vma - 4; | |
10299 | ||
10300 | if ((signed) branch_to_veneer < -(1 << 25) | |
10301 | || (signed) branch_to_veneer >= (1 << 25)) | |
10302 | (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of " | |
10303 | "range"), output_bfd); | |
10304 | ||
10305 | insn |= (branch_to_veneer >> 2) & 0xffffff; | |
10306 | contents[endianflip ^ index] = insn & 0xff; | |
10307 | contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff; | |
10308 | contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff; | |
10309 | contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff; | |
10310 | } | |
10311 | break; | |
10312 | ||
10313 | case VFP11_ERRATUM_ARM_VENEER: | |
10314 | { | |
10315 | bfd_vma branch_from_veneer; | |
10316 | unsigned int insn; | |
10317 | ||
10318 | /* Take size of veneer into account. */ | |
10319 | branch_from_veneer = errnode->u.v.branch->vma | |
10320 | - errnode->vma - 12; | |
10321 | ||
10322 | if ((signed) branch_from_veneer < -(1 << 25) | |
10323 | || (signed) branch_from_veneer >= (1 << 25)) | |
10324 | (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of " | |
10325 | "range"), output_bfd); | |
10326 | ||
10327 | /* Original instruction. */ | |
10328 | insn = errnode->u.v.branch->u.b.vfp_insn; | |
10329 | contents[endianflip ^ index] = insn & 0xff; | |
10330 | contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff; | |
10331 | contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff; | |
10332 | contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff; | |
10333 | ||
10334 | /* Branch back to insn after original insn. */ | |
10335 | insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff); | |
10336 | contents[endianflip ^ (index + 4)] = insn & 0xff; | |
10337 | contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff; | |
10338 | contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff; | |
10339 | contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff; | |
10340 | } | |
10341 | break; | |
10342 | ||
10343 | default: | |
10344 | abort (); | |
10345 | } | |
10346 | } | |
10347 | } | |
e489d0ae PB |
10348 | |
10349 | if (mapcount == 0) | |
10350 | return FALSE; | |
10351 | ||
c7b8f16e | 10352 | if (globals->byteswap_code) |
e489d0ae | 10353 | { |
c7b8f16e | 10354 | qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping); |
57e8b36a | 10355 | |
c7b8f16e JB |
10356 | ptr = map[0].vma; |
10357 | for (i = 0; i < mapcount; i++) | |
10358 | { | |
10359 | if (i == mapcount - 1) | |
10360 | end = sec->size; | |
10361 | else | |
10362 | end = map[i + 1].vma; | |
e489d0ae | 10363 | |
c7b8f16e | 10364 | switch (map[i].type) |
e489d0ae | 10365 | { |
c7b8f16e JB |
10366 | case 'a': |
10367 | /* Byte swap code words. */ | |
10368 | while (ptr + 3 < end) | |
10369 | { | |
10370 | tmp = contents[ptr]; | |
10371 | contents[ptr] = contents[ptr + 3]; | |
10372 | contents[ptr + 3] = tmp; | |
10373 | tmp = contents[ptr + 1]; | |
10374 | contents[ptr + 1] = contents[ptr + 2]; | |
10375 | contents[ptr + 2] = tmp; | |
10376 | ptr += 4; | |
10377 | } | |
10378 | break; | |
e489d0ae | 10379 | |
c7b8f16e JB |
10380 | case 't': |
10381 | /* Byte swap code halfwords. */ | |
10382 | while (ptr + 1 < end) | |
10383 | { | |
10384 | tmp = contents[ptr]; | |
10385 | contents[ptr] = contents[ptr + 1]; | |
10386 | contents[ptr + 1] = tmp; | |
10387 | ptr += 2; | |
10388 | } | |
10389 | break; | |
10390 | ||
10391 | case 'd': | |
10392 | /* Leave data alone. */ | |
10393 | break; | |
10394 | } | |
10395 | ptr = end; | |
10396 | } | |
e489d0ae | 10397 | } |
8e3de13a | 10398 | |
93204d3a | 10399 | free (map); |
8e3de13a | 10400 | arm_data->mapcount = 0; |
c7b8f16e | 10401 | arm_data->mapsize = 0; |
8e3de13a NC |
10402 | arm_data->map = NULL; |
10403 | unrecord_section_with_arm_elf_section_data (sec); | |
10404 | ||
e489d0ae PB |
10405 | return FALSE; |
10406 | } | |
10407 | ||
957c6e41 NC |
10408 | static void |
10409 | unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED, | |
10410 | asection * sec, | |
10411 | void * ignore ATTRIBUTE_UNUSED) | |
10412 | { | |
10413 | unrecord_section_with_arm_elf_section_data (sec); | |
10414 | } | |
10415 | ||
10416 | static bfd_boolean | |
10417 | elf32_arm_close_and_cleanup (bfd * abfd) | |
10418 | { | |
b25e3d87 L |
10419 | if (abfd->sections) |
10420 | bfd_map_over_sections (abfd, | |
10421 | unrecord_section_via_map_over_sections, | |
10422 | NULL); | |
957c6e41 NC |
10423 | |
10424 | return _bfd_elf_close_and_cleanup (abfd); | |
10425 | } | |
10426 | ||
b25e3d87 L |
10427 | static bfd_boolean |
10428 | elf32_arm_bfd_free_cached_info (bfd * abfd) | |
10429 | { | |
10430 | if (abfd->sections) | |
10431 | bfd_map_over_sections (abfd, | |
10432 | unrecord_section_via_map_over_sections, | |
10433 | NULL); | |
10434 | ||
10435 | return _bfd_free_cached_info (abfd); | |
10436 | } | |
10437 | ||
b7693d02 DJ |
10438 | /* Display STT_ARM_TFUNC symbols as functions. */ |
10439 | ||
10440 | static void | |
10441 | elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
10442 | asymbol *asym) | |
10443 | { | |
10444 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; | |
10445 | ||
10446 | if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC) | |
10447 | elfsym->symbol.flags |= BSF_FUNCTION; | |
10448 | } | |
10449 | ||
0beaef2b PB |
10450 | |
10451 | /* Mangle thumb function symbols as we read them in. */ | |
10452 | ||
8384fb8f | 10453 | static bfd_boolean |
0beaef2b PB |
10454 | elf32_arm_swap_symbol_in (bfd * abfd, |
10455 | const void *psrc, | |
10456 | const void *pshn, | |
10457 | Elf_Internal_Sym *dst) | |
10458 | { | |
8384fb8f AM |
10459 | if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst)) |
10460 | return FALSE; | |
0beaef2b PB |
10461 | |
10462 | /* New EABI objects mark thumb function symbols by setting the low bit of | |
10463 | the address. Turn these into STT_ARM_TFUNC. */ | |
10464 | if (ELF_ST_TYPE (dst->st_info) == STT_FUNC | |
10465 | && (dst->st_value & 1)) | |
10466 | { | |
10467 | dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); | |
10468 | dst->st_value &= ~(bfd_vma) 1; | |
10469 | } | |
8384fb8f | 10470 | return TRUE; |
0beaef2b PB |
10471 | } |
10472 | ||
10473 | ||
10474 | /* Mangle thumb function symbols as we write them out. */ | |
10475 | ||
10476 | static void | |
10477 | elf32_arm_swap_symbol_out (bfd *abfd, | |
10478 | const Elf_Internal_Sym *src, | |
10479 | void *cdst, | |
10480 | void *shndx) | |
10481 | { | |
10482 | Elf_Internal_Sym newsym; | |
10483 | ||
10484 | /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit | |
10485 | of the address set, as per the new EABI. We do this unconditionally | |
10486 | because objcopy does not set the elf header flags until after | |
10487 | it writes out the symbol table. */ | |
10488 | if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) | |
10489 | { | |
10490 | newsym = *src; | |
10491 | newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); | |
0fa3dcad PB |
10492 | if (newsym.st_shndx != SHN_UNDEF) |
10493 | { | |
10494 | /* Do this only for defined symbols. At link type, the static | |
10495 | linker will simulate the work of dynamic linker of resolving | |
10496 | symbols and will carry over the thumbness of found symbols to | |
10497 | the output symbol table. It's not clear how it happens, but | |
b0fead2b | 10498 | the thumbness of undefined symbols can well be different at |
0fa3dcad PB |
10499 | runtime, and writing '1' for them will be confusing for users |
10500 | and possibly for dynamic linker itself. | |
10501 | */ | |
10502 | newsym.st_value |= 1; | |
10503 | } | |
0beaef2b PB |
10504 | |
10505 | src = &newsym; | |
10506 | } | |
10507 | bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); | |
10508 | } | |
10509 | ||
b294bdf8 MM |
10510 | /* Add the PT_ARM_EXIDX program header. */ |
10511 | ||
10512 | static bfd_boolean | |
10513 | elf32_arm_modify_segment_map (bfd *abfd, | |
10514 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
10515 | { | |
10516 | struct elf_segment_map *m; | |
10517 | asection *sec; | |
10518 | ||
10519 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
10520 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
10521 | { | |
10522 | /* If there is already a PT_ARM_EXIDX header, then we do not | |
10523 | want to add another one. This situation arises when running | |
10524 | "strip"; the input binary already has the header. */ | |
10525 | m = elf_tdata (abfd)->segment_map; | |
10526 | while (m && m->p_type != PT_ARM_EXIDX) | |
10527 | m = m->next; | |
10528 | if (!m) | |
10529 | { | |
10530 | m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); | |
10531 | if (m == NULL) | |
10532 | return FALSE; | |
10533 | m->p_type = PT_ARM_EXIDX; | |
10534 | m->count = 1; | |
10535 | m->sections[0] = sec; | |
10536 | ||
10537 | m->next = elf_tdata (abfd)->segment_map; | |
10538 | elf_tdata (abfd)->segment_map = m; | |
10539 | } | |
10540 | } | |
10541 | ||
10542 | return TRUE; | |
10543 | } | |
10544 | ||
10545 | /* We may add a PT_ARM_EXIDX program header. */ | |
10546 | ||
10547 | static int | |
a6b96beb AM |
10548 | elf32_arm_additional_program_headers (bfd *abfd, |
10549 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
b294bdf8 MM |
10550 | { |
10551 | asection *sec; | |
10552 | ||
10553 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
10554 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
10555 | return 1; | |
10556 | else | |
10557 | return 0; | |
10558 | } | |
10559 | ||
0beaef2b PB |
10560 | /* We use this to override swap_symbol_in and swap_symbol_out. */ |
10561 | const struct elf_size_info elf32_arm_size_info = { | |
10562 | sizeof (Elf32_External_Ehdr), | |
10563 | sizeof (Elf32_External_Phdr), | |
10564 | sizeof (Elf32_External_Shdr), | |
10565 | sizeof (Elf32_External_Rel), | |
10566 | sizeof (Elf32_External_Rela), | |
10567 | sizeof (Elf32_External_Sym), | |
10568 | sizeof (Elf32_External_Dyn), | |
10569 | sizeof (Elf_External_Note), | |
10570 | 4, | |
10571 | 1, | |
10572 | 32, 2, | |
10573 | ELFCLASS32, EV_CURRENT, | |
10574 | bfd_elf32_write_out_phdrs, | |
10575 | bfd_elf32_write_shdrs_and_ehdr, | |
10576 | bfd_elf32_write_relocs, | |
10577 | elf32_arm_swap_symbol_in, | |
10578 | elf32_arm_swap_symbol_out, | |
10579 | bfd_elf32_slurp_reloc_table, | |
10580 | bfd_elf32_slurp_symbol_table, | |
10581 | bfd_elf32_swap_dyn_in, | |
10582 | bfd_elf32_swap_dyn_out, | |
10583 | bfd_elf32_swap_reloc_in, | |
10584 | bfd_elf32_swap_reloc_out, | |
10585 | bfd_elf32_swap_reloca_in, | |
10586 | bfd_elf32_swap_reloca_out | |
10587 | }; | |
10588 | ||
252b5132 RH |
10589 | #define ELF_ARCH bfd_arch_arm |
10590 | #define ELF_MACHINE_CODE EM_ARM | |
d0facd1b NC |
10591 | #ifdef __QNXTARGET__ |
10592 | #define ELF_MAXPAGESIZE 0x1000 | |
10593 | #else | |
f21f3fe0 | 10594 | #define ELF_MAXPAGESIZE 0x8000 |
d0facd1b | 10595 | #endif |
b1342370 | 10596 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 10597 | #define ELF_COMMONPAGESIZE 0x1000 |
252b5132 | 10598 | |
ba93b8ac DJ |
10599 | #define bfd_elf32_mkobject elf32_arm_mkobject |
10600 | ||
99e4ae17 AJ |
10601 | #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data |
10602 | #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data | |
252b5132 RH |
10603 | #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags |
10604 | #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data | |
10605 | #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create | |
dc810e39 | 10606 | #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup |
157090f7 | 10607 | #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup |
252b5132 | 10608 | #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line |
4ab527b0 | 10609 | #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info |
e489d0ae | 10610 | #define bfd_elf32_new_section_hook elf32_arm_new_section_hook |
3c9458e9 | 10611 | #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol |
957c6e41 | 10612 | #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup |
b25e3d87 | 10613 | #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info |
ee065d83 | 10614 | #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link |
252b5132 RH |
10615 | |
10616 | #define elf_backend_get_symbol_type elf32_arm_get_symbol_type | |
10617 | #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook | |
6a5bb875 | 10618 | #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections |
252b5132 RH |
10619 | #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook |
10620 | #define elf_backend_check_relocs elf32_arm_check_relocs | |
dc810e39 | 10621 | #define elf_backend_relocate_section elf32_arm_relocate_section |
e489d0ae | 10622 | #define elf_backend_write_section elf32_arm_write_section |
252b5132 | 10623 | #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol |
5e681ec4 | 10624 | #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections |
252b5132 RH |
10625 | #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol |
10626 | #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections | |
10627 | #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections | |
74541ad4 | 10628 | #define elf_backend_init_index_section _bfd_elf_init_2_index_sections |
ba96a88f | 10629 | #define elf_backend_post_process_headers elf32_arm_post_process_headers |
99e4ae17 | 10630 | #define elf_backend_reloc_type_class elf32_arm_reloc_type_class |
c178919b | 10631 | #define elf_backend_object_p elf32_arm_object_p |
e16bb312 | 10632 | #define elf_backend_section_flags elf32_arm_section_flags |
40a18ebd NC |
10633 | #define elf_backend_fake_sections elf32_arm_fake_sections |
10634 | #define elf_backend_section_from_shdr elf32_arm_section_from_shdr | |
e16bb312 | 10635 | #define elf_backend_final_write_processing elf32_arm_final_write_processing |
5e681ec4 | 10636 | #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol |
b7693d02 | 10637 | #define elf_backend_symbol_processing elf32_arm_symbol_processing |
0beaef2b | 10638 | #define elf_backend_size_info elf32_arm_size_info |
b294bdf8 MM |
10639 | #define elf_backend_modify_segment_map elf32_arm_modify_segment_map |
10640 | #define elf_backend_additional_program_headers \ | |
10641 | elf32_arm_additional_program_headers | |
4e617b1e PB |
10642 | #define elf_backend_output_arch_local_syms \ |
10643 | elf32_arm_output_arch_local_syms | |
a4fd1a8e PB |
10644 | #define elf_backend_begin_write_processing \ |
10645 | elf32_arm_begin_write_processing | |
252b5132 | 10646 | |
5e681ec4 | 10647 | #define elf_backend_can_refcount 1 |
252b5132 RH |
10648 | #define elf_backend_can_gc_sections 1 |
10649 | #define elf_backend_plt_readonly 1 | |
10650 | #define elf_backend_want_got_plt 1 | |
10651 | #define elf_backend_want_plt_sym 0 | |
4e7fd91e PB |
10652 | #define elf_backend_may_use_rel_p 1 |
10653 | #define elf_backend_may_use_rela_p 0 | |
10654 | #define elf_backend_default_use_rela_p 0 | |
252b5132 | 10655 | |
04f7c78d | 10656 | #define elf_backend_got_header_size 12 |
04f7c78d | 10657 | |
252b5132 | 10658 | #include "elf32-target.h" |
7f266840 | 10659 | |
4e7fd91e PB |
10660 | /* VxWorks Targets */ |
10661 | ||
10662 | #undef TARGET_LITTLE_SYM | |
10663 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec | |
10664 | #undef TARGET_LITTLE_NAME | |
10665 | #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks" | |
10666 | #undef TARGET_BIG_SYM | |
10667 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec | |
10668 | #undef TARGET_BIG_NAME | |
10669 | #define TARGET_BIG_NAME "elf32-bigarm-vxworks" | |
10670 | ||
10671 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
10672 | appropriately for VxWorks. */ | |
10673 | static struct bfd_link_hash_table * | |
10674 | elf32_arm_vxworks_link_hash_table_create (bfd *abfd) | |
10675 | { | |
10676 | struct bfd_link_hash_table *ret; | |
10677 | ||
10678 | ret = elf32_arm_link_hash_table_create (abfd); | |
10679 | if (ret) | |
10680 | { | |
10681 | struct elf32_arm_link_hash_table *htab | |
00a97672 | 10682 | = (struct elf32_arm_link_hash_table *) ret; |
4e7fd91e | 10683 | htab->use_rel = 0; |
00a97672 | 10684 | htab->vxworks_p = 1; |
4e7fd91e PB |
10685 | } |
10686 | return ret; | |
10687 | } | |
10688 | ||
00a97672 RS |
10689 | static void |
10690 | elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
10691 | { | |
10692 | elf32_arm_final_write_processing (abfd, linker); | |
10693 | elf_vxworks_final_write_processing (abfd, linker); | |
10694 | } | |
10695 | ||
4e7fd91e PB |
10696 | #undef elf32_bed |
10697 | #define elf32_bed elf32_arm_vxworks_bed | |
10698 | ||
10699 | #undef bfd_elf32_bfd_link_hash_table_create | |
10700 | #define bfd_elf32_bfd_link_hash_table_create \ | |
10701 | elf32_arm_vxworks_link_hash_table_create | |
00a97672 RS |
10702 | #undef elf_backend_add_symbol_hook |
10703 | #define elf_backend_add_symbol_hook \ | |
10704 | elf_vxworks_add_symbol_hook | |
10705 | #undef elf_backend_final_write_processing | |
10706 | #define elf_backend_final_write_processing \ | |
10707 | elf32_arm_vxworks_final_write_processing | |
10708 | #undef elf_backend_emit_relocs | |
10709 | #define elf_backend_emit_relocs \ | |
10710 | elf_vxworks_emit_relocs | |
4e7fd91e PB |
10711 | |
10712 | #undef elf_backend_may_use_rel_p | |
00a97672 | 10713 | #define elf_backend_may_use_rel_p 0 |
4e7fd91e | 10714 | #undef elf_backend_may_use_rela_p |
00a97672 | 10715 | #define elf_backend_may_use_rela_p 1 |
4e7fd91e | 10716 | #undef elf_backend_default_use_rela_p |
00a97672 | 10717 | #define elf_backend_default_use_rela_p 1 |
00a97672 RS |
10718 | #undef elf_backend_want_plt_sym |
10719 | #define elf_backend_want_plt_sym 1 | |
10720 | #undef ELF_MAXPAGESIZE | |
10721 | #define ELF_MAXPAGESIZE 0x1000 | |
4e7fd91e PB |
10722 | |
10723 | #include "elf32-target.h" | |
10724 | ||
10725 | ||
7f266840 DJ |
10726 | /* Symbian OS Targets */ |
10727 | ||
10728 | #undef TARGET_LITTLE_SYM | |
10729 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec | |
10730 | #undef TARGET_LITTLE_NAME | |
10731 | #define TARGET_LITTLE_NAME "elf32-littlearm-symbian" | |
10732 | #undef TARGET_BIG_SYM | |
10733 | #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec | |
10734 | #undef TARGET_BIG_NAME | |
10735 | #define TARGET_BIG_NAME "elf32-bigarm-symbian" | |
10736 | ||
10737 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
10738 | appropriately for Symbian OS. */ | |
10739 | static struct bfd_link_hash_table * | |
10740 | elf32_arm_symbian_link_hash_table_create (bfd *abfd) | |
10741 | { | |
10742 | struct bfd_link_hash_table *ret; | |
10743 | ||
10744 | ret = elf32_arm_link_hash_table_create (abfd); | |
10745 | if (ret) | |
10746 | { | |
10747 | struct elf32_arm_link_hash_table *htab | |
10748 | = (struct elf32_arm_link_hash_table *)ret; | |
10749 | /* There is no PLT header for Symbian OS. */ | |
10750 | htab->plt_header_size = 0; | |
10751 | /* The PLT entries are each three instructions. */ | |
10752 | htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); | |
10753 | htab->symbian_p = 1; | |
33bfe774 JB |
10754 | /* Symbian uses armv5t or above, so use_blx is always true. */ |
10755 | htab->use_blx = 1; | |
67687978 | 10756 | htab->root.is_relocatable_executable = 1; |
7f266840 DJ |
10757 | } |
10758 | return ret; | |
10759 | } | |
10760 | ||
b35d266b | 10761 | static const struct bfd_elf_special_section |
551b43fd | 10762 | elf32_arm_symbian_special_sections[] = |
7f266840 | 10763 | { |
5cd3778d MM |
10764 | /* In a BPABI executable, the dynamic linking sections do not go in |
10765 | the loadable read-only segment. The post-linker may wish to | |
10766 | refer to these sections, but they are not part of the final | |
10767 | program image. */ | |
0112cd26 NC |
10768 | { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 }, |
10769 | { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 }, | |
10770 | { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 }, | |
10771 | { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 }, | |
10772 | { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 }, | |
5cd3778d MM |
10773 | /* These sections do not need to be writable as the SymbianOS |
10774 | postlinker will arrange things so that no dynamic relocation is | |
10775 | required. */ | |
0112cd26 NC |
10776 | { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC }, |
10777 | { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC }, | |
10778 | { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC }, | |
10779 | { NULL, 0, 0, 0, 0 } | |
7f266840 DJ |
10780 | }; |
10781 | ||
c3c76620 | 10782 | static void |
b34af79c | 10783 | elf32_arm_symbian_begin_write_processing (bfd *abfd, |
a4fd1a8e | 10784 | struct bfd_link_info *link_info) |
c3c76620 MM |
10785 | { |
10786 | /* BPABI objects are never loaded directly by an OS kernel; they are | |
10787 | processed by a postlinker first, into an OS-specific format. If | |
10788 | the D_PAGED bit is set on the file, BFD will align segments on | |
10789 | page boundaries, so that an OS can directly map the file. With | |
10790 | BPABI objects, that just results in wasted space. In addition, | |
10791 | because we clear the D_PAGED bit, map_sections_to_segments will | |
10792 | recognize that the program headers should not be mapped into any | |
10793 | loadable segment. */ | |
10794 | abfd->flags &= ~D_PAGED; | |
a4fd1a8e | 10795 | elf32_arm_begin_write_processing(abfd, link_info); |
c3c76620 | 10796 | } |
7f266840 DJ |
10797 | |
10798 | static bfd_boolean | |
b34af79c | 10799 | elf32_arm_symbian_modify_segment_map (bfd *abfd, |
b294bdf8 | 10800 | struct bfd_link_info *info) |
7f266840 DJ |
10801 | { |
10802 | struct elf_segment_map *m; | |
10803 | asection *dynsec; | |
10804 | ||
7f266840 DJ |
10805 | /* BPABI shared libraries and executables should have a PT_DYNAMIC |
10806 | segment. However, because the .dynamic section is not marked | |
10807 | with SEC_LOAD, the generic ELF code will not create such a | |
10808 | segment. */ | |
10809 | dynsec = bfd_get_section_by_name (abfd, ".dynamic"); | |
10810 | if (dynsec) | |
10811 | { | |
8ded5a0f AM |
10812 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) |
10813 | if (m->p_type == PT_DYNAMIC) | |
10814 | break; | |
10815 | ||
10816 | if (m == NULL) | |
10817 | { | |
10818 | m = _bfd_elf_make_dynamic_segment (abfd, dynsec); | |
10819 | m->next = elf_tdata (abfd)->segment_map; | |
10820 | elf_tdata (abfd)->segment_map = m; | |
10821 | } | |
7f266840 DJ |
10822 | } |
10823 | ||
b294bdf8 MM |
10824 | /* Also call the generic arm routine. */ |
10825 | return elf32_arm_modify_segment_map (abfd, info); | |
7f266840 DJ |
10826 | } |
10827 | ||
10828 | #undef elf32_bed | |
10829 | #define elf32_bed elf32_arm_symbian_bed | |
10830 | ||
10831 | /* The dynamic sections are not allocated on SymbianOS; the postlinker | |
10832 | will process them and then discard them. */ | |
10833 | #undef ELF_DYNAMIC_SEC_FLAGS | |
10834 | #define ELF_DYNAMIC_SEC_FLAGS \ | |
10835 | (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED) | |
10836 | ||
10837 | #undef bfd_elf32_bfd_link_hash_table_create | |
10838 | #define bfd_elf32_bfd_link_hash_table_create \ | |
10839 | elf32_arm_symbian_link_hash_table_create | |
00a97672 | 10840 | #undef elf_backend_add_symbol_hook |
7f266840 | 10841 | |
29ef7005 L |
10842 | #undef elf_backend_special_sections |
10843 | #define elf_backend_special_sections elf32_arm_symbian_special_sections | |
7f266840 | 10844 | |
c3c76620 MM |
10845 | #undef elf_backend_begin_write_processing |
10846 | #define elf_backend_begin_write_processing \ | |
10847 | elf32_arm_symbian_begin_write_processing | |
00a97672 RS |
10848 | #undef elf_backend_final_write_processing |
10849 | #define elf_backend_final_write_processing \ | |
10850 | elf32_arm_final_write_processing | |
10851 | #undef elf_backend_emit_relocs | |
c3c76620 | 10852 | |
7f266840 DJ |
10853 | #undef elf_backend_modify_segment_map |
10854 | #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map | |
10855 | ||
10856 | /* There is no .got section for BPABI objects, and hence no header. */ | |
10857 | #undef elf_backend_got_header_size | |
10858 | #define elf_backend_got_header_size 0 | |
10859 | ||
10860 | /* Similarly, there is no .got.plt section. */ | |
10861 | #undef elf_backend_want_got_plt | |
10862 | #define elf_backend_want_got_plt 0 | |
10863 | ||
4e7fd91e | 10864 | #undef elf_backend_may_use_rel_p |
00a97672 | 10865 | #define elf_backend_may_use_rel_p 1 |
4e7fd91e | 10866 | #undef elf_backend_may_use_rela_p |
00a97672 | 10867 | #define elf_backend_may_use_rela_p 0 |
4e7fd91e | 10868 | #undef elf_backend_default_use_rela_p |
00a97672 | 10869 | #define elf_backend_default_use_rela_p 0 |
00a97672 RS |
10870 | #undef elf_backend_want_plt_sym |
10871 | #define elf_backend_want_plt_sym 0 | |
10872 | #undef ELF_MAXPAGESIZE | |
10873 | #define ELF_MAXPAGESIZE 0x8000 | |
4e7fd91e | 10874 | |
7f266840 | 10875 | #include "elf32-target.h" |